Search in sources :

Example 1 with SOAPFault

use of javax.xml.soap.SOAPFault in project camel by apache.

the class CxfConsumerPayloadFaultCauseEnabledTest method testInvokingFromCxfClient.

@Test
public void testInvokingFromCxfClient() throws Exception {
    this.getCamelContextService();
    URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
    PersonService ss = new PersonService(wsdlURL, SERVICE_QNAME);
    Person client = ss.getSoap();
    Client c = ClientProxy.getClient(client);
    c.getInInterceptors().add(new LoggingInInterceptor());
    c.getOutInterceptors().add(new LoggingOutInterceptor());
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceAddress);
    Holder<String> personId = new Holder<String>();
    personId.value = "";
    Holder<String> ssn = new Holder<String>();
    Holder<String> name = new Holder<String>();
    try {
        client.getPerson(personId, ssn, name);
        fail("SOAPFault expected!");
    } catch (Exception e) {
        assertTrue(e instanceof SOAPFaultException);
        SOAPFault fault = ((SOAPFaultException) e).getFault();
        assertEquals("Someone messed up the service. Caused by: Homer", fault.getFaultString());
    }
}
Also used : LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) PersonService(org.apache.camel.wsdl_first.PersonService) Holder(javax.xml.ws.Holder) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPFault(javax.xml.soap.SOAPFault) Client(org.apache.cxf.endpoint.Client) Person(org.apache.camel.wsdl_first.Person) URL(java.net.URL) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 2 with SOAPFault

use of javax.xml.soap.SOAPFault in project quickstarts by jboss-switchyard.

the class ReverseService method reverse.

@POST
@Path("/")
@WebMethod(action = "urn:switchyard-quickstart:camel-soap-proxy:1.0")
@WebResult(name = "text")
public String reverse(@WebParam(name = "text") String text) throws Exception {
    if (text.equals("fault")) {
        SOAPFactory factory = SOAPFactory.newInstance();
        SOAPFault sf = factory.createFault("myfaultstring", new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, "Server"));
        sf.setFaultActor("myFaultActor");
        Detail d = sf.addDetail();
        QName entryName = new QName("urn:switchyard-quickstart:camel-soap-proxy:1.0", "order", "PO");
        DetailEntry entry = d.addDetailEntry(entryName);
        QName name = new QName("urn:switchyard-quickstart:camel-soap-proxy:1.0", "symbol");
        SOAPElement symbol = entry.addChildElement(name);
        symbol.addTextNode("SUNW");
        throw new SOAPFaultException(sf);
    }
    return new StringBuilder(text).reverse().toString();
}
Also used : QName(javax.xml.namespace.QName) DetailEntry(javax.xml.soap.DetailEntry) SOAPElement(javax.xml.soap.SOAPElement) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPFactory(javax.xml.soap.SOAPFactory) Detail(javax.xml.soap.Detail) Path(javax.ws.rs.Path) WebMethod(javax.jws.WebMethod) POST(javax.ws.rs.POST) WebResult(javax.jws.WebResult)

Example 3 with SOAPFault

use of javax.xml.soap.SOAPFault in project OpenAM by OpenRock.

the class SOAPCommunicator method createSOAPFault.

/**
     * Forms a SOAP Fault and puts it in the SOAP Message Body.
     *
     * @param faultCode   Fault code.
     * @param faultString Fault string.
     * @param detail      Fault details.
     * @return SOAP Fault in the SOAP Message Body or null if unable to generate the message.
     */
public SOAPMessage createSOAPFault(final String faultCode, final String faultString, final String detail) {
    try {
        SOAPMessage message = messageFactory.createMessage();
        SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
        SOAPFault fault = envelope.getBody().addFault();
        fault.setFaultCode(envelope.createName(faultCode, null, SOAPConstants.URI_NS_SOAP_ENVELOPE));
        fault.setFaultString(SAML2Utils.bundle.getString(faultString));
        if (StringUtils.isNotEmpty(detail)) {
            Detail faultDetail = fault.addDetail();
            SOAPElement faultDetailEntry = (SOAPElement) faultDetail.addDetailEntry(envelope.createName("Problem"));
            faultDetailEntry.addAttribute(envelope.createName("details"), SAML2Utils.bundle.getString(detail));
        }
        return message;
    } catch (SOAPException e) {
        debug.error("createSOAPFault:", e);
        return null;
    }
}
Also used : SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPFault(javax.xml.soap.SOAPFault) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) Detail(javax.xml.soap.Detail)

Example 4 with SOAPFault

use of javax.xml.soap.SOAPFault in project wildfly by wildfly.

the class PojoEndpoint method helloError.

public String helloError(String input) {
    try {
        SOAPFault fault = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createFault(input, SOAPConstants.SOAP_VERSIONMISMATCH_FAULT);
        fault.setFaultActor("mr.actor");
        fault.addDetail().addChildElement("test");
        fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "NullPointerException"));
        fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "OperatorNotFound"));
        throw new SOAPFaultException(fault);
    } catch (SOAPException ex) {
        ex.printStackTrace();
    }
    return "Failure!";
}
Also used : QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Example 5 with SOAPFault

use of javax.xml.soap.SOAPFault in project midpoint by Evolveum.

the class AbstractWebserviceTest method assertSoapFault.

protected void assertSoapFault(SOAPFaultException e, String expectedCode, String expectedMessage) {
    SOAPFault fault = e.getFault();
    String faultCode = fault.getFaultCode();
    display("SOAP fault code: " + faultCode);
    assertTrue("Unexpected fault code: " + faultCode, faultCode.endsWith(expectedCode));
    String message = e.getMessage();
    assertTrue("Unexpected fault message: " + message, message.contains(expectedMessage));
}
Also used : SOAPFault(javax.xml.soap.SOAPFault)

Aggregations

SOAPFault (javax.xml.soap.SOAPFault)8 SOAPException (javax.xml.soap.SOAPException)5 Detail (javax.xml.soap.Detail)4 SOAPElement (javax.xml.soap.SOAPElement)4 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)4 QName (javax.xml.namespace.QName)3 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)3 SOAPMessage (javax.xml.soap.SOAPMessage)3 Name (javax.xml.soap.Name)2 SOAPBody (javax.xml.soap.SOAPBody)2 URL (java.net.URL)1 WebMethod (javax.jws.WebMethod)1 WebResult (javax.jws.WebResult)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 DetailEntry (javax.xml.soap.DetailEntry)1 SOAPFactory (javax.xml.soap.SOAPFactory)1 Holder (javax.xml.ws.Holder)1 Person (org.apache.camel.wsdl_first.Person)1 PersonService (org.apache.camel.wsdl_first.PersonService)1