org.apache.cxf.phase.PhaseManager Java Examples

The following examples show how to use org.apache.cxf.phase.PhaseManager. 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: ProtobufClient.java    From fuchsia with Apache License 2.0 6 votes vote down vote up
protected InterceptorChain setupInterceptorChain(Exchange exchange) {
    if (outgoingInterceptorChain != null) {
        return outgoingInterceptorChain;
    }

    Endpoint endpoint = getEndpoint(exchange);

    PhaseManager pm = bus.getExtension(PhaseManager.class);
    @SuppressWarnings("unchecked")
    List<Interceptor<? extends org.apache.cxf.message.Message>> i1 = bus.getOutInterceptors();
    @SuppressWarnings("unchecked")
    List<Interceptor<? extends org.apache.cxf.message.Message>> i2 = endpoint.getOutInterceptors();
    @SuppressWarnings("unchecked")
    List<Interceptor<? extends org.apache.cxf.message.Message>> i3 = getOutInterceptors();
    @SuppressWarnings("unchecked")
    List<Interceptor<? extends org.apache.cxf.message.Message>> i4 = endpoint.getBinding().getOutInterceptors();

    PhaseInterceptorChain phaseInterceptorChain = outboundChainCache.get(pm
            .getOutPhases(), i1, i2, i3, i4);
    return phaseInterceptorChain;
}
 
Example #2
Source File: CXFBusImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstructionWithExtensions() throws BusException {

    IMocksControl control;
    BindingFactoryManager bindingFactoryManager;
    InstrumentationManager instrumentationManager;
    PhaseManager phaseManager;

    control = EasyMock.createNiceControl();

    Map<Class<?>, Object> extensions = new HashMap<>();
    bindingFactoryManager = control.createMock(BindingFactoryManager.class);
    instrumentationManager = control.createMock(InstrumentationManager.class);
    phaseManager = control.createMock(PhaseManager.class);

    extensions.put(BindingFactoryManager.class, bindingFactoryManager);
    extensions.put(InstrumentationManager.class, instrumentationManager);
    extensions.put(PhaseManager.class, phaseManager);

    Bus bus = new ExtensionManagerBus(extensions);

    assertSame(bindingFactoryManager, bus.getExtension(BindingFactoryManager.class));
    assertSame(instrumentationManager, bus.getExtension(InstrumentationManager.class));
    assertSame(phaseManager, bus.getExtension(PhaseManager.class));

}
 
Example #3
Source File: RetransmissionQueueImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * @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);
    }
    List<Interceptor<? extends Message>> i2 = endpoint.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by endpoint: " + i2);
    }
    List<Interceptor<? extends Message>> i3 = endpoint.getBinding().getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by binding: " + i3);
    }
    PhaseManager pm = bus.getExtension(PhaseManager.class);
    retransmitChain = cache.get(pm.getOutPhases(), i1, i2, i3);
    return retransmitChain;
}
 
Example #4
Source File: WebClientSubstitution.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Substitute
static JAXRSClientFactoryBean getBean(String baseAddress, String configLocation) {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    // configLocation is always null and no need to create SpringBusFactory.
    CXFBusFactory bf = new CXFBusFactory();

    // It can not load the extensions from the bus-extensions.txt dynamically.
    // So have to set all of necessary ones here.
    List<Extension> extensions = new ArrayList<>();
    Extension http = new Extension();
    http.setClassname(HTTPTransportFactory.class.getName());
    http.setDeferred(true);
    extensions.add(http);
    ExtensionRegistry.addExtensions(extensions);

    Bus bus = bf.createBus();
    bus.setExtension(new PhaseManagerImpl(), PhaseManager.class);
    bus.setExtension(new ClientLifeCycleManagerImpl(), ClientLifeCycleManager.class);
    bus.setExtension(new ConduitInitiatorManagerImpl(bus), ConduitInitiatorManager.class);

    bean.setBus(bus);
    bean.setAddress(baseAddress);
    return bean;
}
 
Example #5
Source File: AbstractClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected static PhaseInterceptorChain setupInInterceptorChain(ClientConfiguration cfg) {
    PhaseManager pm = cfg.getBus().getExtension(PhaseManager.class);
    List<Interceptor<? extends Message>> i1 = cfg.getBus().getInInterceptors();
    List<Interceptor<? extends Message>> i2 = cfg.getInInterceptors();
    List<Interceptor<? extends Message>> i3 = cfg.getConduitSelector().getEndpoint().getInInterceptors();
    PhaseInterceptorChain chain = new PhaseChainCache().get(pm.getInPhases(), i1, i2, i3);
    chain.add(new ClientResponseFilterInterceptor());
    chain.setFaultObserver(setupInFaultObserver(cfg));
    return chain;
}
 
Example #6
Source File: CXFBusImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testConstructionWithoutExtensions() throws BusException {

    Bus bus = new ExtensionManagerBus();
    assertNotNull(bus.getExtension(BindingFactoryManager.class));
    assertNotNull(bus.getExtension(ConduitInitiatorManager.class));
    assertNotNull(bus.getExtension(DestinationFactoryManager.class));
    assertNotNull(bus.getExtension(PhaseManager.class));
    bus.shutdown(true);
}
 
Example #7
Source File: SpringBusFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testPhases() {
    Bus bus = new SpringBusFactory().createBus();
    PhaseManager cxfPM = bus.getExtension(PhaseManager.class);
    PhaseManager defaultPM = new PhaseManagerImpl();
    SortedSet<Phase> cxfPhases = cxfPM.getInPhases();
    SortedSet<Phase> defaultPhases = defaultPM.getInPhases();
    assertEquals(defaultPhases.size(), cxfPhases.size());
    assertEquals(cxfPhases, defaultPhases);
    cxfPhases = cxfPM.getOutPhases();
    defaultPhases = defaultPM.getOutPhases();
    assertEquals(defaultPhases.size(), cxfPhases.size());
    assertEquals(cxfPhases, defaultPhases);
}
 
Example #8
Source File: SpringBusFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefault() {
    Bus bus = new SpringBusFactory().createBus();
    assertNotNull(bus);
    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
    assertNotNull("No binding factory manager", bfm);
    assertNotNull("No configurer", bus.getExtension(Configurer.class));
    assertNotNull("No resource manager", bus.getExtension(ResourceManager.class));
    assertNotNull("No destination factory manager", bus.getExtension(DestinationFactoryManager.class));
    assertNotNull("No conduit initiator manager", bus.getExtension(ConduitInitiatorManager.class));
    assertNotNull("No phase manager", bus.getExtension(PhaseManager.class));
    assertNotNull("No workqueue manager", bus.getExtension(WorkQueueManager.class));
    assertNotNull("No lifecycle manager", bus.getExtension(BusLifeCycleManager.class));
    assertNotNull("No service registry", bus.getExtension(ServerRegistry.class));

    try {
        bfm.getBindingFactory("http://cxf.apache.org/unknown");
    } catch (BusException ex) {
        // expected
    }

    assertEquals("Unexpected interceptors", 0, bus.getInInterceptors().size());
    assertEquals("Unexpected interceptors", 0, bus.getInFaultInterceptors().size());
    assertEquals("Unexpected interceptors", 0, bus.getOutInterceptors().size());
    assertEquals("Unexpected interceptors", 0, bus.getOutFaultInterceptors().size());

}
 
Example #9
Source File: OutgoingChainInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

    control = EasyMock.createNiceControl();

    phases = new ArrayList<>();
    phases.add(new Phase(Phase.SEND, 1000));
    empty = new ArrayList<>();

    bus = control.createMock(Bus.class);
    PhaseManager pm = new PhaseManagerImpl();
    EasyMock.expect(bus.getExtension(PhaseManager.class)).andReturn(pm).anyTimes();

    service = control.createMock(Service.class);
    endpoint = control.createMock(Endpoint.class);
    binding = control.createMock(Binding.class);
    EasyMock.expect(endpoint.getBinding()).andStubReturn(binding);
    MessageImpl m = new MessageImpl();
    EasyMock.expect(binding.createMessage()).andStubReturn(m);

    EasyMock.expect(endpoint.getService()).andReturn(service).anyTimes();
    EasyMock.expect(endpoint.getOutInterceptors()).andReturn(empty);
    EasyMock.expect(service.getOutInterceptors()).andReturn(empty);
    EasyMock.expect(bus.getOutInterceptors()).andReturn(empty);

    bopInfo = control.createMock(BindingOperationInfo.class);
    opInfo = control.createMock(OperationInfo.class);
    mInfo = control.createMock(MessageInfo.class);
    bmInfo = control.createMock(BindingMessageInfo.class);
    EasyMock.expect(bopInfo.getOperationInfo()).andReturn(opInfo).times(3);
    EasyMock.expect(opInfo.getOutput()).andReturn(mInfo);
    EasyMock.expect(opInfo.isOneWay()).andReturn(false);
    EasyMock.expect(bopInfo.getOutput()).andReturn(bmInfo);

    control.replay();

}
 
Example #10
Source File: ClientImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected PhaseInterceptorChain setupInterceptorChain(Endpoint endpoint) {

        PhaseManager pm = bus.getExtension(PhaseManager.class);

        List<Interceptor<? extends Message>> i1 = bus.getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by bus: " + i1);
        }
        List<Interceptor<? extends Message>> i2 = getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by client: " + i2);
        }
        List<Interceptor<? extends Message>> i3 = endpoint.getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by endpoint: " + i3);
        }
        List<Interceptor<? extends Message>> i4 = endpoint.getBinding().getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by binding: " + i4);
        }
        List<Interceptor<? extends Message>> i5 = null;
        if (endpoint.getService().getDataBinding() instanceof InterceptorProvider) {
            i5 = ((InterceptorProvider)endpoint.getService().getDataBinding()).getOutInterceptors();
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("Interceptors contributed by databinding: " + i5);
            }
        }
        if (i5 != null) {
            return outboundChainCache.get(pm.getOutPhases(), i1, i2, i3, i4, i5);
        }
        return outboundChainCache.get(pm.getOutPhases(), i1, i2, i3, i4);
    }
 
Example #11
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 #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: ColocMessageObserverTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testObserverOnMessage() throws Exception {
    msg.setExchange(ex);

    Binding binding = control.createMock(Binding.class);
    EasyMock.expect(ep.getBinding()).andReturn(binding);

    Message inMsg = new MessageImpl();
    EasyMock.expect(binding.createMessage()).andReturn(inMsg);

    EasyMock.expect(ep.getService()).andReturn(srv).anyTimes();
    EasyMock.expect(
        bus.getExtension(PhaseManager.class)).andReturn(
                                  new PhaseManagerImpl()).times(2);
    EasyMock.expect(bus.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>());
    EasyMock.expect(ep.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>());
    EasyMock.expect(srv.getInInterceptors()).andReturn(new ArrayList<Interceptor<? extends Message>>());
    EasyMock.expect(bus.getExtension(ClassLoader.class)).andReturn(this.getClass().getClassLoader());
    control.replay();
    observer = new TestColocMessageObserver(ep, bus);
    observer.onMessage(msg);
    control.verify();

    Exchange inEx = inMsg.getExchange();
    assertNotNull("Should Have a valid Exchange", inEx);
    assertFalse("Message.REQUESTOR_ROLE should be false",
                 (Boolean)inMsg.get(Message.REQUESTOR_ROLE));
    assertTrue("Message.INBOUND_MESSAGE should be true",
                 (Boolean)inMsg.get(Message.INBOUND_MESSAGE));
    assertNotNull("Chain should be set", inMsg.getInterceptorChain());
    Exchange ex1 = msg.getExchange();
    assertNotNull("Exchange should be set", ex1);
}
 
Example #14
Source File: ColocOutInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvokeInboundChain() {
    //Reset Exchange on msg
    msg.setExchange(null);
    Bus bus = setupBus();
    colocOut.setBus(bus);
    PhaseManager pm = new PhaseManagerImpl();
    EasyMock.expect(bus.getExtension(PhaseManager.class)).andReturn(pm).times(2);

    Endpoint ep = control.createMock(Endpoint.class);
    Binding bd = control.createMock(Binding.class);
    Service srv = control.createMock(Service.class);
    ex.setInMessage(msg);
    ex.put(Bus.class, bus);
    ex.put(Endpoint.class, ep);
    ex.put(Service.class, srv);

    EasyMock.expect(ep.getBinding()).andReturn(bd);
    EasyMock.expect(bd.createMessage()).andReturn(new MessageImpl());
    EasyMock.expect(ep.getInInterceptors())
        .andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
    EasyMock.expect(ep.getService()).andReturn(srv).atLeastOnce();
    EasyMock.expect(srv.getInInterceptors())
        .andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
    EasyMock.expect(bus.getInInterceptors())
        .andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();

    control.replay();
    colocOut.invokeInboundChain(ex, ep);
    Message inMsg = ex.getInMessage();
    assertNotSame(msg, inMsg);
    assertTrue("Requestor role should be set to true.",
               (Boolean)inMsg.get(Message.REQUESTOR_ROLE));
    assertTrue("Inbound Message should be set to true.",
               (Boolean)inMsg.get(Message.INBOUND_MESSAGE));
    assertNotNull("Inbound Message should have interceptor chain set.",
                  inMsg.getInterceptorChain());
    assertTrue("Client Invoke state should be FINISHED", (Boolean)ex.get(ClientImpl.FINISHED));
    control.verify();
}
 
Example #15
Source File: ColocInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #16
Source File: ColocUtilTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetInInterceptorChain() throws Exception {
    PhaseManagerImpl phaseMgr = new PhaseManagerImpl();
    SortedSet<Phase> list = phaseMgr.getInPhases();
    ColocUtil.setPhases(list, Phase.SETUP, Phase.POST_LOGICAL);

    Endpoint ep = control.createMock(Endpoint.class);
    Service srv = control.createMock(Service.class);
    Exchange ex = new ExchangeImpl();

    ex.put(Bus.class, bus);
    ex.put(Endpoint.class, ep);
    ex.put(Service.class, srv);

    EasyMock.expect(bus.getExtension(PhaseManager.class)).andReturn(phaseMgr);
    EasyMock.expect(ep.getInInterceptors())
        .andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
    EasyMock.expect(ep.getService()).andReturn(srv).atLeastOnce();
    EasyMock.expect(srv.getInInterceptors())
        .andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();
    EasyMock.expect(bus.getInInterceptors())
        .andReturn(new ArrayList<Interceptor<? extends Message>>()).atLeastOnce();

    control.replay();
    InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, list);
    control.verify();
    assertNotNull("Should have chain instance", chain);
    Iterator<Interceptor<? extends Message>> iter = chain.iterator();
    assertFalse("Should not have interceptors in chain", iter.hasNext());
    assertNotNull("OutFaultObserver should be set", chain.getFaultObserver());
}
 
Example #17
Source File: SpringBusFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void checkOtherCoreExtensions(Bus bus) throws BusException {
    assertNotNull("No wsdl manager", bus.getExtension(WSDLManager.class));
    assertNotNull("No phase manager", bus.getExtension(PhaseManager.class));
    assertNotNull("No workqueue manager", bus.getExtension(WorkQueueManager.class));
    assertNotNull("No lifecycle manager", bus.getExtension(BusLifeCycleManager.class));
    assertNotNull("No service registry", bus.getExtension(ServerRegistry.class));

}
 
Example #18
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Exchange getExchange() {
    Bus bus = control.createMock(Bus.class);
    bus.getExtension(PhaseManager.class);
    EasyMock.expectLastCall().andReturn(new PhaseManagerImpl()).anyTimes();

    Exchange exchange = control.createMock(Exchange.class);
    exchange.getBus();
    EasyMock.expectLastCall().andReturn(bus).anyTimes();
    EasyMock.expect(exchange.isEmpty()).andReturn(true).anyTimes();
    return exchange;
}
 
Example #19
Source File: RedeliveryQueueImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static InterceptorChain getRedeliveryInterceptorChain(Message m, String phase) {
    Exchange exchange = m.getExchange();
    Endpoint ep = exchange.getEndpoint();
    Bus bus = exchange.getBus();

    PhaseManager pm = bus.getExtension(PhaseManager.class);
    SortedSet<Phase> phases = new TreeSet<>(pm.getInPhases());
    for (Iterator<Phase> it = phases.iterator(); it.hasNext();) {
        Phase p = it.next();
        if (phase.equals(p.getName())) {
            break;
        }
        it.remove();
    }
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    List<Interceptor<? extends Message>> il = ep.getInInterceptors();
    addInterceptors(chain, il);
    il = ep.getService().getInInterceptors();
    addInterceptors(chain, il);
    il = ep.getBinding().getInInterceptors();
    addInterceptors(chain, il);
    il = bus.getInInterceptors();
    addInterceptors(chain, il);
    if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        il = ((InterceptorProvider)ep.getService().getDataBinding()).getInInterceptors();
        addInterceptors(chain, il);
    }

    return chain;
}
 
Example #20
Source File: ColocOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #21
Source File: InterceptorFaultTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void setupGreeter(String cfgResource, boolean useDecoupledEndpoint)
    throws NumberFormatException, MalformedURLException {

    SpringBusFactory bf = new SpringBusFactory();

    controlBus = bf.createBus();
    BusFactory.setDefaultBus(controlBus);

    ControlService cs = new ControlService();
    control = cs.getControlPort();
    updateAddressPort(control, PORT);

    assertTrue("Failed to start greeter", control.startGreeter(cfgResource));

    greeterBus = bf.createBus(cfgResource);
    BusFactory.setDefaultBus(greeterBus);
    LOG.fine("Initialised greeter bus with configuration: " + cfgResource);

    if (null == comparator) {
        comparator = new PhaseComparator();
    }
    if (null == inPhases) {
        inPhases = new ArrayList<>();
        inPhases.addAll(greeterBus.getExtension(PhaseManager.class).getInPhases());
        Collections.sort(inPhases, comparator);
    }
    if (null == postUnMarshalPhase) {
        postUnMarshalPhase = getPhase(Phase.POST_UNMARSHAL);
    }

    GreeterService gs = new GreeterService();

    greeter = gs.getGreeterPort();
    updateAddressPort(greeter, PORT);
    LOG.fine("Created greeter client.");

    if (!useDecoupledEndpoint) {
        return;
    }

    // programatically configure decoupled endpoint that is guaranteed to
    // be unique across all test cases
    decoupledEndpointPort++;
    decoupledEndpoint = "http://localhost:"
        + allocatePort("decoupled-" + decoupledEndpointPort)
        + "/decoupled_endpoint";

    Client c = ClientProxy.getClient(greeter);
    HTTPConduit hc = (HTTPConduit)(c.getConduit());
    HTTPClientPolicy cp = hc.getClient();
    cp.setDecoupledEndpoint(decoupledEndpoint);

    LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint());
}
 
Example #22
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;
    }
}
 
Example #23
Source File: ColocInFaultObserver.java    From cxf with Apache License 2.0 4 votes vote down vote up
public ColocInFaultObserver(Bus bus) {
    super(bus);
    list = new TreeSet<>(bus.getExtension(PhaseManager.class).getInPhases());
    ColocUtil.setPhases(list, Phase.PRE_LOGICAL, Phase.PRE_INVOKE);
}
 
Example #24
Source File: ColocOutFaultObserver.java    From cxf with Apache License 2.0 4 votes vote down vote up
public ColocOutFaultObserver(Bus bus) {
    super(bus);
    list = new TreeSet<>(bus.getExtension(PhaseManager.class).getOutPhases());
    ColocUtil.setPhases(list, Phase.SETUP, Phase.USER_LOGICAL);
}
 
Example #25
Source File: PhaseManagerImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Class<?> getRegistrationType() {
    return PhaseManager.class;
}
 
Example #26
Source File: MultipleEndpointObserver.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected PhaseInterceptorChain createChain() {
    return new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases());
}
 
Example #27
Source File: OutFaultChainInitiatorObserver.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected SortedSet<Phase> getPhases() {
    return getBus().getExtension(PhaseManager.class).getOutPhases();
}
 
Example #28
Source File: InFaultChainInitiatorObserver.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected SortedSet<Phase> getPhases() {
    return getBus().getExtension(PhaseManager.class).getInPhases();
}
 
Example #29
Source File: OutgoingChainInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static PhaseInterceptorChain getChain(Exchange ex, PhaseChainCache chainCache) {
    Bus bus = ex.getBus();
    Binding binding = ex.getBinding();

    Endpoint ep = ex.getEndpoint();

    List<Interceptor<? extends Message>> i1 = bus.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by bus: " + i1);
    }
    List<Interceptor<? extends Message>> i2 = ep.getService().getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by service: " + i2);
    }
    List<Interceptor<? extends Message>> i3 = ep.getOutInterceptors();
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Interceptors contributed by endpoint: " + i3);
    }
    List<Interceptor<? extends Message>> i4 = null;
    if (binding != null) {
        i4 = binding.getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by binding: " + i4);
        }
    }
    List<Interceptor<? extends Message>> i5 = null;
    if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        i5 = ((InterceptorProvider)ep.getService().getDataBinding()).getOutInterceptors();
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Interceptors contributed by databinding: " + i5);
        }
        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;
}
 
Example #30
Source File: ColocMessageObserver.java    From cxf with Apache License 2.0 4 votes vote down vote up
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();
        }
    }
}