use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class JAXWSMethodInvokerTest method testProviderInterpretNullAsOneway.
@Test
public void testProviderInterpretNullAsOneway() throws Throwable {
NullableProviderService serviceObject = new NullableProviderService();
Method serviceMethod = NullableProviderService.class.getMethod("invoke", new Class[] { Source.class });
Exchange ex = new ExchangeImpl();
Message inMessage = new MessageImpl();
inMessage.setInterceptorChain(new PhaseInterceptorChain(new TreeSet<Phase>()));
ex.setInMessage(inMessage);
inMessage.setExchange(ex);
inMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
// request-response with non-null response
ex.setOneWay(false);
MessageContentsList obj = (MessageContentsList) jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] { new StreamSource() }));
assertEquals(1, obj.size());
assertNotNull(obj.get(0));
assertFalse(ex.isOneWay());
// oneway with non-null response
ex.setOneWay(true);
obj = (MessageContentsList) jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] { new StreamSource() }));
assertNull(obj);
assertTrue(ex.isOneWay());
// request-response with null response, interpretNullAsOneway not set so
// default should be true
ex.setOneWay(false);
serviceObject.setNullable(true);
obj = (MessageContentsList) jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] { new StreamSource() }));
assertNull(obj);
assertTrue(ex.isOneWay());
// request-response with null response, interpretNullAsOneway disabled
ex.setOneWay(false);
serviceObject.setNullable(true);
inMessage.put("jaxws.provider.interpretNullAsOneway", Boolean.FALSE);
obj = (MessageContentsList) jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] { new StreamSource() }));
assertEquals(1, obj.size());
assertNull(obj.get(0));
assertFalse(ex.isOneWay());
// request-response with null response, interpretNullAsOneway explicitly enabled
ex.setOneWay(false);
serviceObject.setNullable(true);
inMessage.put("jaxws.provider.interpretNullAsOneway", Boolean.TRUE);
obj = (MessageContentsList) jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] { new StreamSource() }));
assertNull(obj);
assertTrue(ex.isOneWay());
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class JAXWSMethodInvokerTest method testSuspendedException.
@Test
public void testSuspendedException() throws Throwable {
Exception originalException = new RuntimeException();
ContinuationService serviceObject = new ContinuationService(originalException);
Method serviceMethod = ContinuationService.class.getMethod("invoke", new Class[] {});
Exchange ex = new ExchangeImpl();
Message inMessage = new MessageImpl();
ex.setInMessage(inMessage);
inMessage.setExchange(ex);
inMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
try {
jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] {}));
fail("Suspended invocation swallowed");
} catch (SuspendedInvocationException suspendedEx) {
assertSame(suspendedEx, serviceObject.getSuspendedException());
assertSame(originalException, suspendedEx.getRuntimeException());
}
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class ColocUtilTest method testGetOutInterceptorChain.
@Test
public void testGetOutInterceptorChain() throws Exception {
PhaseManagerImpl phaseMgr = new PhaseManagerImpl();
SortedSet<Phase> list = phaseMgr.getInPhases();
ColocUtil.setPhases(list, Phase.SETUP, Phase.POST_LOGICAL);
Endpoint ep = control.createMock(Endpoint.class);
Service srv = control.createMock(Service.class);
Exchange ex = new ExchangeImpl();
ex.put(Bus.class, bus);
ex.put(Endpoint.class, ep);
ex.put(Service.class, srv);
EasyMock.expect(ep.getOutInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
EasyMock.expect(ep.getService()).andReturn(srv).atLeastOnce();
EasyMock.expect(srv.getOutInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
EasyMock.expect(bus.getOutInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
control.replay();
InterceptorChain chain = ColocUtil.getOutInterceptorChain(ex, list);
control.verify();
assertNotNull("Should have chain instance", chain);
Iterator<Interceptor<? extends Message>> iter = chain.iterator();
assertFalse("Should not have interceptors in chain", iter.hasNext());
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class ColocUtilTest method testGetInInterceptorChain.
@Test
public void testGetInInterceptorChain() throws Exception {
PhaseManagerImpl phaseMgr = new PhaseManagerImpl();
SortedSet<Phase> list = phaseMgr.getInPhases();
ColocUtil.setPhases(list, Phase.SETUP, Phase.POST_LOGICAL);
Endpoint ep = control.createMock(Endpoint.class);
Service srv = control.createMock(Service.class);
Exchange ex = new ExchangeImpl();
ex.put(Bus.class, bus);
ex.put(Endpoint.class, ep);
ex.put(Service.class, srv);
EasyMock.expect(bus.getExtension(PhaseManager.class)).andReturn(phaseMgr);
EasyMock.expect(ep.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
EasyMock.expect(ep.getService()).andReturn(srv).atLeastOnce();
EasyMock.expect(srv.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
EasyMock.expect(bus.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
control.replay();
InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, list);
control.verify();
assertNotNull("Should have chain instance", chain);
Iterator<Interceptor<? extends Message>> iter = chain.iterator();
assertFalse("Should not have interceptors in chain", iter.hasNext());
assertNotNull("OutFaultObserver should be set", chain.getFaultObserver());
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class CorbaDSIServant method invoke.
public void invoke(ServerRequest request) throws CorbaBindingException {
String opName = request.operation();
QName requestOperation = operationMap.get(opName);
MessageImpl msgImpl = new MessageImpl();
msgImpl.setDestination(getDestination());
Exchange exg = new ExchangeImpl();
exg.put(String.class, requestOperation.getLocalPart());
exg.put(ORB.class, getOrb());
exg.put(ServerRequest.class, request);
msgImpl.setExchange(exg);
CorbaMessage msg = new CorbaMessage(msgImpl);
msg.setCorbaTypeMap(typeMap);
// If there's no output message part in our operation then it's a oneway op
final BindingOperationInfo bindingOpInfo;
try {
bindingOpInfo = this.destination.getEndPointInfo().getBinding().getOperation(requestOperation);
} catch (Exception ex) {
throw new CorbaBindingException("Invalid Request. Operation unknown: " + opName);
}
if (bindingOpInfo != null) {
BindingMessageInfo bindingMsgOutputInfo = bindingOpInfo.getOutput();
if (bindingMsgOutputInfo == null) {
exg.setOneWay(true);
}
}
// invokes the interceptors
getObserver().onMessage(msg);
}
Aggregations