use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class MtomServerTest method servStatic.
/**
* Serve static file
*/
private void servStatic(final URL resource, final String add) throws Exception {
Bus bus = getStaticBus();
DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
DestinationFactory df = dfm.getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
EndpointInfo ei = new EndpointInfo();
ei.setAddress(add);
Destination d = df.getDestination(ei, bus);
d.setMessageObserver(new MessageObserver() {
public void onMessage(Message message) {
try {
// HTTP seems to need this right now...
ExchangeImpl ex = new ExchangeImpl();
ex.setInMessage(message);
Conduit backChannel = message.getDestination().getBackChannel(message);
MessageImpl res = new MessageImpl();
ex.setOutMessage(res);
res.put(Message.CONTENT_TYPE, "text/xml");
backChannel.prepare(res);
OutputStream out = res.getContent(OutputStream.class);
InputStream is = resource.openStream();
IOUtils.copy(is, out, 2048);
out.flush();
out.close();
is.close();
backChannel.close(res);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of org.apache.cxf.transport.MessageObserver in project camel by apache.
the class CamelDestinationTest method testRoundTripDestination.
@Test
public void testRoundTripDestination() 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);
// 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();
sendoutMessage(backConduit, replyMessage, true, "HelloWorld Response");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
MockEndpoint error = context.getEndpoint("mock:error", MockEndpoint.class);
error.expectedMessageCount(0);
//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 Response");
error.assertIsSatisfied();
destination.shutdown();
}
use of org.apache.cxf.transport.MessageObserver in project camel by apache.
the class CamelDestinationTest method setupCamelDestination.
public CamelDestination setupCamelDestination(EndpointInfo endpointInfo, boolean send) throws IOException {
ConduitInitiator conduitInitiator = EasyMock.createMock(ConduitInitiator.class);
CamelDestination camelDestination = new CamelDestination(context, bus, conduitInitiator, endpointInfo);
if (send) {
// setMessageObserver
observer = new MessageObserver() {
public void onMessage(Message m) {
Exchange exchange = new ExchangeImpl();
exchange.setInMessage(m);
m.setExchange(exchange);
destMessage = m;
}
};
camelDestination.setMessageObserver(observer);
}
return camelDestination;
}
Aggregations