I have an app that has been developed using java and play framework. i have build two app one for the local and one for the remote to view its report data online. Actually i want to synchronize local database with remote database. The question is, how can i communicate and response data between two server programmatically in thread.
To communication between 2 PlayFramework Aps you can use standard REST WS on first App, and WS API on seccond one: https://www.playframework.com/documentation/2.4.x/JavaWS
But, for operations on two databases you should consider using xa-transactions: https://dzone.com/articles/play-20-framework-and-xa
Related
I am super new to React Native and want to use MySQL database to display data on my mobile application. This I have created a web service on JAVAEE Eclipse to connect to the database and perform CRUD operations. I am not aware of how to use the JAVA webservice as a funtion method to perform the desirable task on a button interaction. I will not be using web scripting like php and would definitely like to stay away from firebase and meteor types. It's a strict learning curve which I want to achieve without using different technology at the moment.
My development stack is React Native + JAVA + MySQL
No you'll not need to use or create any java function for this.
Use fetch or axios to call your services.
Let say your service is running on localhost and on port 2000,
now make sure your 1.server and 2.android phone in which you are running RN app are in the same network.
let say you have one service which returns a list of data.
now in react-native use
fetch("your machine/server's ip address + :port/serviceRouter or other things")
e.g.
fetch("http://192.168.0.2:2000/getData")
This will work the same as a postman.
You can find official docs for other details of fetch here
I want to host a Neo4j web service for a Wikipedia graph of pages and categories and basically get some recommendations out via cypher queries.
I have already created and populated the database.
How do I “ideally” setup such a service ?
Should I keep 1 dedicated instance for the Neo4j server and separate
instances for running Tomcat or Jetty which receive the client’s
requests and then forward the request to the Neo4j server instance
via the REST API ?
Or directly send requests (cypher via REST) from the client to the 1 neo4j instance ?
Or should I choose unmanaged extensions provided my Neo4j ?
Or is there any other way to set it up keeping scaling in mind?
I do plan to run load balancing and HA clusters in the future.
The web service will be accessed by browsers and mobile apps.
I have never hosted such a web service before so it would be great if someone helps me out :)
I would recommend that you create an API app that sits between your clients and Neo4j. Your clients would make requests to the API server, which would then make a Cypher request to Neo4j (could be one instance or an HA cluster).
The benefits of this include being able to implement caching at the API layer, authenticate requests before they hit your database server, being able to instantly update Cypher queries by deploying to the API server (imagine if the Cypher logic lived in your mobile app - you would be at the mercy of app store / user upgrades), and easily scaling your API by deploying more API servers.
I've skipped this layer and just used unmanaged extensions to extend the Neo4j REST API and have clients access Neo4j directly which works OK for rapidly implementing a prototype, but you lose many of the benefits listed above with one additional downside that you will have to restart your database in order to deploy new versions of the unmanaged extension.
I am learning to program Java. My objective is to create client server application based on Java and MySQL.
That would have following.
Server Application where all admin controls would be available to configure.
server application will be the only to have access rights to MySQL.
Server will have all functions and objects that clients will require and call and get that functionality. (Reason for that is "I don't want to share MySQL credentials to client apps or rather i don't want MySQL credentials to be transmitted on the network to clients"). As it would increase maintenance tough and it could be a security loop hole.
An analogy of functionality could be: client calls to server telling to add an Order such addOrder(order_id, payment,..,...,..) and so on.
What are the method in practice for such kind of application these days? A example code/or material to get in right direction would suffice
These days the universal way to expose a service remotely is via a web service. This solution was preferred by the industry over time due to its simplicity and ease of integration to the point that binary based protocols like CORBA are now seldom used.
Take the example of Android applications, they are native application mostly using REST web services.
A REST web service can be easilly integrated in the same way with a desktop application, a mobile application or a web application, even if the clients are written in different native platforms and languages.
As sample code, have a look at tutorials on the Spring stack. For the server see this tutorial for building an hello word REST web service. For the client, consider the REST template.
For security, see this Spring security hello world example. Using the Spring stack in Java will likelly give you the largest number of tutorials and online support.
This sounds like a good place to use RMI, which Java has built in support for. RMI will allow your client to call server-side methods on a local object that corresponds to the server, where all messages/commands get transparently sent to the actual server, where you have your DB access stuff and logic.
I evaluate using Meteor Framework in Monitoring Application.
Use case. Java Application running in the cluster generates data. Web Application visualizes this data (charts, etc.)
Currently it is implemented with plain WebSocket and custom pub/sub mechanism.
Java App -> (publishes to) -> WebSocket Server -> (pushes to) -> Web App (Browser)
Technology stack:
Java (data generation)
Node.js (web server)
AngularJS (JavaScript framework)
Questions:
Is Meteor a good candidate for the same?
How will Java app communicate with Meteor? Java client or write directly to MongoDB?
Have found this java client https://github.com/kutrumbo/java-ddp-client
Is it relatively easy to use Meteor in existing Node.js application?
Yes meteor is a good candidate for those tasks! Your project seems to be a quite simple scheme for meteor, not a lot of data to publish and a need for realtime monitoring.
It depends on what you do need to achieve from your Java app
Java server changing the mongoDB : could be a way [edit] I never tried but now Meteor supports realtime DB publication once the MongoDB is changed externally (not more waiting for the 10 secs delay to be published). So just be careful to what you do change on it from the Java App.
Use your Meteor server as the client and pull the values from the Java part which would act as a server. This could be achieved using timers, it is easy to setup a java servlet (or whatever you want) and publish the result from the meteor server side if something interesting happened….
Use the java app to publish changes to the meteor server. That is probably what you are looking for, I could see 2 ways of achieving this.
Via a url. Setup meteor with a router such as iron-router, once your client will connect to the meteor server you will then be able to retrieve the query from the url and do what you want with it. The pro is that is it quite easy to just make a "get" call on the server's url from the java App, cons is that you might be restricted in the data format.
Via this wonderful DDP client to connect to your server, then invoke a method call from that last one. On the server, once the method is invoked just update the corresponding collections and you are done. DDP is really a simple protocol, clients are simple to setup so I would personally go for it.
My advise is to use Node plugin within Meteor. Meteor comes with Node already (it's his engine) and if you really need to you can still use node.js modules within, the inverse is much harder.
How to get started:
Install meteor on your computer
Create one collection test, publish it
Create a dummy webpage just to subscribe and display this collection
Once you are happy with the result, create a Method for updating the collection from outside.
Meteor.methods({
foo: function (arg1) {
test.insert(arg1);
}
In your java client:
DdpClient client = new DdpClient("localhost", 3000);
client.connect();
client.call("foo", objectToAdd); // something like this
You are done, here is a dummy project for adding from your java app an item into the "test" collection. As meteor is responsible for publishing all the content to the clients, you only need now to find a good graphic designer to make an awesome monitoring webpage….
I am developing a multi-platform (Android, iPhone, Windows and Blacbberry) mobile application. The application needs to communicate with our server for several tasks, such as retrieving buddy lists etc. The server interacts with data that is stored in a MySQL database. I intend to code the server element in Java, however I am confused by all the different types. So far, I think I have narrowed it down to three options:
1) I code the application using Jetty to accept http posts. I post XML to the server, handle it, interact with the DB and post a XML response back. I would save the application as a jar and leave it running on my server.
2)I develop a Java web service. REST/JSON/SOAP?
3)I develop a Java web application.
Whilst there are many questions already out there asking what the differences is, I am struggling to find a clear explanation as to what is the best approach in which situation. I have previously used the first approach but am assuming the second approach is the better option, I'm just not sure what the advantage is.
your 1-3 options are all variants of a "Web application".
Jetty is a Java based http server/servlet container. If you want to communicate between client and server using http, you are using an http server (although not necessarily Jetty).
A Web Service is part of a web application that conforms to a standard around how clients communicate with the server, and how the server offers up information to the clients.
A web application is a Java application that makes it services available over http.
So if you want to have your clients communicate with a server, and store info in a db, you are using a web-application.
I would recommend going with option 2 as it is more lightweight and can be parsed directly in you're web application. XML got more overhead and must be translated, while you can just serialize objects directly to JSON from you're Java application and then parse them in javascript at frontend