简体   繁体   English

在“桌面”中调用适配器不起作用

[英]Calling adapters in “desktop” does not work

Using IBM MobileFirst 7.1 使用IBM MobileFirst 7.1

I have created a very simple hybrid project. 我创建了一个非常简单的混合项目。 Then added a very simple java adapter: 然后添加了一个非常简单的java适配器:

@Path("/hello")
public class BrokenAdapterResource {
    @GET
    @Produces("text/plain")
    public String hello() {
        return "Hope keeps man alive....!";
    }
}

and also created a MobileFirst environment: "Desktop Browser web page". 并且还创建了MobileFirst环境:“桌面浏览器网页”。 I try to call the adapter. 我尝试调用适配器。 When I call it from the "common" it works as expected. 当我从“通用”中调用它时,它可以按预期工作。 However when I call it from "desktop" it does not work: 但是,当我从“桌面”调用它时,它不起作用:

var resourceRequest = new WLResourceRequest(
        "/adapters/BrokenAdapter/hello",
        WLResourceRequest.GET);



resourceRequest.send().then(
        function(result){
            var data = JSON.parse(JSON.stringify(result))
            var message = data['responseText']
            $("#message").text(message) //Set the value in message div tag              
        },
        function(error){
            $("#message").text(JSON.stringify(error))
        }
    );

In "common" I get the expected: Hope keeps man alive....! 在“常见”中,我得到了期望: Hope keeps man alive....! . In the "desktop" I always get {"status":200,"responseHeaders":{},"responseText":"undefined","errorCode":"API_INVOCATION_FAILURE","errorMsg":"Unsupported environment","invocationContext":null} 在“桌面”中,我总是得到{"status":200,"responseHeaders":{},"responseText":"undefined","errorCode":"API_INVOCATION_FAILURE","errorMsg":"Unsupported environment","invocationContext":null}

I wonder what if wrong in this case? 我不知道在这种情况下怎么办? Is this the right way to call resources? 这是调用资源的正确方法吗?

I have created a sample project that shows this thing https://hub.jazz.net/project/ignacio4d/BrokenProject/overview 我创建了一个示例项目来显示此内容https://hub.jazz.net/project/ignacio4d/BrokenProject/overview

Please see the following tutorial: https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/server-side-development-category/invoking-adapter-procedures-hybrid-client-applications/ 请参阅以下教程: https : //developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/server-side-development-category/invoking-adapter-procedures-hybrid-client-applications/

specifically: 特别:

MobileFirst applications can access resources using the WLResourceRequest REST API. MobileFirst应用程序可以使用WLResourceRequest REST API访问资源。 The REST API works with all adapters and external resources, and is supported in the following hybrid environments: iOS, Android, Windows Phone 8, and Windows 8. REST API可与所有适配器和外部资源一起使用,并在以下混合环境中受支持:iOS,Android,Windows Phone 8和Windows 8。

If your application supports other hybrid environments such as BlackBerry, Mobile Web, or Desktop Browser, see the tutorial for IBM MobileFirst Platform Foundation 6.3 . 如果您的应用程序支持其他混合环境,例如BlackBerry,Mobile Web或Desktop Browser, 请参阅IBM MobileFirst Platform Foundation 6.3教程

In other words, Java adapters use WLResourceRequest. 换句话说,Java适配器使用WLResourceRequest。 Java adapters do not support the Desktop Browser environment. Java适配器不支持桌面浏览器环境。 A workaround would be to use JavaScript adapters which support both WL.Client.invokeProceudre and WLResourceRequest , so you can use regular WL.Client.invokeProcedure for the Desktop Browser environment. 一种解决方法是使用同时支持WL.Client.invokeProceudreWLResourceRequest JavaScript适配器,因此您可以对桌面浏览器环境使用常规的WL.Client.invokeProcedure

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM