Java Code Examples for org.apache.cxf.phase.PhaseInterceptorChain#add()

The following examples show how to use org.apache.cxf.phase.PhaseInterceptorChain#add() . 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: OutFaultChainInitiatorObserver.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void addToChain(PhaseInterceptorChain chain, Message m) {
    Collection<InterceptorProvider> providers
        = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
    if (providers != null) {
        for (InterceptorProvider p : providers) {
            chain.add(p.getOutFaultInterceptors());
        }
    }
    Collection<Interceptor<? extends Message>> is
        = CastUtils.cast((Collection<?>)m.get(Message.FAULT_OUT_INTERCEPTORS));
    if (is != null) {
        chain.add(is);
    }
    if (m.getDestination() instanceof InterceptorProvider) {
        chain.add(((InterceptorProvider)m.getDestination()).getOutFaultInterceptors());
    }
}
 
Example 2
Source File: CryptoCoverageCheckerTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrder() throws Exception {
    //make sure the interceptors get ordered correctly
    SortedSet<Phase> phases = new TreeSet<Phase>();
    phases.add(new Phase(Phase.PRE_PROTOCOL, 1));
    
    List<Interceptor<? extends Message>> lst = 
        new ArrayList<Interceptor<? extends Message>>();
    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"));
}
 
Example 3
Source File: OutFaultChainInitiatorObserver.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void initializeInterceptors(Exchange ex, PhaseInterceptorChain chain) {
    Endpoint e = ex.getEndpoint();
    Client c = ex.get(Client.class);

    chain.add(getBus().getOutFaultInterceptors());
    if (c != null) {
        chain.add(c.getOutFaultInterceptors());
    }
    chain.add(e.getService().getOutFaultInterceptors());
    chain.add(e.getOutFaultInterceptors());
    chain.add(e.getBinding().getOutFaultInterceptors());
    if (e.getService().getDataBinding() instanceof InterceptorProvider) {
        chain.add(((InterceptorProvider)e.getService().getDataBinding()).getOutFaultInterceptors());
    }

    addToChain(chain, ex.getInMessage());
    addToChain(chain, ex.getOutFaultMessage());
}
 
Example 4
Source File: CryptoCoverageCheckerTest.java    From steady with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrder() throws Exception {
    //make sure the interceptors get ordered correctly
    SortedSet<Phase> phases = new TreeSet<Phase>();
    phases.add(new Phase(Phase.PRE_PROTOCOL, 1));
    
    List<Interceptor<? extends Message>> lst = 
        new ArrayList<Interceptor<? extends Message>>();
    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"));
}
 
Example 5
Source File: OutgoingChainInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static void modifyChain(PhaseInterceptorChain chain, Message m) {
    if (m == null) {
        return;
    }
    Collection<InterceptorProvider> providers
        = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
    if (providers != null) {
        for (InterceptorProvider p : providers) {
            chain.add(p.getOutInterceptors());
        }
    }
    Collection<Interceptor<? extends Message>> is
        = CastUtils.cast((Collection<?>)m.get(Message.OUT_INTERCEPTORS));
    if (is != null) {
        chain.add(is);
    }
    if (m.getDestination() instanceof InterceptorProvider) {
        chain.add(((InterceptorProvider)m.getDestination()).getOutInterceptors());
    }
}
 
Example 6
Source File: CryptoCoverageCheckerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrder() throws Exception {
    //make sure the interceptors get ordered correctly
    SortedSet<Phase> phases = new TreeSet<>();
    phases.add(new Phase(Phase.PRE_PROTOCOL, 1));

    List<Interceptor<? extends Message>> lst = new ArrayList<>();
    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"));
}
 
Example 7
Source File: ColocUtil.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static void modifyChain(PhaseInterceptorChain chain, Message m, boolean in) {
    if (m == null) {
        return;
    }
    Collection<InterceptorProvider> providers
        = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
    if (providers != null) {
        for (InterceptorProvider p : providers) {
            if (in) {
                chain.add(p.getInInterceptors());
            } else {
                chain.add(p.getOutInterceptors());
            }
        }
    }
    String key = in ? Message.IN_INTERCEPTORS : Message.OUT_INTERCEPTORS;
    Collection<Interceptor<? extends Message>> is
        = CastUtils.cast((Collection<?>)m.get(key));
    if (is != null) {
        chain.add(is);
    }
}
 
Example 8
Source File: RMInInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrdering() {
    control.replay();
    Phase p = new Phase(Phase.PRE_LOGICAL, 1);
    SortedSet<Phase> phases = new TreeSet<>();
    phases.add(p);
    PhaseInterceptorChain chain =
        new PhaseInterceptorChain(phases);
    MAPAggregator map = new MAPAggregator();
    RMInInterceptor rmi = new RMInInterceptor();
    chain.add(rmi);
    chain.add(map);
    Iterator<Interceptor<? extends Message>> it = chain.iterator();
    assertSame("Unexpected order.", rmi, it.next());
    assertSame("Unexpected order.", map, it.next());

}
 
Example 9
Source File: OutgoingChainInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static InterceptorChain getOutInterceptorChain(Exchange ex) {
    Bus bus = ex.getBus();
    Binding binding = ex.getBinding();
    PhaseManager pm = bus.getExtension(PhaseManager.class);
    PhaseInterceptorChain chain = new PhaseInterceptorChain(pm.getOutPhases());

    Endpoint ep = ex.getEndpoint();
    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;
}
 
Example 10
Source File: WSS4JInOutTest.java    From steady with Apache License 2.0 5 votes vote down vote up
@Test
public void testOrder() throws Exception {
    //make sure the interceptors get ordered correctly
    SortedSet<Phase> phases = new TreeSet<Phase>();
    phases.add(new Phase(Phase.PRE_PROTOCOL, 1));
    
    List<Interceptor<? extends Message>> lst = new ArrayList<Interceptor<? extends Message>>();
    lst.add(new MustUnderstandInterceptor());
    lst.add(new WSS4JInInterceptor());
    lst.add(new SAAJInInterceptor());
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    chain.add(lst);
    String output = chain.toString();
    assertTrue(output.contains("MustUnderstandInterceptor, SAAJInInterceptor, WSS4JInInterceptor"));
}
 
Example 11
Source File: InFaultChainInitiatorObserver.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addToChain(PhaseInterceptorChain chain, Message m) {
    Collection<InterceptorProvider> providers
        = CastUtils.cast((Collection<?>)m.get(Message.INTERCEPTOR_PROVIDERS));
    if (providers != null) {
        for (InterceptorProvider p : providers) {
            chain.add(p.getInFaultInterceptors());
        }
    }
    Collection<Interceptor<? extends Message>> is
        = CastUtils.cast((Collection<?>)m.get(Message.FAULT_IN_INTERCEPTORS));
    if (is != null) {
        chain.add(is);
    }
}
 
Example 12
Source File: AbstractClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected static PhaseInterceptorChain setupOutInterceptorChain(ClientConfiguration cfg) {
    PhaseManager pm = cfg.getBus().getExtension(PhaseManager.class);
    List<Interceptor<? extends Message>> i1 = cfg.getBus().getOutInterceptors();
    List<Interceptor<? extends Message>> i2 = cfg.getOutInterceptors();
    List<Interceptor<? extends Message>> i3 = cfg.getConduitSelector().getEndpoint().getOutInterceptors();
    PhaseInterceptorChain chain = new PhaseChainCache().get(pm.getOutPhases(), i1, i2, i3);
    chain.add(new ClientRequestFilterInterceptor());
    return chain;
}
 
Example 13
Source File: ColocUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static InterceptorChain getInInterceptorChain(Exchange ex, SortedSet<Phase> phases) {
    Bus bus = ex.getBus();
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);

    Endpoint ep = ex.getEndpoint();
    List<Interceptor<? extends Message>> il = ep.getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by endpoint: " + il);
    }
    chain.add(il);
    il = ep.getService().getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by service: " + il);
    }
    chain.add(il);
    il = bus.getInInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by bus: " + il);
    }
    chain.add(il);

    if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        il = ((InterceptorProvider)ep.getService().getDataBinding()).getInInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by databinding: " + il);
        }
        chain.add(il);
    }
    chain.setFaultObserver(new ColocOutFaultObserver(bus));
    modifyChain(chain, ex, true);
    return chain;
}
 
Example 14
Source File: ColocUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static InterceptorChain getOutInterceptorChain(Exchange ex, SortedSet<Phase> phases) {
    Bus bus = ex.getBus();
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);

    Endpoint ep = ex.getEndpoint();
    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 (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        il = ((InterceptorProvider)ep.getService().getDataBinding()).getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by databinding: " + il);
        }
        chain.add(il);
    }
    modifyChain(chain, ex, false);

    return chain;
}
 
Example 15
Source File: RedeliveryQueueImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void addInterceptors(PhaseInterceptorChain chain,
                                    List<Interceptor<? extends Message>> il) {
    for (Interceptor<? extends Message> i : il) {
        final String iname = i.getClass().getSimpleName();
        if ("OneWayProcessorInterceptor".equals(iname)
            || "MAPAggregatorImpl".equals(iname)
            || "RMInInterceptor".equals(iname)) {
            continue;
        }
        chain.add(i);
    }
}
 
Example 16
Source File: WSS4JInOutTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testOrder() throws Exception {
    //make sure the interceptors get ordered correctly
    SortedSet<Phase> phases = new TreeSet<>();
    phases.add(new Phase(Phase.PRE_PROTOCOL, 1));

    List<Interceptor<? extends Message>> lst = new ArrayList<>();
    lst.add(new MustUnderstandInterceptor());
    lst.add(new WSS4JInInterceptor());
    lst.add(new SAAJInInterceptor());
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    chain.add(lst);
    String output = chain.toString();
    assertTrue(output.contains("MustUnderstandInterceptor, SAAJInInterceptor, WSS4JInInterceptor"));
}
 
Example 17
Source File: EjbInterceptor.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static void copyDataBindingInterceptors(PhaseInterceptorChain newChain, InterceptorChain oldChain) {
    for (Interceptor interceptor : oldChain) {
        if (interceptor instanceof AbstractInDatabindingInterceptor) {
            log.debug("Added data binding interceptor: " + interceptor);
            newChain.add(interceptor);
        }
    }
}
 
Example 18
Source File: WSS4JInOutTest.java    From steady with Apache License 2.0 5 votes vote down vote up
@Test
public void testOrder() throws Exception {
    //make sure the interceptors get ordered correctly
    SortedSet<Phase> phases = new TreeSet<Phase>();
    phases.add(new Phase(Phase.PRE_PROTOCOL, 1));
    
    List<Interceptor<? extends Message>> lst = new ArrayList<Interceptor<? extends Message>>();
    lst.add(new MustUnderstandInterceptor());
    lst.add(new WSS4JInInterceptor());
    lst.add(new SAAJInInterceptor());
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    chain.add(lst);
    String output = chain.toString();
    assertTrue(output.contains("MustUnderstandInterceptor, SAAJInInterceptor, WSS4JInInterceptor"));
}
 
Example 19
Source File: WSS4JInOutTest.java    From steady with Apache License 2.0 5 votes vote down vote up
@Test
public void testOrder() throws Exception {
    //make sure the interceptors get ordered correctly
    SortedSet<Phase> phases = new TreeSet<Phase>();
    phases.add(new Phase(Phase.PRE_PROTOCOL, 1));
    
    List<Interceptor<? extends Message>> lst = new ArrayList<Interceptor<? extends Message>>();
    lst.add(new MustUnderstandInterceptor());
    lst.add(new WSS4JInInterceptor());
    lst.add(new SAAJInInterceptor());
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    chain.add(lst);
    String output = chain.toString();
    assertTrue(output.contains("MustUnderstandInterceptor, SAAJInInterceptor, WSS4JInInterceptor"));
}
 
Example 20
Source File: EjbInterceptor.java    From tomee with Apache License 2.0 4 votes vote down vote up
@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;
    }
}