根本不发送响应头

时间:2013-05-28 13:37:11

标签: tomcat jetty apache-camel response-headers

我有一个由Apache Camel支持的小型Java Web应用程序。它使用Camel的servlet组件。此应用程序用于连接器和从设备接收数据。

就我们支付流量而言,如果有办法拒绝来自网络服务器的所有响应标头并仅发送状态代码,我会感兴趣。

更新

from("servlet:///channel?servletName=ChannelServlet")

...

.split().method("objectSplitter", "splitRootObject")
.log("before removeHeaders")
.removeHeaders("*")
.log("after removeHeaders")
.process(new Processor() {

    @Override
    public void process(Exchange exchange) throws Exception {
        Message out = exchange.getOut();
        out.removeHeaders("*");
        out.setHeader("custom", "custom");
        out.setHeader(Exchange.HTTP_RESPONSE_CODE, "200");
        out.setBody("");
        LOG.debug("In processor");
    }
});

我一直在接受:

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Host: localhost:8080
charset: utf-8
breadcrumbId: ID-eclipse-46977-1369749855622-0-2
User-Agent: Java/1.7.0_21
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type: application/octet-stream
Server: Jetty(7.6.8.v20121106)

在堆栈跟踪结束时:

[          http-bio-9080-exec-5] route1                         INFO  before removeHeaders
[          http-bio-9080-exec-5] Tracer                         INFO  ID-eclipse-43869-1369751726247-0-12 >>> (route1) log[before removeHeaders] --> removeHeaders[*] <<< Pattern:InOut, Headers:{frame=0, imei=393090335172229, type=SdkMsgFrame, genTime=0, breadcrumbId=ID-eclipse-43869-1369751726247-0-11, key=2aa4678e-2eb8-42c2-9b59-2e816c276cd5, numFrames=1}, BodyType:String, Body:eNo1...Q1GJ+
[          http-bio-9080-exec-5] Tracer                         INFO  ID-eclipse-43869-1369751726247-0-12 >>> (route1) removeHeaders[*] --> log[after removeHeaders] <<< Pattern:InOut, BodyType:String, Body:eNo1...Q1GJ+
[          http-bio-9080-exec-5] route1                         INFO  after removeHeaders
[          http-bio-9080-exec-5] Tracer                         INFO  ID-eclipse-43869-1369751726247-0-12 >>> (route1) log[after removeHeaders] --> com.succorfish.harbour.http.route.ServletRoute$1@17968bee <<< Pattern:InOut, BodyType:String, Body:eNo1...Q1GJ+
[          http-bio-9080-exec-5] ServletRoute                   DEBUG In processor
[          http-bio-9080-exec-5] MulticastProcessor             DEBUG Done sequential processing 1 exchanges

2 个答案:

答案 0 :(得分:1)

您可以告诉Camel删除路径末尾的所有标头。然后响应没有任何标题。

from("jetty:...")
   ...
   .removeHeaders("*");

还可以看到其中一些页面

答案 1 :(得分:0)

这个问题的最终答案是你可以从Camel中删除大部分标题,但Tomcat / Jetty无论如何都会追加其中的一些标题。我得到的最小标题是:

Date: Thu, 30 May 2013 09:49:30 GMT
Transfer-Encoding: chunked
Content-Length: 0
Server: Apache-Coyote/1.1

在我的情况下,这仍然是不可接受的,因此我将使用Apache Mina和UDP / TCP而不是HTTP。