Java EE Application Design - web-services

I have a specific question about Java EE architecture. I have an application that requires several components:
A web service and persistence layer (cxf/hibernate)
A management / configuration console (Struts2/JSP?)
One or more user "applications" (Maybe Vaadin?)
Note, the web service will provide services to the user applications.
The web service has been built as a cxf/glassfish application (Eclipse dynamic we app) and is working well.
Should the management and user applications be developed as entirely separate applications (EJB's or ?) or form part of a "single" application with the web service. I am not sure if I am explaining this well enough - but I am new to this sort of design and am trying to approach the solution in a well structured way. For example I could imagine that taking an approach of separate services (applications) could result in:
Primary web service (does common data persistence stuff)
Authentication service
Management App service
First user App service
Second user App service
Each of the user apps is likely to have both common and unique data persistence requirements.

To decide how to split your implementation, you should consider your system through different views. In software architecture, there is a very useful method which is called the 4+1 architectural view model (http://en.wikipedia.org/wiki/4%2B1_architectural_view_model). Using the Physical view you will be able to decide if you may need to install the different components in different machines, and this will help you to define your development view, that will give you the answer to your question -> how to split the different components of your system in a development point of view. Once you have the development view, you can define how the components communicate (process view)... and so on.
This views have always helped me, I hope you find it useful.

Related

Should I use build APIs for my POS web application?

I'm building a POS(Point of sale) web application using Django for my client. This is a single instance web app.
I just want to know, should I build APIs to separate Backend and Frontend?
Whare are the benefits to build the APIs?
First and most importantly, each design decision you take for your application should be for a reason. There is no good or bad approaches, however, the approach you decide on should be based on your use-case.
I don't see any problem for having a monolithic Django application to service a single/multiple POS with limited number of users. Tens of thousands of Django applications out-there not using APIs and performing well.
That being said, if you are developing a POS solution and planning to offer it to public as SAAS (software as a service), then you might need to consider using APIs, have plans for scaling/support/patching/monitoring/upgrade/ CI and CD activities. On the other hand, if might be planning to have a Mobile application in the future; That might be another good reason to have APIs.

MVC web service + web application design that maximizes code reuse

I am using an PHP MVC framework (Yii, but my question could apply to most MVC frameworks) to create a project that should include a web application (website) and RESTful web service. I am facing an early design decision on how to logically separate the application and service logic. Here are some true facts:
The web app and web service will share a lot of functionality and only differ in rendered format (View vs JSON)...
...But, the web app and web service will have some unique features (ie, there will be things that the web app does that the service does not, and vice-versa)
Here are my desires:
I would like to share the common functionality's implementation as much as possible
I do not want the Controller to become unwieldy as a result of combining web service/web application logic
I have a a slight distaste for creating separate web service and web app controllers, especially when they overlap in Actions (other than the rendered format)
I do not want to have the web site consume the web service unless it is really a necessary design decision; I will lose out on a lot of built-in features that use database interfaces and/or have to create classes that conform to available IDataSource and other such interfaces by hooking it up to the web service; also there could be a slight performance decline.
I have thought about it a bit and come up with some solutions below. Please let me know which of these you think would meet my wants or let me know if my wants are not reasonable/counter-productive.
Implement completely separate controllers for WebApp and WebService (modularize the two so that they share no code)
Implement separate controllers for WebApp and WebService, but create methods that do the heavy lifting and call those methods to share implementation - for example, if I wanted to do a item/findBySomeCrazyCriteria I would route to the appropriate controller depending on the URL, but each controller would reference some FindItemsBySomeCrazyCriteriaFunction() defined elsewhere.
Make the web app consume the web service (which would require me to expand the planned functionality of the service)
Implement one controller for both WebApp and WebService, which extends from a BaseController that includes generic hooks for REST type stuff in terms of $this->getModel()` and use overrides where necessary
Anything else
Although my question is related to Yii, I feel like this must have come up in the past for many developers. I would like to know what you did/what you recommend to move forward. I am concerned that if I choose the wrong approach I will "break MVC" or somehow regret it later.
Note: you should not worry about "breaking the MVC". Since you have chosen to use Yii, that part has already happened.
The root of the problem lays in the fact that your controllers do a lot of stuff (and thus, violating SRP). What you call "controllers' actually contain also the application logic (that should be part of model layer) and UI logic (that normally would be part of view instances).
What you should have there is a single application, with one model layer and two presentations (what you refer to as "web application" and "web service"). The controllers should be a slight a possible.
You should move the application logic to the service layer through which then the presentation layer would interact with model. You would end up with a lot lighter controller. Then you could be able to provide a separate set of controllers/view for each of the presentations that your project needs with no or minor code duplication.
I would recommend against writing multiple controllers. It is a much better option to keep your domain logic in the models, rather than controllers. Your controllers should only act as the gateway to the logic and serve them in whatever form the client requests eg. as a JSON encoded response or through a view. It would be best if you just keep the task of identifying the client requirements and after obtaining the results from the model translating the response in an appropriate form.
This flow can be streamlined with suitable helpers and a well implemented routing sub-system so that detection of client requirements becomes effortless.
eg. /user/subscriptions.html will fetch an html page where as /user/subscriptions.json will fetch a JSON response.

App to App interfacing in Django

We are developing a SaaS that uses a number of quite independent apps that are all currently in the same django project running on the same server.
We know that eventually some of the apps will be relocated to their own server primarily due to differences in server loads. We also believe some of the apps may become resources for new applications as well (the same app instances running in our SaaS).
We are at the point that we should go in an clean up cross app coupling and make rules about a common interface medium. My thoughts are that is should be a restful interface between all apps.
So: Is enforcing a restful interface across all apps a bad idea in the best case scenario for such an argument (all apps on different servers), and worst case scenario (all apps stay on the same server)?
You can take at look at Piston for creating RESTful APIs in Django.

CXF WebService Client generation: Use existing Domain Model classes

I have got a web application which is speparated in a GUI (JSF 2.0, Orchestra, Spring) and service (Spring, JPA, Hibernate,...) project. Due to network issues between the web server and the database server, I neet to split the application completely, between the layers and deploy them on two different tomcats, for the service part close to the database server. I have generated allready a webservice and a webservice-client with the Eclipse WTP CXF Plugin.
My Problem is: For the client it generates a copy of the domain model classes, so I can't use them directly in my gui project and would need to introduce an conversion layer, between the web service client and the gui layer. Wich is cumbersome and error prone.
Is there a possibility to generate the web service client (out of the existing web service module and the wsdl) using the shared domain model (model classes are in an separate project, wich both - service and gui - projects depend on)?
desperatly looking for a solution, as the deployment deadline is close...
To generate a copy of the domain model classes (DTOs) is a good practice when you have two physical layers : Your Hibernate POJOs need to be deproxyfied before being sent to an other physical layer. Maybe you could use Dozer to do it, to avoid to spend too much time doing it.
Maybe you should use RMI instead of Web Services if you need performances.
If you're absolutely determined to use your domain objects in the presentation layer, you should look about Gilead (formerly known as Hibernate4GWT).
Pure DTOs, DTOs with Dozer, and Gilead use are described in details here :
http://code.google.com/intl/fr/webtoolkit/articles/using_gwt_with_hibernate.html

Web vs Desktop Development (Online vs. Smart-Client)

I work at a company with a large SAP investment, and we also have dozens of large .Net systems (mostly internally for engineering systems), and Java platforms (mostly for external web applications). As such, we have large development shops on ABAP, C#, and Java EE.
We have decent standards for which platform to use in which domain, but we don't have a lot of clarity around when to use web UIs and when to use desktop UIs.
I've seen some excellent research on this topic in the past (like this), but I'd like something a little more structured
I'd like to build a decision tree based on best practices to help with this question.
Some of the criteria I've seen in the past include:
Is the application targeted to users
with different OS configurations?
Does the application require OS-type
functionality for sorting and editing
data? (I know that AJAX /
asynchronous JS has made possible
much richer desktop-like
functionality to web applications,
but some would argue the desktop is
still king in this area)
Will a web application be able to
provide the availability,
responsiveness, clarity, and utility
that can be delivered with a desktop
application?
I think we are seeing the separation between Web and desktop applications softened quite a bit. Rich internet applications (with Flex, Silverlight, Ajax) started this trend, and WPF with XBAP is taking the user experience of browser-based applications to another level.
It is becoming a bit more involved to have this argument, because there are now more flavors in the spectrum between Web and desktop apps.
Some more questions to ask:
What is the primary objective of the app - data manipulation, or data viewing?
What is the number of data points/records that need to be viewed/edited together on one screen?
What is the organization's IT infrastructure look like? Will they be able to accomodate new deployment models?
Will users work with a central database from remote locations?
Does the organization have a VPN infrastructure of off-site users, and how do users authenticate?
Are there existing applications that the same user group is working with, and how are these applications deployed?
Does the application need offline capabilities?
Given that they are so different, what is the skill set of the development team for web and desktop APIs?