Search in sources :

Example 1 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project camel by apache.

the class Soap11DataFormatAdapter method createExceptionFromFault.

/**
     * Creates an exception and eventually an embedded bean that contains the
     * fault detail. The exception class is determined by using the
     * elementNameStrategy. The qName of the fault detail should match the
     * WebFault annotation of the Exception class. If no fault detail is set a
     * SOAPFaultException is created.
     * 
     * @param fault Soap fault
     * @return created Exception
     */
private Exception createExceptionFromFault(Fault fault) {
    String message = fault.getFaultstring();
    Detail faultDetail = fault.getDetail();
    if (faultDetail == null || faultDetail.getAny().size() == 0) {
        try {
            return new SOAPFaultException(SOAPFactory.newInstance().createFault(message, fault.getFaultcode()));
        } catch (SOAPException e) {
            throw new RuntimeCamelException(e);
        }
    }
    JAXBElement<?> detailEl = (JAXBElement<?>) faultDetail.getAny().get(0);
    Class<? extends Exception> exceptionClass = getDataFormat().getElementNameStrategy().findExceptionForFaultName(detailEl.getName());
    Constructor<? extends Exception> messageConstructor;
    Constructor<? extends Exception> constructor;
    try {
        messageConstructor = exceptionClass.getConstructor(String.class);
        Object detail = JAXBIntrospector.getValue(detailEl);
        try {
            constructor = exceptionClass.getConstructor(String.class, detail.getClass());
            return constructor.newInstance(message, detail);
        } catch (NoSuchMethodException e) {
            return messageConstructor.newInstance(message);
        }
    } catch (Exception e) {
        throw new RuntimeCamelException(e);
    }
}
Also used : SOAPException(javax.xml.soap.SOAPException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) JAXBElement(javax.xml.bind.JAXBElement) Detail(org.xmlsoap.schemas.soap.envelope.Detail) RuntimeCamelException(org.apache.camel.RuntimeCamelException) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Example 2 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project camel by apache.

the class Soap12DataFormatAdapter method createExceptionFromFault.

/**
     * Creates an exception and eventually an embedded bean that contains the
     * fault detail. The exception class is determined by using the
     * elementNameStrategy. The qName of the fault detail should match the
     * WebFault annotation of the Exception class. If no fault detail is set
     * a {@link javax.xml.ws.soap.SOAPFaultException} is created.
     * 
     * @param fault Soap fault
     * @return created Exception
     */
private Exception createExceptionFromFault(Fault fault) {
    StringBuilder sb = new StringBuilder();
    for (Reasontext text : fault.getReason().getText()) {
        sb.append(text.getValue());
    }
    String message = sb.toString();
    Detail faultDetail = fault.getDetail();
    if (faultDetail == null || faultDetail.getAny().size() == 0) {
        try {
            return new SOAPFaultException(SOAPFactory.newInstance().createFault(message, fault.getCode().getValue()));
        } catch (SOAPException e) {
            throw new RuntimeCamelException(e);
        }
    }
    JAXBElement<?> detailEl = (JAXBElement<?>) faultDetail.getAny().get(0);
    Class<? extends Exception> exceptionClass = getDataFormat().getElementNameStrategy().findExceptionForFaultName(detailEl.getName());
    Constructor<? extends Exception> messageConstructor;
    Constructor<? extends Exception> constructor;
    try {
        messageConstructor = exceptionClass.getConstructor(String.class);
        Object detail = JAXBIntrospector.getValue(detailEl);
        try {
            constructor = exceptionClass.getConstructor(String.class, detail.getClass());
            return constructor.newInstance(message, detail);
        } catch (NoSuchMethodException e) {
            return messageConstructor.newInstance(message);
        }
    } catch (Exception e) {
        throw new RuntimeCamelException(e);
    }
}
Also used : Reasontext(org.w3._2003._05.soap_envelope.Reasontext) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) JAXBElement(javax.xml.bind.JAXBElement) SOAPException(javax.xml.soap.SOAPException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPException(javax.xml.soap.SOAPException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Detail(org.w3._2003._05.soap_envelope.Detail)

Example 3 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException 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 4 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project midpoint by Evolveum.

the class TestWSSecurity method test123GetConfigAsNobodyGoodPasswordDigest.

@Test
public void test123GetConfigAsNobodyGoodPasswordDigest() throws Exception {
    final String TEST_NAME = "test123GetConfigAsNobodyGoodPasswordDigest";
    displayTestTitle(TEST_NAME);
    LogfileTestTailer tailer = createLogTailer();
    modelPort = createModelPort(USER_NOBODY_USERNAME, USER_NOBODY_PASSWORD, WSConstants.PW_DIGEST);
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    // WHEN
    try {
        modelPort.getObject(getTypeQName(SystemConfigurationType.class), SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, objectHolder, resultHolder);
        AssertJUnit.fail("Unexpected success");
    } catch (SOAPFaultException e) {
        assertSoapSecurityFault(e, "FailedAuthentication", "could not be authenticated or authorized");
    }
    tailer.tail();
    assertAuditLoginFailed(tailer, "no authorizations");
}
Also used : LogfileTestTailer(com.evolveum.midpoint.test.util.LogfileTestTailer) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.testng.annotations.Test)

Example 5 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project midpoint by Evolveum.

the class TestWSSecurity method test105GetConfigWrongUsernameDigest.

@Test
public void test105GetConfigWrongUsernameDigest() throws Exception {
    final String TEST_NAME = "test105GetConfigWrongUsernameDigest";
    displayTestTitle(TEST_NAME);
    LogfileTestTailer tailer = createLogTailer();
    modelPort = createModelPort("admin", USER_ADMINISTRATOR_PASSWORD, WSConstants.PW_DIGEST);
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    // WHEN
    try {
        modelPort.getObject(getTypeQName(SystemConfigurationType.class), SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, objectHolder, resultHolder);
        AssertJUnit.fail("Unexpected success");
    } catch (SOAPFaultException e) {
        assertSoapSecurityFault(e, "FailedAuthentication", "could not be authenticated or authorized");
    }
    tailer.tail();
    assertAuditLoginFailed(tailer, "no user");
}
Also used : LogfileTestTailer(com.evolveum.midpoint.test.util.LogfileTestTailer) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.testng.annotations.Test)

Aggregations

SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)197 Test (org.junit.Test)67 WebServiceException (javax.xml.ws.WebServiceException)58 ConnectException (java.net.ConnectException)48 QName (javax.xml.namespace.QName)48 ErrorCode (org.olat.modules.vitero.model.ErrorCode)48 SOAPFault (javax.xml.soap.SOAPFault)38 URL (java.net.URL)35 SOAPException (javax.xml.soap.SOAPException)31 LogfileTestTailer (com.evolveum.midpoint.test.util.LogfileTestTailer)21 Service (javax.xml.ws.Service)21 Test (org.testng.annotations.Test)21 Holder (javax.xml.ws.Holder)19 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)17 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)17 SOAPFactory (javax.xml.soap.SOAPFactory)17 SOAPMessage (javax.xml.soap.SOAPMessage)13 BigInteger (java.math.BigInteger)11 ProtocolException (javax.xml.ws.ProtocolException)11