Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Apache Camel将OutputStream/soapmessage输出到HTTP Post_Java_Servlets_Post_Apache Camel - Fatal编程技术网

Java 使用Apache Camel将OutputStream/soapmessage输出到HTTP Post

Java 使用Apache Camel将OutputStream/soapmessage输出到HTTP Post,java,servlets,post,apache-camel,Java,Servlets,Post,Apache Camel,我正在向servlet发送请求,该servlet处理数据如下 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Decode incoming SOAP message InputStream in = req.getInputStream(); ... 下面是我将流发布到servlet的

我正在向servlet发送请求,该servlet处理数据如下

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 
      // Decode incoming SOAP message 
      InputStream in = req.getInputStream(); 
...
下面是我将流发布到servlet的客户机代码

SOAPMessage soapMessage = messageFactory.createMessage(); 
    ... 
OutputStream out = httpUrlConnection.getOutputStream(); 
soapMessage.writeTo(out); 
现在我想在ApacheCamel中开发http客户端,如下所示

from("timer:foo?period=5s") 
    .process(   new Processor() {
               public void process(Exchange exchange) throws Exception {       
                                            ... 
                   exchange.getOut().setHeader(Exchange.HTTP_METHOD,"POST"); 
                   exchange.getOut().setBody( soapMessage ); 
               } }) 
    .to("jetty:http://localhost:8180/app/sendStream"); 
编辑: 我试图运行上面的代码并面临以下错误

org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl to the required type: java.io.InputStream with value com.sun.xml.internal.messaging.saaj.soap.ver1_1.Message1_1Impl@342a6d5a
   at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:177)
   at org.apache.camel.component.jetty.JettyHttpProducer.processInternal(JettyHttpProducer.java:166)

正如错误消息所说。camel不知道如何解析/转换为您正在使用的soap格式。这样做需要一个类型转换器。 您可以使用自己的,如文档所示:

Message message = exchange.getIn();
Document document = message.getBody(Document.class);
或者使用将整个内容转换为字符串来测试路由本身是否工作

然而,由于您正试图解析SOAP(即XML),因此应该将消息解组到SOAP。请看这里:

SoapJaxbDataFormat soap = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
from("direct:start")
  .marshal(soap)
  .to("jms:myQueue")

从文档中可以看到:

到目前为止您都尝试了什么?您是否已将soap消息放入exchange正文并尝试发送它?您遇到了什么问题?更新后,我发现没有可用的类型转换器