1
私はCamelで長時間実行されていますが、これはHTTPリクエストによって起動されます。 StatusstreamをOutputstreamに書きたいのですが、クライアントサイドでレスポンスを取得できません。Camel JettyコンポーネントOutputstreamへの書き込み
キャメル-ルート:
<from uri="jetty:http://localhost:12345/myservice"/>
<process ref="test" />
プロセッサテスト:
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");
}
、呼び出しコード:
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();
しかし、私
は、私は次のように使用してみました私は応答を取得する本体(コメント行)に本文を設定します。ラクダのつながりを保ち、それに続けて書く方法はありますか? Exchange
からHttpServletResponse
を記入し、
arg0.getOut().setBody("This might also be a response");
HTTPコンポーネントがExchange
にHttpServletRequest
を変換するHttpBinding
を使用し、反対: