Worklight http adapter questions

后端 未结 5 2060
南方客
南方客 2021-01-14 16:23

2 simple questions :

  1. Do all http requests make thru http adapter do go thru the worklight server first?

  2. If so then does it mean even a http

相关标签:
5条回答
  • 2021-01-14 17:12

    Do all http requests make thru http adapter do go thru the worklight server first?

    Absolutely not, it is entirely up to you. If you are using HTTP Adapters, then the HTTP request would be initiated from the Worklight Server and it would serve you back the response.

    If so then does it mean even a http adapter request to a public web site say a request to yahoo site for a stock price would also go thru worklight server first then next to the yahoo web site? If so then how do I make a http request without going thru the worklight server? I just want to go straight to yahoo web site without the "intermediate" server (i.e. workligth server)

    If you are using a HTTP Adapter, then it would go through Worklight Server as per the first answer.

    If you do not want the intermediate server, then you can use the conventional means of doing the HTTP request as you would do otherwise either through the Javascript /Ajax layer or natively (Android/iOS/Windows..)

    Adapters are useful when it comes to security which Worklight uses to make sure that the request is initiated from the registered device - the authentication is done by exchanging device tokens etc.

    0 讨论(0)
  • 2021-01-14 17:19

    Of course You can access it directly without calling any adapter functions using simple jquery ajax calls.

    $.ajax({
           url: url,
           data: data,
           success: success,
           dataType: dataType
    });
    

    or

    $.get(url, function() {
        alert( "success" );
    })
    .done(function() {
        alert( "second success" );
    })
    .fail(function() {
        alert( "error" );
    })
    .always(function() {
       alert( "finished" );
    });
    
    0 讨论(0)
  • 2021-01-14 17:20

    1) Do all http requests make thru http adapter do go thru the worklight server first?

    Yes. Worklight Adapters work by executing JavaScript on the Worklight Server using Mozilla Rhino. You can read more about Adapters in the IBM Worklight Getting Started Modules. Look at Modules 5 and 6 for Adapter specific details. There are also code samples you can try next. The API documentation is in IBM InfoCenter. There is also a Developer Works article that talks about adapters that you may find helpful.

    2) If so then does it mean even a http adapter request to a public web site say a request to yahoo site for a stock price would also go thru worklight server first then next to the yahoo web site?

    Yes.

    I just want to go straight to yahoo web site without the "intermediate" server (i.e. workligth server)

    IBM Worklight ships with jQuery, you can use the ajax method. Here's an example:

    WLJQ.ajax( "http://finance.yahoo.com/d/quotes.csv?s=DOW+MSFT+AAPL+GOOG&f=snl1" )
    .done(function (data) {
        console.log(data);
    });
    

    Note that WLJQ is the namespace for the version of jQuery that Worklight ships. You can use jQuery or $ by doing: var $ = WLJQ; or var jQuery = WLJQ;.

    You should get something like this back:

    "DOW","Dow Chemical Comp",30.89
    "MSFT","Microsoft Corpora",27.37
    "AAPL","Apple Inc.",448.97
    "GOOG","Google Inc.",790.13
    
    0 讨论(0)
  • 2021-01-14 17:21

    If you use the adapter API on the client side then your request with go through the Worklight server. You can still make AJAX requests from the client side and skip the server. Essentially you'd be making server requests in the same way you would in Cordova, which means using a whitelist to allow your requests to access third party servers.

    0 讨论(0)
  • 2021-01-14 17:24

    I think you are missing an important point about the adapter architecture in WL. The adapter lives in the server, so by definition, any request you make with it will "go thru" the server. However, the information is not going through your WAS (or Tomcat) server.

    Is there a reason you don't want to use the adapter? I would recommend using it since it makes it easier to pull down data, whether from a RESTful http call or database query.

    If you did want to get around the adapter, there are issues with cross-domain authorization. I don't have much experience in this area, but you may be able to get around it using something like jQuery.ajax().

    0 讨论(0)
提交回复
热议问题