访问Web服务时HTTP适配器无法正常工作

时间:2015-08-05 09:43:21

标签: ibm-mobilefirst mobilefirst-adapters

在工作室中调用适配器时,它正在工作

{
   "isSuccessful": true,
   "responseHeaders": {
      "Accept-Ranges": "none",
      "Access-Control-Allow-Origin": "*",
      "Alternate-Protocol": "80:quic,p=0",
      "Cache-Control": "public, max-age=86400",
      "Content-Type": "application\/json; charset=UTF-8",
      "Date": "Wed, 05 Aug 2015 09:17:20 GMT",
      "Expires": "Thu, 06 Aug 2015 09:17:20 GMT",
      "Server": "mafe",
      "Transfer-Encoding": "chunked",
      "Vary": "Accept-Language,Accept-Encoding",
      "X-Frame-Options": "SAMEORIGIN",
      "X-XSS-Protection": "1; mode=block"
   },
   "responseTime": 174,
   "results": [
      {
         "address_components": [
            {
               "long_name": "4250",
               "short_name": "4250",
               "types": [
                  "street_number"
               ]
            },
            {
               "long_name": "South Miami Boulevard",
               "short_name": "S Miami Blvd",
               "types": [
                  "route"
               ]
            },
            {
               "long_name": "Durham",
               "short_name": "Durham",
               "types": [
                  "locality",
                  "political"
               ]
            },
            {
               "long_name": "Triangle",
               "short_name": "Triangle",
               "types": [
                  "administrative_area_level_3",
                  "political"
               ]
            },
            {
               "long_name": "Durham County",
               "short_name": "Durham County",
               "types": [
                  "administrative_area_level_2",
                  "political"
               ]
            },
            {
               "long_name": "North Carolina",
               "short_name": "NC",
               "types": [
                  "administrative_area_level_1",
                  "political"
               ]
            },
            {
               "long_name": "United States",
               "short_name": "US",
               "types": [
                  "country",
                  "political"
               ]
            },
            {
               "long_name": "27703",
               "short_name": "27703",
               "types": [
                  "postal_code"
               ]
            },
            {
               "long_name": "9138",
               "short_name": "9138",
               "types": [
                  "postal_code_suffix"
               ]
            }
         ],
         "formatted_address": "4250 South Miami Boulevard, Durham, NC 27703, USA",
         "geometry": {
            "bounds": {
               "northeast": {
                  "lat": 35.9026873,
                  "lng": -78.8516022
               },
               "southwest": {
                  "lat": 35.9026836,
                  "lng": -78.85162009999999
               }
            },
            "location": {
               "lat": 35.9026836,
               "lng": -78.85162009999999
            },
            "location_type": "RANGE_INTERPOLATED",
            "viewport": {
               "northeast": {
                  "lat": 35.9040344302915,
                  "lng": -78.8502621697085
               },
               "southwest": {
                  "lat": 35.9013364697085,
                  "lng": -78.8529601302915
               }
            }
         },
         "place_id": "EjE0MjUwIFNvdXRoIE1pYW1pIEJvdWxldmFyZCwgRHVyaGFtLCBOQyAyNzcwMywgVVNB",
         "types": [
            "street_address"
         ]
      }
   ],
   "status": "OK",
   "statusCode": 200,
   "statusReason": "OK",
   "totalTime": 181
}

但是,当从设备中的应用程序调用时,它无法正常工作。

这是适配器 .js文件:

function getLatLang(pAddress){
var input = {
            method : 'get',
            returnedContentType : 'json',
            path : 'maps/api/geocode/json',
            parameters : {
                'address' : pAddress,
                'sensor' : 'false' 
            }
        };

        return WL.Server.invokeHttp(input);

}

这是适配器 .xml文件:

<connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>http</protocol>
            <domain>maps.googleapis.com</domain>
            <port>80</port> 
            <connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
            <socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
            <maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
            <!-- Following properties used by adapter's key manager for choosing specific certificate from key store  
            <sslCertificateAlias></sslCertificateAlias> 
            <sslCertificatePassword></sslCertificatePassword>
            -->     
        </connectionPolicy>
    </connectivity>

这是main.js文件:

function getLatLang(){
                        //alert("Hi");
                        var gmap = document.getElementById("gmap").value;
                        var invocationData = {
                            adapter : "Go2needsHTTP",
                            procedure : "getLatLang",
                            parameters : [gmap]
                        };
                        //alert("Hi");
                        var options = 
                        {
                            onSuccess : procedureSuccess,
                            onFailure : procedureFailure,
                        };
                        WL.Client.invokeProcedure(invocationData, options);
                    }

1 个答案:

答案 0 :(得分:0)

你没有提供你的HTML,也没有提供你如何调用这个函数(而不是函数本身),所以如果你说在运行应用程序本身时没有任何反应,这意味着你并没有实际调用你的JavaScript,意味着你在某个地方有错误 - 可能是一个错字。

W / out更全面的代码,没有别的可说的了。