Java Code Examples for org.apache.cxf.interceptor.InterceptorChain#remove()

The following examples show how to use org.apache.cxf.interceptor.InterceptorChain#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedeliveryQueueImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void redeliver() throws Exception {
    LOG.log(Level.INFO, "Redelivering ... for " + (1 + retries));
    String restartingPhase;
    if (message.getContent(Exception.class) != null) {
        message.removeContent(Exception.class);
        message.getExchange().put(Exception.class, null);

        // clean-up message for redelivery
        closeStreamResources();
        message.removeContent(Node.class);
    }


    InputStream is = null;
    CachedOutputStream cos = (CachedOutputStream)message.get(RMMessageConstants.SAVED_CONTENT);
    is = cos.getInputStream();
    message.setContent(InputStream.class, is);
    message = message.getExchange().getEndpoint().getBinding().createMessage(message);
    restartingPhase = Phase.POST_STREAM;
    // skip some interceptor chain phases for redelivery
    InterceptorChain chain = getRedeliveryInterceptorChain(message, restartingPhase);
    ListIterator<Interceptor<? extends Message>> iterator = chain.getIterator();
    while (iterator.hasNext()) {
        Interceptor<? extends Message> incept = iterator.next();
        if (incept.getClass().getName().equals(RMCaptureInInterceptor.class.getName())) {
            chain.remove(incept);
        }
    }
    message.getExchange().setInMessage(message);
    message.setInterceptorChain(chain);
    chain.doIntercept(message);
    Exception ex = message.getContent(Exception.class);
    if (null != ex) {
        throw ex;
    }
}
 
Example 2
Source File: MessageLossSimulator.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true);
    String action = null;
    if (maps != null && null != maps.getAction()) {
        action = maps.getAction().getValue();
    }
    if (RMContextUtils.isRMProtocolMessage(action)) {
        return;
    }
    if (MessageUtils.isPartialResponse(message)) {
        return;
    }
    if (Boolean.TRUE.equals(message.get(RMMessageConstants.RM_RETRANSMISSION))) {
        return;
    }

    if (mode == 1) {
        // never lose
        return;
    } else if (mode == -1) {
        // always lose
    } else {
        // alternatively lose
        synchronized (this) {
            appMessageCount++;
            if (0 != (appMessageCount % 2)) {
                return;
            }
        }
    }

    InterceptorChain chain = message.getInterceptorChain();
    ListIterator<Interceptor<? extends Message>> it = chain.getIterator();
    while (it.hasNext()) {
        PhaseInterceptor<?> pi = (PhaseInterceptor<? extends Message>)it.next();
        if (MessageSenderInterceptor.class.getName().equals(pi.getId())) {
            chain.remove(pi);
            LOG.fine("Removed MessageSenderInterceptor from interceptor chain.");
            break;
        }
    }

    message.setContent(OutputStream.class, new WrappedOutputStream(message));

    message.getInterceptorChain().add(new MessageLossEndingInterceptor(throwsException));
}