Search in sources :

Example 86 with Client

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

the class TopologyTemplateResource method triggerGenerateBuildPlan.

/**
 * @param uriInfo the URI ending with "topologytemplate/" of a service template
 */
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response triggerGenerateBuildPlan(@Context UriInfo uriInfo) {
    String plansURI = uriInfo.getAbsolutePath().resolve("../plans/").toString();
    String csarURI = uriInfo.getAbsolutePath().resolve("../?csar").toString();
    String request = "<generatePlanForTopology><CSARURL>";
    request += csarURI;
    request += "</CSARURL><PLANPOSTURL>";
    request += plansURI;
    request += "</PLANPOSTURL></generatePlanForTopology>";
    Client client = Client.create();
    Builder wr = null;
    if (RestUtils.isResourceAvailable("http://localhost:1339/planbuilder")) {
        wr = client.resource("http://localhost:1339/planbuilder/sync").type(MediaType.APPLICATION_XML);
    } else if (RestUtils.isResourceAvailable("http://localhost:1337/containerapi/planbuilder")) {
        wr = client.resource("http://localhost:1337/containerapi/planbuilder/sync").type(MediaType.APPLICATION_XML);
    }
    try {
        wr.post(String.class, request);
    } catch (com.sun.jersey.api.client.UniformInterfaceException e) {
        return Response.serverError().entity(e.getMessage()).build();
    }
    return Response.ok().build();
}
Also used : Builder(com.sun.jersey.api.client.WebResource.Builder) Client(com.sun.jersey.api.client.Client) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 87 with Client

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

the class RestUtils method isResourceAvailable.

/**
 * Checks whether a given resource (with absolute URL!) is available with a HEAD request on it.
 */
public static boolean isResourceAvailable(String path) {
    Client client = Client.create();
    WebResource wr = client.resource(path);
    boolean res;
    try {
        ClientResponse response = wr.head();
        res = (response.getStatusInfo().getFamily().equals(Family.SUCCESSFUL));
    } catch (com.sun.jersey.api.client.ClientHandlerException ex) {
        // In the case of a java.net.ConnectException, return false
        res = false;
    }
    return res;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) Client(com.sun.jersey.api.client.Client)

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