Results 1 to 2 of 2
  1. #1
    mosini is offline Member
    Join Date
    Dec 2014
    Posts
    2
    Rep Power
    0

    Default Tomcat 7.0 HTTP post request utf-8 issues with windows server 2008 R2

    I have a very strange issue, I have a web app (JSP file) on Tomcat 7.0 instance. I can't figure out why it is not sending POST UTF-8 request correctly. I have installed it on windows server 2008 R2. I have configured all those needed settings in server.xml and web.xml, such as URIEncoding=UTF-8 for tags and setting filter in web.xml.

    inside my JSP, I am calling a .Net web service which accepts POST method:
    Java Code:
    private String urlcallPOST(String content){
        String result="";
        try
    {
    String urlParameters =  "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"+
    "<SOAP-ENV:Envelope"+
    "    xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\""+
    "    xmlns:ns1=\"http://tempuri.org/\">"+
    "    <SOAP-ENV:Body>"+
    "        <ns1:Message>"+
    "            <ns1:contentList>"+
    "                <ns1:string>"+content+"</ns1:string>"+
    "            </ns1:contentList>"+
    "        </ns1:Message>" +
    "    </SOAP-ENV:Body>" +
    "</SOAP-ENV:Envelope>";
    
    
    URL url = new URL("http://theIP/webservice.asmx"); 
    URLConnection connection =  url.openConnection();          
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestProperty("Content-Type","text/xml; charset=utf-8");
    connection.setRequestProperty("SOAPAction", "\"http://tempuri.org/Message\"");
    
    byte[] buf = urlParameters.getBytes();
    DataOutputStream os = new DataOutputStream(connection.getOutputStream());
    os.write(buf, 0, buf.length);
    
    
    BufferedReader reader = new BufferedReader(new    InputStreamReader(connection.getInputStream()));
    String line = null;
    while ((line = reader.readLine()) != null) {
        System.out.println(line);
    }
    
    reader.close();
    os.close();
    }
    
    catch(Exception e)
    {
    }
    
    
     return result;
    }
    I have used meta tag and defined charset=utf-8 and also used:

    request.setCharacterEncoding("UTF-8");
    before any request. I have created one folder called GetMine inside webapps inside tomcat 7.0.57. and copied this jsp file there. When I call the urlCallPOST method with content="some utf-8 Arabic text" it shows ???? inside Tomcat's log folder in stdout file.

    The Strange point is that when I create a java project(NOT j2ee or static web) inside ECLIPSE and call urlcallPOST. It works fine.

    When I saw the result from ECLIPSE was fine, decided to install WireShark packet capture tool and check the result and was surprised that when executing code from ECLIPSE, wireshark was showing those Arabic characters in this format: \330\263\330\264 etc. and webservice also returns correct response. but When checked from my JSP executing it, the wireshark was showing those Arabic characters in this format: ?????

    I googled and find this website showing these Arabic encoding: Dynamic charset converter ? interactive conversion tables to compare 8-bits character sets viewing their unicode names and binary, octal, decimal, hexadecimal and UTF-8 values

    I tried hard-coding \330\263\330\264 inside the content tag of my urlCallPOST method, but still it doesn't show correct characters (some characters were showing correctly!!!!)

    What should I do? Is this something wrong/bug with windows server 2008 R2's encoding? I have this exact configuration within Solaris and JBOSS tomcat and it is working fine.

  2. #2
    mosini is offline Member
    Join Date
    Dec 2014
    Posts
    2
    Rep Power
    0

    Cool Re: Tomcat 7.0 HTTP post request utf-8 issues with windows server 2008 R2

    Quote Originally Posted by mosini View Post
    I have a very strange issue, I have a web app (JSP file) on Tomcat 7.0 instance. I can't figure out why it is not sending POST UTF-8 request correctly. I have installed it on windows server 2008 R2. I have configured all those needed settings in server.xml and web.xml, such as URIEncoding=UTF-8 for tags and setting filter in web.xml.

    What should I do? Is this something wrong/bug with windows server 2008 R2's encoding? I have this exact configuration within Solaris and JBOSS tomcat and it is working fine.
    Finally I find the solution.
    You need to add just a little config within tomcat's configuration:
    add "-Dfile.encoding=UTF-8" and that's all. See the picture below.
    Tomcat 7.0 HTTP post request utf-8 issues with windows server 2008 R2-tomcat.jpgClick image for larger version. 

Name:	tomcat.jpg 
Views:	8 
Size:	59.2 KB 
ID:	6758

    further more, you may want to add URIEncoding=UTF-8 within your server.xml file.
    Tomcat 7.0 HTTP post request utf-8 issues with windows server 2008 R2-uri.png

Similar Threads

  1. HTTP POST request using JSON
    By blertadhimitri in forum New To Java
    Replies: 8
    Last Post: 12-20-2013, 12:01 PM
  2. Configuring Tomcat 7 with SQL SERVER 2008
    By madhav.dubey9 in forum New To Java
    Replies: 0
    Last Post: 06-26-2013, 02:13 PM
  3. HTTP POST Request (HttpURLConnection)
    By Dude in forum Networking
    Replies: 17
    Last Post: 07-15-2011, 11:11 PM
  4. 64 bit java on Windows Server 2008 Enterprise SP2?
    By darrens in forum New To Java
    Replies: 1
    Last Post: 07-06-2011, 07:51 PM
  5. HTTP Post Request from Java
    By Darrarski in forum New To Java
    Replies: 10
    Last Post: 06-05-2010, 05:22 PM

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
  •