9 Replies Latest reply on Jul 22, 2016 12:59 PM by rareddy

    parsing exception while using  procedure invokeHttp of Rest Translator

    durgadatta

      Hi I am using following procedure,

       

      exec invokeHttp('POST','"+"select * from EMPLOYEE  where EMP_NAME='Dinesh'"+"', '" + url + "', 'TRUE', '"+header+"')

       

      Here header is a json object ;

       

      I am using TEIID EMBEDDED 9.0.1

       

      During execution the following parsing error is coming .

      Here I am passing EMP_NAME as a string so I have to enclose it within single quote , there the parsing error is coming .

       

      Please help me out , how to send the string with single quote .

       

       

       

       

      Caused by: org.teiid.api.exception.query.QueryParserException: TEIID31100 Parsing error: Encountered "'POST','select * from EMPLOYEE where EMP_NAME ='[*]Dinesh[*]''," at line 1, column 72.

      Was expecting: "and" | "between" | "in" | "is" | "like" | "like_regex" | "not" | "or" | "similar" | "," ...

      at org.teiid.query.parser.QueryParser.convertParserException(QueryParser.java:214)

      at org.teiid.query.parser.QueryParser.parseCommand(QueryParser.java:164)

      at org.teiid.query.parser.QueryParser.parseCommand(QueryParser.java:140)

      at org.teiid.dqp.internal.process.Request.parseCommand(Request.java:305)

      at org.teiid.dqp.internal.process.Request.generatePlan(Request.java:399)

      at org.teiid.dqp.internal.process.PreparedStatementRequest.generatePlan(PreparedStatementRequest.java:119)

      at org.teiid.dqp.internal.process.Request.processRequest(Request.java:473)

      at org.teiid.dqp.internal.process.PreparedStatementRequest.processRequest(PreparedStatementRequest.java:294)

      at org.teiid.dqp.internal.process.RequestWorkItem.processNew(RequestWorkItem.java:642)

      at org.teiid.dqp.internal.process.RequestWorkItem.process(RequestWorkItem.java:337)

      at org.teiid.dqp.internal.process.AbstractWorkItem.run(AbstractWorkItem.java:51)

      at org.teiid.dqp.internal.process.RequestWorkItem.run(RequestWorkItem.java:274)

      at org.teiid.dqp.internal.process.DQPCore.executeRequest(DQPCore.java:313)

      at org.teiid.dqp.internal.process.DQPCore.executeRequest(DQPCore.java:245)

      at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

      at java.lang.reflect.Method.invoke(Method.java:483)

      at org.teiid.transport.LocalServerConnection$1$1.call(LocalServerConnection.java:177)

      at java.util.concurrent.FutureTask.run(FutureTask.java:266)

      at org.teiid.dqp.internal.process.DQPWorkContext.runInContext(DQPWorkContext.java:276)

      at org.teiid.dqp.internal.process.DQPWorkContext.runInContext(DQPWorkContext.java:260)

      at org.teiid.transport.LocalServerConnection$1.invoke(LocalServerConnection.java:175)

      at com.sun.proxy.$Proxy19.executeRequest(Unknown Source)

      at org.teiid.jdbc.StatementImpl.execute(StatementImpl.java:688)

      at org.teiid.jdbc.StatementImpl.executeSql(StatementImpl.java:554)

        • 1. Re: parsing exception while using  procedure invokeHttp of Rest Translator
          bmajsak

          Moved from Arquillian to Teiid forum.

          • 2. Re: parsing exception while using  procedure invokeHttp of Rest Translator
            rareddy

            invokeHTTP as name suggests is to invoke a http call, not a SQL call. See the documentation at Web Services Translator · Teiid Documentation

             

            An example VDB would be like to read an XML file

            <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
            <vdb name="webservice" version="1">
                <description>Shows how to call Web Services</description>
                
                <model name="CustomerSource">
                    <source name="webservice" translator-name="ws" connection-jndi-name="java:/webDS"/>
                </model>
                
                  <model name="Customers" type="VIRTUAL">
                    <metadata type="DDL"><![CDATA[        
                          CREATE  VIEW CustomersView (
                           customernumber varchar(100) PRIMARY KEY, customername varchar(200), contactlastname varchar(100),  contactfirstname varchar(100))
                          AS
                           SELECT
                                 A.customernumber, A.customername, A.contactlastname, A.contactfirstname
                           FROM
                            (EXEC CustomerSource.invokeHttp('GET', null, 'http://localhost:8080/CustomerRESTWebSvc/MyRESTApplication/customerList', 'TRUE')) AS f,
                            XMLTABLE('/customers/customer' PASSING XMLPARSE(DOCUMENT f.result) COLUMNS customernumber string PATH 'customernumber/text()',
                            customername string PATH 'customername/text()', contactlastname string PATH 'contactlastname/text()', contactfirstname string PATH 'contactfirstname/text()') AS A;          
                    ]]>
                    </metadata>
                </model>
            </vdb>
            

             

            The URL in the invokeHttp can be relative or absolute. If it is relative then the base uri needs to be defined in the data source defined by "java:/webDS" in above example. For creating the data source see example here Web Service Data Sources · Teiid Documentation

             

            if the payload is JSON, then wrap the response with JSONTOXML function to convert into XML, then use above to parse into tabular results.

             

            HTH

             

            Ramesh..

            • 3. Re: parsing exception while using  procedure invokeHttp of Rest Translator
              durgadatta

              Thanks Ramesh for quick replay . Actually here I am calling rest URL , and I need to pass sql query as a request body parameter to target REST server.

              So I have tried passing the query  as a json object and also as a string, in both case it is failing .

               

              Here my requirement is to pass the sql query to REST server . Is it achievable from VDB ?

               

              How to pass the above sql query  as request object ?

               

              Thanks,

              Durga 

              • 4. Re: parsing exception while using  procedure invokeHttp of Rest Translator
                durgadatta

                I am using this procedure (invokeHttP) in my custom Translator ,

                • 5. Re: parsing exception while using  procedure invokeHttp of Rest Translator
                  rareddy

                  >Here my requirement is to pass the sql query to REST server . Is it achievable from VDB ?

                  absolutely


                  >How to pass the above sql query  as request object ?

                  depends on how you design your rest service, is it a GET or POST etc.


                  >I am using this procedure (invokeHttP) in my custom Translator ,

                  Not in the exception stack you provided above, you are calling it directly from JDBC layer. In that case, you need to strictly follow the invokeHTTP calling semantics.

                  If you want to write custom translator, then you would need to extend "ws" translator and write your own. See examples of "swagger" and "odata4", "odata" as how they extended and using the existing "ws" translator to issue "http" calls.

                  1 of 1 people found this helpful
                  • 6. Re: parsing exception while using  procedure invokeHttp of Rest Translator
                    durgadatta

                    I am executing invokeHttp procedure from custom translator , as jdbc procedure execution .


                    There I am sending POSt request with following syntax


                    exec invokeHttp('POST','"+"select * from EMPLOYEE  where EMP_NAME='Dinesh'"+"', '" + "http://localhost:8081/wsendpoint" + "', 'TRUE', '"+header+"')


                    and  here "header" is a  json object .


                    in this case parsing error is coming . It is not allowing String value in in request parameter ( EMP_NAME='Dinesh' ) . If I am passing any other type long/int (like EMP_ID=10)  it is working .


                    So how to pass String value here ?









                     

                    • 7. Re: parsing exception while using  procedure invokeHttp of Rest Translator
                      shawkins

                      > in this case parsing error is coming . It is not allowing String value in in request parameter ( EMP_NAME='Dinesh' ) . If I am passing any other type long/int (like EMP_ID=10)  it is working .


                      If you nest a single quote in a string literal it needs to be escaped with another single quote ''Dinesh''

                      • 8. Re: parsing exception while using  procedure invokeHttp of Rest Translator
                        durgadatta

                        Thanks Steven . I miss lead the problem, this solved the problem .

                         

                        If we want to pass dynamic query  as arguments in invokeHttp procedure within vdb file. what will be the syntax ?

                         

                        for example  ,

                        If user trigger  query "SELECT * from EMPLOYEE ", I have to pass this query OVER rest call , is it doable from VDB ?

                         

                        Here EMPLOYEE is a view on top of  invokeHttp() procedure .

                         

                        Any sample example or vdb file  will be helpful .

                         

                        Thanks,

                        Durga

                        • 9. Re: parsing exception while using  procedure invokeHttp of Rest Translator
                          rareddy

                          It depends upon how you defined transformation query of the EMPLOYEE view. It is not automatically passed. A View gets executed at the Teiid engine level, so what is in transformation SQL matters. If view is based on some source table in custom translator, then if one executes the view, you will see relevant access to that source table, which could be a invokeHttp call in your translator, with full freedom to send whatever you want.