我正在使用 IBM MobileFirst Platform 7 中的 HTTP (SOAP) 适配器。在控制台中一切正常,但是当我尝试在真实设备中运行该应用程序时,它失败了,并且没有调用 Web 服务。
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 适配器应该遵循哪些步骤?
这是我的代码:
索引.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
函数温度转换器(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;
};