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

The following examples show how to use org.apache.cxf.BusFactory#newInstance() . 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
@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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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);
}