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;
}
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()));
}
}
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;
}
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;
}
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));
}
Aggregations