"Exception javax.xml.ws.WebServiceException: Unsupported endpoint address" trying to call web service using JAX-WS 2.1
Asked Answered
C

1

7

I'm trying to call the web service here: http://publicbetawebservices.hotel.de/V2_8/FreeHotelSearchWebService.svc?WSDL

I've generated proxy classes using wsimport with JDK1.6.0_29. My wsimport command line is:

wsimport.exe" -keep -B-XautoNameResolution -d E:\mapov\mapov-dev\shared\hotel_info\ http://publicbetawebservices.hotel.de/V2_8/FreeHotelSearchWebService.svc?WSDL

I'm using the following code to attempt to call the service:

QName qName = new QName("http://webservices.hotel.de/V2_8", "FreeHotelSearchWebService");
FreeHotelSearchWebService service = new FreeHotelSearchWebService(new URL("http://publicbetawebservices.hotel.de/V2_8/FreeHotelSearchWebService.svc"), qName);
IFreeHotelSearchWebService sws = service.getBasicHttpBindingIFreeHotelSearchWebService();
String version = sws.getWebservicesVersion();
System.out.println("Hotel.info web service version: " + version);

However I get the following exception:

Exception in thread "main" javax.xml.ws.WebServiceException: Unsupported endpoint address: at com.sun.xml.ws.api.pipe.TransportTubeFactory.create(TransportTubeFactory.java:148) at com.sun.xml.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:134) at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:641) at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:600) at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:585) at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:482) at com.sun.xml.ws.client.Stub.process(Stub.java:323) at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:161) at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:113) at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93) at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:144) at $Proxy42.getWebservicesVersion(Unknown Source)

In most examples I've seen the generated code includes a getPort() method but that hasn't been generated for this class. Is my code wrong or do I need to run wsimport differently? I've also tried calling the FreeHotelWebService constructor without the parameters which yields the same exception.

Cellophane answered 21/12, 2011 at 11:9 Comment(2)
OK I found the issue. The WSDL didn't specify the endpoint address so I had to manually set it like this: BindingProvider bp = (BindingProvider)sws; bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "publicbetawebservices.hotel.de/V2_8/…); Thanks to Tug's blog post here: tugdualgrall.blogspot.com/2009/02/… for the solution.Cellophane
Could you post it as an answer and accept it? Thanks!Strictly
P
6

Reanimating an answerless question basing on Justin's and Tug's Blog:

JAX-WS: How to configure the service end point at runtime?

When deploying your Web Service client you often need to change the endpoint of the service that has been set during the code generation. This short post explains how you can set change it at runtime in the client code.

You have two approaches to do that:

  • set the endpoint in the Port using the BindingProvider;
  • get the endpoint URL from the WSDL itself at runtime;

Use the Binding Provider to set the endpoint URL

The first approach is to change the BindingProvider.ENDPOINT_ADDRESS_PROPERTY property value of the BindingProvider (Port) using the following code:

    try { 
        EmployeeServiceService service = new EmployeeServiceService();

        EmployeeService port = service.getEmployeeServicePort();
        BindingProvider bp = (BindingProvider)port;
        bp.getRequestContext().put(
          BindingProvider.ENDPOINT_ADDRESS_PROPERTY, 
           "http://server1.grallandco.com:8282/HumanRessources/EmployeeServiceService");

        Employee emp = port.getEmployee(123);
        System.out.println("Result = "+ emp);
    } catch (Exception ex) {...
       

Use the WSDL to get the endpoint URL

Another part is to set the WSDL when you are creating the Service. The service will be using the value that is located in the WSDL port -SOAP Endpoint-. This is simply done using the following code:

    try { 
       EmployeeServiceService service =
         new org.demo.service.EmployeeServiceService(
           new URL(       
             "http://server1.grallandco.com:8282/HumanRessources/" + 
             "EmployeeServiceService?wsdl"), 
           new QName(
             "http://service.demo.org/",
             "EmployeeServiceService"));

        EmployeeService port = service.getEmployeeServicePort();
        Employee emp = port.getEmployee(123);

     System.out.println("Result = "+ emp);
    } catch (Exception ex) {...}
      

Note that, in Glassfish, like lot of Web Service environments the WSDL can generate dynamically the Endpoint URL based on the URL used to get the WSDL. With this approach you can also dynamically change the Soap endpoint (if compatible with the network configuration of the production environment.)

Pashm answered 20/9, 2018 at 17:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.