Search in sources :

Example 16 with BinaryWSProcedureExecution

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;
}
Also used : Blob(java.sql.Blob) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) MetadataException(org.teiid.metadata.MetadataException) TranslatorException(org.teiid.translator.TranslatorException) SwaggerParser(io.swagger.parser.SwaggerParser) Swagger(io.swagger.models.Swagger) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) TranslatorException(org.teiid.translator.TranslatorException) List(java.util.List) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)16 Blob (java.sql.Blob)11 List (java.util.List)10 SQLException (java.sql.SQLException)9 ArrayList (java.util.ArrayList)9 TranslatorException (org.teiid.translator.TranslatorException)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Argument (org.teiid.language.Argument)4 Call (org.teiid.language.Call)4 Literal (org.teiid.language.Literal)4 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 HashMap (java.util.HashMap)3 EdmDataServices (org.odata4j.edm.EdmDataServices)3 Schema (org.teiid.metadata.Schema)3 IOException (java.io.IOException)2 TreeMap (java.util.TreeMap)2 Status (javax.ws.rs.core.Response.Status)2 HttpStatusCode (org.apache.olingo.commons.api.http.HttpStatusCode)2 ODataVersion (org.odata4j.core.ODataVersion)2