I have a usecase for importing zip file into our microservice. Hence below is the code I have.
REST RESOURCE
---------------
@Path("/models")
@Provider
@Produces( {"application/json"} )
@OpenAPIDefinition(
info = @Info
(
title = "insightmanager",
version = "1.0.0",
description = "Insight Manager"
),
servers = {
@Server(
url = "{protocol}//{host}:{port}/{basePath}",
variables = {
@ServerVariable(name = "protocol",defaultValue = "http:"),
@ServerVariable(name = "host", defaultValue = "localhost"),
@ServerVariable(name = "port", defaultValue = "8765"),
@ServerVariable(name = "basePath",defaultValue="insight-server/api/1.0/")
})}
)
public class ModelResource {
@POST
@Path(value = "{modelId}/version}/importmodel")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Operation(summary = "import model ",
responses = {
@ApiResponse(responseCode = "200" ,description = "get t2p info",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = T2PInfo.class))),
@ApiResponse(responseCode = "500", description = "import failed",
content = @Content(mediaType="application/json",schema=@Schema(implementation = oracle.insight.server.rest.model.Status.class)))})
public Response importModel(@Context HttpHeaders headers, @FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData, @PathParam("version") String version,
@QueryParam("overwrite") boolean overwrite, @QueryParam("locale") String locale) {
ModelService modelService = ModelServiceFactory.INSTANCE.getModelService();
Response response = modelService.importModel(uploadedInputStream, overwrite, locale);
return response;
}
}
I have a Configuration Bundle like;
public class InsightManagerBundle implements ConfiguredBundle<DWInsightManagerConfiguration> {
@Override
public void run(final DWInsightManagerConfiguration configuration, final Environment environment) throws Exception {
configureCors(environment);
}
@Override
public void initialize(final Bootstrap<?> bootstrap) {
// nothing to do here, we need access to configuration and we won't have that until run() is executed.
}
private void configureCors(Environment environment) {
final FilterRegistration.Dynamic cors =
environment.servlets().addFilter("CORS", CrossOriginFilter.class);
// Configure CORS parameters
cors.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
cors.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "origin, content-type, accept, authorization");
cors.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "OPTIONS,GET,PUT,POST,DELETE,HEAD");
cors.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, "true");
// Add URL mapping
cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
}
}
This configuration bundle is being added in Application;
public final class DWInsightManagerApplication extends Application<DWInsightManagerConfiguration> {
public DWInsightManagerApplication() {
super();
}
@Override
public String getName() {
return DWInsightManagerConfiguration.ROOT_PATH;
}
@Override
public void run(final DWInsightManagerConfiguration configuration, final Environment environment) {
insightManager.customizeRouting(environment.jersey().getResourceConfig());
}
@Override
public void initialize(Bootstrap<DWInsightManagerConfiguration> bootstrap) {
super.initialize(bootstrap);
bootstrap.addBundle(new InsightManagerBundle());
}
}
I tried adding in our Configuration class or within run method of our application itself but it is of no use.
I always get "405 Method Not Allowed"
Response Headers;
HTTP/1.1 405 Method Not Allowed
Server: nginx
Date: Mon, 24 Jun 2019 09:04:50 GMT
Content-Length: 54
Connection: keep-alive
allow: DELETE,GET,OPTIONS,PUT
.........
DELETE, GET, PUT works without issues. This POST rest API works in other framework, so I do not see any issue with that.
Is there something am missing basic stuff or is it an issue with 2.0.0-rc3 candidate.
Any help would be highly appreciated.