use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter 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 fromEmail = getFromEmail(from);
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.filter.HTTPBasicAuthFilter in project java-docs-samples by GoogleCloudPlatform.
the class MailgunServlet method sendSimpleMessage.
// CHECKSTYLE OFF: VariableDeclarationUsageDistance
// [START simple]
private ClientResponse sendSimpleMessage(String recipient) {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("api", MAILGUN_API_KEY));
WebResource webResource = client.resource("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
MultivaluedMapImpl formData = new MultivaluedMapImpl();
formData.add("from", "Mailgun User <mailgun@" + MAILGUN_DOMAIN_NAME + ">");
formData.add("to", recipient);
formData.add("subject", "Simple Mailgun Example");
formData.add("text", "Plaintext content");
return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project java-docs-samples by GoogleCloudPlatform.
the class MailgunServlet method sendComplexMessage.
// [END simple]
// [START complex]
private ClientResponse sendComplexMessage(String recipient) {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("api", MAILGUN_API_KEY));
FormDataMultiPart formData = new FormDataMultiPart();
formData.field("from", "Mailgun User <mailgun@" + MAILGUN_DOMAIN_NAME + ">");
formData.field("to", recipient);
formData.field("subject", "Complex Mailgun Example");
formData.field("html", "<html>HTML <strong>content</strong></html>");
ClassLoader classLoader = getClass().getClassLoader();
File txtFile = new File(classLoader.getResource("example-attachment.txt").getFile());
formData.bodyPart(new FileDataBodyPart("attachment", txtFile, MediaType.TEXT_PLAIN_TYPE));
WebResource webResource = client.resource("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
return webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, formData);
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project atlas by apache.
the class AtlasBaseClient method initializeState.
void initializeState(Configuration configuration, String[] baseUrls, UserGroupInformation ugi, String doAsUser) {
this.configuration = configuration;
Client client = getClient(configuration, ugi, doAsUser);
if ((!AuthenticationUtil.isKerberosAuthenticationEnabled()) && basicAuthUser != null && basicAuthPassword != null) {
final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(basicAuthUser, basicAuthPassword);
client.addFilter(authFilter);
}
String activeServiceUrl = determineActiveServiceURL(baseUrls, client);
atlasClientContext = new AtlasClientContext(baseUrls, client, ugi, doAsUser);
service = client.resource(UriBuilder.fromUri(activeServiceUrl).build());
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project activityinfo by bedatadriven.
the class OdkApplicationDriver method queryFormList.
public List<String> queryFormList() {
Client client = Client.create();
if (currentUser != null) {
client.addFilter(new HTTPBasicAuthFilter(currentUser.getEmail(), currentUser.getPassword()));
}
Document formList = client.resource(server.getRootUrl()).path("formList").get(Document.class);
NodeList formNodes = formList.getElementsByTagName("form");
List<String> forms = new ArrayList<>();
for (int i = 0; i < formNodes.getLength(); ++i) {
forms.add(parseFormName(formNodes.item(i)));
}
return forms;
}
Aggregations