use of com.sun.jersey.api.client.config.DefaultClientConfig in project lobcder by skoulouzis.
the class TestREST method configureClient.
public static ClientConfig configureClient() {
TrustManager[] certs = new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
} };
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("TLS");
ctx.init(null, certs, new SecureRandom());
} catch (java.security.GeneralSecurityException ex) {
}
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
ClientConfig config = new DefaultClientConfig();
try {
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}, ctx));
} catch (Exception e) {
}
return config;
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project lobcder by skoulouzis.
the class TestWebWAVFS method setUpClass.
@BeforeClass
public static void setUpClass() throws Exception {
String propBasePath = "etc" + File.separator + "test.properties";
prop = TestSettings.getTestProperties(propBasePath);
String testURL = prop.getProperty("webdav.test.url");
// Some problem with the pom.xml. The properties are set but System.getProperty gets null
if (testURL == null) {
testURL = "http://localhost:8080/lobcder-1.0-SNAPSHOT/";
}
assertTrue(testURL != null);
if (!testURL.endsWith("/")) {
testURL = testURL + "/";
}
uri = URI.create(testURL);
root = uri.toASCIIString();
if (!root.endsWith("/")) {
root += "/";
}
username1 = prop.getProperty(("webdav.test.username1"), "");
if (username1 == null) {
username1 = "user1";
}
assertTrue(username1 != null);
password1 = prop.getProperty(("webdav.test.password1"), "");
if (password1 == null) {
password1 = "passwd1";
}
assertTrue(password1 != null);
username2 = prop.getProperty(("webdav.test.username2"), "user2");
assertTrue(username2 != null);
password2 = prop.getProperty(("webdav.test.password2"), "passwd2");
assertTrue(password2 != null);
quckTest = Boolean.valueOf(prop.getProperty(("test.quick"), "true"));
client1 = new HttpClient();
HttpClientParams params = new HttpClientParams();
params.setParameter("http.protocol.handle-redirects", false);
client1.setParams(params);
assertNotNull(uri.getHost());
assertNotNull(uri.getPort());
assertNotNull(client1);
int port = uri.getPort();
if (port == -1) {
port = 443;
}
ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
Protocol https = new Protocol("https", socketFactory, port);
Protocol.registerProtocol("https", https);
client1.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username1, password1));
httpclient = new DefaultHttpClient();
org.apache.http.auth.Credentials defaultcreds = new org.apache.http.auth.UsernamePasswordCredentials(username1, password1);
httpclient.getCredentialsProvider().setCredentials(org.apache.http.auth.AuthScope.ANY, (org.apache.http.auth.Credentials) defaultcreds);
// httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
client2 = new HttpClient();
assertNotNull(uri.getHost());
assertNotNull(uri.getPort());
assertNotNull(client2);
client2.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username2, password2));
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
restClient = Client.create(clientConfig);
restClient.addFilter(new com.sun.jersey.api.client.filter.HTTPBasicAuthFilter(username1, password1));
restURL = prop.getProperty(("rest.test.url"), "http://localhost:8080/lobcder-2.0-SNAPSHOT/rest/");
utils = new Utils(client1);
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project lobcder by skoulouzis.
the class VPDRI method configureClient.
public static ClientConfig configureClient() {
TrustManager[] certs = new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
} };
SSLContext ctx = null;
try {
ctx = SSLContext.getInstance("TLS");
ctx.init(null, certs, new SecureRandom());
} catch (java.security.GeneralSecurityException ex) {
}
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
ClientConfig config = new DefaultClientConfig();
try {
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}, ctx));
} catch (Exception e) {
}
return config;
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project 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 cloudbreak by hortonworks.
the class YarnHttpClient method deleteApplication.
@Override
public void deleteApplication(DeleteApplicationRequest deleteApplicationRequest) throws CloudbreakOrchestratorFailedException, MalformedURLException {
// Add the application name to the URL
YarnEndpoint dashEndpoint = new YarnEndpoint(apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH + '/' + deleteApplicationRequest.getName());
ClientConfig clientConfig = new DefaultClientConfig();
Client client = Client.create(clientConfig);
// Delete the application
WebResource webResource = client.resource(dashEndpoint.getFullEndpointUrl().toString());
ClientResponse response = webResource.accept("application/json").type("application/json").delete(ClientResponse.class);
// Validate HTTP 204 return
String msg;
switch(response.getStatus()) {
case YarnResourceConstants.HTTP_NO_CONTENT:
msg = String.format("Successfully deleted application %s", deleteApplicationRequest.getName());
LOGGER.debug(msg);
break;
case YarnResourceConstants.HTTP_NOT_FOUND:
msg = String.format("Application %s not found, already deleted?", deleteApplicationRequest.getName());
LOGGER.debug(msg);
break;
default:
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 CloudbreakOrchestratorFailedException(msg);
}
}
Aggregations