Search in sources :

Example 76 with MessageImpl

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();
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Bus(org.apache.cxf.Bus) FaultMode(org.apache.cxf.message.FaultMode) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Message(org.apache.cxf.message.Message) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) MessageImpl(org.apache.cxf.message.MessageImpl) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 77 with MessageImpl

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);
}
Also used : Exchange(org.apache.cxf.message.Exchange) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) QName(javax.xml.namespace.QName) CorbaMessage(org.apache.cxf.binding.corba.CorbaMessage) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) CorbaBindingException(org.apache.cxf.binding.corba.CorbaBindingException)

Example 78 with MessageImpl

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);
}
Also used : MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Before(org.junit.Before)

Example 79 with MessageImpl

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);
}
Also used : Binding(org.apache.cxf.binding.Binding) Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) PhaseManager(org.apache.cxf.phase.PhaseManager) MessageImpl(org.apache.cxf.message.MessageImpl) PhaseManagerImpl(org.apache.cxf.bus.managers.PhaseManagerImpl) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Example 80 with MessageImpl

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());
}
Also used : Exchange(org.apache.cxf.message.Exchange) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) TradePriceData(org.apache.hello_world_doc_lit_bare.types.TradePriceData) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Aggregations

MessageImpl (org.apache.cxf.message.MessageImpl)610 Message (org.apache.cxf.message.Message)291 Test (org.junit.Test)290 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)193 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)152 Exchange (org.apache.cxf.message.Exchange)148 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)137 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)115 Crypto (org.apache.wss4j.common.crypto.Crypto)113 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)107 JAXBElement (javax.xml.bind.JAXBElement)100 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)93 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)86 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)83 Element (org.w3c.dom.Element)74 ArrayList (java.util.ArrayList)62 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 Principal (java.security.Principal)59 Endpoint (org.apache.cxf.endpoint.Endpoint)58