首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >捕获apache骆驼路由cxf web响应

捕获apache骆驼路由cxf web响应
EN

Stack Overflow用户
提问于 2014-04-28 11:16:09
回答 3查看 3.9K关注 0票数 0

我对堆栈溢出和Apache路由很陌生,并且遇到了一些问题。我创建了一个非常简单的SOAP服务,它接受包含一些随机文本的XML请求,然后在响应中返回相同的字符串。

使用Camel,我可以将请求发送到web服务并获得响应(如果我使用日志组件来捕获请求/响应的话)。

理想情况下,我希望将XML消息(message1.xml、message2.xml、message3.xml)发送到webservice,然后处理它们并将响应存储在文件中:src/data/ responses /(message1.xml、message2.xml、message3.xml)等等。我认为这可能就像在我的路线上增加一个额外的步骤一样简单(见下文)。

代码语言:javascript
复制
<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>

但是,当我使用mvn camel:run运行路由时,它会在/responses/文件夹中为每条消息创建一个空白的XML文件。执行路由时会显示下列错误消息:

代码语言:javascript
复制
[           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

讯息历史

代码语言:javascript
复制
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]

交换

代码语言:javascript
复制
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]

]

斯塔克迹

代码语言:javascript
复制
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

我假设它可能无法检索响应并将其存储在一个文件中,或者可能所有的东西都可以指向我的方向?

谢谢你的帮助!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-04-28 12:35:04

使用Camel v2.12.2,我没有得到异常,但是在记录body内容时文件是空的。这是因为流只能读取一次,请参阅here。因此,在使用CXF CXF服务之后删除日志:

代码语言:javascript
复制
<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>

除此之外,我还添加了fileName选项,以获得一个很好的文件名。

票数 0
EN

Stack Overflow用户

发布于 2014-04-28 12:32:47

我不确定message2.xml是否调用单向服务。您能再次检查src/data目录中的message2.xml吗?如果是单向消息或无效的soap请求,则可能无法获得所需的正确输入流。

票数 0
EN

Stack Overflow用户

发布于 2014-04-29 09:46:25

我想我已经修好了..。

我认为这可能是由于响应在路由过程中没有被缓存或存储,导致它创建空白文件(message1.xml、message2.xml和message3.xml)。我发现有一个可以设置的流缓存设置,所以我打开了它,它现在使用正确的XML响应来创建所有三个文件。请参见下面的路径XML:

代码语言:javascript
复制
<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>

谢谢你的建议:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23339650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档