Search in sources :

Example 31 with SOAPService

use of org.apache.hello_world.services.SOAPService in project cxf by apache.

the class HostnameVerificationTest method testNoSubjectAlternativeNameCNMatch.

// No Subject Alternative Name, but the CN matches
@org.junit.Test
public void testNoSubjectAlternativeNameCNMatch() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = HostnameVerificationTest.class.getResource("hostname-client.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);
    updateAddressPort(port, PORT3);
    assertEquals(port.greetMe("Kitty"), "Hello Kitty");
    // Enable Async
    ((BindingProvider) port).getRequestContext().put("use.async.http.conduit", true);
    assertEquals(port.greetMe("Kitty"), "Hello Kitty");
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Greeter(org.apache.hello_world.Greeter) URL(java.net.URL)

Example 32 with SOAPService

use of org.apache.hello_world.services.SOAPService in project cxf by apache.

the class TrustManagerTest method testNoOpX509TrustManager.

// The X509TrustManager is effectively empty here so trust verification should work
@org.junit.Test
public void testNoOpX509TrustManager() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = TrustManagerTest.class.getResource("client-trust.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);
    updateAddressPort(port, PORT);
    TLSClientParameters tlsParams = new TLSClientParameters();
    X509TrustManager trustManager = new NoOpX509TrustManager();
    TrustManager[] trustManagers = new TrustManager[1];
    trustManagers[0] = trustManager;
    tlsParams.setTrustManagers(trustManagers);
    tlsParams.setDisableCNCheck(true);
    Client client = ClientProxy.getClient(port);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setTlsClientParameters(tlsParams);
    assertEquals(port.greetMe("Kitty"), "Hello Kitty");
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Bus(org.apache.cxf.Bus) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) URL(java.net.URL) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) X509TrustManager(javax.net.ssl.X509TrustManager) Greeter(org.apache.hello_world.Greeter) Client(org.apache.cxf.endpoint.Client)

Example 33 with SOAPService

use of org.apache.hello_world.services.SOAPService in project cxf by apache.

the class TrustManagerTest method testInvalidServerCertX509TrustManager.

@org.junit.Test
public void testInvalidServerCertX509TrustManager() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = TrustManagerTest.class.getResource("client-trust.xml");
    Bus bus = bf.createBus(busFile.toString());
    BusFactory.setDefaultBus(bus);
    BusFactory.setThreadDefaultBus(bus);
    URL url = SOAPService.WSDL_LOCATION;
    SOAPService service = new SOAPService(url, SOAPService.SERVICE);
    assertNotNull("Service is null", service);
    final Greeter port = service.getHttpsPort();
    assertNotNull("Port is null", port);
    updateAddressPort(port, PORT);
    String invalidPrincipalName = "CN=Bethal2,OU=Bethal,O=ApacheTest,L=Syracuse,C=US";
    TLSClientParameters tlsParams = new TLSClientParameters();
    X509TrustManager trustManager = new ServerCertX509TrustManager(invalidPrincipalName);
    TrustManager[] trustManagers = new TrustManager[1];
    trustManagers[0] = trustManager;
    tlsParams.setTrustManagers(trustManagers);
    tlsParams.setDisableCNCheck(true);
    Client client = ClientProxy.getClient(port);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setTlsClientParameters(tlsParams);
    try {
        port.greetMe("Kitty");
        fail("Failure expected on an invalid principal name");
    } catch (Exception ex) {
    // expected
    }
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Bus(org.apache.cxf.Bus) TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) URL(java.net.URL) CertificateException(java.security.cert.CertificateException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) X509TrustManager(javax.net.ssl.X509TrustManager) Greeter(org.apache.hello_world.Greeter) Client(org.apache.cxf.endpoint.Client)

Example 34 with SOAPService

use of org.apache.hello_world.services.SOAPService in project cxf by apache.

the class OASISCatalogTest method testClientWithDefaultCatalog.

@Test
public void testClientWithDefaultCatalog() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/catalog/hello_world_services.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull(service);
    Greeter greeter = service.getPort(portName, Greeter.class);
    assertNotNull(greeter);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Greeter(org.apache.hello_world.Greeter) URL(java.net.URL) Test(org.junit.Test)

Example 35 with SOAPService

use of org.apache.hello_world.services.SOAPService in project cxf by apache.

the class OASISCatalogTest method testClientWithoutCatalog.

@Test
public void testClientWithoutCatalog() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/catalog/hello_world_services.wsdl");
    assertNotNull(wsdl);
    // set Catalog on the Bus
    Bus bus = BusFactory.getDefaultBus();
    OASISCatalogManager catalog = new OASISCatalogManager();
    bus.setExtension(catalog, OASISCatalogManager.class);
    // prevent cache from papering over the lack of a schema.
    WSDLManagerImpl mgr = (WSDLManagerImpl) bus.getExtension(WSDLManager.class);
    mgr.setDisableSchemaCache(true);
    try {
        SOAPService service = new SOAPService(wsdl, serviceName);
        service.getPort(portName, Greeter.class);
        fail("Test did not fail as expected");
    } catch (WebServiceException e) {
    // ignore
    }
    // update catalog dynamically now
    Enumeration<URL> jaxwscatalog = getClass().getClassLoader().getResources("META-INF/jax-ws-catalog.xml");
    assertNotNull(jaxwscatalog);
    while (jaxwscatalog.hasMoreElements()) {
        URL url = jaxwscatalog.nextElement();
        catalog.loadCatalog(url);
    }
    SOAPService service = new SOAPService(wsdl, serviceName);
    Greeter greeter = service.getPort(portName, Greeter.class);
    assertNotNull(greeter);
    bus.shutdown(true);
}
Also used : SOAPService(org.apache.hello_world.services.SOAPService) Bus(org.apache.cxf.Bus) WebServiceException(javax.xml.ws.WebServiceException) Greeter(org.apache.hello_world.Greeter) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) WSDLManagerImpl(org.apache.cxf.wsdl11.WSDLManagerImpl) WSDLManager(org.apache.cxf.wsdl.WSDLManager) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Greeter (org.apache.hello_world.Greeter)57 SOAPService (org.apache.hello_world.services.SOAPService)57 URL (java.net.URL)56 Bus (org.apache.cxf.Bus)41 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)40 Client (org.apache.cxf.endpoint.Client)14 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)14 Test (org.junit.Test)13 CertificateException (java.security.cert.CertificateException)9 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)8 TrustManager (javax.net.ssl.TrustManager)7 X509TrustManager (javax.net.ssl.X509TrustManager)7 IOException (java.io.IOException)5 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)5 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)4 GeneralSecurityException (java.security.GeneralSecurityException)3 BindingProvider (javax.xml.ws.BindingProvider)3 UntrustedURLConnectionIOException (org.apache.cxf.transport.http.UntrustedURLConnectionIOException)3 MalformedURLException (java.net.MalformedURLException)2 InputStream (java.io.InputStream)1