You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by James Scott <js...@hnt.com> on 2000/09/07 20:30:29 UTC

Cocoon and EJB

Hello all-

I'm designing an EJB-based application where I'd also like to use Cocoon/XSL.
I'm fairly new to both technologies and I'm trying to develop a good design
pattern. What I keep coming up with is a "producer" object (extending
org.apache.cocoon.producer.AbstractProducer) that calls methods on the EJBs and
constructs an XML document which is then processed by Cocoon.

I'm wondering if there's a better way to this and eliminate a layer of calls
(right now I have at least 3: cocoon -> producer -> ejb -> possible support
classes). Would XSP be a better fit? Looking over the XSP docs it seems like the
XSP processor uses the same producer model so I'm not sure it would be more
efficient. What's the advantage of XSP? Maintainability?

Has anybody used XSP with EJB? I'd appreciate your thoughts.

Thanks,

JLS

Re: Cocoon and EJB

Posted by Jens Lorenz <je...@interface-business.de>.
----- Original Message ----- 
From: Nicola Ken Barozzi <ni...@supereva.it>
To: <co...@xml.apache.org>
Sent: Thursday, September 07, 2000 9:03 PM
Subject: Re: Cocoon and EJB


> > Has anybody used XSP with EJB? I'd appreciate your thoughts.
> 
> EJB are, to put it maybe a little too simple, beans.
> Well, XSPs are excellent for beans.

Well. Just wanted to mention, that I'm currently dealing with
Beans and XSP ... and, well my design sucks but it works and
can easily interact with other XSP tag libs (which rocks) ...

> Are you sure you need then when the SQL taglib might be enough?

This seems to be the main usage for cocoon. Getting some date
from a database and formating it neatly ... But keep in mind,
that for a rather big amount of applications this data needs
to be postprocessed (and XSLT isn't enought) ...

Also I wonder that the other way isn't even spoken of. E.g.
presenting a form on the Browser, letting the user give some
input, and then transform it into XML and putting it back
into an bean, DB whatever ...

> Take a look at the samples of cocoon and reread the docs, I'm sure
> you will see things more clearly. :-)
> 
> nicola_ken


Regards,

Jens

-- 

jens.lorenz@interface-business.de

interface:business GmbH                             \\|//
Tolkewitzer Strasse 49                              (o o)
01277 Dresden                               ~~~~oOOo~(_)~oOOo~~~~
Germany                     




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>

Cocoon and HTTP POST

Posted by Per Kreipke <pe...@onclave.com>.
Newbie Q:
I'm wondering if Cocoon can handle POSTS as well as GETs. Which sample would
I look at?

Per.


Re: Cocoon and EJB

Posted by Nicola Ken Barozzi <ni...@supereva.it>.
----- Original Message ----- 
From: "James Scott" <js...@hnt.com>

> 
> 
> Nicola Ken Barozzi wrote:
> > 
> > ----- Original Message -----
> > From: "James Scott" <js...@hnt.com>
> > > Hello all-
> > >
> > > I'm wondering if there's a better way to this and eliminate a layer of calls
> > > (right now I have at least 3: cocoon -> producer -> ejb -> possible support
> > > classes).
> > 
> > IMO it's not an issue. If you look at a fairly _normal_ stacktrace, you can see
> > in any program something like 10-15 layers; AWT or Swing are _full_ of them.
> > Anyway Cocoon is a sort of Producer container, it instantiates the right elements
> > in the chain and lets them do the work.
> 
> That's fair. I knew from the docs that XSP templates get compiled into producers
> so I didn't think they'd be any more efficient. I can see that they'll be easier
> to maintain and let me get out of some of the tedium of outputting XML.

Yup.

> > EJB are, to put it maybe a little too simple, beans.
> > Well, XSPs are excellent for beans.
> > Are you sure you need then when the SQL taglib might be enough?
> 
> I think EJBs are appropriate to this project because we're trying to construct
> reusable components.   Encapsulating the business logic in EJBs and using XSP to
> format the output will give us a great deal of reusability, I think. I'd rather
> consolidate the SQL in a handful of EJB source files than have it spread across
> many XSP files. EJBs will also allow easy access from non-browser clients.

Simple beans can do the trick also.
Remember that in some cases EJB can sloooow things down!
I know I'm repeating, but SQL incapsulation is done via beans,
E or not.
Look at the Sun J2EE site for a comparison.

Happy to help :-)

nicola_ken




Re: Cocoon and EJB

Posted by James Scott <js...@hnt.com>.

Nicola Ken Barozzi wrote:
> 
> ----- Original Message -----
> From: "James Scott" <js...@hnt.com>
> > Hello all-
> >
> > I'm wondering if there's a better way to this and eliminate a layer of calls
> > (right now I have at least 3: cocoon -> producer -> ejb -> possible support
> > classes).
> 
> IMO it's not an issue. If you look at a fairly _normal_ stacktrace, you can see
> in any program something like 10-15 layers; AWT or Swing are _full_ of them.
> Anyway Cocoon is a sort of Producer container, it instantiates the right elements
> in the chain and lets them do the work.

That's fair. I knew from the docs that XSP templates get compiled into producers
so I didn't think they'd be any more efficient. I can see that they'll be easier
to maintain and let me get out of some of the tedium of outputting XML.

> EJB are, to put it maybe a little too simple, beans.
> Well, XSPs are excellent for beans.
> Are you sure you need then when the SQL taglib might be enough?

I think EJBs are appropriate to this project because we're trying to construct
reusable components.   Encapsulating the business logic in EJBs and using XSP to
format the output will give us a great deal of reusability, I think. I'd rather
consolidate the SQL in a handful of EJB source files than have it spread across
many XSP files. EJBs will also allow easy access from non-browser clients.

But...this is the Cocoon list and not the EJB list ;)

Thanks,

JLS

Re: Cocoon and EJB

Posted by Nicola Ken Barozzi <ni...@supereva.it>.
----- Original Message ----- 
From: "James Scott" <js...@hnt.com>
To: <co...@xml.apache.org>
Sent: Thursday, September 07, 2000 8:30 PM
Subject: Cocoon and EJB


> Hello all-
> 
> I'm designing an EJB-based application where I'd also like to use Cocoon/XSL.
> I'm fairly new to both technologies and I'm trying to develop a good design
> pattern. What I keep coming up with is a "producer" object (extending
> org.apache.cocoon.producer.AbstractProducer) that calls methods on the EJBs and
> constructs an XML document which is then processed by Cocoon.
> 
> I'm wondering if there's a better way to this and eliminate a layer of calls
> (right now I have at least 3: cocoon -> producer -> ejb -> possible support
> classes). 

IMO it's not an issue. If you look at a fairly _normal_ stacktrace, you can see
in any program something like 10-15 layers; AWT or Swing are _full_ of them.
Anyway Cocoon is a sort of Producer container, it instantiates the right elements
in the chain and lets them do the work.
As for the EJB, if you want to lose encapsulation, portability, distributed transactions,
etc, you can do everything by hand ;-) .
Of course, it depends on your projrct, see tje javasoft.com website (J2EE) on the 
"EJB or not" issue.

> Would XSP be a better fit? Looking over the XSP docs it seems like the
> XSP processor uses the same producer model so I'm not sure it would be more
> efficient. What's the advantage of XSP? Maintainability?

The point is not efficiency.
We could say that
servlet : JSP = producer : XSP  .
XSP is just a _much_ easier way of creating a producer.
They are compiled into producers.
Keep in mind that there are already many libraries, called taglibs, to 
use in XSPs. 

> Has anybody used XSP with EJB? I'd appreciate your thoughts.

EJB are, to put it maybe a little too simple, beans.
Well, XSPs are excellent for beans.
Are you sure you need then when the SQL taglib might be enough?
Take a look at the samples of cocoon and reread the docs, I'm sure
you will see things more clearly. :-)

nicola_ken

Nicola Ken Barozzi - AISA Industries S.p.A
http://www.aisaindustries.it/
Via Leonardo da Vinci,2 Ticengo (CR) Italy
Research Activity:
Politecnico di Milano - Dipartimento di Meccanica
Piazza Leonardo da Vinci, n.32 - 20133 Milano (Italy)



Re: Cocoon and EJB

Posted by Paul Russell <pa...@luminas.co.uk>.
On Thu, Sep 07, 2000 at 02:30:29PM -0400, James Scott wrote:
> Hello all-
> I'm designing an EJB-based application where I'd also like to use Cocoon/XSL.
> I'm fairly new to both technologies and I'm trying to develop a good design
> pattern. What I keep coming up with is a "producer" object (extending
> org.apache.cocoon.producer.AbstractProducer) that calls methods on the EJBs and
> constructs an XML document which is then processed by Cocoon.

You're almost certainly better using XSP for this.

> I'm wondering if there's a better way to this and eliminate a layer of calls
> (right now I have at least 3: cocoon -> producer -> ejb -> possible support
> classes). Would XSP be a better fit? Looking over the XSP docs it seems like the
> XSP processor uses the same producer model so I'm not sure it would be more
> efficient. What's the advantage of XSP? Maintainability?

That and the fact that it provides a clear extra layer of abstraction:

 EJB: Business logic
 XSP: Defining *what* appears on each page.
 XSLT + Serializers: Defining how it appears.

> Has anybody used XSP with EJB? I'd appreciate your thoughts.

I've not yet, but it's something I'm going to be doing very very
soon (about a month or two with C2). Keep the list posted with
your progress and I'll let you know how I get on too?

-- 
Paul Russell                               <pa...@luminas.co.uk>
Technical Director,                   http://www.luminas.co.uk
Luminas Ltd.

Re: Cocoon and EJB

Posted by James Scott <js...@hnt.com>.

Alexander Weinmann wrote:

> Don't call the database directly with the sql taglib. Database queries
> are part of the business logic and should be encapsulated inside the
> EJB's. 

Right, that's the whole point! I don't want my presentation code (XSP) to be
dependent on a specific schema. 

> I think, the optimal solution would be a EJB Taglib that allows you
> to write something look
> 
> <ejb:use-session-bean  class="...."   />
> 
> This is also related to questions about an XSP equivalent to the
> <jsp:useBean  > tag, that have been discussed on this forum some weeks
> ago.

I agree. If there's an effort currently underway for an ejb: taglib then I need
to join it. If it's not started...looks like I just volunteered.

A discussion for the cocoon-dev list, perhaps?

JLS

Re: Cocoon and EJB

Posted by Alexander Weinmann <aw...@bct-technology.com>.
I also agree with what other people wrote: Use XSP, and not Producers.
Don't call the database directly with the sql taglib. Database queries
are part of the business logic and should be encapsulated inside the
EJB's.  Use XSP only to build up the XML output and to handle request
parameters.

I think, the optimal solution would be a EJB Taglib that allows you
to write something look

<ejb:use-session-bean  class="...."   />

This is also related to questions about an XSP equivalent to the
<jsp:useBean  > tag, that have been discussed on this forum some weeks
ago. 


James Scott wrote:
> 
> Hello all-
> 
> I'm designing an EJB-based application where I'd also like to use Cocoon/XSL.
> I'm fairly new to both technologies and I'm trying to develop a good design
> pattern. What I keep coming up with is a "producer" object (extending
> org.apache.cocoon.producer.AbstractProducer) that calls methods on the EJBs and
> constructs an XML document which is then processed by Cocoon.
> 
> I'm wondering if there's a better way to this and eliminate a layer of calls
> (right now I have at least 3: cocoon -> producer -> ejb -> possible support
> classes). Would XSP be a better fit? Looking over the XSP docs it seems like the
> XSP processor uses the same producer model so I'm not sure it would be more
> efficient. What's the advantage of XSP? Maintainability?
> 
> Has anybody used XSP with EJB? I'd appreciate your thoughts.
> 
> Thanks,
> 
> JLS
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org

-- 
Alexander Weinmann | Web Developer
BCT Technology AG | D-77731 Willstätt/Germany | www.bct-technology.com
Phone +49(0)07852/996-0
Fax   +49(0)07852/996-100