开发者

wsdl2java with Basic Authentication (Axis 1.6.1)

开发者 https://www.devze.com 2023-04-12 13:19 出处:网络
I am using wsdl2java to generate my java stub code for a web service. I know it has been a bugsince 1.4 that a wsdl source that requires HTTP basic auth could not be accessed. You will receive a 401

I am using wsdl2java to generate my java stub code for a web service.

I know it has been a bug since 1.4 that a wsdl source that requires HTTP basic auth could not be accessed. You will receive a 401 error because authorization was denied and there is no way to specify credentia开发者_开发知识库ls.

Does anyone know if this issue was resolved or has someone a workaround for this? I could setup a proxyy server probably, but this is too much hassle for me, I am seeking something simple :)


you can try as this

...
serviceStub = new TestBeanServiceStub("<WEB SERVICE URL>"); // Set your value
HttpTransportProperties.Authenticator basicAuthenticator = new HttpTransportProperties.Authenticator();
List<String> authSchemes = new ArrayList<String>();
authSchemes.add(Authenticator.BASIC);
basicAuthenticator.setAuthSchemes(authSchemes); 
basicAuthenticator.setUsername("<UserName>"); // Set your value
basicAuthenticator.setPassword("<Password>"); // Set your value
basicAuthenticator.setPreemptiveAuthentication(true);
serviceStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, basicAuthenticator);
serviceStub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, "false");
...


As a workaround, I downloaded the wsdl file manually (using my browser) and saved it along with my code, and pointed wsdl2java to my local copy.


You can pass username and password in URL like this: http://username:password@example.com/wsdl It works for me in axis: 1.7.9

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号