Search in sources :

Example 11 with MessageObserver

use of org.apache.cxf.transport.MessageObserver in project cxf by apache.

the class CorbaServerConduitTest method setupCorbaServerConduit.

protected CorbaServerConduit setupCorbaServerConduit(boolean send) {
    target = EasyMock.createMock(EndpointReferenceType.class);
    endpointInfo = EasyMock.createMock(EndpointInfo.class);
    CorbaServerConduit corbaServerConduit = new CorbaServerConduit(endpointInfo, target, targetObject, null, orbConfig, corbaTypeMap);
    if (send) {
        // setMessageObserver
        observer = new MessageObserver() {

            public void onMessage(Message m) {
                inMessage = m;
            }
        };
        corbaServerConduit.setMessageObserver(observer);
    }
    return corbaServerConduit;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message)

Example 12 with MessageObserver

use of org.apache.cxf.transport.MessageObserver in project cxf by apache.

the class SoapBindingFactory method addListener.

@Override
public synchronized void addListener(Destination d, Endpoint e) {
    synchronized (d) {
        MessageObserver mo = d.getMessageObserver();
        if (d.getAddress() != null && d.getAddress().getAddress() != null && d.getAddress().getAddress().getValue() != null && d.getAddress().getAddress().getValue().startsWith("soap.udp")) {
            // soap.udp REQUIRES usage of WS-Addressing... we need to turn this on
            setupUDP(e, e.getEndpointInfo());
        }
        if (mo == null) {
            super.addListener(d, e);
            return;
        }
        if (mo instanceof ChainInitiationObserver) {
            ChainInitiationObserver cio = (ChainInitiationObserver) mo;
            Binding b = e.getBinding();
            Binding b2 = cio.getEndpoint().getBinding();
            if (b == b2) {
                // re-registering the same endpoint?
                return;
            }
            Object o = cio.getEndpoint().get("allow-multiplex-endpoint");
            if (o instanceof String) {
                o = Boolean.parseBoolean((String) o);
            } else if (o == null) {
                o = Boolean.FALSE;
            }
            if (b instanceof org.apache.cxf.binding.soap.SoapBinding && b2 instanceof org.apache.cxf.binding.soap.SoapBinding && ((org.apache.cxf.binding.soap.SoapBinding) b).getSoapVersion().equals(((org.apache.cxf.binding.soap.SoapBinding) b2).getSoapVersion()) && Boolean.FALSE.equals(o)) {
                throw new ListenerRegistrationException("Soap " + ((org.apache.cxf.binding.soap.SoapBinding) b).getSoapVersion().getVersion() + " endpoint already registered on address " + e.getEndpointInfo().getAddress());
            }
            MultipleEndpointObserver newMO = new MultipleEndpointObserver(getBus()) {

                @Override
                protected Message createMessage(Message message) {
                    return new SoapMessage(message);
                }
            };
            newMO.getBindingInterceptors().add(new AttachmentInInterceptor());
            newMO.getBindingInterceptors().add(new StaxInInterceptor());
            // This will not work if one of the endpoints disables message
            // processing. But, if you've disabled message processing, you
            // probably aren't going to use this feature.
            newMO.getBindingInterceptors().add(new ReadHeadersInterceptor(getBus(), (SoapVersion) null));
            newMO.getBindingInterceptors().add(new StartBodyInterceptor());
            newMO.getBindingInterceptors().add(new CheckFaultInterceptor());
            // Add in a default selection interceptor
            newMO.getRoutingInterceptors().add(new EndpointSelectionInterceptor());
            newMO.getEndpoints().add(cio.getEndpoint());
            mo = newMO;
        }
        if (mo instanceof MultipleEndpointObserver) {
            MultipleEndpointObserver meo = (MultipleEndpointObserver) mo;
            meo.getEndpoints().add(e);
        }
        d.setMessageObserver(mo);
    }
}
Also used : SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding) Binding(org.apache.cxf.binding.Binding) ReadHeadersInterceptor(org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor) CheckFaultInterceptor(org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) ListenerRegistrationException(org.apache.cxf.endpoint.ListenerRegistrationException) StaxInInterceptor(org.apache.cxf.interceptor.StaxInInterceptor) EndpointSelectionInterceptor(org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor) StartBodyInterceptor(org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor) ChainInitiationObserver(org.apache.cxf.transport.ChainInitiationObserver) MultipleEndpointObserver(org.apache.cxf.transport.MultipleEndpointObserver) AttachmentInInterceptor(org.apache.cxf.interceptor.AttachmentInInterceptor)

Example 13 with MessageObserver

use of org.apache.cxf.transport.MessageObserver in project cxf by apache.

the class CorbaDSIServantTest method testInvoke.

/*public void testCorbaDSIServant() throws Exception {

        CorbaDestination destination = testUtils.getSimpleTypesTestDestination();
        Service service = new ServiceImpl();
        Endpoint endpoint = new EndpointImpl(bus, service, destination.getEndPointInfo());
        MessageObserver observer = new ChainInitiationObserver(endpoint, bus);
        destination.setMessageObserver(observer);
        POA rootPOA = null;
        CorbaDSIServant dsiServant = new CorbaDSIServant();
        dsiServant.init(orb,
                        rootPOA,
                        destination,
                        observer);

        assertNotNull("DSIServant should not be null", dsiServant != null);
        assertNotNull("POA should not be null", dsiServant._default_POA() != null);
        assertNotNull("Destination should not be null", dsiServant.getDestination() != null);
        assertNotNull("ORB should not be null", dsiServant.getOrb() != null);
        assertNotNull("MessageObserver should not be null", dsiServant.getObserver() != null);

        byte[] objectId = new byte[10];
        String[] interfaces = dsiServant._all_interfaces(rootPOA, objectId);
        assertNotNull("Interfaces should not be null", interfaces != null);
        assertEquals("Interface ID should be equal", interfaces[0], "IDL:Simple:1.0");

    }*/
@Test
public void testInvoke() throws Exception {
    CorbaDestination dest = new TestUtils().getComplexTypesTestDestination();
    CorbaDSIServant dsiServant = new CorbaDSIServant();
    dsiServant.init(orb, null, dest, null);
    ServerRequest request = new ServerRequest() {

        public String operation() {
            return "greetMe";
        }

        public Context ctx() {
            return null;
        }
    };
    MessageObserver incomingObserver = new TestObserver();
    dsiServant.setObserver(incomingObserver);
    Map<String, QName> map = new HashMap<>(2);
    map.put("greetMe", new QName("greetMe"));
    dsiServant.setOperationMapping(map);
    dsiServant.invoke(request);
}
Also used : TestUtils(org.apache.cxf.binding.corba.TestUtils) CorbaDestination(org.apache.cxf.binding.corba.CorbaDestination) MessageObserver(org.apache.cxf.transport.MessageObserver) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ServerRequest(org.omg.CORBA.ServerRequest) Test(org.junit.Test)

Example 14 with MessageObserver

use of org.apache.cxf.transport.MessageObserver in project cxf by apache.

the class JMSDestinationTest method testRoundTripDestination.

private Message testRoundTripDestination(boolean createSecurityContext) throws Exception {
    EndpointInfo ei = setupServiceInfo("HelloWorldService", "HelloWorldPort");
    JMSConduit conduit = setupJMSConduitWithObserver(ei);
    conduit.getJmsConfig().setCreateSecurityContext(createSecurityContext);
    final Message outMessage = createMessage();
    final JMSDestination destination = setupJMSDestination(ei);
    // set up MessageObserver for handling the conduit message
    MessageObserver observer = new MessageObserver() {

        public void onMessage(Message m) {
            Exchange exchange = new ExchangeImpl();
            exchange.setInMessage(m);
            m.setExchange(exchange);
            verifyReceivedMessage(m);
            verifyHeaders(m, outMessage);
            // setup the message for
            Conduit backConduit;
            try {
                backConduit = destination.getBackChannel(m);
                // wait for the message to be got from the conduit
                Message replyMessage = new MessageImpl();
                sendOneWayMessage(backConduit, replyMessage);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    destination.setMessageObserver(observer);
    sendMessageSync(conduit, outMessage);
    // wait for the message to be got from the destination,
    // create the thread to handler the Destination incoming message
    verifyReceivedMessage(waitForReceiveInMessage());
    // wait for a while for the jms session recycling
    // Send a second message to check for an issue
    // Where the session was closed the second time
    sendMessageSync(conduit, outMessage);
    Message inMessage = waitForReceiveInMessage();
    verifyReceivedMessage(inMessage);
    // wait for a while for the jms session recycling
    // Thread.sleep(1000L);
    conduit.close();
    destination.shutdown();
    return inMessage;
}
Also used : Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) InvalidClientIDException(javax.jms.InvalidClientIDException) JMSException(javax.jms.JMSException)

Example 15 with MessageObserver

use of org.apache.cxf.transport.MessageObserver in project cxf by apache.

the class AbstractJMSTester method setupJMSConduitWithObserver.

protected JMSConduit setupJMSConduitWithObserver(EndpointInfo ei) throws IOException {
    JMSConduit jmsConduit = setupJMSConduit(ei);
    MessageObserver observer = new MessageObserver() {

        public void onMessage(Message m) {
            inMessage.set(m);
            synchronized (inMessage) {
                inMessage.notifyAll();
            }
        }
    };
    jmsConduit.setMessageObserver(observer);
    return jmsConduit;
}
Also used : MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message)

Aggregations

MessageObserver (org.apache.cxf.transport.MessageObserver)43 Message (org.apache.cxf.message.Message)34 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)21 Conduit (org.apache.cxf.transport.Conduit)14 IOException (java.io.IOException)13 Exchange (org.apache.cxf.message.Exchange)12 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)11 Test (org.junit.Test)11 MessageImpl (org.apache.cxf.message.MessageImpl)10 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)10 Bus (org.apache.cxf.Bus)8 QName (javax.xml.namespace.QName)7 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)6 Fault (org.apache.cxf.interceptor.Fault)5 Destination (org.apache.cxf.transport.Destination)5 URISyntaxException (java.net.URISyntaxException)4 URL (java.net.URL)4 HashMap (java.util.HashMap)4 List (java.util.List)4 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)4