Search in sources :

Example 1 with MessageSenderInterceptor

use of org.apache.cxf.interceptor.MessageSenderInterceptor 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 MessageSenderInterceptor

use of org.apache.cxf.interceptor.MessageSenderInterceptor in project cxf by apache.

the class MessageLossSimulator method handleMessage.

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));
}
Also used : InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Message(org.apache.cxf.message.Message) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) MessageSenderInterceptor(org.apache.cxf.interceptor.MessageSenderInterceptor) AbstractWrappedOutputStream(org.apache.cxf.io.AbstractWrappedOutputStream) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) 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 3 with MessageSenderInterceptor

use of org.apache.cxf.interceptor.MessageSenderInterceptor in project cxf by apache.

the class MessageLossSimulator method handleMessage.

// CHECKSTYLE:OFF: ReturnCount
public void handleMessage(Message message) throws Fault {
    AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true);
    // Fixed the build error of ws_rm, now there is no ensureExposedVersion anymore
    // RMContextUtils.ensureExposedVersion(maps);
    String action = null;
    if (maps != null && null != maps.getAction()) {
        action = maps.getAction().getValue();
    }
    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<? extends Message> pi = (PhaseInterceptor<? extends Message>) it.next();
        if (MessageSenderInterceptor.class.getName().equals(pi.getId())) {
            chain.remove(pi);
            LOG.info("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) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) Interceptor(org.apache.cxf.interceptor.Interceptor) MessageSenderInterceptor(org.apache.cxf.interceptor.MessageSenderInterceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor)

Aggregations

Interceptor (org.apache.cxf.interceptor.Interceptor)3 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)3 MessageSenderInterceptor (org.apache.cxf.interceptor.MessageSenderInterceptor)3 AbstractWrappedOutputStream (org.apache.cxf.io.AbstractWrappedOutputStream)3 Message (org.apache.cxf.message.Message)3 AbstractPhaseInterceptor (org.apache.cxf.phase.AbstractPhaseInterceptor)3 PhaseInterceptor (org.apache.cxf.phase.PhaseInterceptor)3 IOException (java.io.IOException)2 Fault (org.apache.cxf.interceptor.Fault)2 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)2