use of com.sun.jersey.api.client.config.DefaultClientConfig in project cloudbreak by hortonworks.
the class YarnHttpClient method validateApiEndpoint.
@Override
public void validateApiEndpoint() throws YarnClientException, MalformedURLException {
YarnEndpoint dashEndpoint = new YarnEndpoint(apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH);
ClientConfig clientConfig = new DefaultClientConfig();
Client client = Client.create(clientConfig);
WebResource webResource = client.resource(dashEndpoint.getFullEndpointUrl().toString());
ClientResponse response = webResource.accept("application/json").type("application/json").get(ClientResponse.class);
// Validate HTTP 200 status code
if (response.getStatus() != YarnResourceConstants.HTTP_SUCCESS) {
String msg = String.format("Received %d status code from url %s, reason: %s", response.getStatus(), dashEndpoint.getFullEndpointUrl().toString(), response.getEntity(String.class));
LOGGER.debug(msg);
throw new YarnClientException(msg);
}
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project commons by twitter.
the class HttpStatsFilterIntegrationTest method setUp.
@Before
public void setUp() {
Stats.flush();
server = new JettyHttpServerDispatch();
server.listen(0);
server.registerFilter(GuiceFilter.class, "/*");
clock = new FakeClock();
final Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(TestServlet.class).in(Singleton.class);
bind(Clock.class).toInstance(clock);
bind(HttpStatsFilter.class).in(Singleton.class);
}
}, new JerseyServletModule() {
@Override
protected void configureServlets() {
filter("/*").through(HttpStatsFilter.class);
serve("/*").with(GuiceContainer.class, ImmutableMap.of(PROPERTY_CONTAINER_RESPONSE_FILTERS, HttpStatsFilter.class.getName()));
}
});
server.getRootContext().addEventListener(new GuiceServletContextListener() {
@Override
protected Injector getInjector() {
return injector;
}
});
ClientConfig config = new DefaultClientConfig();
client = Client.create(config);
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project incubator-atlas by apache.
the class AtlasBaseClient method getClient.
@VisibleForTesting
protected Client getClient(Configuration configuration, UserGroupInformation ugi, String doAsUser) {
DefaultClientConfig config = new DefaultClientConfig();
// Enable POJO mapping feature
config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
int readTimeout = configuration.getInt("atlas.client.readTimeoutMSecs", 60000);
int connectTimeout = configuration.getInt("atlas.client.connectTimeoutMSecs", 60000);
if (configuration.getBoolean(TLS_ENABLED, false)) {
// configuration object, persist it, then subsequently pass in an empty configuration to SSLFactory
try {
SecureClientUtils.persistSSLClientConfiguration(configuration);
} catch (Exception e) {
LOG.info("Error processing client configuration.", e);
}
}
final URLConnectionClientHandler handler;
if ((AuthenticationUtil.isKerberosAuthenticationEnabled())) {
handler = SecureClientUtils.getClientConnectionHandler(config, configuration, doAsUser, ugi);
} else {
if (configuration.getBoolean(TLS_ENABLED, false)) {
handler = SecureClientUtils.getUrlConnectionClientHandler();
} else {
handler = new URLConnectionClientHandler();
}
}
Client client = new Client(handler, config);
client.setReadTimeout(readTimeout);
client.setConnectTimeout(connectTimeout);
return client;
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project hive by apache.
the class RangerRestClientImpl method getRangerClient.
@VisibleForTesting
synchronized Client getRangerClient(HiveConf hiveConf) {
Client ret = null;
ClientConfig config = new DefaultClientConfig();
config.getClasses().add(MultiPartWriter.class);
config.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
config.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, (int) hiveConf.getTimeVar(HiveConf.ConfVars.REPL_EXTERNAL_CLIENT_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS));
config.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, (int) hiveConf.getTimeVar(HiveConf.ConfVars.REPL_RANGER_CLIENT_READ_TIMEOUT, TimeUnit.MILLISECONDS));
ret = Client.create(config);
return ret;
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project coprhd-controller by CoprHD.
the class ApiTestBase method createCookieHttpsClient.
/**
* Use this client if you want to use cookies instead of the http headers for holding the
* auth token
*/
protected Client createCookieHttpsClient(final String username, final String password) throws NoSuchAlgorithmException {
// Disable server certificate validation as we are using
// self-signed certificate
disableCertificateValidation();
final ClientConfig config = new DefaultClientConfig();
final Client c = Client.create(config);
c.addFilter(new LoggingFilter());
c.setFollowRedirects(false);
c.addFilter(new HTTPBasicAuthFilter(username, password));
c.addFilter(new ClientFilter() {
private ArrayList<Object> cookies;
private ArrayList<Object> getCookiesToSet() {
if (cookies != null && !cookies.isEmpty()) {
ArrayList<Object> cookiesToSet = new ArrayList<Object>();
StringBuilder cookieToAdd = new StringBuilder();
for (Object cookieRaw : cookies) {
NewCookie cookie = (NewCookie) cookieRaw;
cookieToAdd.append(cookie.getName());
cookieToAdd.append("=");
cookieToAdd.append(cookie.getValue());
cookieToAdd.append("; ");
}
cookiesToSet.add(cookieToAdd);
return cookiesToSet;
}
return null;
}
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
ArrayList<Object> cookiesToSet = getCookiesToSet();
if (cookiesToSet != null) {
request.getHeaders().put("Cookie", cookiesToSet);
}
ClientResponse response = getNext().handle(request);
if (response.getCookies() != null) {
if (cookies == null) {
cookies = new ArrayList<Object>();
}
// simple addAll just for illustration (should probably check for duplicates and expired cookies)
cookies.addAll(response.getCookies());
}
if (response.getStatus() == 302) {
WebResource wb = c.resource(response.getLocation());
cookiesToSet = getCookiesToSet();
if (cookiesToSet != null) {
response = wb.header("Cookie", cookiesToSet).get(ClientResponse.class);
} else {
response = wb.get(ClientResponse.class);
}
}
return response;
}
});
return c;
}
Aggregations