• Post Reply Bookmark Topic Watch Topic
  • New Topic

A design pattern for web services?

 
Rob Wehrstein
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying learn more about architectural patterns for web applications. The examples that come with Tomcat don't seem to demonstrate this aspect of software development so well. Is there a place where I can find good information on this topic?

A specific problem I'm trying to solve by using JSP/JSTL/Servlets/Java/etc is the following:

1) given the coupled input variables A and B (in URL string or POST data), generate coupled variables C and D.
2) given A, B, C, and D, generate the data, E, that needs to be displayed to the user
3) given C, D and E, display the page

Note: It is possible to combine some of the steps, but I've found that separating them can sometimes lead to cleaner code that separates the logic from the visual presentation.

I can do this with a Servlet, but I have to read in fragments of HTML and parse strings. It works okay, but it just looks messy to me. Is there a better design pattern, or a better approach, that I should be using?

 
Marcus Biel
Ranch Hand
Posts: 51
IntelliJ IDE Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your description is rather abstract, so I am not sure if I understood your request, what I did understand is you are looking for architectural design patterns for web application,
and you described the general flow of how a request is processed and a response generated.

Regarding this there are 2 design patterns coming to my mind - mvc - which I would call deprecated, and Hexagonal architecture.
In short, the idea behind Hexagonal architecture is to hide complexity behind interfaces and layers, and to protect the business logic (domain) from all the infrastructural mess.

Actually I have done a video talk about hexagonal architecture, which should explain it in detail:
Hexagonal Architecture Video


Hope that helps!

Marcus

 
Tim Holloway
Bartender
Posts: 18417
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcus Biel wrote:... mvc - which I would call deprecated


I wouldn't. JavaServer Faces is an integral part of the JEE spec and it's about as pure an implementation of MVC as you'll find on a web framework. Struts continues to be popular and it's Model 2, which is a less-complete form of MVC. That's not even counting countless apps doing their own MVC with servlet/JSP combos. Or frameworks such as Cocoon.

However, since the question had to do specifically with design patterns for Web Services, MVC isn't and never was appropriate for Web Services. MVC is about maintaining a GUI mapping to a data model and Web Services by definition are non-GUI services.

I don't know any specific design patterns for Web Services. Although I'm inclined to think of Web Services as themselves a pattern. Or at least a paradigm (MVC isn't technically a "pattern", either in that respect). There are a couple of documents available on the Web for JEE/J2EE design patterns in general, and a web service is very likely to be implemented in terms of them.

Tomcat's docs don't describe any patterns, since Tomcat is only a container and it's left up to you how to design and implement web applications. Insofar as it supports patterns it is doing so only in the sense that any webapp container does and not specifically just Tomcat.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest, I think that the OP may be conflating the terms web services and web apps. Hard to tell.

In any case, MVC is far from being generally considered deprecated.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However, since the question had to do specifically with design patterns for Web Services, MVC isn't and never was appropriate for Web Services. MVC is about maintaining a GUI mapping to a data model and Web Services by definition are non-GUI services.


I take exception to that statement.

Note that in a RESTful architecture, a request can specify a variety of headers which correspond to a view, such as Accept, Content-Type and Accept-Encoding.

For example, you might request a resource as text, html, a csv stream, audio stream or a JSP image. This is one of the strengths of a RESTful architecture.

It would be up to the Controller to hand the Model to the right View generator for the request.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before we spiral down a rathole of patterns for web services versus that for web applications, perhaps we should find out from the OP which was meant?

Rob Wehrstein, can you comment?
 
Rob Wehrstein
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Before we spiral down a rathole of patterns for web services versus that for web applications, perhaps we should find out from the OP which was meant?


I actually, I meant web applications.
 
Rob Wehrstein
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I managed to solve this problem and get a reasonably clean separation of logic and visual display.

1) The user calls the servlet.
2) The servlet analyzes the variables in the request, generates new data, and then forwards the request to a JSP page.
3) The JSP decides among a small number of rendering options, and then renders the page.
4) When the user makes a new request, the JSP page refers back to the servlet.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be interested to read this article.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!