Results 1 to 9 of 9

Thread: HTTP-Outbound gateway not showing special characters -encoding breaks

  1. #1
    Join Date
    Jan 2012
    Posts
    5

    Default HTTP-Outbound gateway not showing special characters -encoding breaks

    We have a client which uses http-outboundgateway to place REST calls
    Code:
    	<int-http:outbound-gateway request-channel="glNewsRequestChannel"
    		url="${gl.url}" http-method="GET" expected-response-type="java.lang.String"
    		reply-channel="glHeaderEnricher" charset="iso-8859-1">
    		<int-http:uri-variable name="site_code"
    			expression="payload" />
    	</int-http:outbound-gateway>
    When response is fetched and saved logged in a file, it shows some jumbled character -which is basically unable to translate in specific encoding.
    I referred SI documentation which mention unless a factory is specified Java URLconnection class is used to place REST call.
    To narrow down the issue, I wrote a small Java program and used the URLconnection class directly without using any out of box template or gateway -it successfully fetches and renders all the special character. I tried another standalone app which apache http library and it was also able to fetch the character.
    Any configuration which I am missing as part of SI ?

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,841

    Default

    Were you also using the "iso-8859-1" charset (as specified in your gateway config) when testing in isolation with the URLconnection?

  3. #3
    Join Date
    Jan 2012
    Posts
    5

    Default

    Thanks Mark for quick reply, yes while testing in isolation I tested it with and without that. In both cases I get the same result.
    Similarly even if i remove the charset parameter from the gateway config -it does not have any impact.

  4. #4
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Can you please provide the test case of this in isolation and a sample String containing the characters in question?

  5. #5
    Join Date
    Jan 2012
    Posts
    5

    Default

    Standalone code with URLconnection:
    Code:
    		   BufferedReader reader = null;
    		  try {
    			  URLConnection connection = new URL(url).openConnection();
    			  connection.setRequestProperty("Accept-Charset",  "iso-8859-1");
    			  InputStream responseBody = connection.getInputStream();
    			    try {
    			        reader = new BufferedReader(new InputStreamReader(responseBody));
    			        for (String line; (line = reader.readLine()) != null;) {
    			            LOGGER.debug(line);
    			        }
    			    } finally {
    			        if (reader != null) 
    			        	try { 
    			        		reader.close(); 
    			        	}catch (IOException logOrIgnore) {}
    			    }
    			  
    		} catch (MalformedURLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} 
    	  }
    I cannot post the external URL, but following is the String as logged by Spring Integration -
    Code:
    <p>OAKLAND, Calif. – The champagne was returned to storage. Reams of plastic taped onto the lockers as protection were rolled up and stuffed into the equipment manager's office.</p>
    Notice the jumbled character -if same string is fetched using the Java class it renders as
    Code:
    OAKLAND, Calif. – The champagne was returned to storage. Reams of plastic taped onto the lockers as protection were rolled up and stuffed into the equipment manager's office
    From the isolated code, even if I remove the charset stuff -it just works fine. Charset has been set based on encoding we get in headers "Content-Type: text/html; charset=iso-8859-1"

  6. #6
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    OK, i'll give it a shot

  7. #7
    Join Date
    Jan 2012
    Posts
    5

    Default

    Quote Originally Posted by oleg.zhurakousky View Post
    OK, i'll give it a shot
    Hi Oleg, Any update? Did u get a chance to try it out? Is there any configuration part which I am missing?

  8. #8
    Join Date
    Jan 2012
    Posts
    5

    Default

    Further investigation revealed that we were using wrong message converter -Instead of using String converter if we use byte[], in accordance to bytearraymessageconverter -it works as expected.

  9. #9
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Sorry for not getting back to you sooner (SpringOne preparations http://www.springone2gx.com/conferen...n/2012/10/home), but I am glad it all worked out

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •