use of org.apache.cxf.message.FaultMode in project tomee by apache.
the class AbstractFaultChainInitiatorObserver method onMessage.
public void onMessage(Message message) {
assert null != message;
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
Exchange exchange = message.getExchange();
Message faultMessage;
if (isOutboundObserver()) {
Exception ex = message.getContent(Exception.class);
if (!(ex instanceof Fault)) {
ex = new Fault(ex);
}
FaultMode mode = message.get(FaultMode.class);
faultMessage = exchange.getOutMessage();
if (null == faultMessage) {
faultMessage = new MessageImpl();
faultMessage.setExchange(exchange);
faultMessage = exchange.getEndpoint().getBinding().createMessage(faultMessage);
}
faultMessage.setContent(Exception.class, ex);
if (null != mode) {
faultMessage.put(FaultMode.class, mode);
}
// CXF-3981
if (message.get("javax.xml.ws.addressing.context.inbound") != null) {
faultMessage.put("javax.xml.ws.addressing.context.inbound", message.get("javax.xml.ws.addressing.context.inbound"));
}
exchange.setOutMessage(null);
exchange.setOutFaultMessage(faultMessage);
if (message.get(BindingFaultInfo.class) != null) {
faultMessage.put(BindingFaultInfo.class, message.get(BindingFaultInfo.class));
}
} else {
faultMessage = message;
exchange.setInMessage(null);
exchange.setInFaultMessage(faultMessage);
}
// setup chain
PhaseInterceptorChain chain = new PhaseInterceptorChain(getPhases());
initializeInterceptors(faultMessage.getExchange(), chain);
faultMessage.setInterceptorChain(chain);
try {
chain.doIntercept(faultMessage);
} catch (RuntimeException exc) {
LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
throw exc;
} catch (Exception exc) {
LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
throw new RuntimeException(exc);
}
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
use of org.apache.cxf.message.FaultMode in project cxf by apache.
the class ResponseTimeCounter method increase.
public void increase(MessageHandlingTimeRecorder mhtr) {
if (!enabled) {
return;
}
long handlingTime = 0;
if (mhtr.isOneWay()) {
// We can count the response time
if (mhtr.getEndTime() > 0) {
handlingTime = mhtr.getHandlingTime();
}
} else {
handlingTime = mhtr.getHandlingTime();
}
write.lock();
try {
FaultMode faultMode = mhtr.getFaultMode();
invocations.getAndIncrement();
if (null == faultMode) {
// no exception occured
} else {
switch(faultMode) {
case CHECKED_APPLICATION_FAULT:
checkedApplicationFaults.incrementAndGet();
break;
case LOGICAL_RUNTIME_FAULT:
logicalRuntimeFaults.incrementAndGet();
break;
case RUNTIME_FAULT:
runtimeFaults.incrementAndGet();
break;
case UNCHECKED_APPLICATION_FAULT:
unCheckedApplicationFaults.incrementAndGet();
break;
default:
runtimeFaults.incrementAndGet();
break;
}
}
totalHandlingTime.addAndGet(handlingTime);
averageProcessingTime.getAndSet(totalHandlingTime.get() / invocations.get());
} finally {
write.unlock();
}
updateMax(handlingTime);
updateMin(handlingTime);
}
use of org.apache.cxf.message.FaultMode in project cxf by apache.
the class ResponseTimeMessageInInterceptorTest method testClientFaultMessageIn.
public void testClientFaultMessageIn(FaultMode faultMode) {
// need to increase the counter and is a client
setupCounterRepository(true, true);
setupExchangeForMessage();
setupOperationForMessage();
EasyMock.expect(message.getExchange()).andReturn(exchange);
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
EasyMock.expect(exchange.isOneWay()).andReturn(false);
EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(true);
exchange.put(FaultMode.class, faultMode);
EasyMock.expectLastCall();
EasyMock.expect(message.get(FaultMode.class)).andReturn(faultMode).anyTimes();
EasyMock.expect(exchange.get(FaultMode.class)).andReturn(faultMode).anyTimes();
EasyMock.expect(exchange.getOutMessage()).andReturn(message);
MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
mhtr.endHandling();
EasyMock.expectLastCall();
mhtr.setFaultMode(faultMode);
EasyMock.expectLastCall();
EasyMock.replay(mhtr);
EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
EasyMock.replay(exchange);
EasyMock.replay(message);
rtmoi.handleFault(message);
EasyMock.verify(message);
EasyMock.verify(bus);
EasyMock.verify(exchange);
EasyMock.verify(mhtr);
}
use of org.apache.cxf.message.FaultMode in project cxf by apache.
the class AbstractFaultChainInitiatorObserver method onMessage.
public void onMessage(Message message) {
assert null != message;
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
Exchange exchange = message.getExchange();
Message faultMessage;
if (isOutboundObserver()) {
Exception ex = message.getContent(Exception.class);
if (!(ex instanceof Fault)) {
ex = new Fault(ex);
}
FaultMode mode = message.get(FaultMode.class);
faultMessage = exchange.getOutMessage();
if (null == faultMessage) {
faultMessage = new MessageImpl();
faultMessage.setExchange(exchange);
faultMessage = exchange.getEndpoint().getBinding().createMessage(faultMessage);
}
faultMessage.setContent(Exception.class, ex);
if (null != mode) {
faultMessage.put(FaultMode.class, mode);
}
// CXF-3981
if (message.get("javax.xml.ws.addressing.context.inbound") != null) {
faultMessage.put("javax.xml.ws.addressing.context.inbound", message.get("javax.xml.ws.addressing.context.inbound"));
}
exchange.setOutMessage(null);
exchange.setOutFaultMessage(faultMessage);
if (message.get(BindingFaultInfo.class) != null) {
faultMessage.put(BindingFaultInfo.class, message.get(BindingFaultInfo.class));
}
} else {
faultMessage = message;
exchange.setInMessage(null);
exchange.setInFaultMessage(faultMessage);
}
// setup chain
PhaseInterceptorChain chain = new PhaseInterceptorChain(getPhases());
initializeInterceptors(faultMessage.getExchange(), chain);
faultMessage.setInterceptorChain(chain);
try {
chain.doIntercept(faultMessage);
} catch (RuntimeException exc) {
LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
throw exc;
} catch (Exception exc) {
LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
throw new RuntimeException(exc);
}
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
use of org.apache.cxf.message.FaultMode in project cxf by apache.
the class ClientFaultConverter method handleMessage.
public void handleMessage(Message msg) {
Fault fault = (Fault) msg.getContent(Exception.class);
if (fault.getDetail() != null && !MessageUtils.getContextualBoolean(msg, DISABLE_FAULT_MAPPING, false)) {
processFaultDetail(fault, msg);
setStackTrace(fault, msg);
}
FaultMode faultMode = FaultMode.UNCHECKED_APPLICATION_FAULT;
// Check if the raised exception is declared in the WSDL or by the JAX-RS resource
Method m = msg.getExchange().get(Method.class);
if (m != null) {
Exception e = msg.getContent(Exception.class);
for (Class<?> cl : m.getExceptionTypes()) {
if (cl.isInstance(e)) {
faultMode = FaultMode.CHECKED_APPLICATION_FAULT;
break;
}
}
}
msg.getExchange().put(FaultMode.class, faultMode);
}
Aggregations