Search in sources :

Example 96 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class AtmosphereWebSocketJettyDestination method activate.

protected void activate() {
    super.activate();
    if (handler.getServletContext().getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") == null) {
        try {
            Class<?> dcc = ClassUtils.forName("org.eclipse.jetty.util.DecoratedObjectFactory", getClass().getClassLoader());
            handler.getServletContext().setAttribute("org.eclipse.jetty.util.DecoratedObjectFactory", dcc.newInstance());
        } catch (ClassNotFoundException | LinkageError | InstantiationException | IllegalAccessException e) {
        // ignore, old version of Jetty
        }
    }
    ServletConfig config = new VoidServletConfig(initParams) {

        @Override
        public ServletContext getServletContext() {
            return handler.getServletContext();
        }
    };
    try {
        framework.init(config);
    } catch (ServletException e) {
        throw new Fault(new Message("Could not initialize WebSocket Framework", LOG, e.getMessage()), e);
    }
}
Also used : ServletException(javax.servlet.ServletException) VoidServletConfig(org.atmosphere.util.VoidServletConfig) Message(org.apache.cxf.common.i18n.Message) ServletConfig(javax.servlet.ServletConfig) VoidServletConfig(org.atmosphere.util.VoidServletConfig) Fault(org.apache.cxf.interceptor.Fault)

Example 97 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class CryptoCoverageCheckerTest method runInterceptorAndValidate.

private void runInterceptorAndValidate(String document, Map<String, String> prefixes, List<XPathExpression> xpaths, boolean pass) throws Exception {
    final Document doc = this.readDocument(document);
    final SoapMessage msg = this.getSoapMessageForDom(doc);
    final CryptoCoverageChecker checker = new CryptoCoverageChecker(prefixes, xpaths);
    final PhaseInterceptor<SoapMessage> wss4jInInterceptor = this.getWss4jInInterceptor();
    wss4jInInterceptor.handleMessage(msg);
    try {
        checker.handleMessage(msg);
        if (!pass) {
            fail("Passed interceptor erroneously.");
        }
    } catch (Fault e) {
        if (pass) {
            fail("Failed interceptor erroneously.");
        }
        assertTrue(e.getMessage().contains("element found matching XPath"));
    }
}
Also used : Fault(org.apache.cxf.interceptor.Fault) Document(org.w3c.dom.Document) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 98 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class DefaultCryptoCoverageCheckerTest method runInterceptorAndValidate.

private void runInterceptorAndValidate(String document, Map<String, String> prefixes, List<XPathExpression> xpaths, boolean pass) throws Exception {
    final Document doc = this.readDocument(document);
    final SoapMessage msg = this.getSoapMessageForDom(doc);
    final CryptoCoverageChecker checker = new DefaultCryptoCoverageChecker();
    checker.addPrefixes(prefixes);
    checker.addXPaths(xpaths);
    final PhaseInterceptor<SoapMessage> wss4jInInterceptor = this.getWss4jInInterceptor();
    wss4jInInterceptor.handleMessage(msg);
    try {
        checker.handleMessage(msg);
        if (!pass) {
            fail("Passed interceptor erroneously.");
        }
    } catch (Fault e) {
        if (pass) {
            fail("Failed interceptor erroneously.");
        }
        assertTrue(e.getMessage().contains("element found matching XPath"));
    }
}
Also used : Fault(org.apache.cxf.interceptor.Fault) Document(org.w3c.dom.Document) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 99 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class FaultHandlingInterceptor method handleMessage.

public synchronized void handleMessage(Message message) throws Fault {
    FaultMode mode = MessageUtils.getFaultMode(message);
    if (null != mode) {
        Throwable cause = message.getContent(Exception.class).getCause();
        if (FaultMode.CHECKED_APPLICATION_FAULT == mode) {
            PingMeFault original = (PingMeFault) cause;
            FaultDetail detail = new FaultDetail();
            detail.setMajor((short) 20);
            detail.setMinor((short) 10);
            PingMeFault replaced = new PingMeFault(original.getMessage(), detail);
            message.setContent(Exception.class, new Fault(replaced));
        } else {
            RuntimeException original = (RuntimeException) cause;
            RuntimeException replaced = new RuntimeException(original.getMessage().toUpperCase());
            message.setContent(Exception.class, new Fault(replaced));
        }
    }
}
Also used : FaultMode(org.apache.cxf.message.FaultMode) PingMeFault(org.apache.cxf.greeter_control.PingMeFault) FaultDetail(org.apache.cxf.greeter_control.types.FaultDetail) Fault(org.apache.cxf.interceptor.Fault) PingMeFault(org.apache.cxf.greeter_control.PingMeFault)

Example 100 with Fault

use of org.apache.cxf.interceptor.Fault in project cxf by apache.

the class BaseGreeterImpl method pingMe.

public void pingMe(String faultType) throws PingMeFault {
    if ("USER".equals(faultType)) {
        FaultDetail detail = new FaultDetail();
        detail.setMajor((short) 1);
        detail.setMinor((short) 2);
        throw new PingMeFault("USER FAULT TEST", detail);
    } else if ("SYSTEM".equals(faultType)) {
        throw new Fault(new Message(EX_STRING, (ResourceBundle) null, new Object[] { "FAULT TEST" }));
    } else {
        throw new IllegalArgumentException(EX_STRING);
    }
}
Also used : PingMeFault(org.apache.cxf.hello_world_corba.PingMeFault) Message(org.apache.cxf.common.i18n.Message) FaultDetail(org.apache.cxf.hello_world_corba.types.FaultDetail) PingMeFault(org.apache.cxf.hello_world_corba.PingMeFault) Fault(org.apache.cxf.interceptor.Fault)

Aggregations

Fault (org.apache.cxf.interceptor.Fault)283 IOException (java.io.IOException)74 QName (javax.xml.namespace.QName)56 Message (org.apache.cxf.message.Message)52 XMLStreamException (javax.xml.stream.XMLStreamException)50 Element (org.w3c.dom.Element)42 Message (org.apache.cxf.common.i18n.Message)34 Exchange (org.apache.cxf.message.Exchange)30 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)30 SOAPException (javax.xml.soap.SOAPException)28 InputStream (java.io.InputStream)27 ArrayList (java.util.ArrayList)27 XMLStreamReader (javax.xml.stream.XMLStreamReader)26 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)26 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)25 Test (org.junit.Test)24 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)23 List (java.util.List)21 SOAPMessage (javax.xml.soap.SOAPMessage)21 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)21