use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class DispatchClientServerTest method doJAXBPayload.
private void doJAXBPayload(Dispatch<Object> disp) throws Exception {
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
String expected = "Hello Jeeves";
GreetMe greetMe = new GreetMe();
greetMe.setRequestType("Jeeves");
Object response = disp.invoke(greetMe);
assertNotNull(response);
String responseValue = ((GreetMeResponse) response).getResponseType();
assertEquals("Expected string, " + expected, expected, responseValue);
// Test oneway
disp.invokeOneWay(greetMe);
// Test async polling
Response<Object> response2 = disp.invokeAsync(greetMe);
assertNotNull(response2);
GreetMeResponse greetMeResponse = (GreetMeResponse) response2.get();
String responseValue2 = greetMeResponse.getResponseType();
assertEquals("Expected string, " + expected, expected, responseValue2);
// Test async callback
TestJAXBHandler tjbh = new TestJAXBHandler();
Future<?> fd = disp.invokeAsync(greetMe, tjbh);
assertNotNull(fd);
waitForFuture(fd);
String responseValue3 = ((GreetMeResponse) tjbh.getResponse()).getResponseType();
assertEquals("Expected string, " + expected, expected, responseValue3);
org.apache.hello_world_soap_http.types.TestDocLitFault fr = new org.apache.hello_world_soap_http.types.TestDocLitFault();
fr.setFaultType(BadRecordLitFault.class.getSimpleName());
tjbh = new TestJAXBHandler();
fd = disp.invokeAsync(fr, tjbh);
waitForFuture(fd);
try {
fd.get();
fail("did not get expected exception");
} catch (ExecutionException ex) {
// expected
}
GreetMeLater later = new GreetMeLater();
later.setRequestType(1000);
HTTPClientPolicy pol = new HTTPClientPolicy();
pol.setReceiveTimeout(100);
disp.getRequestContext().put(HTTPClientPolicy.class.getName(), pol);
Response<Object> o = disp.invokeAsync(later);
try {
o.get(10, TimeUnit.SECONDS);
fail("Should have gotten a SocketTimeoutException");
} catch (ExecutionException ex) {
assertTrue(ex.getCause() instanceof SocketTimeoutException);
}
later.setRequestType(20000);
pol.setReceiveTimeout(20000);
disp.getRequestContext().put(HTTPClientPolicy.class.getName(), pol);
o = disp.invokeAsync(later);
try {
o.get(100, TimeUnit.MILLISECONDS);
fail("Should have gotten a SocketTimeoutException");
} catch (TimeoutException ex) {
// ignore - expected
}
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class UndertowDigestAuthTest method setupClient.
private HTTPConduit setupClient(boolean async) throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
greeter = new SOAPService(wsdl, SERVICE_NAME).getPort(Greeter.class);
BindingProvider bp = (BindingProvider) greeter;
ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor());
ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor());
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS);
HTTPConduit cond = (HTTPConduit) ClientProxy.getClient(greeter).getConduit();
HTTPClientPolicy client = new HTTPClientPolicy();
client.setConnectionTimeout(600000);
client.setReceiveTimeout(600000);
cond.setClient(client);
if (async) {
if (cond instanceof AsyncHTTPConduit) {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("ffang", "pswd");
bp.getRequestContext().put(Credentials.class.getName(), creds);
bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
client.setAutoRedirect(true);
} else {
fail("Not an async conduit");
}
} else {
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ffang");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
cond.setAuthSupplier(new DigestAuthSupplier());
}
ClientProxy.getClient(greeter).getOutInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.PRE_STREAM_ENDING) {
public void handleMessage(Message message) throws Fault {
Map<String, ?> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
if (headers.containsKey("Proxy-Authorization")) {
throw new RuntimeException("Should not have Proxy-Authorization");
}
}
});
client.setAllowChunking(false);
return cond;
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.
the class ConnectionHelper method setKeepAliveConnection.
public static void setKeepAliveConnection(Object proxy, boolean keepAlive, boolean force) {
if (force || "HP-UX".equals(System.getProperty("os.name")) || "Windows XP".equals(System.getProperty("os.name"))) {
Client client = ClientProxy.getClient(proxy);
HTTPConduit hc = (HTTPConduit) client.getConduit();
HTTPClientPolicy cp = hc.getClient();
cp.setConnection(keepAlive ? ConnectionType.KEEP_ALIVE : ConnectionType.CLOSE);
}
}
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);
wc.type("application/xml");
ClientConfiguration clientConfig = WebClient.getConfig(wc);
clientConfig.getRequestContext().put("use.async.http.conduit", 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 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) {
Collections.addAll(clientFactory.getFeatures(), 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;
}
Aggregations