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);
}
}
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"));
}
}
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"));
}
}
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));
}
}
}
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);
}
}
Aggregations