use of org.teiid.translator.ws.BinaryWSProcedureExecution in project teiid by teiid.
the class SwaggerMetadataProcessor method getSchema.
protected Swagger getSchema(WSConnection conn) throws TranslatorException {
Swagger swagger = null;
try {
String swaggerFile = getSwaggerFilePath();
if (swaggerFile != null && !swaggerFile.isEmpty()) {
File f = new File(swaggerFile);
if (!f.exists() || !f.isFile()) {
throw new TranslatorException(SwaggerPlugin.Event.TEIID28019, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28019, swaggerFile));
}
SwaggerParser parser = new SwaggerParser();
swagger = parser.read(f.getAbsolutePath(), null, true);
} else {
BaseQueryExecution execution = new BaseQueryExecution(this.ef, null, null, conn);
Map<String, List<String>> headers = new HashMap<String, List<String>>();
// $NON-NLS-1$ //$NON-NLS-2$
BinaryWSProcedureExecution call = execution.buildInvokeHTTP("GET", "swagger.json", null, headers);
call.execute();
if (call.getResponseCode() != 200) {
throw new TranslatorException(SwaggerPlugin.Event.TEIID28015, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28015, call.getResponseCode()));
}
Blob out = (Blob) call.getOutputParameterValues().get(0);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(out.getBinaryStream());
swagger = new SwaggerParser().read(rootNode, true);
}
} catch (Exception e) {
throw new TranslatorException(SwaggerPlugin.Event.TEIID28016, e, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28016, e));
}
return swagger;
}
Aggregations