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());
}
use of com.sun.jersey.api.client.Client in project nhin-d by DirectProject.
the class BaseTestPlan method getResource.
public static WebResource getResource(String serviceURL) {
final ClientConfig config = new DefaultClientConfig();
config.getSingletons().add(new ConfigJSONProvider());
// need to set timeouts so we don't block forever in the event of a bad URL or hung web server
config.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, CONNECTION_TIMEOUT);
config.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, READ_TIMEOUT);
final Client client = Client.create(config);
WebResource resource = client.resource(serviceURL);
return resource;
}
use of com.sun.jersey.api.client.Client in project incubator-atlas by apache.
the class AtlasClientTest method getClientForTest.
private AtlasClient getClientForTest(final String... baseUrls) {
return new AtlasClient((UserGroupInformation) null, (String) null, baseUrls) {
boolean firstCall = true;
@Override
protected String determineActiveServiceURL(String[] baseUrls, Client client) {
String returnUrl = baseUrls[0];
if (baseUrls.length > 1 && !firstCall) {
returnUrl = baseUrls[1];
}
firstCall = false;
return returnUrl;
}
@Override
protected Configuration getClientProperties() {
return configuration;
}
@Override
protected Client getClient(Configuration configuration, UserGroupInformation ugi, String doAsUser) {
return client;
}
};
}
use of com.sun.jersey.api.client.Client 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