Announcement Announcement Module
Collapse
No announcement yet.
HTTP-Outbound gateway not showing special characters -encoding breaks Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Were you also using the "iso-8859-1" charset (as specified in your gateway config) when testing in isolation with the URLconnection?

    Comment


    • #3
      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.

      Comment


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

        Comment


        • #5
          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"

          Comment


          • #6
            OK, i'll give it a shot

            Comment


            • #7
              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?

              Comment


              • #8
                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.

                Comment


                • #9
                  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

                  Comment

                  Working...
                  X