use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class LogicalHandlerInterceptorTest method xtestReturnFalseClientSide.
// JAX-WS spec: If handler returns false, for a request-response MEP, if the message
// direction is reversed during processing of a request message then the message
// becomes a response message.
// NOTE: commented out as this has been covered by other tests.
@Test
@org.junit.Ignore
public void xtestReturnFalseClientSide() throws Exception {
@SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
list.add(new LogicalHandler<LogicalMessageContext>() {
public void close(MessageContext arg0) {
}
public boolean handleFault(LogicalMessageContext messageContext) {
return true;
}
public boolean handleMessage(LogicalMessageContext messageContext) {
LogicalMessage msg = messageContext.getMessage();
AddNumbersResponse resp = new AddNumbersResponse();
resp.setReturn(11);
msg.setPayload(resp, null);
return false;
}
});
HandlerChainInvoker invoker1 = new HandlerChainInvoker(list);
IMocksControl control1 = createNiceControl();
Binding binding1 = control1.createMock(Binding.class);
@SuppressWarnings("rawtypes") List<Handler> hList = CastUtils.cast(list);
expect(binding1.getHandlerChain()).andReturn(hList).anyTimes();
Exchange exchange1 = control1.createMock(Exchange.class);
expect(exchange1.get(HandlerChainInvoker.class)).andReturn(invoker1).anyTimes();
Message outMessage = new MessageImpl();
outMessage.setExchange(exchange1);
InterceptorChain chain = control1.createMock(InterceptorChain.class);
outMessage.setInterceptorChain(chain);
chain.abort();
EasyMock.expectLastCall();
MessageObserver observer = control1.createMock(MessageObserver.class);
expect(exchange1.get(MessageObserver.class)).andReturn(observer).anyTimes();
observer.onMessage(isA(Message.class));
EasyMock.expectLastCall();
control1.replay();
LogicalHandlerInInterceptor li = new LogicalHandlerInInterceptor(binding1);
li.handleMessage(outMessage);
control1.verify();
}
use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class SOAPHandlerInterceptor method handleAbort.
private void handleAbort(SoapMessage message, MessageContext context) {
if (isRequestor(message)) {
// client side outbound
if (getInvoker(message).isOutbound()) {
message.getInterceptorChain().abort();
MessageObserver observer = message.getExchange().get(MessageObserver.class);
if (!message.getExchange().isOneWay() && observer != null) {
Endpoint e = message.getExchange().getEndpoint();
Message responseMsg = new MessageImpl();
responseMsg.setExchange(message.getExchange());
responseMsg = e.getBinding().createMessage(responseMsg);
// the request message becomes the response message
message.getExchange().setInMessage(responseMsg);
SOAPMessage soapMessage = ((SOAPMessageContext) context).getMessage();
if (soapMessage != null) {
responseMsg.setContent(SOAPMessage.class, soapMessage);
XMLStreamReader xmlReader = createXMLStreamReaderFromSOAPMessage(soapMessage);
responseMsg.setContent(XMLStreamReader.class, xmlReader);
}
responseMsg.put(InterceptorChain.STARTING_AT_INTERCEPTOR_ID, SOAPHandlerInterceptor.class.getName());
observer.onMessage(responseMsg);
}
// We dont call onCompletion here, as onCompletion will be called by inbound
// LogicalHandlerInterceptor
} else {
// client side inbound - Normal handler message processing
// stops, but the inbound interceptor chain still continues, dispatch the message
// By onCompletion here, we can skip following Logical handlers
onCompletion(message);
}
} else {
if (!getInvoker(message).isOutbound()) {
// server side inbound
message.getInterceptorChain().abort();
Endpoint e = message.getExchange().getEndpoint();
if (!message.getExchange().isOneWay()) {
Message responseMsg = new MessageImpl();
responseMsg.setExchange(message.getExchange());
responseMsg = e.getBinding().createMessage(responseMsg);
message.getExchange().setOutMessage(responseMsg);
SOAPMessage soapMessage = ((SOAPMessageContext) context).getMessage();
responseMsg.setContent(SOAPMessage.class, soapMessage);
InterceptorChain chain = OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange());
responseMsg.setInterceptorChain(chain);
// so the idea of starting interceptor chain from any
// specified point does not work
// well for outbound case, as many outbound interceptors
// have their ending interceptors.
// For example, we can not skip MessageSenderInterceptor.
chain.doInterceptStartingAfter(responseMsg, SoapPreProtocolOutInterceptor.class.getName());
}
} else {
// server side outbound - Normal handler message processing
// stops, but still continue the outbound interceptor chain, dispatch the message
}
}
}
use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class CorbaDestination method setMessageObserver.
public synchronized void setMessageObserver(MessageObserver observer) {
if (observer != incomingObserver) {
MessageObserver old = incomingObserver;
incomingObserver = observer;
if (observer != null) {
if (old == null) {
activate();
}
} else {
if (old != null) {
deactivate();
}
}
}
}
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();
}
Aggregations