use of com.sun.jersey.api.client.WebResource.Builder 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.WebResource.Builder in project pentaho-platform by pentaho.
the class CommandLineProcessor method performExport.
/**
* REST Service Export
*
* @throws ParseException
* --export --url=http://localhost:8080/pentaho --username=admin --password=password
* --file-path=c:/temp/export.zip --charset=UTF-8 --path=public/pentaho-solutions/steel-wheels
* --logfile=c:/temp/steel-wheels.log --withManifest=true
* @throws java.io.IOException
*/
private void performExport() throws ParseException, IOException, InitializationException {
String contextURL = getOptionValue(INFO_OPTION_URL_NAME, true, false);
String path = getOptionValue(INFO_OPTION_PATH_NAME, true, false);
String withManifest = getOptionValue(INFO_OPTION_WITH_MANIFEST_NAME, false, true);
String effPath = RepositoryPathEncoder.encodeURIComponent(RepositoryPathEncoder.encodeRepositoryPath(path));
if (// remove trailing slash
effPath.lastIndexOf(":") == effPath.length() - 1 && effPath.length() > 1) {
// allow user to enter "--path=/"
effPath = effPath.substring(0, effPath.length() - 1);
}
String logFile = getOptionValue(INFO_OPTION_LOGFILE_NAME, false, true);
String exportURL = contextURL + "/api/repo/files/" + effPath + "/download?withManifest=" + ("false".equals(withManifest) ? "false" : "true");
// path is validated before executing
String filepath = getOptionValue(INFO_OPTION_FILEPATH_NAME, true, false);
if (!isValidExportPath(filepath, logFile)) {
throw new ParseException(Messages.getInstance().getString("CommandLineProcessor.ERROR_0005_INVALID_FILE_PATH", filepath));
}
initRestService();
WebResource resource = client.resource(exportURL);
// Response response
Builder builder = resource.type(MediaType.MULTIPART_FORM_DATA).accept(MediaType.TEXT_HTML_TYPE);
ClientResponse response = builder.get(ClientResponse.class);
if (response != null && response.getStatus() == 200) {
String filename = getOptionValue(INFO_OPTION_FILEPATH_NAME, true, false);
final InputStream input = response.getEntityInputStream();
createZipFile(filename, input);
input.close();
String message = Messages.getInstance().getString("CommandLineProcessor.INFO_EXPORT_COMPLETED").concat("\n");
message += Messages.getInstance().getString("CommandLineProcessor.INFO_RESPONSE_STATUS", response.getStatus());
message += "\n";
message += Messages.getInstance().getString("CommandLineProcessor.INFO_EXPORT_WRITTEN_TO", filename);
if (logFile != null && !"".equals(logFile)) {
System.out.println(message);
writeFile(message, logFile);
}
System.out.println(Messages.getInstance().getString("CommandLineProcessor.INFO_EXPORT_SUCCESSFUL"));
} else if (response != null && response.getStatus() == 403) {
errorMessage = Messages.getInstance().getErrorString("CommandLineProcessor.ERROR_0007_FORBIDDEN", path);
System.out.println(errorMessage);
} else if (response != null && response.getStatus() == 404) {
errorMessage = Messages.getInstance().getErrorString("CommandLineProcessor.ERROR_0004_UNKNOWN_SOURCE", path);
System.out.println(errorMessage);
}
}
use of com.sun.jersey.api.client.WebResource.Builder in project ORCID-Source by ORCID.
the class Orcid12APIClient method fetchPublicProfile.
/**
* Fetches the profile from the ORCID public API v1.2
*
* @param orcid
* @return
* @throws LockedRecordException
* @throws IOException
*/
public byte[] fetchPublicProfile(String orcid, String mediaType) throws LockedRecordException, DeprecatedRecordException, IOException {
WebResource webResource = jerseyClient.resource(baseUri).path(orcid + "/orcid-profile");
webResource.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
Builder builder = webResource.accept(mediaType).header("Authorization", "Bearer " + accessToken);
ClientResponse response = builder.get(ClientResponse.class);
if (response.getStatus() != 200) {
switch(response.getStatus()) {
case 301:
OrcidDeprecated orcidDeprecated = response.getEntity(OrcidDeprecated.class);
throw new DeprecatedRecordException(orcidDeprecated);
case 409:
OrcidMessage orcidMessage = response.getEntity(OrcidMessage.class);
throw new LockedRecordException(orcidMessage);
default:
LOG.error("Unable to fetch public record " + orcid + " on API 1.2 HTTP error code: " + response.getStatus());
throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}
}
byte[] elements = IOUtils.toByteArray(response.getEntityInputStream());
response.close();
return elements;
}
use of com.sun.jersey.api.client.WebResource.Builder in project ORCID-Source by ORCID.
the class Orcid20APIClient method fetchFunding.
public Funding fetchFunding(String orcid, Long putCode) {
WebResource webResource = jerseyClient.resource(baseUri).path(orcid + "/funding/" + putCode);
webResource.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
Builder builder = webResource.accept(MediaType.APPLICATION_XML).header("Authorization", "Bearer " + accessToken);
ClientResponse response = builder.get(ClientResponse.class);
if (response.getStatus() != 200) {
switch(response.getStatus()) {
default:
LOG.error("Unable to fetch funding record " + orcid + "/" + putCode + " on API 2.0 HTTP error code: " + response.getStatus());
throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}
}
return response.getEntity(Funding.class);
}
use of com.sun.jersey.api.client.WebResource.Builder in project eureka by Netflix.
the class AbstractJerseyEurekaHttpClient method register.
@Override
public EurekaHttpResponse<Void> register(InstanceInfo info) {
String urlPath = "apps/" + info.getAppName();
ClientResponse response = null;
try {
Builder resourceBuilder = jerseyClient.resource(serviceUrl).path(urlPath).getRequestBuilder();
addExtraHeaders(resourceBuilder);
response = resourceBuilder.header("Accept-Encoding", "gzip").type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, info);
return anEurekaHttpResponse(response.getStatus()).headers(headersOf(response)).build();
} finally {
if (logger.isDebugEnabled()) {
logger.debug("Jersey HTTP POST {}{} with instance {}; statusCode={}", serviceUrl, urlPath, info.getId(), response == null ? "N/A" : response.getStatus());
}
if (response != null) {
response.close();
}
}
}
Aggregations