use of org.apache.cxf.message.FaultMode 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.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 ResponseTimeMessageOutInterceptorTest method testServerFaultMessageOut.
public void testServerFaultMessageOut(FaultMode faultMode) {
// need to increase the counter and is not a client
setupCounterRepository(true, false);
setupExchangeForMessage();
EasyMock.expect(message.getExchange()).andReturn(exchange);
EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
EasyMock.expect(message.get(FaultMode.class)).andReturn(faultMode).anyTimes();
EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(null);
EasyMock.expectLastCall();
EasyMock.expect(exchange.get(FaultMode.class)).andReturn(faultMode).anyTimes();
MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
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 ResponseTimeMessageInInterceptor method handleFault.
@Override
public void handleFault(Message message) {
Exchange ex = message.getExchange();
if (Boolean.TRUE.equals(ex.get("org.apache.cxf.management.counter.enabled"))) {
FaultMode mode = message.get(FaultMode.class);
if (mode == null) {
mode = FaultMode.UNCHECKED_APPLICATION_FAULT;
}
ex.put(FaultMode.class, mode);
}
}
use of org.apache.cxf.message.FaultMode in project cxf by apache.
the class ResponseTimeMessageOutInterceptor method handleFault.
@Override
public void handleFault(Message message) {
Exchange ex = message.getExchange();
if (ex.get("org.apache.cxf.management.counter.enabled") != null) {
if (ex.isOneWay()) {
// do nothing, done by the ResponseTimeInvokerInterceptor
} else {
FaultMode faultMode = message.get(FaultMode.class);
if (faultMode == null) {
// client side exceptions don't have FaultMode set un the message properties (as of 2.1.4)
faultMode = FaultMode.RUNTIME_FAULT;
}
ex.put(FaultMode.class, faultMode);
endHandlingMessage(ex);
}
}
}
Aggregations