You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Per Kreipke <pe...@onclave.com> on 2000/09/07 23:06:01 UTC

Cocoon and HTTP POST

Newbie Q:
I'm wondering if Cocoon can handle POSTS as well as GETs. Which sample would
I look at?

Per.


RE: Cocoon and HTTP POST

Posted by Per Kreipke <pe...@onclave.com>.
> >It does, it does. Thanks for the XSP/XSLT hints!
> >
> >Let me ask a follow up question. Suppose the POST content type wasn't
> >"application/x-www-form-urlencoded" (e.g. not form elements).
> >
> >Specifically, suppose it was "text/xml", how would you recommend
> going about
> >implementing processing the contents and spitting back an XML
> reply? E.g. a
> >messaging framework:
> >
> >>From client:
> ><request>
> > <content>This is my message</content>
> ></request>
> >
> >To client:
> ><reply>
> > <content>No one's home</content>
> ></reply>
> >
> >I'm thinking that cocoon would be really good for this type of server.
> >
> >I'm thinking it's a 'producer', but I'd be much happier just
> implementing a
> >logicsheet to do this.
> >
> >Insights?
>
> Looks like you are talking about XML/RPC.

:-) That obvious eh? Yes, I was hoping to contribute a
taglib/producer/whatever to allow Cocoon to serve XMLRPC requests.

> I have no idea if any of the servlet engines would automatically
> decode non
> "application/x-www-form-urlencoded" content for you.

Well, not automatically, but it was actually too easy: I added (e.g.
exposed) the ProducerFromRequest producer to cocoon.properties and then
POSTed to any XSP with the added query 'producer=request'. This streamed the
XML from the request body (POST with Content-Type "text/xml") back out to
the client. Note: it didn't look at the XSP file the URL referred to _at
all_.

There were two problems.

Of course, this should be considered unsafe: someone could potentially POST
XSP code that ran on the server if they added a <?cocoon-process
type="xsp"?> line, etc.

To test that, I did exactly that, expecting the XSP I sent to be executed.
Instead, it then executed the XSP of the file from the URL, not the XSP I
sent. Seems to me that C1 is not really respecting the producer I selected
completely, somehow there's a file producer in there too.

Suggestions? Corrections?

> You would probably have to decode the POST data yourself.
>
> Maybe the source code for Apache Soap (XML/RPC server) would provide some
> clues.

There's a XMLRPC client/server library for Java that I was looking at. I
works well at doing all the decoding, etc. But it's its own servlet, e.g.
it's outside the Cocoon framework which means I lose all its benefits.

Comments?

Per.


XSP could not compile error - Cocoon 1.8 Dev

Posted by HuiSion Teh <hu...@magix.com.sg>.
hi

The following code is ok:
	<para>
		<xsp:attribute name="font">red</xsp:attribute>
		This is a test
	</para>

The following code is NOT ok and generate the attached error:
	<util:include-uri>
		<xsp:attribute name="href">http://localhost:8080/test.xml</xsp:attribute>
	</util:include-uri>

I suspect there is a bug in the util taglib or bug in my use of Java 1.3.0
Linux beta from SUN.

Pls help...I am using Cocoon 1.8-dev and
	Tomcat Web Server/3.1 (JSP 1.1; Servlet 2.2; Java 1.3.0beta_refresh; Linux
2.2.14-5.0 i386; 	java.vendor=Sun Microsystems Inc.)

Regards

================================================
java.lang.Exception: XSP Java Compiler: Compilation failed for _test.java
164: No method matching valueOf() found in class java.lang.String.
      String __name = String.valueOf();
                                    ^
1 error


	at
org.apache.cocoon.processor.xsp.language.java.XSPJavaProcessor.compile(XSPJa
vaProcessor.java:141)
	at
org.apache.cocoon.processor.xsp.XSPProcessor.process(XSPProcessor.java:489)
	at org.apache.cocoon.Engine.handle(Engine.java:333)
	at org.apache.cocoon.Cocoon.service(Cocoon.java:167)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
	at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
	at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:160)
	at
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338
)
	at java.lang.Thread.run(Thread.java:484)


RE: Cocoon and HTTP POST

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
At 17:32 -0400 08/09/00, Per Kreipke wrote:
>
>
>It does, it does. Thanks for the XSP/XSLT hints!
>
>Let me ask a follow up question. Suppose the POST content type wasn't
>"application/x-www-form-urlencoded" (e.g. not form elements).
>
>Specifically, suppose it was "text/xml", how would you recommend going about
>implementing processing the contents and spitting back an XML reply? E.g. a
>messaging framework:
>
>>From client:
><request>
> <content>This is my message</content>
></request>
>
>To client:
><reply>
> <content>No one's home</content>
></reply>
>
>I'm thinking that cocoon would be really good for this type of server.
>
>I'm thinking it's a 'producer', but I'd be much happier just implementing a
>logicsheet to do this.
>
>Insights?

Looks like you are talking about XML/RPC.

I have no idea if any of the servlet engines would automatically decode non
"application/x-www-form-urlencoded" content for you.

You would probably have to decode the POST data yourself.

Maybe the source code for Apache Soap (XML/RPC server) would provide some
clues.

regards Jeremy
-- 
   ___________________________________________________________________

   Jeremy Quinn                                           Karma Divers
                                                       webSpace Design
                                            HyperMedia Research Centre

   <ma...@mac.com>     		 <http://www.media.demon.co.uk>
    <phone:+44.[0].20.7737.6831>        <pa...@sms.genie.co.uk>

RE: Cocoon and HTTP POST

Posted by Per Kreipke <pe...@onclave.com>.
> At 17:06 -0400 07/09/00, Per Kreipke wrote:
> >Newbie Q:
> >I'm wondering if Cocoon can handle POSTS as well as GETs. Which
> sample would
> >I look at?
>
> There are no examples that directly distinguish between POST and other
> methods, ie. with java code inside the XSP, but the FP Taglib
> provides this
> functionality with a Tag <fp:if-post></fp:if-post> and
> <fp:if-get></fp:if-get>.
>
> Whether you want to use the rest of FP or not, you can still use
> this Tag ...
>
> Basically to write this in Java, you'd do something like this:
>
> <xsp:logic>
> 	if ("POST".equalsIgnoreCase(request.getMethod())) {
> 		// your POST handling
> 	} else {
> 		// your GET etc. handling
> 	}
> </xsp:logic>
>
> or with the FP Tags:
>
> <fp:if-post>
> 	<!-- your "POST" output -->
> </fp:if-post>
>
> <fp:if-get>
> 	<!-- your "GET" output -->
> </fp:if-get>
>
> You can extract form values like this:
>
> 	<request:get-parameter name="fieldName" default="default value"/>
>
> BTW. Using the default value is very useful for checkboxes etc, as it
> allows you to have a default value in the case that the checkbox was
> unchecked ...
>
> ie <request:get-parameter name="myCheckBox" default="false"/>
>
>
> Hope this helps
>
> regards Jeremy


It does, it does. Thanks for the XSP/XSLT hints!

Let me ask a follow up question. Suppose the POST content type wasn't
"application/x-www-form-urlencoded" (e.g. not form elements).

Specifically, suppose it was "text/xml", how would you recommend going about
implementing processing the contents and spitting back an XML reply? E.g. a
messaging framework:

>From client:
<request>
 <content>This is my message</content>
</request>

To client:
<reply>
 <content>No one's home</content>
</reply>

I'm thinking that cocoon would be really good for this type of server.

I'm thinking it's a 'producer', but I'd be much happier just implementing a
logicsheet to do this.

Insights?

Per.


Re: Cocoon and HTTP POST

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
At 17:06 -0400 07/09/00, Per Kreipke wrote:
>Newbie Q:
>I'm wondering if Cocoon can handle POSTS as well as GETs. Which sample would
>I look at?

There are no examples that directly distinguish between POST and other
methods, ie. with java code inside the XSP, but the FP Taglib provides this
functionality with a Tag <fp:if-post></fp:if-post> and
<fp:if-get></fp:if-get>.

Whether you want to use the rest of FP or not, you can still use this Tag ...

Basically to write this in Java, you'd do something like this:

<xsp:logic>
	if ("POST".equalsIgnoreCase(request.getMethod())) {
		// your POST handling
	} else {
		// your GET etc. handling
	}
</xsp:logic>

or with the FP Tags:

<fp:if-post>
	<!-- your "POST" output -->
</fp:if-post>

<fp:if-get>
	<!-- your "GET" output -->
</fp:if-get>

You can extract form values like this:

	<request:get-parameter name="fieldName" default="default value"/>

BTW. Using the default value is very useful for checkboxes etc, as it
allows you to have a default value in the case that the checkbox was
unchecked ...

ie <request:get-parameter name="myCheckBox" default="false"/>


Hope this helps

regards Jeremy
-- 
   ___________________________________________________________________

   Jeremy Quinn                                           Karma Divers
                                                       webSpace Design
                                            HyperMedia Research Centre

   <ma...@mac.com>     		 <http://www.media.demon.co.uk>
    <phone:+44.[0].20.7737.6831>        <pa...@sms.genie.co.uk>