use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project camunda-bpm-platform by camunda.
the class AbstractWebappIntegrationTest method createClient.
@Before
public void createClient() throws Exception {
testProperties = new TestProperties();
String applicationContextPath = getApplicationContextPath();
APP_BASE_PATH = testProperties.getApplicationPath("/" + applicationContextPath);
LOGGER.info("Connecting to application " + APP_BASE_PATH);
ClientConfig clientConfig = new DefaultApacheHttpClient4Config();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
client = ApacheHttpClient4.create(clientConfig);
defaultHttpClient = (DefaultHttpClient) client.getClientHandler().getHttpClient();
HttpParams params = defaultHttpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, 3 * 60 * 1000);
HttpConnectionParams.setSoTimeout(params, 10 * 60 * 1000);
}
use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project ANNIS by korpling.
the class Helper method createRESTClient.
/**
* Creates an authentificiated REST client
*
* @param userName
* @param password
* @return A newly created client.
*/
public static Client createRESTClient(String userName, String password) {
DefaultApacheHttpClient4Config rc = new DefaultApacheHttpClient4Config();
rc.getClasses().add(SaltProjectProvider.class);
ThreadSafeClientConnManager clientConnMgr = new ThreadSafeClientConnManager();
clientConnMgr.setDefaultMaxPerRoute(10);
rc.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, clientConnMgr);
if (userName != null && password != null) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
rc.getProperties().put(ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER, credentialsProvider);
rc.getProperties().put(ApacheHttpClient4Config.PROPERTY_PREEMPTIVE_BASIC_AUTHENTICATION, true);
}
Client c = ApacheHttpClient4.create(rc);
return c;
}
use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project spring-cloud-netflix by spring-cloud.
the class SpringClientFactoryTests method testCookiePolicy.
@SuppressWarnings("deprecation")
@Test
public void testCookiePolicy() {
SpringClientFactory factory = new SpringClientFactory();
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
addEnvironment(parent, "ribbon.restclient.enabled=true");
parent.register(RibbonAutoConfiguration.class, ArchaiusAutoConfiguration.class);
parent.refresh();
factory.setApplicationContext(parent);
RestClient client = factory.getClient("foo", RestClient.class);
ApacheHttpClient4 jerseyClient = (ApacheHttpClient4) client.getJerseyClient();
assertEquals(CookiePolicy.IGNORE_COOKIES, jerseyClient.getClientHandler().getHttpClient().getParams().getParameter(ClientPNames.COOKIE_POLICY));
parent.close();
factory.destroy();
}
use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project camunda-bpm-platform by camunda.
the class AbstractWebIT method createClient.
public void createClient(String ctxPath) throws Exception {
testProperties = new TestProperties();
APP_BASE_PATH = testProperties.getApplicationPath("/" + ctxPath);
LOGGER.info("Connecting to application " + APP_BASE_PATH);
ClientConfig clientConfig = new DefaultApacheHttpClient4Config();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
client = ApacheHttpClient4.create(clientConfig);
defaultHttpClient = (DefaultHttpClient) client.getClientHandler().getHttpClient();
HttpParams params = defaultHttpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, 3 * 60 * 1000);
HttpConnectionParams.setSoTimeout(params, 10 * 60 * 1000);
}
use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project hop by apache.
the class RestTest method testCallEndpointWithDeleteVerb.
@Test
public void testCallEndpointWithDeleteVerb() throws HopException {
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
headers.add("Content-Type", "application/json");
ClientResponse response = mock(ClientResponse.class);
doReturn(200).when(response).getStatus();
doReturn(headers).when(response).getHeaders();
doReturn("true").when(response).getEntity(String.class);
WebResource.Builder builder = mock(WebResource.Builder.class);
doReturn(response).when(builder).delete(ClientResponse.class);
WebResource resource = mock(WebResource.class);
doReturn(builder).when(resource).getRequestBuilder();
ApacheHttpClient4 client = mock(ApacheHttpClient4.class);
doReturn(resource).when(client).resource(nullable(String.class));
mockStatic(ApacheHttpClient4.class);
when(ApacheHttpClient4.create(any())).thenReturn(client);
RestMeta meta = mock(RestMeta.class);
doReturn(false).when(meta).isDetailed();
doReturn(false).when(meta).isUrlInField();
doReturn(false).when(meta).isDynamicMethod();
IRowMeta rmi = mock(IRowMeta.class);
doReturn(1).when(rmi).size();
RestData data = mock(RestData.class);
data.method = RestMeta.HTTP_METHOD_DELETE;
data.inputRowMeta = rmi;
data.resultFieldName = "result";
data.resultCodeFieldName = "status";
data.resultHeaderFieldName = "headers";
Rest rest = mock(Rest.class, Answers.RETURNS_DEFAULTS);
doCallRealMethod().when(rest).callRest(any());
doCallRealMethod().when(rest).searchForHeaders(any());
setInternalState(rest, "meta", meta);
setInternalState(rest, "data", data);
Object[] output = rest.callRest(new Object[] { 0 });
verify(builder, times(1)).delete(ClientResponse.class);
assertEquals("true", output[1]);
assertEquals(200L, output[2]);
assertEquals("{\"Content-Type\":\"application\\/json\"}", output[3]);
}
Aggregations