Search in sources :

Example 31 with ExchangeImpl

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());
}
Also used : Exchange(org.apache.cxf.message.Exchange) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) MessageContentsList(org.apache.cxf.message.MessageContentsList) TreeSet(java.util.TreeSet) StreamSource(javax.xml.transform.stream.StreamSource) Method(java.lang.reflect.Method) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 32 with ExchangeImpl

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());
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) MessageContentsList(org.apache.cxf.message.MessageContentsList) Method(java.lang.reflect.Method) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) MessageImpl(org.apache.cxf.message.MessageImpl) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 33 with ExchangeImpl

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());
}
Also used : Exchange(org.apache.cxf.message.Exchange) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Phase(org.apache.cxf.phase.Phase) Endpoint(org.apache.cxf.endpoint.Endpoint) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) PhaseManagerImpl(org.apache.cxf.bus.managers.PhaseManagerImpl) Interceptor(org.apache.cxf.interceptor.Interceptor) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 34 with ExchangeImpl

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());
}
Also used : Exchange(org.apache.cxf.message.Exchange) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Phase(org.apache.cxf.phase.Phase) Endpoint(org.apache.cxf.endpoint.Endpoint) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) Service(org.apache.cxf.service.Service) PhaseManagerImpl(org.apache.cxf.bus.managers.PhaseManagerImpl) Interceptor(org.apache.cxf.interceptor.Interceptor) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 35 with ExchangeImpl

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);
}
Also used : Exchange(org.apache.cxf.message.Exchange) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) QName(javax.xml.namespace.QName) CorbaMessage(org.apache.cxf.binding.corba.CorbaMessage) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException)

Aggregations

ExchangeImpl (org.apache.cxf.message.ExchangeImpl)227 MessageImpl (org.apache.cxf.message.MessageImpl)189 Message (org.apache.cxf.message.Message)166 Exchange (org.apache.cxf.message.Exchange)159 Test (org.junit.Test)107 Endpoint (org.apache.cxf.endpoint.Endpoint)42 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 ByteArrayInputStream (java.io.ByteArrayInputStream)28 QName (javax.xml.namespace.QName)23 Bus (org.apache.cxf.Bus)23 HashMap (java.util.HashMap)22 List (java.util.List)22 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 SOAPMessage (javax.xml.soap.SOAPMessage)16 LogEvent (org.apache.cxf.ext.logging.event.LogEvent)16 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)14 Conduit (org.apache.cxf.transport.Conduit)14