How to Use Struts with a Web Service


The title of this section is a bit misleading. It seems to imply that there might be a single best way of using Struts with a Web Service. This isn't the case. There are many options that could make sense based on your specific environment and application. However, that being said, this chapter provides a specific recommended approach.

This recommended approach is illustrated in the sample application presented in the next section. But first, here are some key points to the design:

  • The Web Service is called from the Action class. The need to manage Exception s and to coordinate different views based on the Web Service response makes the Action class the appropriate place for calling the Web Service.

  • A value object is used to transfer data to and from the Web Service. Value objects are simple JavaBeans that are used to hold properties as a group . The benefit of using value objects is that doing so enables you to send data to the Web Service "one bean at a time" instead of "one property at a time." This makes the communications much more efficient and simplifies processing in the Action class.

  • Details of the Web Service communications are hidden using a facade pattern. A facade is nothing more than a class designed to expose an easy-to-use set of methods while hiding complex code inside. A facade can hide access with a single Web Service or it might manage communications with more than one. As you'll see in the sample application, applying a facade greatly simplifies both development and maintenance of your Action class.

If you read the previous chapter regarding integration of EJBs with Struts, this should all sound familiar. In fact, you'll see that the sample applications in these two chapters are virtually identical except that the facade class developed in the previous chapter is replaced with a different facade class.

By isolating the communications in the Action class and using a facade class to hide the implementation details, the design itself has actually been validated ! The entire back-end system has changed, but the only portion of the Struts code that has to be modified is a single facade class!

In reality, it's not quite that simple and you'll still need to understand how to implement things on the server side. But the point remains that this design is solid and could be used as the basis for a larger, production application.



Struts Kick Start
Struts Kick Start
ISBN: 0672324725
EAN: 2147483647
Year: 2002
Pages: 177

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net