use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project jbossws-cxf by jbossws.
the class AddressingTestCase method testDecoupledEndpointForLongLastingProcessingOfInvocations.
/**
* This shows the usage of decoupled-endpoint for getting back response on a new http connection.
* The CXF client basically creates a destination listening at the provided decoupled endpoint address, using the
* configured http transport factory. The client gets back a HTTP 202 accept response message immediately after
* the call to the server, then once the actual response comes back to the decoupled endpoint, the client is
* notified and returns control to the application code.
*
* @throws Exception
*/
@Test
@RunAsClient
public void testDecoupledEndpointForLongLastingProcessingOfInvocations() throws Exception {
final Bus bus = BusFactory.newInstance().createBus();
BusFactory.setThreadDefaultBus(bus);
try {
// construct proxy
QName serviceName = new QName("http://www.jboss.org/jbossws/ws-extensions/wsaddressing", "AddressingService");
URL wsdlURL = new URL(baseURL + "/jaxws-samples-wsa/AddressingService?wsdl");
Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
ServiceIface proxy = (ServiceIface) service.getPort(ServiceIface.class);
Client client = ClientProxy.getClient(proxy);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = conduit.getClient();
// set low connection and receive timeouts to ensure the http client can't keep the connection open till the response is received
// 5 secs
policy.setConnectionTimeout(5000);
// 10 secs
policy.setReceiveTimeout(10000);
try {
// this takes at least 30 secs
proxy.sayHello("Sleepy");
fail("Timeout exception expected");
} catch (WebServiceException e) {
assertTrue(e.getCause() instanceof SocketTimeoutException);
}
policy.setDecoupledEndpoint("http://" + getServerHost() + ":18181/jaxws-samples-wsa/decoupled-endpoint");
// this takes at least 30 secs... but now the client doesn't time out
String response = proxy.sayHello("Sleepy");
assertEquals("Hello Sleepy!", response);
} finally {
bus.shutdown(true);
}
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project tomee by apache.
the class HTTPConduit method getClient.
public HTTPClientPolicy getClient(Message message) {
ClientPolicyCalculator cpc = new ClientPolicyCalculator();
HTTPClientPolicy pol = message.get(HTTPClientPolicy.class);
updateClientPolicy(message);
if (pol != null) {
pol = cpc.intersect(pol, clientSidePolicy);
} else {
pol = clientSidePolicy;
}
PolicyDataEngine policyDataEngine = bus.getExtension(PolicyDataEngine.class);
if (policyDataEngine == null) {
return pol;
}
return policyDataEngine.getPolicy(message, pol, cpc);
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project tbd-studio-se by Talend.
the class AmbariClientBuilder method build.
/**
* Build a client proxy, for a specific proxy type.
*
* @param proxyType proxy type class
* @return client proxy stub
*/
protected <T> T build(Class<T> proxyType) {
String address = generateAddress();
T rootResource;
// We want to ensure that the shared bean isn't set concurrently in multiple callers
synchronized (AmbariClientBuilder.class) {
JAXRSClientFactoryBean bean = cleanFactory(clientStaticResources.getUnchecked(proxyType));
bean.setAddress(address);
if (username != null) {
bean.setUsername(username);
bean.setPassword(password);
}
if (enableLogging) {
bean.setFeatures(Arrays.<AbstractFeature>asList(new LoggingFeature()));
}
rootResource = bean.create(proxyType);
}
boolean isTlsEnabled = address.startsWith("https://");
ClientConfiguration config = WebClient.getConfig(rootResource);
HTTPConduit conduit = (HTTPConduit) config.getConduit();
if (isTlsEnabled) {
TLSClientParameters tlsParams = new TLSClientParameters();
if (!validateCerts) {
tlsParams.setTrustManagers(new TrustManager[] { new AcceptAllTrustManager() });
} else if (trustManagers != null) {
tlsParams.setTrustManagers(trustManagers);
}
tlsParams.setDisableCNCheck(!validateCn);
conduit.setTlsClientParameters(tlsParams);
}
HTTPClientPolicy policy = conduit.getClient();
policy.setConnectionTimeout(connectionTimeoutUnits.toMillis(connectionTimeout));
policy.setReceiveTimeout(receiveTimeoutUnits.toMillis(receiveTimeout));
return rootResource;
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project openmeetings by apache.
the class AbstractWebServiceTest method getClient.
public static WebClient getClient(String url) {
WebClient c = WebClient.create(url, List.of(new AppointmentMessageBodyReader())).accept("application/json").type("application/json");
HTTPClientPolicy p = WebClient.getConfig(c).getHttpConduit().getClient();
p.setConnectionTimeout(TIMEOUT);
p.setReceiveTimeout(TIMEOUT);
return c;
}
use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project tesb-rt-se by Talend.
the class MonitoringServiceFullTest method testSendEvents.
// @Before
// public void setUp() throws Exception {
// executeSqlScript("create.sql", true);
// }
@Test
public void testSendEvents() throws PutEventsFault, MalformedURLException, URISyntaxException {
Client client = ClientProxy.getClient(monitoringService);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy clientConfig = new HTTPClientPolicy();
clientConfig.setReceiveTimeout(100000);
conduit.setClient(clientConfig);
jdbcTemplate.update("delete from EVENTS");
List<EventType> events = new ArrayList<EventType>();
EventType eventType = new EventType();
eventType.setEventType(EventEnumType.REQ_OUT);
URL messageContentFile = this.getClass().getResource("/testmessage.xml").toURI().toURL();
eventType.setContent(new DataHandler(messageContentFile));
CustomInfoType ciType = new CustomInfoType();
CustomInfoType.Item prop1 = new CustomInfoType.Item();
prop1.setKey("mykey1");
prop1.setValue("myValue1");
ciType.getItem().add(prop1);
CustomInfoType.Item prop2 = new CustomInfoType.Item();
prop2.setKey("mykey2");
prop2.setValue("myValue2");
ciType.getItem().add(prop2);
eventType.setCustomInfo(ciType);
MessageInfoType mit = new MessageInfoType();
mit.setFlowId("uuid");
eventType.setMessageInfo(mit);
events.add(eventType);
String result = monitoringService.putEvents(events);
Assert.assertEquals("success", result);
long id = jdbcTemplate.queryForObject("select id from EVENTS", Long.class);
Event readEvent = eventRepository.readEvent(id);
Assert.assertEquals(EventTypeEnum.REQ_OUT, readEvent.getEventType());
Map<String, String> customInfo = readEvent.getCustomInfo();
Assert.assertEquals("myValue1", customInfo.get("mykey1"));
Assert.assertEquals("myValue2", customInfo.get("mykey2"));
}
Aggregations