use of com.sun.jersey.api.client.config.DefaultClientConfig in project ranger by apache.
the class NiFiClient method getWebResource.
protected WebResource getWebResource() {
final ClientConfig config = new DefaultClientConfig();
if (sslContext != null) {
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostnameVerifier, sslContext));
}
final Client client = Client.create(config);
return client.resource(url);
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project ranger by apache.
the class RangerRESTClient method buildClient.
private Client buildClient() {
Client client = null;
if (mIsSSL) {
KeyManager[] kmList = getKeyManagers();
TrustManager[] tmList = getTrustManagers();
SSLContext sslContext = getSSLContext(kmList, tmList);
ClientConfig config = new DefaultClientConfig();
// to handle List<> unmarshalling
config.getClasses().add(JacksonJsonProvider.class);
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
return session.getPeerHost().equals(urlHostName);
}
};
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hv, sslContext));
client = Client.create(config);
}
if (client == null) {
ClientConfig config = new DefaultClientConfig();
// to handle List<> unmarshalling
config.getClasses().add(JacksonJsonProvider.class);
client = Client.create(config);
}
if (StringUtils.isNotEmpty(mUsername) && StringUtils.isNotEmpty(mPassword)) {
client.addFilter(new HTTPBasicAuthFilter(mUsername, mPassword));
}
// Set Connection Timeout and ReadTime for the PolicyRefresh
client.setConnectTimeout(mRestClientConnTimeOutMs);
client.setReadTimeout(mRestClientReadTimeOutMs);
return client;
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project coprhd-controller by CoprHD.
the class ApiTestBase method createHttpClient.
/**
* create the httpclient, returns a BalancedWebResource that can be used the same
* way a WebResource is.
*/
protected BalancedWebResource createHttpClient(final String username, final String attribute, final String groups, List<String> hostNames) {
BalancedWebResource lbw = new BalancedWebResource();
for (String h : hostNames) {
final ClientConfig config = new DefaultClientConfig();
final Client c = Client.create(config);
c.addFilter(new ClientFilter() {
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
ArrayList<Object> headerValue = new ArrayList<Object>();
String userAndAttribute = username;
if (!attribute.isEmpty()) {
userAndAttribute += "," + attribute;
}
headerValue.add(userAndAttribute + ";" + groups);
request.getHeaders().put(NoAuthHeaderUserFilter.USER_INFO_HEADER_TAG, headerValue);
return getNext().handle(request);
}
});
lbw.addWebResource(c.resource(h));
}
return lbw;
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project pentaho-platform by pentaho.
the class RepositoryPublishResourceIT method configure.
@Override
protected AppDescriptor configure() {
ClientConfig config = new DefaultClientConfig();
config.getClasses().add(MultiPartWriter.class);
config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
return new WebAppDescriptor.Builder("org.pentaho.platform.web.http.api.resources").contextPath("api").addFilter(PentahoRequestContextFilter.class, "pentahoRequestContextFilter").clientConfig(config).build();
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project pentaho-platform by pentaho.
the class CommandLineProcessor method initRestService.
/**
* Used only for REST Jersey calls
*
* @param contextURL The Pentaho server web application base URL.
*/
private void initRestService(String contextURL) throws ParseException, KettleException, URISyntaxException {
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
client = Client.create(clientConfig);
client.addFilter(new HTTPBasicAuthFilter(getUsername(), getPassword()));
client.addFilter(new SessionCookiesFilter(new CookieManager()));
client.addFilter(new CsrfTokenFilter(new URI(contextURL + API_CSRF_TOKEN)));
}
Aggregations