use of com.sun.jersey.api.client.config.DefaultClientConfig in project onebusaway-application-modules by camsys.
the class RemoteConnectionServiceImpl method postBinaryData.
@Override
public <T> T postBinaryData(String url, File data, Class<T> responseType) {
T response = null;
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource resource = client.resource(url);
try {
response = resource.accept("text/csv").type("text/csv").post(responseType, new FileInputStream(data));
} catch (UniformInterfaceException e) {
log.error("Unable to read response from the server.");
e.printStackTrace();
} catch (FileNotFoundException e) {
log.error("CSV File not found. It is not uploaded correctly");
e.printStackTrace();
}
return response;
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project lobcder by skoulouzis.
the class TestREST method testTicketTranslator.
// @Test
// public void testReservation() throws IOException {
// System.err.println("testReservation");
// try {
// createCollection();
// //Wait for replication
// Thread.sleep(15000);
//
//
// // /rest/reservation/get_workers/?id=all
// WebResource webResource = restClient.resource(restURL);
//
// //Get list of workers
// MultivaluedMap<String, String> params = new MultivaluedMapImpl();
// params.add("id", "all");
// WebResource res = webResource.path("reservation").path("get_workers").queryParams(params);
// List<WorkerStatus> workersList = res.accept(MediaType.APPLICATION_XML).
// get(new GenericType<List<WorkerStatus>>() {
// });
//
//
// //If we have workers ask for a path reservation
// if (workersList != null && workersList.size() > 0) {
// //rest/reservation/5455/request/?dataPath=/&storageSiteHost=sps1&storageSiteHost=sps2&storageSiteHost=sps3
// params = new MultivaluedMapImpl();
// String dataPath = "file1";
// params.add("dataName", dataPath);
// for (WorkerStatus w : workersList) {
// params.add("storageSiteHost", w.hostName);
// }
//
// res = webResource.path("reservation").path("some_communication_id").path("request").queryParams(params);
// ReservationInfo info = res.accept(MediaType.APPLICATION_XML).
// get(new GenericType<ReservationInfo>() {
// });
//
// assertNotNull(info);
// assertNotNull(info.communicationID);
// assertNotNull(info.storageHost);
// assertNotNull(info.storageHostIndex);
// assertNotNull(info.workerDataAccessURL);
//
//
// //Check if worker is ready
// params = new MultivaluedMapImpl();
// params.add("host", info.storageHost);
//
//
// res = webResource.path("reservation").path("workers").queryParams(params);
// List<WorkerStatus> list = res.accept(MediaType.APPLICATION_XML).
// get(new GenericType<List<WorkerStatus>>() {
// });
//
// assertNotNull(list);
// assertFalse(list.isEmpty());
// for (WorkerStatus w : list) {
// assertNotNull(w.status);
// assertNotNull(w.hostName);
// assertEquals("READY", w.status);
// }
//
// //Now get the file
// GetMethod get = new GetMethod(info.workerDataAccessURL);
// int status = client.executeMethod(get);
// assertEquals(HttpStatus.SC_OK, status);
// assertEquals("foo", get.getResponseBodyAsString());
//
//
//
//
// //run without host names
// params = new MultivaluedMapImpl();
// dataPath = "file1";
// params.add("dataName", dataPath);
// res = webResource.path("reservation").path("some_communication_id").path("request").queryParams(params);
// info = res.accept(MediaType.APPLICATION_XML).
// get(new GenericType<ReservationInfo>() {
// });
//
// assertNotNull(info);
// assertNotNull(info.communicationID);
// assertNotNull(info.storageHostIndex);
// assertNotNull(info.workerDataAccessURL);
//
//
// //Now get the file
// get = new GetMethod(info.workerDataAccessURL);
// status = client.executeMethod(get);
// assertEquals(HttpStatus.SC_OK, status);
// assertEquals("foo", get.getResponseBodyAsString());
//
// }
// } catch (Exception ex) {
// Logger.getLogger(TestREST.class.getName()).log(Level.SEVERE, null, ex);
// } finally {
// utils.deleteResource(testcol, false);
// }
// }
// @Test
// public void testGetWorkersStatus() throws IOException {
// System.err.println("testGetWorkersStatus");
// try {
// createCollection();
// WebResource webResource = restClient.resource(restURL);
// // rest/reservation/workers/?host=kscvdfv&host=sp2&host=192.168.1.1
// MultivaluedMap<String, String> params = new MultivaluedMapImpl();
// params.add("host", "host1");
// params.add("host", "host2");
// params.add("host", "host3");
//
// WebResource res = webResource.path("reservation").path("workers").queryParams(params);
// List<WorkerStatus> list = res.accept(MediaType.APPLICATION_XML).
// get(new GenericType<List<WorkerStatus>>() {
// });
//
// assertNotNull(list);
// assertFalse(list.isEmpty());
// for (WorkerStatus w : list) {
// assertNotNull(w.status);
// assertNotNull(w.hostName);
// }
//
//
// } finally {
// utils.deleteResource(testcol, false);
// }
// }
@Test
public void testTicketTranslator() throws IOException {
System.err.println("testTicketTranslator");
String testcol = root + "testResourceForTicketTranslator/";
String testURI1 = testcol + "file1";
try {
utils.createCollection(testcol, true);
utils.createFile(this.root + testURI1, true);
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client nonAuthRestClient = Client.create(clientConfig);
WebResource webResource = nonAuthRestClient.resource(translatorURL);
WebResource res = webResource.path("getshort").path(password);
String shortToken = res.accept(MediaType.TEXT_PLAIN).get(String.class);
assertNotNull(shortToken);
Client shortAuthRestClient = Client.create(clientConfig);
shortAuthRestClient.addFilter(new com.sun.jersey.api.client.filter.HTTPBasicAuthFilter(username, shortToken));
webResource = shortAuthRestClient.resource(restURL);
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("path", "/testResourceForTicketTranslator");
res = webResource.path("items").path("query").queryParams(params);
List<LogicalDataWrapped> list = res.accept(MediaType.APPLICATION_XML).get(new GenericType<List<LogicalDataWrapped>>() {
});
assertNotNull(list);
assertFalse(list.isEmpty());
} finally {
utils.deleteResource(testcol, false);
}
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project lobcder by skoulouzis.
the class WebDAVTest method setUpClass.
@BeforeClass
public static void setUpClass() throws Exception {
// String propBasePath = System.getProperty("user.home") + File.separator
// + "workspace" + File.separator + "lobcder-tests"
// + File.separator + "etc" + File.separator + "test.properties";
String propBasePath = "etc" + File.separator + "test.properties";
Properties prop = TestSettings.getTestProperties(propBasePath);
String testURL = prop.getProperty("webdav.test.url", "http://localhost:8080/lobcder/dav");
assertTrue(testURL != null);
if (!testURL.endsWith("/")) {
testURL = testURL + "/";
}
uri = URI.create(testURL);
root = uri.toASCIIString();
if (!root.endsWith("/")) {
root += "/";
}
username = prop.getProperty(("webdav.test.username1"), "user");
assertTrue(username != null);
password = prop.getProperty(("webdav.test.password1"), "token0");
assertTrue(password != null);
quckTest = Boolean.valueOf(prop.getProperty(("test.quick"), "true"));
int port = uri.getPort();
if (port == -1) {
port = 443;
}
ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
Protocol https = new Protocol("https", socketFactory, port);
Protocol.registerProtocol("https", https);
// List authPrefs = new ArrayList();
// authPrefs.add(AuthPolicy.BASIC);
// client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
client = new HttpClient();
client.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username, password));
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(username, password));
restURL = prop.getProperty(("rest.test.url"), "http://localhost:8080/lobcder/dav/rest/");
utils = new Utils(client);
client2 = new HttpClient();
assertNotNull(uri.getHost());
assertNotNull(uri.getPort());
assertNotNull(client2);
username2 = prop.getProperty(("webdav.test.username2"), "user2");
assertTrue(username2 != null);
password2 = prop.getProperty(("webdav.test.password2"), "passwd2");
assertTrue(password2 != null);
client2.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username2, password2));
}
use of com.sun.jersey.api.client.config.DefaultClientConfig in project lobcder by skoulouzis.
the class Catalogue method configureClient.
private 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 incubator-atlas by apache.
the class SecureEmbeddedServerTestBase method setup.
@BeforeMethod
public void setup() throws Exception {
jksPath = new Path(Files.createTempDirectory("tempproviders").toString(), "test.jks");
providerUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file/" + jksPath.toUri();
String baseUrl = String.format("https://localhost:%d/", securePort);
DefaultClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
client.resource(UriBuilder.fromUri(baseUrl).build());
service = client.resource(UriBuilder.fromUri(baseUrl).build());
}
Aggregations