use of javax.xml.ws.ProtocolException in project cxf by apache.
the class HandlerChainInvokerTest method testHandleFaultReturnsTrue.
// JAXB spec 9.3.2.2: Return true This indicates that fault message processing
// should continue. The runtime invokes handle Fault on the next handler or dispatches
// the fault message (see section 9.1.2.2) if there are no further handlers.
@Test
public void testHandleFaultReturnsTrue() {
ProtocolException pe = new ProtocolException("banzai");
logicalHandlers[2].setException(pe);
invoker.setRequestor(true);
logicalHandlers[0].setHandleFaultRet(true);
logicalHandlers[1].setHandleFaultRet(true);
logicalHandlers[2].setHandleFaultRet(true);
logicalHandlers[3].setHandleFaultRet(true);
boolean continueProcessing = false;
try {
continueProcessing = invoker.invokeLogicalHandlers(false, lmc);
fail("did not get expected exception");
} catch (RuntimeException e) {
assertEquals("banzai", e.getMessage());
}
assertFalse(continueProcessing);
// assertTrue(invoker.isClosed());
assertEquals(1, logicalHandlers[0].getHandleMessageCount());
assertEquals(1, logicalHandlers[1].getHandleMessageCount());
assertEquals(1, logicalHandlers[2].getHandleMessageCount());
assertEquals(0, logicalHandlers[3].getHandleMessageCount());
assertEquals(1, logicalHandlers[0].getHandleFaultCount());
assertEquals(1, logicalHandlers[1].getHandleFaultCount());
assertEquals(0, logicalHandlers[2].getHandleFaultCount());
assertEquals(0, logicalHandlers[3].getHandleFaultCount());
assertTrue(logicalHandlers[1].getInvokeOrderOfHandleFault() < logicalHandlers[0].getInvokeOrderOfHandleFault());
assertEquals(1, logicalHandlers[0].getCloseCount());
assertEquals(1, logicalHandlers[1].getCloseCount());
assertEquals(1, logicalHandlers[2].getCloseCount());
assertEquals(0, logicalHandlers[3].getCloseCount());
}
use of javax.xml.ws.ProtocolException in project cxf by apache.
the class ModifyNumberHandler method handleMessage.
public final boolean handleMessage(LogicalMessageContext messageContext) {
try {
// get the LogicalMessage from our context
LogicalMessage msg = messageContext.getMessage();
// check the payload, if its an AddNumbers request, we'll intervene
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Object payload = msg.getPayload(jaxbContext);
Object value = payload;
if (payload instanceof JAXBElement) {
value = ((JAXBElement<?>) payload).getValue();
}
if (value instanceof AddNumbers) {
AddNumbers req = (AddNumbers) value;
int a = req.getArg0();
req.setArg0(a * 10);
msg.setPayload(payload, jaxbContext);
}
return true;
} catch (JAXBException ex) {
throw new ProtocolException(ex);
}
}
use of javax.xml.ws.ProtocolException in project cxf by apache.
the class SmallNumberHandler method handleMessage.
public final boolean handleMessage(LogicalMessageContext messageContext) {
try {
boolean outbound = (Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
// get the LogicalMessage from our context
LogicalMessage msg = messageContext.getMessage();
// check the payload, if its an AddNumbers request, we'll intervene
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Object payload = msg.getPayload(jaxbContext);
if (payload instanceof JAXBElement) {
payload = ((JAXBElement<?>) payload).getValue();
}
if (payload instanceof AddNumbers) {
AddNumbers req = (AddNumbers) payload;
// now, if the arguments are small, let's do the calculation here
int a = req.getArg0();
int b = req.getArg1();
if (isSmall(a) && isSmall(b)) {
int answer = a + b;
// System.out.printf("SmallNumberHandler addNumbers(%d, %d) == %d\n", a, b, answer);
// ok, we've done the calculation, so build the
// response and set it as the payload of the message
AddNumbersResponse resp = new AddNumbersResponse();
resp.setReturn(answer);
msg.setPayload(new ObjectFactory().createAddNumbersResponse(resp), jaxbContext);
Source src = msg.getPayload();
msg.setPayload(src);
payload = msg.getPayload(jaxbContext);
if (payload instanceof JAXBElement) {
payload = ((JAXBElement<?>) payload).getValue();
}
AddNumbersResponse resp2 = (AddNumbersResponse) payload;
if (resp2 == resp) {
throw new WebServiceException("Shouldn't be the same object");
}
// returned to the client
return false;
}
}
}
return true;
} catch (JAXBException ex) {
throw new ProtocolException(ex);
}
}
use of javax.xml.ws.ProtocolException in project cxf by apache.
the class TestHandler method handleMessage.
public boolean handleMessage(T ctx) {
methodCalled("handleMessage");
printHandlerInfo("handleMessage", isOutbound(ctx));
boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
boolean ret = getHandleMessageRet();
if (!isServerSideHandler()) {
return true;
}
try {
verifyJAXWSProperties(ctx);
} catch (PingException e) {
e.printStackTrace();
throw new ProtocolException(e);
}
Object obj = ctx.getMessage().getPayload(jaxbCtx);
if (obj instanceof Ping || obj instanceof PingResponse) {
ret = handlePingMessage(outbound, ctx);
} else if (obj instanceof PingWithArgs) {
ret = handlePingWithArgsMessage(outbound, ctx);
}
return ret;
}
use of javax.xml.ws.ProtocolException in project cxf by apache.
the class MAPTestBase method testExplicitMAPs.
@Test
public void testExplicitMAPs() throws Exception {
try {
String msgId = "urn:uuid:12345-" + Math.random();
Map<String, Object> requestContext = ((BindingProvider) greeter).getRequestContext();
AddressingProperties maps = new AddressingProperties();
AttributedURIType id = ContextUtils.getAttributedURI(msgId);
maps.setMessageID(id);
requestContext.put(CLIENT_ADDRESSING_PROPERTIES, maps);
String greeting = greeter.greetMe("explicit1");
assertEquals("unexpected response received from service", "Hello explicit1", greeting);
checkVerification();
// message ID fault is expected
try {
greeter.greetMe("explicit2");
fail("expected ProtocolException on duplicate message ID");
} catch (ProtocolException pe) {
assertEquals("expected duplicate message ID failure", "Duplicate Message ID " + msgId, pe.getMessage());
checkVerification();
}
// clearing the message ID ensure a duplicate is not sent
maps.setMessageID(null);
// maps.setRelatesTo(ContextUtils.getRelatesTo(id.getValue()));
greeting = greeter.greetMe("explicit3");
assertEquals("unexpected response received from service", "Hello explicit3", greeting);
} catch (UndeclaredThrowableException ex) {
throw (Exception) ex.getCause();
}
}
Aggregations