简体   繁体   中英

Problem with passing SOAP headers using Apache CXF client

I am trying to implement a simple client for a webservice, the only problem I am facing with the webservice is, it has a generic endpoint: http://myserver3333.com:8080/ws/services and the way you lookup for web services deployed is via SOAP header.

So, for example, if you try to hit the service vis SOAP UI,

  1. the endpoint I specify is: http://myserver3333.com:8080/ws/services
  2. In the SOAP headers I specific the following:
    SERVICE-NAME = MyAwesomeService
    OPERATION-NAME = makeMeMoreAwesome

So, how can I do the same thing using apache cxf client?

My current code:

    URL wsdlLocation = new URL("http://myserver3333.com:8080/ws/service");

    MyAwesomeService  service = new MyAwesomeService(wsdlLocation);
    MyAwesomeServicePort port = service.getMyAwesomeServiceSOAPPort();

    List<Header> headers = new ArrayList<Header>();
    Header operationNameHeader = new Header(new QName("OPERATION-NAME"), "makeMeMoreAwesome",
                                            new JAXBDataBinding(String.class));
    Header serviceNameHeader = new Header(new QName("SERVICE-NAME"), "MyAwesomeService",
                                            new JAXBDataBinding(String.class));

    headers.add(operationNameHeader);
    headers.add(serviceNameHeader);

    BindingProvider bindingProvider = (BindingProvider)port;
    bindingProvider.getRequestContext().put(Header.HEADER_LIST, headers);

    MakeMeMoreAwesomeRequest request = new MakeMeMoreAwesomeRequest();
    MakeMeMoreAwesomeResponse response = port.makeMeMoreAwesome(request);

    System.out.println(response.getAck());

But when I run this, I get this error:

Exception in thread "main" com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.

java.io.IOException: Server returned HTTP response code: 500 for URL: http://myserver3333.com:8080/ws/services
java.io.IOException: Server returned HTTP response code: 500 for URL: http://myserver3333.com:8080/ws/services?wsdl

Which is correct because there is no WSDL at that location, it need to follow the soap header to get the service.

Update:

After two points from @Daniel Kulp I am here:

  1. I added a new line: bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://myserver3333.com:8080/ws/services");

And now I get this error:

org.apache.cxf.binding.soap.SoapFault: "http://www.myserver.com/ws/services", the namespace on the "errorMessage" element, is not a valid SOAP version.
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.readVersion(ReadHeadersInterceptor.java:115)
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:141)
    at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:60)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:771)

My assumption is, this error is same as this one. But I am not using ?wsdl. So, any suggestions?

2 comments:

1) You aren't picking up CXF. Check your classpath to make sure CXF is there and not the Sun/Oracle implementation. com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException shows you are picking up the Sun implementation.

2) The URL passed into MyAwesomeService(wsdlLocation) MUST be a URL to the WSDL, not the endpoint itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM