Search in sources :

Example 1 with Conduit

use of org.apache.cxf.transport.Conduit in project camel by apache.

the class CxfProducer method doStart.

@Override
protected void doStart() throws Exception {
    // failsafe as cxf may not ensure the endpoint is started (CAMEL-8956)
    ServiceHelper.startService(endpoint);
    if (client == null) {
        client = endpoint.createClient();
    }
    Conduit conduit = client.getConduit();
    if (conduit.getClass().getName().endsWith("JMSConduit")) {
        java.lang.reflect.Method getJmsConfig = conduit.getClass().getMethod("getJmsConfig");
        Object jmsConfig = getJmsConfig.invoke(conduit);
        java.lang.reflect.Method getMessageType = jmsConfig.getClass().getMethod("getMessageType");
        boolean isTextPayload = "text".equals(getMessageType.invoke(jmsConfig));
        if (isTextPayload && endpoint.getDataFormat().equals(DataFormat.MESSAGE)) {
            //throw Exception as the Text JMS mesasge won't send as stream
            throw new RuntimeException("Text JMS message coundn't be a stream");
        }
    }
    endpoint.getChainedCxfEndpointConfigurer().configureClient(client);
}
Also used : Conduit(org.apache.cxf.transport.Conduit)

Example 2 with Conduit

use of org.apache.cxf.transport.Conduit in project camel by apache.

the class CamelDestinationTest method testRoundTripDestinationWithFault.

@Test
public void testRoundTripDestinationWithFault() throws Exception {
    inMessage = null;
    EndpointInfo conduitEpInfo = new EndpointInfo();
    conduitEpInfo.setAddress("camel://direct:Producer");
    // set up the conduit send to be true
    CamelConduit conduit = setupCamelConduit(conduitEpInfo, true, false);
    final Message outMessage = new MessageImpl();
    endpointInfo.setAddress("camel://direct:EndpointA");
    final CamelDestination destination = setupCamelDestination(endpointInfo, true);
    destination.setCheckException(true);
    // set up MessageObserver for handling the conduit message
    MessageObserver observer = new MessageObserver() {

        public void onMessage(Message m) {
            try {
                Exchange exchange = new ExchangeImpl();
                exchange.setInMessage(m);
                m.setExchange(exchange);
                verifyReceivedMessage(m, "HelloWorld");
                //verifyHeaders(m, outMessage);
                // setup the message for
                Conduit backConduit;
                backConduit = getBackChannel(destination, m);
                // wait for the message to be got from the conduit
                Message replyMessage = new MessageImpl();
                replyMessage.setContent(Exception.class, new RuntimeCamelException());
                sendoutMessage(backConduit, replyMessage, true, "HelloWorld Fault");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    MockEndpoint error = context.getEndpoint("mock:error", MockEndpoint.class);
    error.expectedMessageCount(1);
    //this call will active the camelDestination
    destination.setMessageObserver(observer);
    // set is one way false for get response from destination
    // need to use another thread to send the request message
    sendoutMessage(conduit, outMessage, false, "HelloWorld");
    // wait for the message to be got from the destination,
    // create the thread to handler the Destination incoming message
    verifyReceivedMessage(inMessage, "HelloWorld Fault");
    error.assertIsSatisfied();
    destination.shutdown();
}
Also used : MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 3 with Conduit

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

the class TestUtilities method invokeBytes.

public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception {
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress(address);
    ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
    ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport);
    Conduit conduit = conduitInit.getConduit(ei, getBus());
    TestMessageObserver obs = new TestMessageObserver();
    conduit.setMessageObserver(obs);
    Message m = new MessageImpl();
    conduit.prepare(m);
    OutputStream os = m.getContent(OutputStream.class);
    os.write(message);
    // TODO: shouldn't have to do this. IO caching needs cleaning
    // up or possibly removal...
    os.flush();
    os.close();
    return obs.getResponseStream().toByteArray();
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 4 with Conduit

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

the class JMSConfigFeature method initialize.

@Override
public void initialize(Client client, Bus bus) {
    checkJmsConfig();
    Conduit conduit = client.getConduit();
    if (!(conduit instanceof JMSConduit)) {
        throw new ConfigurationException(new Message("JMSCONFIGFEATURE_ONLY_JMS", LOG));
    }
    JMSConduit jmsConduit = (JMSConduit) conduit;
    jmsConduit.setJmsConfig(jmsConfig);
    super.initialize(client, bus);
}
Also used : Message(org.apache.cxf.common.i18n.Message) ConfigurationException(org.apache.cxf.configuration.ConfigurationException) Conduit(org.apache.cxf.transport.Conduit)

Example 5 with Conduit

use of org.apache.cxf.transport.Conduit in project fabric8 by jboss-fuse.

the class LoadBalanceTargetSelector method getNextConduit.

protected Conduit getNextConduit(Message message) {
    Conduit answer = null;
    Exchange exchange = message.getExchange();
    EndpointInfo ei = endpoint.getEndpointInfo();
    String address = loadBalanceStrategy.getNextAlternateAddress();
    if (overrideAddress(message)) {
        // We need to override the Endpoint Address here
        message.put(Message.ENDPOINT_ADDRESS, address);
    }
    try {
        ConduitInitiatorManager conduitInitiatorMgr = exchange.getBus().getExtension(ConduitInitiatorManager.class);
        if (conduitInitiatorMgr != null) {
            ConduitInitiator conduitInitiator = conduitInitiatorMgr.getConduitInitiatorForUri(address);
            if (conduitInitiator != null) {
                EndpointReferenceType epr = new EndpointReferenceType();
                AttributedURIType ad = new AttributedURIType();
                ad.setValue(address);
                epr.setAddress(ad);
                answer = conduitInitiator.getConduit(ei, epr, exchange.getBus());
                MessageObserver observer = exchange.get(MessageObserver.class);
                if (observer != null) {
                    answer.setMessageObserver(observer);
                } else {
                    getLogger().warning("MessageObserver not found");
                }
            } else {
                getLogger().warning("ConduitInitiator not found: " + ei.getAddress());
            }
        } else {
            getLogger().warning("ConduitInitiatorManager not found");
        }
    } catch (IOException ex) {
        throw new Fault(ex);
    }
    return answer;
}
Also used : Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) MessageObserver(org.apache.cxf.transport.MessageObserver) Conduit(org.apache.cxf.transport.Conduit) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) Fault(org.apache.cxf.interceptor.Fault) IOException(java.io.IOException)

Aggregations

Conduit (org.apache.cxf.transport.Conduit)90 Message (org.apache.cxf.message.Message)39 Test (org.junit.Test)38 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)35 Exchange (org.apache.cxf.message.Exchange)32 MessageImpl (org.apache.cxf.message.MessageImpl)19 IOException (java.io.IOException)18 Endpoint (org.apache.cxf.endpoint.Endpoint)16 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)15 MessageObserver (org.apache.cxf.transport.MessageObserver)15 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)13 OutputStream (java.io.OutputStream)11 Bus (org.apache.cxf.Bus)11 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)11 Destination (org.apache.cxf.transport.Destination)11 InputStream (java.io.InputStream)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Fault (org.apache.cxf.interceptor.Fault)7