Search in sources :

Example 1 with SOAPFaultBuilder

use of com.sun.xml.ws.fault.SOAPFaultBuilder in project metro-jax-ws by eclipse-ee4j.

the class FaultTester method testFault3.

public void testFault3() throws Exception {
    QName sc1 = new QName("http://example.org/1", "one");
    QName sc2 = new QName("http://example.org/2", "two");
    QName sc3 = new QName("http://example.org/3", "three");
    String faultString = "INTERNAL_ERROR";
    QName detailMsg = new QName("DetailMessage");
    String detailValue = "This method is not implemented";
    SOAPFactory fac = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPFault fault = fac.createFault(faultString, SOAPConstants.SOAP_RECEIVER_FAULT);
    fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
    fault.appendFaultSubcode(sc1);
    fault.appendFaultSubcode(sc2);
    fault.appendFaultSubcode(sc3);
    fault.addDetail().addDetailEntry(detailMsg).setTextContent(detailValue);
    Message fm = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_12, fault);
    // get the SOAPFault back
    SOAPFaultBuilder sfb = SOAPFaultBuilder.create(fm);
    Throwable ex = sfb.createException(null);
    assertTrue(ex instanceof SOAPFaultException);
    SOAPFaultException sfe = (SOAPFaultException) ex;
    SOAPFault sf = sfe.getFault();
    assertTrue(sf.getFaultString().equals(faultString));
    // compare detail
    Detail detail = sfe.getFault().getDetail();
    assertTrue(detail != null);
    Iterator iter = detail.getDetailEntries();
    assertTrue(iter.hasNext());
    DetailEntry n = (DetailEntry) iter.next();
    assertTrue(n.getNamespaceURI().equals(detailMsg.getNamespaceURI()) && n.getLocalName().equals(detailMsg.getLocalPart()));
    n.getTextContent().equals(detailValue);
    // compare code and subcodes
    Iterator scs = sf.getFaultSubcodes();
    assertTrue(scs.hasNext());
    QName sc = (QName) scs.next();
    assertTrue(sc.equals(sc1));
    assertTrue(scs.hasNext());
    sc = (QName) scs.next();
    assertTrue(sc.equals(sc2));
    assertTrue(scs.hasNext());
    sc = (QName) scs.next();
    assertTrue(sc.equals(sc3));
}
Also used : Message(com.sun.xml.ws.api.message.Message) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) QName(javax.xml.namespace.QName) SOAPFaultBuilder(com.sun.xml.ws.fault.SOAPFaultBuilder) Iterator(java.util.Iterator) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException)

Example 2 with SOAPFaultBuilder

use of com.sun.xml.ws.fault.SOAPFaultBuilder in project metro-jax-ws by eclipse-ee4j.

the class StubHandler method readResponse.

public JavaCallInfo readResponse(Packet p, JavaCallInfo call) throws Throwable {
    Message msg = p.getMessage();
    if (msg.isFault()) {
        SOAPFaultBuilder faultBuilder = SOAPFaultBuilder.create(msg);
        Throwable t = faultBuilder.createException(checkedExceptions);
        call.setException(t);
        throw t;
    } else {
        initArgs(call.getParameters());
        Object ret = responseBuilder.readResponse(msg, call.getParameters());
        call.setReturnValue(ret);
        return call;
    }
}
Also used : Message(com.sun.xml.ws.api.message.Message) SOAPFaultBuilder(com.sun.xml.ws.fault.SOAPFaultBuilder)

Example 3 with SOAPFaultBuilder

use of com.sun.xml.ws.fault.SOAPFaultBuilder in project metro-jax-ws by eclipse-ee4j.

the class DispatchImpl method doInvoke.

/**
 * Synchronously invokes a service.
 *
 * See {@link #process(Packet, RequestContext, ResponseContextReceiver)} on
 * why it takes a {@link RequestContext} and {@link ResponseContextReceiver} as a parameter.
 */
public final T doInvoke(T in, RequestContext rc, ResponseContextReceiver receiver) {
    Packet response = null;
    try {
        try {
            checkNullAllowed(in, rc, binding, mode);
            Packet message = createPacket(in);
            message.setState(Packet.State.ClientRequest);
            resolveEndpointAddress(message, rc);
            setProperties(message, true);
            response = process(message, rc, receiver);
            Message msg = response.getMessage();
            // REVIEW: eliminate allowFaultResponseMsg, but make that behavior default for MessageDispatch, PacketDispatch
            if (msg != null && msg.isFault() && !allowFaultResponseMsg) {
                SOAPFaultBuilder faultBuilder = SOAPFaultBuilder.create(msg);
                // it will get back to us is a protocol exception
                throw (SOAPFaultException) faultBuilder.createException(null);
            }
        } catch (JAXBException e) {
            // TODO: i18nify
            throw new DeserializationException(DispatchMessages.INVALID_RESPONSE_DESERIALIZATION(), e);
        } catch (WebServiceException e) {
            // it could be a WebServiceException or a ProtocolException
            throw e;
        } catch (Throwable e) {
            // WebServiceException
            throw new WebServiceException(e);
        }
        return toReturnValue(response);
    } finally {
        // REVIEW: Move to AsyncTransportProvider
        if (response != null && response.transportBackChannel != null)
            response.transportBackChannel.close();
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Message(com.sun.xml.ws.api.message.Message) WebServiceException(jakarta.xml.ws.WebServiceException) SOAPFaultBuilder(com.sun.xml.ws.fault.SOAPFaultBuilder) JAXBException(jakarta.xml.bind.JAXBException) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) DeserializationException(com.sun.xml.ws.encoding.soap.DeserializationException)

Example 4 with SOAPFaultBuilder

use of com.sun.xml.ws.fault.SOAPFaultBuilder in project metro-jax-ws by eclipse-ee4j.

the class FaultTester method testFault1.

public void testFault1() throws Throwable {
    SOAPMessage msg = SOAPVersion.SOAP_11.saajMessageFactory.createMessage(null, new ByteArrayInputStream(fault1.getBytes()));
    SOAPFaultBuilder sfb = SOAPFaultBuilder.create(new SAAJMessage(msg));
    Throwable t = sfb.createException(null);
    assertTrue(t instanceof SOAPFaultException);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPFaultBuilder(com.sun.xml.ws.fault.SOAPFaultBuilder) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException)

Example 5 with SOAPFaultBuilder

use of com.sun.xml.ws.fault.SOAPFaultBuilder in project metro-jax-ws by eclipse-ee4j.

the class FaultTester method testFault2.

public void testFault2() throws Throwable {
    InputStream is = this.getClass().getClassLoader().getResourceAsStream("fault2.xml");
    FileOutputStream fos = new FileOutputStream("fault2.xml");
    fos.write(fault2.trim().getBytes());
    fos.close();
    SOAPMessage msg = SOAPVersion.SOAP_12.saajMessageFactory.createMessage(null, new ByteArrayInputStream(fault2.trim().getBytes()));
    SOAPFaultBuilder sfb = SOAPFaultBuilder.create(new SAAJMessage(msg));
    Throwable t = sfb.createException(null);
    assertTrue(t instanceof SOAPFaultException);
    SOAPFaultException sfe = (SOAPFaultException) t;
    Detail detail = sfe.getFault().getDetail();
    assertTrue(detail != null);
    Iterator iter = detail.getDetailEntries();
    // there should be two detail entries
    assertTrue(iter.hasNext());
    DetailEntry de = (DetailEntry) iter.next();
    assertTrue(de.getElementQName().equals(new QName("http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", "FaultDetail")));
    Node n = de.getFirstChild();
    assertTrue(n.getNodeValue().equals("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidValues"));
    assertTrue(iter.hasNext());
    de = (DetailEntry) iter.next();
    assertTrue(de.getElementQName().equals(new QName("http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd", "FaultDetail2")));
    n = de.getFirstChild();
    assertTrue(n.getNodeValue().equals("http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidValues1"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) SOAPFaultException(jakarta.xml.ws.soap.SOAPFaultException) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPFaultBuilder(com.sun.xml.ws.fault.SOAPFaultBuilder) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator)

Aggregations

SOAPFaultBuilder (com.sun.xml.ws.fault.SOAPFaultBuilder)5 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)4 Message (com.sun.xml.ws.api.message.Message)3 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Iterator (java.util.Iterator)2 QName (javax.xml.namespace.QName)2 Packet (com.sun.xml.ws.api.message.Packet)1 DeserializationException (com.sun.xml.ws.encoding.soap.DeserializationException)1 JAXBException (jakarta.xml.bind.JAXBException)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 Node (org.w3c.dom.Node)1