2015-09-30 82 views
0

我发送请求的servlet,类似的的OutputStream /的SOAPMessage要HTTP邮政与Apache骆驼

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); 

现在我想开发http客户端在Apache的骆驼后像下面

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 [email protected]42a6d5a 
    at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:177) 
    at org.apache.camel.component.jetty.JettyHttpProducer.processInternal(JettyHttpProducer.java:166) 
+0

你至今尝试过什么?你有没有把你的肥皂信息放进交换机构并试图发送它?你面临什么问题? –

+0

发布更新,我发现没有类型的转换器可用 – ImranRazaKhan

回答

0

正如错误消息所述。骆驼不知道如何解析/转换为您正在使用的肥皂格式。它需要一个类型转换器来完成。 http://camel.apache.org/type-converter.html 您可以使用自己的如图所示DOC:

Message message = exchange.getIn(); 
Document document = message.getBody(Document.class); 

或者使用整件事转换为字符串只是测试的路线本身的工作原理。

但是,由于您试图解析XML,所以您应该将消息解组为SOAP。在这里看到:

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

从文档:http://camel.apache.org/soap.html