3 Replies Latest reply on Dec 12, 2010 12:45 PM by chungyeung

    ProducerTemplate encoding

    chungyeung

      Hi,

       

      Can somebody tell me how I can set the encoding to "ISO-8859-1" when I use producer template to fetch data from a servlet with the following code?

       

      ProducerTemplate template;

       

      String output = template.requestBodyAndHeaders("http://sev64:8080//TestServlet/XMLHandler", null, headers, String.class);

       

      In the servlet, I used

       

      response.setCharacterEncoding("ISO-8859-1");

       

      and it works if I use other mechanism to get the response.  It just does not work using the template.

       

      Thanks for helping.

        • 1. Re: ProducerTemplate encoding
          njiang

          You just need set the exchange property for the encoding like this

          exchange.setProperty(Exchange.CHARSET_NAME, "ISO-8859-1");
          

          But you may need to use the template send() method to send the request, and extract the response yourself.

          • 2. Re: ProducerTemplate encoding
            chungyeung

            Hi njiang,

             

            Thanks for the reply but I failed to extract the response from a template send() method.  I tried various methods like:

             

            Exchange outExchg = template.send(endpoint, exchg);

             

            but the outExchg does not contain any response data.  I would be grateful if you could post an example.

            • 3. Re: ProducerTemplate encoding
              chungyeung

              Sorry njiang!  It actually works.  Thanks.