在Android设备中调用SOAP适配器失败

时间:2015-05-05 12:10:32

标签: android ibm-mobilefirst mobilefirst-adapters

我正在使用IBM MobileFirst Platform 7中的HTTP(SOAP)适配器。在控制台中一切正常,但是当我尝试在真实设备中运行应用程序时,它失败并且不会调用Web服务。< / p>

Logcat显示以下内容:

05-05 17:33:11.012: W/PluginManager(13237): THREAD WARNING: exec() call to WLAuthorizationManagerPlugin.getClientInstanceIdHeader blocked the main thread for 173ms. Plugin should use CordovaInterface.getThreadPool().
05-05 17:33:11.032: D/wl.request(13237): WLRequestSender.run in WLRequestSender.java:40 :: Sending request http://192.168.1.43:10080/Adapters/authorization/v1/clients/instance
05-05 17:33:11.072: D/dalvikvm(13237): GC_CONCURRENT freed 4707K, 24% free 19499K/25604K, paused 4ms+3ms, total 60ms
05-05 17:33:21.092: D/wl.certManager(13237): WLCertManager.clearKeystore in WLCertManager.java:258 :: Key store cleared.
05-05 17:33:21.122: D/NONE(13237): Client registration failed with error: {"status":500,"responseHeaders":{},"responseText":"","invocationContext":null}
05-05 17:33:21.132: E/NONE(13237): [/apps/services/api/CallingAdapters/android/query] failure. state: 500, response: undefined

在真实设备上使用HTTP适配器应遵循哪些步骤?

这是我的代码:

的index.htm

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>CallingAdapters</title>
<meta name="viewport"
    content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="css/main.css">
<script>
    window.$ = window.jQuery = WLJQ;
</script>
<script>
    function mSuccess(result) {

                var httpStatusCode = result.status;
                if (200 == httpStatusCode) {
                    var invocationResult = result.invocationResult;
                    var isSuccessful = invocationResult.isSuccessful;
                    if (invocationResult.isSuccessful) {
                        var CelsiusToFahrenheitResponse = invocationResult.CelsiusToFahrenheitResponse;
                        var res = CelsiusToFahrenheitResponse.CelsiusToFahrenheitResult;
                        alert("Success::::" + res);
                    } else {
                        alert("Error. isSuccessful=" + isSuccessful);
                    }
                }


    }
</script>
<script>
    function mFailure(result) {
        alert("Failure");
    }
</script>
<script>
    function callFunc() {
        var value = $('#input1').val()
                var invocationData = {
                    adapter : 'SOAPAdapter',
                    procedure : 'temperatureConvertor',
                    parameters : [ value ]
                };

        WL.Client.invokeProcedure(invocationData, {
            onSuccess : mSuccess,
            onFailure : mFailure,
        });
    }
</script>
</head>
<body style="display: none;">
    <!--application UI goes here-->
    Hello MobileFirst By Sravana Lakshmi

    <div>
        <input id="input1" type="number" />
    </div>
    <input type="submit" name="submit" onclick="callFunc()" />
    <script src="js/initOptions.js"></script>
    <script src="js/main.js"></script>
    <script src="js/messages.js"></script>

</body>
</html>

SOADAdapter.xml

<wl:adapter name="SOAPAdapter"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:wl="http://www.ibm.com/mfp/integration"
    xmlns:http="http://www.ibm.com/mfp/integration/http">

    <displayName>SOAPAdapter</displayName>
    <description>SOAPAdapter</description>
    <connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>http</protocol>
            <domain>www.w3schools.com</domain>
            <port>80</port>         
            <connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
            <socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
            <maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>   
        </connectionPolicy>
    </connectivity>

    <procedure name="temperatureConvertor"/>
</wl:adapter>

SOAPAdapter-impl.js

function temperatureConvertor(celsiusTemp){

var request = 
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Body>
            <CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/">
                <Celsius>{celsiusTemp}</Celsius>
            </CelsiusToFahrenheit>
        </soap:Body>
    </soap:Envelope>;

    var input = {
        method: 'post',
        returnedContentType: 'xml',
        path: '/webservices/tempconvert.asmx',
        body: {
            content: request.toString(),
            contentType: 'text/xml; charset=utf-8',
        },
    };

    var result = WL.Server.invokeHttp(input);

    return result.Envelope.Body;
};

1 个答案:

答案 0 :(得分:0)

您引用的答案假设您知道设备可以访问的服务器的ipaddress。

这里的关键点是您的设备与开发环境所看到的网络连接不同。设备上运行的代码必须能够看到服务器,即适配器运行的位置。

试试这个:

在桌面浏览器中加载MFP控制台。您使用的是什么网址?

该网址是否适用于您设备上的浏览器?

例如,如果是:

 http://localhost:10080/xyz/console

  http://127.0.0.1:10080/xyz/console

然后很明显,无法在您的设备上运行。但鉴于您的设备可能位于一些完全不同的网络上,那么您的台式机可能对设备不可见。例如:

  http://192.168.0.19:10080/xyz/console

可能无法访问。在极端情况下,甚至可能无法进入服务器。例如,一些公司有一个政策,即移动设备可能没有连接到公司网络,而是只能连接到“访客”网络,故意不提供对开发网络的访问。在这种情况下,我们可能需要设置特殊网络进行测试。例如,有时我会设置我自己的开发机器和我的设备可以使用的隔离WiFi网络。