Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to handle specified exception thrown from WebMethod #596

Open
Tomas-Kraus opened this issue Jun 2, 2022 · 0 comments
Open

Failed to handle specified exception thrown from WebMethod #596

Tomas-Kraus opened this issue Jun 2, 2022 · 0 comments

Comments

@Tomas-Kraus
Copy link
Member

Previously Tracked by: https://bugs.openjdk.java.net/browse/JDK-8184905

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); 

} 

}

  1. 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());
}
}

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

  2. 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]"

Source: javaee/metro-jax-ws#1222
Author: LanceAndersen

lukasj added a commit that referenced this issue Jun 9, 2022
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
lukasj added a commit to lukasj/metro-jax-ws that referenced this issue Feb 2, 2023
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
(cherry picked from commit 331b805)
lukasj added a commit that referenced this issue Feb 2, 2023
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
(cherry picked from commit 331b805)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant