You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Uwe Gerger <Uw...@bmw.de> on 2003/07/28 12:45:08 UTC

[Solution] Re: Example with StreamGenerator

Hello Charlene,
thank you for your example. I've tried another way (to send the data via
POST from my servlet), and here ist the solution:

in your servlet send the data via POST (sContent contains the stream):

      StringBuffer data = new StringBuffer("myContent=" + sContent);
      String urlString =
"http://127.0.0.1:8080/BeanConnection2/cocoon/streamtest.xml";
      

      System.out.println("urlString=" + urlString);

      DataOutputStream streamOut = null;
      DataInputStream streamIn = null;
      

      try
      {
         URL url = new URL(urlString);
         HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
         connection.setDoInput(true);
         connection.setDoOutput(true);
         connection.setUseCaches(false);
         connection.setRequestMethod("POST");

         connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");

         // send request
         streamOut =
            new DataOutputStream(
               new
java.io.BufferedOutputStream(connection.getOutputStream()));

         streamOut.writeBytes(data.toString());
         streamOut.flush();
         streamOut.close();
         streamOut = null;

         // Set content type and size
         String contentType = connection.getContentType();
         int size = connection.getContentLength();
         response.setContentLength(size);

         // Copy the data from in to out
         InputStream in = connection.getInputStream();
         OutputStream out = response.getOutputStream();
         byte[] ba = new byte[8192];
         int bytesRead;
         // Read until no more bytes are available (-1 is returned).
         while ((bytesRead = in.read(ba)) != -1)
            out.write(ba, 0, bytesRead);
         in.close();
         out.close();
     } catch(...)
     {}

In the sitemap you have to configure the stream generator:
		<map:pipeline>
			<map:match pattern="**streamtest.xml">
				<map:generate type="stream">
					<map:parameter name="form-name" value="myContent"/>
        		        </map:generate>
				<map:serialize type="xml"/>
			</map:match>	
		</map:pipeline>

Thanks
	Uwe



Charlene.Yan@thomsonlearning.com schrieb:
> 
> I did something similar.  But I used Struts instead of a servlet.  Struts is a servlet too.  My Struts application and cocoon  are two parallel entries in tomcat's web apps.  Basically in your servlet you should forward it to a page like the following:
> This page will not show in your browser.  It is doing a submit to cocoon pipeline with xml string as a form hidden field.  Cocoon will take it just like the StreamGenerator example and can do all kinds of things with it.  In my case, I created an Excel report, a rtf report and send email with rtf report as attachment.
> 
> Hope this helps.
> 
> Charlene
> 
> <html>
> <head>
> <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <title>Email Report</title>
> </head>
> <body onLoad="document.PostXML.submit();">
>     <%@ page buffer="5" autoFlush="true" %>
>     <%
>       response.setHeader("Cache-Control", "no-cache");
>       response.setHeader("Pragma", "no-cache");
>       response.setHeader("Expires", "Thu, 29 Oct 2000 17:04:19 GMT");
>       try {
>     %>
>       <form method="post" name="PostXML" action="http://localhost:8080/cocoon/samples/mail/sendmail/">
>         <input type="hidden" name="Foo" value="YOUR XML STRING HERE" />
>         </form>
>     <%
>       } catch(Exception e) {
>       e.printStackTrace();
>     %>
>     <h2>
>       <center>
>         <font color='red'>ERROR:</font>
>         This page can not be accessed directly!
>       </center>
>     </h2>
>     <%
>       }
>     %>
>   </body>
> </html>
> 
> 
> 
> 
> -----Original Message-----
> From: Uwe Gerger [mailto:Uwe.Gerger@bmw.de]
> Sent: Thursday, July 24, 2003 8:53 AM
> To: users@cocoon.apache.org
> Subject: Re: Example with StreamGenerator
> 
> Hello Upayavira,
> what I need is to send a XML stream via POST from a Java servlet to
> Cocoon in order to use the stream generator!
> 
> The XML stream is a String and I don't know what I have to do! Should I
> append the string to the URL so that it looks like this:
> localhost:8080/cocoon/test.xml<?xml version="1.0"><test></test> ????
> 
> Thanks in advance for any help
>         Uwe
> 
> uv@upaya.co.uk schrieb:
> >
> > Uwe,
> >
> > Can you explain what your need is? Then we can see if we can find the
> > best solution for you.
> >
> > Regards,
> >
> > Upayavira
> >
> > On Thu, 24 Jul 2003 14:17:59 +0200, "Uwe Gerger" <Uw...@bmw.de>
> > said:
> > > Do you mean the URL of the java servlet (in my case)? And then, what
> > > does cocoon do?
> > >
> > > Thanks
> > >       Uwe
> > >
> > >
> > >
> > > brunopierre4@yahoo.fr schrieb:
> > > >
> > > > why not sending to cocoon the url of the asp which generate your xml?
> > > >
> > > > > does the stream generator only works with POST?
> > > > >
> > > > > If yes, I don't know how to do this from a java servlet. Should I append
> > > > > the xml stream to the URL so that it looks like this:
> > > > > localhost:8080/cocoon/test.xml<?xml version="1.0"
> > > > > encoding="UTF-8"?><test></test>
> > > > >
> > > > > How did you do it in your ASP site?
> > > > >
> > > > > Thanks
> > > > > Uwe
> > > > >
> > > > > uv@upaya.co.uk schrieb:
> > > > > >
> > > > > > Uwe,
> > > > > >
> > > > > > > i'm would like to use the StreamGenerator in my application. For this
> > > > I
> > > > > > > searched for an example in my Cocoon 2.0.4 distribution, but without
> > > > > > > success! Can anybody help me?
> > > > > >
> > > > > > I cannot help you with an example, but I can tell you that I did build a
> > > > > > working site that uses it in a total of 15 minutes.
> > > > > >
> > > > > > An ASP based site built an XML object and sent it by HTTP POST to the
> > > > > > cocoon server. The Cocoon pipeline started with a stream generator and
> > > > > > followed it by a SourceWritingTransformer which wrote the body of the
> > > > > > post to an XML file on disc.
> > > > > >
> > > > > > The stream generator just outputs the XML that was sent as the body of
> > > > > > POST. There's not much more to it than that.
> > > > > >
> > > > > > Regards, Upayavira
> > > > > >
> > > > > > ---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > > > > > For additional commands, e-mail: users-help@cocoon.apache.org
> > > > >
> > > > > --
> > > > > Uwe Gerger                                _/_/_/   _/    _/  _/    _/
> > > > > BMW AG, TG-53 IT-Technologie             _/   _/  _/_/_/_/  _/    _/
> > > > > 80788 Muenchen                          _/_/_/   _/ _/ _/  _/ _/ _/
> > > > > Tel: +49 89 382 35687                  _/   _/  _/    _/  _/_/_/_/
> > > > > Fax: +49 89 382 49040                 _/_/_/   _/    _/  _/    _/
> > > > > mailto:Uwe.Gerger@bmw.de
> > > > >
> > > > >
> > > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > > > > For additional commands, e-mail: users-help@cocoon.apache.org
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > > > For additional commands, e-mail: users-help@cocoon.apache.org
> > >
> > > --
> > > Uwe Gerger                                _/_/_/   _/    _/  _/    _/
> > > BMW AG, TG-53 IT-Technologie             _/   _/  _/_/_/_/  _/    _/
> > > 80788 Muenchen                          _/_/_/   _/ _/ _/  _/ _/ _/
> > > Tel: +49 89 382 35687                  _/   _/  _/    _/  _/_/_/_/
> > > Fax: +49 89 382 49040                 _/_/_/   _/    _/  _/    _/
> > > mailto:Uwe.Gerger@bmw.de
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > > For additional commands, e-mail: users-help@cocoon.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> 
> --
> Uwe Gerger                                _/_/_/   _/    _/  _/    _/
> BMW AG, TG-53 IT-Technologie             _/   _/  _/_/_/_/  _/    _/
> 80788 Muenchen                          _/_/_/   _/ _/ _/  _/ _/ _/
> Tel: +49 89 382 35687                  _/   _/  _/    _/  _/_/_/_/
> Fax: +49 89 382 49040                 _/_/_/   _/    _/  _/    _/
> mailto:Uwe.Gerger@bmw.de
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org

-- 
Uwe Gerger                                _/_/_/   _/    _/  _/    _/
BMW AG, TG-53 IT-Technologie             _/   _/  _/_/_/_/  _/    _/
80788 Muenchen                          _/_/_/   _/ _/ _/  _/ _/ _/
Tel: +49 89 382 35687                  _/   _/  _/    _/  _/_/_/_/
Fax: +49 89 382 49040                 _/_/_/   _/    _/  _/    _/
mailto:Uwe.Gerger@bmw.de


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org