Java Code Examples for org.apache.cxf.BusFactory#createBus()

The following examples show how to use org.apache.cxf.BusFactory#createBus() . These examples are extracted from open source projects. 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 Project: cxf   File: BusExtensionLoadingTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests the ExtensionManagerBus can be built using a given classloader
 *
 * @throws Exception
 */
@Test
public void testBusConstructionWithoutTCCL() throws Exception {
    ClassLoader origClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(new TestClassLoader());
        BusFactory factory = new CXFBusFactory() {
            public Bus createBus(Map<Class<?>, Object> e, Map<String, Object> properties) {
                return new ExtensionManagerBus(e, properties, this.getClass().getClassLoader());
            }
        };
        Bus bus = factory.createBus();
        assertNotNullExtensions(bus);
        bus.shutdown(true);
    } finally {
        Thread.currentThread().setContextClassLoader(origClassLoader);
    }
}
 
Example 2
@Test
    public void testMatchManagedConnectionsWithBoundConnections() throws Exception {


        Subject subj = new Subject();
        BusFactory bf = BusFactory.newInstance();
        Bus bus = bf.createBus();
        BusFactory.setDefaultBus(bus);
        ManagedConnectionFactoryImpl factory = EasyMock.createMock(ManagedConnectionFactoryImpl.class);
        factory.getBus();
        // In ManagedConnectionImpl:
        // one for getCXFServiceFromBus , another for createInvocationHandler
        EasyMock.expectLastCall().andReturn(bus).times(4);

        EasyMock.replay(factory);


        ManagedConnectionImpl mc1 = new ManagedConnectionImpl(factory, cri, subj);
        Object connection = mc1.getConnection(subj, cri);
        assertNotNull("connection must not be null.", connection);

        /*
        ManagedConnectionImpl mc2 = new ManagedConnectionImpl(factory, cri2, subj);
        connection = mc2.getConnection(subj, cri2);
        assertNotNull("connection must not be null.", connection);
        */
//        EasyMock.verify(factory);

        Set<ManagedConnection> mcSet = new HashSet<>();
        mcSet.add(mc1);
        //mcSet.add(mc2);

        assertSame("MC1 must be selected.", mci.matchManagedConnections(mcSet, subj, cri), mc1);
        //assertSame("MC2 must be selected.", mci.matchManagedConnections(mcSet, subj, cri2), mc2);
        //assertNull("No connection must be selected.", mci.matchManagedConnections(mcSet, subj, cri3));
        bus.shutdown(true);
    }
 
Example 3
Source Project: cxf   File: BusExtensionLoadingTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test for checking the ExtensionManagerBus is built using the TCCL by default
 *
 * @throws Exception
 */
@Test
public void testDefaultBusConstruction() throws Exception {
    BusFactory factory = new CXFBusFactory();
    Bus bus = factory.createBus();
    assertNotNullExtensions(bus);
    bus.shutdown(true);
}
 
Example 4
Source Project: cxf   File: UndertowDigestAuthTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 5
Source Project: cxf   File: UndertowBasicAuthTest.java    License: 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 6
Source Project: cxf   File: JettyDigestAuthTest.java    License: 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 7
Source Project: cxf   File: JettyBasicAuthTest.java    License: 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 8
Source Project: cxf   File: BusServer.java    License: Apache License 2.0 5 votes vote down vote up
protected void run()  {
    //
    // Just instantiate the Bus; services will be instantiated
    // and published automatically through Spring
    //
    final BusFactory factory = BusFactory.newInstance();
    Bus bus = factory.createBus();
    setBus(bus);
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
}
 
Example 9
Source Project: cxf   File: BusServer.java    License: Apache License 2.0 5 votes vote down vote up
protected void run()  {
    //
    // Just instantiate the Bus; services will be instantiated
    // and published automatically through Spring
    //
    final BusFactory factory = BusFactory.newInstance();
    Bus bus = factory.createBus();
    setBus(bus);
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
}
 
Example 10
Source Project: cxf   File: UsernameTokenTest.java    License: Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testPlaintextWSDLOverHTTPSViaCode() throws Exception {

    TrustManagerFactory tmf =
        TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    final KeyStore ts = KeyStore.getInstance("JKS");
    try (InputStream trustStore =
        ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", UsernameTokenTest.class)) {
        ts.load(trustStore, "password".toCharArray());
    }
    tmf.init(ts);

    TLSClientParameters tlsParams = new TLSClientParameters();
    tlsParams.setTrustManagers(tmf.getTrustManagers());
    tlsParams.setDisableCNCheck(true);

    HTTPConduitConfigurer myHttpConduitConfig = new HTTPConduitConfigurer() {
        public void configure(String name, String address, HTTPConduit c) {
            if ("{http://cxf.apache.org}TransportURIResolver.http-conduit".equals(name)) {
                c.setTlsClientParameters(tlsParams);
            }
        }
    };

    BusFactory busFactory = BusFactory.newInstance();
    bus = busFactory.createBus();
    bus.setExtension(myHttpConduitConfig, HTTPConduitConfigurer.class);
    BusFactory.setThreadDefaultBus(bus);

    URL wsdl = new URL("https://localhost:" + PORT + "/DoubleItUTPlaintext?wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort");
    DoubleItPortType utPort =
            service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(utPort, test.getPort());

    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(utPort);
    }

    ((BindingProvider)utPort).getRequestContext().put(SecurityConstants.USERNAME, "Alice");

    ((BindingProvider)utPort).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      "org.apache.cxf.systest.ws.common.UTPasswordCallback");

    Client client = ClientProxy.getClient(utPort);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setTlsClientParameters(tlsParams);

    assertEquals(50, utPort.doubleIt(25));

    ((java.io.Closeable)utPort).close();
}
 
Example 11
Source Project: cxf   File: ManagedConnectionTestBase.java    License: Apache License 2.0 3 votes vote down vote up
@Before
public void setUp() throws ResourceException, MalformedURLException, BusException {

    subj = new Subject();

    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");

    QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPService");

    QName serviceName2 = new QName("http://apache.org/hello_world_soap_http", "SOAPService2");

    QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapPort");

    QName portName2 = new QName("http://apache.org/hello_world_soap_http", "SoapPort2");

    cri = new CXFConnectionRequestInfo(Greeter.class, wsdl, serviceName, portName);

    cri2 = new CXFConnectionRequestInfo(Greeter.class, wsdl, serviceName2, portName2);

    BusFactory bf = BusFactory.newInstance();
    bus = bf.createBus();
    BusFactory.setDefaultBus(bus);


    EasyMock.reset(factory);

    factory.getBus();

    EasyMock.expectLastCall().andReturn(bus).anyTimes();
    EasyMock.replay(factory);

    mci = new ManagedConnectionImpl(factory, cri, subj);

    mci.addConnectionEventListener(mockListener);
}