Search in sources :

Example 36 with Client

use of com.sun.jersey.api.client.Client in project neo4j by neo4j.

the class RedirectToBrowserTest method shouldRedirectToBrowser.

@Test
public void shouldRedirectToBrowser() throws Exception {
    Client nonRedirectingClient = Client.create();
    nonRedirectingClient.setFollowRedirects(false);
    final JaxRsResponse response = new RestRequest(server.baseUri(), nonRedirectingClient).accept(MediaType.TEXT_HTML_TYPE).get(server.baseUri().toString());
    assertEquals(303, response.getStatus());
    assertEquals(new URI("http://localhost:7474/browser/"), response.getLocation());
    response.close();
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Client(com.sun.jersey.api.client.Client) URI(java.net.URI) Test(org.junit.Test)

Example 37 with Client

use of com.sun.jersey.api.client.Client in project neo4j by neo4j.

the class DiscoveryServiceIT method shouldRedirectOnHtmlRequest.

@Test
public void shouldRedirectOnHtmlRequest() throws Exception {
    Client nonRedirectingClient = Client.create();
    nonRedirectingClient.setFollowRedirects(false);
    JaxRsResponse clientResponse = new RestRequest(null, nonRedirectingClient).get(server().baseUri().toString(), TEXT_HTML_TYPE);
    assertEquals(303, clientResponse.getStatus());
}
Also used : Client(com.sun.jersey.api.client.Client) Test(org.junit.Test)

Example 38 with Client

use of com.sun.jersey.api.client.Client in project nhin-d by DirectProject.

the class TestUtils method getResource.

public static WebResource getResource(String serviceURL) {
    final ClientConfig config = new DefaultClientConfig();
    config.getSingletons().add(new TxJSONProvider());
    // 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) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client) TxJSONProvider(org.nhindirect.monitor.providers.TxJSONProvider)

Example 39 with Client

use of com.sun.jersey.api.client.Client in project ORCID-Source by ORCID.

the class TransformFundRefDataIntoCSV method fetchJsonFromGeoNames.

/**
     * Queries GeoNames API for a given geonameId and return the JSON string
     * */
private String fetchJsonFromGeoNames(String geoNameId) {
    String result = null;
    if (cache.containsKey("geoname_json_" + geoNameId)) {
        return cache.get("geoname_json_" + geoNameId);
    } else {
        Client c = Client.create();
        WebResource r = c.resource(geonamesApiUrl);
        MultivaluedMap<String, String> params = new MultivaluedMapImpl();
        params.add("geonameId", geoNameId);
        params.add("username", apiUser);
        result = r.queryParams(params).get(String.class);
        cache.put("geoname_json_" + geoNameId, result);
    }
    return result;
}
Also used : WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Client(com.sun.jersey.api.client.Client)

Example 40 with Client

use of com.sun.jersey.api.client.Client in project ORCID-Source by ORCID.

the class IdentityProviderManagerImpl method downloadMetadata.

private Document downloadMetadata(String metadataUrl) {
    LOGGER.info("About to download idp metadata from {}", metadataUrl);
    Client client = Client.create();
    WebResource resource = client.resource(metadataUrl);
    ClientResponse response = resource.accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    Document document = response.getEntity(Document.class);
    return document;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) Client(com.sun.jersey.api.client.Client) Document(org.w3c.dom.Document)

Aggregations

Client (com.sun.jersey.api.client.Client)87 ClientResponse (com.sun.jersey.api.client.ClientResponse)61 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 WebResource (com.sun.jersey.api.client.WebResource)19 HashSet (java.util.HashSet)19 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 JSONException (org.codehaus.jettison.json.JSONException)3