Problem with passing SOAP headers using Apache CXF client

11,179

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.

Share:
11,179
zengr
Author by

zengr

Software Engineer in San Fransisco Bay Area. #Java #Python #Generalist ↑ ↑ ↓ ↓ ← → ← → B A

Updated on June 04, 2022

Comments

  • zengr
    zengr almost 2 years

    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?