Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8190836

NPE on ExceptionBean when processing SOAP Fault

XMLWordPrintable

    • b01
    • x86_64
    • windows_7

        FULL PRODUCT VERSION :
        d:\Fusion\test\ionBaseApp\ionTest>d:\Java\jdk1.7.0_161\bin\java -version
        java version "1.7.0_161"
        Java(TM) SE Runtime Environment (build 1.7.0_161-b13)
        Java HotSpot(TM) 64-Bit Server VM (build 24.161-b13, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        All OSs

        A DESCRIPTION OF THE PROBLEM :
        The response of a web service is as below... This is a web service created on Oracle SOA Suite in BPEL...

        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
           <soap:Body xmlns:tns="http://www.esri.com/schemas/ArcGIS/10.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
              <tns:Fault xmlns:my="urn:myNamespace" xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/">
                 <faultcode>tns:Client</faultcode>
                 <faultstring>Not found - parcel_key = 283458</faultstring>
                 <detail>
                    <exception>this is my exception</exception>
                 </detail>
              </tns:Fault>
           </soap:Body>
        </soapenv:Envelope>

        When processing SOAPFault JDK 1.7 fails with NPE... the NPE is unexpected...

        d:\Fusion\test\ionBaseApp\ionTest>d:\Java\jdk1.7.0_161\bin\java -cp classes cogc.test.Class1
        Exception in thread "main" javax.xml.ws.WebServiceException: java.lang.NullPointerException
                at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.doInvoke(DispatchImpl.java:196)
                at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.invoke(DispatchImpl.java:203)
                at cogc.test.Class1.main(Class1.java:94)
        Caused by: java.lang.NullPointerException
                at com.sun.xml.internal.ws.fault.ExceptionBean.isStackTraceXml(ExceptionBean.java:166)
                at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.attachServerException(SOAPFaultBuilder.java:276)
                at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:117)
                at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.doInvoke(DispatchImpl.java:184)
                ... 2 more


        Results for JDK 1.8 are as expected...

        d:\Fusion\test\ionBaseApp\ionTest>d:\Java\jdk1.8.0\bin\java -cp classes cogc.test.Class1
        Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Not found - parcel_key = 283458 Please see the server log to find more detail regarding exact cause of the failure.
                at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
                at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:116)
                at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.doInvoke(DispatchImpl.java:259)
                at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.invoke(DispatchImpl.java:289)
                at cogc.test.Class1.main(Class1.java:94)


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run test class against a web service that produces results as below...

        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
           <soap:Body xmlns:tns="http://www.esri.com/schemas/ArcGIS/10.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
              <tns:Fault xmlns:my="urn:myNamespace" xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/">
                 <faultcode>tns:Client</faultcode>
                 <faultstring>Not found - parcel_key = 283458</faultstring>
                 <detail>
                    <exception>this is my exception</exception>
                 </detail>
              </tns:Fault>
           </soap:Body>
        </soapenv:Envelope>


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Results for JDK 1.8 are as expected...

        d:\Fusion\test\ionBaseApp\ionTest>d:\Java\jdk1.8.0\bin\java -cp classes cogc.test.Class1
        Exception in thread "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Not found - parcel_key = 283458 Please see the server log to find more detail regarding exact cause of the failure.
                at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
                at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:116)
                at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.doInvoke(DispatchImpl.java:259)
                at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.invoke(DispatchImpl.java:289)
                at cogc.test.Class1.main(Class1.java:94)

        ACTUAL -
        The NPE is unexpected....

        d:\Fusion\test\ionBaseApp\ionTest>d:\Java\jdk1.7.0_161\bin\java -cp classes cogc.test.Class1
        Exception in thread "main" javax.xml.ws.WebServiceException: java.lang.NullPointerException
                at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.doInvoke(DispatchImpl.java:196)
                at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.invoke(DispatchImpl.java:203)
                at cogc.test.Class1.main(Class1.java:94)
        Caused by: java.lang.NullPointerException
                at com.sun.xml.internal.ws.fault.ExceptionBean.isStackTraceXml(ExceptionBean.java:166)
                at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.attachServerException(SOAPFaultBuilder.java:276)
                at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:117)
                at com.sun.xml.internal.ws.client.dispatch.DispatchImpl.doInvoke(DispatchImpl.java:184)
                ... 2 more



        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        package cogc.test;

        import java.io.File;

        import java.io.IOException;

        import java.io.StringWriter;

        import javax.xml.namespace.QName;
        import javax.xml.parsers.DocumentBuilder;
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.ParserConfigurationException;
        import javax.xml.soap.MessageFactory;
        import javax.xml.soap.SOAPBody;
        import javax.xml.soap.SOAPConstants;
        import javax.xml.soap.SOAPHeader;
        import javax.xml.soap.SOAPMessage;
        import javax.xml.transform.OutputKeys;
        import javax.xml.transform.Transformer;
        import javax.xml.transform.TransformerConfigurationException;
        import javax.xml.transform.TransformerException;
        import javax.xml.transform.TransformerFactory;
        import javax.xml.transform.dom.DOMSource;
        import javax.xml.transform.stream.StreamResult;
        import javax.xml.ws.Dispatch;
        import javax.xml.ws.Service;
        import javax.xml.ws.soap.SOAPBinding;

        import org.w3c.dom.Document;
        import org.w3c.dom.Node;
        import org.w3c.dom.NodeList;

        import org.xml.sax.SAXException;

        public class Class1 {

            public static void main(String[] args) throws Exception {

                //String endpointUrl = "http://msvfusd1:6011/LgpCustomerRequest/SendCustomerRequestProxy";
                String endpointUrl = "http://msvfusd1:6011/LgpCustomerRequest/RetrieveParcelCentroidProxy";
                //String endpointUrl = "file://response.xml";

                QName serviceName = new QName("urn:LgpCustomerRequests", "SendCustomerRequestService");
                QName portName = new QName("urn:LgpCustomerRequests", "SendCustomerRequestPort");

                /** Create a service and add at least one port to it. **/
                Service service = Service.create(serviceName);
                service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointUrl);

                /** Create a Dispatch instance from a service.**/
                Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);

                /** Create SOAPMessage request. **/
                // compose a request message
                MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);

                SOAPMessage request;
                SOAPMessage reply;

                Node envelope = readXml().getFirstChild();

                Node header = null;
                Node body = null;
                for (Node child = envelope.getFirstChild(); child != null; child = child.getNextSibling()) {
                    if (child.getNodeType() != 1)
                        continue;
                    if (child.getLocalName().equals("Header"))
                        header = child;
                    if (child.getLocalName().equals("Body"))
                        body = child;
                }

                if (body == null)
                    throw new Exception("Soap envelope does not contain a body");
                request = factory.createMessage();
                if (header != null) {
                    SOAPHeader soapHeader = request.getSOAPHeader();
                    NodeList headerChildren = header.getChildNodes();
                    for (int i = 0; i < headerChildren.getLength(); i++) {
                        Node headerChild = headerChildren.item(i);
                        Node importedChild = soapHeader.getOwnerDocument().importNode(headerChild, true);
                        soapHeader.appendChild(importedChild);
                    }

                }
                SOAPBody soapBody = request.getSOAPBody();
                NodeList bodyChildren = body.getChildNodes();
                for (int i = 0; i < bodyChildren.getLength(); i++) {
                    Node bodyChild = bodyChildren.item(i);
                    Node importedChild = soapBody.getOwnerDocument().importNode(bodyChild, true);
                    soapBody.appendChild(importedChild);
                }

                reply = (SOAPMessage) dispatch.invoke(request);

                SOAPBody responseBody = reply.getSOAPBody();
                Node response = responseBody.getParentNode();

                System.out.println(serialize(response));

            }

            public static Node readXml() throws ParserConfigurationException, SAXException, IOException {
                File fXmlFile = new File("centroid.xml");
                DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                dbFactory.setNamespaceAware(true);
                DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                Document doc = dBuilder.parse(fXmlFile);
                return doc;
            }

            public static String serialize(Node node) throws TransformerConfigurationException, TransformerException {
                TransformerFactory tf = TransformerFactory.newInstance();

                Transformer transformer = tf.newTransformer();
                transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

                StringWriter writer = new StringWriter();
                transformer.transform(new DOMSource(node), new StreamResult(writer));

                String output = writer.getBuffer().toString();

                return output;
            }

        }

        ---------- END SOURCE ----------

        SUPPORT :
        YES

              aefimov Aleksej Efimov
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: