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());
}
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;
}
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();
}
}
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);
}
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();
}
Aggregations