WebFault are always marked as UNCHECKED_APPLICATION_FAULT
ggingras Apr 22, 2013 4:40 PMMy web service (JBoss-as-7.1.2, jbossws 4.0.2.GA) throws exceptions that are correctly annoted and the result is ok. Except that every time an exception is thrown, there is one stacktrace printed to the console that should not be there since it is a deplared exception of my web service.
6:17:57,445 WARNING [org.apache.cxf.phase.PhaseInterceptorChain] (http-/0.0.0.0:8080-1) Application {http://www.abc.com/xml}WebService#{http://www.abc.com/xml}doSomething has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault: abc at org.jboss.wsf.stack.cxf.JBossWSInvoker.createFault(JBossWSInvoker.java:246) at org.jboss.wsf.stack.cxf.JBossWSInvoker._invokeInternal(JBossWSInvoker.java:207) at org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:127)
Instead of
6:17:57,445 INFO [org.apache.cxf.phase.PhaseInterceptorChain] (http-/0.0.0.0:8080-1) Application {http://www.abc.com/xml}WebService#{http://www.abc.com/xml}doSomething has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault: abc
The problem seems to come from JBossWSInvoker which expects web faults to be wrapped within a InvocationTargetException which is not the case.
try { invHandler.invoke(ep, inv); retObj = inv.getReturnValue(); } catch (InvocationTargetException e) { Throwable t = e.getCause(); if (t == null) { t = e; } exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT); for (Class<?> cl : m.getExceptionTypes()) { if (cl.isInstance(t)) { exchange.getInMessage().put(FaultMode.class, FaultMode.CHECKED_APPLICATION_FAULT); } } if (t instanceof Fault) { exchange.getInMessage().put(FaultMode.class, FaultMode.CHECKED_APPLICATION_FAULT); throw (Fault)t; } throw createFault(t, m, paramList, true); } catch (Fault f) { exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT); throw f; } catch (Exception e) { exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT); throw createFault(e, m, paramList, false); }
The solutions, is either make my exception extend InvocationTargetException or wrap my fault in InvocationTargetException. I don't like any of the solution.
Is there any other way?