Search in sources :

Example 11 with Phase

use of org.apache.cxf.phase.Phase in project cxf by apache.

the class CryptoCoverageCheckerTest method testOrder.

@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"));
}
Also used : PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Phase(org.apache.cxf.phase.Phase) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) ArrayList(java.util.ArrayList) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) TreeSet(java.util.TreeSet) Interceptor(org.apache.cxf.interceptor.Interceptor) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Test(org.junit.Test)

Example 12 with Phase

use of org.apache.cxf.phase.Phase in project tesb-rt-se by Talend.

the class DemoInterceptor method addInterceptors.

/**
 * This method will add a DemoInterceptor into every in and every out phase
 * of the interceptor chains.
 *
 * @param provider
 */
public static void addInterceptors(InterceptorProvider provider) {
    PhaseManager phases = BusFactory.getDefaultBus().getExtension(PhaseManager.class);
    for (Phase p : phases.getInPhases()) {
        provider.getInInterceptors().add(new DemoInterceptor(p.getName()));
        provider.getInFaultInterceptors().add(new DemoInterceptor(p.getName()));
    }
    for (Phase p : phases.getOutPhases()) {
        provider.getOutInterceptors().add(new DemoInterceptor(p.getName()));
        provider.getOutFaultInterceptors().add(new DemoInterceptor(p.getName()));
    }
}
Also used : Phase(org.apache.cxf.phase.Phase) PhaseManager(org.apache.cxf.phase.PhaseManager)

Example 13 with Phase

use of org.apache.cxf.phase.Phase in project cxf by apache.

the class ChainInitiationObserverTest method setUp.

@Before
public void setUp() {
    control = EasyMock.createNiceControl();
    message = control.createMock(Message.class);
    Phase phase1 = new Phase("phase1", 1);
    SortedSet<Phase> phases = new TreeSet<>();
    phases.add(phase1);
    chain = new TestChain(phases);
    observer = new ChainInitiationObserver(null, null);
}
Also used : Phase(org.apache.cxf.phase.Phase) Message(org.apache.cxf.message.Message) TreeSet(java.util.TreeSet) Before(org.junit.Before)

Example 14 with Phase

use of org.apache.cxf.phase.Phase in project cxf by apache.

the class RMInInterceptorTest method testOrdering.

@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());
}
Also used : PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Phase(org.apache.cxf.phase.Phase) Message(org.apache.cxf.message.Message) TreeSet(java.util.TreeSet) MAPAggregator(org.apache.cxf.ws.addressing.MAPAggregator) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Example 15 with Phase

use of org.apache.cxf.phase.Phase in project cxf by apache.

the class ColocMessageObserver method onMessage.

public void onMessage(Message m) {
    Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
    ClassLoaderHolder origLoader = null;
    try {
        if (loader != null) {
            origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
        }
        if (LOG.isLoggable(Level.FINER)) {
            LOG.finer("Processing Message at collocated endpoint.  Request message: " + m);
        }
        Exchange ex = new ExchangeImpl();
        setExchangeProperties(ex, m);
        Message inMsg = endpoint.getBinding().createMessage();
        MessageImpl.copyContent(m, inMsg);
        // Copy Request Context to Server inBound Message
        // TODO a Context Filter Strategy required.
        inMsg.putAll(m);
        inMsg.put(COLOCATED, Boolean.TRUE);
        inMsg.put(Message.REQUESTOR_ROLE, Boolean.FALSE);
        inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
        BindingOperationInfo boi = ex.getBindingOperationInfo();
        OperationInfo oi = boi != null ? boi.getOperationInfo() : null;
        if (oi != null) {
            inMsg.put(MessageInfo.class, oi.getInput());
        }
        ex.setInMessage(inMsg);
        inMsg.setExchange(ex);
        if (LOG.isLoggable(Level.FINEST)) {
            LOG.finest("Build inbound interceptor chain.");
        }
        // Add all interceptors between USER_LOGICAL and INVOKE.
        SortedSet<Phase> phases = new TreeSet<>(bus.getExtension(PhaseManager.class).getInPhases());
        ColocUtil.setPhases(phases, Phase.USER_LOGICAL, Phase.INVOKE);
        InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, phases);
        chain.add(addColocInterceptors());
        inMsg.setInterceptorChain(chain);
        // Convert the coloc object type if necessary
        BindingOperationInfo bop = m.getExchange().getBindingOperationInfo();
        OperationInfo soi = bop != null ? bop.getOperationInfo() : null;
        if (soi != null && oi != null) {
            if (ColocUtil.isAssignableOperationInfo(soi, Source.class) && !ColocUtil.isAssignableOperationInfo(oi, Source.class)) {
                // converting source -> pojo
                ColocUtil.convertSourceToObject(inMsg);
            } else if (ColocUtil.isAssignableOperationInfo(oi, Source.class) && !ColocUtil.isAssignableOperationInfo(soi, Source.class)) {
                // converting pojo -> source
                ColocUtil.convertObjectToSource(inMsg);
            }
        }
        chain.doIntercept(inMsg);
        if (soi != null && oi != null) {
            if (ColocUtil.isAssignableOperationInfo(soi, Source.class) && !ColocUtil.isAssignableOperationInfo(oi, Source.class) && ex.getOutMessage() != null) {
                // converting pojo -> source
                ColocUtil.convertObjectToSource(ex.getOutMessage());
            } else if (ColocUtil.isAssignableOperationInfo(oi, Source.class) && !ColocUtil.isAssignableOperationInfo(soi, Source.class) && ex.getOutMessage() != null) {
                // converting pojo -> source
                ColocUtil.convertSourceToObject(ex.getOutMessage());
            }
        }
        // Set Server OutBound Message onto InBound Exchange.
        setOutBoundMessage(ex, m.getExchange());
    } finally {
        if (origBus != bus) {
            BusFactory.setThreadDefaultBus(origBus);
        }
        if (origLoader != null) {
            origLoader.reset();
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) Bus(org.apache.cxf.Bus) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Phase(org.apache.cxf.phase.Phase) Message(org.apache.cxf.message.Message) TreeSet(java.util.TreeSet) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Source(javax.xml.transform.Source)

Aggregations

Phase (org.apache.cxf.phase.Phase)21 TreeSet (java.util.TreeSet)10 Message (org.apache.cxf.message.Message)10 Test (org.junit.Test)8 PhaseManagerImpl (org.apache.cxf.bus.managers.PhaseManagerImpl)6 Endpoint (org.apache.cxf.endpoint.Endpoint)6 Interceptor (org.apache.cxf.interceptor.Interceptor)6 Exchange (org.apache.cxf.message.Exchange)6 PhaseInterceptorChain (org.apache.cxf.phase.PhaseInterceptorChain)6 Bus (org.apache.cxf.Bus)5 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)5 PhaseManager (org.apache.cxf.phase.PhaseManager)5 ArrayList (java.util.ArrayList)4 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)4 Before (org.junit.Before)4 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)3 Service (org.apache.cxf.service.Service)3 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)3 MustUnderstandInterceptor (org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor)2 SAAJInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor)2