Search in sources :

Example 81 with 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;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

Example 82 with Client

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) Client(com.sun.jersey.api.client.Client) Test(org.junit.Test)

Example 83 with Client

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;
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) WebResource(com.sun.jersey.api.client.WebResource) ConfigJSONProvider(org.nhindirect.config.providers.ConfigJSONProvider) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client)

Example 84 with Client

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;
        }
    };
}
Also used : Configuration(org.apache.commons.configuration.Configuration) Matchers.anyString(org.mockito.Matchers.anyString) Client(com.sun.jersey.api.client.Client) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 85 with 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());
}
Also used : Path(org.apache.hadoop.fs.Path) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) Client(com.sun.jersey.api.client.Client) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

Client (com.sun.jersey.api.client.Client)85 ClientResponse (com.sun.jersey.api.client.ClientResponse)60 Test (org.junit.Test)59 URI (java.net.URI)51 TimelineEntity (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)36 Set (java.util.Set)30 HashSet (java.util.HashSet)19 WebResource (com.sun.jersey.api.client.WebResource)18 GenericType (com.sun.jersey.api.client.GenericType)17 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)9 TimelineMetric (org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric)9 JSONObject (org.codehaus.jettison.json.JSONObject)7 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)6 URLConnectionClientHandler (com.sun.jersey.client.urlconnection.URLConnectionClientHandler)4 ArrayList (java.util.ArrayList)4 FlowRunEntity (org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity)4 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)3 FlowActivityEntity (org.apache.hadoop.yarn.api.records.timelineservice.FlowActivityEntity)3