2016-03-31 34 views
1

Camel'de, bir HTTP-İstekiyle tetiklenen uzun bir işlem sürem var. Çıktı Akışı'na Durum Güncellemeleri yazmak istiyorum, ancak Müşteri Tarafındaki Yanıtı alamıyorum.Camel Jetty Bileşeni Outputstream'e yazdı

Deve-Rota:

<from uri="jetty:http://localhost:12345/myservice"/> 
<process ref="test" /> 

İşlemci Testi:

public void process(Exchange arg0) throws Exception { 
    System.out.println("TestProcessor"); 
    HttpServletResponse response = (HttpServletResponse) arg0.getIn().getHeader(Exchange.HTTP_SERVLET_RESPONSE); 

    OutputStreamWriter wr = new OutputStreamWriter(response.getOutputStream()); 
    BufferedWriter w = new BufferedWriter(wr); 
    for(int x = 0; x < 10; x++){ 
     w.write("Zeile: " + x + "\n"); 
     w.newLine(); 
    } 
//  arg0.getIn().setBody("This might also be a response"); 
} 

Ve Arama Kodu:

final HttpURLConnection conn = (HttpURLConnection) url.openConnection();   
      conn.setDoOutput(true); 
      conn.setInstanceFollowRedirects(false); 
      conn.setRequestMethod("GET"); 
      conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
      conn.setRequestProperty("charset", "utf-8"); 
      conn.setRequestProperty("Content-Length", Integer.toString(postDataLength)); 
      conn.setUseCaches(false); 
      new Thread(new Runnable(){ 

       @Override 
       public void run() { 
        try { 
         if(!urlParameters.isEmpty()){ 
          try(DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) { 
           wr.write(postData); 
           wr.close(); 
          } 
         } 
         InputStream s = conn.getInputStream(); 
         System.out.println("got InputStream"); 
         InputStreamReader is = new InputStreamReader(s); 
         BufferedReader br = new BufferedReader(is); 
         String line; 
         while((line = br.readLine()) != null){ 
          System.out.println("ReadLine: " + line); 
         } 

         conn.disconnect(); 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 
       } 

      }).start(); 

Ama i

Aşağıdaki kullanarak çalıştı sadece bir cevap al ben vücudu işlemciye (yorumlanan çizgi) ayarlayın. Bağlantıyı deve'de tutmanın ve ona yazmaya devam etmenin bir yolu var mı? Bir Exchange bir HttpServletResponse doldurmak,

arg0.getOut().setBody("This might also be a response"); 

HTTP Bileşen bir Exchange bir HttpServletRequest dönüştürmek için HttpBinding kullanın ve tersi:

cevap

0

HTTP Cihaznzla bir cevap göndermek için out mesajı kullanmalıdır . Varsayılan uygulamayı here görebilir veya kendiniz sağlayabilirsiniz.