You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by anil <an...@btinternet.com> on 2008/01/29 18:06:59 UTC

processToDom talking to another block

Hi -

Could someone clarify whether it's possible for me to use the processToDOM
function in pipelineUtil to talk to a pipeline from another block's sitemap?

I've tried a number of different ways to address the pipeline within the
other block but each time I have received a No pipeline matched request
error.

The syntax I've used to address the pipeline (i.e. the first parameter to
the processToDOM function) is as follows:

servlet:rmm-search:/transformForSolr

/rmm-search/transformForSolr

The first parameter is supposed to be a URI but the documentation for
processPipelineTo (which I believe processToDOM is built on top of) says
that the url cannot contain a scheme, so I didn't expect the first option
above to work.

The documentation for processPipelineTo does say that if the pipeline URI
beings with a / then cocoon will process the request from the root sitemap,
so I thought that may work. Unfortunately not.

If someone could clarify how I should address the pipeline in my other block
I'd be really grateful? 

I wondered is there any way I can call a pipeline in block that my
flowscript is running from, get the parameter in that local pipeline and
then forward the request on to the other block & receive the result back in
flowscript?

Many thanks,
Anil.


-- 
View this message in context: http://www.nabble.com/processToDom-talking-to-another-block-tp15163995p15163995.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


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


Re: processToDom talking to another block

Posted by Grzegorz Kossakowski <gk...@apache.org>.
anil pisze:
> Hi Grzegorz -
> 
> Thanks for your help regarding talking to a pipeline in another block. I've
> got a supplementary question which I hope you can help with. 
> 
> How do I pass a string of XML to the pipeline to have it transformed?
> 
> Basically I receive a string of XML in flowscript (this XML is read from the
> input stream, sent by an xforms engine) and I'd like to pass this string to
> the pipeline to perform some XSLT transformation, and have the result of the
> transformation passed back to me within flowscript.
> 
> To achieve this previously I had done:
> 
> 
> var output = pipelineUtil.processToDOM("transformForExist", viewData);
> 
> 
> with viewData being the data - this is then read by:
> 
> <map:generate src="module:flow-attr:stringOutput" />
> 
> So now I am using the source resolver my flowscript is as follows:
> 	
> var map = new java.util.HashMap();
> map.put("stringOutput", submission);
> 
> var source =
> sourceResolver.resolveURI("servlet:rmm-search:/transformForSolr", null,
> map);
> var sourceOutput = SourceUtil.toDOM(source);

This wrong because the map you pass is not used to build parameters attached to the URI. Javadocs of
SourceResolver#resolveURI() say:

  parameters - - Additional parameters for the URI. The parameters are specific to the used scheme.

Since it's schema specific it implys it's not universal way to pass parameters that will be taken
the same way as they could be passed using literal ?param=value syntax. Actually, servlet: source
implementation (along with most implementations of other sources) completely ignores parameters object.

> But I can't find a way to read the parameter within the transformForSolr
> pipeline. I tried using the request generator to read the parameters, but
> this didn't seem to work.
> 
> Sorry, I'm just a bit confused - am I doing the right thing?

The whole approach must be different, you have basically two choices:
1. Make a Servlet *Service* request
2. Attach you string as a parameter to your URI using ?param=value syntax. Method
appendParameters()[1] would be helpful.


Since second method is rather ineffective and clumsy (because parameters in URI should be used for
short values) I won't elaborate on this method.


Let's take a closer look of Servlet *Service* request. I have put word service in bold quite
intentionally in order to point out that it's not plain servlet request that you make using
SourceResolver which is, in fact, plain GET request. Servlet Service request is also implemented as
standard HTTP request but with POST method and special meaning attached to the POSTed data. See [2]
for more information about it (it's link to docs of SSF just being created now).


The only missing detail is how to enforce Source object obtained from ServletResolver to make a
service request and how to pass the data? Let's take a look at API docs of ServletSource[3]. As you
see it implements PostableSource[4] interface. That's the key, you need to getOutputStream from
source and write your XML data to it. Then you can use SourceUtil.toDOM(source) method as before.

You may wonder how you are going to parse XML coming as POST data to your another block. Answer is
simple, use standard ("file") generator and service-consumer: source. Your pipeline should look like:

    <map:generate src="service-consumer:"/>
    [...]
    <map:serialize type="xml"/>

And you are done.


I think that for such operations should some helper/util class be created. Moreover, this should be
moved to documentation as FAQ entry. Anil, since I helped quite a lot it would be nice if you could
take care of adding summary of this discussion to our documentation. Instructions how to do that are
here[5].

[1]
http://excalibur.apache.org/apidocs/org/apache/excalibur/source/SourceUtil.html#appendParameters(java.lang.String,%20org.apache.excalibur.source.SourceParameters)
[2] http://cocoon.zones.apache.org/daisy/cdocs-servlet-service-impl/g1/1412.html
[3]
http://cocoon.apache.org/subprojects/servlet-service/1.0/servlet-service-components/1.0/apidocs/org/apache/cocoon/servletservice/components/ServletSource.html
[4]
http://cocoon.apache.org/subprojects/servlet-service/1.0/servlet-service-components/1.0/apidocs/org/apache/cocoon/servletservice/postable/PostableSource.html
[5] http://cocoon.apache.org/1273_1_1.html

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

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


Re: processToDom talking to another block

Posted by anil <an...@btinternet.com>.
Hi Grzegorz -

Thanks for your help regarding talking to a pipeline in another block. I've
got a supplementary question which I hope you can help with. 

How do I pass a string of XML to the pipeline to have it transformed?

Basically I receive a string of XML in flowscript (this XML is read from the
input stream, sent by an xforms engine) and I'd like to pass this string to
the pipeline to perform some XSLT transformation, and have the result of the
transformation passed back to me within flowscript.

To achieve this previously I had done:


var output = pipelineUtil.processToDOM("transformForExist", viewData);


with viewData being the data - this is then read by:

<map:generate src="module:flow-attr:stringOutput" />

So now I am using the source resolver my flowscript is as follows:
	
var map = new java.util.HashMap();
map.put("stringOutput", submission);

var source =
sourceResolver.resolveURI("servlet:rmm-search:/transformForSolr", null,
map);
var sourceOutput = SourceUtil.toDOM(source);


But I can't find a way to read the parameter within the transformForSolr
pipeline. I tried using the request generator to read the parameters, but
this didn't seem to work.

Sorry, I'm just a bit confused - am I doing the right thing?

Many thanks,
Anil. 

-- 
View this message in context: http://www.nabble.com/processToDom-talking-to-another-block-tp15163995p15183436.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


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


Re: processToDom talking to another block

Posted by anil <an...@btinternet.com>.
Grzegorz -

As always, thank you very much for your prompt response. I'm not able to try
this now, but I will do so in the next day or so and report back to the
list.

Once again, many thanks.
Anil.

-- 
View this message in context: http://www.nabble.com/processToDom-talking-to-another-block-tp15163995p15171362.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


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


Re: processToDom talking to another block

Posted by Grzegorz Kossakowski <gk...@apache.org>.
anil pisze:
> Hi -
> 
> Could someone clarify whether it's possible for me to use the processToDOM
> function in pipelineUtil to talk to a pipeline from another block's sitemap?

It's not possible. PipelineUtil class has been designed before servlet: protocol's advent and was
limited to cocoon: protocol by design. This class is completely block-unaware and its use (at least
for now) should be avoided.

> I've tried a number of different ways to address the pipeline within the
> other block but each time I have received a No pipeline matched request
> error.
> 
> The syntax I've used to address the pipeline (i.e. the first parameter to
> the processToDOM function) is as follows:
> 
> servlet:rmm-search:/transformForSolr
> 
> /rmm-search/transformForSolr
> 
> The first parameter is supposed to be a URI but the documentation for
> processPipelineTo (which I believe processToDOM is built on top of) says
> that the url cannot contain a scheme, so I didn't expect the first option
> above to work.
> 
> The documentation for processPipelineTo does say that if the pipeline URI
> beings with a / then cocoon will process the request from the root sitemap,
> so I thought that may work. Unfortunately not.
> 
> If someone could clarify how I should address the pipeline in my other block
> I'd be really grateful? 

One of the goals behind Servlet Service Framework was coherence so the rule is to always reference
pipelines from other blocks the same way. Having said that, you must use this URI:

  servlet:rmm-search:/transformForSolr

As noted above, this won't work with PipelineUtil but will work with SourceUtil#toDOM[1]. All you
need is Source representation of your URI. You can get it using SourceResolver[2] which can be
obtained using

  cocoon.getComponent(Packages.org.apache.excalibur.source.SourceResolver.ROLE);

NOTE: Don't forget to release obtained source and resolver itself!

This method can be treated as a work-around so patches improving this situation are welcome.

> I wondered is there any way I can call a pipeline in block that my
> flowscript is running from, get the parameter in that local pipeline and
> then forward the request on to the other block & receive the result back in
> flowscript?

You can access pipelines from current block by omitting connection's name when using servlet: protocol.

[1]
http://cocoon.apache.org/2.2/core-modules/core/2.2/apidocs/org/apache/cocoon/components/source/SourceUtil.html#toDOM(org.apache.excalibur.source.Source)
[2] http://excalibur.apache.org/apidocs/org/apache/excalibur/source/SourceResolver.html

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

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