Question

I am new to Stack Overflow and Apache Camel routing and am having some trouble. I have created a really simple SOAP web service that takes an XML request that contains some random text and it then returns the same string in a response.

Using Camel I am able to send the request to the web service and get a response (if I use the log component to capture the request/response.

Ideally I would like to send the XML messages (message1.xml, message2.xml, message3.xml) to the webservice and then process them and store the responses in file:src/data/responses/(message1.xml, message2.xml, message3.xml) etc.. I thought it might be as simple as adding an extra step to my route (see below).

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:src/data?noop=true" />
<log loggingLevel="INFO" message="${body}"/>
<to uri="cxf://http://localhost:8181/cxf/webservice?wsdlURL=src/main/resources/META-INF/webservice.wsdl&amp;serviceName={http://carose.com/}EchoServiceImplService&amp;portName={http://carose.com/}EchoServiceImplPort&amp;dataFormat=MESSAGE"/>
<log loggingLevel="INFO" message="${body}"/>
<to uri="file:src/data/responses" />
</route>
</camelContext>

However, when I run the route using mvn camel:run it creates a blank XML file in the /responses/ folder for each message. The following error messages are displayed when executing the route:

[           default-workqueue-1] route1                         INFO  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:echoTextResponse xmlns:ns2="http://carose.com/"><return>Hello this is a test 123</return></ns2:echoTextResponse></soap:Body></soap:Envelope>
[           default-workqueue-2] route1                         INFO  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:echoTextResponse xmlns:ns2="http://carose.com/"><return>this is another test!</return></ns2:echoTextResponse></soap:Body></soap:Envelope>
[           default-workqueue-3] route1                         INFO  <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:echoTextResponse xmlns:ns2="http://carose.com/"><return>and another test!</return></ns2:echoTextResponse></soap:Body></soap:Envelope>
[           default-workqueue-2] DefaultErrorHandler            ERROR Failed delivery for (MessageId: ID-christophersair-lan-53992-1398682968504-0-9 on ExchangeId: ID-christophersair-lan-53992-1398682968504-0-4). Exhausted after delivery attempt: 1 caught: org.apache.camel.component.file.GenericFileOperationFailedException: Cannot store file: src/data/responses/message2.xml

Message History

RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[route1            ] [route1            ] [file://src/data?noop=true                                                     ] [        26]
[route1            ] [log1              ] [log                                                                           ] [         1]
[route1            ] [to1               ] [cxf://http://localhost:8181/cxf/webservice?wsdlURL=src/main/resources/META-INF] [        15]
[route1            ] [log2              ] [log                                                                           ] [         3]
[route1            ] [to2               ] [file:src/data/responses                                                       ] [         5]

Exchange

Exchange[
Id                  ID-christophersair-lan-53992-1398682968504-0-4
ExchangePattern     InOnly
Headers             {breadcrumbId=ID-christophersair-lan-53992-1398682968504-0-3, CamelCxfMessage={org.apache.cxf.client=true, org.apache.cxf.message.inbound=true, org.apache.cxf.message.Message.PROTOCOL_HEADERS={content-type=[text/xml;charset=UTF-8], Server=[Jetty(7.6.7.v20120910)], transfer-encoding=[chunked]}, Content-Type=text/xml;charset=UTF-8, org.apache.cxf.transport.Conduit=conduit: class org.apache.cxf.transport.http.URLConnectionHTTPConduit2125068082target: http://localhost:8181/cxf/webservice, org.apache.cxf.ws.policy.AssertionInfoMap={}, org.apache.cxf.binding.soap.SoapVersion=org.apache.cxf.binding.soap.Soap11@48a43495, org.apache.cxf.message.Message.RESPONSE_CODE=200, org.apache.cxf.message.Message.ENCODING=UTF-8}, CamelFileAbsolute=false, CamelFileAbsolutePath=/Users/christopherrose/RedHat/SG Project/webservice-client/camel-wsclient/src/data/message2.xml, CamelFileLastModified=1398259868000, CamelFileLength=337, CamelFileName=message2.xml, CamelFileNameConsumed=message2.xml, CamelFileNameOnly=message2.xml, CamelFileParent=src/data, CamelFilePath=src/data/message2.xml, CamelFileRelativePath=message2.xml, CamelRedelivered=false, CamelRedeliveryCounter=0, content-type=text/xml;charset=UTF-8, ResponseContext={org.apache.cxf.client=true, org.apache.cxf.message.Message.PROTOCOL_HEADERS={content-type=[text/xml;charset=UTF-8], Server=[Jetty(7.6.7.v20120910)], transfer-encoding=[chunked]}, org.apache.cxf.message.inbound=true, Content-Type=text/xml;charset=UTF-8, org.apache.cxf.message.Message.ENCODING=UTF-8, org.apache.cxf.message.Message.RESPONSE_CODE=200, org.apache.cxf.binding.soap.SoapVersion=org.apache.cxf.binding.soap.Soap11@48a43495, org.apache.cxf.ws.policy.AssertionInfoMap={}, org.apache.cxf.transport.Conduit=conduit: class org.apache.cxf.transport.http.URLConnectionHTTPConduit2125068082target: http://localhost:8181/cxf/webservice}, Server=Jetty(7.6.7.v20120910), transfer-encoding=chunked}
BodyType            sun.net.www.protocol.http.HttpURLConnection.HttpInputStream
Body                [Body is instance of java.io.InputStream]

]

Stacktrace

org.apache.camel.component.file.GenericFileOperationFailedException: Cannot store file: src/data/responses/message2.xml
at org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:269)
at         org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer.java:277)
at org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:165)
at org.apache.camel.component.file.GenericFileProducer.process(GenericFileProducer.java:79)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:113)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
at org.apache.camel.processor.Pipeline.access$100(Pipeline.java:43)
at org.apache.camel.processor.Pipeline$1.done(Pipeline.java:136)
at org.apache.camel.processor.CamelInternalProcessor$InternalCallback.done(CamelInternalProcessor.java:251)
at org.apache.camel.processor.RedeliveryErrorHandler$1.done(RedeliveryErrorHandler.java:410)
at org.apache.camel.management.InstrumentationProcessor$1.done(InstrumentationProcessor.java:81)
at org.apache.camel.processor.SendProcessor$1.done(SendProcessor.java:123)
at org.apache.camel.component.cxf.CxfClientCallback.handleResponse(CxfClientCallback.java:63)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:856)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1614)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream$1.run(HTTPConduit.java:1129)
at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:428)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:353)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.io.IOException: stream is closed
at sun.net.www.http.ChunkedInputStream.ensureOpen(ChunkedInputStream.java:174)
at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:673)
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3053)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3047)
at org.apache.camel.component.file.FileOperations.writeFileByStream(FileOperations.java:375)
at org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:263)
... 24 more
[           default-workqueue-3] DefaultErrorHandler            ERROR Failed delivery for (MessageId: ID-christophersair-lan-53992-1398682968504-0-7 on ExchangeId: ID-christophersair-lan-53992-1398682968504-0-6). Exhausted after delivery attempt: 1 caught: org.apache.camel.component.file.GenericFileOperationFailedException: Cannot store file: src/data/responses/message3.xml

I am assuming that it maybe unable to retrieve the response and store it in a file or maybe there is something that all might be able to point me in the direction of?

Thanks for any help!

Was it helpful?

Solution

Using Camel v2.12.2, I did not get an exception, but the file was empty when logging the body content. This is as streams can only be read once, see here. Thus, remove the log after consuming the CXF webservice:

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="file:src/data?noop=true" />
        <log loggingLevel="INFO" message="${body}"/>
        <to uri="cxf://http://localhost:8181/cxf/webservice?wsdlURL=src/main/resources/META-INF/webservice.wsdl&amp;serviceName={http://carose.com/}EchoServiceImplService&amp;portName={http://carose.com/}EchoServiceImplPort&amp;dataFormat=MESSAGE"/>
        <!-- do not log the body or the file written will be empty
        <log loggingLevel="INFO" message="${body}"/>
        -->
        <to uri="file:src/data/responses?fileName=output.txt" />
    </route>
</camelContext>

Beside that, I added the fileName option in order to obtain a nice file name.

OTHER TIPS

I'm not sure if you message2.xml is call a one way service. Can you double check the message2.xml in your src/data directory? If it's one way message or an invalided soap request, you may not get a right input stream you want.

I think I have managed to fix it..

I thought it might have been due to the response not being cached or stored anywhere during the route, causing it to create the blank files (message1.xml, message2.xml and message3.xml). I found that there is a stream caching setting that you can set, so I turned that on and it is now creating all three files with the correct XML responses in. See my route XML below:

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route streamCache="true">
    <from uri="file:src/data?noop=true" />
    <log loggingLevel="INFO" message="${body}"/>
    <to uri="cxf://http://localhost:8181/cxf/webservice?wsdlURL=src/main/resources/META-INF/webservice.wsdl&amp;serviceName={http://carose.com/}EchoServiceImplService&amp;portName={http://carose.com/}EchoServiceImplPort&amp;dataFormat=MESSAGE"/>
    <log loggingLevel="INFO" message="${body}"/>
    <to uri="file:src/data/responses" />
</route>

Thanks for the suggestions :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top