문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top