Package org.apache.cxf.phase

Examples of org.apache.cxf.phase.PhaseInterceptorChain


    protected Message createMessage(Message message) {
        return message;
    }

    protected PhaseInterceptorChain createChain() {
        PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class)
            .getInPhases());
        return chain;
    }
View Full Code Here


    public void onMessage(Message m) {
        Bus origBus = BusFactory.getThreadDefaultBus(false);
        BusFactory.setThreadDefaultBus(bus);
        try {
            PhaseInterceptorChain phaseChain = null;
           
            if (m.getInterceptorChain() instanceof PhaseInterceptorChain) {
                phaseChain = (PhaseInterceptorChain)m.getInterceptorChain();
                if (phaseChain.getState() == InterceptorChain.State.PAUSED) {
                    phaseChain.resume();
                    return;
                }
            }
           
            Message message = getBinding().createMessage(m);
            Exchange exchange = message.getExchange();
            if (exchange == null) {
                exchange = new ExchangeImpl();
                exchange.setInMessage(message);
            }
            setExchangeProperties(exchange, message);
   
            // setup chain
            phaseChain = chainCache.get(bus.getExtension(PhaseManager.class).getInPhases(),
                                                         bus.getInInterceptors(),
                                                         endpoint.getService().getInInterceptors(),
                                                         endpoint.getInInterceptors(),
                                                         getBinding().getInInterceptors());
           
           
            message.setInterceptorChain(phaseChain);
           
            phaseChain.setFaultObserver(endpoint.getOutFaultObserver());
          
            phaseChain.doIntercept(message);
        } finally {
            BusFactory.setThreadDefaultBus(origBus);
        }
    }
View Full Code Here

            setOutMessageProperties(message, oi);
            setExchangeProperties(exchange, endpoint, oi);
           
            // setup chain
   
            PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
            message.setInterceptorChain(chain);
           
            modifyChain(chain, reqContext);
            chain.setFaultObserver(outFaultObserver);
           
            // setup conduit selector
            prepareConduitSelector(message);
           
            // execute chain       
            chain.doIntercept(message);

        } finally {
            BusFactory.setThreadDefaultBus(origBus);
        }      
    }
View Full Code Here

            setOutMessageProperties(message, oi);
            setExchangeProperties(exchange, endpoint, oi);
           
            // setup chain
   
            PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
            message.setInterceptorChain(chain);
           
            modifyChain(chain, reqContext);
            chain.setFaultObserver(outFaultObserver);
           
            // setup conduit selector
            prepareConduitSelector(message);
           
            // execute chain       
            chain.doIntercept(message);
   
            return processResult(message, exchange, oi, resContext);
           
        } finally {
            BusFactory.setThreadDefaultBus(origBus);
View Full Code Here

            new ArrayList<Interceptor>();
        lst.add(new MustUnderstandInterceptor());
        lst.add(new WSS4JInInterceptor());
        lst.add(new SAAJInInterceptor());
        lst.add(new CryptoCoverageChecker());
        PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
        chain.add(lst);
        String output = chain.toString();
        assertTrue(output.contains("MustUnderstandInterceptor, SAAJInInterceptor, "
                + "WSS4JInInterceptor, CryptoCoverageChecker"));
    }
View Full Code Here

        // no need for the underlying conduit to throw the IO exceptions in case of
        // client requests returning error HTTP code, it can be overridden if really needed
        exchange.put("org.apache.cxf.http.no_io_exceptions", true);
        m.setExchange(exchange);
       
        PhaseInterceptorChain chain = setupOutInterceptorChain(cfg);
        m.setInterceptorChain(chain);
       
        // context
        if (cfg.getRequestContext().size() > 0 || cfg.getResponseContext().size() > 0) {
            Map<String, Object> context = new HashMap<String, Object>();
View Full Code Here

    private void doResend(SoapMessage message) {
        try {
           
            // initialize copied interceptor chain for message
            PhaseInterceptorChain retransmitChain = manager.getRetransmitChain(message);
            ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
            Endpoint endpoint = manager.getReliableEndpoint(message).getEndpoint(protocol);
            PhaseChainCache cache = new PhaseChainCache();
            boolean after = true;
            if (retransmitChain == null) {
               
                // no saved retransmit chain, so construct one from scratch (won't work for WS-Security on server, so
                //  need to fix)
                retransmitChain = buildRetransmitChain(endpoint, cache);
                after = false;

            }
            message.setInterceptorChain(retransmitChain);
           
            // clear flag for SOAP out interceptor so envelope will be written
            message.remove(SoapOutInterceptor.WROTE_ENVELOPE_START);
           
            // discard all saved content
            Set<Class<?>> formats = message.getContentFormats();
            List<CachedOutputStreamCallback> callbacks = null;
            for (Class<?> clas: formats) {
                Object content = message.getContent(clas);
                if (content != null) {
                    LOG.info("Removing " + clas.getName() + " content of actual type " + content.getClass().getName());
                    message.removeContent(clas);
                    if (clas == OutputStream.class && content instanceof WriteOnCloseOutputStream) {
                        callbacks = ((WriteOnCloseOutputStream)content).getCallbacks();
                    }
                }
            }
           
            // read SOAP headers from saved input stream
            RewindableInputStream is = (RewindableInputStream)message.get(RMMessageConstants.SAVED_CONTENT);
            is.rewind();
            XMLStreamReader reader = StaxUtils.createXMLStreamReader(is, "UTF-8");
            message.getHeaders().clear();
            if (reader.getEventType() != XMLStreamConstants.START_ELEMENT
                && reader.nextTag() != XMLStreamConstants.START_ELEMENT) {
                throw new IllegalStateException("No document found");
            }
            readHeaders(reader, message);
            int event;
            while ((event = reader.nextTag()) != XMLStreamConstants.START_ELEMENT) {
                if (event == XMLStreamConstants.END_ELEMENT) {
                    throw new IllegalStateException("No body content present");
                }
            }
           
            // set message addressing properties
            AddressingProperties maps = new MAPCodec().unmarshalMAPs(message);
            RMContextUtils.storeMAPs(maps, message, true, MessageUtils.isRequestor(message));
            AttributedURIType to = null;
            if (null != maps) {
                to = maps.getTo();
            }
            if (null == to) {
                LOG.log(Level.SEVERE, "NO_ADDRESS_FOR_RESEND_MSG");
                return;
            }
            if (RMUtils.getAddressingConstants().getAnonymousURI().equals(to.getValue())) {
                LOG.log(Level.FINE, "Cannot resend to anonymous target");
                return;
            }
           
            // initialize conduit for new message
            Conduit c = message.getExchange().getConduit(message);
            if (c == null) {
                c = buildConduit(message, endpoint, to);
            }
            c.prepare(message);
           
            // replace standard message marshaling with copy from saved stream
            ListIterator<Interceptor<? extends Message>> iterator = retransmitChain.getIterator();
            while (iterator.hasNext()) {
                Interceptor<? extends Message> incept = iterator.next();
               
                // remove JAX-WS interceptors which handle message modes and such
                if (incept.getClass().getName().startsWith("org.apache.cxf.jaxws.interceptors")) {
                    retransmitChain.remove(incept);
                } else if (incept instanceof PhaseInterceptor
                    && (((PhaseInterceptor<?>)incept).getPhase() == Phase.MARSHAL)) {
                   
                    // remove any interceptors from the marshal phase
                    retransmitChain.remove(incept);
                }
            }
            retransmitChain.add(new CopyOutInterceptor(reader));
           
            // restore callbacks on output stream
            if (callbacks != null) {
                OutputStream os = message.getContent(OutputStream.class);
                if (os != null) {
                    WriteOnCloseOutputStream woc;
                    if (os instanceof WriteOnCloseOutputStream) {
                        woc = (WriteOnCloseOutputStream)os;
                    } else {
                        woc = new WriteOnCloseOutputStream(os);
                        message.setContent(OutputStream.class, woc);
                    }
                    for (CachedOutputStreamCallback cb: callbacks) {
                        woc.registerCallback(cb);
                    }
                }
            }
           
            // send the message
            message.put(RMMessageConstants.RM_RETRANSMISSION, Boolean.TRUE);
            if (after) {
                retransmitChain.doInterceptStartingAfter(message, RMCaptureOutInterceptor.class.getName());
            } else {
                retransmitChain.doIntercept(message);
            }
            if (LOG.isLoggable(Level.INFO)) {
                RMProperties rmps = RMContextUtils.retrieveRMProperties(message, true);
                SequenceType seq = rmps.getSequence();
                LOG.log(Level.INFO, "Retransmitted message " + seq.getMessageNumber() + " in sequence "
View Full Code Here

     * @param endpoint
     * @param cache
     * @return
     */
    protected PhaseInterceptorChain buildRetransmitChain(final Endpoint endpoint, PhaseChainCache cache) {
        PhaseInterceptorChain retransmitChain;
        Bus bus = getManager().getBus();
        List<Interceptor<? extends Message>> i1 = bus.getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by bus: " + i1);
        }
View Full Code Here

   
    public static InterceptorChain getOutInterceptorChain(Exchange ex) {
        Bus bus = ex.get(Bus.class);
        Binding binding = ex.get(Binding.class);
        PhaseManager pm = bus.getExtension(PhaseManager.class);
        PhaseInterceptorChain chain = new PhaseInterceptorChain(pm.getOutPhases());
       
        Endpoint ep = ex.get(Endpoint.class);
        List<Interceptor<? extends Message>> il = ep.getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by endpoint: " + il);
        }
        chain.add(il);
        il = ep.getService().getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by service: " + il);
        }
        chain.add(il);
        il = bus.getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by bus: " + il);
        }
        chain.add(il);       
        if (binding != null) {
            il = binding.getOutInterceptors();
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Interceptors contributed by binding: " + il);
            }
            chain.add(il);
        }
        modifyChain(chain, ex);
        chain.setFaultObserver(ep.getOutFaultObserver());
        return chain;
    }
View Full Code Here

            if (i4 == null) {
                i4 = i5;
                i5 = null;
            }
        }
        PhaseInterceptorChain chain;
        if (i5 != null) {
            chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(),
                                   i1, i2, i3, i4, i5);
        } else if (i4 != null) {
            chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(),
                                   i1, i2, i3, i4);
        } else {
            chain = chainCache.get(bus.getExtension(PhaseManager.class).getOutPhases(),
                                   i1, i2, i3);
        }
       
        modifyChain(chain, ex);
        chain.setFaultObserver(ep.getOutFaultObserver());
        return chain;
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.phase.PhaseInterceptorChain

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.