Search in sources :

Example 21 with HTTPBasicAuthFilter

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));
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) WebResource(com.sun.jersey.api.client.WebResource) IOException(java.io.IOException) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 22 with HTTPBasicAuthFilter

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);
}
Also used : WebResource(com.sun.jersey.api.client.WebResource) FormDataMultiPart(com.sun.jersey.multipart.FormDataMultiPart) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) File(java.io.File) FileDataBodyPart(com.sun.jersey.multipart.file.FileDataBodyPart)

Example 23 with HTTPBasicAuthFilter

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());
}
Also used : Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 24 with HTTPBasicAuthFilter

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");
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) Before(org.junit.Before)

Example 25 with HTTPBasicAuthFilter

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);
}
Also used : JSONObject(org.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Aggregations

HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)45 Client (com.sun.jersey.api.client.Client)31 WebResource (com.sun.jersey.api.client.WebResource)19 ClientResponse (com.sun.jersey.api.client.ClientResponse)15 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)14 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)14 LoggingFilter (com.sun.jersey.api.client.filter.LoggingFilter)7 ArrayList (java.util.ArrayList)7 ClientFilter (com.sun.jersey.api.client.filter.ClientFilter)6 HTTPSProperties (com.sun.jersey.client.urlconnection.HTTPSProperties)5 ApacheHttpClient (com.sun.jersey.client.apache.ApacheHttpClient)4 HostnameVerifier (javax.net.ssl.HostnameVerifier)4 SSLSession (javax.net.ssl.SSLSession)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 ClientRequest (com.sun.jersey.api.client.ClientRequest)3 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)3 FormDataMultiPart (com.sun.jersey.multipart.FormDataMultiPart)3 FileInputStream (java.io.FileInputStream)3 URI (java.net.URI)3 KeyStore (java.security.KeyStore)3