Re: Using Struts with XML-RPC (or JAXB?) [Scanned for known viruses]
Karen - Following is a re-post from a similar thread about a week ago where I laid out one potential solution for this problem - assuming I understand your issue correctly. Following is a description and some code I used for setting up communications between Struts and Axis for SOAP communications. The suammry of this recommendation is: - Post to form bean - Modify form bean design to allow you to extract a 'value object' from it (not XML). - Create a facade class that 'hides' the communications to the remote server. Have it accept the 'value object'. - Inside the 'facade class' have it create the XML from the value object and oversee communications - The Action class simply takes a valid form bean, extracts a value object form it and send it through the facade. In essence, your facade class is a 'model' component that hides any knowledge of the back end from the Action class and form bean. There are files below that you can use to see what I'm talking about. Let me know if you have questions - Kevin Kevin I've attached a few files from my upcoming book Struts Kick Start that provide a basic design pattern that sounds like it may be similar to what your describing. What I do is: - Create a Value Object that encapsulates data communicated with the Model component. - Create a facade class that accepts and returns value objects through 'business methods'. By defining the facade to work at a 'business method' level, it helps keep any code related to a particular persistence layer or back-end system out of the Action class. This also addresses the issues you described of 'designing to test' - the clean seperation between the Action class and the Model components that the Facade provides simplifies testing. - Create the form bean to provide set/get methods that also accept and return value objects - this greatly simplifies the Action class and isolates it from changes. The Action class (a bit simplified - I've taken out detailed comments and exception handling) goes something like: // cast the form bean CustomerForm cf = (CustomerForm) form; // Create a facade to interface to the back-end system CustomerWSFacade facade = new CustomerWSFacade(); // Extract the value object from the form bean CustomerValueObject cvo = cf.getValueObject(); // Pass the value object to the facade. It returns an update value object cvo = facade.addressChange( cvo ); // Use the returned value object to update the values in the form bean. cf.setValueObject(cvo); These particular classes come from the chapter on providing integration with Axis for Web Services. Another chapter uses the identical set of classes to communicate with JBoss using a Session Bean - all I did was write a different facade class. The point of this was to demonstrate a design that made it very simple to perform maintenance or changes on the back-end or persistence layer. Regarding testing - I'd recommend you take a look at the StrutsTestCase project at sourceforge - it provides some great templates for both JUnit and Cactus tests that are designed for Struts. Makes JUnit/Cactus testing pretty straightforward. A copy of this and detailed directions also come with the book. http://strutstestcase.sourceforge.net/ Best of luck - Kevin Author, Struts Kick Start (See attached file: customer.zip) Karen Choi <[EMAIL PROTECTED]> on 10/21/2002 06:41:59 PM Please respond to "Struts Users Mailing List" <[EMAIL PROTECTED]> To:[EMAIL PROTECTED] cc: (bcc: Kevin Bedell/Systems/USHO/SunLife) Subject:Using Struts with XML-RPC (or JAXB?) I am stuck on a rather vexing Struts problem... It sounds simple enough. I need to read some values from a form bean, then parse those values into a valid xml document (must conform to schema I've been provided with) then send that document to a defined service endpoint (another servlet). I know how to do this the "normal" way, but I can't seem to figure out how to do it with Struts. Would I be able to use JAXB, and create an XML representation of my form bean, which could be sent to the servlet, or is there another approach that I am not aware of. Any help or suggestions would be greatly appreciated. - Do you Yahoo!? Y! Web Hosting - Let the expert host your web site --- This e-mail message (including attachments, if any) is intended for the use of the individual or entity to which it is addressed and may contain information that is privileged, proprietary , confidential and exempt from disclosure. If you are not the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the se
Re: Using Struts with XML ?
Hi Denis, I'm pretty new to struts myself, but it sounds like you could use action form as a container for your value objects and route to JSPs that understand which bits of XML are needed to assemble the final output and to do the compilation (maybe using a tag library to access your XSLT Stylesheet Factory/Cache) Another way would be to include enough information about what stylesheet to use in your value objects such that you could use a global forward to single servlet that simply reads the value objects to produce XML and does the XSL transformation. Servlet filters would also work...I've been looking at servlet filters myself... If I return an String representation of an XML document, I have to pay the cost of converting it to a DOM tree. If I build a DOM tree to begin with then I don't have to pay that cost. If I use a servlet filter, I think we'd have to pay that cost because (if I'm not incorrect, the servlet filter would expect to work off the response, i.e., the output stream) One way to cut down on processor cycles that works (in theory) is to do browser id to determine if the client is XSLT-aware. IE 4&5 and to a lesser degree, NS 6.1 all support XSLT processing on the client side. It might be interesting to look at pushing off the work of XSL transformation to the client in cases where the client is XSLT-aware. The ultimate problem is that when we use XSLT, some of the benefit of using struts vaporizes in that it is a much tricker to make good use of the tag libraries. I'm not sure where we are going to come down on this issue, but it may be that it is simply a better fit time-wise for us to use struts-enhanced JSPs for now. I dunno yet. --Michael Denis Goeury wrote: > Hi Michael, > > Our application is also based on EJBs. In our case, the business layer can > provide standard Value Objects (through a Session Facade) or their XML > representation. All those XML parts are put together in View objects to > construct our proprietary DOM tree. After that the XSL transformation is > applied and returns the HTML content in a ServletResponse. > > The problem with our current presentation layer is that the control logic is > managed by many different servlets and is therefore very difficult to > maintain. There is also a lot of 'cut & paste' code in those servlets > because there was no concept of ActionForms and Action objects. We would > also like to define the navigation in an XML descriptor instead of putting > it inside the servlets (that's what struts-config.xml does). > > For the transformation, I was also thinking about using a Filter servlet to > transform the XML to HTML and decouple it from the main application. But for > that we need to move to WebLogic 6.1 to get the servlet API 2.3. > > That's what we have now... > > Denis. > > -Original Message- > From: Michael Baldwin [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, October 02, 2001 12:24 PM > To: [EMAIL PROTECTED] > Subject: Re: Using Struts with XML ? > > Denis, > I'm looking at the a similar problem for a new system. I'd very much like > to > apply XSLT to the result. > I'm considering using struts Actions to interact with an EJB layer that will > produce value objects. > I'm thinking then about forwarding on the request to a JSP that understands > how > to transform these value objects into a DOM tree and then uses a XSLT > Transformer to do the real work. > > >From what I can tell, this path has not been well tread using struts, so > I'm > still looking at options. > > How are you currently going about XML document generation and XSLT template > application? Is it all servlet managed? I'd be interested to hear. > > --Michael
Re: Using Struts with XML ?
Ravi had some notes about this here: http://www.mail-archive.com/struts-user@jakarta.apache.org/msg15849.html At Jakarta, we use Ant to build our HTML pages from XML and XSL. See the Struts source distribution for an example. I haven't tried it, but I keep thinking it would be interesting to do the same with JSPs. This would gives you the flexibility of XML,XLS without changing how you write your applications (e.g. custom tags), or incurring the overhead of the runtime transformations. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel +1 716 737-3463 -- http://www.husted.com/about/struts/ Denis Goeury wrote: > > Hi, > > I am currently in the process of evaluating Struts to rewrite our > presentation layer. For now, I think it provides almost all the support we > need (except for multipage forms) but its JSP oriented model is a kind of > limitation for us. That's because our current presentation layer is done by > using XML documents and XSL templates and we want to keep those > technologies. > > To fix this issue I was thinking about creating one servlet that could be in > charge of creating the XML pages. This servlet would receive requests (from > the RequestDispatcher) like /checkout.xml and construct the Checkout XML > document. With this approach we will probably loose the support provided by > TagLibs. > > Is there a better solution? What about XTags Taglib? > > Thanks a lot for all the ideas you can give me, > > Denis Goeury.
RE: Using Struts with XML ?
Hi Michael, Our application is also based on EJBs. In our case, the business layer can provide standard Value Objects (through a Session Facade) or their XML representation. All those XML parts are put together in View objects to construct our proprietary DOM tree. After that the XSL transformation is applied and returns the HTML content in a ServletResponse. The problem with our current presentation layer is that the control logic is managed by many different servlets and is therefore very difficult to maintain. There is also a lot of 'cut & paste' code in those servlets because there was no concept of ActionForms and Action objects. We would also like to define the navigation in an XML descriptor instead of putting it inside the servlets (that's what struts-config.xml does). For the transformation, I was also thinking about using a Filter servlet to transform the XML to HTML and decouple it from the main application. But for that we need to move to WebLogic 6.1 to get the servlet API 2.3. That's what we have now... Denis. -Original Message- From: Michael Baldwin [mailto:[EMAIL PROTECTED]] Sent: Tuesday, October 02, 2001 12:24 PM To: [EMAIL PROTECTED] Subject: Re: Using Struts with XML ? Denis, I'm looking at the a similar problem for a new system. I'd very much like to apply XSLT to the result. I'm considering using struts Actions to interact with an EJB layer that will produce value objects. I'm thinking then about forwarding on the request to a JSP that understands how to transform these value objects into a DOM tree and then uses a XSLT Transformer to do the real work. >From what I can tell, this path has not been well tread using struts, so I'm still looking at options. How are you currently going about XML document generation and XSLT template application? Is it all servlet managed? I'd be interested to hear. --Michael
Re: Using Struts with XML ?
Denis, I'm looking at the a similar problem for a new system. I'd very much like to apply XSLT to the result. I'm considering using struts Actions to interact with an EJB layer that will produce value objects. I'm thinking then about forwarding on the request to a JSP that understands how to transform these value objects into a DOM tree and then uses a XSLT Transformer to do the real work. >From what I can tell, this path has not been well tread using struts, so I'm still looking at options. How are you currently going about XML document generation and XSLT template application? Is it all servlet managed? I'd be interested to hear. --Michael Denis Goeury wrote: > Hi, > > I am currently in the process of evaluating Struts to rewrite our > presentation layer. For now, I think it provides almost all the support we > need (except for multipage forms) but its JSP oriented model is a kind of > limitation for us. That's because our current presentation layer is done by > using XML documents and XSL templates and we want to keep those > technologies. > > To fix this issue I was thinking about creating one servlet that could be in > charge of creating the XML pages. This servlet would receive requests (from > the RequestDispatcher) like /checkout.xml and construct the Checkout XML > document. With this approach we will probably loose the support provided by > TagLibs. > > Is there a better solution? What about XTags Taglib? > > Thanks a lot for all the ideas you can give me, > > Denis Goeury.