3

I have a client and a server both written in Java and sharing Java classes that should be sent between each other. I'm not sure which libraries I can use for this on mobile because I don't know what Dalvik supports, what RoboVM supports etc. Not sure what Gluon Mobile can do for me in this case.

Specifically I have a file that looks like this:

class Data {
    IntegerProperty int1 = new SimpleIntegerProperty(4);
    ObjectProperty<Person> person = new SimpleObjectProperty();
    ObservableList<Contact> contacts = FXCollections.observableArrayList();
    // other properties
    // also add the getters for the properties and the getters and setters for the values
}

Person and Contact are similar to the above - they contain mostly data properties and some methods for adding and removing from internal (private) lists etc. Basically they are like beans or POJOs only with properties wrappers. This is the data that needs to be sent between the server and the client but only the wrapped values are important - not the bindings. This leads me to the point about serialization: javaFX properties are not serializeable so it was suggested here to make such class as the above externalizeable and write and read the wrapped values.

Ultimately I don't care if i need to do this custom stuff (though it's a lot of work) or if there's a way around it. I need a method on the server like Data receiveDatafor(...) that the client can call, the server fetches the Data data and returns it. The client and server each have their own unrelated bindings to the Data object.

Currently we use RMI internally for desktop. I read that RMI isn't supported and it might not be that great of an option anyway but it does allow to just send java objects really easily. JavaEE has websockets which can transfer the binary form of the objects but it's JavaEE so I guess not supported. I'm not against JSONing and sending as Text but it seems more work than to just serialize - could be wrong. The communication method should support encryption for example when sending passwords. What are my options?

Community
  • 1
  • 1
Mark
  • 2,167
  • 4
  • 32
  • 64

1 Answers1

4

In terms of client-server communication you can have a look at Gluon Connect and Gluon CloudLink.

Gluon Connect

An open source library:

Gluon Connect is a client-side library that simplifies binding your data from any source and format to your JavaFX UI controls. It works by retrieving data from a data source and converting that data from a specific format into JavaFX observable lists and observable objects that can be used directly in JavaFX UI controls.

It is also part of the Charm dependencies, so you have it already included when you create a new Gluon project.

See the documentation on how to use to create a FileProvider or a RestProvider, and also the GluonConnectRestProvider sample.

As the doc already mentions: with a RestClient you can "convert" a REST endpoint into an ObservableList:

// create a RestClient to the specific URL
RestClient restClient = RestClient.create()
    .requestMethod(RestClient.Method.GET)
    .host("https://api.stackexchange.com")
    .path("/2.2/errors");

// retrieve a list from the DataProvider
GluonObservableList<Error> errors = DataProvider
    .retrieveList(restClient.buildListDataReader(Error.class));

// create a JavaFX ListView and populate it with the retrieved list
ListView<Error> lvErrors = new ListView<>(errors);

The Notes sample uses Gluon Connect for local storage of Notes and Settings.

Note that these samples make uses of JavaFX POJOs (i.e. Error, Note and Settings use properties).

Gluon CloudLink

Gluon CloudLink enables enterprise and mobile developers to easily connect their different services and applications together, enabling bi-directional communications between mobile apps, enterprise infrastructure, and cloud systems.

The data is stored in the cloud, and you (as administrator) can access to it through a Dashboard.

See documentation about it here.

Have a look at the PWS-GluonCloudLink-Whiteboard sample: a full demo of a back-end application (webapp-mobile) running on the cloud (Pivotal Web Services) and a mobile client (mobile app).

In the client side, once you get a valid GluonClient, you can retrieve an observable list of items:

public GluonObservableList<Item> retrieveItems() {
    GluonObservableList<Item> items = DataProvider.retrieveList(gluonClient.createListDataReader("items", Item.class));
    return items;
}

As you can see, in the client you don't deal with REST endpoints, json serializing... Everything is just JavaFX observables. The connection with the backend is set in CloudLink with the Dashboard application, defining a REST Connector.

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • Iv'e gotten around to this task now. With Gluon Connect I understand how to make a REST request on the client but what needs to be done on the server? Also the link at the bottom of https://github.com/gluon-samples/gluon-connect-rest-provider is not working. – Mark Mar 30 '17 at 13:38
  • 1
    Have a look at the CloudLink-Rest-Connector [sample](https://github.com/gluon-samples/cloudlink-rest-connector) or the PWS [sample](https://github.com/gluon-samples/pws-whiteboard). They target the CloudLink, but you could connect your client directly to them. – José Pereda Mar 30 '17 at 13:44
  • Iv'e done some reading but I'm missing pieces. Do I need Glassfish for this? We plan on hosting the server process on AWS if that's relevant. I don't see regardless of all that what code I need to write on the server process in order to allow a client to call a request on it. – Mark Apr 01 '17 at 17:53
  • 1
    The typical web app with your back-end usually runs on Tomcat/Glassfish/Payara..., but you can host it as well on the cloud. As I mentioned before, the PWS sample runs on CloudFoundry using Spring Boot, and you don't need an application server. But I really suggest you get started first by running the CloudLink-Rest-Connector sample locally on Glassfish. – José Pereda Apr 01 '17 at 18:46
  • I can't create a `GluonClient` object ("cannot be resolved to a type"), there's no import available for it. Do I need to specify some dependency in Gradle? – Mark Apr 12 '17 at 23:36
  • Add this: `compile 'com.gluonhq:charm-cloudlink-client:4.3.2'` – José Pereda Apr 12 '17 at 23:54
  • Still nothing (refreshed gradle project and saw it downloading pom and jar). Anything else I might be missing? – Mark Apr 13 '17 at 00:00
  • 1
    Yes, there is no GluonClient now. You can use DataClient instead (See docs for Gluon CloudLink Data Storage) – José Pereda Apr 13 '17 at 00:15
  • Done some more reading. I think I'm missing the bigger picture. It looks like I need some application server (like JBoss, GlassFish...) and hook the java server application into that, is this right? Then I need to use the `DataClient` to connect to that application server instead of to Gluon CloudLink (because `CLOUD_FIRST` connect to CloudLink)? – Mark Apr 13 '17 at 19:52
  • Gluon CloudLink could be your endpoint (i.e. you just need to store some data on the cloud, and you can use `DataClient` to read/write it), or it could be the bridge to your back-end, where you have your system connected. With REST endpoints, back-end communicates with CloudLink to read/write the data (using Connectors), and you still be using a `DataClient` to talk to the CloudLink and retrieve that data for your mobile front-end. To be clear: CloudLink is not a cloud, and you can't host your back-end there. The use of a back-end is up to you, depending on your needs. – José Pereda Apr 13 '17 at 20:41
  • OK, so yet again I'm confused. CloudLink is something I need to buy and it gives me some storage and connection bandwidth, no? If my data resides in the java server process and the database in the backend what does the CloudLink do? Can Gluon Connect be used for bi-directional communication (server sends data to client and client to server) without CloudLink? if not, does it mean that I need to buy the CloudLink service in order to have bidirectional communication between the mobile end and the backend? Sorry for not understanding. – Mark Apr 13 '17 at 21:25
  • 1
    If you read again my answer, you'll see that you don't need CloudLink to connect front-end with back-end (using Connect precisely), but if you use it, you'll see that it's very convenient. It works as an [MBaaS](https://en.wikipedia.org/wiki/Mobile_backend_as_a_service). If you have the time, check the recent presentations [here](http://gluonhq.com/support/media/), like this [one](https://youtu.be/sr1ZHoBCuv4) or this [screencast](https://www.youtube.com/watch?v=i8JywDkOHJI) – José Pereda Apr 13 '17 at 23:09