Search in sources :

Example 71 with SOAPFaultException

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

the class DispatchImpl method mapException.

private RuntimeException mapException(Exception ex) {
    if (ex instanceof Fault && ex.getCause() instanceof IOException) {
        throw new WebServiceException(ex.getMessage(), ex.getCause());
    }
    if (getBinding() instanceof HTTPBinding) {
        HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
        exception.initCause(ex);
        return exception;
    } else if (getBinding() instanceof SOAPBinding) {
        SOAPFault soapFault = null;
        try {
            soapFault = JaxWsClientProxy.createSoapFault((SOAPBinding) getBinding(), ex);
        } catch (SOAPException e) {
        // ignore
        }
        if (soapFault == null) {
            return new WebServiceException(ex);
        }
        SOAPFaultException exception = new SOAPFaultException(soapFault);
        exception.initCause(ex);
        return exception;
    }
    return new WebServiceException(ex);
}
Also used : HTTPException(javax.xml.ws.http.HTTPException) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) SOAPFault(javax.xml.soap.SOAPFault) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) HTTPBinding(javax.xml.ws.http.HTTPBinding)

Example 72 with SOAPFaultException

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

the class JaxWsClientProxy method invoke.

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (client == null) {
        throw new IllegalStateException("The client has been closed.");
    }
    Endpoint endpoint = getClient().getEndpoint();
    String address = endpoint.getEndpointInfo().getAddress();
    MethodDispatcher dispatcher = (MethodDispatcher) endpoint.getService().get(MethodDispatcher.class.getName());
    Object[] params = args;
    if (null == params) {
        params = new Object[0];
    }
    try {
        if (method.getDeclaringClass().equals(BindingProvider.class) || method.getDeclaringClass().equals(Object.class) || method.getDeclaringClass().equals(Closeable.class) || method.getDeclaringClass().equals(AutoCloseable.class)) {
            return method.invoke(this, params);
        } else if (method.getDeclaringClass().isInstance(client)) {
            return method.invoke(client, params);
        }
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
    BindingOperationInfo oi = dispatcher.getBindingOperation(method, endpoint);
    if (oi == null) {
        Message msg = new Message("NO_BINDING_OPERATION_INFO", LOG, method.getName());
        throw new WebServiceException(msg.toString());
    }
    client.getRequestContext().put(Method.class.getName(), method);
    boolean isAsync = isAsync(method);
    Object result = null;
    try {
        if (isAsync) {
            result = invokeAsync(method, oi, params);
        } else {
            result = invokeSync(method, oi, params);
        }
    } catch (WebServiceException wex) {
        throw wex;
    } catch (Exception ex) {
        for (Class<?> excls : method.getExceptionTypes()) {
            if (excls.isInstance(ex)) {
                throw ex;
            }
        }
        if (ex instanceof Fault && ex.getCause() instanceof IOException) {
            throw new WebServiceException(ex.getMessage(), ex.getCause());
        }
        if (getBinding() instanceof HTTPBinding) {
            HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
            exception.initCause(ex);
            throw exception;
        } else if (getBinding() instanceof SOAPBinding) {
            SOAPFault soapFault = createSoapFault((SOAPBinding) getBinding(), ex);
            if (soapFault == null) {
                throw new WebServiceException(ex);
            }
            SOAPFaultException exception = new SOAPFaultException(soapFault);
            if (ex instanceof Fault && ex.getCause() != null) {
                exception.initCause(ex.getCause());
            } else {
                exception.initCause(ex);
            }
            throw exception;
        } else {
            throw new WebServiceException(ex);
        }
    } finally {
        if (addressChanged(address)) {
            setupEndpointAddressContext(getClient().getEndpoint());
        }
    }
    Map<String, Object> respContext = client.getResponseContext();
    Map<String, Scope> scopes = CastUtils.cast((Map<?, ?>) respContext.get(WrappedMessageContext.SCOPES));
    if (scopes != null) {
        for (Map.Entry<String, Scope> scope : scopes.entrySet()) {
            if (scope.getValue() == Scope.HANDLER) {
                respContext.remove(scope.getKey());
            }
        }
    }
    return adjustObject(result);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) HTTPException(javax.xml.ws.http.HTTPException) Message(org.apache.cxf.common.i18n.Message) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SoapFault(org.apache.cxf.binding.soap.SoapFault) Endpoint(org.apache.cxf.endpoint.Endpoint) MethodDispatcher(org.apache.cxf.service.invoker.MethodDispatcher) HTTPBinding(javax.xml.ws.http.HTTPBinding) WebServiceException(javax.xml.ws.WebServiceException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) BindingProvider(javax.xml.ws.BindingProvider) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HTTPException(javax.xml.ws.http.HTTPException) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebServiceException(javax.xml.ws.WebServiceException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Scope(javax.xml.ws.handler.MessageContext.Scope) SOAPFault(javax.xml.soap.SOAPFault) Map(java.util.Map)

Example 73 with SOAPFaultException

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

the class HandlerChainInvoker method setFaultMessage.

/*
     * When the message direction is reversed, if the message is not already a
     * fault message then it is replaced with a fault message
     */
private void setFaultMessage(MessageContext mc, Exception exception) {
    Message msg = ((WrappedMessageContext) mc).getWrappedMessage();
    msg.setContent(Exception.class, exception);
    msg.removeContent(XMLStreamReader.class);
    msg.removeContent(Source.class);
    try {
        SOAPMessage soapMessage = null;
        SoapVersion version = null;
        if (msg instanceof SoapMessage) {
            version = ((SoapMessage) msg).getVersion();
        }
        soapMessage = SAAJFactoryResolver.createMessageFactory(version).createMessage();
        msg.setContent(SOAPMessage.class, soapMessage);
        SOAPBody body = SAAJUtils.getBody(soapMessage);
        SOAPFault soapFault = body.addFault();
        if (exception instanceof SOAPFaultException) {
            SOAPFaultException sf = (SOAPFaultException) exception;
            soapFault.setFaultString(sf.getFault().getFaultString());
            SAAJUtils.setFaultCode(soapFault, sf.getFault().getFaultCodeAsQName());
            soapFault.setFaultActor(sf.getFault().getFaultActor());
            if (sf.getFault().hasDetail()) {
                Node nd = soapMessage.getSOAPPart().importNode(sf.getFault().getDetail(), true);
                nd = nd.getFirstChild();
                soapFault.addDetail();
                while (nd != null) {
                    soapFault.getDetail().appendChild(nd);
                    nd = nd.getNextSibling();
                }
            }
        } else if (exception instanceof Fault) {
            SoapFault sf = SoapFault.createFault((Fault) exception, ((SoapMessage) msg).getVersion());
            soapFault.setFaultString(sf.getReason());
            SAAJUtils.setFaultCode(soapFault, sf.getFaultCode());
            if (sf.hasDetails()) {
                soapFault.addDetail();
                Node nd = soapMessage.getSOAPPart().importNode(sf.getDetail(), true);
                nd = nd.getFirstChild();
                while (nd != null) {
                    soapFault.getDetail().appendChild(nd);
                    nd = nd.getNextSibling();
                }
            }
        } else {
            SAAJUtils.setFaultCode(soapFault, new QName("http://cxf.apache.org/faultcode", "HandlerFault"));
            soapFault.setFaultString(exception.getMessage());
        }
    } catch (SOAPException e) {
        e.printStackTrace();
    // do nothing
    }
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessage(javax.xml.soap.SOAPMessage) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SoapFault(org.apache.cxf.binding.soap.SoapFault) SOAPMessage(javax.xml.soap.SOAPMessage) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SoapVersion(org.apache.cxf.binding.soap.SoapVersion) SOAPBody(javax.xml.soap.SOAPBody) SOAPException(javax.xml.soap.SOAPException) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) SOAPFault(javax.xml.soap.SOAPFault)

Example 74 with SOAPFaultException

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

the class SecurityTokenServiceImpl method throwUnsupportedOperation.

private void throwUnsupportedOperation(String string) {
    try {
        SOAPFault fault = SAAJFactoryResolver.createSOAPFactory(null).createFault();
        fault.setFaultString("Unsupported operation " + string);
        throw new SOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new Fault(e);
    }
}
Also used : SOAPException(javax.xml.soap.SOAPException) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault)

Example 75 with SOAPFaultException

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

the class SubscriptionGrantingTest method cannotProcessFilter.

@Test
public void cannotProcessFilter() throws IOException {
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    DeliveryType delivery = new DeliveryType();
    XMLGregorianCalendar dateRequest = (XMLGregorianCalendar) DurationAndDateUtil.parseDurationOrTimestamp("2138-06-26T12:23:12.000-01:00");
    exp.setValue(DurationAndDateUtil.convertToXMLString(dateRequest));
    exp.setBestEffort(true);
    subscribe.setExpires(exp);
    subscribe.setDelivery(delivery);
    subscribe.getDelivery().getContent().add(createDummyNotifyTo());
    subscribe.setFilter(new FilterType());
    subscribe.getFilter().getContent().add("@^5this-is-not-a-valid-xpath-expression!!!*-/");
    try {
        eventSourceClient.subscribeOp(subscribe);
    } catch (SOAPFaultException ex) {
        Assert.assertTrue(ex.getFault().getFaultCode().contains(CannotProcessFilter.LOCAL_PART));
        Assert.assertTrue(ex.getFault().getTextContent().contains(CannotProcessFilter.REASON));
        return;
    }
    Assert.fail("Event source should have sent a CannotProcessFilter fault");
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) FilterType(org.apache.cxf.ws.eventing.FilterType) ExpirationType(org.apache.cxf.ws.eventing.ExpirationType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Subscribe(org.apache.cxf.ws.eventing.Subscribe) DeliveryType(org.apache.cxf.ws.eventing.DeliveryType) Test(org.junit.Test) SimpleEventingIntegrationTest(org.apache.cxf.ws.eventing.base.SimpleEventingIntegrationTest)

Aggregations

SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)97 Test (org.junit.Test)47 QName (javax.xml.namespace.QName)33 URL (java.net.URL)22 LogfileTestTailer (com.evolveum.midpoint.test.util.LogfileTestTailer)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 SOAPFault (javax.xml.soap.SOAPFault)17 SOAPException (javax.xml.soap.SOAPException)16 Service (javax.xml.ws.Service)11 WebServiceException (javax.xml.ws.WebServiceException)9 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)9 SOAPMessage (javax.xml.soap.SOAPMessage)8 SoapFault (org.apache.cxf.binding.soap.SoapFault)8 Bus (org.apache.cxf.Bus)6 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)6 Fault (org.apache.cxf.interceptor.Fault)6