1 2 3 4 Previous Next 46 Replies Latest reply on Nov 19, 2018 2:57 PM by cagreek

    401 Unauthorized in REST Web Service Source

    vijayjose

      Using jboss EAP 7 and Teiid Designer 10.4 and wildfly 10.

       

      Using  Web Service Source-Source and View Models(REST)  How to Consume a JSON REST Web Service in Teiid Designer .

       

      REST api is working finely.selected Security type as NONE and generated vdb.

       

      When executing vdb ,getting an error

       

      org.teiid.core.TeiidProcessingException: TEIID30504 SourceModel: TEIID15005 Error Calling HTTP Service - 401 Unauthorized

       

      And when running the preview data of procedure ,query get executed and return everything as null.

       

      Attaching server.log

        • 1. Re: 401 Unauthorized in REST Web Service Source
          rareddy

          Vijay,

           

          I do not think when the data source got created in the Server, Designer did not configure the credentials on web resource adapter.  You can edit, standalone-teiid.xml file on server, find the resource-adapter subsystem and your RA config and provide the credentials as per here Web Service Data Sources · Teiid Documentation and restart the server, then you should work correctly.

           

          Ramesh..

          • 2. Re: 401 Unauthorized in REST Web Service Source
            vijayjose

            I didn't get it correctly.

             

            This is my resource adapter.

             

            <resource-adapter id="SourceModel_DS">

                                <module slot="main" id="org.jboss.teiid.resource-adapter.webservice"/>

                                <transaction-support>NoTransaction</transaction-support>

                                <connection-definitions>

                                    <connection-definition class-name="org.teiid.resource.adapter.ws.WSManagedConnectionFactory" jndi-name="java:/SourceModel_DS" enabled="true" pool-name="SourceModel_DS">

                                        <config-property name="EndPoint">

                                            http://192.168.1.67:8090/db/chnl/settings/1370

                                        </config-property>

                                        <config-property name="SecurityType">

                                            None

                                        </config-property>

                                    </connection-definition>

                                </connection-definitions>

                            </resource-adapter>

             

            when testing the connection of REST web service source, showing error,

            java.lang.Exception: Failed to validate the WSDL connection at org.teiid.designer.datatools.profiles.ws.WSWizardUtils.testRestURLConnection(WSWizardUtils.java:125) at org.teiid.designer.datatools.profiles.ws.WSProfileDetailsWizardPage$URLPingJob.testXmlUrlConnection(WSProfileDetailsWizardPage.java:598) at org.teiid.designer.datatools.profiles.ws.WSProfileDetailsWizardPage$URLPingJob.run(WSProfileDetailsWizardPage.java:588) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

            • 3. Re: 401 Unauthorized in REST Web Service Source
              rareddy

              SecurityType can not be "None" based on your Web Service. You need to configure it to what your service requires. See Web Service Data Sources · Teiid Documentation

               

              If it is HHTPBasic, then supply the user name and password.

               

               <config-property name="SecurityType">HTTPBasic</config-property>
               <config-property name="AuthUserName">xxxxxxxxxxx</config-property>
               <config-property name="AuthPassword">xxxxxxxxxxx</config-property>
              

               

              Ramesh..

              • 4. Re: 401 Unauthorized in REST Web Service Source
                vijayjose

                Using a token for security and passing it as a header.There is no username and password.

                • 5. Re: 401 Unauthorized in REST Web Service Source
                  rareddy

                  Is that some custom header or some authentication scheme that Teiid may or may not support yet?

                   

                  BTW, if it is a custom header, you can provide a CXF configuration to the resource-adapter and follow directions like in this post [1] to supply the header.

                   

                  [1] How do i modify HTTP headers for a JAX-WS response in CXF? - Stack Overflow

                  • 6. Re: 401 Unauthorized in REST Web Service Source
                    vijayjose

                    Why Authentication Failed:This request requires HTTP authentication error is showing when i use security type as none and adding my security token as header.

                     

                    The token value changes  dynamically(20 minutes),so it is difficult to change the java code every time.

                    Is there any alternate method.

                     

                    I tried to add CXF configuration to resource-adapter:

                    copied CXF Configuration from https://teiid.gitbooks.io/documents/content/admin/Web_Service_Data_Sources.html added the file as a config-property in resource-adapter.

                    created a java file and added xml  to config property xml file.

                    But it is showing error:

                    The prefix "cxf" for element "cxf:bus" is not bound attaching the xml file.

                     

                    Where should i place the java file?

                    • 7. Re: 401 Unauthorized in REST Web Service Source
                      rareddy

                      You need to add the Java file in JAR in the following module directory "<wildflyinstall>/modules/system/layers/dv/org/jboss/teiid/resource-adapter/webservice/main". Then edit module.xml in this directory to add the name of your JAR. As per the error, I would need to see full error to figure out where may be an issue.

                       

                      If the Token changes every 20 mins then your Java file needs to be smart enough to figure out what that code is and adjust to that. Another option is, the invokeHTTP call you are making in your model can take an argument to send a custom header. See [1] at invokeHTTP Procedure section. If you take this route, you do not need to pass in the CXF configuration file above or provide the Java implementation. However, you would need to device a way to send this authorization token to your procedure/statement that is using this invokeHTTP call.

                       

                      [1] Web Services Translator · Teiid Documentation

                      • 8. Re: 401 Unauthorized in REST Web Service Source
                        vijayjose

                        When i am selecting security time as none and giving the correct token as header and without any of the modification,I am getting the correct answer with(SUCCESS 200) in preview data of procedure.And if i create a vdb and run it ,showing 401.

                         

                        Attaching the log file with error :The prefix "cxf" for element "cxf:bus" is not bound .

                        • 9. Re: 401 Unauthorized in REST Web Service Source
                          vijayjose

                          Is there any example ,how to add invokeHTTP Procedure section?

                          • 10. Re: 401 Unauthorized in REST Web Service Source
                            rareddy

                            The issue is designer uses a  different execution logic than the server. Server execution is much more extensive in terms of configurability.

                             

                            as per invokeHttp example, is you seen the link I provided above, it has an example in there

                            call invokeHttp(... headers=>jsonObject('application/json' as "Content-Type", jsonArray('gzip', 'deflate') as "Accept-Encoding"))

                            This example shows adding two headers "Content-Type" and "Accept-Encoding". Now change your procedure that is calling web service with headers of your choosing, and then execute. As I mentioned above if you go this route, you do not have to provide the CXF configuration file. But side effect is, if you are saying this changes every 20 minutes, then you need to pass in an input parameter to this procedure that defines the auth header value. That means user needs to know what that is.

                             

                            When you go CXF route, you can control the header programmatically. Your CXF configuration, you provided you copied what I provided as example, you need to add

                             

                            xmlns:cxf="http://cxf.apache.org/core"

                             

                            In the header of XML to bring in the cxf namespace into context. see more information about writing interceptors here Apache CXF -- Interceptors

                             

                            Ramesh..

                            • 11. Re: 401 Unauthorized in REST Web Service Source
                              vijayjose

                              This is the content of my procedure,I tried to change as above ,but it always results in error:

                               

                              BEGIN

                                DECLARE STRING VARIABLES.qp = '';

                                SELECT A.response AS response FROM (EXEC SourceModel_1.invokeHttp(action => 'GET', endpoint => VARIABLES.qp, stream => 'TRUE', headers => '{"X-Auth-Token":"token value"}')) AS f, XMLTABLE('/response' PASSING JSONTOXML('response', f.result) COLUMNS response string PATH 'text()') AS A;

                              END

                               

                              added  xmlns:cxf="http://cxf.apache.org/core"

                              getting new error : cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'cxf:bus'."

                              attaching log file.

                              • 12. Re: 401 Unauthorized in REST Web Service Source
                                rareddy

                                Vijay,

                                 

                                I said you need to choose one of the two solutions. Looks like you did not correctly follow the example I gave. The query should be like

                                 

                                BEGIN
                                  DECLARE STRING VARIABLES.qp = '';
                                  SELECT A.response AS response FROM (EXEC SourceModel_1.invokeHttp(action => 'GET', endpoint => VARIABLES.qp, stream => 'TRUE', headers=>jsonObject('token value' as 'X-Auth-Token')) AS f, 
                                         XMLTABLE('/response' PASSING JSONTOXML('response', f.result) COLUMNS response string PATH 'text()') AS A;
                                END
                                

                                 

                                where "toke value" should be your header value. Remove your CXF file configuration for now.

                                 

                                Ramesh..

                                • 13. Re: 401 Unauthorized in REST Web Service Source
                                  vijayjose

                                  Ramesh,

                                   

                                  Found 1  ')'  missing ,added it before " AS f " in procedure ,but still getting the same error.

                                   

                                  ERROR: Error in parsing of sql - Encountered " "exec" "EXEC "" at line 3, column 45.

                                   

                                   

                                  BEGIN

                                    DECLARE STRING VARIABLES.qp = '';

                                    SELECT A.response AS response FROM (EXEC SourceModel.invokeHttp(action => 'GET', endpoint => VARIABLES.qp, stream => 'TRUE', headers => jsonObject('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx' as 'X-Auth-Token'))) AS f, XMLTABLE('/response' PASSING JSONTOXML('response', f.result) COLUMNS response string PATH 'text()') AS A;

                                  END

                                  • 14. Re: 401 Unauthorized in REST Web Service Source
                                    shawkins

                                    The JSONOBJECT needs to use identifiers, not literals for names:

                                     

                                    BEGIN
                                      DECLARE STRING VARIABLES.qp = '';
                                      SELECT A.response AS response FROM (EXEC SourceModel.invokeHttp(action => 'GET', endpoint => VARIABLES.qp, stream => 'TRUE', headers => jsonObject('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx' as "X-Auth-Token"))) AS f, XMLTABLE('/response' PASSING JSONTOXML('response', f.result) COLUMNS response string PATH 'text()') AS A;
                                    END
                                    
                                    1 of 1 people found this helpful
                                    1 2 3 4 Previous Next