Search in sources :

Example 31 with Exchange

use of org.apache.cxf.message.Exchange in project jbossws-cxf by jbossws.

the class JBossWSInvokerTest method testMessageContextThreadLocal.

/**
 * The JBossWSInvoker internals rely on the Apache CXF side of the Invoker abstraction to properly
 * set the generated WrappedMessageContext into the WebServiceContextImpl's threadlocal. As a consequence,
 * the JBossWSInvoker::performInvocation method can build up the JBoss integration WebServiceContext without
 * needing to pass in a MessageContext, as the properly created one is automatically retrieved internally
 * using the Apache CXF thread local. This all however assumes the Invoker inheritance tree is not erroneously
 * changed or the integration is not inadvertently broken in some way.
 * This test hence verifies the MessageContext instance is available inside the performInvocation method.
 */
@Test
public void testMessageContextThreadLocal() {
    TestInvoker invoker = new TestInvoker();
    // just to avoid internal NPE
    invoker.setTargetBean(this);
    Exchange exchange = getTestExchange();
    Object obj = invoker.invoke(exchange, null);
    String res = obj instanceof List<?> ? ((List<?>) obj).get(0).toString() : obj.toString();
    assertEquals("OK", res);
}
Also used : Exchange(org.apache.cxf.message.Exchange) List(java.util.List) Test(org.junit.Test)

Example 32 with Exchange

use of org.apache.cxf.message.Exchange in project jbossws-cxf by jbossws.

the class EndpointAssociationInterceptor method handleMessage.

@Override
public void handleMessage(Message message) throws Fault {
    Endpoint endpoint = EndpointAssociation.getEndpoint();
    Exchange exchange = message.getExchange();
    exchange.put(Endpoint.class, endpoint);
}
Also used : Exchange(org.apache.cxf.message.Exchange) Endpoint(org.jboss.wsf.spi.deployment.Endpoint)

Example 33 with Exchange

use of org.apache.cxf.message.Exchange in project jbossws-cxf by jbossws.

the class HandlerAuthInterceptor method handleMessage.

@Override
public void handleMessage(Message message) throws Fault {
    final Exchange ex = message.getExchange();
    HandlerChainInvoker invoker = ex.get(HandlerChainInvoker.class);
    if (null == invoker) {
        final org.apache.cxf.endpoint.Endpoint endpoint = ex.getEndpoint();
        if (endpoint instanceof JaxWsEndpointImpl) {
            // JAXWS handlers are not assigned to different endpoint types
            final JaxWsEndpointImpl ep = (JaxWsEndpointImpl) endpoint;
            @SuppressWarnings("rawtypes") final List<Handler> handlerChain = ep.getJaxwsBinding().getHandlerChain();
            if (handlerChain != null && !handlerChain.isEmpty()) {
                // save
                invoker = new JBossWSHandlerChainInvoker(handlerChain, isOutbound(message, ex));
                ex.put(HandlerChainInvoker.class, invoker);
            }
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) HandlerChainInvoker(org.apache.cxf.jaxws.handler.HandlerChainInvoker) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) Handler(javax.xml.ws.handler.Handler)

Example 34 with Exchange

use of org.apache.cxf.message.Exchange in project tomee by apache.

the class PhaseInterceptorChain method getServiceInfo.

private String getServiceInfo(Message message) {
    StringBuilder description = new StringBuilder();
    if (message.getExchange() != null) {
        Exchange exchange = message.getExchange();
        Service service = exchange.getService();
        if (service != null) {
            description.append('\'');
            description.append(service.getName());
            BindingOperationInfo boi = exchange.getBindingOperationInfo();
            OperationInfo opInfo = boi != null ? boi.getOperationInfo() : null;
            if (opInfo != null) {
                description.append('#').append(opInfo.getName());
            }
            description.append("\' ");
        }
    }
    return description.toString();
}
Also used : Exchange(org.apache.cxf.message.Exchange) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Service(org.apache.cxf.service.Service)

Example 35 with Exchange

use of org.apache.cxf.message.Exchange in project tomee by apache.

the class JAXRSOutInterceptor method processResponse.

// Response shouldn't be closed here
@SuppressWarnings("resource")
private void processResponse(ServerProviderFactory providerFactory, Message message) {
    if (isResponseAlreadyHandled(message)) {
        return;
    }
    MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs == null || objs.isEmpty()) {
        return;
    }
    Object responseObj = objs.get(0);
    final Response response;
    if (responseObj instanceof Response) {
        response = (Response) responseObj;
        if (response.getStatus() == 500 && message.getExchange().get(JAXRSUtils.EXCEPTION_FROM_MAPPER) != null) {
            message.put(Message.RESPONSE_CODE, 500);
            return;
        }
    } else {
        int status = getStatus(message, responseObj != null ? 200 : 204);
        response = JAXRSUtils.toResponseBuilder(status).entity(responseObj).build();
    }
    Exchange exchange = message.getExchange();
    OperationResourceInfo ori = (OperationResourceInfo) exchange.get(OperationResourceInfo.class.getName());
    serializeMessage(providerFactory, message, response, ori, true);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Exchange(org.apache.cxf.message.Exchange) MessageContentsList(org.apache.cxf.message.MessageContentsList) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo)

Aggregations

Exchange (org.apache.cxf.message.Exchange)338 Message (org.apache.cxf.message.Message)196 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)159 MessageImpl (org.apache.cxf.message.MessageImpl)144 Test (org.junit.Test)119 Endpoint (org.apache.cxf.endpoint.Endpoint)75 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)62 QName (javax.xml.namespace.QName)51 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)43 Bus (org.apache.cxf.Bus)33 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)32 Conduit (org.apache.cxf.transport.Conduit)31 Fault (org.apache.cxf.interceptor.Fault)30 IOException (java.io.IOException)28 ArrayList (java.util.ArrayList)28 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)28 MessageContentsList (org.apache.cxf.message.MessageContentsList)23 Service (org.apache.cxf.service.Service)22 SOAPMessage (javax.xml.soap.SOAPMessage)21 List (java.util.List)19