使用AJAX调用worklight SQL适配器过程

时间:2021-09-24 00:07:40

Can someone give an example of how to invoke and receive a response from an SQL adapter in worklight using AJAX call? I'm using worklight 6.0

有人能举例说明如何使用AJAX调用来调用和接收来自worklight中的SQL适配器的响应吗?我使用worklight 6.0

I have security at the app level. I need to invoke a procedure that doesn't need authentication (example: Registering an account) and hence need to invoke the adapter using AJAX

我有应用级的安全性。我需要调用一个不需要身份验证(例如:注册一个帐户)的过程,因此需要使用AJAX调用适配器

This is my adapter:

这是我的适配器:

var invocationData = {
                    adapter : 'UserInfo',
                    procedure : 'addUserInfo',
                    parameters : [ customerData.firstName,
                            customerData.lastName, customerData.email,
                            customerData.province, customerData.zipPostal,
                            customerData.phoneNumber, customerData.streetName,
                            customerData.streetNumber, customerData.country,
                            customerData.city ]
                };
                WL.Client.invokeProcedure(invocationData, {
                    onSuccess : insertUserSuccess,
                    onFailure : insertUserFailure
                });

2 个解决方案

#1


2  

My understanding is that you just want to invoke an Adapter procedure using Ajax from some client.

我的理解是,您只需要从某个客户端调用使用Ajax的适配器过程。

Is it the same as this other question ?

这和另一个问题一样吗?

Calling Worklight adapter from external app

从外部应用程序调用工作灯适配器

You can check the details of the HTTP API here

您可以在这里查看HTTP API的详细信息

http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.0.0/com.ibm.worklight.help.doc/admin/r_http_interface_of_the_prod_server.html?lang=en

http://www - 01. ibm.com/support/knowledgecenter/sszh4a_6.0.0/com.ibm.worklight.help.doc/admin/r_http_interface_of_the_prod_server.html?lang=en

Update: Also note that if you have any security tests configured, different than "wl_unprotected" (your adapter is 100% public with that, be careful!!) you may need extra steps to handle authentication.

更新:还要注意,如果您配置了任何与“wl_protected”不同的安全性测试(您的适配器是100%公开的,请小心!!),您可能需要额外的步骤来处理身份验证。

If you have a default adapter, without any security test set, you may receive a 401 unauthorized in your first request, and in the body of the 401 you may find a WL-Instance-ID property, that you must send together with a new request to get authorized to use it.

如果你有一个默认的适配器,没有任何安全测试集,你可能会在第一个请求中收到一个未授权的401,而在401的主体中你可能会发现一个wl实例id属性,你必须连同一个新的请求一起发送来获得授权使用它。

Update 2: Worklight/MobileFirst Platform doesn't enable CORS (so you can't "naturally" call adapters using ajax from an external web page). It may be possible to workaround that by using a gateway (IHS maybe) that adds the header "Access-Control-Allow-Origin" to all adapter responses. Note that you are handling a security thing, so make sure you know what you are doing.

更新2:Worklight/MobileFirst平台不支持CORS(因此您不能“自然地”从外部web页面使用ajax调用适配器)。可以通过使用网关(可能是IHS)来解决这个问题,该网关将头“访问控制允许的来源”添加到所有适配器响应中。注意,您正在处理安全事务,所以请确保您知道自己在做什么。

#2


1  

Worklight (6.3 and below) adapters can work only with the Worklight Server. If you plan on using Worklight adapters, you are required to use the API as provided by the Worklight framework - the code mentioned in the question.

Worklight(6.3及以下)适配器只能与Worklight服务器一起工作。如果您计划使用Worklight适配器,则需要使用Worklight框架提供的API——问题中提到的代码。

You can still use regular AJAX requests - but those won't/cannot be requests sent to/by the Worklight adapter.

您仍然可以使用常规的AJAX请求——但是这些请求不会/不能通过Worklight适配器发送到/。

WLJQ.ajax( "some-URL" )
.done(function (data) {
    console.log(data);
});

If the destination does require going through the Worklight Server, and it is not protected by any realm, what is the problem then? Send the request.

如果目标确实需要通过Worklight服务器,并且它不受任何领域的保护,那么问题是什么?发送请求。

Perhaps you should not protect the app at the environment level but rather at the procedure level (set the security test on the adapter procedure in the adapter XML and not on the environment in application-descriptor.xml).

也许您不应该在环境级别上保护应用程序,而应该在过程级别(在适配器XML中对适配器过程设置安全性测试,而不是在应用程序描述符. XML中的环境中)。

Perhaps you need to better explain your specific scenario...

也许你需要更好地解释你的具体情况……

#1


2  

My understanding is that you just want to invoke an Adapter procedure using Ajax from some client.

我的理解是,您只需要从某个客户端调用使用Ajax的适配器过程。

Is it the same as this other question ?

这和另一个问题一样吗?

Calling Worklight adapter from external app

从外部应用程序调用工作灯适配器

You can check the details of the HTTP API here

您可以在这里查看HTTP API的详细信息

http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.0.0/com.ibm.worklight.help.doc/admin/r_http_interface_of_the_prod_server.html?lang=en

http://www - 01. ibm.com/support/knowledgecenter/sszh4a_6.0.0/com.ibm.worklight.help.doc/admin/r_http_interface_of_the_prod_server.html?lang=en

Update: Also note that if you have any security tests configured, different than "wl_unprotected" (your adapter is 100% public with that, be careful!!) you may need extra steps to handle authentication.

更新:还要注意,如果您配置了任何与“wl_protected”不同的安全性测试(您的适配器是100%公开的,请小心!!),您可能需要额外的步骤来处理身份验证。

If you have a default adapter, without any security test set, you may receive a 401 unauthorized in your first request, and in the body of the 401 you may find a WL-Instance-ID property, that you must send together with a new request to get authorized to use it.

如果你有一个默认的适配器,没有任何安全测试集,你可能会在第一个请求中收到一个未授权的401,而在401的主体中你可能会发现一个wl实例id属性,你必须连同一个新的请求一起发送来获得授权使用它。

Update 2: Worklight/MobileFirst Platform doesn't enable CORS (so you can't "naturally" call adapters using ajax from an external web page). It may be possible to workaround that by using a gateway (IHS maybe) that adds the header "Access-Control-Allow-Origin" to all adapter responses. Note that you are handling a security thing, so make sure you know what you are doing.

更新2:Worklight/MobileFirst平台不支持CORS(因此您不能“自然地”从外部web页面使用ajax调用适配器)。可以通过使用网关(可能是IHS)来解决这个问题,该网关将头“访问控制允许的来源”添加到所有适配器响应中。注意,您正在处理安全事务,所以请确保您知道自己在做什么。

#2


1  

Worklight (6.3 and below) adapters can work only with the Worklight Server. If you plan on using Worklight adapters, you are required to use the API as provided by the Worklight framework - the code mentioned in the question.

Worklight(6.3及以下)适配器只能与Worklight服务器一起工作。如果您计划使用Worklight适配器,则需要使用Worklight框架提供的API——问题中提到的代码。

You can still use regular AJAX requests - but those won't/cannot be requests sent to/by the Worklight adapter.

您仍然可以使用常规的AJAX请求——但是这些请求不会/不能通过Worklight适配器发送到/。

WLJQ.ajax( "some-URL" )
.done(function (data) {
    console.log(data);
});

If the destination does require going through the Worklight Server, and it is not protected by any realm, what is the problem then? Send the request.

如果目标确实需要通过Worklight服务器,并且它不受任何领域的保护,那么问题是什么?发送请求。

Perhaps you should not protect the app at the environment level but rather at the procedure level (set the security test on the adapter procedure in the adapter XML and not on the environment in application-descriptor.xml).

也许您不应该在环境级别上保护应用程序,而应该在过程级别(在适配器XML中对适配器过程设置安全性测试,而不是在应用程序描述符. XML中的环境中)。

Perhaps you need to better explain your specific scenario...

也许你需要更好地解释你的具体情况……