Search in sources :

Example 1 with ClientODataDeserializerImpl

use of org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl in project teiid by teiid.

the class TestODataMetadataProcessor method createMetadata.

private static MetadataFactory createMetadata(final String file, final String schema, final String schemaNamespace) throws TranslatorException {
    ODataMetadataProcessor processor = new ODataMetadataProcessor() {

        protected XMLMetadata getSchema(WSConnection conn) throws TranslatorException {
            try {
                ClientODataDeserializerImpl deserializer = new ClientODataDeserializerImpl(false, ContentType.APPLICATION_XML);
                XMLMetadata metadata = deserializer.toMetadata(new FileInputStream(UnitTestUtil.getTestDataFile(file)));
                return metadata;
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    };
    Properties props = new Properties();
    props.setProperty("schemaNamespace", schemaNamespace);
    processor.setSchemaNamespace(schemaNamespace);
    MetadataFactory mf = new MetadataFactory("vdb", 1, schema, SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    processor.process(mf, null);
    return mf;
}
Also used : WSConnection(org.teiid.translator.WSConnection) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) FileNotFoundException(java.io.FileNotFoundException) ClientODataDeserializerImpl(org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl) XMLMetadata(org.apache.olingo.client.api.edm.xml.XMLMetadata) ClientCsdlXMLMetadata(org.apache.olingo.client.core.edm.ClientCsdlXMLMetadata) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 2 with ClientODataDeserializerImpl

use of org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl 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)

Aggregations

ClientODataDeserializerImpl (org.apache.olingo.client.core.serialization.ClientODataDeserializerImpl)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Blob (java.sql.Blob)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Properties (java.util.Properties)1 XMLMetadata (org.apache.olingo.client.api.edm.xml.XMLMetadata)1 ClientCsdlXMLMetadata (org.apache.olingo.client.core.edm.ClientCsdlXMLMetadata)1 MetadataFactory (org.teiid.metadata.MetadataFactory)1 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)1 WSConnection (org.teiid.translator.WSConnection)1 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)1