0

I have a WSDL that it has username and password. I used to soapUI and created this WSDL classes, after that in soapUI, by right click on my project I created jax-ws artifacts in a folder in my computer, Then in eclipse I created a dynamic web project and added WSDL client files in my dynamic web project.

enter image description here

After that I wanted to used this wed-service so in a main-class I add these codes for getting output:

    package ir.post.service.main;

import ir.post.service.Exception_Exception;
import ir.post.service.PostcodeWS;
import ir.post.service.PostcodeWSPortBindingQSService;

import javax.xml.ws.BindingProvider;


public class Demo {


    public static void main(String[] args) throws Exception_Exception {         
        PostcodeWSPortBindingQSService service = new PostcodeWSPortBindingQSService();
        PostcodeWS port = (PostcodeWS) service.getPort(PostcodeWSPortBindingQSService.class);

        BindingProvider provider = (BindingProvider) port;

        provider.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "wsdlUsername");   
        provider.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "H!Tb3@hf");

        System.out.println(port.getPostcodeByTelephone("webmethodUsername", "1300@$#0t$rn1n1s3@", 0221, 123456789));    
    }   
}

After running above class as java application, I get this error :

    Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://ip-address/post/PostcodeWSService?wsdl. It failed with: 
    Got Server returned HTTP response code: 401 for URL: http://ip-address/post/PostcodeWSService?wsdl while opening stream from http://ip-address/post/PostcodeWSService?wsdl.
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(Unknown Source)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(Unknown Source)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(Unknown Source)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(Unknown Source)
    at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(Unknown Source)
    at javax.xml.ws.Service.<init>(Unknown Source)
    at javax.xml.ws.Service.create(Unknown Source)
    at ir.post.service.Demo.main(Demo.java:35)
Caused by: java.io.IOException: Got Server returned HTTP response code: 401 for URL: http://ip-address/post/PostcodeWSService?wsdl while opening stream from http://ip-address/post/PostcodeWSService?wsdl
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(Unknown Source)
    at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(Unknown Source)
    ... 9 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://ip-address/post/PostcodeWSService?wsdl
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.URL.openStream(Unknown Source)
    ... 11 more

How can I solve this issue? please help me about this problem?

Thanks.

brelian
  • 403
  • 2
  • 15
  • 31
  • Please see this link which has similar issue - http://stackoverflow.com/questions/11284779/getting-error-java-io-ioexception-server-returned-http-response-code-401-for – Rao Dec 23 '15 at 12:19
  • @Rao, thanks for your reply, but I couldn't use that link, Is it possible for you guide me more about it? – brelian Dec 23 '15 at 12:49
  • Do you mean the link nor accession? – Rao Dec 23 '15 at 12:57
  • @Rao, Acttually I confused, and I don't know what shall I do??? :( – brelian Dec 23 '15 at 13:00
  • 401 is thrown when authrization failed. Here is another relevant link, please try http://stackoverflow.com/questions/6293722/how-can-i-use-wsimport-to-generate-a-webservice-client-which-wsdl-requires-authe – Rao Dec 23 '15 at 13:55

0 Answers0