Search in sources :

Example 16 with Phase

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

the class ColocOutInterceptor method invokeInboundChain.

protected void invokeInboundChain(Exchange ex, Endpoint ep) {
    Message m = getInBoundMessage(ex);
    Message inMsg = ep.getBinding().createMessage();
    MessageImpl.copyContent(m, inMsg);
    // Copy Response Context to Client inBound Message
    // TODO a Context Filter Strategy required.
    inMsg.putAll(m);
    inMsg.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
    inMsg.setExchange(ex);
    Exception exc = inMsg.getContent(Exception.class);
    if (exc != null) {
        ex.setInFaultMessage(inMsg);
        ColocInFaultObserver observer = new ColocInFaultObserver(bus);
        observer.onMessage(inMsg);
    } else {
        // Handle Response
        ex.setInMessage(inMsg);
        PhaseManager pm = bus.getExtension(PhaseManager.class);
        SortedSet<Phase> phases = new TreeSet<>(pm.getInPhases());
        ColocUtil.setPhases(phases, Phase.USER_LOGICAL, Phase.PRE_INVOKE);
        InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, phases);
        inMsg.setInterceptorChain(chain);
        chain.doIntercept(inMsg);
    }
    ex.put(ClientImpl.FINISHED, Boolean.TRUE);
}
Also used : InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) Phase(org.apache.cxf.phase.Phase) Message(org.apache.cxf.message.Message) PhaseManager(org.apache.cxf.phase.PhaseManager) TreeSet(java.util.TreeSet)

Example 17 with Phase

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

the class ColocInInterceptor method handleMessage.

public void handleMessage(Message msg) throws Fault {
    Exchange ex = msg.getExchange();
    if (ex.isOneWay()) {
        return;
    }
    Bus bus = ex.getBus();
    SortedSet<Phase> phases = new TreeSet<>(bus.getExtension(PhaseManager.class).getOutPhases());
    // TODO Set Coloc FaultObserver chain
    ColocUtil.setPhases(phases, Phase.SETUP, Phase.USER_LOGICAL);
    InterceptorChain chain = ColocUtil.getOutInterceptorChain(ex, phases);
    if (LOG.isLoggable(Level.FINER)) {
        LOG.finer("Processing Message at collocated endpoint.  Response message: " + msg);
    }
    // Initiate OutBound Processing
    BindingOperationInfo boi = ex.getBindingOperationInfo();
    Message outBound = ex.getOutMessage();
    if (boi != null) {
        outBound.put(MessageInfo.class, boi.getOperationInfo().getOutput());
    }
    outBound.put(Message.INBOUND_MESSAGE, Boolean.FALSE);
    outBound.setInterceptorChain(chain);
    chain.doIntercept(outBound);
}
Also used : Exchange(org.apache.cxf.message.Exchange) 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)

Example 18 with Phase

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

the class ColocUtil method setPhases.

public static void setPhases(SortedSet<Phase> list, String start, String end) {
    Phase startPhase = new Phase(start, 1);
    Phase endPhase = new Phase(end, 2);
    Iterator<Phase> iter = list.iterator();
    boolean remove = true;
    while (iter.hasNext()) {
        Phase p = iter.next();
        if (remove && p.getName().equals(startPhase.getName())) {
            remove = false;
        } else if (p.getName().equals(endPhase.getName())) {
            remove = true;
        } else if (remove) {
            iter.remove();
        }
    }
}
Also used : Phase(org.apache.cxf.phase.Phase)

Example 19 with Phase

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

the class ColocUtilTest method testSetColocInPhases.

@Test
public void testSetColocInPhases() throws Exception {
    PhaseManagerImpl phaseMgr = new PhaseManagerImpl();
    SortedSet<Phase> list = phaseMgr.getInPhases();
    int size1 = list.size();
    ColocUtil.setPhases(list, Phase.USER_LOGICAL, Phase.INVOKE);
    assertNotSame("The list size should not be same", size1, list.size());
    assertEquals("Expecting Phase.USER_LOGICAL", list.first().getName(), Phase.USER_LOGICAL);
    assertEquals("Expecting Phase.POST_INVOKE", list.last().getName(), Phase.INVOKE);
}
Also used : Phase(org.apache.cxf.phase.Phase) PhaseManagerImpl(org.apache.cxf.bus.managers.PhaseManagerImpl) Endpoint(org.apache.cxf.endpoint.Endpoint) Test(org.junit.Test)

Example 20 with Phase

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

the class WSS4JInOutTest 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());
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    chain.add(lst);
    String output = chain.toString();
    assertTrue(output.contains("MustUnderstandInterceptor, SAAJInInterceptor, WSS4JInInterceptor"));
}
Also used : SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) 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) SOAPMessage(javax.xml.soap.SOAPMessage) TreeSet(java.util.TreeSet) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) ArrayList(java.util.ArrayList) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) MustUnderstandInterceptor(org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) Test(org.junit.Test)

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