Search in sources :

Example 1 with InterceptorChain

use of org.apache.cxf.interceptor.InterceptorChain in project camel by apache.

the class MessageLossSimulator method handleMessage.

public void handleMessage(Message message) throws Fault {
    Object maps = RMContextUtils.retrieveMAPs(message, false, true);
    // RMContextUtils.ensureExposedVersion(maps);
    String action = getAction(maps);
    if (RMContextUtils.isRMProtocolMessage(action)) {
        return;
    }
    appMessageCount++;
    // do not discard odd-numbered messages
    if (0 != (appMessageCount % 2)) {
        return;
    }
    // discard even-numbered message
    InterceptorChain chain = message.getInterceptorChain();
    ListIterator<Interceptor<? extends Message>> it = chain.getIterator();
    while (it.hasNext()) {
        PhaseInterceptor<?> pi = (PhaseInterceptor<?>) it.next();
        if (MessageSenderInterceptor.class.getName().equals(pi.getId())) {
            chain.remove(pi);
            LOG.debug("Removed MessageSenderInterceptor from interceptor chain.");
            break;
        }
    }
    message.setContent(OutputStream.class, new WrappedOutputStream(message));
    message.getInterceptorChain().add(new AbstractPhaseInterceptor<Message>(Phase.PREPARE_SEND_ENDING) {

        public void handleMessage(Message message) throws Fault {
            try {
                message.getContent(OutputStream.class).close();
            } catch (IOException e) {
                throw new Fault(e);
            }
        }
    });
}
Also used : Message(org.apache.cxf.message.Message) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) Fault(org.apache.cxf.interceptor.Fault) IOException(java.io.IOException) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) MessageSenderInterceptor(org.apache.cxf.interceptor.MessageSenderInterceptor) AbstractWrappedOutputStream(org.apache.cxf.io.AbstractWrappedOutputStream) Interceptor(org.apache.cxf.interceptor.Interceptor) MessageSenderInterceptor(org.apache.cxf.interceptor.MessageSenderInterceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor)

Example 2 with InterceptorChain

use of org.apache.cxf.interceptor.InterceptorChain in project ddf by codice.

the class MetricsOutInterceptorTest method testHandleMessageWithOneWayClientMessage.

/**
     * Test method for
     * {@link ddf.metrics.interceptor.MetricsOutInterceptor#handleMessage(org.apache.cxf.message.Message)}
     * .
     *
     * @throws InterruptedException
     */
@Test
public void testHandleMessageWithOneWayClientMessage() {
    // Setup
    MetricsOutInterceptor outInterceptor = new MetricsOutInterceptor();
    Message mockMessage = mock(Message.class);
    Exchange ex = new ExchangeImpl();
    Bus mockBus = mock(Bus.class);
    InterceptorChain mockIc = mock(InterceptorChain.class);
    ex.put(Bus.class, mockBus);
    ex.setOneWay(true);
    when(mockBus.getId()).thenReturn("bus_id");
    when(mockMessage.getExchange()).thenReturn(ex);
    when(mockMessage.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn("false");
    when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn(true);
    when(mockMessage.getInterceptorChain()).thenReturn(mockIc);
    // Perform test
    outInterceptor.handleMessage(mockMessage);
    // validate that LatencyTimeRecorder.beginHandling was called once
    verify(mockMessage, times(1)).getInterceptorChain();
}
Also used : Exchange(org.apache.cxf.message.Exchange) Bus(org.apache.cxf.Bus) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Message(org.apache.cxf.message.Message) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 3 with InterceptorChain

use of org.apache.cxf.interceptor.InterceptorChain in project tomee by apache.

the class EjbInterceptor method intercept.

@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    Endpoint endpoint = this.exchange.get(Endpoint.class);
    Service service = endpoint.getService();
    Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding();
    this.exchange.put(InvocationContext.class, context);
    if (binding.getHandlerChain() == null || binding.getHandlerChain().isEmpty()) {
        // no handlers so let's just directly invoke the bean
        log.debug("No handlers found.");
        EjbMethodInvoker invoker = (EjbMethodInvoker) service.getInvoker();
        return invoker.directEjbInvoke(this.exchange, this.method, this.params);
    } else {
        // have handlers so have to run handlers now and redo data binding
        // as handlers can change the soap message
        log.debug("Handlers found.");
        Message inMessage = exchange.getInMessage();
        PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());
        chain.setFaultObserver(endpoint.getOutFaultObserver());
        /*
             * Since we have to re-do data binding and the XMLStreamReader
             * contents are already consumed by prior data binding step
             * we have to reinitialize the XMLStreamReader from the SOAPMessage
             * created by SAAJInInterceptor.
             */
        if (inMessage instanceof SoapMessage) {
            try {
                reserialize((SoapMessage) inMessage);
            } catch (Exception e) {
                throw new ServerRuntimeException("Failed to reserialize soap message", e);
            }
        } else {
        // TODO: how to handle XML/HTTP binding?
        }
        this.exchange.setOutMessage(null);
        // install default interceptors
        chain.add(new ServiceInvokerInterceptor());
        //chain.add(new OutgoingChainInterceptor()); // it is already in the enclosing chain, if we add it there we are in the tx so we write the message in the tx!
        // See http://cwiki.apache.org/CXF20DOC/interceptors.html
        // install Holder and Wrapper interceptors
        chain.add(new WrapperClassInInterceptor());
        chain.add(new HolderInInterceptor());
        // install interceptors for handler processing
        chain.add(new MustUnderstandInterceptor());
        chain.add(new LogicalHandlerInInterceptor(binding));
        chain.add(new SOAPHandlerInterceptor(binding));
        // install data binding interceptors - todo: check we need it
        copyDataBindingInterceptors(chain, inMessage.getInterceptorChain());
        InterceptorChain oldChain = inMessage.getInterceptorChain();
        inMessage.setInterceptorChain(chain);
        try {
            chain.doIntercept(inMessage);
        } finally {
            inMessage.setInterceptorChain(oldChain);
        }
        // TODO: the result should be deserialized from SOAPMessage
        Object result = getResult();
        return result;
    }
}
Also used : Binding(javax.xml.ws.Binding) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SOAPMessage(javax.xml.soap.SOAPMessage) HolderInInterceptor(org.apache.cxf.jaxws.interceptors.HolderInInterceptor) SOAPHandlerInterceptor(org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) Service(org.apache.cxf.service.Service) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Endpoint(org.apache.cxf.endpoint.Endpoint) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) LogicalHandlerInInterceptor(org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor) ServiceInvokerInterceptor(org.apache.cxf.interceptor.ServiceInvokerInterceptor) ServerRuntimeException(org.apache.openejb.server.ServerRuntimeException) WrapperClassInInterceptor(org.apache.cxf.jaxws.interceptors.WrapperClassInInterceptor) AroundInvoke(javax.interceptor.AroundInvoke)

Aggregations

InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)3 Message (org.apache.cxf.message.Message)3 IOException (java.io.IOException)1 AroundInvoke (javax.interceptor.AroundInvoke)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 Binding (javax.xml.ws.Binding)1 Bus (org.apache.cxf.Bus)1 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)1 MustUnderstandInterceptor (org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 Fault (org.apache.cxf.interceptor.Fault)1 Interceptor (org.apache.cxf.interceptor.Interceptor)1 MessageSenderInterceptor (org.apache.cxf.interceptor.MessageSenderInterceptor)1 ServiceInvokerInterceptor (org.apache.cxf.interceptor.ServiceInvokerInterceptor)1 AbstractWrappedOutputStream (org.apache.cxf.io.AbstractWrappedOutputStream)1 LogicalHandlerInInterceptor (org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor)1 SOAPHandlerInterceptor (org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor)1 HolderInInterceptor (org.apache.cxf.jaxws.interceptors.HolderInInterceptor)1 WrapperClassInInterceptor (org.apache.cxf.jaxws.interceptors.WrapperClassInInterceptor)1 JaxWsEndpointImpl (org.apache.cxf.jaxws.support.JaxWsEndpointImpl)1