Convert Applet to Servlet (Apache) - java

I currently have a java applet sitting on my Apache server (in the htdocs directory). The applet is a web crawler and takes a very long time to process before delivering results (I guess applets get very limited resources).
I would like to push the crawling work onto the server but I don't have any idea how to do this. I know that I can make a Servlet maybe using Tomcat or something like that but I don't know what would be involved.
Do I need to install Tomcat (or is this part of Apache)?
Is this something that can be done in several hours (the first time)? Or will this take me some time to do?
Currently my applet is at http://mySite.ca:4005/crawler/. I only have access to port 4005 (other users get the other ports). Would Tomcat play nice Apache? Can I direct requests to http://mySite.ca:4005/crawler/ to tomcat and allow Apache to handle the rest of the requests (ie: requests to http://mySite.ca:4005/otherPage/)?
I don't really care about the applet/GUI code that I have written, my main objective is to get the webcrawler running with some arguments (input from user) and then display the results (output to user).

Do I need to install Tomcat (or is this part of Apache)?
Tomcat is not part of Apache HTTPD, you need to install it separately.
Check Tomcat homepage for details.
Note that you could also use other servers to run servlets, e.g. Jetty
Is this something that can be done in several hours (the first time)? Or will this take me some time to do?
This depends on your familiarity with computers and your particular operating system. I would do it in couple of minutes. :-P
Currently my applet is at http://mySite.ca:4005/crawler/. I only have access to port 4005 (other users get the other ports). Would Tomcat play nice Apache?
In general, Tomcat has been designed to be integrated with Apache HTTPD, see the documentation about connectors and connectors website for details.
I'm not sure about assigning different ports to different users, I do not think this is the proper way to do this. What exactly are you trying to achieve here?
Can I direct requests to http://mySite.ca:4005/crawler/ to tomcat and allow Apache to handle the rest of the requests (ie: requests to http://mySite.ca:4005/otherPage/)?
Yes you can. Check the Connectors guide and Apache HTTPD Location directive for details.
I would advise you to use plain HTTP to communicate between your applet and servlet.

Related

JSF web application to monitor client resources

I have to provide a way in which a server will monitor its client's resources (i.e. cpu usage and ram) and store the data in a database.
I am learning about the JSF right now and aim to develop a web application that will use OperatingSystemMXBean methods on the client to get the resources of that machine. The problem is that I am not sure if this is the right approach to the task or even possible to do it with the JSF - operatingSystemMXBean combo.
My question - is it possible to do it this way? And if yes, is this approach worth the effort or is there a far simpler way of doing it.
Thank you.
You can not run java code on the client side. As you are new to JSF you should read more about this technology. The java codes that you write in jsf pages compile in the server side and the result will pass to client browser. If you want to get client resources like ram and cpu you need third party apps on the client side. Maybe there were some plugins that installs on client browser to do this(or you write your own) that you should search more about this. And also another approach is that you write a program which installs in the client pc to send his resources information to your server over internet.

How to allow interaction between Java application and user front Web interface

I need to create a user facing web interface (perhaps with HTML5 and Javascript) that allows a user to draw lines using a mouse. The interaction would involve mouse drag, clicks, etc. I need to send these inputs to a Java application on a remote machine and get back some result and update the web page the user's drawing on. So this would require a two way communication.
Since this is a proof of concept prototype, I need a solution that's easy and simple, and hopefully fast since the user would like to see the update quickly. What technology do you recommend to allow the communication between the web interface and java application? I was thinking about writing a simple server in Java and talk to the remote application using JMS... not sure this is the right direction.
Thank you for your insights.
Any servlet container, such as Tomcat, JBoss, Jetty, GlassFish or WebSphere would do.
I'm not sure JMS is a good fit here.
The browser would communicate with the server the way all web-apps do, via http requests. So, on the server you would use servlets, or some frameworks that builds on top of servlets, running in the container of your choice. You webapp would periodically send an xml http request (XHR/AJAX) to update the state of the drawing. Or it would do it when the user wanted to save their design.
Keep in mind what you are describing is a Web Application. This means that an application is running in the browser, so it can maintain its own state independent of the server. It just needs to sync up every now and again. You don't need to continuously send requests to the server.
it can be done also using RIA: actionscript3/flash+xml socket+java server. You can handle events via actionscript3 and then send parameters to server and after receive answer. There is lot of source for as3 drawing api after you can modify for socket connection.
have you tried this ? Look at the demo section on the shared canvas.
http://jwebsocket.org/

how to design a web application that developers can use to retrieve the crashdump/Logs from customer environment

Hi I am c++ developer and my knowledge to web technologies is minimum. Right now i am trying to design a web application which the development team can use to connect to specific customer and collect any crash dumps or log files.
With my research i realized it could be the following way.
1) develop an agent with build it http server and listing for request in specific port and install it in a machine with internet access and public ip address in all customer sites environment.
2) The agent is capable of collecting the required information from the customer environment based on the request it receives.
3) Develop an application with browser interface, and installed it centrally on the development data center. This application must have capability to connect to a specific customer environment and send http request over the internet to listening agent in that customer site and collect crash dump or logs or some statistics on the customer environment based on the request.
I am not sure this is the right way of doing, but I am sure there is a better way to do it.
Any help or pointers on what is the right approach and what kind of infrastructure is require to implement this kind of a service is highly appreciated.
Regards,
Prakash R
The approach looks serviceable, except you don't need to develop any applications to do that, as existing applications fit the bill nicely:
Use a web server of your choice. Apache is well known and open source (free). You might wish to configure security.
Assuming you're running under unix, you could use a link to include the log directory in the file system the apache serves.
Use your browser. (You obviously have one already). If you have many sites, you could use bookmarks, on a link list in your intranet, or ...

Integration of Java server application into Application Server like TomCat, GlassFish, etc

I am working on a server application that does the following:
Read data from a measuring device that is being addressed via a serial interface (javax.comm, RXTX) or sockets.
Exchange data (read and write) with another server application using sockets.
Insert data from (1) and (2) into a database using JDBC.
Offer the data from steps (1) to (3) to a JavaScript-based web app.
My current prototype is a stand-alone Java application and implements task (4) by writing the data to an XML file that is being delivered to the client via a web server (Apache), but I consider this to be a hack, not a clean solution.
This server application needs to start up and work also without any web clients being present.
I would like to integrate this server application into a Java application server, but I do not have much experience with these technologies and don't know where to start. I have tried some simple examples for TomCat and GlassFish, but that did not bring me any further because they are all built around serving web requests synchronously and stop where it would be getting interesting for me.
Is this possible to run such an app within TomCat or GlassFish?
If yes, where would be a good point to start (examples, which base classes, ...)?
Would it make any sense to split the application and implement only task (4) in a servlet, the rest in an ordinary application, communication via sockets, etc.?
Would other servers, e.g JBoss, be a better choice and if yes, why?
Edit:
The reasons I want to use a Java EE container are:
I would like to have a clean external interface for step (4).
On the long run, the application will need to scale to a huge number of simultaneous clients (at least several 10.000), so a want a standard way of scalability and application management.
In general, it's not a good idea to implement all of this in a servlet container such as Tomcat.
A servlet container is designed to service requests from a client. It sounds like you have a process which will be running all the time or at least periodically. You can do this in Tomcat, but it's probably easier to do it outside. Leave Tomcat to do what it's good at, servicing requests from browsers. It's happiest when the requests are short lived.
So I would do as you suggest, and only have step 4 in the container. You can easily interrogate the database populated in step 3, so there is no need to create web services to populate the servlet container.
For step 4, you will need to expose some services from Tomcat, either through rest, soap, whatever you like. The javascript clients can then interrogate these services. This is all completely doable with Tomcat.
For scalability, there shouldn't be a problem using Tomcat. If all it's doing is pumping data from the database to the client, there probably isn't a reason to choose a J2EE container. If you don't have need of complex transaction management or security, try using something open source. It sounds like you can get what you want from Tomcat (& hibernate & spring security if necessary). If you start to have performance problems, then the fix will probably be the same for JBoss & Tomcat: you need more servers.
My advice: stick to the simple open source solutions and move to an application server only if you find it to be necessary.
I would loosely couple the solution and not try to do everything on the Java EE/Servlet container as exchanging data using sockets (managed by the application itself) is not something you typically want to do from a Java EE/Servlet container.
Running this on a Java EE container might also be overkill as this doesn't sound like a typical enterprise application where stuff like security and transaction management is important and the app could benefit from services provided by the Java EE/Servlet container.

How can I host many identical java web applications?

I have a problem. I need to host many (tens, hundreds) of small identical JAVA web applications that have different loads during one time. I want to use Glassfish V3. Do I need to use a load balancer and clusters or something else? Advise where can I find information about similar problems and their solutions...
I need to host many (tens, hundreds) of small identical JAVA web applications that have different loads during one time.
For hundreds of webapps, you will very likely need more than one app server instance. But this sounds odd to be honest.
I want to use Glassfish V3. Do I need to use a load balancer and clusters or something else?
Right now, GlassFish v3 offers only basic clustering support using mod_jk (i.e. no load balancer plugin, no centralized admin, no high availibility). If you are interested, have a look at this note that describes the configuration steps of GFv3 and mod_jk.
For centralized admin and clustering, you'll have to wait for GlassFish 3.1 (see the GlassFish Roadmap Community Update slides).
You could check out Gigaspaces. I have seen it used in conjunction with Mule for a somewhat similar project. ESBs tend to be overkill in my opinion, but it sounds like you have quite the task to conquer.
Based on your requirements, you cannot do load balancing since the load is predetermined by which client the request is for. Each request has to go to the app handling that client, so it cannot be distributed outside the set of apps dedicated to that client.
You can use multi-threading. you could set up the configuration so that different threads handle different clients. However, it might be better to simply have a server that can handle requests from different clients. Based on the client sent with the request, it would be dispatched to a different database etc.

Categories