2

I have made webservice client with NetBeans 8.2 wizard from an existing WSDL document. Java8 and JAX-WS 2.2.9 is used.

As far as I understand everything works with the wizard created code as expected but the query is missing value from "SOAPAction" header which is requirement to have value for the query to work. The header key exists but value is empty string: SOAPAction: "" when it should be SOAPAction = "SendReports"

I have tried using this:

Map<String, List<String>> requestHeaders = new HashMap<>();
requestHeaders.put("SOAPAction", Arrays.asList("sendReports"));
sourceDispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);

-> which results also in empty value. If I put "SOAPAction_2" & "sendReports", that header works correct but obviously the header key is wrong and wont solve my problem. Something overwrites my value afterwards?

The webservice method has annotation:

@WebMethod(operationName = "SendReports", action = "SendReports")

Any tips on what could I try next?

I saw many posts suggesting using BindingProvider but I cannot use com.sun.* packages for reasons left unexplained.

user2864740
  • 60,010
  • 15
  • 145
  • 220
Jokkeri
  • 1,001
  • 1
  • 13
  • 35
  • Not just `requestHeaders.put("SOAPAction", "sendReports")`? :} – user2864740 Jul 12 '18 at 06:37
  • 1
    Apparently some problems if just String: _Thank you! If you're as dumb as me, you might attempt to use a Map because you read the answer too fast. Don't be like me. Use a Map> and save the four hours I spent trying to debug HTTP transport error: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List_ from [https://stackoverflow.com/questions/6666060/java-web-service-client-adding-http-headers](https://stackoverflow.com/questions/6666060/java-web-service-client-adding-http-headers) – Jokkeri Jul 12 '18 at 06:43

1 Answers1

1

Finally found a working solution.

I created a Web service Dispatch client with Netbeans (as originally) and had to add SOAPACTION_USE_PROPERTY and SOAPACTION_URI_PROPERTY. These I had tried before as System properties but seemed not to work that way.

Here is the working snippet:

public void sendReports() throws IOException {
    ReportService service = new ReportService();
    QName portQName = new QName("http://URL/ReportService", "ReportService");
    req = readFile("C:/temp/myFile.xml", "UTF-8");;
    try {

        // Call Web Service Operation
        Dispatch<Source> sourceDispatch = null;
        sourceDispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);

        Map<String, Object> map = sourceDispatch.getRequestContext();
        map.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
        map.put(BindingProvider.SOAPACTION_URI_PROPERTY, "SendReports");

        Source result = sourceDispatch.invoke(new StreamSource(new StringReader(req)));
    } catch (Exception ex) {
        // TODO handle custom exceptions here
    }
}
Jokkeri
  • 1,001
  • 1
  • 13
  • 35