Search in sources :

Example 6 with BinaryWSProcedureExecution

use of org.teiid.translator.ws.BinaryWSProcedureExecution in project teiid by teiid.

the class BaseQueryExecution method buildInvokeHTTP.

protected BinaryWSProcedureExecution buildInvokeHTTP(String method, String uri, Object payload, Map<String, List<String>> headers) throws TranslatorException {
    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_CONNECTOR, MessageLevel.DETAIL)) {
        try {
            LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Source-URL=", // $NON-NLS-1$ //$NON-NLS-2$
            URLDecoder.decode(uri, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
        }
    }
    List<Argument> parameters = new ArrayList<Argument>();
    parameters.add(new Argument(Direction.IN, new Literal(method, TypeFacility.RUNTIME_TYPES.STRING), null));
    parameters.add(new Argument(Direction.IN, new Literal(payload, TypeFacility.RUNTIME_TYPES.STRING), null));
    parameters.add(new Argument(Direction.IN, new Literal(uri, TypeFacility.RUNTIME_TYPES.STRING), null));
    parameters.add(new Argument(Direction.IN, new Literal(true, TypeFacility.RUNTIME_TYPES.BOOLEAN), null));
    // the engine currently always associates out params at resolve time even if the
    // values are not directly read by the call
    parameters.add(new Argument(Direction.OUT, TypeFacility.RUNTIME_TYPES.STRING, null));
    Call call = this.translator.getLanguageFactory().createCall("invokeHttp", parameters, null);
    BinaryWSProcedureExecution execution = new BinaryWSProcedureExecution(call, this.metadata, this.executionContext, null, this.connection);
    execution.setUseResponseContext(true);
    execution.setCustomHeaders(headers);
    return execution;
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) Literal(org.teiid.language.Literal) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 7 with BinaryWSProcedureExecution

use of org.teiid.translator.ws.BinaryWSProcedureExecution in project teiid by teiid.

the class SwaggerProcedureExecution method execute.

@Override
public void execute() throws TranslatorException {
    Procedure procedure = this.command.getMetadataObject();
    BinaryWSProcedureExecution execution = buildWSExecution(this.command);
    execution.execute();
    if (execution.getResponseCode() >= 200 && execution.getResponseCode() < 300) {
        this.responseHeaders = execution.getResponseHeaders();
        // Success
        if (procedure.getResultSet() != null) {
            if (procedure.getResultSet().getColumns().get(0).getName().equals("return")) {
                // this procedure with return, but headers made this into a resultset.
                this.returnValue = getReturnValue(execution);
            } else {
                try {
                    Blob blob = (Blob) execution.getOutputParameterValues().get(0);
                    InputStream wsResponse = blob.getBinaryStream();
                    Object obj = execution.getResponseHeader("Content-Type");
                    if (obj == null) {
                        throw new TranslatorException(SwaggerPlugin.Event.TEIID28017, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28017, "Not Defined"));
                    } else {
                        List<?> contentType = (List<?>) obj;
                        SwaggerSerializer serializer = getSerializer(contentType.get(0).toString());
                        if (serializer == null) {
                            throw new TranslatorException(SwaggerPlugin.Event.TEIID28017, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28017, obj.toString()));
                        }
                        handleResponse(procedure, wsResponse, execution.getResponseHeaders(), serializer);
                    }
                } catch (SQLException e) {
                    throw new TranslatorException(e);
                }
            }
        } else if (getReturnParameter() != null) {
            // this is scalar result
            this.returnValue = getReturnValue(execution);
        }
    } else if (execution.getResponseCode() == 404) {
    // treat as empty response. Typically that when someone uses it.
    } else {
        throw new TranslatorException(SwaggerPlugin.Event.TEIID28018, SwaggerPlugin.Util.gs(SwaggerPlugin.Event.TEIID28018, execution.getResponseCode()));
    }
}
Also used : Blob(java.sql.Blob) SQLException(java.sql.SQLException) InputStream(java.io.InputStream) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) Procedure(org.teiid.metadata.Procedure) TranslatorException(org.teiid.translator.TranslatorException) List(java.util.List)

Example 8 with BinaryWSProcedureExecution

use of org.teiid.translator.ws.BinaryWSProcedureExecution in project teiid by teiid.

the class BaseQueryExecution method invokeHTTP.

protected BinaryWSProcedureExecution invokeHTTP(String method, String uri, String payload, Map<String, List<String>> headers) throws TranslatorException {
    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_ODATA, MessageLevel.DETAIL)) {
        try {
            LogManager.logDetail(LogConstants.CTX_ODATA, "Source-URL=", // $NON-NLS-1$ //$NON-NLS-2$
            URLDecoder.decode(uri, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
        }
    }
    List<Argument> parameters = new ArrayList<Argument>();
    parameters.add(new Argument(Direction.IN, new Literal(method, TypeFacility.RUNTIME_TYPES.STRING), null));
    parameters.add(new Argument(Direction.IN, new Literal(payload, TypeFacility.RUNTIME_TYPES.STRING), null));
    parameters.add(new Argument(Direction.IN, new Literal(uri, TypeFacility.RUNTIME_TYPES.STRING), null));
    parameters.add(new Argument(Direction.IN, new Literal(true, TypeFacility.RUNTIME_TYPES.BOOLEAN), null));
    // the engine currently always associates out params at resolve time even if the
    // values are not directly read by the call
    parameters.add(new Argument(Direction.OUT, TypeFacility.RUNTIME_TYPES.STRING, null));
    Call call = this.translator.getLanguageFactory().createCall(ODataExecutionFactory.INVOKE_HTTP, parameters, null);
    BinaryWSProcedureExecution execution = new BinaryWSProcedureExecution(call, this.metadata, this.executionContext, null, this.connection);
    execution.setUseResponseContext(true);
    execution.setCustomHeaders(headers);
    execution.execute();
    return execution;
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) Literal(org.teiid.language.Literal) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 9 with BinaryWSProcedureExecution

use of org.teiid.translator.ws.BinaryWSProcedureExecution in project teiid by teiid.

the class ODataExecutionFactory method getSchema.

protected XMLMetadata getSchema(WSConnection conn) throws TranslatorException {
    if (this.serviceMatadata == null) {
        try {
            BaseQueryExecution execution = new BaseQueryExecution(this, null, null, conn);
            Map<String, List<String>> headers = new HashMap<String, List<String>>();
            // $NON-NLS-1$ //$NON-NLS-2$
            BinaryWSProcedureExecution call = execution.invokeHTTP("GET", "$metadata", null, headers);
            if (call.getResponseCode() != HttpStatusCode.OK.getStatusCode()) {
                throw execution.buildError(call);
            }
            Blob out = (Blob) call.getOutputParameterValues().get(0);
            ClientODataDeserializerImpl deserializer = new ClientODataDeserializerImpl(false, ContentType.APPLICATION_XML);
            this.serviceMatadata = deserializer.toMetadata(out.getBinaryStream());
            return this.serviceMatadata;
        } catch (SQLException e) {
            throw new TranslatorException(e);
        } catch (Exception e) {
            throw new TranslatorException(e);
        }
    }
    return this.serviceMatadata;
}
Also used : Blob(java.sql.Blob) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ClientODataDeserializerImpl(org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl) ArrayList(java.util.ArrayList) List(java.util.List) SQLException(java.sql.SQLException)

Example 10 with BinaryWSProcedureExecution

use of org.teiid.translator.ws.BinaryWSProcedureExecution in project teiid by teiid.

the class BaseQueryExecution method executeWithReturnEntity.

protected ODataEntitiesResponse executeWithReturnEntity(String method, String uri, String payload, String entityTable, EdmDataServices edsMetadata, String eTag, Status... expectedStatus) throws TranslatorException {
    Map<String, List<String>> headers = getDefaultHeaders();
    if (eTag != null) {
        // $NON-NLS-1$
        headers.put("If-Match", Arrays.asList(eTag));
    }
    if (payload != null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        headers.put("Content-Type", Arrays.asList("application/atom+xml"));
    }
    BinaryWSProcedureExecution execution = executeDirect(method, uri, payload, headers);
    for (Status status : expectedStatus) {
        if (status.getStatusCode() == execution.getResponseCode()) {
            if (execution.getResponseCode() != Status.NO_CONTENT.getStatusCode() && execution.getResponseCode() != Status.NOT_FOUND.getStatusCode()) {
                Blob blob = (Blob) execution.getOutputParameterValues().get(0);
                ODataVersion version = getODataVersion(execution);
                Feed feed = parse(blob, version, entityTable, edsMetadata);
                return new ODataEntitiesResponse(uri, feed, entityTable, edsMetadata);
            }
            // this is success with no-data
            return new ODataEntitiesResponse();
        }
    }
    // throw an error
    return new ODataEntitiesResponse(buildError(execution));
}
Also used : Status(javax.ws.rs.core.Response.Status) Blob(java.sql.Blob) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ODataVersion(org.odata4j.core.ODataVersion) ArrayList(java.util.ArrayList) List(java.util.List) Feed(org.odata4j.format.Feed)

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