use of javax.ws.rs.core.HttpHeaders.CONTENT_LOCATION in project aries-jax-rs-whiteboard by apache.
the class FrameworkBundlesResource method bundles.
// 137.3.2.2
@POST
@Consumes(TEXT_PLAIN)
@Produces({ APPLICATION_BUNDLE_JSON, APPLICATION_BUNDLE_XML })
@Path("framework/bundles{ext:(\\.json|\\.xml)*}")
@Operation(operationId = "POST/bundles", summary = "Installs a new bundle to the managed framework and thereby logically appends it to the bundles resource", requestBody = @RequestBody(description = "One of the following contents is allowed; a location string with content-type type 'text/plain' OR a bundle jar with content-type 'application/vnd.osgi.bundle'", required = true, content = { @Content(mediaType = TEXT_PLAIN, schema = @Schema(description = "a location string", type = "string")), @Content(mediaType = APPLICATION_VNDOSGIBUNDLE, schema = @Schema(description = "a bundle jar", type = "string", format = "binary")) }), responses = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = BundleSchema.class))), @ApiResponse(responseCode = "400", description = "the REST management service received a BundleException when trying to install", content = { @Content(mediaType = APPLICATION_BUNDLEEXCEPTION_JSON, schema = @Schema(implementation = BundleExceptionSchema.class)), @Content(mediaType = APPLICATION_BUNDLEEXCEPTION_XML, schema = @Schema(implementation = BundleExceptionSchema.class)) }), @ApiResponse(responseCode = "406", description = "The REST management service does not support any of the requested representations") }, parameters = { @Parameter(name = CONTENT_LOCATION, in = ParameterIn.HEADER, description = "When posting a bundle jar a location string can be specified using the 'Content-Location' header", required = false) })
public Response bundles(String location, @Parameter(allowEmptyValue = true, description = "File extension", schema = @Schema(allowableValues = { ".json", ".xml" })) @PathParam("ext") String ext, @HeaderParam(CONTENT_TYPE) MediaType contentType) {
try {
Instant now = Instant.now().minusMillis(2);
Bundle bundle = bundleContext.installBundle(location);
if (!now.isBefore(Instant.ofEpochMilli(bundle.getLastModified()))) {
throw new WebApplicationException(location, 409);
}
ResponseBuilder builder = Response.ok(bundleSchema(bundle));
return Optional.ofNullable(ext).map(String::trim).map(e -> ".json".equals(e) ? APPLICATION_BUNDLE_JSON : APPLICATION_BUNDLE_XML).map(type -> builder.type(type)).orElse(builder).build();
} catch (BundleException exception) {
return Response.status(400).type(contentType.equals(APPLICATION_BUNDLE_JSON_TYPE) ? APPLICATION_BUNDLEEXCEPTION_JSON_TYPE : APPLICATION_BUNDLEEXCEPTION_XML_TYPE).entity(BundleExceptionSchema.build(exception.getType(), exception.getMessage())).build();
}
}
use of javax.ws.rs.core.HttpHeaders.CONTENT_LOCATION in project aries-jax-rs-whiteboard by apache.
the class FrameworkBundlesResource method bundles.
// 137.3.2.3
@POST
@Consumes(APPLICATION_VNDOSGIBUNDLE)
@Produces({ APPLICATION_BUNDLE_JSON, APPLICATION_BUNDLE_XML })
@Path("framework/bundles{ext:(\\.json|\\.xml)*}")
@Operation(hidden = true)
public Response bundles(InputStream inputStream, @Parameter(allowEmptyValue = true, description = "File extension", schema = @Schema(allowableValues = { ".json", ".xml" })) @PathParam("ext") String ext, @HeaderParam(CONTENT_LOCATION) String location, @HeaderParam(CONTENT_TYPE) MediaType contentType) {
try {
location = Optional.ofNullable(location).orElseGet(() -> "org.apache.aries.jax.rs.whiteboard:".concat(UUID.randomUUID().toString()));
Instant now = Instant.now().minusMillis(2);
Bundle bundle = bundleContext.installBundle(location, inputStream);
if (!now.isBefore(Instant.ofEpochMilli(bundle.getLastModified()))) {
throw new WebApplicationException(location, 409);
}
ResponseBuilder builder = Response.ok(bundleSchema(bundle));
return Optional.ofNullable(ext).map(String::trim).map(e -> ".json".equals(e) ? APPLICATION_BUNDLE_JSON : APPLICATION_BUNDLE_XML).map(type -> builder.type(type)).orElse(builder).build();
} catch (BundleException exception) {
return Response.status(400).type(contentType.equals(APPLICATION_BUNDLE_JSON_TYPE) ? APPLICATION_BUNDLEEXCEPTION_JSON_TYPE : APPLICATION_BUNDLEEXCEPTION_XML_TYPE).entity(BundleExceptionSchema.build(exception.getType(), exception.getMessage())).build();
}
}
Aggregations