5 Replies Latest reply on Jun 4, 2013 7:47 AM by shawkins

    EmbeddedServer with Web Service as Data Source

    websusk

      Currently I am using the Teiid Embedded Server (8.2.0) to connect to 2 different databases.  I have the 2 database connections working, and the virtual views are returning data.  I now need to replace one of the database sources with a web service source.  I'm having a hard time finding examples or a direction on how to do so outside of the Teiid Designer, which I am not using.

       

      1)  Are there special requirements that the given web service needs to follow? 

            -  Does it have to be REST, or can any old web service that returns data be used?  (Guessing WSDL URL is used as the endPoint)

      2)  The service in question required a call to a "login" method that returns an ID needed for any "get_data" call, so can multiple calls be used in 1 Teiid "get" call, such as "login() then get_data(), then logout()?

      3)  Any examples or can someone point me in the direction of the documentation for this?  Can't seem to find it in the admin guide.

       

      So, the following code is what I have for one of them (some changed, but the point is there)....

       

      DataSource datasource = craeteDataSource(config);  // create data source

      EmbeddedServer.ConnectionFactoryProvider jdbcProvider = new EmbeddedServer.SimpleConnectionFactoryProvider(datasource);

      teiidServer.addConnectionFactoryProvider("source-jdbc-db", jdbcProvider);

      teiidServer.addTranslator(SQLServerExecutionFactory.class);

       

      ModelMetaData metadata = new ModelMetaData();

      Properties p = new Properties();

      p.setProperty("importer.tableNamePattern", "TABLE_HERE");

      metadata.setProperties(p);

      metadata.setName("sql_db");

      metadata.setSchemaSourceType("native");

      metadata.addSourceMapping("sqlserver-connector-db", "sqlserver", "source-jdbc-db");

      ModelMetaData metadataVirtualView = new ModelMetaData();

      metadataVirtualView.setName("Data");

      metadataVirtualView.setModelType(Type.VIRTUAL);

      metadataVirtualView.setSchemaSourceType("ddl");

      metadataVirtualView.setSchemaText(DATA_QUERY);

       

      // deploy the VDB to the embedded server

      teiidServer.deployVDB("Teiid", metadata,metadataVirtualView);

        • 1. Re: EmbeddedServer with Web Service as Data Source
          websusk

          Is using a web service data source even supported with EmbeddedServer, or is the designer required for such a need?

          • 2. Re: EmbeddedServer with Web Service as Data Source
            rareddy

            Brian,

             

            You need develop a ConnectionFactory for web resource then you can use it. It is no different than JDBC in semantics. However, you want to see how you can wrap the Teiid supplied "WSConnectionImpl" or write your own for that purpose. The example provided with the "embedded" kit shows the File Connection as an example.

             

            Ramesh..

            • 3. Re: EmbeddedServer with Web Service as Data Source
              shawkins

              Brian,

               

              > Is using a web service data source even supported with EmbeddedServer, or is the designer required for such a need?

               

              Desinger is not required regardless.  It's more of question of whether you want to use an AS based Teiid instance.  There are two calling modes for the ws logic - soap based and arbitrary endpoint (presumably rest).  The soap paths, whether the usage of the invoke method or the use in 8.3+ of operation procedures imported from a WSDL requires CXF will be installed/configured.  The embedded kit currently does not include CXF.  I'll run through a test to see if the arbitrary endpoint, invokeHttp procedure, will work without CXF - but I suspect it won't due to how intertwined the logic is.

               

              > Are there special requirements that the given web service needs to follow?

               

              In a AS deployement the built-in logic supports both soap and simple http calls along with common options for authenticating.

               

              > The service in question required a call to a "login" method that returns an ID needed for any "get_data" call, so can multiple calls be used in 1 Teiid "get" call, such as "login() then get_data(), then logout()?

               

              This seems more like the interaction model used by Salesforce.  With Salesforce the notion of a connection/query span the login and execution cycle with interact over multiple ws calls.  You'd likely want to do something similar in a custom translator and/or resource adapter.

               

              > Any examples or can someone point me in the direction of the documentation for this?  Can't seem to find it in the admin guide.

               

              Yes, the docs are lite on embedded, but are sporadically expanding - https://docs.jboss.org/author/display/TEIID/Embedded+Guide mostly to highlight the vdb deployment and differences with the AS based deployment.  In theory you should just be able to add CXF to your embedded instance to use the built-in ws translator - you could contribute your experience to the docs if you do that.  However your interaction model of multiple calls to a single option means that you probably have to go a different route anyway as we do not currently have a built-in path to explicitly manage source connection lifecycles from user sql.

               

              The long winded explanation of the last point is that unless you are under a transaction with a source pool that is tracking connections by transaction, then the usage of a pooled resource is not guarenteed to use the same connection for multiple source queries under a given user query.  However there are times in a Teiid procedure where explicit connection management is useful so a feature request is warrented.

              • 4. Re: EmbeddedServer with Web Service as Data Source
                sahni02

                Hi ,

                 

                Any sample program on this (to connect the WS in TEIID embeded mode), it would be better if someone will post the sample program.

                 

                Nishikant Sahu

                • 5. Re: EmbeddedServer with Web Service as Data Source
                  shawkins

                  It's probably more of a problem of setting up the classpath/dependencies.  The code itself will be straight-forward:

                   

                  {code}

                  //create your server instance

                  EmbeddedServer es = new EmbeddedServer();

                  es.start(new EmbeddedConfiguration());

                   

                  //add a ws translator (you can also add a named instance if you need to set properties)

                  es.addTranslator(WSExecutionFactory.class);

                   

                  //add the connection factory

                  WSManagedConnectionFactory cf = new WSManagedConnectionFactory();

                  //set values on the managed connection factory as needed

                  es.addConnectionFactory("ws", cf.createConnectionFactory());

                   

                  //deploy a vdb

                  ModelMetaData mmd = new ModelMetaData();

                  mmd.setName("ws");

                  mmd.addSourceMapping("ws", "ws", "ws");

                  es.deployVDB("test", mmd);

                   

                  //do a simple http get

                  Connection c = es.getDriver().connect("jdbc:teiid:test", null);

                  Statement stmt = c.createStatement();

                  stmt.execute("select to_chars(x.result, 'UTF-8') from (call invokeHttp(action=>'GET', endpoint='http://www.cnn.com')) x");

                  ResultSet rs = stmt.getResultSet();

                  rs.next();

                  System.out.println(rs.getString(1));

                  {code}

                   

                  The translator/resource adapter are already included in the embedded kit.  From there you have to include the necessary CXF dependencies.  For latest see - https://github.com/teiid/teiid/blob/master/connectors/connector-ws/pom.xml - which has been updated over 8.3 to use CXF for the simple http/rest calls as well.

                   

                  Steve