2015-09-30 79 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