use of org.eclipse.vorto.plugin.utils.ApiGatewayResponse in project vorto by eclipse.
the class GeneratorExecutionHandler method handleRequest.
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
ObjectMapper mapper = ObjectMapperFactory.getInstance();
ApiGatewayRequest request = ApiGatewayRequest.createFromJson(input);
Optional<ICodeGenerator> generator = generators.stream().filter(gen -> gen.getMeta().getKey().equals(request.getPathParam(PLUGINKEY))).findAny();
if (!generator.isPresent()) {
objectMapper.writeValue(output, createHttpReponse(404));
}
ModelContent modelContent = mapper.readValue(request.getInput(), ModelContent.class);
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
Model converted = converter.convert(modelContent, Optional.empty());
InvocationContext invocationContext = InvocationContext.simpleInvocationContext(request.getQueryParams());
InformationModel infomodel = org.eclipse.vorto.plugin.utils.Utils.toInformationModel(converted);
try {
IGenerationResult generatorResult = generator.get().generate(infomodel, invocationContext);
ApiGatewayResponse validResponse = createResponse(generatorResult);
OutputStreamWriter writer = new OutputStreamWriter(output, "UTF-8");
writer.write(objectMapper.writeValueAsString(validResponse));
writer.close();
} catch (GeneratorException e) {
ApiGatewayResponse response = createHttpReponse(500);
objectMapper.writeValue(output, response);
}
}
use of org.eclipse.vorto.plugin.utils.ApiGatewayResponse in project vorto by eclipse.
the class GeneratorMetaHandler method handleRequest.
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
ApiGatewayRequest request = ApiGatewayRequest.createFromJson(input);
GeneratorPluginInfo pluginInfo = GeneratorPluginInfoFactory.getInstance().getForPlugin(request.getPathParam("pluginkey"));
if (pluginInfo == null) {
ApiGatewayResponse response = ApiGatewayResponse.builder().setStatusCode(404).build();
objectMapper.writeValue(output, response);
} else {
ApiGatewayResponse gatewayResponse = ApiGatewayResponse.builder().setStatusCode(200).setRawBody(objectMapper.writeValueAsString(pluginInfo)).build();
objectMapper.writeValue(output, gatewayResponse);
}
}
Aggregations