How can i handle Apache Camel NoRouteToHostException exception? - web-services

i want to treat the case when connection with Camel HTTP component cannot be established
example:
<from uri="timer:tm?period=2000"/>
<to uri="https://URI"/>
when there is no connection i get this exception:
java.net.NoRouteToHostException: No route to host: connect
I want to handle this response and change it to an understandable message by the consumer. How can i do this ?

Camel provides a couple of very powerful error handling mechanisms with very useful redelivery and deadletter functionality. Those include:
Error Handlers: https://camel.apache.org/error-handler.html
Dead Letter Channels: https://camel.apache.org/dead-letter-channel.html
Try, Catch & Finally: https://camel.apache.org/try-catch-finally.html
Exception Clause: https://camel.apache.org/exception-clause.html
For your usecase, Exception Clause is the best fit. Redelivery would help you to retry the HTTP call and avoid failure due to a temporary downtime, e.g. a server restart:
<onException>
<exception>java.net.NoRouteToHostException</exception>
<!-- retry 3 times with a delay of 10 seconds -->
<redeliveryPolicy maximumRedeliveries="3" logStackTrace="true" redeliveryDelay="10000" />
<!-- only logs once redeliveries have failed -->
<to uri="log:classToLog?level=ERROR"/>
</onException>

You can handle exception using try..catch..finally.
http://camel.apache.org/try-catch-finally.html
Example in Spring DSL:
<route id="send_request">
<from uri="timer:tm?period=2000" />
<doTry>
<to uri="https://URI" />
<doCatch>
<exception>java.net.NoRouteToHostException</exception>
<handled>
<constant>true</constant>
</handled>
<log message="Some Message : ${exception.message}"
loggingLevel="WARN" />
</doCatch>
</doTry>

Related

Unmarshalling error in apache camel with jaxb data format

I am completely new to camel and jboss fuse and I am facing one problem. I am trying to send a request to my webservice using soapUI.I have used cxf component of apache camel and jaxb in apache camel. In the request there is a tag AuthTimeStamp.
When I am entering
<AuthTimestamp>2009-01-02T11:13:56.745+05:30 </AuthTimestamp>
it is working fine. But when I am entering:
<AuthTimestamp>3-23-190017:00</AuthTimestamp>
it is giving me error. I believe jaxb is doing some kind of validation and my request is failing there. But I don't to return soap fault type error.
I want a proper xml to be returned with proper information. If the request passes to my cxf bean then I can handle the exception make a proper error packet and return it. Similar questions have been asked before but I was not able to find appropriate solution.
Initial part of my camel route:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<!-- Service for gateway is exposed. cxfEndpoint mentioned in EsangamBeanConfig.xml-->
<!-- <to uri="bean:NSDGPortTypeImpl"/> -->
<!-- <simple>${body.getIISMessage()}</simple> -->
<!-- <to uri="bean:iISMessageProcessorID?method=logTransaction(${body})"/>
-->
<!--Here goes IISMessageContext(body) -->
<!--Here goes SubmitDocument(body) -->
<!--Here goes IISMessageContext(body) -->
<camelContext id="eSangamMessagingCamelContext" xmlns="http://camel.apache.org/schema/spring">
<dataFormats>
<jaxb contextPath="in.gov.esangam.eservices.messaging" prettyPrint="true" encoding="UTF-8" id="myJaxb"/>
</dataFormats>
<route id="eSangam Messaging Start">
<from uri="cxf:bean:NSDGPortType"/>
<log message="New Request Arrived at Gateway"/>
Below is the stack trace:
14:47:31,842 | WARN | qtp1545452967-60 | PhaseInterceptorChain | 118 - org.apache.cxf.cxf-core - 3.0.4.redhat-620133 | Interceptor for {http://www.mit.gov.in/eGov/schema/NSDG/wsdl}NSDGPortTypeService#{http://www.mit.gov.in/eGov/schema/NSDG/wsdl}processSubmitDocument has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Unmarshalling Error: 3/23/19005:00:00PM
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:908)[132:org.apache.cxf.cxf-rt-databinding-jaxb:3.0.4.redhat-620133]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:712)[132:org.apache.cxf.cxf-rt-databinding-jaxb:3.0.4.redhat-620133]
at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:176)[132:org.apache.cxf.cxf-rt-databinding-jaxb:3.0.4.redhat-620133]
at org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:194)[131:org.apache.cxf.cxf-rt-wsdl:3.0.4.redhat-620133]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)[118:org.apache.cxf.cxf-core:3.0.4.redhat-620133]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)[118:org.apache.cxf.cxf-core:3.0.4.redhat-620133]
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)[123:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-620133]
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)[123:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-620133]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)[123:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-620133]
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)[123:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-620133]
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)[123:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-620133]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)[123:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-620133]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:212)[123:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-620133]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)[89:org.apache.geronimo.specs.geronimo-servlet_3.0_spec:1.0.0]
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268)[123:org.apache.cxf.cxf-rt-transports-http:3.0.4.redhat-620133]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:69)[101:org.ops4j.pax.web.pax-web-jetty:3.2.3]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:533)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:240)[101:org.ops4j.pax.web.pax-web-jetty:3.2.3]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:75)[101:org.ops4j.pax.web.pax-web-jetty:3.2.3]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.Server.handle(Server.java:370)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)[94:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_91]
Caused by: javax.xml.bind.UnmarshalException
- with linked exception:
[javax.xml.bind.UnmarshalException: 3/23/19005:00:00PM
- with linked exception:
[java.lang.IllegalArgumentException: 3/23/19005:00:00PM]]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:483)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:417)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:394)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:858)[132:org.apache.cxf.cxf-rt-databinding-jaxb:3.0.4.redhat-620133]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$100(JAXBEncoderDecoder.java:102)[132:org.apache.cxf.cxf-rt-databinding-jaxb:3.0.4.redhat-620133]
at org.apache.cxf.jaxb.JAXBEncoderDecoder$2.run(JAXBEncoderDecoder.java:897)
at java.security.AccessController.doPrivileged(Native Method)[:1.8.0_91]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:895)[132:org.apache.cxf.cxf-rt-databinding-jaxb:3.0.4.redhat-620133]
... 40 more
Caused by: javax.xml.bind.UnmarshalException: 3/23/19005:00:00PM
- with linked exception:
[java.lang.IllegalArgumentException: 3/23/19005:00:00PM]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:740)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleError(UnmarshallingContext.java:770)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleError(UnmarshallingContext.java:766)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.handleParseConversionException(Loader.java:275)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.LeafPropertyLoader.text(LeafPropertyLoader.java:69)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.text(UnmarshallingContext.java:589)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.processText(StAXStreamConnector.java:338)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleEndElement(StAXStreamConnector.java:216)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:185)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:415)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
... 46 more
Caused by: javax.xml.bind.UnmarshalException: 3/23/19005:00:00PM
- with linked exception:
[java.lang.IllegalArgumentException: 3/23/19005:00:00PM]
... 56 more
Caused by: java.lang.IllegalArgumentException: 3/23/19005:00:00PM
at org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parseYear(Unknown Source)[:]
at org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl$Parser.parse(Unknown Source)[:]
at org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl.<init>(Unknown Source)[:]
at org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl.newXMLGregorianCalendar(Unknown Source)[:]
at com.sun.xml.bind.DatatypeConverterImpl._parseDateTime(DatatypeConverterImpl.java:378)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$2.parse(RuntimeBuiltinLeafInfoImpl.java:279)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$2.parse(RuntimeBuiltinLeafInfoImpl.java:277)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.FilterTransducer.parse(FilterTransducer.java:84)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.parse(TransducedAccessor.java:245)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
at com.sun.xml.bind.v2.runtime.unmarshaller.LeafPropertyLoader.text(LeafPropertyLoader.java:65)[113:org.apache.servicemix.bundles.jaxb-impl:2.2.11.1]
... 51 more
14:47:31,846 | INFO | qtp1545452967-60 | Soap12FaultOutInterceptor | 134 - org.apache.cxf.cxf-rt-bindings-soap - 3.0.4.redhat-620133 | class org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptor$Soap12FaultOutInterceptorInternalapplication/soap+xml

Mule 3.7 until successful failureExpression not working

I am using until-successful to retry calling a web service only when it is down.
Below is what I have tried:
<until-successful maxRetries="10" failureExpression="#[(message.inboundProperties['http.status'] != 200) && (message.inboundProperties['http.status'] != 500)]" synchronous="true" millisBetweenRetries="5000">
<flow-ref name="callSubFlow" doc:name="Flow Reference"/>
If I get a HTTP response 500 I also do not want to retry calling the web service. I have mocked a web service and when it returns a HTTP 500 response the until successful keeps retrying calling the web service. What is wrong with the failureExpression above?
Thanks
There is a lot of confusion around this expression. As per documentation,
FAILURE : "A message processor within the until-successful scope throws an exception or contains an exception payload. Also, if an expression is provided in the attribute failureExpression and it evaluates to true."
https://docs.mulesoft.com/mule-user-guide/v/3.6/until-successful-scope#success-and-failure
The catch here is that with the current implementation of Mule 'failureExpression' is checked and used when no exception is thrown. Otherwise it does always retry in case of exception. Solution for your problem would be to have a catch block for particular exception and then set a property, in failureExpression evaluate that property to retry in until successful. Basically, you would be using recursion technique kind of code for retrying.
Example for your code:
<until-successful maxRetries="10" failureExpression="#[flowVars['errorInActualOutboundFlow']]" synchronous="true" millisBetweenRetries="5000">
<flow-ref name="callActualOutboundFlow" doc:name="Flow Reference"/>
</until-successful>
Actual Outbound Flow:
<flow name="callActualOutboundFlow" processingStrategy="synchronous">
<http:request config-ref="HTTP_Request_Configuration" path="/" method="GET" doc:name="HTTP"/>
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy doc:name="Catch Exception Strategy" when="#[exception.causedBy(java.net.ConnectException)]">
<logger message="#### Until-Successful will retry in this case " level="INFO" doc:name="Logger"/>
<set-variable variableName="errorInActualOutboundFlow" value="#[true]" doc:name="Variable"/>
</catch-exception-strategy>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<set-variable variableName="errorInActualOutboundFlow" value="#[false]" doc:name="Copy_of_Variable"/>
Here is how if fixed my issue. I created another flow that catches only the Web Service 500 error. The until -successful then does not retry to call the web service again.
<until-successful maxRetries="${webservice.timeout.max.retries}" failureExpression="#[exception != null && (exception.causedBy(java.net.ConnectException) || exception.causedBy(java.net.SocketTimeoutException) || exception.causedBy(java.util.concurrent.TimeoutException) || exception.causedBy(java.net.SocketException))]"
synchronous="true" millisBetweenRetries="5000" >
<processor-chain doc:name="Processor Chain">
<set-payload value="#[payLoad]" />
<flow-ref name="Flow1" />
</processor-chain>
</until-successful>
<flow name="Flow1">
<ws:consumer config-ref="WSConsumerConfig" operation="execute" />
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy doc:name="Catch Exception Strategy" when="#[exception != null && exception.causedBy(org.mule.module.ws.consumer.SoapFaultException)]">
<logger message="SoapFaultException occurred." level="INFO" doc:name="Logger"/>
<set-payload value="#[exception]" doc:name="Set Payload"></set-payload>
</catch-exception-strategy>
</choice-exception-strategy>
</flow>
You also need to tell HTTP Request component that 500 is the Non-failure scenario in this case. Because By default 200 is the success scenario, other than anything needs to be mention in 'success-status-code-validator'.
<until-successful maxRetries="5" synchronous="true" doc:name="Until Successful" failureExpression="#[ message.inboundProperties['http.status'] != 200 && message.inboundProperties['http.status'] != 500 ]" millisBetweenRetries="1000">
<http:request config-ref="HTTP_Request_Configuration" path="test1" method="GET" doc:name="HTTP">
<http:success-status-code-validator values="200,500"/>.
</http:request>
</until-successful>
Instead of Directly using HTTP here, Believe you used callSubFlow there where you used HTTP-request, mention in <http:success-status-code-validator values="200,500"/> as success. So it don't retry in this case, works as expected.
If you want to handle 500 as separate logic other than 200, you can do condition check after http:request by checking its message.inboundProperties['http.status'] and can proceed with logic based on 200 or 500.
It is failed in your case, because Http-request saying '500' as failure and Until mentioned as Non-failure.

WSO2 ESB: how to carry a SOAP answer into a file (or DB) using a scheduled task

I deploy a proxy service in WSO2 ESB that asks a web service for a dataset by a SOAP request and the web service correctly returns the requested dataset. In order to have evidence of the right answer of the web service, how can I do to store this dataset into a generic file during a regular scheduling in a task?
In your proxy def, you can find :
a inSequence executed when a request is sent to this proxy,
a outSequence that receive a response if you send a request from your inSequence (with send mediator)
a faultSequence executed if an error occurs.
So, if you "asks a web service for a dataset" from your inSequence using send mediator, your outSequence receive the response (your "dataset") and you just have to send it to a file :
<!-- name of the file -->
<property name="transport.vfs.ReplyFileName" value="dataset.xml" scope="transport"/>
<!-- OUT_ONLY because we want to use send mediator but don't want a callback waiting for a response -->
<property name="OUT_ONLY" value="true" />
<!-- Send current message (the response from your webService) to the filesystem : test directory must exist on c:\ -->
<send>
<endpoint>
<address uri="vfs:file:///C:/test"/>
</endpoint>
</send>
--> don't forget to activate VFS sender in repository/conf/axis2/axis2.xml : uncomment <transportSender name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportSender"/>

Camel JMS object message payload converts from object to byte message while using Websphere MQ

I am using apache camel (Fuse 2.10.x) with soap over http and soap over jms. JMS message gets converted from Object message to Byte message format which causes the problem in reading the message.
I am using JNDI connection for websphere MQ in JBOSS 5.0 GA environment.
<tx-connection-factory>
<jndi-name>MQConnFactory
<xa-transaction />
<rar-name>wmq.jmsra.rar
<connection-definition>javax.jms.ConnectionFactory</connection-definition>
<
<config-property name="channel" type="java.lang.String">xxxx</config-property>
<config-property name="hostName" type="java.lang.String">xxxxx</config-property>
<config-property name="port" type="java.lang.String">xxxx</config-property>
<config-property name="username" type="java.lang.String">xxxxx</config-property>
<config-property name="password" type="java.lang.String">xxxx</config-property>
<config-property name="queueManager" type="java.lang.String">xxxxxx</config-property>
<config-property name="transportType" type="java.lang.Integer">CLIENT</config-property>
<security-domain-and-application>JmsXARealm</security-domain-and-application>
<min-pool-size>1
<max-pool-size>60
<idle-timeout-minutes>10
<blocking-timeout-millis>5000
</tx-connection-factory>
We faced someother problem with IBM attributes which were resolved by removing the attributes. Also we have camel header attribute to set the message
<route id="myrouteName">
<from uri="direct:myrouteName"></from>
<setHeader headerName="prequest">
<simple>${body[0]}</simple>
</setHeader>
<doTry>
<to uri="bean:myWrapService?method=mymethod" />
<filter> <simple>${body.reqVO} != null</simple>
<setHeader headerName="CamelJmsMessageType"> <constant>Object</constant></setHeader>
<to uri="{{requestQ}}" pattern="InOnly" />
</filter>
<to uri="direct:responseHandler" />
<to uri="bean:responseService?method=myMethod"/>
<doCatch>
<exception>java.lang.Exception</exception>
<to uri="bean:exceptionHandler?method=process" />
<to uri="bean:responseService?method=myMethod" />
</doCatch>
</doTry>
</route>
This works fine with soap over http. RequestQ get messages as JMS object message. But same RequestQ get message by JMS Byte Message in soap over JMS.
Suggest me approach which I can ensure that message recieved as Object message in all scenario.
Note: Same scenario works fine with activeMQ as JMS provider.
Other Tech Stack: Spring 3.x, hibernate, apache cxf and etc.
16:33:17,134 INFO [STDOUT] 16:33:17.133 [Camel (csCamelConfig) thread #8 - JmsConsumer[reqQueue]] DEBUG o.a.c.component.jms.JmsConfiguration - Sending JMS message to: queue://XXXXXXXXXX/REQ.QUEUE2?CCSID=819&encoding=1&targetClient=1 with message:
JMSMessage class: jms_object
JMSType: null
JMSDeliveryMode: 1
JMSExpiration: 0
JMSPriority: 0
JMSMessageID: null
JMSTimestamp: 0
JMSCorrelationID: null
JMSDestination: null
JMSReplyTo: null
JMSRedelivered: false
CamelJmsDeliveryMode: 1
CamelJmsMessageType: Object
JMS_IBM_Character_Set: IBM437
JMS_IBM_Encoding: 273
JMS_IBM_Format:
JMS_IBM_MsgType: 8
JMS_IBM_PutApplType: 28
JMS_IBM_PutDate: 20140910
JMS_IBM_PutTime: 15475401
breadcrumbId: ID-INN58JT4BS-53364-1410346638012-2-8
operationName: pay
operationNamespace: http:/www.xxx.com/xxxxx/xxxxx/
class com.xxx.xxxx.xxx.vo.PayloadDTO
16:33:19,465 INFO [STDOUT] 16:33:19.465 [Camel (csCamelConfig) thread #8 - JmsConsumer[paymJmsReqQueue]] DEBUG o.a.camel.processor.SendProcessor - >>>> Endpoint[direct://responseHandler] Exchange[Message: com.xxx.xxxx.base.vo.PayloadDTO#e486e6]
16:33:19,466 INFO [STDOUT] 16:33:19.466 [Camel (csCamelConfig) thread #8 - JmsConsumer[paymJmsReqQueue]] INFO o.a.c.processor.interceptor.Tracer - ID-INN58JT4BS-53364-1410346638012-2-10 >>> (responseHandler) direct://responseHandler --> bean://responseProcessor?method=process <<< Pattern:InOut, Headers:{CamelCxfMessage={javax.xml.ws.wsdl.port={http:/impl.xxxx.xxxx.xxx.com/}ServiceImplPort, JMSCorrelationID=null, JMSMessageID=ID:414d5120484b49424b31533120202020318cf553bd565320, org.apache.cxf.service.model.MessageInfo=[MessageInfo INPUT: {http:/www.xxx.com/xxxxx/xxxx/}xxxx], JMSDeliveryMode=1, org.apache.cxf.message.Message.PROTOCOL_HEADERS={JMS_IBM_Character_Set=[IBM437], JMS_IBM_Encoding=[273], JMS_IBM_Format=[ ], JMS_IBM_MsgType=[8], JMS_IBM_PutApplType=[28], JMS_IBM_PutDate=[20140910], JMS_IBM_PutTime=[15475401], JMSDeliveryMode=[1], JMSExpiration=[0], JMSMessageID=[ID:414d5120484b49424b31533120202020318cf553bd565320], JMSPriority=[0], JMSRedelivered=[false], JMSTimestamp=[1410364074010], JMSXAppID=[Websphere MQ Client for Java], JMSXDeliveryCount=[1], JMSXUserID=[root ]}, JMSXUserID=root , org.apache.cxf.interceptor.LoggingMessage.ID=2, JMS_IBM_MsgType=8, JMSReplyTo=null, JMSTimestamp=1410364074010, JMSDestination=null, JMSType=null, JMSXDeliveryCount=1, JMSRedelivered=false, javax.xml.ws.wsdl.interface={http:/www.xxx.xxx/xxxxx/xxxx/}xxxx, org.apache.cxf.request.uri=null, HTTP.REQUEST=null, Accept=/, org.apache.cxf.headers.Header.list=[], org.apache.cxf.message.Message.BASE_PATH=cwmq://queue:jmsReqQueue?jmsMessageType=Bytes&replyTo=msRespQueue, org.apache.cxf.message.Message.PATH_INFO=null, JMS_IBM_Format= , org.apache.camel.exchange=Exchange[JmsMessage[JmsMessageID: ID:414d5120484b49424b31533120202020318cf553bd565320]], JMSExpiration=0, JMSPriority=0, javax.xml.ws.wsdl.service={http:/impl.xxx.xxx.xxx.xx/}ServiceImplService, JMS_IBM_PutApplType=28, JMS_IBM_PutDate=20140910, org.apache.cxf.binding.soap.SoapVersion=org.apache.cxf.binding.soap.Soap11#ab8a96, JMS_IBM_PutTime=15475401, org.apache.cxf.message.Message.ENCODING=null, org.apache.cxf.message.Message.QUERY_STRING=null, JMSXGroupID=null, JMS_IBM_Character_Set=IBM437, HTTP.RESPONSE=null, org.apache.cxf.request.method=null, javax.xml.ws.wsdl.operation={http:/www.xxx.xxx/xxxx/xxxxx/}xxxxx, org.apache.cxf.transport.Destination=org.apache.camel.component.cxf.transport.CamelDestination#17a840, javax.xml.ws.wsdl.description=camel://cwmq:queue:jmsReqQueue?jmsMessageType=Bytes&replyTo=jmsRespQueue?wsdl, JMS_IBM_Encoding=273, Content-Type=/, JMSXAppID=Websphere MQ Client for Java}, JMSXUserID=root , breadcrumbId=ID-INN58JT4BS-53364-1410346638012-2-8, JMS_IBM_Character_Set=IBM437, JMSExpiration=0, JMSXDeliveryCount=1, JMSXAppID=Websphere MQ Client for Java, JMS_IBM_Format= , prequest=com.xxx.xxxx.xxxxx.PRequest#93899f, JMSTimestamp=1410364074010, JMS_IBM_PutApplType=28, org.apache.cxf.headers.Header.list=[], JMSDeliveryMode=1, JMS_IBM_PutDate=20140910, JMSPriority=0, JMSRedelivered=false, JMS_IBM_Encoding=273, operationNamespace=http://www.xxx.xxx/xxx/xxx=xxxx, CamelJmsMessageType=Object, JMS_IBM_PutTime=15475401, JMSMessageID=ID:414d5120484b49424b31533120202020318cf553bd565320, JMS_IBM_MsgType=8}, BodyType:com.xxx.xxxxx.base.vo.PayloadDTO, Body:com.xxx.xxxx.base.vo.PayloadDTO#e486e6
16:33:19,466 INFO [STDOUT] 16:33:19.466 [Camel (csCamelConfig) thread #8 - JmsConsumer[paymJmsReqQueue]] DEBUG o.a.camel.processor.SendProcessor - >>>> Endpoint[bean://responseProcessor?method=process] Exchange[Message: com.scb.channels.base.vo.PayloadDTO#e486e6]
JmsConsumer[reqQueue]] DEBUG o.a.c.c.jms.EndpointMessageListener - Endpoint[pwmq://queue:reqQueue?concurrentConsumers=2&exchangePattern=InOnly&jmsMessageType=Object&maxConcurrentConsumers=10&maxMessagesPerTask=2] consumer received JMS message:
JMSMessage class: jms_bytes
JMSType: null
JMSDeliveryMode: 2
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:414d5120484b49424b31533120202020318cf553051a5420
JMSTimestamp: 1410364124990
JMSCorrelationID: null
JMSDestination: null
JMSReplyTo: null
JMSRedelivered: false
JMSXAppID: WebSphere MQ Client for Java
JMSXDeliveryCount: 1
JMSXUserID: ibnkmq
JMS_IBM_Character_Set: IBM437
JMS_IBM_Encoding: 273
JMS_IBM_Format:
JMS_IBM_MsgType: 8
JMS_IBM_PutApplType: 28
JMS_IBM_PutDate: 20140910
JMS_IBM_PutTime: 15484499
aced000573720023636f6d2e7363622e6368616e6e656c732e626173652e766f2e5061796c6f6164
44544f163e357ea7d7ff690200044c000c63757272656e7453746174657400124c6a6176612f6c61
6e672f537472696e673b4c000972657175657374564f7400214c636f6d2f7363622f6368616e6e65
6c732f626173652f766f2f42617365564f3b4c000a726573706f6e7365564f71007e00024c000974
72616365506174687400104c6a6176612f7574696c2f4c6973743b7870707372002b636f6d2e7363
622e6368616e6e656c732e626173652e766f2e42696c6c657250617952657175657374564f6aa292
32aa1e2e1f0200034c00106163636f756e74496e7175697279564f74002b4c636f6d2f7363622f63
68616e6e656c732f626173652f766f2f4163636f756e74496e7175697279564f3b4c001562696c6c
506179526567697374726174696f6e564f7400304c636f6d2f7363622f6368616e6e656c732f6261
73652f766f2f42696c6c506179526567697374726174696f6e564f3b4c001262696c6c6572506179
...
So by setting targetClient=1 it means the code is asking the underlying JMS client to send the message as a 'raw' MQ message. It won't have any JMS properties... just a MQ header and payload. Any application getting the message won't see a JMS message. Therefore the JMS client if it sees the message will only be able to create a bytes message.
Whereabouts was this targetclient configured? I don't see in the config above.

Server Side Logging with Spring-WS

I have implemented a web services using JaxWS-Spring. I would like to log the XML being received. I have tried various attempts, among which to add the proper categories to my log4j.properties file and using interceptors. However I have always failed for one reason or another (logging seems to be ignored - adding interceptors to my application context gives other issues).
The following snippets from my project :
PS: I am using Spring 2.5.6
web.xml
<servlet>
<servlet-name>jaxws-servlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Mapping to redirect all requests from 'FaxWebService' to jaxws-servlet. -->
<servlet-mapping>
<servlet-name>jaxws-servlet</servlet-name>
<url-pattern>/FaxWebService</url-pattern>
</servlet-mapping>
applicationContext.xml
<!-- Bind the URL FaxWebService to our bean FaxWebService. -->
<wss:binding url="/FaxWebService">
<wss:service>
<ws:service bean="#faxWebService"/>
</wss:service>
</wss:binding>
<!-- Bean responsible of taking care of the webservice. -->
<bean id="faxWebService" class="com.connexo.icubeplus3.dispatcher.webservices.FaxWebService"
scope="singleton">
<property name="dummyMode" value="${fax.dummy.mode}"/>
</bean>
I doubt this has anything to do with Spring WS to be honest.
If you want to log the incoming messages in Spring WS, you want to raise the logging level for org.springframework.ws.client.MessageTracing.sent and org.springframework.ws.client.MessageTracing.received to TRACE. For example, in log4j config:
<logger name="org.springframework.ws.client.MessageTracing.sent">
<level value="TRACE" />
<appender-ref ref="stdout" />
</logger>
<logger name="org.springframework.ws.client.MessageTracing.received">
<level value="TRACE" />
<appender-ref ref="stdout" />
</logger>
You will have to write a handler to log it. There are various examples in the web, like http://docs.oracle.com/cd/E13222_01/wls/docs103/webserv_adv_rpc/handlers.html