Headless client for WebSockets

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Headless client for WebSockets

Postby bobcart » Wed Oct 04, 2017 12:57 pm

I first tried posting this question in the headless client section, but I'm guessing this might be better. I wish to implement a server side capability to access webservices from a number of sites that deliver data via both RESTful APIs and Websockets. I've found the ability to use RESTful services to be functional and useful and found the "Consuming web services in Servoy" video by Sean Devlin to be helpful. However, I also want to do the same thing with Websockets.
My understanding is the NG client is made possible with Websockets so the server must implement that functionality. Does that mean that the headless client would already support the ability to be a client to consume websockets APIs from webservices? If not, please explain why not and suggested workarounds.

My attraction to Servoy over the years has been largely because I can get a lot done on my own for certain projects without a big development team. With the NG client, the web browser becomes a practical user client. However, to really make a web product hum these days, it is all about integrations and APIs. Websockets are key to that. I wouyld love to do this in Servoy if I can with reasonably low pain. One thing against is that most of the APIs out there provide libraries for C#, Node.js, Go, Ruby, Python, PHP, etc. I can study these and see how they work, but I need to know how to get started consuming webservices via websockets in Servoy.

I would really appreciate any advice you can offer. Should I just skip Servoy for use with Websockets for now? Thanks in advance!
bobcart
 
Posts: 214
Joined: Fri Nov 21, 2003 8:01 pm
Location: Melbourne (AUS)

Re: Headless client for WebSockets

Postby pbakker » Wed Oct 04, 2017 1:29 pm

The Servoy NGClient just relies on the features of Java and the underlying Application Server on which you deploy your NGClient solution for dealing with WebSockets.

Teh Fact that the NGClient is based on Sablo which utilizes Websockets ain't going to help you one bit for communicating to 3rd party WebSocket-based API's from within your solution.

If you want to do such a thing, you can either:
- Use inline Java inside your solutions and use Java's support for connecting to Websockets
- Do the same as the above, but wrap it in a Servoy plugin
- connect to the Websockets in the browser and create a NGClient Service to send stuff back and forth to the serverside part of your solution

Paul
pbakker
 
Posts: 2821
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Headless client for WebSockets

Postby bobcart » Wed Oct 04, 2017 3:56 pm

Thank you, Paul. But damn. I hate to hear it. I really wanted to use Servoy. I was hoping that the Websockets work already implemented hinted at a path towards broader and more generalised support for websockets.

I don't have the time or skill to write a generalized Java framework for handling websockets APIs. I don't relish the thought of building and maintaining java libraries for a dozen websockets webservices. The strict typing in java while parsing JSON strings would get ugly. I see a year of my life disappearing. In the third option, no comment on the challenge to achieve good performance and reliability of a scripted web browser.

By way of interest, I took a look at a few of the webservices I need to implement looking for patterns. In one case their REST API is now deprecated and in another only a subset of data is available via REST. In each case, they provide libraries in several languages, but surprisingly, no mention of java.

Websockets libraries from four of the webservices I need:
- Node.js, Go, Ruby. C#, C++, Python
- Python, Node.js, PHP
- C, C#, C++, GO, Node.JS, PERL, Python, Ruby, PHP
- Go, Ruby, Node.js, Python

Only Node.js and Python are always there with Go, Ruby and PHP in 3 out of 4 of them. I like Python, but know little of Node.js. It seems to be a rising star.

Not happy...
bobcart
 
Posts: 214
Joined: Fri Nov 21, 2003 8:01 pm
Location: Melbourne (AUS)

Re: Headless client for WebSockets

Postby pbakker » Wed Oct 04, 2017 9:35 pm

Maybe if you shared which Web Services you like to connect to, you might get other people interested in exposing an api in Servoy to connect to Web Sockets
pbakker
 
Posts: 2821
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Headless client for WebSockets

Postby david » Thu Oct 05, 2017 7:59 pm

I don't have the code on my current machine but hooking into Sablo as you suspect is not a big deal. I use it for rolling my own SPA (non-angular) front-ends. Ping me back channel if you'd like more info. - David
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1726
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Headless client for WebSockets

Postby rgansevles » Fri Oct 06, 2017 9:39 am

Hooking into Sablo won't help here, Sablo is a library for sharing state between a webserver and a browser which happens to use websockets for that.
You can't use it to connect to any service.

Creating a Servoy plugin to connect as a client to a websockets server should not be too difficult, there are java websocket client libabries available that just need to be wrapped as servoy plugin.

Websockets are no more then a bi-directional channel for bytes.
Once you have that running you will also need to interpret the messages and send messages in their expected format.
This is where is becomes specific and may be complex, depending on the API the server provides.

Which service do you want to connect to?

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1861
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Headless client for WebSockets

Postby bobcart » Fri Oct 06, 2017 11:26 am

Exactly. The fact Sabel uses websockets means the server supports websockets to at least that extent. I was hoping to exploit that and turn it around so it acted as the client for a websockets web service. I wasn’t suggesting Sablo would help directly.

The specific opportunity I am addressing requires high frequency access to multiple websockets webservices. Some of these APIs haven’t even been completed yet so no need to elaborate. It’s not one or two, but many. I need a generalizable framework to manage them.

With my REST testing, I created a form and method for each of several APIs and a generalized global method that exchanges JSON strings and also implemented oauth. The real work is then stringifying and parsing JSON strings as needed. Problem with REST is that servoy has to poll the APIs but it doesn’t know when there is new or changed data to get. Sadly, most of the APIs allow fewer connections per time period than I need so I can’t just query them constantly. Websockets provides a solution to push the changes, but I need Servoy to listen. Ideally, I’d just need to handle things as I did for REST.

I’m guessing that I would need a few websockets functions or methods to call from a form method that could be triggered any way I need. For each, I’d have the endpoint, API key and secret for general connections then a method to handle the set of JSON exchanges needed. I’d trigger an alert on any change to an API docs or version number to maintain each API method.

How could this be handled in Servoy? A Java plug-in using existing java websockets classes could be workable, but I’m guessing that is a task that is bigger than it needs to be if I can get out of the box functionality via node.js. Perhaps a node.js framework triggered from a database used by Servoy could be a solution? I’m just looking for direction now. How would a servoy developer handle such a problem?
bobcart
 
Posts: 214
Joined: Fri Nov 21, 2003 8:01 pm
Location: Melbourne (AUS)

Re: Headless client for WebSockets

Postby pbakker » Fri Oct 06, 2017 1:12 pm

"Perhaps a node.js framework triggered from a database used by Servoy could be a solution?" sounds a lot more complex and work (also think about deployment) than what I suggested earlier:
- Use inline Java inside your solutions and use Java's support for connecting to Websockets
- Do the same as the above, but wrap it in a Servoy plugin
pbakker
 
Posts: 2821
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Headless client for WebSockets

Postby bobcart » Sat Oct 07, 2017 3:30 pm

Thank you, Paul. I took a look at the java websocket support and how to make a plugin. It does look pretty accessible. Famous last words. I am now wondering how to handle authentication/oauth and of course how to design something that is generalized, bulletproof and truly functional. I'll keep poking around.
bobcart
 
Posts: 214
Joined: Fri Nov 21, 2003 8:01 pm
Location: Melbourne (AUS)


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 4 guests