Java EE application approach - java

I have come up with a small project to help me learn Java EE, i'm unsure what technology best suites what I want to achieve however so i'm hoping someone can point me in the right direction.
What is essentially a gloried web crawler should be constantly running somewhere - maybe updating a database or not (the information will become out of date quickly so there might be no need to persist the information).
Clients can then view the up to date information when they log in, i presume a servlet is the best approach for this.
I'm not sure what technology is best for this kind of 'always running service'. I want the information always there regardless of whether a client is viewing it or not.
What approach would you take? While i realise it might not be the best solution using an application server for this, i'm doing this as a fun project for myself to help me learn.

have come up with a small project to help me learn Java EE, i'm unsure what technology best suites what I want to achieve however so i'm hoping someone can point me in the right direction..
Let's try. I'll base my answer on Java EE 6.
Clients can then view the up to date information when they log in, I presume a servlet is the best approach for this.
Or JSF 2.0 and Facelets (Facelets are the default view technology in JSF 2.0 and replace JSP as the view technology for pages)
I'm not sure what technology is best for this kind of 'always running service'. I want the information always there regardless of whether a client is viewing it or not.
It would be probably easier to run this in another VM but you could try with an #Asynchronous bean with EJB 3.1. See the links below.
See also
Part Three: New Features in EJB 3.1
News: Article: New features in EJB 3.1, Part III
TOTD #139: Asynchronous Request Processing using Servlets 3.0 and Java EE 6
TOTD #137: Asynchronous EJB, a light-weight JMS solution – Feature-rich Java EE 6

Ill address each point below:
1) Your concern over storing data in a db or not. The information should be stored in a database as your server will die from not having enough memory to keep everything available freely.
2) When clients log in yes you would want to use a servlet. To be more specific you would want a layer of abstraction between the model and the database. The Controller would speak with the model about its current state than proceed to paint the view (the web page) with the most recent data.
3) I wouldn't necessarily classify this as a service so to speak, but more so a portal of information. An application server is fine for this type of work as it provides a central point for clients to interface with the application.

Related

Any simple way to push Strings from JavaEE BackEnd to Javascript-Client?

in my project we are using an JavaEE(CDI,Hibernate)-Backend deployed on a WildFly-Server with an AngularJS-Frontend.
Is there any simple way to push messages from within a war-file to a Javascript-Client?
Thanks.
As you've mentioned JavaEE: Websockets are part of EE specification since version 7 - check https://docs.oracle.com/javaee/7/tutorial/websocket.htm.
The Websocket part of the spec is a bit rudimental, for example you have to implement things like topics, broadcasts or reconnect mechanisms by yourself (at least I couldn't find these functions in the specification). In case you need such functionalities it might make sense to take a look at socket.io (https://socket.io/) which can easily be integrated into Angular (https://tutorialedge.net/typescript/angular/angular-socket-io-tutorial/).
If polling (which is also implemented as a fallback in socket.io) is also an option, it's up to you what you prefer (and how complex the content should be). The EE specification is full of technologies with powerful abilities to return content: Servlets, JSF, JSP, JAX-RS, JAX-WS.
Just for clarification: Pushing or polling information with these solutions does only work when the clients have openend your web app in browser (even in background). If you also want to push information when they are not visiting your app you have to check solutions like Web Push Notifications from Google (https://developers.google.com/web/fundamentals/push-notifications/).
Hope this helps.

ICEFaces & GWT Integration: ICEPush

I'm a newcomer to JSF and am still trying to follow examples to learn the basics of how it works, and that has now lead me to begin exploring ICEFaces.
I love the concept behind GWT that you can just write in pure Java and have it compile down to JS and HTML, but I have also heard that ICEFaces offers a lot of things that GWT doesn't.
That led me to start thinking: is there a way to combine the two in a project, and get the best of both worlds? Is it possible to get the AJAX-centricity, rich UIs and underlying capabilities of JSF, but then use GWT to handle all the client-side code generation?
I looked at something called ICEPush which may very well do just this, but without fully understanding the roles both technologies play in MVC web apps I wanted to take a moment and see what the SO community thought of such a hybrid solution.
Having said that, I was wondering if someone could break down - in quasi laymans terms - the intentional difference between these two frameworks, and to give argumentation as to why they can be - or shouldn't be - combined inside the same project.
Essentially I'm looking for an AJAX-friendly, rich UI Java webapp framework that is open source, has an active dev community, and comes loaded decent/good documentation.
Also, not that beggars can be choosers, but I'd appreciate it if answerers don't solicit other solutions besides ICEFaces or GWT. I'm very well aware that these are not the only two webapp frameworks out there, and this question isn't going to convince me to start using either of them; I'm simply interested if their strengths can be combined, or not.
Thanks in advance.
JSF in general makes heavy usage of javascript. JSF or bette the JSF frameworks provide lots of components. The Javascript is generated on the fly.
GWT compiles the Javascript upfront. It provides some components as well. GWT is doing AJAX calls to its interfaces.
I'm not aware of any bridge that allows you to integrate JSF with GWT. So there is no interface and those technologies don't work together.
Both come with good documentation and have an active community.
ICEpush can be used directly with GWT; you can find out more about the integration here:
http://www.icepush.org/product/icepush-GWT.html
ICEpush provides a simple API to "push" notifications to the browser. Essentially, users (or browser windows) are organized into groups. When something interesting happens (such as a new photo uploaded to a photo sharing application) you can invoke a push on the group users.
In the case of the ICEpush GWT integration, you receive a callback into your "Java" code and can respond to the notification (such as, display the new photo). A GWT application can potentially run offline, but that does introduce the risk of application code being subject to offline attack.
In the case of ICEfaces, the ICEpush integration is abstracted away: rather than a "push" to a group, you "render" a group. With ICEfaces you request that all relevant pages be rendered on the server and any necessary page updates are sent to the browser. This makes it particularly easy to add Ajax Push features to an ICEfaces application.
So, the choice is really whether you want to use JSF or GWT. With JSF you have a standard server-side framework that emphasizes pages built from declarative markup. It is the natural successor to JSP application development. With GWT you have a procedural client/server distributed framework that emphasizes events and pages that are built from "Java" objects. It is the natural successor to AWT/Swing on the web. Both are very popular, so it's more a question of the technique you prefer.

Alfresco - /alfresco and /share difference

So i have installed Alfresco and have two web applications /alfresco and /share. Whats the difference and purposes of these applications? Can one application exist without the other?
/alfresco
This context points you to the Repository application. It's the "core" app, where the content is effectively stored and where all the magic happens. Back in the old times, it was the one and only application, so that when Alfresco introduced Share, it was the only place where to find a UI for some features. Now, Share is missing just a couple things.
Currently, the idea is that this JSF application should be a kind of Admin only interface, only to be accessed whenever Share is missing something. However, if you really love JSF (really?) you can still opt to use this interface to build your Alfresco implementation.
This application is mainly interesting for its features rather than for its UI: all the connections to external systems, like DB, CIFS or IMAP for example, happen from here.
On a side note, the "original" implementation of Alfresco WCM is built around this application. Anyway, because of several reasons this implementation of WCM is being phased out, with a new implementation built around Share and its concepts (e.g. Sites) that will grow quite a lot soon.
Don't expect new fancy development on this UI.
/share
This is usually intended the main UI for end users. No JSF here (thanks, God!), it's a Spring Surf frontend to Alfresco that focuses on providing a Collaborative environment. Here you will find the concepts of Sites, project/topic focussed containers for content, blogs and wikis.
As all the content is stored via the other application, Share is almost stateless: no DB connection is opened from here, everything is pulled and pushed to /alfresco via Alfresco REST API and CMIS.
As already mentioned, the new WCM is leveraged from here, as well as all the common ECM features of Alfresco such as workflows, versioning, document transformations, ACLs and so on. Plus, document previews and thumbnails, Blogs, Wikis, Data Lists, ...
This is most likely the UI Alfresco will continue to improve, adding all the whistles and bells they can come up with.
Adding some more information on latest version alfresco 5.0b.
Major changes in alfresco 5.0b is that Alfresco web client is removed from alfresco.So there wont be any JSF coding
Repository Architecture is still there, So if you want to deal with core app "/alfresco" is the location which will be used for creating webscript,workflows and other thing.
Conclusion
Share will be only used as frontend application.All core portion will
be on alfresco repository.
Alfresco:
By a developer point of view I would describe "alfresco" as the backend repository that sums up most of the functionality for which we use ACS. The services that share uses are defined in alfresco.
Share:
Share was introduced so that a person with not so much technical knowledge may be able to get as much as possible out of the ECM. If you are new to share you should look into model manager, smart folders and actions.
In 2020, think of /alfresco as the repository part of Alfresco and /share as the user interface. Keep in mind that Share is now deprecated and will be replaced more and more with something called Alfresco Digital Workspace. For now, they have most of the same functionality except that the old Share uses an older Javascript framework, called "Surf" that integrates with a much older version of Spring. The Alfresco Digital Workspace is created using Angular and is a client that can be run from its own WAR.

Which Java technology should I use, if I want to build a website with thousands of users?

Sorry for asking this question, but I searched all Java-related questions, but I got more confused. I am still not clear what should I start with.
My main thing is building websites in Java, because someone told me that there are some machine learning or AI libraries available in Java which I can use in Java. So I decided to use that as it can reduce my work.
Now I don't know Java at all. Some people say the following are used to build websites, like:
Servlets alone can build a website
JSP alone can also build a website
Struts
Spring Framework with Hibernate
Seam
Java EE also for websites
I am confused. Where should I start from? Where does core Java fits in here?
I was thinking of perhaps learning Python as I know I have to learn Python only, not its variations.
So please guide me to one thing which can solve my basic purpose of using ready-made libraries of AI.
If I can do that with JSP then I will start with that.
But if I need to learn all of them, then it’s better if can start learning Python.
I have five months to finish the website.
I really don't know why there are many branches of Java for doing one thing.
To correct some misconceptions of yours:
servlets and JSP are Java EE
Seam and Struts can be used together with Hibernate as well
Spring MVC is a web framework. Spring as a dependency injection framework can be used together with any other framework.
there are many more options, like JSF, Tapestry, Click, Play, etc.
It depends on what will the site will be doing, but you can choose any.
Experience has shown that building complex HTML forms (especially validation) and Ajax functionality is hard to get right. You will most likely appreciate having a library to assist you with that. The same thing with database access.
Everything builds on servlets. Learn those in order to understand the libraries you will use.
I would suggest learning JavaServer Faces (JSF) with facelets. The easiest, while being powerful, is JSF 2 in Java EE 6. The easiest way to get started is to use NetBeans with GlassFish 3.
For static web pages, HTML alone is enough and if you want to make it more user-friendly and interactive, use JavaScript.
There are lot of frameworks you can use directly in JavaScript, like jQuery. Now if you want to make some more functionalities, like database interaction, then you will need either PHP, Java (JSP and Servlets) or .NET (there exist some more, but I’m aware of three only). Each of them have their library to interact with database.
Since you are interested in Java, go through Servlets, HTML, JavaScript, and JSP. Once this is done, you can look into JSF and EJB beans. So if you have knowledge of Java this will not take too much time, because the syntax is the same; the only difference is the concept.
So you will have a frontend (HTML, JS, and JSP) which will interact with the backend (Servlets and the database) which will be deployed in a Web container. To deploy, you can use an one of the available application servers, like Apache Tomcat, GlassFish, or WebSphere. To develop your application, you can use Eclipse as the IDE, which is one of the best IDEs I have used.
So decide your architecture and design, break it into components and start writing small applications first. Once you are experienced in small application, start writing an application where there are more things you have to care of, like load on database, availability, security, etc. For that, you can refer a very famous question on Stack Overflow, What technical details should a programmer of a web application consider before making the site public?.
The closest to core Java is servlets. No extra syntax, very minimal library, but no included functionality.
For building websites, the main thing is HTML and HTTP.
All technologies (including Enterprise Java or Server side Java) do the same—to understand an HTTP request and respond back with HTML. All that you mentioned do the same thing with a different level of sophistication.
Start with Wikipedia.org to know what technologies do what. If you are completely new to Java, go through the Sun tutorials, do sample programs, and get comfortable with Java packages, JVM and classes. (This might take a week or two).
To build websites using Java, you'll have to learn Java Servlets—everything else (JSP, Struts, JSF, and Spring(!)) are built on it. Get Head First books on Java and Servlets; they will be useful.
You can always build the page in Ruby or something that will give you a website very fast. For the AI stuff that analyzes the bought items for the recommendations, use something unrelated to the page that only takes the database to work with.
I would not mix the whole web page stuff with the AI computing. You can do the AI things that will take a long time and maybe should done on a different machine to have your webpage also responsive with C++ or Java in normal applications.
Choosing your front end technique because of later usage is a very dangerous thing. Using the whole Java EE concept and learning it from scratch will take you much longer than have a quick start with your page if you do it in Ruby or PHP.
You can then build the first version of the page and generate a user base. Start working on the AI stuff once you got some data with other technologies.
If your page has performance problems because your technology does not scale, you can always begin switching parts of the stuff out with a faster technology or maybe simply a bigger machine. Get your page running before you build it bulletproof for the thousand users you are expecting.
If you’re trying to build a website from scratch, with no prior knowledge, your best bet is to go with frameworks that provide a complete stack for web development.
If you aren't dead set on Java, you could probably start learning Ruby on Rails, which would be easier to start with (if so, go buy a Ruby on Rails tutorial which goes through all the necessary things for modern web development, from MVC to version control).
For Java, try:
Play Framework is very similar to Ruby on Rails. It will get you started very quickly, and hopefully (if you follow conventions) handle all of your peripheral needs.
Spring Roo is a very-fast-to-work-with framework, but it might get hard to maintain and extend later on.
These two are full web frameworks, that is, they handle database, MVC (presentation layer), configuration setting, etc... (I'll explain shortly). And could even ease your deployment process.
If you're going to go through any other route (using several frameworks together), you are probably not going to finish what you are doing in five months.
To understand why, and to clear some things you wrote in your question, you need to understand that modern web development (and enterprise development as a whole) is comprised of several different technologies:
Presentation: the term web frameworks has been more or less taken to mean frameworks that deal with this side of web development, i.e., how to create a web page (an HTML page). Most of the frameworks offer an MVC like approach (which you can read about elsewhere), and this is what most of the frameworks/technologies you gave sit in—JSP and Struts (which uses JSP) are examples of web frameworks. Servlets is a lower-level API that standardizes how to answer HTTP requests (which JSP and Struts sit on top of).
Persistence: being able to show a webpage doesn't mean squat these days if you can't save data to a database, and that is what the persistence frameworks do (they ease the way you can save data to the database). Hibernate is a persistence framework.
For Java there are also dependency injection (DI), which is what Spring DI is. It's tough to explain DI to people not familiar with the troubles of Java, so I won't try to explain it, but it's a very important part of modern Java development.
apart from these core technologies, there are also many items that you'll need to learn to actually deploy the application (unless your using services like Heroku or Google App Engine, which should simplify things), and troubleshoot it later (understanding how concurrency and HTTP works).
To address the other technologies you brought up:
I've never really touched Seam, so I'm not sure, but it looks like a collection of other frameworks (mainly EJB 3, which itself is a collection of APIs, and JSF).
Spring denotes a popular open source group (the SpringSource group) that provides various technologies, but most likely when you hear about it they refer to two things Spring's dependency injection (DI) and Spring's MVC (which is a web framework).
Java EE is merely a collection of high level APIs which other technologies implement (Hibernate implements JPA which is part of Java EE for instance).

Please discuss what are and why use portlets

Why would I want to use java portlets above tomcat and gwt?
Would portlets make it less- or un- necessary for me to use jsp and jsf?
Has Jboss been part of the portlet evolution culture? Does Jboss satisfy the portlet jsrs?
What portlet implementation/brand would run on gae java and gae python?
Are portlet specs due to peer pressure from php cms culture?
What are the equivalent of portlet and portlet jsr in .net?
Portlets were a well-meaning but mis-guided attempt at a reusable widget API for web applications. Think of the personalised google home page, with the portlets like weather, news, mail, etc.
Unfortunately, they made a bit of a mess of it. The Portlet API is a bit of a pig, a real barrel of not-fun, and there are very few implementations of it. The only one I've ever used is JBoss Portal, but it's a bit of a brute, and rather buggy. Liferay may also be a portlet server, but the home page is heavy on fluff and light on information, so I can't tell.
Spring provides an MVC framework for the portlet API which tries to reduce the pain, but frankly I wish they hadn't bothered, it just clutters up the documentation.
Essentially, the whole shebang looks like a solution in search of a problem.
If you happen to have a framework that you need to use, and it supports portlets, you may find then that portlets are going to be useful, since the application is built with the idea, but, as others have mentioned, if you are starting on a project, there are many other technologies that will do what you want with less effort, in a more stable environment.
For example, when I worked at the University of South Florida, the learning management system was (and is) Blackboard, and they now support portlets: http://www.ja-sig.org/wiki/display/JSG/Blackboard+Portlet. So, if the application provides an API, and expects people to use portlets, then it may make sense to look at them.
UPDATE:
After looking at the question there were a couple of things I missed.
Portlets were an attempt, it seems, to try to do as Google did on their homepage, where you could have multiple unrelated blocks of information on the webpage, so you could track your stack portfolio and your favorite hockey team, for example. I don't think it was influenced by PHP CMS as it was just an idea that was ready to come about, and if you need the server code to help pull the information, and to tie it into an application, this was one approach.
The closest thing in ASP.NET that I can think of to portlets are controls. I could have a stock portfolio control and when I include it on my page, you can set the options and it will show you your stocks and hockey team scores.
Not everyone uses JSF, for example, so controls would need to be written by hand as JSPs and servlets, with javascript.
Why would I want to use java portlets above tomcat and gwt?
These technologies are not directly comparable. Coming from regular web page development, Portlets seem like a very restrictive technology. But then the value of Portal servers is largely the control they give to administrators and users - the fact that this makes your life more difficult is irrelevant.
Would portlets make it less- or un- necessary for me to use jsp and jsf?
You can write directly to the output, just like you would in a Servlet. You probably still want a view technology (that will have to support portlets).

Categories