Search in sources :

Example 96 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project camel by apache.

the class CxfEndpointBeanTest method testPropertiesSettingOnCxfClient.

@Test
public void testPropertiesSettingOnCxfClient() throws Exception {
    CxfEndpoint clientEndpoint = ctx.getBean("clientEndpoint", CxfEndpoint.class);
    CxfProducer producer = (CxfProducer) clientEndpoint.createProducer();
    // need to start the producer to get the client
    producer.start();
    Client client = producer.getClient();
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    assertEquals("Got the wrong user name", "test", conduit.getAuthorization().getUserName());
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) CxfProducer(org.apache.camel.component.cxf.CxfProducer) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Example 97 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class JavaFirstSchemaValidationTest method createClient.

private static <T> T createClient(String port, Class<T> serviceClass, SchemaValidationType type, Feature... features) {
    JaxWsProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
    clientFactory.setServiceClass(serviceClass);
    clientFactory.setAddress(getAddress(port, serviceClass));
    if (features != null) {
        clientFactory.getFeatures().addAll(Arrays.asList(features));
    }
    @SuppressWarnings("unchecked") T newClient = (T) clientFactory.create();
    Client proxy = ClientProxy.getClient(newClient);
    if (type != null) {
        proxy.getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, type);
    }
    HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
    // give me longer debug times
    HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
    clientPolicy.setConnectionTimeout(1000000);
    clientPolicy.setReceiveTimeout(1000000);
    conduit.setClient(clientPolicy);
    return newClient;
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Client(org.apache.cxf.endpoint.Client)

Example 98 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class ClientServerWebSocketTest method testBasicAuth.

@Test
public void testBasicAuth() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateGreeterAddress(greeter, PORT);
    try {
        // try the jaxws way
        BindingProvider bp = (BindingProvider) greeter;
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "BJ");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
        String s = greeter.greetMe("secure");
        assertEquals("Hello BJ", s);
        bp.getRequestContext().remove(BindingProvider.USERNAME_PROPERTY);
        bp.getRequestContext().remove(BindingProvider.PASSWORD_PROPERTY);
        ((Closeable) greeter).close();
        greeter = service.getPort(portName, Greeter.class);
        updateGreeterAddress(greeter, PORT);
        // try setting on the conduit directly
        Client client = ClientProxy.getClient(greeter);
        HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
        AuthorizationPolicy policy = new AuthorizationPolicy();
        policy.setUserName("BJ2");
        policy.setPassword("pswd");
        httpConduit.setAuthorization(policy);
        s = greeter.greetMe("secure");
        ((Closeable) greeter).close();
        assertEquals("Hello BJ2", s);
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) Greeter(org.apache.hello_world_soap_http.Greeter) Closeable(java.io.Closeable) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BindingProvider(javax.xml.ws.BindingProvider) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) Test(org.junit.Test)

Example 99 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class CipherSuitesTest method testAESIncludedTLSv12ViaCode.

// Both client + server include AES, client enables a TLS v1.2 CipherSuite
@org.junit.Test
public void testAESIncludedTLSv12ViaCode() throws Exception {
    // Doesn't work with IBM JDK
    if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
        return;
    }
    SpringBusFactory bf = new SpringBusFactory();
    URL busFile = CipherSuitesTest.class.getResource("ciphersuites-client-noconfig.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);
    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    TLSClientParameters tlsParams = new TLSClientParameters();
    X509TrustManager trustManager = new NoOpX509TrustManager();
    TrustManager[] trustManagers = new TrustManager[1];
    trustManagers[0] = trustManager;
    tlsParams.setTrustManagers(trustManagers);
    tlsParams.setDisableCNCheck(true);
    tlsParams.setSecureSocketProtocol("TLSv1.2");
    tlsParams.setCipherSuites(Collections.singletonList("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"));
    conduit.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 100 with HTTPConduit

use of org.apache.cxf.transport.http.HTTPConduit in project cxf by apache.

the class WSSCUnitTest method testEndorsingSecureConverationViaCode.

@Test
public void testEndorsingSecureConverationViaCode() throws Exception {
    URL wsdl = WSSCUnitTest.class.getResource("DoubleItWSSC.wsdl");
    Service service = Service.create(wsdl, SERVICE_QNAME);
    QName portQName = new QName(NAMESPACE, "DoubleItTransportPort");
    DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class);
    updateAddressPort(port, test.getPort());
    if (test.isStreaming()) {
        SecurityTestUtil.enableStreaming(port);
    }
    // TLS configuration
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    final KeyStore ts = KeyStore.getInstance("JKS");
    try (InputStream trustStore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", WSSCUnitTest.class)) {
        ts.load(trustStore, "password".toCharArray());
    }
    tmf.init(ts);
    TLSClientParameters tlsParams = new TLSClientParameters();
    tlsParams.setTrustManagers(tmf.getTrustManagers());
    tlsParams.setDisableCNCheck(true);
    Client client = ClientProxy.getClient(port);
    HTTPConduit http = (HTTPConduit) client.getConduit();
    http.setTlsClientParameters(tlsParams);
    // STSClient configuration
    Bus clientBus = BusFactory.newInstance().createBus();
    STSClient stsClient = new STSClient(clientBus);
    stsClient.setTlsClientParameters(tlsParams);
    ((BindingProvider) port).getRequestContext().put("security.sts.client", stsClient);
    assertEquals(50, port.doubleIt(25));
    ((java.io.Closeable) port).close();
}
Also used : TLSClientParameters(org.apache.cxf.configuration.jsse.TLSClientParameters) Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) Service(javax.xml.ws.Service) KeyStore(java.security.KeyStore) URL(java.net.URL) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) STSClient(org.apache.cxf.ws.security.trust.STSClient) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) DoubleItPortType(org.example.contract.doubleit.DoubleItPortType) STSClient(org.apache.cxf.ws.security.trust.STSClient) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Aggregations

HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)125 Client (org.apache.cxf.endpoint.Client)52 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)47 Test (org.junit.Test)42 URL (java.net.URL)35 Bus (org.apache.cxf.Bus)32 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)32 QName (javax.xml.namespace.QName)22 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)20 Service (javax.xml.ws.Service)16 KeyStore (java.security.KeyStore)15 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)15 Greeter (org.apache.hello_world.Greeter)14 SOAPService (org.apache.hello_world.services.SOAPService)14 TrustManager (javax.net.ssl.TrustManager)13 IOException (java.io.IOException)12 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)11 InputStream (java.io.InputStream)8 X509TrustManager (javax.net.ssl.X509TrustManager)8 BindingProvider (javax.xml.ws.BindingProvider)8