Search in sources :

Example 1 with Detail

use of jakarta.xml.soap.Detail in project metro-jax-ws by eclipse-ee4j.

the class jaxws413Test method test1.

public void test1() throws SOAPException, IOException {
    SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault();
    fault.setFaultCode(new QName("http://foo/bar", "mycode", "myprefix"));
    fault.setFaultString("Some exception");
    Detail detail = fault.addDetail();
    detail.addDetailEntry(new QName("http://foo/bar", "soap11detail"));
    Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(SOAPVersion.SOAP_11, fault);
    SOAPMessage sm = faultMsg.readAsSOAPMessage();
    Detail det = sm.getSOAPBody().getFault().getDetail();
    Iterator iter = det.getDetailEntries();
    assertTrue(iter.hasNext());
    Element item = (Element) iter.next();
    assertEquals(item.getNamespaceURI(), "http://foo/bar");
    assertEquals(item.getLocalName(), "soap11detail");
}
Also used : Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPMessage(jakarta.xml.soap.SOAPMessage) Detail(jakarta.xml.soap.Detail)

Example 2 with Detail

use of jakarta.xml.soap.Detail in project metro-jax-ws by eclipse-ee4j.

the class WsaTubeHelper method getFaultActionFromSEIModel.

String getFaultActionFromSEIModel(Packet requestPacket, Packet responsePacket) {
    String action = null;
    if (seiModel == null || wsdlPort == null) {
        return action;
    }
    try {
        SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
        if (sm == null) {
            return action;
        }
        if (sm.getSOAPBody() == null) {
            return action;
        }
        if (sm.getSOAPBody().getFault() == null) {
            return action;
        }
        Detail detail = sm.getSOAPBody().getFault().getDetail();
        if (detail == null) {
            return action;
        }
        String ns = detail.getFirstChild().getNamespaceURI();
        String name = detail.getFirstChild().getLocalName();
        WSDLOperationMapping wsdlOp = requestPacket.getWSDLOperationMapping();
        JavaMethodImpl jm = (wsdlOp != null) ? (JavaMethodImpl) wsdlOp.getJavaMethod() : null;
        if (jm != null) {
            for (CheckedExceptionImpl ce : jm.getCheckedExceptions()) {
                if (ce.getDetailType().tagName.getLocalPart().equals(name) && ce.getDetailType().tagName.getNamespaceURI().equals(ns)) {
                    return ce.getFaultAction();
                }
            }
        }
        return action;
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
Also used : WSDLOperationMapping(com.sun.xml.ws.api.model.WSDLOperationMapping) JavaMethodImpl(com.sun.xml.ws.model.JavaMethodImpl) WebServiceException(jakarta.xml.ws.WebServiceException) SOAPException(jakarta.xml.soap.SOAPException) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) SOAPMessage(jakarta.xml.soap.SOAPMessage) Detail(jakarta.xml.soap.Detail)

Example 3 with Detail

use of jakarta.xml.soap.Detail in project metro-jax-ws by eclipse-ee4j.

the class WsaTubeHelper method getFaultAction.

String getFaultAction(@Nullable WSDLBoundOperation wbo, Packet responsePacket) {
    String action = AddressingUtils.getAction(responsePacket.getMessage().getHeaders(), addVer, soapVer);
    if (action != null) {
        return action;
    }
    action = addVer.getDefaultFaultAction();
    if (wbo == null) {
        return action;
    }
    try {
        SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
        if (sm == null) {
            return action;
        }
        if (sm.getSOAPBody() == null) {
            return action;
        }
        if (sm.getSOAPBody().getFault() == null) {
            return action;
        }
        Detail detail = sm.getSOAPBody().getFault().getDetail();
        if (detail == null) {
            return action;
        }
        String ns = detail.getFirstChild().getNamespaceURI();
        String name = detail.getFirstChild().getLocalName();
        WSDLOperation o = wbo.getOperation();
        WSDLFault fault = o.getFault(new QName(ns, name));
        if (fault == null) {
            return action;
        }
        action = fault.getAction();
        return action;
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) SOAPException(jakarta.xml.soap.SOAPException) WSDLOperation(com.sun.xml.ws.api.model.wsdl.WSDLOperation) SOAPMessage(jakarta.xml.soap.SOAPMessage) WSDLFault(com.sun.xml.ws.api.model.wsdl.WSDLFault) Detail(jakarta.xml.soap.Detail)

Example 4 with Detail

use of jakarta.xml.soap.Detail in project metro-jax-ws by eclipse-ee4j.

the class JAXBTest method createFault.

private static SOAPFault createFault() throws Exception {
    SOAPFactory fac = SOAPFactory.newInstance();
    SOAPFault sf = fac.createFault("This is a fault.", new QName("http://schemas.xmlsoap.org/wsdl/soap/http", "Client"));
    Detail d = sf.addDetail();
    SOAPElement de = d.addChildElement(DETAIL1_QNAME);
    de.addAttribute(new QName("", "msg1"), "This is the first detail message.");
    return sf;
}
Also used : QName(javax.xml.namespace.QName) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPFactory(jakarta.xml.soap.SOAPFactory) Detail(jakarta.xml.soap.Detail)

Example 5 with Detail

use of jakarta.xml.soap.Detail in project openmq by eclipse-ee4j.

the class UMSService method createSOAPFaultMessage.

/**
 * Create a soap fault message and set its error code and error string as specified in the parameter.
 */
public static SOAPMessage createSOAPFaultMessage(Throwable t, String faultCode, String faultString) {
    SOAPMessage soapFault = null;
    try {
        MessageFactory mf = MessageFactory.newInstance();
        soapFault = mf.createMessage();
        SOAPEnvelope env = soapFault.getSOAPPart().getEnvelope();
        SOAPBody body = env.getBody();
        SOAPFault faultElement = body.addFault();
        String soapNs = env.getElementName().getPrefix();
        String fcode = soapNs + ":" + faultCode;
        faultElement.setFaultCode(fcode);
        faultElement.setFaultString(faultString);
        Detail detail = faultElement.getDetail();
        if (detail == null) {
            detail = faultElement.addDetail();
        }
        Name stname = MessageUtil.createJMSName("StackTrace");
        SOAPElement entryEle = detail.addDetailEntry(stname);
        // get stack trace
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(baos);
        t.printStackTrace(ps);
        ps.close();
        String trace = baos.toString("utf8");
        entryEle.setValue(trace);
        soapFault.saveChanges();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return soapFault;
}
Also used : PrintStream(java.io.PrintStream) SOAPBody(jakarta.xml.soap.SOAPBody) MessageFactory(jakarta.xml.soap.MessageFactory) SOAPElement(jakarta.xml.soap.SOAPElement) SOAPFault(jakarta.xml.soap.SOAPFault) SOAPEnvelope(jakarta.xml.soap.SOAPEnvelope) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage) Detail(jakarta.xml.soap.Detail) SOAPException(jakarta.xml.soap.SOAPException) Name(jakarta.xml.soap.Name)

Aggregations

Detail (jakarta.xml.soap.Detail)10 SOAPFault (jakarta.xml.soap.SOAPFault)7 QName (javax.xml.namespace.QName)7 SOAPMessage (jakarta.xml.soap.SOAPMessage)5 Element (org.w3c.dom.Element)5 Message (com.sun.xml.ws.api.message.Message)4 SOAPException (jakarta.xml.soap.SOAPException)4 SOAPElement (jakarta.xml.soap.SOAPElement)3 WebServiceException (jakarta.xml.ws.WebServiceException)3 FaultMessage (com.sun.xml.ws.message.FaultMessage)2 JAXBMessage (com.sun.xml.ws.message.jaxb.JAXBMessage)2 JAXBException (jakarta.xml.bind.JAXBException)2 SOAPFactory (jakarta.xml.soap.SOAPFactory)2 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)2 Iterator (java.util.Iterator)2 DOMResult (javax.xml.transform.dom.DOMResult)2 WSDLOperationMapping (com.sun.xml.ws.api.model.WSDLOperationMapping)1 WSDLFault (com.sun.xml.ws.api.model.wsdl.WSDLFault)1 WSDLOperation (com.sun.xml.ws.api.model.wsdl.WSDLOperation)1 CheckedExceptionImpl (com.sun.xml.ws.model.CheckedExceptionImpl)1