Reputation: 2087
I have tiny Java web application backed by Apache Camel. It uses Camel's servlet component. This application is meant to be connector and receive data from devices.
As far as we pay for traffic I am interesting if there is a way to deny all response headers from web server and send only status code.
Update:
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");
}
});
I am always receiving:
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)
At the end of stacktrace:
[ 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
Upvotes: 0
Views: 2300
Reputation: 2087
The final answer to this question is that you can remove most of headers from Camel but Tomcat/Jetty will append some of them anyway. The smallest headers I have got were:
Date: Thu, 30 May 2013 09:49:30 GMT
Transfer-Encoding: chunked
Content-Length: 0
Server: Apache-Coyote/1.1
This is still unacceptable in my case, so I will use Apache Mina and UDP/TCP instead of HTTP.
Upvotes: 0
Reputation: 55760
You can tell Camel to remove all headers at the end of the route. Then the response dont have any headers.
from("jetty:...")
...
.removeHeaders("*");
See some of these pages also
Upvotes: 1