0

The route :

  from("direct:start")
  .setProperty(Exchange.CHARSET_NAME, constant("iso-8859-1"))
  .process(new Processor() {            
        @Override
        public void process(Exchange exchange) throws Exception {
          Message m = exchange.getOut();
          m.setBody(exchange.getIn().getBody());
          m.setHeader(Exchange.HTTP_METHOD, HttpMethods.POST);
          m.setHeader(Exchange.CONTENT_ENCODING, "gzip" );
          m.setHeader(Exchange.CONTENT_LENGTH, m.getBody(byte[].class).length );
          m.setHeader(HttpHeaders.CONTENT_TYPE, "application/xml");
          m.setHeader(Exchange.HTTP_CHARACTER_ENCODING, "iso-8859-1");
          m.setHeader(HttpHeaders.ACCEPT_ENCODING, "gzip, deflate");        
        }
    })
  .marshal().gzip()
  .to("http4://remote.com/path")
  .unmarshal().gzip();

What I am sending :

String body = "<?xmlversion=\"1.0\"encoding=\"ISO-8859-1\"?><theXml></theXml>";
producer.sendBody(body);

I am getting

HTTP operation failed invoking http://remote.com/path with statusCode: 411

What is missing/wrong with this route ?

EDIT

The correct route would be

  from("direct:start")
  .process(new Processor() {            
        @Override
        public void process(Exchange exchange) throws Exception {
          Message m = exchange.getOut();
          m.setBody(exchange.getIn().getBody());
          m.setHeader(Exchange.HTTP_METHOD, HttpMethods.POST);
          m.setHeader(Exchange.CONTENT_ENCODING, "gzip" );
          m.setHeader(Exchange.CONTENT_TYPE, "application/xml");        
        }
    })
  // http4 takes care of compressing/decompressing gzip
  .to("http4://remote.com/path")

But now I have another problem : the remote server does not handle "Transfer-Encoding: Chuncked" Which seems to be the default way camel-http4 does it. And i can't figure out how to turn Chunked off.

See next question How to turn off “Transfer-Encoding Chuncked” in Camel-http4?

Community
  • 1
  • 1
redben
  • 5,578
  • 5
  • 47
  • 63
  • Hmm. The HTTP status code is pretty clear -- the server is expecting a Content-Length header... but you are clearly setting one in the request. – Charles Jan 17 '13 at 00:48

1 Answers1

1

You are setting the content length from the length of the unencoded data. It should probably be the length of the transmitted data. Refer to this SO question: content-length when using http compression

By the way, do you really need to gzip with the data format? There is a Unit test in camel sending GZIPed data.

https://svn.apache.org/repos/asf/camel/trunk/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpCompressionTest.java

Community
  • 1
  • 1
Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84
  • You are right, it is not needed ! now it is ok but then I have found another problem... The remote server does not handle "Transfer-Encoding: chunked", but I can't figure out how to disable it in camel-http4 – redben Jan 17 '13 at 15:03