use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project teammates by TEAMMATES.
the class MailgunService method sendEmailWithService.
@Override
protected void sendEmailWithService(EmailWrapper wrapper) {
try (FormDataMultiPart email = parseToEmail(wrapper)) {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("api", Config.MAILGUN_APIKEY));
WebResource webResource = client.resource("https://api.mailgun.net/v3/" + Config.MAILGUN_DOMAINNAME + "/messages");
ClientResponse response = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, email);
if (isNotSuccessStatus(response.getStatus())) {
log.severe("Email failed to send: " + response.getStatusInfo().getReasonPhrase());
}
} catch (IOException e) {
log.warning("Could not clean up resources after sending email: " + TeammatesException.toStringWithStackTrace(e));
}
}
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));
WebResource webResource = client.resource("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
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));
return webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, formData);
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project incubator-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 opennms by OpenNMS.
the class RestClientTest method setUp.
@Before
public void setUp() {
ClientConfig config = new DefaultClientConfig();
m_client = Client.create(config);
m_client.addFilter(new HTTPBasicAuthFilter("demo", "demo"));
m_resource = m_client.resource("http://demo.opennms.org/opennms/rest/alarms");
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project pentaho-kettle by pentaho.
the class UserRoleDelegate method initManaged.
private void initManaged(PurRepositoryMeta repositoryMeta, IUser userInfo) throws JSONException {
String baseUrl = repositoryMeta.getRepositoryLocation().getUrl();
String webService = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + "api/system/authentication-provider";
HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(userInfo.getLogin(), userInfo.getPassword());
Client client = new Client();
client.addFilter(authFilter);
WebResource.Builder resource = client.resource(webService).accept(MediaType.APPLICATION_JSON_TYPE);
/**
* if set, _trust_user_ needs to be considered. See other places in pur-plugin's:
*
* @link https://github.com/pentaho/pentaho-kettle/blob/8.0.0.0-R/plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/PurRepositoryConnector.java#L97-L101
* @link https://github.com/pentaho/pentaho-kettle/blob/8.0.0.0-R/plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/WebServiceManager.java#L130-L133
*/
if (StringUtils.isNotBlank(System.getProperty("pentaho.repository.client.attemptTrust"))) {
resource = resource.header(TRUST_USER, userInfo.getLogin());
}
String response = resource.get(String.class);
String provider = new JSONObject(response).getString("authenticationType");
managed = "jackrabbit".equals(provider);
}
Aggregations