Sharing a configuration between java client and server applications - java

I'm building a java client server application (both are JSE), here a quick description.
Server
The server interact with an external system receiving "requests" and providing "responses" to these requests via TCP/IP.
The content of the "response" depends on "rules" described into a "rules deposit".
Client
Clients are Java applications connected via HornetMQ to server.
I have multiple clients that (not simultaneously) can change the "rules deposit" to update/change or correct the response behavior.
My question is: how I implement this shared "rules deposit"? Are common frameworks I can use ?
Some notes:
I cannot use shared file
I'm not obliged to use HornetMQ
I prefer not to use Database RDBMS

Related

Communication between Java Swing Application(On client side) and server

What are the possible ways in which Java Swing Application which is running on client side can communicate with server?
I've read that JSP can be used in web pages to communicate between server and client.But, is it possible to use JSP with Swing application? if so, how? It would be helpful, if it is demonstrated with simple login form. Thanks.
Any client-side application, whether it be a java swing app or otherwise, can certainly communicate with any server (assuming no network limiting architecture -- firewalls and whatnot). Your options are numerous
Raw sockets
Any one of the myriad of network protocols.
HTTP/HTTPS
FTP
SCP
et. al.
It depends on what protocol, services and applications are available on the server to connect with.
HTTP/HTTPS is very common. You'll need to manually create HTTP requests and send them to the server (assuming the server is a web server).

Web cilent and server communication throught firewall

I want to create a web application, which is divided into two part one is client and another is server.
Client:
Client part is on the shared server.
Client is the GWT Application which only use to display data (containing only ui elements and ui events).
Client application is used by server to view and present it's own data.
Server:
The server is the simple java web service (restlet).
The server is reside behind the firewall.
The server contains actual data.
There are N number of servers.
Server does not contains any view if server wants ro view data it will use the gwt client application.
Every server uses same gwt application to view it's own data.
Note :
Client does not contains any address of the server. server will send the request to view it's data.
There is no firewall inbound exception on server firewall to access server data from out side client
I need to communicate client and server through firewall, Is there any architecture or design pattern to implement this type of application?
I don't think that the firewall can bring new restrictions to a GWT application compared with other types of applications (clients).
In case you have the GWT client on one server which makes calls to a different server you might have some issues due to same origin restriction.
This can be resolved in several ways:
- your GWT application has a server-side part which calls the other servers. And your GWT client makes normal RPC / JSON calls to the GWT server side (on the same server).
- in case you want to make directly the call on the different server from your GWT client you can use JSONP or the restygwt library.

How can I communicate with an object on a remote machine?

I know my IP address, and that of my friend.
How can I transfer objects/files between the two machines?
I am an advanced Java programmer, but have never worked with networks before.
EDIT:
I am now using an API called jnmp2p ( http://code.google.com/p/jnmp2p/ ).
It works fine when I use internal IPs, but fails when I give the external ones.
How do I connect to a computer that isn't on my private network?
If you looking for communication between two java applications and do not want to meddle with the low level networking details, then you can use following two approaches, depending on the type of applications you are dealing with.
If both the application (on two machines) are java standalone applications, then RMI is the best bet. Check out the basics from these links (1,2)
If your application (receiving files/objects) is a web application then its you can write the Servlet on the serve side and then write a client application to send files/objects(binary) to server. Commons FileUpload is very popular library for this purpose.
Author of jnmp2p here. I don't maintain the library any more because I've moved onto other things. However I had some comments.
Peer to peer communication with IPs outside your private network is a hard problem. This is because stateful NATs and firewalls on both ends have become common-place, which prevent you from establishing connections between machines directly.
For example skype uses a rendezvous service where both machines start outbound connections to a third machine and communicate via that. Aside from setting up additional infrastructure that any peer to peer solution is going to be limited to subnets within your NAT, so solutions like JNMP2P or RMI (with gross modifications) are going to be your best bet.

JAVA push from server to clients

I would like to have the clients query each other through the server without delay ( = no polling interval ).
Example: Server S, clients A and B
Client A wants to request Client B.
Client A will make a request to the server S, no problem there.
Then Server S needs to be able to request Client B but how to do that without polling?
All the node.js/APE (for PHP) technos are designed for the web, however I don't use a web server for that. Does Java has something close to a push technology/framework that is not web?
I would really prefer a solution that doesn't require each client to use their own reserved port (I don't want to end up with 1 WebService per client for example)
Note: all the clients are on the same machine.
A couple of options...
Plain socket communication. java.net.Socket, java.net.ServerSocket. Maximum flexibility but requires knowledge of low level TCP/IP API/concepts.
The good old RMI. Java based RPC layer on top of TCP/IP. Works good when client and server are both in Java and generally in same subnet. May give problems when client and/or server are natted.
Spring Remoting, it's actually pretty decent.
Bi-Directional Web Services. i.e. clients host their own WSes which the Server calls when it needs to do a callback.
JMS as someone already mentioned.
Distributed Data Structures, Check out http://www.hazelcast.com/
Lots of options to chose from, no need for webserver.
If you really don't want to use a web server then I would check out JMS. That being said, all the cool kids are using web servers these days since the protocols are so ubiquitous.
Your use case requires a messaging protocol. We don't really know the scope of your problem but you already said you want a server to exchange requests between clients, so I would go with an existing solution rather than a roll your own approach.
JMS has been mentioned and is certainly a viable Java based solution, another would be XMPP which is a real time communication protocol commonly used for instant messaging.
It is an open standard that has both server and client support in every major language and platform. This would allow you to have standalone apps, web based ones and apps for mobile devices all being able to communicate with each other. The only potential gotcha for your use case is that it is text based. Since you haven't said what requests you want to pass back and forth, I don't know if this will fit your bill or not.
You can use Smack for client side development in Java and any OS server you want.

Can I use any authentication mechanism on a network server implemented with Java Socket?

I implemented a network server with Java ServerSocket and Socket. There's no problem of getting/sending http requests/responses from/to web browsers. However, I want to add authentication ability to the server. I noticed there's such class java.net.Authenticator or java.net.PasswordAuthentication, but I've no idea if I could apply them to the server.
If any of you have used com.sun.httpserver.HttpServer, its authentication is easily supported by com.sun.httpserver.Authenticator which can be set through HttpContext.setAuthenticator() method. Unfortunately, using com.* package may not be allowed in our project. I just want to know if there's any class in java standard packages which can enable me do the same thing as com.sun.httpserver.Authenticator?
I can also implement this by forcing client to provide user and password in http requests, and parse them in the server. But if there's any convenient way, I would be very thankful.
Thanks.
I think, you confuse the network layers.
com.sun.httpserver.HttpServer implements the HTTP protocol and works in the application layer. HTTP defines authentication mechanism, thus com.sun.httpserver.Authenticator is an implementation of the authentication mechanism defined in the HTTP standard.
java.net.ServerSocket and Socket works in the transport layer and implements the TCP protocol. TCP does not define authentication service.
When your client-server communication uses HTTP, you should looking for an HTTP server implementation. IMHO isn't a good idea reimplement a HTTP server based on java.net.* package.
Unfortunately Java SE doesn't contains HTTP server -com.sun.httpserver isn't part of the standard-, but there are many open source and portable implementations. The two widely used is Tomcat and Jetty.

Categories