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

Failed to handle specified exception thrown from WebMethod

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • tbd
    • 9
    • xml
    • None

      To reproduce this issue:
      1. wsgen -cp . wstest.FaultImpl against the following java file, please note, the issue will happen either when createSOAPFaultException or createSOAP12FaultException :
      package wstest;

      import javax.jws.WebMethod;
      import javax.jws.WebService;
      import javax.xml.namespace.QName;
      import javax.xml.soap.Detail;
      import javax.xml.soap.DetailEntry;
      import javax.xml.soap.Name;
      import javax.xml.soap.SOAPConstants;
      import javax.xml.soap.SOAPElement;
      import javax.xml.soap.SOAPException;
      import javax.xml.soap.SOAPFactory;
      import javax.xml.soap.SOAPFault;
      import javax.xml.ws.soap.SOAPFaultException;

      @WebService
      public class FaultImpl {
          @WebMethod
          public void test() throws SOAPException {
              throw createSOAPFaultException();
              // throw createSOAP12FaultException(null, "SOAPFaultException");
          }

          private SOAPFaultException createSOAPFaultException() throws SOAPException {

              String namespace = "http://faultservice.org/wsdl";
              SOAPFactory soapFactory = SOAPFactory.newInstance();
              Name name = soapFactory.createName("BasicFault", "ns0", namespace);
              Detail detail = soapFactory.createDetail();
              DetailEntry entry = detail.addDetailEntry(name);
              entry.addNamespaceDeclaration("ns0", namespace);
              entry.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
              entry.addNamespaceDeclaration("myenv", "http://schemas.xmlsoap.org/soap/envelope/");
              entry.addNamespaceDeclaration("myns", "http://myurri/tmp");
              Name attrName = soapFactory.createName("encodingStyle", "myenv",
                      "http://schemas.xmlsoap.org/soap/envelope/");
              entry.addAttribute(attrName, "http://schemas.xmlsoap.org/soap/encoding/");
              Name attrName2 = soapFactory.createName("myAttr", "myns", "http://myurri/tmp");
              entry.addAttribute(attrName2, "myvalue");
              SOAPElement child = entry.addChildElement("message");
              child.addTextNode("basic fault");

              Name name2 = soapFactory.createName("AdditionalElement", "ns0", namespace);
              DetailEntry entry2 = detail.addDetailEntry(name2);
              entry2.addNamespaceDeclaration("ns0", namespace);

              SOAPElement child2 = entry2.addChildElement("BOGUS");
              child2.addTextNode("2 text");

              QName qname = new QName("http://schemas.xmlsoap.org/soap/envelope/", "client");
              // printDetail(detail);
              SOAPFault sf = soapFactory.createFault("soap fault exception fault", qname);
              org.w3c.dom.Node n = sf.getOwnerDocument().importNode(detail, true);
              sf.appendChild(n);
              return new SOAPFaultException(sf);

          }

          private SOAPFaultException createSOAP12FaultException(QName subcode, String msg)
                  throws SOAPException {

              String namespace = "http://faultservice.org/wsdl";
              SOAPFactory soapFactory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
              Name name = soapFactory.createName("BasicFault", "ns0", namespace);
              Detail detail = soapFactory.createDetail();
              DetailEntry entry = detail.addDetailEntry(name);
              entry.addNamespaceDeclaration("ns0", namespace);
              entry.setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
              entry.addNamespaceDeclaration("myenv", "http://schemas.xmlsoap.org/soap/envelope/");
              entry.addNamespaceDeclaration("myns", "http://myurri/tmp");
              Name attrName = soapFactory.createName("encodingStyle", "myenv",
                      "http://schemas.xmlsoap.org/soap/envelope/");
              entry.addAttribute(attrName, "http://schemas.xmlsoap.org/soap/encoding/");
              Name attrName2 = soapFactory.createName("myAttr", "myns", "http://myurri/tmp");
              entry.addAttribute(attrName2, "myvalue");
              SOAPElement child = entry.addChildElement("message");
              child.addTextNode("basic fault");

              Name name2 = soapFactory.createName("AdditionalElement", "ns0", namespace);
              DetailEntry entry2 = detail.addDetailEntry(name2);
              entry2.addNamespaceDeclaration("ns0", namespace);

              SOAPElement child2 = entry2.addChildElement("BOGUS");
              child2.addTextNode("2 text");

              QName qname = new QName("http://www.w3.org/2003/05/soap-envelope", "Sender");
              // printDetail(detail);
              SOAPFault sf = soapFactory.createFault(msg, qname);
              if (subcode != null)
                  sf.appendFaultSubcode(subcode);
              // Node n = sf.addDetail().getOwnerDocument().importNode(detail, true);
              org.w3c.dom.Node n = sf.getOwnerDocument().importNode(detail, true);
              // printDetail((Detail)n);
              sf.appendChild(n);
              return new SOAPFaultException(sf);

          }
      }

      2. start the web service with the following java file:
      package wstest;

       import javax.xml.ws.Endpoint;

       public class FaultService {
           public static void main(String[] args) {
               Endpoint.publish("http://localhost:8080/WebServices/faultimpl", new FaultImpl());
           }
       }

      3. generate the client:
      wsimport -keep -p wstest.server http://localhost:8080/WebServices/faultimpl?wsdl

      4. run the client test with the following java file:
      import java.rmi.*;
      import javax.naming.*;
      import wstest.server.*;

      public class FaultClient {
          public static void main(String[] args) throws java.lang.Exception {
              FaultImplService service = new FaultImplService();
              FaultImpl port = service.getPort(FaultImpl.class);
              port.test();
          }
      }

      Expect Client received "SOAP Fault from server: soap fault exception fault", but actually Client received "SOAP Fault from server: Cannot find SOAP wrapper for element [ns0:BasicFault: null]"

            zli Zheng Jun Li (Inactive)
            fyuan Frank Yuan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: