User avatar
Bjorn_Andersson
GpsGate
Posts: 463
Joined: Wed Jun 28, 2006 5:20 pm
Location: Sweden
Contact: Website

GUIDE: Web Service Scripting

Wed Sep 10, 2014 11:59 am

Guide: Web Service Script

By using this feature you can create you own web service interface into GpsGate Server.
This is useful when having a thrird party system that needs to consume data from GpsGate Server in a custom format.

For more information see:
http://gpsgate.com/blogComment/web_service_scripts

Regards,
GpsGate Support
Bjorn Andersson

piter197
Posts: 832
Joined: Sun Jan 09, 2011 3:32 am

RE: GUIDE: Web Service Scripting

Sat Jan 10, 2015 7:58 am

Hi,

I have successfully follow the example from the blog, I have 3 questions:

1. How to get vehicle speed and time UTC data?
I use

Code: Select all

  var speed = user.trackPoint.speed;
  var utc = user.trackPoint.utc;

  response.body =
    '<response>' +
      '<speed>' + speed + '</speed>' +
      '<utc>' + utc + '</utc>' +
    '</reponse>';
But I always get Response body: <response><speed>undefined</speed><utc>undefined</utc></reponse>


2. How to get Address of the vehicle?

3. How to test this using Poster in Firefox?
I have set URL the same as URL field in Web Service Script window, and use request format exactly the same as in Object browser request body. But I always get result

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>404 - File or directory not found.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;}
h1{font-size:2.4em;margin:0;color:#FFF;}
h2{font-size:1.7em;margin:0;color:#CC0000;}
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;}
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
background-color:#555555;}
#content{margin:0 0 0 2%;position:relative;}
.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}
-->
</style>
</head>
<body>
<div id="header">Server Error</div>
<div id="content">
<div class="content-container"><fieldset>
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.
</fieldset></div>
</div>
</body>
</html>



Best Regards,
piter197

User avatar
Gabor
GpsGate
Posts: 86
Joined: Thu May 16, 2013 3:43 pm

RE: GUIDE: Web Service Scripting

Mon Jan 12, 2015 5:07 pm

Hi piter197,

1)
I could reproduce the issue when the user object was null.
You can use the following line to test that: log(user==null); // it writes to the test output panel of the script editor.
This can also help you to check the properties: log(JSON.stringify(user));

2)
The reverse geocoding function is available in version 4.0.0.2190 and newer.
Go to SiteAdmin - > Plugins
Change repository url to beta.gpsgate.com.
Update Patch.v4 if it is necessary.

Example:

Code: Select all

...
try {
    var latitude = 59.34213;
    var longitude = 18.05538;
    var location = geo.reverseGeocode(latitude, longitude);
    if(location != null) {
        response.body = "<result><address>" + location.address + "</address></result>";
    }
    else {
          response.body = "<result><address>No address found</address></result>";
    }
}
catch(error) {
    response.body = "<result><error>" + error + "</error></result>";
}
3)
Please go to SiterAdmin -> Service -> Providers and check whether you have the WebServiceScriptProvider started.


Regards,
Gabor
GpsGate Support

piter197
Posts: 832
Joined: Sun Jan 09, 2011 3:32 am

RE: GUIDE: Web Service Scripting

Mon Jan 12, 2015 7:49 pm

Hi Gabor,

Thank you for your explanation.

1)
log(JSON.stringify(user)) really help to check correct properties of user. The speed and utc should be:

var speed = user.trackPoint.velocity.groundSpeed;
var utc = user.trackPoint.utcTimestamp;


2)
Thank you for providing reverse geocoding function, it works.

3)
Still no luck when using Poster. Stil getting the same error message.
I have check SiteAdmin -> Service -> Provider and WebServiceScriptProvider already in Start condition. But for Url, Username, CallInterval, CustomLong, CustomString, CallTimeout, RouteLabel and DefaultProvider all value empty or 0. Do I have to fill Url and Username (and password) for the provider here ?

I set URL in Poster the same as in Web service script URL, with this: http://www.myweb.com/webservicescript/26/test

then in the content to send part, same as request body in Script editor:
<request>
<login>
<user>user1</user>
<pass>myuser1password</pass>
</login>
<vehicleid>121</vehicleid>
</request>



4)
When I open Script editor using Firefox 34.0 under OS X 10.10, the right part of Script Editor Window (exposed objects and test values) display blank. This is not happening for Chrome or Safari under OS X.

Best Regards,
piter197

User avatar
Gabor
GpsGate
Posts: 86
Joined: Thu May 16, 2013 3:43 pm

RE: GUIDE: Web Service Scripting

Tue Jan 13, 2015 11:55 am

Hi piter197,

3)
It seems the listener of the WebServiceScript could not bind to server address for some reason. Please go to SiteAdmin -> Service -> Providers. Stop and Start the WebServiceScriptProvider.
Send us the error log to support(at)gpsgate(dot)com email address, if you have new errors in the NMEA log file (C:\GpsGateServer\ErrorLog) from the time when you restarted the provider. Also send us what windows version you are using.

4)
Thank you for reporting this. Unfortunately I could not reproduce the issue, I keep testing. I have tried the same Firefox version, although I use Windows.
Does it fix itself if you resize the script editor window or the panel inside the window?


Regards,
Gabor
GpsGate Support

piter197
Posts: 832
Joined: Sun Jan 09, 2011 3:32 am

RE: GUIDE: Web Service Scripting

Tue Jan 13, 2015 1:05 pm

Hi Gabor,

3)
I have check IIS and NMEA error log file for time near stop-start WebServiceScriptProvider but can not find any new error regarding this. I'm using Windows 2008 R2 Standard with SP1.

4)
Yes when I resize (click and drag) the panel inside the window, it fix itself, but when I have done resize (unclick) then the right panel become blank again.




Best Regards,
piter197

User avatar
Gabor
GpsGate
Posts: 86
Joined: Thu May 16, 2013 3:43 pm

RE: GUIDE: Web Service Scripting

Tue Jan 13, 2015 2:04 pm

Hi piter197,

3)
Please try to run this command on the server:
netsh http add urlacl url=http://+:80/webservicescript user=\Everyone
I expect this to allow WebServiceScript listener to use that prefix.


Regards,
Gabor
GpsGate Support

piter197
Posts: 832
Joined: Sun Jan 09, 2011 3:32 am

RE: GUIDE: Web Service Scripting

Tue Jan 13, 2015 2:36 pm

Hi Gabor,

After run this on server:
netsh http add urlacl url=http://+:80/webservicescript user=\Everyone

I got response from command prompt: URL reservation successfully added


Then I try to post:
<request>
<login>
<user>user1</user>
<pass>myuser1password</pass>
</login>
<vehicleid>121</vehicleid>
</request>


But got this response:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Service Unavailable</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY>Service Unavailable
<p>HTTP Error 503. The service is unavailable.</p>
</BODY></HTML>

I have try to stop-start again the Web Service Script provider, still no luck.



Best Regards,
piter197

User avatar
Gabor
GpsGate
Posts: 86
Joined: Thu May 16, 2013 3:43 pm

RE: GUIDE: Web Service Scripting

Tue Jan 13, 2015 6:49 pm

Hi piter197,

There is a new Patch.V4 version (4.0.0.2199) available with a fix in the beta.gpsgate.com repository. Does it solve your issue about accessing the script service?

If it works, you can try to revert the changes of the manual configuration attempt:
netsh http delete urlacl url=http://+:80/webservicescript



Regards,
Gabor
GpsGate Support

piter197
Posts: 832
Joined: Sun Jan 09, 2011 3:32 am

RE: GUIDE: Web Service Scripting

Wed Jan 14, 2015 12:02 am

Hi Gabor,

Thank you. New Patch.v4 fix my problem [:)]

Best Regards,
piter197

piter197
Posts: 832
Joined: Sun Jan 09, 2011 3:32 am

RE: GUIDE: Web Service Scripting

Wed Jan 14, 2015 1:47 am

Hi Support,

I have suggestion, because script limited to max of 1500 characters, please provide Description field so we can put more documentation there regarding the script.

Thank you.

Best Regards,
piter197

User avatar
Gabor
GpsGate
Posts: 86
Joined: Thu May 16, 2013 3:43 pm

RE: GUIDE: Web Service Scripting

Wed Jan 14, 2015 10:53 am

Hi piter197,

Please contact support @ gpsgate.com regarding the character limit and
we will guide you how to increase it.


Regards,
Gabor
GpsGate Support

piter197
Posts: 832
Joined: Sun Jan 09, 2011 3:32 am

RE: GUIDE: Web Service Scripting

Sat Jan 17, 2015 2:02 pm

Hi Support,


Please consider for API directory.getUsers() the return value can be selected not only All users but also return only Vehicles (or Operators or Administrators).

Thank you.


Best Regards,
piter197

User avatar
Gabor
GpsGate
Posts: 86
Joined: Thu May 16, 2013 3:43 pm

RE: GUIDE: Web Service Scripting

Mon Jan 19, 2015 11:00 am

Hi piter197,

Thank you for your feedback. We will consider this for the next update of WebServiceScript.


Regards,
Gabor
GpsGate Support

piter197
Posts: 832
Joined: Sun Jan 09, 2011 3:32 am

RE: GUIDE: Web Service Scripting

Sat Jan 24, 2015 12:01 pm

Hi Support,

Please consider to provide customFields.setValues.

Thank you.

Best Regards,
piter197

Return to “GpsGate for Developers”