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);
}
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();
}
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();
}
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);
}
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;
}
Aggregations