use of com.sun.jersey.api.client.Client in project apex-core by apache.
the class StramMiniClusterTest method testWebService.
/**
* Verify the web service deployment and lifecycle functionality
*
* @throws Exception
*/
//disabled due to web service init delay issue
@Ignore
@Test
public void testWebService() throws Exception {
// single container topology of inline input and module
Properties props = new Properties();
props.put(StreamingApplication.APEX_PREFIX + "stream.input.classname", TestGeneratorInputOperator.class.getName());
props.put(StreamingApplication.APEX_PREFIX + "stream.input.outputNode", "module1");
props.put(StreamingApplication.APEX_PREFIX + "module.module1.classname", GenericTestOperator.class.getName());
LOG.info("Initializing Client");
LogicalPlanConfiguration tb = new LogicalPlanConfiguration(new Configuration(false));
tb.addFromProperties(props, null);
StramClient client = new StramClient(new Configuration(yarnCluster.getConfig()), createDAG(tb));
if (StringUtils.isBlank(System.getenv("JAVA_HOME"))) {
// JAVA_HOME not set in the yarn mini cluster
client.javaCmd = "java";
}
try {
client.start();
client.startApplication();
// attempt web service connection
ApplicationReport appReport = client.getApplicationReport();
// delay to give web service time to fully initialize
Thread.sleep(5000);
Client wsClient = Client.create();
wsClient.setFollowRedirects(true);
WebResource r = wsClient.resource("http://" + appReport.getTrackingUrl()).path(StramWebServices.PATH).path(StramWebServices.PATH_INFO);
LOG.info("Requesting: " + r.getURI());
ClientResponse response = r.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
LOG.info("Got response: " + json.toString());
assertEquals("incorrect number of elements", 1, json.length());
assertEquals("appId", appReport.getApplicationId().toString(), json.get("id"));
r = wsClient.resource("http://" + appReport.getTrackingUrl()).path(StramWebServices.PATH).path(StramWebServices.PATH_PHYSICAL_PLAN_OPERATORS);
LOG.info("Requesting: " + r.getURI());
response = r.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
json = response.getEntity(JSONObject.class);
LOG.info("Got response: " + json.toString());
} finally {
//LOG.info("waiting...");
//synchronized (this) {
// this.wait();
//}
//boolean result = client.monitorApplication();
client.killApplication();
client.stop();
}
}
use of com.sun.jersey.api.client.Client in project apex-core by apache.
the class WebServicesVersionConversionTest method testVersioning.
@Test
public void testVersioning() throws Exception {
WebServicesClient wsClient = new WebServicesClient();
Client client = wsClient.getClient();
WebResource ws = client.resource("http://localhost:" + port).path("/new_path");
WebServicesVersionConversion.Converter versionConverter = new WebServicesVersionConversion.Converter() {
@Override
public String convertCommandPath(String path) {
if (path.equals("/new_path")) {
return "/old_path";
}
return path;
}
@Override
public String convertResponse(String path, String response) {
if (path.equals("/new_path")) {
try {
JSONObject json = new JSONObject(response);
json.put("new_key", json.get("old_key"));
json.remove("old_key");
return json.toString();
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
}
return response;
}
};
VersionConversionFilter versionConversionFilter = new VersionConversionFilter(versionConverter);
client.addFilter(versionConversionFilter);
JSONObject result = new JSONObject(ws.get(String.class));
Assert.assertEquals(result.getString("url"), "/old_path");
Assert.assertEquals(result.getString("new_key"), "value");
Assert.assertEquals(result.getString("other_key"), "other_value");
}
use of com.sun.jersey.api.client.Client in project gfm_viewer by satyagraha.
the class WebServiceClientDefault method getClient.
private Client getClient(String endpoint) {
// set up standard properties
DefaultApacheHttpClient4Config clientConfig = new DefaultApacheHttpClient4Config();
Map<String, Object> clientProperties = clientConfig.getProperties();
clientProperties.put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
clientConfig.getClasses().addAll(ConnUtilities.getJerseyProviders());
// see if proxy needed
URI uri;
try {
uri = new URI(endpoint);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
WebProxyData webProxyData = webProxyConfig.getWebProxyData(uri);
if (webProxyData != null) {
if (webProxyData.getProxyUri() != null) {
clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_PROXY_URI, webProxyData.getProxyUri());
if (webProxyData.getUserId() != null) {
clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_PROXY_USERNAME, webProxyData.getUserId());
if (webProxyData.getPassword() != null) {
clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD, webProxyData.getPassword());
}
}
}
}
// set up client properties
clientProperties.put(DefaultApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, connectionManager);
LOGGER.fine("clientProperties(): " + clientProperties);
// build client
Client client = ApacheHttpClient4.create(clientConfig);
return client;
}
use of com.sun.jersey.api.client.Client in project ORCID-Source by ORCID.
the class MailGunManager method sendEmail.
public boolean sendEmail(String from, String to, String subject, String text, String html, boolean custom) {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("api", getApiKey()));
// determine correct api based off domain.
WebResource webResource = null;
String toAddress = to.trim();
String fromEmail = getFromEmail(from);
if (shouldBeSentThroughDedicatedIP(toAddress)) {
if (custom)
webResource = client.resource(getAltNotifyApiUrl());
else if (fromEmail.endsWith("@verify.orcid.org"))
webResource = client.resource(getAltVerifyApiUrl());
else if (fromEmail.endsWith("@notify.orcid.org"))
webResource = client.resource(getAltNotifyApiUrl());
else
webResource = client.resource(getAltApiUrl());
} else {
if (custom)
webResource = client.resource(getNotifyApiUrl());
else if (fromEmail.endsWith("@verify.orcid.org"))
webResource = client.resource(getVerifyApiUrl());
else if (fromEmail.endsWith("@notify.orcid.org"))
webResource = client.resource(getNotifyApiUrl());
else
webResource = client.resource(getApiUrl());
}
MultivaluedMapImpl formData = new MultivaluedMapImpl();
formData.add("from", from);
formData.add("to", to);
formData.add("subject", subject);
formData.add("text", text);
if (html != null) {
formData.add("html", html);
}
formData.add("o:testmode", testmode);
if (testmode.equals("yes"))
LOGGER.error("Email form data: \n" + formData.toString());
// sandbox
if (to.matches(filter)) {
ClientResponse cr = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);
if (cr.getStatus() != 200) {
LOGGER.error("Post MailGunManager.sendEmail not accepted: " + formData.toString());
return false;
}
}
return true;
}
use of com.sun.jersey.api.client.Client in project ORCID-Source by ORCID.
the class OpenIDConnectTest method check403UserInfoWithoutToken.
@Test
public void check403UserInfoWithoutToken() throws JSONException {
//get userinfo
Client client = Client.create();
WebResource webResource = client.resource(baseUri + "/oauth/userinfo");
ClientResponse userInfo = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
Assert.assertEquals(403, userInfo.getStatus());
}
Aggregations