use of org.apache.cxf.message.MessageImpl in project cxf by apache.
the class AbstractFaultChainInitiatorObserver method onMessage.
public void onMessage(Message message) {
assert null != message;
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
Exchange exchange = message.getExchange();
Message faultMessage;
if (isOutboundObserver()) {
Exception ex = message.getContent(Exception.class);
if (!(ex instanceof Fault)) {
ex = new Fault(ex);
}
FaultMode mode = message.get(FaultMode.class);
faultMessage = exchange.getOutMessage();
if (null == faultMessage) {
faultMessage = new MessageImpl();
faultMessage.setExchange(exchange);
faultMessage = exchange.getEndpoint().getBinding().createMessage(faultMessage);
}
faultMessage.setContent(Exception.class, ex);
if (null != mode) {
faultMessage.put(FaultMode.class, mode);
}
// CXF-3981
if (message.get("javax.xml.ws.addressing.context.inbound") != null) {
faultMessage.put("javax.xml.ws.addressing.context.inbound", message.get("javax.xml.ws.addressing.context.inbound"));
}
exchange.setOutMessage(null);
exchange.setOutFaultMessage(faultMessage);
if (message.get(BindingFaultInfo.class) != null) {
faultMessage.put(BindingFaultInfo.class, message.get(BindingFaultInfo.class));
}
} else {
faultMessage = message;
exchange.setInMessage(null);
exchange.setInFaultMessage(faultMessage);
}
// setup chain
PhaseInterceptorChain chain = new PhaseInterceptorChain(getPhases());
initializeInterceptors(faultMessage.getExchange(), chain);
faultMessage.setInterceptorChain(chain);
try {
chain.doIntercept(faultMessage);
} catch (RuntimeException exc) {
LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
throw exc;
} catch (Exception exc) {
LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
throw new RuntimeException(exc);
}
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
use of org.apache.cxf.message.MessageImpl in project cxf by apache.
the class CorbaDSIServant method invoke.
public void invoke(ServerRequest request) throws CorbaBindingException {
String opName = request.operation();
QName requestOperation = operationMap.get(opName);
MessageImpl msgImpl = new MessageImpl();
msgImpl.setDestination(getDestination());
Exchange exg = new ExchangeImpl();
exg.put(String.class, requestOperation.getLocalPart());
exg.put(ORB.class, getOrb());
exg.put(ServerRequest.class, request);
msgImpl.setExchange(exg);
CorbaMessage msg = new CorbaMessage(msgImpl);
msg.setCorbaTypeMap(typeMap);
// If there's no output message part in our operation then it's a oneway op
final BindingOperationInfo bindingOpInfo;
try {
bindingOpInfo = this.destination.getEndPointInfo().getBinding().getOperation(requestOperation);
} catch (Exception ex) {
throw new CorbaBindingException("Invalid Request. Operation unknown: " + opName);
}
if (bindingOpInfo != null) {
BindingMessageInfo bindingMsgOutputInfo = bindingOpInfo.getOutput();
if (bindingMsgOutputInfo == null) {
exg.setOneWay(true);
}
}
// invokes the interceptors
getObserver().onMessage(msg);
}
use of org.apache.cxf.message.MessageImpl in project cxf by apache.
the class ColocOutInterceptorTest method setUp.
@Before
public void setUp() throws Exception {
colocOut = new ColocOutInterceptor();
msg = new MessageImpl();
ex = new ExchangeImpl();
msg.setExchange(ex);
}
use of org.apache.cxf.message.MessageImpl in project cxf by apache.
the class ColocMessageObserverTest method testObserverOnMessage.
@Test
public void testObserverOnMessage() throws Exception {
msg.setExchange(ex);
Binding binding = control.createMock(Binding.class);
EasyMock.expect(ep.getBinding()).andReturn(binding);
Message inMsg = new MessageImpl();
EasyMock.expect(binding.createMessage()).andReturn(inMsg);
EasyMock.expect(ep.getService()).andReturn(srv).anyTimes();
EasyMock.expect(bus.getExtension(PhaseManager.class)).andReturn(new PhaseManagerImpl()).times(2);
EasyMock.expect(bus.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>());
EasyMock.expect(ep.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>());
EasyMock.expect(srv.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>());
EasyMock.expect(bus.getExtension(ClassLoader.class)).andReturn(this.getClass().getClassLoader());
control.replay();
observer = new TestColocMessageObserver(ep, bus);
observer.onMessage(msg);
control.verify();
Exchange inEx = inMsg.getExchange();
assertNotNull("Should Have a valid Exchange", inEx);
assertFalse("Message.REQUESTOR_ROLE should be false", (Boolean) inMsg.get(Message.REQUESTOR_ROLE));
assertTrue("Message.INBOUND_MESSAGE should be true", (Boolean) inMsg.get(Message.INBOUND_MESSAGE));
assertNotNull("Chain should be set", inMsg.getInterceptorChain());
Exchange ex1 = msg.getExchange();
assertNotNull("Exchange should be set", ex1);
}
use of org.apache.cxf.message.MessageImpl in project cxf by apache.
the class BareInInterceptorTest method setUpUsingDocLit.
private void setUpUsingDocLit() throws Exception {
String ns = "http://apache.org/hello_world_doc_lit_bare";
WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource("/wsdl/jaxb/doc_lit_bare.wsdl").toString(), new QName(ns, "SOAPService"));
service = factory.create();
endpointInfo = service.getServiceInfos().get(0).getEndpoint(new QName(ns, "SoapPort"));
endpoint = new EndpointImpl(bus, service, endpointInfo);
JAXBDataBinding db = new JAXBDataBinding();
db.setContext(JAXBContext.newInstance(new Class[] { TradePriceData.class }));
service.setDataBinding(db);
operation = endpointInfo.getBinding().getOperation(new QName(ns, "SayHi"));
operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(TradePriceData.class);
operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(TradePriceData.class);
message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
exchange.put(Service.class, service);
exchange.put(Endpoint.class, endpoint);
exchange.put(Binding.class, endpoint.getBinding());
}
Aggregations