I must create a desktop java client that comunicate to a servlet in order to receive some notificationes.
The servlet is an async servlet but my doubt is with the client.
How is the best way to "listen" a response from the server. I looked to the httpcomponents-asyncclient from apache, but I´m not trully convinced about that library. Maybe an infinite loop?
You might want to check out netty, it's what we use for our IntelliJ IDEA real time collaboration plugin to communicate with our remote server. It's very simple to get started with and abstracts all the hard parts, including creating secure connections. This is the netty user guide, it should get you started.
HttpComponents from Apache is very common
(be careful not to use the old one). Check a simple example.
Do you need to be constantly waiting for responses? If so, this is not the correct direction! The client should not have to call any method to get notifications... it should just be listening to some socket that the server writes to... Or just processing some queue. Perhaps you need to consider learning a bit of real time technologies and methods.
Related
I've been asked to look into adding an LDAP interface to an existing Java web application - that is, to make it possible for LDAP clients to connect to the application as if it's an LDAP server. I could write code to listen on a dedicated port and implement the LDAP protocol, and hook that into the existing database... but I'd have to understand the protocol first and then there are potential security issues if I write that from the ground up (not to mention the time it could take).
What I'm looking for is a library of existing code - something that handles the ports and protocols, and lets me focus on writing just the back end. There are plenty of client-side libraries out there, as you'd expect, but I've had no luck in finding something to help with server-side development. So the question is, does anyone here know of such a library that would help with this?
Yes you will most probably find many more client implementations than server, however LDAP is a request response protocol, so with a bit of playing around you should be able to use the same classes and their serialization capabilities. Instead of sending the request you would be receiving it, and responding with the response you would otherwise expect from the client.
You could look at the Apache Directory. https://directory.apache.org/api/
It has an embedded directory server project as part of it, which claims to be extensible and embeddable in your application. https://directory.apache.org/apacheds/
So maybe that could be the answer to your needs.
I've a Python application for data analysis and a Java EE application for web monitoring. Now I need to establish a durable communication between them, in order to transfer the analysis result from python to java.
Since both of the applications are located at the same server, I want to implement a TCP socket. As for the data volume, there're about 10 sensors' data transferred per second. I'm using Tomcat 8.0 for Java EE and a simple script for python. So my questions are :
Is socket implementation a good idea ?
If yes, how to implement it, can somebody give me a tutorial or example ?
If not, what should I do next ?
Additional information
I saw a related question on StackOverflow How to serve a socket from a Java EE application, there're some propositions :
Implement a Connector (JCA). But I think the target runtime is JBoss rather than Tomcat.
Implement a Java Naming and Directory Interface (JNDI). That's what I'm trying as you can see as my previous question Why JNDI resource can only be called once in Tomcat? People use JNDI for using resources, e.g. db connection. So I'm not sure if it's a good way for realtime communication. And I've met many troubles by learning it.
I thought about web-socket. But does it mean I need a python server as well ?
I believe there is a hundred way to do it to share data between these technologies. But for Java you should keep it simple. In Tomcat you don't need to write a socket implementation, you just need a basic Servlet implementation. So basically for your questions.
Is socket implementation a good idea ?
Shortly NO.
If yes, how to implement it, can somebody give me a tutorial or
example ?
Already answered NO.
If not, what should I do next ?
Write a basic servlet application who listen an server url address. Your phyton script is just a client. In phyton site you just send a POST request to servlet url and in Java side get the request read your data and process it. You can start to learn Servlet from Mkyong.
Ok so I have created an application, which is a Java Web Start application, but I have determined that I will need to write data to the server machine, hence the need for an additional server application. Pretty much I want the client to send different strings in order to process a clients requests in varying ways (eg create a new user file on the server machine or send user data read from a file to the client machine).
I was thinking of possibly using sockets, but if there is a better way then I'm all for that. Also I assume that whatever I do use, I will need to use threading in order to process many simultaneous requests, is this correct?
For your purpose you better create a webservice which communicates over http for exchanging data. I would recommend doing this in Java or maybe creating a WCF in C#.
Tutorials in Eclipse for java webservice: http://www.vogella.com/articles/REST/article.html#first_project
In netbeans: http://netbeans.org/kb/docs/websvc/jax-ws.html
The first tutorial is a restful service which is pretty popular and easy to grasp.
Good luck!
I would like to use AWS and especially Amazon Simple Email Service (SES) in order to setup a webservice allowing to send emails.
Emails would be triggered by some kind of POST request to the webservice with some authentication, and the webservice would then just send the email on behalf of the web service user.
Where should I start? The webservice part looks dead simple but I'm not familiar at all with web services. I still need to run some kind of multithreaded webserver since there could be a bunch of concurrent requests.
Is there a way for me to write a very simple web server in Ruby or Java to do that? Any pointer appreciated.
After some digging, the simplest solution is to use something like node.js or sinatra. The nice thing is that these are almost self-contained and require barely any configuration. They provide a very easy way to reply to HTTP requests.
Once you get one of these, you start the script with a port.
The small webservice will now listen on that port. You only need to take action based on the requests passed as parameter.
And yeah, now it sounds so obvious...
their documentation is good way to start. its quite easy to start, may encounter difficulties based on your problem domains.
you also need to implement something on top of this service.
http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/index.html
http://docs.amazonwebservices.com/ses/latest/APIReference/
http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/
Good Luck!
I would start with looking at AWS sdk Java.
They seem to support SES.
http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/index.html
Good Luck!
I'm in the process of writing a client/server application which should work message based. I would like re-use as much as possible instead of writing another implementation and curious what others are using.
Features the library should offer:
client and server side functionality
should work message based
support multi-threading
should work behind load balancer / firewalls
I did several tests with HTTPCore, but the bottom line is that one has to implement both client and server, only the transport layer would be covered. RMI is not an option either due to the network related requirements.
Any ideas are highly appreciated.
Details
My idea is to implement a client/server wrapper which handles the client communication (including user/password validation) and writes incoming requests to a JMS queue:
#1 User --> Wrapper (Check for user/password) --> JMS --> "Server"
#2 User polls Wrapper which polls JMS
Separate processes will handle the requests and can reply via wrapper to the clients. I'd like to use JMS because:
it handles persistence quite well
load balancing - it's easy to handle peaks by adding additional servers as consumer
JMSTimeToLive comes in handy too
Unfortunately I don't see a way to use JMS on it's own, because clients should only have access to their messages and the setup of different users on JMS side doesn't sound feasible either.
Well, HTTP is probably the best supported in terms of client and server code implementing it - but it may well be completely inappropriate based on your requirements. We'll need to actually see some requirements (or at least a vague idea of what the application is like) before we can really advise you properly.
RMI works nicely for us. There are limitations, such as not being able to call back to the client unless you can connect directly to that computer (does not work if client is behind a firewall). You can also easily wrap your communication in SSL or tunnel it over HTTP which can be wrapped in SSL.
If you do end up using this remember to always set the serial version of a class that is distributed to the client. You can set it to 1L when you create it, or if the client already has the class use serialver.exe to discover the existing class's serial. Otherwise as soon as you change or add a public method or variable compatibility with existing clients will break.
static final long serialVersionUID = 1L
EDIT: Each RMI request that comes into the server gets its own thread. You don't have to handle this yourself.
EDIT: I think some details were added later in the question. You can tunnel RMI over HTTP, then you could use a load balancer with it.
I've recently started playing with Hessian and it shows a lot of promise. It natively uses HTTP which makes it simpler than RMI over HTTP and it's a binary protocol which means it's faster than all the XML-based protocols. It's very easy to get Hessian going. I recently did this by embedding Jetty in our app, configuring the Hessian Servlet and making it implement our API interface. The great thing about Hessian is it's simplicity... nothing like JMS or RMI over HTTP. There are also libraries for Hessian in other languages.
I'd say the best-supported, if not best-implemented, client/server communications package for Java is Sun's RMI (Remote Method Invocation). It's included with the standard Java class library, and gets the job done, even if it's not the fastest option out there. And, of course, it's supported by Sun. I implemented a turn-based gaming framework with it several years ago, and it was quite stable.
It is difficult to make a suggestion based on the information given but possibly the use of TemporaryQueues e.g. dynamically created PTP destinations on a per client basis might fit the problem?
Here is a reasonable overview.
Did you tried RMI or CORBA? With both of them you can distribute your logic and create Sessions
Use Spring....Then pick and choose the protocol.
We're standardizing on Adobe's AMF as we're using Adobe Flex/AIR in the client-tier and Java6/Tomcat6/BlazeDS/Spring-Framework2.5/iBATIS2.3.4/ActiveMQ-JMS5.2 in our middle-tier stack (Oracle 10g back-end).
Because we're standardizing on Flex client-side development, AMF and BlazeDS (now better coupled to Spring thanks to Adobe and SpringSource cooperating on the integration), are the most efficient and convenient means we can employ to interact with the server-side.
We also heavily build on JMS messaging in the data center - BlazeDS enables us to bridge our Flex clients as JMS topic subscribers. That is extremely powerful and effective.
Our Flex .swf and Java .class code is bundled into the same .jar file for deployment. That way the correct version of the client code will be deployed to interact with the corresponding middle-tier java code that will process client service calls (or messaging operations). That has always been a bane of client-server computing - making sure the correct versions of the respective tiers are hooked up to each other. We've effectively solved that age-old problem with our particular approach to packaging and deployment.
All of our client-server interactions work over HTTP/HTTPS ports 80 and 443. Even the server-side messaging push we do with BlazeDS bridged to our ActiveMQ JMS message broker.