1 Reply Latest reply on Mar 20, 2013 12:59 PM by rukbat

    Problem when parsing response of SOAP call in Weblogic

      Hello everybody,

      We are in the process of migrating functionality from a Weblogic Server *8,1 sp5* with java 1.4 to *10.3.6* with java 1.7.

      The case that is described below is working properly in the old server, however we are facing an issue when transferring the handling to the new one.
      The problem lies while retrieving and parsing an XML response that was retrieved from an external system through SOAP calls.

      The following libraries and procedure are used in the method:

      java.net.HttpURLConnection to make the connection
      java.io.OutputStream to send the request
      java.io.InputStream to get the response
      byte[] to store the result before transforming in to String
      javax.xml.parsers.DocumentBuilder, java.io.StringReader and org.xml.sax.InputSource to transform the String into org.w3c.dom.Document

      Then the following exception is thrown:
      *"org.xml.sax.SAXParseException - Content is not allowed in trailing section."*

      When opening the logs of the application with notepad++ many null characters appear after the end of the file which seem to cause the issue. I repeat that no such cases appear when executing the request from the old server.

      The respective code is the following:

           //Creating the connection
           URL u = new URL(default_server);
           URLConnection uc = u.openConnection();
           HttpURLConnection connection = (HttpURLConnection) uc;

           connection.setRequestProperty("SOAPAction", soap_action);

           OutputStream out = connection.getOutputStream();
           Writer wout = new OutputStreamWriter(out);


           InputStream in = connection.getInputStream();

           int c = in.available();
           byte r[] = new byte[c];
           String response = new String(r);
           //Transorming the String to XML Doc
           DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
           DocumentBuilder builder = factory.newDocumentBuilder();
           StringReader theReader = new StringReader(response);
           InputSource theInputSource = new InputSource();
           Document doc = builder.parse(theInputSource); //Here occurs org.xml.sax.SAXParseException - Content is not allowed in trailing section.

           return doc;

      I know that i can solve the issue by getting the stripping the response from junk characters but this not a safe resolution.
      Do you have any information to share on the matter? Do you think it is a java version issue or maybe a server configuration issue?
      Thank you in advance your time.

      Best Regards,

      Edited by: 995036 on Mar 20, 2013 6:12 AM