Results 1 to 3 of 3
  1. #1
    magesh_r is offline Member
    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Default CharConversionException during Servlet Post method - Need fix.

    XML request message using HTTP POST is received by the Servlet interface.
    While we are reading and trying to parse the InputStreamObject, we are getting the following error message.

    doPost java.io.CharConversionException: Characters larger than 4 bytes are not supported: byte 0x8e implies a length of more than 4 bytes
    It looks like we are receiving some invalid Non-ASCII characters in the XML message.

    The above error is thrown intermittently.
    Whenever we have this CharConversionException, the servlet gets corrupted and it impacts few good xml messages that follows after the error.

    I need to know the following:

    1. How to fix this exception and skip the bad message?
    2. Is it possible to log the entire xml message in the catch block, whenever we have this exception?
    NOTE: we tried different ways, not able to print the xml message, as the inputstream seems to be closed/null, when it reaches the catch block.

    Tried the below code , but the servlet process/thread hungs and throws the below error:
    Thread "WebContainer : 3" (00000028) has been active for 667781 milliseconds and may be hung. There is/are 1 thread(s) in total in the server that may be hung.

    Below is the code snippet:

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    response.setContentType("text/xml");
    request.setCharacterEncoding("ISO-8859-1");
    OutputStream out = response.getOutputStream();
    InputStream inputStream=null;
    InputStream inputStreamTemp=null;
    try {
    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload();

    // Parse the request
    FileItemIterator iter = null;
    iter = upload.getItemIterator(request);
    while (iter.hasNext()) {
    FileItemStream item = iter.next();
    String name = item.getFieldName();
    inputStream = item.openStream();
    inputStreamTemp=inputStream;
    // we are trying to process the input stream
    processXml(inputStream);
    }
    }

    catch(CharConversionException charConversionException){
    this.logger.error(charConversionException);
    if(inputStreamTemp !=null){
    logSlurp(inputStreamTemp,logger);
    }
    }

    private static void logSlurp(InputStream in, Log logger) throws IOException {
    StringBuffer out = new StringBuffer();

    byte[] b = new byte[in.available()];
    for (int n; (n = in.read(b)) != -1;) {
    out.append(new String(b, 0, n));
    }
    if (logger.isInfoEnabled()) {
    logger.info(out.toString());
    }


    }
    }

    Need any help to fix the issue we are facing? Issue of either fixing/overcoming the actual exception and printing out the entire xml message(bad one) in ours log
    during the catch block.

    Thanks a lot.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: CharConversionException during Servlet Post method - Need fix.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: CharConversionException during Servlet Post method - Need fix.

    Cross posted, also without code tags
    https://forums.oracle.com/forums/thr...readID=2504732

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. HTTP post to html servlet
    By Mith in forum Java Servlet
    Replies: 2
    Last Post: 10-23-2012, 08:32 PM
  2. Replies: 0
    Last Post: 09-17-2012, 08:10 AM
  3. Replies: 1
    Last Post: 08-23-2011, 11:19 AM
  4. Replies: 2
    Last Post: 10-28-2010, 03:55 PM
  5. Maximum size of POST to Servlet
    By Ward in forum Java Servlet
    Replies: 0
    Last Post: 03-04-2009, 11:35 AM

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
  •