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();
}
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;
}
Aggregations