use of org.teiid.translator.ws.BinaryWSProcedureExecution in project teiid by teiid.
the class S3ProcedureExecution method invokeHTTP.
protected BinaryWSProcedureExecution invokeHTTP(String method, String uri, Object payload, Map<String, String> headers) throws TranslatorException {
Map<String, List<String>> targetHeaders = new HashMap<String, List<String>>();
headers.forEach((k, v) -> targetHeaders.put(k, Arrays.asList(v)));
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_WS, MessageLevel.DETAIL)) {
try {
LogManager.logDetail(LogConstants.CTX_WS, "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.OBJECT), 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.ef.getLanguageFactory().createCall("invokeHttp", parameters, null);
BinaryWSProcedureExecution execution = new BinaryWSProcedureExecution(call, this.metadata, this.ec, null, this.conn);
execution.setUseResponseContext(true);
execution.setCustomHeaders(targetHeaders);
return execution;
}
use of org.teiid.translator.ws.BinaryWSProcedureExecution in project teiid by teiid.
the class ODataMetadataProcessor method getEds.
private EdmDataServices getEds(WSConnection conn) throws TranslatorException {
try {
BaseQueryExecution execution = new BaseQueryExecution(ef, null, null, conn);
// $NON-NLS-1$ //$NON-NLS-2$
BinaryWSProcedureExecution call = execution.executeDirect("GET", "$metadata", null, execution.getDefaultHeaders());
if (call.getResponseCode() != Status.OK.getStatusCode()) {
throw execution.buildError(call);
}
Blob out = (Blob) call.getOutputParameterValues().get(0);
EdmDataServices eds = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(out.getBinaryStream())));
return eds;
} catch (SQLException e) {
throw new TranslatorException(e);
} catch (Exception e) {
throw new TranslatorException(e);
}
}
use of org.teiid.translator.ws.BinaryWSProcedureExecution in project teiid by teiid.
the class BaseQueryExecution method executeQuery.
protected InputStream executeQuery(String method, String uri, String payload, String eTag, HttpStatusCode[] 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) {
headers.put("Content-Type", // $NON-NLS-1$
Arrays.asList(ContentType.APPLICATION_JSON.toContentTypeString()));
}
BinaryWSProcedureExecution execution;
try {
execution = invokeHTTP(method, uri, payload, headers);
for (HttpStatusCode status : expectedStatus) {
if (status.getStatusCode() == execution.getResponseCode()) {
if (execution.getResponseCode() != HttpStatusCode.NO_CONTENT.getStatusCode() && execution.getResponseCode() != HttpStatusCode.NOT_FOUND.getStatusCode()) {
Blob blob = (Blob) execution.getOutputParameterValues().get(0);
return blob.getBinaryStream();
}
// this is success with no-data
return null;
}
}
} catch (SQLException e) {
throw new TranslatorException(e);
}
// throw an error
throw buildError(execution);
}
use of org.teiid.translator.ws.BinaryWSProcedureExecution in project teiid by teiid.
the class ODataProcedureExecution method execute.
@Override
public void execute() throws TranslatorException {
String URI = this.visitor.buildURL();
Schema schema = visitor.getProcedure().getParent();
EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
if (this.visitor.hasCollectionReturn()) {
if (this.visitor.isReturnComplexType()) {
// complex return
this.response = executeWithComplexReturn(this.visitor.getMethod(), URI, null, this.visitor.getReturnEntityTypeName(), edm, null, Status.OK, Status.NO_CONTENT);
} else {
// entity type return
this.response = executeWithReturnEntity(this.visitor.getMethod(), URI, null, this.visitor.getTable().getName(), edm, null, Status.OK, Status.NO_CONTENT);
}
if (this.response != null && this.response.hasError()) {
throw this.response.getError();
}
} else {
try {
BinaryWSProcedureExecution execution = executeDirect(this.visitor.getMethod(), URI, null, getDefaultHeaders());
if (execution.getResponseCode() != Status.OK.getStatusCode()) {
throw buildError(execution);
}
Blob blob = (Blob) execution.getOutputParameterValues().get(0);
ODataVersion version = getODataVersion(execution);
// if the procedure is not void
if (this.visitor.getReturnType() != null) {
FormatParser<? extends OObject> parser = FormatParserFactory.getParser(OSimpleObject.class, FormatType.ATOM, new Settings(version, edm, this.visitor.getProcedure().getName(), // entitykey
null, // isResponse
true, ODataTypeManager.odataType(this.visitor.getReturnType())));
OSimpleObject object = (OSimpleObject) parser.parse(new InputStreamReader(blob.getBinaryStream()));
this.returnValue = this.translator.retrieveValue(object.getValue(), this.visitor.getReturnTypeClass());
}
} catch (SQLException e) {
throw new TranslatorException(e);
}
}
}
use of org.teiid.translator.ws.BinaryWSProcedureExecution in project teiid by teiid.
the class ODataQueryExecution method execute.
@Override
public void execute() throws TranslatorException {
String URI = this.visitor.buildURL();
if (this.visitor.isCount()) {
Map<String, List<String>> headers = new TreeMap<String, List<String>>();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
headers.put("Accept", Arrays.asList("text/xml", "text/plain"));
// $NON-NLS-1$
BinaryWSProcedureExecution execution = executeDirect("GET", URI, null, headers);
if (execution.getResponseCode() != Status.OK.getStatusCode()) {
throw buildError(execution);
}
Blob blob = (Blob) execution.getOutputParameterValues().get(0);
try {
this.countResponse = Integer.parseInt(ObjectConverterUtil.convertToString(blob.getBinaryStream()));
} catch (IOException e) {
throw new TranslatorException(e);
} catch (SQLException e) {
throw new TranslatorException(e);
}
} else {
Schema schema = visitor.getEnityTable().getParent();
EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
// $NON-NLS-1$
this.response = executeWithReturnEntity("GET", URI, null, visitor.getEnityTable().getName(), edm, null, Status.OK, Status.NO_CONTENT, Status.NOT_FOUND);
if (this.response != null && this.response.hasError()) {
throw this.response.getError();
}
}
}
Aggregations