Re: Combining Cocoon and Struts
Dag, just looking at your sample below again ... given that you are using Castor XML to convert an object hierarchy to XML (which you then forward to Cocoon in some way), why not look into the CastorTransformer that generates SAX events based on an object bound to the request/sesion/context and a mapping file. You can actually find samples within the Cocoon distribution, and to be honest, that's exactly where we will be moving in the near future if I can get my head around a small problem. Werner Dag Nygaard wrote: Werner Guttmann wrote: > We have been using both of the following two options to establish a clean contract > between Struts and Cocoon: > > - Use of XMLizable interface from within XSPs > - Use of Castor XML > > In both cases, you would use Struts actions to go to the model and return you the > data and bind it to a the HttpRequest/HttpSession. From there on, simply forward > your request to a Cocoon pipeline which takes care of the (de)marshalling required > to convert your object model to SAX events which are then processed further > downstream. > > I hope this helps. > Werner Thanks to all of you who previous replied to my question! Alot of "floating objects" became clearer. Werner, I think I know what you are saying, in a broad sense. But since I am not that drilled in Cocoon and Struts yet, I hope you (or somebody else?) could assist us in the right directions a little bit more... Note: We have already looked at a sucessful Struts-Cocoon combination where Struts creates a xml-file and forwards control to a Cocoon pipeline. OK, for research, but not for multiuser environment... :) Given a new pipeline: map:match pattern="myrequest"> map:generate type="request"/> map:transform src="stylesheets/myrequest.xsl"/> map:serialize/> /map:match> "borrowed" from the example in http://marc.theaimsgroup.com/?l=xml-cocoon-usersm=100349922300307w=2 How should do I do it in my HelloActionSX.java file? The code below is from the version were we write the xml to a file between Struts and Cocoon, slightly modified... The form contains two string-fields and a submit button. The form entries are collected and written with appropriate xml-tags, to the temp-file. Struts sends control to the Cocoon-pipeline, which prestents the entries on a new page. Should we marshal the request in the same way that we marshal the form? Previously we used a FileWriter as ContentHandler-paramameter to the marshal-construct. What should we use for the request, SAXContentHandler? Or, do we somehow just push out the request directly to the Cocoon-pipeline? Struts-code: public class HelloActionSX extends AbstStrutsActionBase { public ActionForward perform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { // Where to go next ActionForward actionForward = null; HelloForm helloForm = (HelloForm) form; // get the form bean // Do something with the form - i.e. extract the values String firstname = helloForm.getFirstName(); String lastname = helloForm.getLastName(); //-- load mapping //-- marshal the form Mapping myMapping = new Mapping(); // FileWriter writer = new FileWriter("tempfile.xml"); *** How do we replace writer? With SAXContentHandler? with unmodified request, i.e. convert the request in Cocoon? * Marshaller marshaller = new Marshaller(writer); try { myMapping.loadMapping(".../mapping.xml"); marshaller.setMapping(myMapping); marshaller.marshal(helloForm); } catch ( MarshalException me) { System.out.println("MarshalException: " + me.getMessage() ); } catch ( ValidationException ve ) { System.out.println("ValidationException: " + ve.getMessage() ); } catch ( MappingException mapEx) { mapEx.printStackTrace(); System.out.println("MappingException: " + mapEx.getMessage() ); } finally { //writer.close(); } actionForward = mapping.findForward("hello"); return actionForward; } } -- Dag - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html> To unsubscribe, e-mail: [EMAIL PROTECTED]> For additional commands, e-mail: [EMAIL PROTECTED]>
Re: Combining Cocoon and Struts
Werner Guttmann wrote: We have been using both of the following two options to establish a clean contract between Struts and Cocoon: - Use of XMLizable interface from within XSPs - Use of Castor XML In both cases, you would use Struts actions to go to the model and return you the data and bind it to a the HttpRequest/HttpSession. From there on, simply forward your request to a Cocoon pipeline which takes care of the (de)marshalling required to convert your object model to SAX events which are then processed further downstream. I hope this helps. Werner Thanks to all of you who previous replied to my question! Alot of floating objects became clearer. Werner, I think I know what you are saying, in a broad sense. But since I am not that drilled in Cocoon and Struts yet, I hope you (or somebody else?) could assist us in the right directions a little bit more... Note: We have already looked at a sucessful Struts-Cocoon combination where Struts creates a xml-file and forwards control to a Cocoon pipeline. OK, for research, but not for multiuser environment... :) Given a new pipeline: map:match pattern=myrequest map:generate type=request/ map:transform src=stylesheets/myrequest.xsl/ map:serialize/ /map:match borrowed from the example in http://marc.theaimsgroup.com/?l=xml-cocoon-usersm=100349922300307w=2 How should do I do it in my HelloActionSX.java file? The code below is from the version were we write the xml to a file between Struts and Cocoon, slightly modified... The form contains two string-fields and a submit button. The form entries are collected and written with appropriate xml-tags, to the temp-file. Struts sends control to the Cocoon-pipeline, which prestents the entries on a new page. Should we marshal the request in the same way that we marshal the form? Previously we used a FileWriter as ContentHandler-paramameter to the marshal-construct. What should we use for the request, SAXContentHandler? Or, do we somehow just push out the request directly to the Cocoon-pipeline? Struts-code: public class HelloActionSX extends AbstStrutsActionBase { public ActionForward perform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { // Where to go next ActionForward actionForward = null; HelloForm helloForm = (HelloForm) form; // get the form bean // Do something with the form - i.e. extract the values String firstname = helloForm.getFirstName(); String lastname = helloForm.getLastName(); //-- load mapping //-- marshal the form Mapping myMapping = new Mapping(); // FileWriter writer = new FileWriter(tempfile.xml); *** How do we replace writer? With SAXContentHandler? with unmodified request, i.e. convert the request in Cocoon? * Marshaller marshaller = new Marshaller(writer); try { myMapping.loadMapping(.../mapping.xml); marshaller.setMapping(myMapping); marshaller.marshal(helloForm); } catch ( MarshalException me) { System.out.println(MarshalException: + me.getMessage() ); } catch ( ValidationException ve ) { System.out.println(ValidationException: + ve.getMessage() ); } catch ( MappingException mapEx) { mapEx.printStackTrace(); System.out.println(MappingException: + mapEx.getMessage() ); } finally { //writer.close(); } actionForward = mapping.findForward(hello); return actionForward; } } -- Dag - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Combining Cocoon and Struts
Hi Dag ! Does your Struts work standalone without Cocoon's part ? if not, you have to check correctness of your sample webapp. I studied Struts before Cocoon, and you can dig for info there : [EMAIL PROTECTED] You also can read this document : http://stealthis.athensgroup.com/presentations/Model_Layer_Framework/Struts_ Whitepaper.pdf Struts is fun but I am not sure whether using it with Cocoon is a good idea... You may study in-depth each of the frameworks, as I did (but in French...) and do some comparison tables. Hoping I am not too wrong, Babs - Original Message - From: Dag Nygaard [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, September 30, 2002 1:13 PM Subject: Combining Cocoon and Struts There are a lot of questions raised around Cocoon and Struts, but few (if any) answers of how to combine the two - FAQ-food?. I am now in the process of attempting the combination and not being very knowledgeable in either Cocoon, Struts, JSP, I feel at times pretty lost. Could someone help me out? The setup is as follows on a Win2K platform: I have deployed Cocoon 2.0.3 in tomcat 4.0.4 environment, i.e. placed the cocoon.war file in the $CATALINA_HOME/webapps/ directory. The welcome-page, http://localhost:8080/cocoon, confirms that Cocoon and Tomcat function OK together. A Cocoon-testapplication resides on $CATALINA_HOME/webapps/cocoon/myapp/, xml- and xsp-docs in subdirectory resources/ and stylesheets (xsl) in subdirectory styles/. A Hello_user.xml with matching hello_user.xsl pipeline functions OK. To test a similar Struts setup, we have created a new application subdirectory myjspapp, under cocoon/ in which Struts' WEB-INF/-directory reside with: - compiled classes in subdirectories/files - for both Actions and Forms - modified files struts-config.xml and other struts-*.tld-files, web.xml-file - lib/-directory with castor-0.9.3.21.jar, castor-0.9.3.21-xml.jar and struts.jar. Note: I have also copied these jar-files to cocoon/WEB-INF/lib/ - src/-directory. A Hello_user.jsp-file (with a Hello_user.html-file) reside in the root of myjspapp uses the abovementioned hello_user.xsl-file. The pipeline I attempt to use looks like this: map:pipeline map:match pattern=hellojsp map:generate src=myjspapp/hello_user.jsp type=jsp/ map:transform src=myapp/styles/hello_user.xsl/ map:serialize type=html/ /map:match This setup fails. The errormessage I get is: org.apache.cocoon.ProcessingException: ServletException in JspGenerator.generate(): javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection My guess is that the Struts-parts require access/setup of the struts-config.xml-file, but how do I do that? Is there something I should setup in Cocoon's cocoon.xconf-file or Cocoon's web.xml-file? -- Dag Nygaard [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Etudiant: Wanadoo t'offre le Pack eXtense Haut Débit soit 150,92 euros d'économies ! Et pour 1 euro de plus, reçois le CD-ROM du jeu Dark Age of Camelot + 1 mois de jeu en réseau offert ! Clique ici : http://www.ifrance.com/_reloc/mail.etudiant - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Combining Cocoon and Struts
Barbara Post wrote: Hi Dag ! Does your Struts work standalone without Cocoon's part ? if not, you have to check correctness of your sample webapp. Yes. As I wrote, I believe the problem is in Cocoon releasing it's control to Struts, but I can't figure out how. I studied Struts before Cocoon, and you can dig for info there : [EMAIL PROTECTED] I have attempted this... You also can read this document : http://stealthis.athensgroup.com/presentations/Model_Layer_Framework/Struts_ Whitepaper.pdf Allright paper, but I need primarily help in the setup... Struts is fun but I am not sure whether using it with Cocoon is a good idea... You may study in-depth each of the frameworks, as I did (but in French...) and do some comparison tables. I would have prefered a Cocoon-only environment, but for political reasons, we have to try a combination first. Previous poster has also described such a pipeline without describing the setup, and we want to see if there is a gain in the combination. Hoping I am not too wrong, Babs Dag - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Combining Cocoon and Struts
From: Dag Nygaard [mailto:[EMAIL PROTECTED]] There are a lot of questions raised around Cocoon and Struts, but few (if any) answers of how to combine the two - FAQ-food?. I am now in the process of attempting the combination and not being very knowledgeable in either Cocoon, Struts, JSP, I feel at times pretty lost. Could someone help me out? Let's try. (Selfreminder: create Cocoon-Struts comparison samples/articles/FAQs) The setup is as follows on a Win2K platform: I have deployed Cocoon 2.0.3 in tomcat 4.0.4 environment, i.e. placed the cocoon.war file in the $CATALINA_HOME/webapps/ directory. The welcome-page, http://localhost:8080/cocoon, confirms that Cocoon and Tomcat function OK together. Good. A Cocoon-testapplication resides on $CATALINA_HOME/webapps/cocoon/myapp/, xml- and xsp-docs in subdirectory resources/ and stylesheets (xsl) in subdirectory styles/. A Hello_user.xml with matching hello_user.xsl pipeline functions OK. To test a similar Struts setup, we have created a new application subdirectory myjspapp, under cocoon/ in which Struts' WEB-INF/-directory reside with: Do you mean that you have this structure: webapps/cocoon/myjspapp/WEB-INF? If yes, then it's definitely incorrect if you didn't alter the server.xml (in Tomcat/conf) to that subdirectory as an application context (which can be not allowed, anyway). - compiled classes in subdirectories/files - for both Actions and Forms - modified files struts-config.xml and other struts-*.tld-files, web.xml-file - lib/-directory with castor-0.9.3.21.jar, castor-0.9.3.21-xml.jar and struts.jar. Note: I have also copied these jar-files to cocoon/WEB-INF/lib/ - src/-directory. You should use the same WEB-INF directory both for Cocoon and Struts and also take a look at the web.xml and make sure that you have desired servlet mappings. Struts by default is mapped to *.do and Cocoon is mapped to /* and *.jsp. Remove mapping to JSP from Cocoon and try again. Note, that if you call JSP directly then it won't be processed by Struts, only *.do (or whatever you configure in web.xml) URLs are went through Struts. A Hello_user.jsp-file (with a Hello_user.html-file) reside in the root of myjspapp uses the abovementioned hello_user.xsl-file. The pipeline I attempt to use looks like this: map:pipeline map:match pattern=hellojsp map:generate src=myjspapp/hello_user.jsp type=jsp/ map:transform src=myapp/styles/hello_user.xsl/ map:serialize type=html/ /map:match This setup fails. The errormessage I get is: org.apache.cocoon.ProcessingException: ServletException in JspGenerator.generate(): javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection My guess is that the Struts-parts require access/setup of the struts-config.xml-file, but how do I do that? Is there something I should setup in Cocoon's cocoon.xconf-file or Cocoon's web.xml-file? It's configured in the web application deployment descriptor: WEB-INF/web.xml as ActionServlet init params. Hope this helps a little. Konstantin -- Dag Nygaard [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Combining Cocoon and Struts
Dag, I would have prefered a Cocoon-only environment, but for political reasons, we have to try a combination first. Previous poster has also described such a pipeline without describing the setup, and we want to see if there is a gain in the combination. I am facing a similar situation here, but with Cocoon 2.1 still being in dev mode, I guess using Cocoon and Struts together is a viable option. We have been doing this for 1.5 yrs now, and there's a couple of options to consider for the contract between the two frameworks. Generally, we use Struts and JSPs for any form processing (incl. validation) and Cocoon for processing data and rendering it to various output formats. We have been using both of the following two options to establish a clean contract between Struts and Cocoon: - Use of XMLizable interface from within XSPs - Use of Castor XML In both cases, you would use Struts actions to go to the model and return you the data and bind it to a the HttpRequest/HttpSession. From there on, simply forward your request to a Cocoon pipeline which takes care of the (de)marshalling required to convert your object model to SAX events which are then processed further downstream. I hope this helps. Werner Hoping I am not too wrong, Babs Dag - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]