Hi,
the expected contents of the postData is a xml document. You can add to your
client application sending POST request the ability to read the external xml
document. Find any well formed xml doc and experiment. 
Consider adding to your client:
...

HttpURLConnection connect = null;
try
{
        //read external xml document - m_FileName is the fully qualified
path to your document
        //and m_url contains the endpoint of your call
        
        int size = 16384;
        char[] buffer = new char[size]; 
        BufferedReader inBuf   = new BufferedReader(new
FileReader(m_FileName));
        int offset = 0;
        int length = -1;

        do {
                length = inBuf.read( buffer, offset, size-offset );
                if( length > 0 )
                {
                        offset += length;
                }
        }  while( ( length > 0 )  );

        String postData = new String( buffer,0,offset); 

        URL url = new URL(m_url);
        connect = (HttpURLConnection)url.openConnection();
        System.out.println("Contentlen is " + postData.length());


        // Sets the request method to POST, and enable to send data 
        connect.setRequestMethod("POST"); 
        connect.setAllowUserInteraction(false); 
        connect.setDoOutput(true); 

        // Sets the defaul Content-type and content lenght for POST requests

        connect.setRequestProperty( "Content-type", "text/xml" ); 
        connect.setRequestProperty( "Content-length",
Integer.toString(postData.length())); 

        // Gets the output stream and POSTs data 
        OutputStream POSTStream = connect.getOutputStream(); 
        PrintWriter POSTWriter = new PrintWriter(POSTStream); 
        POSTWriter.println(postData); 
        POSTWriter.flush(); 
        POSTWriter.close(); 

        // Checks the response code 
        int responseCode = connect.getResponseCode(); 
        if (responseCode != HttpURLConnection.HTTP_OK) { 
                System.out.println ("Unable to connect to "+m_url+". (http
error code: "+String.valueOf(responseCode)+")."); 
        } 
        String inputLine; 
        InputStreamReader in = new InputStreamReader
(connect.getInputStream()); 
        BufferedReader reader = new BufferedReader(in); 
        //Reads data 
        while ((inputLine = reader.readLine()) != null) 
                System.out.println(inputLine); 
        in.close(); 
        connect.disconnect(); 
} 
catch (MalformedURLException e) { 
        System.out.println (m_url + " is not a valid URL."); 
        System.exit(1); 
}
catch (IOException e) { 
        System.out.println ("Unable to connect to "+ m_url + "Exception: " +
e.getMessage()); 
        System.exit(1); 
} 



> -----Original Message-----
> From: Joseph Jupin [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 30, 2002 4:36 PM
> To: [EMAIL PROTECTED]
> Subject: Re: problems with StreamGenerator...
> 
> 
> Hi, Kinga...
> 
> Thanx for taking time to talk about this.  But so far, 
> that solution's not working either.  Just a quick question 
> - does the contents of the postData need to be of the form 
> "?foo=data" and does the data segment need to be url 
> encoded?
> 
> I've put your suggestions in and so far, the server hangs 
> - it never responds back - and doesn't even act like it's 
> been queried...  kinda strange...
> 
> again, many thanx...
> 
> peace.  JOe...
> 
> On Wed, 30 Jan 2002 11:11:53 -0800
>   "DZIEMBOWSKI,KINGA (HP-NewJersey,ex2)" 
> <[EMAIL PROTECTED]> wrote:
> >Hi,
> >
> >As a first step you should specify the Content-type HTTP 
> >header.
> >StreamGenerator do not accepts all mime types.
> >connect.setRequestProperty( "Content-type", "text/xml" );
> >
> >As a second the StreamGenerator sample is showing one of 
> >the aspects of
> >StreamGenerator - ability to process the data coming from 
> >the form. I such
> >case it expects the payload to be a value of the "Foo" 
> >parameter. This is
> >not the main reason for existence of this generator. The 
> >main reason is the
> >ability to process POST requests where the payloads is in 
> >InputStream. This
> >is typical scenario for the clients implemented using 
> >HttpURLConnection. (By
> >the way be careful, HttpURLConnection has a bug. If the 
> >response has
> >statusCode >400 you will be unable to retrieve the 
> >response payload,
> >exception is thrown...)
> >
> >The code sample to do that can be similar to:
> >     Assuming you have a xml contents in String postData
> >
> >     connect.setRequestMethod("POST"); 
> >     connect.setAllowUserInteraction(false); 
> >     connect.setDoOutput(true); 
> >
> >     // Sets the default Content-type and content length for 
> >POST
> >requests 
> >     connect.setRequestProperty( "Content-type", "text/xml" 
> >); 
> >     connect.setRequestProperty( "Content-length",
> >Integer.toString(postData.length()));
> >     // Gets the output stream and POSTs data 
> >     OutputStream POSTStream = connect.getOutputStream(); 
> >     PrintWriter POSTWriter = new PrintWriter(POSTStream); 
> >     POSTWriter.println(postData); 
> >     POSTWriter.flush(); 
> >     POSTWriter.close(); 
> >I hope this will help
> >Kinga
> >
> >> -----Original Message-----
> >> From: Joseph Jupin [mailto:[EMAIL PROTECTED]]
> >> Sent: Wednesday, January 30, 2002 12:47 PM
> >> To: [EMAIL PROTECTED]
> >> Subject: problems with StreamGenerator...
> >> 
> >> 
> >> Hey, All...
> >> 
> >> I've been using Cocoon 2.0 for about a month & 1/2 now 
> >>and 
> >> I've run into the following problem:
> >> 
> >> First off, refer to the Order example that comes with 
> >> cocoon which when you hit the submit, it will return the 
> >> xml typed into the textarea.  Now, for testing, I've 
> >>taken 
> >> my xml doc, modified the stream pipeline to use my 
> >> transform and then output html.  Using the same form, 
> >> entered my xml text (cut & Paste from my text file) - 
> >>hit 
> >> submit and it works like a charm - the generated HTML 
> >> comes back after the transform.
> >> 
> >> Now, the problem is in an application I'm writing that 
> >> needs to send the XML data as a parameter call to the 
> >> cocoon server and capture the resulting HTML.  Using the 
> >> URL class and URLConnection class, I have to pass the 
> >> parameter (say "Foo") and the URLEncoder.encode value of 
> >> the parameter (URLEncoder.encode(some text))...  The 
> >> problem is that the stream or cocoon doesn't see the 
> >> parameter passed in.  Any ideas on how to get it to 
> >> understand the URLEncoded parameter.
> >> 
> >> Here's some example code:
> >> 
> >> StringBuffer uri = new 
> >> StringBuffer("http://localhost:8080/cocoon/request1";);
> >> 
> >> try {
> >>     URL url = new URL(uri.toString());
> >>     HttpURLConnection u_connect = 
> >> (HttpURLConnection)url.openConnection();
> >>     u_connect.setRequestMethod("POST");
> >>     u_connect.setDoOutput(true);
> >>     u_connect.setRequestProperty("Foo", 
> >> URLEncoder.encode(some text));
> >> 
> >>     u_connect.connect();
> >> 
> >>     // print out some results...
> >> 
> >> } catch (exceptions...) {}
> >> 
> >> Now, here's some of the output:
> >> 
> >> content length:  12341
> >> content type  :  text/html
> >> content encode:  null
> >> request method:  POST
> >> response code :  500
> >> response mssg :  Internal Server Error
> >> e:java.lang.NullPointerException
> >> 
> >> So, in other words it gets there and then returns the 
> >> nullPointerException afterwards.  Now, remember the text 
> >> is pure XML so that's why it needs encoding - the 
> >> URLConnection nor URL will accept it due to illegal 
> >> characters otherwise...
> >> 
> >> any help would be greatly appreciated...
> >> 
> >> peace.  JOe...
> >> 
> >> 
> >> 
> ---------------------------------------------------------------------
> >> Please check that your question has not already been 
> >>answered in the
> >> FAQ before posting. 
> >><http://xml.apache.org/cocoon/faqs.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/faqs.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/faqs.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/faqs.html>

To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>

Reply via email to