我正在尝试使用Apache Camel Jetty Component创建HTTP代理服务器。以下是我的代码 -
from("jetty:http://localhost:8080?matchOnUriPrefix=true")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
HttpServletRequest req = exchange.getIn().getBody(
HttpServletRequest.class);
Enumeration<String> headers = request.getHeaderNames();
while (headers.hasMoreElements()) {
String headerName = headers.nextElement();
String headerValue = request.getHeader(headerName);
}
InputStream stream = request.getInputStream();
int bytesRead;
String line = "";
byte b[] = new byte[1024];
while ((bytesRead = stream.read(b)) != -1) {
line = line + new String(b, 0, bytesRead);
}
})
.to("http://www.google.com:80?bridgeEndpoint=true&throwExceptionOnFailure=false")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
HttpServletResponse res = exchange.getIn().getBody(
HttpServletResponse.class);
});
我能够读取HttpServletRequest标头和数据。但是,我无法读取HttpServletResponse数据,因为HttpServletResponse中没有getInputStream()方法。我发现了一些与此问题相关的帖子,但是他们说要么必须子类化HttpServletResponse,要么创建一个过滤器。但是在apache camel中,我没有直接与HttpServletResponse类进行交互,所以我可以如何对它进行子类化或创建过滤器
请帮我解决这个问题。