I have a service bundle where I want to compress a response by using CXF GZIPFeature. The bundle is deployed on JBoss Fuse(jboss-fuse-6.1.0.redhat-379). Camel route configuraion is:
<cxf:bus id="cxf" name ="cxf">
<cxf:features>
<bean class="org.apache.cxf.transport.common.gzip.GZIPFeature">
<property name="threshold">
<value>1</value>
</property>
</bean>
</cxf:features>
</cxf:bus>
<camel:camelContext ...>
<camel:route id="test-server">
<camel:to uri="cxfbean:servicebeans?bus=#cxf&providers=#providers" />
</camel:route>
</camel:camelContext>
But this throws classcast exception:
java.lang.ClassCastException: org.apache.cxf.transport.common.gzip.GZIPOutInterceptor$GZipThresholdOutputStream cannot be cast to org.apache.cxf.io.CachedOutputStream
at org.apache.camel.component.cxf.transport.CamelDestination$CamelOutputStream.commitOutputMessage(CamelDestination.java:284)[204:org.apache.camel.camel-cxf-transport:2.12.0.redhat-610379]
at org.apache.camel.component.cxf.transport.CamelDestination$CamelOutputStream.doClose(CamelDestination.java:296)[204:org.apache.camel.camel-cxf-transport:2.12.0.redhat-610379]
at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:220)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]
at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:241)[:1.7.0_67]
at org.apache.cxf.io.AbstractWrappedOutputStream.close(AbstractWrappedOutputStream.java:77)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]
at org.apache.cxf.io.AbstractThresholdOutputStream.close(AbstractThresholdOutputStream.java:102)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)[164:org.apache.cxf.cxf-api:2.7.0.redhat-610379]
Is there a legal way to use CXF GZIPFeature in the route? I don't want to use Camel's DataFormat to gzip.
I'm using servicemix-camel-cxf and had nearly the same problem. In the end I decided to simply add this in route:
<marshal>
<gzip/>
</marshal>
Check it out - maybe it will help you too.
But in that case you have to set Content-Type: gzip header.
Try to add
<setHeader headerName="Content-Type">
<constant>gzip</constant></setHeader>
However for me it didn't help, so I added header in java code. =)
Related
Here is my spring configuration.
Spring.xml
-------------
<!-- Outgoing SOAP client endpoint -->
<cxf:cxfEndpoint id="serviceEndpoint" address="${endpointAddress}"
wsdlURL="${wsdlAddress}" endpointName="${portName}" serviceName="${serviceName}">
<!-- The interceptors - needed to log the SOAP requests and responses -->
<!-- They can be removed, when no logging is needed -->
<cxf:inInterceptors>
<ref bean="loggingInInterceptor" />
</cxf:inInterceptors>
<cxf:outInterceptors>
<ref bean="loggingOutInterceptor" />
</cxf:outInterceptors>
<cxf:outFaultInterceptors>
<ref bean="loggingOutInterceptor" />
</cxf:outFaultInterceptors>
<cxf:inFaultInterceptors>
<ref bean="loggingInInterceptor" />
</cxf:inFaultInterceptors>
<cxf:properties>
<entry key="dataFormat" value="PAYLOAD" />
</cxf:properties>
</cxf:cxfEndpoint>
<http:conduit name="*.http-conduit">
<http:tlsClientParameters disableCNCheck="${disableHostnameCheck}">
<sec:keyManagers keyPassword="${keystorePassword}">
<sec:keyStore type="JKS" password="${keystorePassword}"
file="${keystoreLocation}" />
</sec:keyManagers>
<sec:trustManagers>
<sec:keyStore type="JKS" password="${truststorePassword}"
file="${truststoreLocation}" />
</sec:trustManagers>
<sec:cipherSuitesFilter>
<!-- these filters ensure that a ciphersuite with export-suitable or
null encryption is used, but exclude anonymous Diffie-Hellman key change
as this is vulnerable to man-in-the-middle attacks -->
<sec:include>.*_EXPORT_.*</sec:include>
<sec:include>.*_EXPORT1024_.*</sec:include>
<sec:include>.*_WITH_DES_.*</sec:include>
<sec:include>.*_WITH_AES_.*</sec:include>
<sec:include>.*_WITH_NULL_.*</sec:include>
<sec:exclude>.*_DH_anon_.*</sec:exclude>
</sec:cipherSuitesFilter>
</http:tlsClientParameters>
<http:client AutoRedirect="true" Connection="Keep-Alive"
ReceiveTimeout="${connectionTimeout}" ConnectionTimeout="${connectionTimeout}" />
</http:conduit>
Here is the Camel route configuration
-------------
<from ...
<to uri="cxf:bean:serviceEndpoint" />
This works well and we can have the soap request/response logged into the log file. Here soap request with soap header is generated by cxf.
Do we have a way to capture the soap request and response into camel Exchange? I have to send an email attached with soap request and response if the service call is failed.
Have tried using thread local but it doesn't seems to work expected.
Suggestion:
You have it in CXF Interceptors - take a look at them.
I guess, you can send your e-mail out of it.
Start from org.apache.cxf.phase.AbstractPhaseInterceptor class - there are bunch of different ones for different phases.
P.S. From first glance org.apache.cxf.binding.soap.saaj.SAAJInInterceptor and
org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor could be good candidates...
This is my spring integration case:
1) ftp adapter to download a pdf file
2) pdf2TextTransformer transform pdf to text by using pdfbox
3) pdfText2CsvTransformer transform text to csv
I add an enricher in the chain, however, seems header doesn't propagate to myErrorChannel, anyone can tell me why?
Here is my debug log, header file_originalFile doesn't propagate to myErrorChannel
][Headers={file_originalFile=D:\projects\DMTP\ftp\local2\6000047256 - Copy - Copy.pdf, file_name=6000047256 - Copy - Copy.pdf, id=a091fe5e-83f3-e48c-4be5-927849dbf31a, timestamp=1501472718172}]
11:45:18.180 DEBUG [task-scheduler-2][org.springframework.integration.channel.PublishSubscribeChannel] preSend on channel 'errorChannel', message: [Payload MessageTransformationException content=org.springframework.integration.transformer.MessageTransformationException: org.springframework.messaging.MessageHandlingException: java.lang.StringIndexOutOfBoundsException: String index out of range: -3][Headers={id=251c77f0-30e8-e18c-6980-ebfb289f79a4, timestamp=1501472718180}]
11:45:18.180 DEBUG [task-scheduler-2][org.springframework.integration.handler.ServiceActivatingHandler] ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor#56eacc77] received message: [Payload MessageTransformationException content=org.springframework.integration.transformer.MessageTransformationException: org.springframework.messaging.MessageHandlingException: java.lang.StringIndexOutOfBoundsException: String index out of range: -3][Headers={id=251c77f0-30e8-e18c-6980-ebfb289f79a4, timestamp=1501472718180}]
file_originalFile:null
MessageHeaders: {id=251c77f0-30e8-e18c-6980-ebfb289f79a4, timestamp=1501472718180}
MessagePayload: org.springframework.integration.transformer.MessageTransformationException: org.springframework.messaging.MessageHandlingException: java.lang.StringIndexOutOfBoundsException: String index out of range: -3
11:45:18.182 DEBUG [task-scheduler-2][org.springframework.integration.handler.ServiceActivatingHandler] handler 'ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor#56eacc77]' produced no reply for request Message: [Payload MessageTransformationException content=org.springframework.integration.transformer.MessageTransformationException: org.springframework.messaging.MessageHandlingException: java.lang.StringIndexOutOfBoundsException: String index out of range: -3][Headers={id=251c77f0-30e8-e18c-6980-ebfb289f79a4, timestamp=1501472718180}]
here is my configuration:
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="${host}"/>
<property name="port" value="${availableServerPort}"/>
<property name="username" value="${userid}"/>
<property name="password" value="${password}"/>
</bean>
<bean id="cachingSessionFactory" class="org.springframework.integration.file.remote.session.CachingSessionFactory">
<constructor-arg ref="ftpClientFactory"/>
</bean>
<int:channel id="ftpChannelIn">
<int:queue capacity="1"/>
</int:channel>
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannelIn"
session-factory="cachingSessionFactory"
filename-pattern="*.pdf"
auto-create-local-directory="true"
delete-remote-files="true"
remote-directory="/in2"
local-directory="D:/projects/DMTP/ftp/local2">
<!--<int:poller fixed-rate="1000"/>-->
<int:poller fixed-delay="1"/>
</int-ftp:inbound-channel-adapter>
<int:chain input-channel="ftpChannelIn">
<int:header-enricher>
<int:header name="foo" value="bar"/>
</int:header-enricher>
<file:file-to-bytes-transformer/>
<int:transformer ref="pdf2TextTransformer"/>
<int:transformer ref="pdfText2CsvTransformer"/>
<int-ftp:outbound-channel-adapter
remote-directory="/out"
session-factory="cachingSessionFactory"
remote-filename-generator="filenameGenerator"/>
</int:chain>
<int:channel id="ftpChannelOut">
</int:channel>
<bean id="filenameGenerator" class="file.DatedDirectoryFactory "/>
<int:poller default="true" fixed-delay="50"/>
<int:channel id="myErrorChannel"/>
<int:service-activator input-channel="errorChannel" ref="errorLogger"/>
The ErrorMessage is built in the Poller and it is based on the exception:
try {
getMessagingTemplate().send(errorChannel, getErrorMessageStrategy().buildErrorMessage(t, null));
sent = true;
}
There is no any info about original headers.
Your headers, in particular <int:header name="foo" value="bar"/> is presented on the downstream requestMessage. Typically, when exception happens in the Integration Component, the MessagingException is thrown.
In your case it is MessageTransformationException. That kind of exception has failedMessage property. This is exactly your requestMessage what is "guilty" in the error. And, as you understand, already here you can get access to you headers - MessagingException.getFailedMessage().getHeaders()get("foo"). And, of course, file_originalFile will be available here as well.
If your transformers are returning Message<?> then they are responsible for copying the headers; the framework assumes that. If your transformers are POJO, and return just the transformed payload (the recommended programming model), the framework will take care of propagating the headers.
Turn on debug logging to examine the message flow; if you still think it "doesn't work", explain in more detail and edit the question to show the log.
BTW, "doesn't work" is not an adequate description of a problem.
currently I am working with camel and wmq. What I tried to do is sending a message to wmq. I configure the camel by using Spring Framework. Here is how configure the wmq:
component.xml
<bean id="websphere-mq" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="transportType">
<util:constant static-field="com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP" />
</property>
<property name="hostName" value="localhost" />
<property name="port" value="1414" />
<property name="queueManager" value="localmanager" />
<property name="channel" value="CH.ADM1" />
<property name="CCSID" value="819"/>
<property name="useConnectionPooling" value="true" />
</bean>
</property>
</bean>
config.xml
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="stream:in?promptMessage=Ausweisnummer: "/>
<process ref="TransformToXML"/>
<to uri ="xslt:mobako.sender.xsl"/>
<to uri ="websphere-mq:queue:LSMH.ZKSEAP.SERVICEBUS"/>
</route>
<route>
<from uri="websphere-mq:queue:ZKSEAP.LSMH.SERVICEBUS"/>
<to uri="stream:out"/>
</route>
</camelContext>
When I check the to the wmq, I found out that the wmq has been listening to my process, but it did not get any message.
Then to check if my wmq configuration is right, I tried to change my config.xml into something like this:
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="websphere-mq:queue:ZKSEAP.LSMH.SERVICEBUS"/>
<to uri="stream:out"/>
</route>
</camelContext>
After that I tried to write the message manually to the wmq. And when I tried to run my process, then the message from wmq is writen on my console.
Then, I sum up that, with my configuration, I can get the message from the wmq, but I can not write to wmq.
What is the problem actually? Is there something wrong or missing from my configuration? Thanks so much.
EDITED
Hey, finally I found out what is wrong.
The problem is: my jms version not the same with my camel version.
But, after I changed the jms version, I got following error (regarding to the wmq) on my server:
2014-06-05 15:14:34,859 [Axis2 Task] ERROR WMQMsg - Expected MQ message format '
MQSTR ', but received 'MQHRF2 '
How to solve it? Thanks again.
I think your problem is in your JMS message types and conversion.
Please see following link and try to convert your message type that you get from stream:in.
http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.0.1/com.ibm.mq.csqzaw.doc/jm25524_.htm?cp=SSFKSJ_7.0.1%2F1-25-3-4-1-1-1&lang=en
http://www.capitalware.com/rl_blog/?p=1168
Processing MQ ByteMessage using JMS client
Firstly, I don't really understand your route:
Specifically, you have two .to uris. Maybe I am wrong, but logically you'd need some kind of logic to route a message to one endpoint or another.
Secondly, if I may, I will provide you with a solution that worked for me.
As I understood, you only need to set up a camel endpoint of type jms, and then let the camel do all the boilerplate code for you. You do require a specific ConnectionFactory (in our case wmq). I will create it in Java, doing it with Spring beans just adds complexity.
CamelContext camelContext = new DefaultCamelContext();
MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
connectionFactory.setHostName("localhost");
try {
connectionFactory.setPort(1414);
connectionFactory.setQueueManager("QueueManagerName");
connectionFactory.setChannel("ChannelName");
connectionFactory.setTransportType(1);
} catch (JMSException e) {
e.printStackTrace();
}
camelContext.addComponent("wmq", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
For the second part, we can use the wmq as any other endpoint.
try {
camelContext.addRoutes(new RouteBuilder() {
#Override
public void configure() throws Exception {
from("file://data/in/?noop=true")
.to("wmq:queue:YourQueueName");
}
});
} catch (Exception e) {
e.printStackTrace();
}
I'm using camel and cxf component to get some data from web-service. In some case web-service returns standard soap:fault.
I have the next steps:
<camel:route id="someId">
<camel:onException useOriginalMessage="false">
<camel:exception>java.lang.Exception</camel:exception>
<camel:handled>
<camel:constant>false</camel:constant>
</camel:handled>
<camel:process ref="defaultNaoIntegrationErrorHandler" />
<camel:to uri="ref:naointegration.checkAvailability.jms.error.queue" />
</camel:onException>
<camel:from uri="direct:naoCheckAvailabilityOut" />
<camel:marshal ref="soapjaxbSAP" />
<camel:to id="naoCheckAvailabilityEndpoint" uri="cxf:bean:naoCheckAvailabilityEndpoint" />
<camel:unmarshal ref="soapjaxbSAP" />
</camel:route>
where naoCheckAvailabilityEndpoint is:
<cxf:cxfEndpoint id="naoCheckAvailabilityEndpoint"
address="${naointegration.I011.CheckAvailability.soap.address}"
endpointName="s:checkAvailabilityEndpoint" serviceName="s:SOAPService"
xmlns:s="http://www.example.com/test">
<cxf:properties>
<entry key="dataFormat" value="MESSAGE" />
<entry key="setDefaultBus" value="true" />
</cxf:properties>
<cxf:outInterceptors>
<ref bean="logOutbound" />
</cxf:outInterceptors>
<cxf:inFaultInterceptors>
<ref bean="logOutbound" />
</cxf:inFaultInterceptors>
</cxf:cxfEndpoint>
If I'm getting normal soap message everything is ok. And when I'm getting soap foalt/http 500 I have just string message which contains soap message (xml) with soap fault.
Reading cxf and camel mail lists on like problems I understood cxf endpoint should throw exception if there soap foalt, exception of type org.apache.cxf.binding.soap.SoapFault, but I can not get it.
The goal is onException clause do handling of soap fault exception.
Any suggestions?
You are using the MESSAGE data format, which means the camel-cxf endpoint just pass the stream from the transport, it will not read the under layer message, so the camel-cxf endpoint cannot tell which message is normal soap message or soap fault message.
If you want to let the camel route deal with the soap fault, you need to use the PAYLOAD or POJO data format.
This is an intermittent problem, roughly 4/5 starts hit null pointer. Camel-Context.xml is below.
Error:
2011-10-18 08:31:25,245 [main ] INFO MainSupport - Apache Camel 2.8.0 stopping
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from file [D:\Users\michaelb\workspace\camel-example-spring-eda\target\classes\META-INF\spring\camel-context-NERD.xml]; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at org.apache.camel.spring.Main.createDefaultApplicationContext(Main.java:185)
at org.apache.camel.spring.Main.doStart(Main.java:139)
at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:67)
at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:54)
at org.apache.camel.impl.MainSupport.run(MainSupport.java:136)
at org.apache.camel.impl.MainSupport.run(MainSupport.java:322)
at com.softwareag.eda.NERD.main(NERD.java:39)
Caused by: java.lang.NullPointerException
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.checkOverrideProperties(ClassBeanInfoImpl.java:190)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:171)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:494)
Camel-Context.xml
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
org.apache.camel.example.spring.eda
<!-- Announce route -->
<route id="Announcer" startupOrder="3">
<from uri="file:src/data?noop=true" />
<choice>
<when>
<xpath>$eventtype = 'shipment'</xpath>
<to uri="jmsEDA:topic:orderMgmt" />
</when>
<otherwise>
<to uri="jmsEDA:topic:orderMgmt" />
</otherwise>
</choice>
</route>
<!-- Listen route -->
<route id="Listener" startupOrder="2">
<from uri="jmsEDA:topic:orderMgmt" />
<to uri="file://target/test?noop=true" />
<to uri="outputToScreen" />
<log message="done" />
</route>
</camelContext>
<!-- EDA JMS endpoint URL -->
<bean id="jmsEDA" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL"
value="vm://localhost?broker.persistent=false&broker.useJmx=false" />
</bean>
</property>
</bean>
<!-- Screen output endpoint -->
<bean id="outputToScreen"
class="com.softwareag.eda.NERD.outputToScreen">
</bean>
</beans>
I came across your question due to experiencing the same problem. On Feb 18, 2012 the 2.2.5 version of JAXB was released. After upgrading to 2.2.5, the problem seems to have been resolved. So far, it hasn't occurred again in testing.
See http://jaxb.java.net/ for details.
For reference, my configuration uses Camel 2.8.4 and Spring 3.0.5.
The problem is also mentioned here and it has an statement from Claus Ibsen here. You solved it already, it is Java 7.
Same thing for 1.6.0_30-b12 (32 bit) with Camel 2.8 and 2.9
I've downgraded my jaxb-impl version from 2.2.4 to 2.2.3.
I think it's not a JDK, but a JAXB issue :
C:\java\jdk1.7.0_03\bin\xjc.exe -version
xjc 2.2.4
It is fixed in JBoss 7.1.2. So you need to fix it yourself in JBoss 7.1.1
You can find more about this issue here.