use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class HTTPSConduitTest method testHttpsTrust.
@Test
public void testHttpsTrust() throws Exception {
startServer("Bethal");
URL wsdl = getClass().getResource("greeting.wsdl");
assertNotNull("WSDL is null", wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
assertNotNull("Service is null", service);
Greeter bethal = service.getPort(bethalQ, Greeter.class);
assertNotNull("Port is null", bethal);
updateAddressPort(bethal, getPort("PORT4"));
// Okay, I'm sick of configuration files.
// This also tests dynamic configuration of the conduit.
Client client = ClientProxy.getClient(bethal);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAutoRedirect(false);
// If we set any name, but Edward, Mary, or George,
// and a password of "password" we will get through
// Bethal.
AuthorizationPolicy authPolicy = new AuthorizationPolicy();
authPolicy.setUserName("Betty");
authPolicy.setPassword("password");
http.setClient(httpClientPolicy);
http.setTlsClientParameters(tlsClientParameters);
http.setAuthorization(authPolicy);
// Our expected server should be OU=Bethal
http.setTrustDecider(new MyHttpsTrustDecider("Bethal"));
configureProxy(client);
String answer = bethal.sayHi();
assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer));
assertProxyRequestCount(0);
// Nobody will not equal OU=Bethal
MyHttpsTrustDecider trustDecider = new MyHttpsTrustDecider("Nobody");
http.setTrustDecider(trustDecider);
try {
answer = bethal.sayHi();
fail("Unexpected answer from Bethal: " + answer);
} catch (Exception e) {
// e.printStackTrace();
// assertTrue("Trust Decider was not called",
// 0 > trustDecider.wasCalled());
}
assertProxyRequestCount(0);
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class HTTPSProxyConduitTest method configureProxy.
public void configureProxy(Client client) {
HTTPConduit cond = (HTTPConduit) client.getConduit();
HTTPClientPolicy pol = cond.getClient();
if (pol == null) {
pol = new HTTPClientPolicy();
cond.setClient(pol);
}
pol.setProxyServer("localhost");
pol.setProxyServerPort(PROXY_PORT);
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class CXF6655Test method testConnectionWithProxy.
@Test
public void testConnectionWithProxy() throws Exception {
QName serviceName = new QName("http://cxf.apache.org/systest/jaxws/", "HelloService");
HelloService service = new HelloService(null, serviceName);
assertNotNull(service);
Hello hello = service.getHelloPort();
Client client = ClientProxy.getClient(hello);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setReceiveTimeout(0);
httpClientPolicy.setProxyServerType(ProxyServerType.HTTP);
httpClientPolicy.setProxyServer("localhost");
httpClientPolicy.setProxyServerPort(PROXY_PORT);
http.setClient(httpClientPolicy);
((BindingProvider) hello).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/hello");
assertEquals("getSayHi", hello.sayHi("SayHi"));
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class JAXRSAsyncClientTest method testPatchBookTimeout.
@Test
public void testPatchBookTimeout() throws Exception {
String address = "http://localhost:" + PORT + "/bookstore/patch";
WebClient wc = WebClient.create(address).type("application/xml");
ClientConfiguration clientConfig = WebClient.getConfig(wc);
clientConfig.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, true);
HTTPClientPolicy clientPolicy = clientConfig.getHttpConduit().getClient();
clientPolicy.setReceiveTimeout(500);
clientPolicy.setConnectionTimeout(500);
try {
Book book = wc.invoke("PATCH", new Book("Timeout", 123L), Book.class);
fail("should throw an exception due to timeout, instead got " + book);
} catch (javax.ws.rs.ProcessingException e) {
// expected!!!
}
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class InterceptorFaultTest method setupGreeter.
private void setupGreeter(String cfgResource, boolean useDecoupledEndpoint) throws NumberFormatException, MalformedURLException {
SpringBusFactory bf = new SpringBusFactory();
controlBus = bf.createBus();
BusFactory.setDefaultBus(controlBus);
ControlService cs = new ControlService();
control = cs.getControlPort();
updateAddressPort(control, PORT);
assertTrue("Failed to start greeter", control.startGreeter(cfgResource));
greeterBus = bf.createBus(cfgResource);
BusFactory.setDefaultBus(greeterBus);
LOG.fine("Initialised greeter bus with configuration: " + cfgResource);
if (null == comparator) {
comparator = new PhaseComparator();
}
if (null == inPhases) {
inPhases = new ArrayList<>();
inPhases.addAll(greeterBus.getExtension(PhaseManager.class).getInPhases());
Collections.sort(inPhases, comparator);
}
if (null == postUnMarshalPhase) {
postUnMarshalPhase = getPhase(Phase.POST_UNMARSHAL);
}
GreeterService gs = new GreeterService();
greeter = gs.getGreeterPort();
updateAddressPort(greeter, PORT);
LOG.fine("Created greeter client.");
if (!useDecoupledEndpoint) {
return;
}
// programatically configure decoupled endpoint that is guaranteed to
// be unique across all test cases
decoupledEndpointPort++;
decoupledEndpoint = "http://localhost:" + allocatePort("decoupled-" + decoupledEndpointPort) + "/decoupled_endpoint";
Client c = ClientProxy.getClient(greeter);
HTTPConduit hc = (HTTPConduit) (c.getConduit());
HTTPClientPolicy cp = hc.getClient();
cp.setDecoupledEndpoint(decoupledEndpoint);
LOG.fine("Using decoupled endpoint: " + cp.getDecoupledEndpoint());
}
Aggregations