Which is the way to create a JavaFX client-server app using Json packets for the communication? I should interact in real time between two different remote JavaFX instances (like in a chat) sending from one side to the other messages Json formatted.
Any example for doing that?
Thanks!
If you need a high level overview of how this could be done, then you need a library for http (You want to send JSON over http, right?) and some library to work with JSON. I think JavaFX2 is not the case in this problem, you can do this in any Java app.
There is a nice thing called Apache HttpComponents to work with http. Tutorials on their site should provide you with some tips of how to implement both server and client functionality.
To work with JSON you can use, for example, Google's GSON library. Some discussion of JSON libraries can be found here.
At first look you need to form a Java object, representing JSON, convert in to String and pack it up into an http POST request.
Hope this will be some help.
Related
I have a small Java SE application, it´s practically a fat client sitting on top of a database. To further my Java skills, I decided to make a client-server application out of it. The server application communicates with the database and handles all kinds of lengthy operations, while the client application only receives the results, mostly ArrayLists of moderate length and primitives.
To this end, I started reading on RMI and did the Oracle tutorial, which I found surprisingly difficult to understand and even get to work.
Is there anything else I can use instead of RMI, without having to dive into JavaEE?
One way I would suggest would be to use JSON as the format for data exchange. You can use GSON to convert the data from Java objects to JSON and back. The transport could be done directly on the HTTP protocol using REST. You can use Jersey as a REST server/client or roll your own (since you don't want to use JEE, which Jersey is part of).
SIMON is as simple to use as RMI, but with fewer traps in the initial setup. It also has some advantages over RMI. Here is a simple hello-world example:
http://dev.root1.de/projects/simon/wiki/Sample_helloworld110
I take it RMI = Remote Method Invocation ...
You can have a look at XMLRPC, JSONRPC, JMS, or if you want to roll your own, use JSON to POST messages and convert the JSON back to a java object on the other side using GSON (from Google) or setup RabbitMQ and use AMQP to submit and receive messages if you don't want to handle the POSTing yourself, Spring AMQP makes it fairly easy to do this.
this is my first post on stackoverflow.
I am quite good at Java SE and client side Java Programming, but new to Java web development.
When I search for Java webframeworks, a huge amount of framework are offered, but nothing really seems to fit my needs.
What I actually want is a dumb server and a smart client.
I want the client to ask for certain information and the server to return the requested information in a xml or json format, so that the client itself manages the data.
In most cases the webframeworks render the html pages etc. on the server side, but I just want for example to use AJAX or the android xml parser to get the information and then fill the UI on the clientside.
I am not sure, if Webservices are the right thing for me, because I want to make several async requests to the server.
Or should I simply use servlets, which just return the right xml on request.
A second thing is how to handle the authorization and authentication of the users, which send the request to the webserver.
I do not want to allow everyone to receive the xml or json, which is generated by the server.
In short:
Is there a java based webframework, which can handle authorization and authentication of users and just returns xml or json to a smart client?
Which java based webframework fits best to my needs?
On the following webpage my aim is described, but unfortunately there is no hint how to implement such a "dumb" server...
http://seng130.wordpress.com/lectures-2/web-application-architecture/
You will likely need to use multiple frameworks. Spring-Security to handle your url intercept based on authority. Then use Servlet with Spring-MVC to handle the request within the Controller methods. Tutorial here: http://static.springsource.org/spring-security/site/tutorial.html You can have those methods return string values of JSON or XML. I would suggest using Jackson to convert your objects to a JSON form on the fly and the javax libraries for XML.
Example of Spring-MVC with Jackson:
http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/
Example with Jersey servlet and Jackson
http://www.mkyong.com/webservices/jax-rs/json-example-with-jersey-jackson/
I'm creating a Java application that uses Hunch's API, but the problem is I have no clue as to how I can use a web API in Java. Any ideas?
That depends on what the API provides, generally you'd need a web server (like Tomcat) to run a web framework.
If it's just an api to communicate with a service via HTTP (maybe webservices) then have a look at the corresponding libraries (JAX-WS etc.).
Edit: I looked up Hunch API, and assume it is this: http://hunch.com/developers/v1/
It seems like it would return JSON encoded data, so you might use the URL class to read data from an URL. That data would be a JSON string which then needs to be decoded using one of the many JSON libraries out there (e.g. JSON-simple).
im starting with web services. I'm working in a project that needs to communicate Android with a web server and I'd like to save some time chosing the appropriate protocol for the communication.
Between JSON ,REST and SOAP:
Which ones can I run in a non-dedicated server?
Whats the best choice for a high trafic server?
Thanks in advance
JSON and REST are not mututally exclusive. JSON is a data format that the REST interface can return.
You may run either on a non dedicated server. I would personally choose REST for rapid prototyping on Android as it is easier to get up and running. (With SOAP you will probably want to have a schema which takes time to put together)
There's a good comparison between REST and SOAP on the REST wiki article: http://en.wikipedia.org/wiki/Representational_State_Transfer#Concept
REST is more of a framework than a communications protocol. JSON and SOAP could be use to create a RESTful application.
If you're writing something with many resources, I'd use REST as it is far more structured. There are also a lot of libraries that will set most of things up for you. I find JSON and SOAP are better for custom functionality that you want to hack together quickly. They can be lightweight, but less structured.
I am building an ESB (enterprise Service Bus). This means i need to
set up tcp connections and communicate with JSON (well not NEED.. but json is light and easy)
I made a server who is able to set up a TCP socket and receive json. This is all very nice but i need to be able to call methods via a tcp connection.
so for example to call a method:
{server:pictures, method:changeImage('name')}
This is just an example and could change.
my question is: Is there a framework that is able to:
set up tcp server
receive json messages and call the appropriate method
return an answer (in json).
of course json could also be xml but i would rather use json (much cleaner)
thanxs in advance!
A Web Server serving RESTful web services is exactly what you're asking about..
If I were you, I would look into using SOAP based messaging and the WS-* Standards. Things like WS-Federation and WS-AtomicTransactions will allow you to build a more robust ESB.
Any modern Servlet container, perhaps? Running DWR or jabsorb? Have you looked at the modern ESB implementations? Sounds like you have a lot of wheel I've seen before here.
Why do you need to create your own ESB? As I understand it's a quite complex task. Have you considered using existing open-source solutions?