Java Code Examples for org.apache.cxf.Bus#setExtension()

The following examples show how to use org.apache.cxf.Bus#setExtension() . 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: InstrumentationManagerImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void setBus(Bus bus) {
    if (this.bus == null) {
        readJMXProperties(bus);
    } else {
        // possibly this bus was reassigned from another im bean
        InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
        if (this != im) {
            bus.setExtension(this, InstrumentationManager.class);
            try {
                ManagedBus mbus = new ManagedBus(bus);
                im.unregister(mbus);
                if (LOG.isLoggable(Level.INFO)) {
                    LOG.info("unregistered " + mbus.getObjectName());
                }
            } catch (JMException e) {
                // ignore
            }
        }
    }
    this.bus = bus;
}
 
Example 2
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 3
Source File: UndertowHTTPDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testContinuationsIgnored() throws Exception {

    HttpServletRequest httpRequest = EasyMock.createMock(HttpServletRequest.class);

    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    EndpointInfo ei = new EndpointInfo(serviceInfo, "");
    ei.setName(new QName("bla", "Port"));

    final UndertowHTTPServerEngine httpEngine = new UndertowHTTPServerEngine();
    httpEngine.setContinuationsEnabled(false);
    UndertowHTTPServerEngineFactory factory = new UndertowHTTPServerEngineFactory() {
        @Override
        public UndertowHTTPServerEngine retrieveUndertowHTTPServerEngine(int port) {
            return httpEngine;
        }
    };
    Bus b2 = new ExtensionManagerBus();
    transportFactory = new HTTPTransportFactory();
    b2.setExtension(factory, UndertowHTTPServerEngineFactory.class);

    TestUndertowDestination testDestination =
        new TestUndertowDestination(b2,
                                 transportFactory.getRegistry(),
                                 ei,
                                 factory);
    testDestination.finalizeConfig();
    Message mi = testDestination.retrieveFromContinuation(httpRequest);
    assertNull("Continuations must be ignored", mi);
}
 
Example 4
Source File: RestClientCdiTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings({"unchecked", "rawTypes"})
public void testCreationalContextsNotReleasedOnClientCloseUsingNormalScope() throws Exception {
    IMocksControl control = EasyMock.createStrictControl();
    BeanManager mockedBeanMgr = control.createMock(BeanManager.class);
    CreationalContext<?> mockedCreationalCtx = control.createMock(CreationalContext.class);
    Bean<?> mockedBean = control.createMock(Bean.class);
    List<String> stringList = new ArrayList<>(Collections.singleton("xyz"));

    EasyMock.expect(mockedBeanMgr.getBeans(List.class))
            .andReturn(Collections.singleton(mockedBean));
    EasyMock.expect(mockedBeanMgr.createCreationalContext(mockedBean))
            .andReturn((CreationalContext) mockedCreationalCtx);
    EasyMock.expect(mockedBeanMgr.getReference(mockedBean, List.class, mockedCreationalCtx))
            .andReturn(stringList);
    EasyMock.expect(mockedBean.getScope())
            .andReturn((Class) NormalScope.class);
    EasyMock.expect(mockedBeanMgr.isNormalScope(NormalScope.class))
            .andReturn(true);
    control.replay();

    Bus bus = new ExtensionManagerBus();
    bus.setExtension(mockedBeanMgr, BeanManager.class);

    Instance<List> i = CDIUtils.getInstanceFromCDI(List.class, bus);

    i.release();

    control.verify();
}
 
Example 5
Source File: RestClientCdiTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings({"unchecked", "rawTypes"})
public void testCreationalContextsReleasedOnClientClose() throws Exception {
    IMocksControl control = EasyMock.createStrictControl();
    BeanManager mockedBeanMgr = control.createMock(BeanManager.class);
    CreationalContext<?> mockedCreationalCtx = control.createMock(CreationalContext.class);
    Bean<?> mockedBean = control.createMock(Bean.class);
    List<String> stringList = new ArrayList<>(Collections.singleton("abc"));

    EasyMock.expect(mockedBeanMgr.getBeans(List.class))
            .andReturn(Collections.singleton(mockedBean));
    EasyMock.expect(mockedBeanMgr.createCreationalContext(mockedBean))
            .andReturn((CreationalContext) mockedCreationalCtx);
    EasyMock.expect(mockedBeanMgr.getReference(mockedBean, List.class, mockedCreationalCtx))
            .andReturn(stringList);
    EasyMock.expect(mockedBean.getScope())
            .andReturn((Class) ApplicationScoped.class);
    EasyMock.expect(mockedBeanMgr.isNormalScope(ApplicationScoped.class))
            .andReturn(false);
    mockedCreationalCtx.release();
    EasyMock.expectLastCall().once();
    control.replay();

    Bus bus = new ExtensionManagerBus();
    bus.setExtension(mockedBeanMgr, BeanManager.class);

    Instance<List> i = CDIUtils.getInstanceFromCDI(List.class, bus);
    assertEquals(stringList, i.getValue());
    i.release();

    control.verify();
}
 
Example 6
Source File: CxfCatalogUtils.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static void loadOASISCatalog(Bus bus, URL catalogURL) {
    OASISCatalogManager catalog = new OASISCatalogManager();
    try {
        catalog.loadCatalog(catalogURL);
        logger.debug("Loaded " + catalogURL + " catalog.");
        bus.setExtension(catalog, OASISCatalogManager.class);
    } catch (IOException e) {
        logger.warning("Failed to load catalog file: " + catalogURL, e);
    }
}
 
Example 7
Source File: HeaderManagerImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Resource
public final void setBus(Bus bus) {
    this.bus = bus;
    if (null != bus) {
        bus.setExtension(this, HeaderManager.class);
    }
}
 
Example 8
Source File: AssertionBuilderRegistryImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Resource
public final void setBus(Bus b) {
    bus = b;
    if (b != null) {
        b.setExtension(this, AssertionBuilderRegistry.class);
        org.apache.cxf.ws.policy.PolicyBuilder builder
            = b.getExtension(org.apache.cxf.ws.policy.PolicyBuilder.class);
        if (builder instanceof PolicyBuilder) {
            engine = (PolicyBuilder)builder;
        }
    }
}
 
Example 9
Source File: OASISCatalogManager.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static OASISCatalogManager getCatalogManager(Bus bus) {
    if (bus == null) {
        return getContextCatalog();
    }
    OASISCatalogManager catalog = bus.getExtension(OASISCatalogManager.class);
    if (catalog == null) {
        catalog = getContextCatalog();
        if (catalog != null) {
            bus.setExtension(catalog, OASISCatalogManager.class);
        }
    }
    return catalog;

}
 
Example 10
Source File: PolicyBuilderImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public final void setBus(Bus theBus) {
    bus = theBus;
    if (bus != null) {
        theBus.setExtension(this, PolicyBuilder.class);
        AssertionBuilderRegistry reg = theBus.getExtension(AssertionBuilderRegistry.class);
        if (reg != null) {
            factory = reg;
        }
        org.apache.cxf.ws.policy.PolicyEngine e
            = bus.getExtension(org.apache.cxf.ws.policy.PolicyEngine.class);
        if (e != null) {
            this.setPolicyRegistry(e.getRegistry());
        }
    }
}
 
Example 11
Source File: JMSConfigFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransactionManagerFromBus() throws XAException, NamingException {
    Bus bus = BusFactory.newInstance().createBus();
    ConfiguredBeanLocator cbl = bus.getExtension(ConfiguredBeanLocator.class);
    MyBeanLocator mybl = new MyBeanLocator(cbl);
    bus.setExtension(mybl, ConfiguredBeanLocator.class);

    TransactionManager tmExpected = new GeronimoTransactionManager();
    mybl.register("tm", tmExpected);
    tmByName(bus, tmExpected);
    tmByClass(bus, tmExpected);
}
 
Example 12
Source File: OASISCatalogManager.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Resource
public void setBus(Bus bus) {
    this.bus = bus;
    if (null != bus) {
        bus.setExtension(this, OASISCatalogManager.class);
    }
    loadContextCatalogs();
}
 
Example 13
Source File: JettyDigestAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testGetWSDL() throws Exception {
    BusFactory bf = BusFactory.newInstance();
    Bus bus = bf.createBus();
    bus.getInInterceptors().add(new LoggingInInterceptor());
    bus.getOutInterceptors().add(new LoggingOutInterceptor());

    MyHTTPConduitConfigurer myHttpConduitConfig = new MyHTTPConduitConfigurer();
    bus.setExtension(myHttpConduitConfig, HTTPConduitConfigurer.class);
    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(bus);
    factory.createClient(ADDRESS + "?wsdl");
}
 
Example 14
Source File: UndertowBasicAuthTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testGetWSDL() throws Exception {
    BusFactory bf = BusFactory.newInstance();
    Bus bus = bf.createBus();
    bus.getInInterceptors().add(new LoggingInInterceptor());
    bus.getOutInterceptors().add(new LoggingOutInterceptor());

    MyHTTPConduitConfigurer myHttpConduitConfig = new MyHTTPConduitConfigurer();
    bus.setExtension(myHttpConduitConfig, HTTPConduitConfigurer.class);
    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance(bus);
    factory.createClient(ADDRESS + "?wsdl");
}
 
Example 15
Source File: JettyHTTPDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testContinuationsIgnored() throws Exception {

    HttpServletRequest httpRequest = EasyMock.createMock(HttpServletRequest.class);

    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    EndpointInfo ei = new EndpointInfo(serviceInfo, "");
    ei.setName(new QName("bla", "Port"));

    final JettyHTTPServerEngine httpEngine = new JettyHTTPServerEngine();
    httpEngine.setContinuationsEnabled(false);
    JettyHTTPServerEngineFactory factory = new JettyHTTPServerEngineFactory() {
        @Override
        public JettyHTTPServerEngine retrieveJettyHTTPServerEngine(int port) {
            return httpEngine;
        }
    };
    Bus b2 = new ExtensionManagerBus();
    transportFactory = new HTTPTransportFactory();
    b2.setExtension(factory, JettyHTTPServerEngineFactory.class);

    TestJettyDestination testDestination =
        new TestJettyDestination(b2,
                                 transportFactory.getRegistry(),
                                 ei,
                                 factory);
    testDestination.finalizeConfig();
    Message mi = testDestination.retrieveFromContinuation(httpRequest);
    assertNull("Continuations must be ignored", mi);
}
 
Example 16
Source File: NettyHttpServerEngineFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * This call is used to set the bus. It should only be called once.
 *
 * @param bus
 */
@Resource(name = "cxf")
public final void setBus(Bus bus) {
    this.bus = bus;
    if (bus != null) {
        bus.setExtension(this, NettyHttpServerEngineFactory.class);
        lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
        if (null != lifeCycleManager) {
            lifeCycleManager.registerLifeCycleListener(this);
        }
    }
}
 
Example 17
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetReplyToUsingBaseAddress() throws Exception {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);

    final String localReplyTo = "/SoapContext/decoupled";
    final String decoupledEndpointBase = "http://localhost:8181/cxf";
    final String replyTo = decoupledEndpointBase + localReplyTo;

    ServiceInfo s = new ServiceInfo();
    Service svc = new ServiceImpl(s);
    EndpointInfo ei = new EndpointInfo();
    InterfaceInfo ii = s.createInterface(new QName("FooInterface"));
    s.setInterface(ii);
    ii.addOperation(new QName("fooOp"));
    SoapBindingInfo b = new SoapBindingInfo(s, "http://schemas.xmlsoap.org/soap/", Soap11.getInstance());
    b.setTransportURI("http://schemas.xmlsoap.org/soap/http");
    ei.setBinding(b);

    ei.setAddress("http://nowhere.com/bar/foo");
    ei.setName(new QName("http://nowhere.com/port", "foo"));
    Bus bus = new ExtensionManagerBus();
    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    DestinationFactory df = control.createMock(DestinationFactory.class);
    Destination d = control.createMock(Destination.class);
    bus.setExtension(dfm, DestinationFactoryManager.class);
    EasyMock.expect(dfm.getDestinationFactoryForUri(localReplyTo)).andReturn(df);
    EasyMock.expect(df.getDestination(
        EasyMock.anyObject(EndpointInfo.class), EasyMock.anyObject(Bus.class))).andReturn(d);
    EasyMock.expect(d.getAddress()).andReturn(EndpointReferenceUtils.getEndpointReference(localReplyTo));

    Endpoint ep = new EndpointImpl(bus, svc, ei);
    exchange.put(Endpoint.class, ep);
    exchange.put(Bus.class, bus);
    exchange.setOutMessage(message);
    setUpMessageProperty(message,
                         REQUESTOR_ROLE,
                         Boolean.TRUE);
    message.getContextualProperty(WSAContextUtils.REPLYTO_PROPERTY);
    message.put(WSAContextUtils.REPLYTO_PROPERTY, localReplyTo);
    message.put(WSAContextUtils.DECOUPLED_ENDPOINT_BASE_PROPERTY, decoupledEndpointBase);

    AddressingProperties maps = new AddressingProperties();
    AttributedURIType id =
        ContextUtils.getAttributedURI("urn:uuid:12345");
    maps.setMessageID(id);
    maps.setAction(ContextUtils.getAttributedURI(""));
    setUpMessageProperty(message,
                         CLIENT_ADDRESSING_PROPERTIES,
                         maps);
    control.replay();
    aggregator.mediate(message, false);
    AddressingProperties props =
        (AddressingProperties)message.get(JAXWSAConstants.ADDRESSING_PROPERTIES_OUTBOUND);

    assertEquals(replyTo, props.getReplyTo().getAddress().getValue());
    control.verify();
}
 
Example 18
Source File: RestrictedAlgorithmSuiteLoader.java    From cxf with Apache License 2.0 4 votes vote down vote up
public RestrictedAlgorithmSuiteLoader(Bus bus) {
    bus.setExtension(this, AlgorithmSuiteLoader.class);
}
 
Example 19
Source File: SHA512PolicyLoader.java    From cxf with Apache License 2.0 4 votes vote down vote up
public SHA512PolicyLoader(Bus bus) {
    bus.setExtension(this, AlgorithmSuiteLoader.class);
}
 
Example 20
Source File: SpringBusFactoryTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
TestExtension(Bus bus) {
    bus.setExtension(this, TestExtension.class);
}