how to capture soap fault detail in camel-spring-ws - java

I am using camel framework 2.22.0 and camel-spring-ws in my spring boot microservice to convert xml into soap at runtime and make a request to backend and same time receive the soap response and coverts it back to XML before sending the response back to calling system.
Success scenarios are all working fine but when soap fault it only logs the soap string and can't see any soap response been populated. soap response is not getting captured and doesn't get back to calling system apart from http status code 500.
The below is what backend system is sending as soap fault. I can't see anything in camel exchange body populated with soap fault. I need to capture the xml response in detail tag section and to send back to calling system.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>abc-complex-type.x.x: Value '0' of attribute 'schemaVersion' of element 'ABCSubmission:ABCSubmission' is not valid with respect to the corresponding attribute use. Attribute 'schemaVersion' has a fixed value of '1'.</faultstring>
<detail>
<ns2:ABCSubmissionException xmlns:ns2="java:com.webservice.ejb" xmlns="ABCintegration.xdt">
<ns2:ABCIntegrationError schemaVersionMajor="1" schemaVersionMinor="0">
<ErrorName>ABCMessageSyntaxInvalid</ErrorName>
<ErrorDescription>cvc-complex-type.3.1: Value '0' of attribute 'schemaVersion' of element 'ABCSubmission:ABCSubmission' is not valid with respect to the corresponding attribute use. Attribute 'schemaVersion' has a fixed value of '1'.</ErrorDescription>
</ns2:ABCIntegrationError>
</ns2:ABCSubmissionException>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

Camel differentiates between Exceptions and Faults (historic reasons). Unfortunately this seems to be missing in the Camel Documentation.
If you want that Camel treats Faults the same as Exceptions (handled by the Camel error handler), you have to set
.handleFault()
You can set this globally on the Camel Context or on specific routes. See also the comment at the bottom of this page

Related

How can I extract an XML payload from SOAP message with Java?

I am new to SOAP and need to extract an XML payload from a SOAP message. Our application is contacting a soap service, and the service is returning an XML Document that is embedded within a SOAP message. I need to extract this XML that is within the SOAP body, and save it as a "stand alone" well formed XML document. What is the best way to go about this?

One or more http request headers was not valid for the SOAP request

I'm trying to connect my Java application with the Channel Advisor API and I get this error:
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server was unable to process request. One or more http request headers was not valid for the SOAP request. </faultstring>
<detail/>
</soap:Fault>
</soap:Body>
</soap:Envelope>
Here is my request:
String requestURL = "https://api.channeladvisor.com/ChannelAdvisorAPI/v7/InventoryService.asmx";
String request =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:web='http://api.channeladvisor.com/webservices/'>"+
"<soapenv:Header>"+
"<web:APICredentials>"+
"<!--Optional:-->"+
"<web:DeveloperKey>XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX</web:DeveloperKey>"+
"<!--Optional:-->"+
"<web:Password>XXXXXXXXXX</web:Password>"+
"</web:APICredentials>"+
"</soapenv:Header>"+
"<soapenv:Body>"+
"<web:GetInventoryQuantity>"+
"<web:accountID>XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXXX</web:accountID>"+
"<web:sku>XXXXXX-XX-XXX</web:sku>"+
"</web:GetInventoryQuantity>"+
"</soapenv:Body>"+
"</soapenv:Envelope>";
The strange thing is that if I try the same request with SoapUI I get back a successful response.
Any idea how to fix this?
Have you tried to address the actual message the web service is returning (emphasis mine)?
Server was unable to process request. One or more http request headers was not valid for the SOAP request
If it works from SoapUI then it means you are not sending a proper request from your Java application. SoapUI records some logs when it performs the request. You can look at he HTTP logs and see what headers it sends.
My guess is you are either missing the SOAPAction or the Content-Type. Start adding the headers one by one and see when the web service stops complaining.

Duplicate Namespace in header for error response from SOAP web service

If I send a request with the header like as below .,
<S:Header>
<ns2:transId xmlns="http://test.ws.com/testws"
xmlns:ns2="http://test.db.com/db9">123ASD89EDFE7363</ns2:transId>
</S:Header>
its working fine for success responses also there is no unnecessary namespace exist in the header. But error cases, the response from the web service is sent with the two namespaces using same default identifiers for the header element as like below.,
<S:Header>
<transId xmlns="http://test.ws.com/testws"
xmlns="http://test.db.com/db9">123ASD89EDFE7363</transId>
</S:Header>
because of the above format, the client application is unable to parse the responses.
the client artifact is generated using the clientgen from the wsdl. can anyone please help to find the resolution for the above issue.
Thanks in advance.
Can you describe the issue a little more?
It sounds like you're making an HTTP request with a header that has the value "123ASD...", and that when the server responds with OK (200) then it works as expected, but that when the server responds with an error condition (4xx-5xx) then the response it bad.
is it duplicating the same header twice in the HTTP response headers?
Or is it sending an extra request (like perhaps a redirect)?
Like
GET gets a 301 repsonse with the header and then maybe it sends to an error page but it uses the same header twice or something?
A little more information about the header value (does it change every time?) might help...
Thanks for your response. its a SOAP message with header and body over HTTP and there is no issues with the HTTP. error response is like the soap fault or schema validation error from the server when we send bad soap requests. Its not duplicating the header, but when a soap request sent with the unnecessary namespace xmlns="http://test.ws.com/testws" (it has nothing to do with the header elements but my client app adds this everytime when it sends request ), the web service returns the response including the above one and the needed namespace of xmlns="http://test.db.com/db9". my question is the web service is not using different identifiers when it sends two namespaces. the header value is static during one transaction like sessionid.

SOAP to XML conversion and sending it in response object

I am new to webservices,some how i managed to host a service with metro.With the help of SOAP UI and also httpUrlConnection object i am able to get SOAP response.But my next task is to send a response with content type "application/xml".So i used httpServletResponse,but i am not getting how to extract only XML part(without SOAP envolope and SOAP header) and also how to send XML inside respose object.Whether the way in which i am doing is rite?If yes,how to proceed with next step.
There are various ways to send xml content within SOAP response. To keep wsdl and xsd simple, you may use CDATA for your xml content and parse like a string on the receiving end.
<![CDATA[YOUR XML GOES HERE]]>
If you want to parse SOAP message and extract XML then you may want to use Java API SAAJ

How to remove header attribute from Axis2 SOAP response

I am trying to remove the header attributes from a SOAP response.
I have searched and ran across the idea that setting the mustUnderstand option too false will remove the header attribute element, but not the header tag.
How do I remove the header tag from an Axis2 SOAP response? Is it possible?
You can write SoapHandler that intercepts all your soap requests. Inside SoapHandler you have access to SoapMessageContext than obtain SoapMessage.getEnvelope().getHeader() and play with header in all ways (remove/add header elements). This approach good because you introduce new layer in your api and can preprocess inbound and outbound messages without impact on your main code.
Maybe following link will help you http://java.dzone.com/articles/creating-soap-message-handlers

Categories