Search in sources :

Example 16 with SOAPFault

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

the class JAXBTest method testJAXBElementMarshalling.

public void testJAXBElementMarshalling() throws Exception {
    JAXBRIContext jc = (JAXBRIContext) JAXBContext.newInstance(whitebox.jaxb.client.DetailType.class);
    DetailType dt = new DetailType();
    SOAPFault sf = createFault();
    dt.getDetails().add(sf.getDetail());
    Marshaller m = jc.createMarshaller();
    m.marshal(dt, System.out);
    XMLStreamBufferResult sbr = new XMLStreamBufferResult();
    m.setProperty(Marshaller.JAXB_FRAGMENT, true);
    m.marshal(dt, sbr);
    XMLStreamBuffer infoset = sbr.getXMLStreamBuffer();
    XMLStreamReader reader = infoset.readAsXMLStreamReader();
    if (reader.getEventType() == START_DOCUMENT)
        XMLStreamReaderUtil.nextElementContent(reader);
    verifyDetail(reader);
}
Also used : Marshaller(jakarta.xml.bind.Marshaller) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamBuffer(com.sun.xml.stream.buffer.XMLStreamBuffer) SOAPFault(jakarta.xml.soap.SOAPFault) XMLStreamBufferResult(com.sun.xml.stream.buffer.XMLStreamBufferResult) JAXBRIContext(org.glassfish.jaxb.runtime.api.JAXBRIContext)

Example 17 with SOAPFault

use of jakarta.xml.soap.SOAPFault 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 18 with SOAPFault

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

the class WsaTestImpl method createSOAPFault.

SOAPFault createSOAPFault(String message) {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault();
        fault.setFaultString(message);
        fault.setFaultCode(new QName("http://example.org/echo", "EmptyEchoString"));
        return fault;
    } catch (SOAPException ex) {
        throw new WebServiceException(ex);
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) SOAPException(jakarta.xml.soap.SOAPException) SOAPFault(jakarta.xml.soap.SOAPFault)

Example 19 with SOAPFault

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

the class NonAnonymousClientTest method test1194.

/**
 * SOAP 1.1 two-way message with a non-anonymous ReplyTo and FaultTo address.
 */
public void test1194() throws Exception {
    invokeAsync(createDispatchForNonAnonymousWithWSDLWithoutAddressing(), MESSAGES.getNonAnonymousReplyToMessage(), S11_NS, getNonAnonymousEndpointAddress(), clientAddress, ECHO_IN_ACTION, "fault-test1194");
    // Lets see we get a response in 60 s
    SOAPMessage m = respMsgExchanger.exchange(null, TestConstants.CLIENT_MAX_TIMEOUT, TimeUnit.SECONDS);
    // System.out.println("****************************");
    // m.writeTo(System.out);
    // System.out.println("\n****************************");
    SOAPFault f = m.getSOAPBody().getFault();
    assertNotNull(f);
    assertEquals(USER_FAULT_CODE, f.getFaultCodeAsQName());
}
Also used : SOAPFault(jakarta.xml.soap.SOAPFault) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 20 with SOAPFault

use of jakarta.xml.soap.SOAPFault 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

SOAPFault (jakarta.xml.soap.SOAPFault)45 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)21 QName (javax.xml.namespace.QName)16 SOAPException (jakarta.xml.soap.SOAPException)12 WebServiceException (jakarta.xml.ws.WebServiceException)11 SOAPMessage (jakarta.xml.soap.SOAPMessage)9 HandlerTracker (fromwsdl.handler.common.HandlerTracker)8 HandlerTracker (handler.handler_processing.common.HandlerTracker)8 Detail (jakarta.xml.soap.Detail)7 Message (com.sun.xml.ws.api.message.Message)5 SOAPBody (jakarta.xml.soap.SOAPBody)5 SOAPFactory (jakarta.xml.soap.SOAPFactory)5 Element (org.w3c.dom.Element)5 SOAPElement (jakarta.xml.soap.SOAPElement)3 InvalidAddressingHeaderException (com.sun.xml.ws.addressing.model.InvalidAddressingHeaderException)2 WSService (com.sun.xml.ws.api.WSService)2 OneWayFeature (com.sun.xml.ws.api.addressing.OneWayFeature)2 MemberSubmissionAddressingFeature (com.sun.xml.ws.developer.MemberSubmissionAddressingFeature)2 FaultDetailHeader (com.sun.xml.ws.message.FaultDetailHeader)2 Iterator (java.util.Iterator)2