Add Web Interface to existing Project - java

I tried to understand this several times allready, but still have not found out how this should be done.
I want to create a web interface for some existing console or swing application. Something like the web interface SABNzb offers (I know, it's Python – it's just an example).
I have looked at several technologies allready, like creating web services using a tomcat server, or java server pages/faces, but all the tutorials that I found so far start with "Create a new Web Project..." at wich point I stop because this is not what I want! I have a finished an application in which I want to integrate a web interface, not some web service that instantiates my program as a local variable and uses its code. So basicaly it feels like all the tutorials I find are the wrong way around.
The core procedure of this is clear, the application should listen for http requests on a port I choose and answer with a created html code to it. So basicaly I could open a port using a socket and write an html page to its output on connect. But this rather feels like inventing the wheel all over again, also I'm not sure how an interactive web page would work this way.
Maybe I am thinking somewhat strange here or did not understand how some of these things work, but I am pretty unexperienced with web technologies, so grasping the concept is rather hard at the moment. Can anyone point me to a tutorial that shows how this might be done, or some other source of information on it?

You don't need JSP or JSF; all you need is a servlet. It's an HTTP listener class. You can do REST with that.
The moment you say that you have to deploy your servlet in a WAR on a servlet/JSP engine. Tomcat is a good choice.
Google for a servlet tutorial and you'll be on your way.
My First Tomcat Servlet

Ok, thanks to duffymos answer and comments i realized i was actualy searching with the wrong keywords.
Embedded web server is the thing i was looking for.
Like Simple or build in HTTPServer class in java.

Related

spring mvc without web server (tomcat or glassfish)

I just need a little hint in what direction my research should go.
Because currently I have a spring standalone jar project (spring-context, spring-data-jpa and hibernate entitymanager. Everything set up without xml files).
Now I want to run this application on two computers inside a network. Both should be able to send objects over the network. But I want to accomplish this without a web server (so no tomcat or glassfish).
Is this even possible? and how is this called?
I have problems finding something close to this plan. Most of the time I find tutorials and threads for sending objects with tomcat. But I more or less only need a open port that listens to incomming objects.
EDIT
Later I also want to put a third player in the communication process: A website. So then two standalone jar programs and one website will pass objects around. That's why I hope spring mvc will work for a stanalone solution as well.
(I know that this question will get tagged down, but it's ok, as long as I get some designations I can use to research better, so thanks ...)
You have many specifications. ProtoBuf seems to be interesting https://github.com/google/protobuf/tree/master/java
Without having server it would be a pain for you as you will have to implement concurrency, security and this kind of stuff.
Does Spring Boot work for you? Server is embeded ;-)
What about use normal java sockets? There is plenty information if you google it. If you need help with this just let me know and I can send you some java application. Just type Java Sockets and lets learn!
Alvaro.

What are necessary components and strategies for developing a REST-based client program?

I have been doing research for days and am so lost because everyone implements this differently or these tutorials are unclear.
I will be writing a web application that uses API's from sites like AWS, CROWD, etc. to create a single-sign on portal to manage many different things.
I have never worked in web development before, so this is all new. How should I get started in this project? What exact files will I need to create? Any advice would be helpful.
The only constraints that I have been given is that this will run in Tomcat, so I need to use java.
You need to understand the basics of client - server architecture and develop a
web service to standardize the REST based actions such as RPC.

Webservices: Why use soap engine and application server?

First sorry for my english. I am currently trying to develop a JAVA webservice for Android devices. More precisely, the webservice provider would be an ordinary computer and webservices clients would be Android devices.
After I have read some tutorials, I have done this one (webservice + client), which require only Eclipse. Everything works OK. So my question is the following: given that my webservice is working well and is accessible, why would I use soap engine and application server, as mentionned in this short introduction to webservice ? Said another way, what are the advantages, concretely?
I have tried to google, read and learn more, but I am stuck at this point.. If I have well-understood, SOAP engines, like Apache AXIS, allow to dynamically generate SOAP data and to receive requests from different clients. But does not my webservice already generate automatically SOAP requests/responses, since I can use my webservice with my dedicated client?
Regarding application server, I just can't figure out what it is. I found few documentation about that I could understand.
I know that instead of asking these kind of question, a better way would be to practice myself soap engine and application server, but I would prefer to know what I am doing and using rather than to go in a "random mode".
I hope I've been clear, thanks a lot for you answers.
MCFarah
You asked a couple of questions which are quite heavy, but i'll try to give a brief overview:
Web/Application Servers are basically a piece of program that implements a lot of stuff that help the developer, by allowing him to focus on the actual development and not on the stuff around. Stuff like: Threads, security, Database connection pooling etc.
You don't have to use SOAP webservice, actually I think you'd be better off using REST.
The tutorial you did is a "Hello World" tutorial. It is only good for getting started but once you start writing a larger application you would want to use a web server. Id recommend starting with Tomcat.
Just start using the technologies and post questions as you go.

Integrate a Java stand alone application to the Web

I develop Java applications with Eclipse that process data. So far I only developed stand alone applications that take data from file or database, process the data, and output the results to the console/file/database.
I would like put my application online. I never did any web development, but from my understanding, the only difference is that my code needs to be on a web server that can get http requests from users, and return http response based on my application's result.
I would like to get advice on the easiest way I can do this. What technology do I need to learn and what tools I can use for making the transition easier. I would also like to separate my code from the code related to the web stuff.
Thanks a lot!
The simplest approach to developing Java web applications is via the Servlet specification. This lets you load your application into a Servlet container (such as Jetty or Tomcat), which handles the HTTP-side invocation issue. Your servlet is then a front-end for your front end agnostic processing application.
Since all applications require a user interface, take a look at the myraid of possible templating languages available. Velocity is always a safe pick. This will help you seperate the user interface from the adapter code.
While you investigate alternatives, Java Web Start may be the fastest way to get your existing application online. Here's a trivial example.
The easiest is most likely to learn how to write a simple servlet, how the HTML looks that you want to generate and then adapt your existing application to run inside the servlet code, and print html instead of just plain text.
This is described in the Servlet part of the Java EE tutorial (which is not great, but a start)
http://java.sun.com/javaee/5/docs/tutorial/doc/bnafe.html
If you want a more accessible book, I can recommend the Head First series. http://oreilly.com/catalog/9780596005405
For a web container, Apache Tomcat is fine. http://tomcat.apache.org/

How to deliver a Java program locally through a browser

I want to write an application that runs entirely locally on one machine - there is no need for connection to the internet or to any external machines.
I was thinking that it would be a good idea to use a web browser as the platform for this application so that I would not have to mess around with lots of UI stuff - I could just knock together the web pages fairly quickly and take advantage of CSS to get consistent styles throughout the application.
However I want to interact with a MYSQL database on the machine in question. With this in mind I was thinking that I could somehow use Java to process the information that the user inputs from the application and communicate it to the database via JDBC.
I know that I could use an applet to do this but the downside to that is that I would like the user to be able to save files to the local machine - and I have read that applets run in a sandbox which prevents them from gaining any access to the local machine.
I also know that I could use PHP but I would like to take advantage of object oriented design which Java is perfect for.
Does anyone have any thoughts, suggestions or links to tutorials/webpages which could help me to decide how best to go about this.
Any thoughts are very much appreciated..
I know you said you don't want to mess around with GUI stuff in java, but have you looked in to java web start? It does almost exactly what you need; a user clicks a link through a web browser and your application is deployed on their machine, it even checks to make sure the right JVM is used. Because it is a full application and not an applet, your app won't be sandboxed, and you don't have any access restrictions in your program (other than the normal java stuff..), and for example, it would be easy to do what you mentioned and talk to a mySQL DB. The only downside, is what I mentioned earlier, is that you would have to design a UI in java.
Web Start Wikipedia Page
Sun FAQ on Web Start
Grails may be a useful starting point. It'll provide you with a web server solution that's standalone, and it'll look after the JDBC requirements and the CRUD (create-read-update-delete) capability via dynamically generated web pages. It should take minimal effort to put together an app providing your database interfacing via web pages.
(fyi. Grails is the Java equivalent of Rails)
If you feel comfortable with Java EE-based web development, you could probably just bundle your application with Tomcat or Jetty.
If you do not want to run standalone servlet container just for one application, you can also embed Jetty into a runnable Java application (see documentation here).
Either way you can leverage existing Java EE frameworks (Spring JDBC, Hibernate, all those web frameworks) for abstracting away technical complexities, although with embedded Jetty, you'd probably need to write some kind of integration layer for the web application framework of your choice.
I think you should give Restlet, a lightweight rest framework a try. The tutorial shows you how to start a local webserver, and by that deliver a "Hello World" through the browser within minutes (no joke!), and there's plenty of extensions for any kind of need.
In combination with Java Web Start by which you can deploy and start the application to the local host this should be what you need.
as someone suggested already you can use embbeded jetty server on your application and just let your user to start it using somekind of shell script or batch script. You only need to make your layour directory complaint with a Java Web Application and your on it. ie:
MyApplication
app/
WEB-INF/
lib/
classes/
web.xml
start.bat |
start.cmd - depends on your client OS
start.sh |
Then you should only need to take care of launching Jetty in your start.[bat|cmd|sh] with your app as your webaplication context and your done!
Using JDBC doesn't mean that you have to write an applet, you can use JDBC in any kind of application: a desktop application, a web application, EJBs, MDBs, etc.
You want to use a browser and Java on the server side? Then go for it and use Servlets / JSPs. Consider maybe using an presentation framework (Wicket, Struts2, Spring MVC,...), Hibernate for data access and Spring for other facilities and wiring. Grails is a good idea too.
BTW, I'm not a PHP specialist but PHP has object-oriented capabilities (introduced in PHP4 , enhanced in PHP5) so you won't sacrifice everything if you choose PHP.
So it really depends of what you want to do. If you want to write some Java (webapp or desktop app): choose Java. If you want to put quickly a few web pages in place and have an apache server, choose PHP. If you look for really high productivity, go for RoR or Grails.
You can try GWT + Google Gears
GWT is a GUI toolkit similar to Swing for the browser. Google Gears is a browser side database. Your app is completely in Javascript in a single HTML file and cross-browser compatible.
GWT app can make Server calls and Gears can sync up with a Server database. So you need not restrict your app data completely to the local desktop.
If you're interested in some experimentation, like new stuff and would like to reuse the plethora of Java libs (including JDBC) then you might be interested in the lift web framework, which is Scala-based.
If you want to do it as an applet you can. Sign the applet and give it permissions to the local network (to connect to the MYSQL server that way)... that should be possible. Here is a tutorial on it.

Categories

Resources