Search in sources :

Example 1 with AbstractPhaseInterceptor

use of org.apache.cxf.phase.AbstractPhaseInterceptor in project camel by apache.

the class RawMessageWSDLGetInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    String method = (String) message.get(Message.HTTP_REQUEST_METHOD);
    String query = (String) message.get(Message.QUERY_STRING);
    if (!"GET".equals(method) || StringUtils.isEmpty(query)) {
        return;
    }
    String baseUri = (String) message.get(Message.REQUEST_URL);
    String ctx = (String) message.get(Message.PATH_INFO);
    Map<String, String> map = UrlUtils.parseQueryString(query);
    if (isRecognizedQuery(map, baseUri, ctx, message.getExchange().getEndpoint().getEndpointInfo())) {
        Document doc = getDocument(message, baseUri, map, ctx);
        Endpoint e = message.getExchange().get(Endpoint.class);
        Message mout = new MessageImpl();
        mout.setExchange(message.getExchange());
        mout = e.getBinding().createMessage(mout);
        mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange()));
        message.getExchange().setOutMessage(mout);
        mout.put(DOCUMENT_HOLDER, doc);
        Iterator<Interceptor<? extends Message>> iterator = mout.getInterceptorChain().iterator();
        while (iterator.hasNext()) {
            Interceptor<? extends Message> inInterceptor = iterator.next();
            if (inInterceptor instanceof AbstractPhaseInterceptor) {
                AbstractPhaseInterceptor<?> interceptor = (AbstractPhaseInterceptor<?>) inInterceptor;
                if (interceptor.getPhase().equals(Phase.PREPARE_SEND) || interceptor.getPhase().equals(Phase.PRE_STREAM)) {
                    // just make sure we keep the right interceptors
                    continue;
                }
            }
            mout.getInterceptorChain().remove(inInterceptor);
        }
        // notice this is being added after the purge above, don't swap the order!
        mout.getInterceptorChain().add(RawMessageWSDLGetOutInterceptor.INSTANCE);
        // skip the service executor and goto the end of the chain.
        message.getInterceptorChain().doInterceptStartingAt(message, OutgoingChainInterceptor.class.getName());
    }
}
Also used : Endpoint(org.apache.cxf.endpoint.Endpoint) Message(org.apache.cxf.message.Message) OutgoingChainInterceptor(org.apache.cxf.interceptor.OutgoingChainInterceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Document(org.w3c.dom.Document) MessageImpl(org.apache.cxf.message.MessageImpl) Interceptor(org.apache.cxf.interceptor.Interceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) EndpointSelectionInterceptor(org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor) OutgoingChainInterceptor(org.apache.cxf.interceptor.OutgoingChainInterceptor)

Example 2 with AbstractPhaseInterceptor

use of org.apache.cxf.phase.AbstractPhaseInterceptor 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)

Aggregations

Interceptor (org.apache.cxf.interceptor.Interceptor)2 Message (org.apache.cxf.message.Message)2 AbstractPhaseInterceptor (org.apache.cxf.phase.AbstractPhaseInterceptor)2 IOException (java.io.IOException)1 EndpointSelectionInterceptor (org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 Fault (org.apache.cxf.interceptor.Fault)1 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)1 MessageSenderInterceptor (org.apache.cxf.interceptor.MessageSenderInterceptor)1 OutgoingChainInterceptor (org.apache.cxf.interceptor.OutgoingChainInterceptor)1 AbstractWrappedOutputStream (org.apache.cxf.io.AbstractWrappedOutputStream)1 MessageImpl (org.apache.cxf.message.MessageImpl)1 PhaseInterceptor (org.apache.cxf.phase.PhaseInterceptor)1 Document (org.w3c.dom.Document)1