0
votes

I'm trying to call a web service via SOAP/JAX-WS using a Camel route, and keep getting the error: CaughtExceptionMessage:HTTP operation failed invoking http://xyz.com/Service with statusCode: 404.

Calling the same service using Soap UI works file, so my guess is that the request is not getting marshaled the same, and the service is unable to find which method is being called, causing the 404. Soap UI gives the following request XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"     xmlns:bfg="http://xyz.com/Service">
   <soapenv:Header/>
   <soapenv:Body>
      <bfg:login>
         <bfg:request>
            <ipAddress>1.2.3.4</ipAddress>
            <locationId>0</locationId>
            <password>Foo</password>
            <productId>1</productId>
            <username>Bar</username>
            <vendorSoftwareId>0</vendorSoftwareId>
         </bfg:request>
       </bfg:login>
   </soapenv:Body>
</soapenv:Envelope>

Camel spits out the following XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <ns2:Envelope xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" 
      xmlns:ns3="http://xyz.com/Service" 
      xmlns:ns4="http://xyz.com/Other">    
<ns2:Body>        
    <ns3:login>            
       <ns3:request>                
           <ipAddress>1.2.3.4</ipAddress>                
           <locationId>0</locationId>                
           <password>Foo</password>                
           <productId>0</productId>                
           <username>Bar</username>               
           <vendorSoftwareId>0</vendorSoftwareId>            
       </ns3:request>       
    </ns3:login>    
  </ns2:Body>
</ns2:Envelope> 

The differences are pretty small, really just the namespaces. Copying and pasting the XML into SoapUI and then using it will produce a valid request/response.

The Camel route and config is as follows:

private final SoapJaxbDataFormat globalServiceSoap = 
    new SoapJaxbDataFormat(Service.class.getPackage().getName(),  
     new ServiceInterfaceStrategy(Service.class, true));

from(RouteConstants.LOGIN_SERVICE_END_POINT_URI)
     .routeId("internal::loginGlobalService").marshal(globalServiceSoap)
    .to(endpointUri).unmarshal(globalServiceSoap).process(postLoginProcessor);

Where the request object to be marshaled is the body of the message heading into that Camel route. What is Camel doing on the request to cause it to fail with a 404?

ANY help or ideas would be greatly appreciated.

1

1 Answers

0
votes

It turns out that Camel was not adding a contentType header or a SOAPAction header and so the web service was throwing a 404 as it didn't accept the request as a valid SOAP call (most likely the contentType isn't crucial to getting it working). I'd have thought that Camel and the SoapJaxbDataFormat would have been smart enough to add that type of stuff (the examples I saw suggest it should) but it seems not.

Using a java code based route definition it was easy enough to add the missing headers:

from(RouteConstants.LOGIN_SERVICE_END_POINT_URI)
    .routeId("internal::loginGlobalService")
    .setHeader(Exchange.CONTENT_TYPE, constant("text/xml"))
    .setHeader("SOAPAction",   constant("login")).marshal(globalServiceSoap)
    .to(endpointUri).unmarshal(globalServiceSoap).process(postLoginProcessor);

and the resulting request was accepted fine. The marshaling of the request to XML worked fine and needed no change.