You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Cedric Picard <C....@kainos.com> on 2002/11/13 13:49:23 UTC

[REQ] Validation actions

Hi there,

I am currently trying to integrate cocoon 2.0.3 with a web application.
The idea is to use cocoon as a reports engine to generate printable HTML
documents.

I have basically downloaded cocoon-2.0.3-src.zip, built on Windows 2K
(JDK 1.3.1), and deployed in Jboss 2.4.6 with tomcat 4.0.3.

In a first step, I chose to deploy cocoon as standalone, and simply add
my own sitemap to the existing webapp:
<map:pipelines>
  <map:pipeline>
    <map:match pattern="CMReports/**">
      <map:mount uri="CMReports" src="CMReports/sitemap.xmap"
check-reload="yes"/>
    </map:match>
  </map:pipeline>
  ...
</map:pipelines>

And access the reports pages at
http://localhost:8080/cocoon/Reports/myreport.html

In a second step, I added an action in my own sitemap, to perform
session validation, so that reports can only be accessible via our web
application, passing our session object to the pipeline.

CMReports/sitemap.xmap:
<?xml version="1.0" encoding="UTF-8"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">

   <map:components>
     <map:generators default="file"/>
     <map:transformers default="xslt"/>
     <map:readers default="resource"/>
     <map:serializers default="html"/>
     <map:selectors default="browser"/>
     <map:matchers default="wildcard"/>
     <map:actions>
       <map:action name="ensureLoggedIn" 
                    src="com.kainos.cocoon.action.EnsureLoggedInAction"
/>
     </map:actions>
   </map:components>
   
   <map:pipelines>
     <!-- HTML reports -->
     <map:pipeline>
       <map:match pattern="*.html">
         <map:act type="ensureLoggedIn">
           <map:generate type="serverpages" src="documents/{1}.xsp" />
           <map:transform src="stylesheets/{1}.xsl" />
           <map:serialize type="html" />
         </map:act>
       </map:match>
     </map:pipeline>
   </map:pipelines>   
</map:sitemap>

And here is the code for the action:
public class EnsureLoggedInAction extends AbstractAction
{
	public Map act(Redirector redirector_p,
				   SourceResolver resolver_p,
				   Map objectModel_p,
				   String sSource_p,
				   Parameters params_p)
	{
		Map map = null;

		Request request = (Request)
objectModel_p.get(Constants.REQUEST_OBJECT);

		CSessionSB sessionSB = null;

		// extract the session object passed as an attribute to
the request object
		sessionSB = (CSessionSB)
request.getAttribute("coreSessionSB");

		if (null == sessionSB)
		{
			return null;
		}

		try
		{
			sessionSB.ensureLoggedIn();

			// the user is logged in, set the map to an
empty map
			map = EMPTY_MAP;
		}
		catch(CNotPermittedException e)
		{
			// nothing to do, map already equals to null
		}
		catch(RemoteException e)
		{
			// nothing we can do about it
		}
		finally
		{
			return map;
		}
	}
}

I also modified build.xml to include EnsureLoggedIn.class in
web-inf/classes, but upon accessing the page via our web application, I
get a resource not found exception
The requested URI "/cocoon/CMReports/CMUsers.html" was not found

I can only assume the addition of the login validation caused the
problem, as the page was generated successfully prior to the addition of
the action, but cannot see what is going wrong,

Is there any way of debugging actions?
Cedric Picard,
Software Engineer
Kainos Software Ltd.



--

This e-mail is confidential and is intended for the named recipient only. If
you receive it in error please destroy the message and all copies. Kainos
Software Ltd. does not accept liability for damage sustained as a result of
malicious software (e.g. viruses). Kainos does not accept liability for, or
permit, the creation of contracts on its behalf by e-mail, the publication of
any defamatory statement by its employees by e-mail, or changes subsequently
made to the original message. The Company's registered office is located at
4-6 Upper Crescent, Belfast, BT7 1NT, Northern Ireland, Tel +44 28 9057 1100.

Re: [REQ] Validation actions

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 13.Nov.2002 -- 12:49 PM, Cedric Picard wrote:
>        <map:match pattern="*.html">
>          <map:act type="ensureLoggedIn">
>            <map:generate type="serverpages" src="documents/{1}.xsp" />
>            <map:transform src="stylesheets/{1}.xsl" />
>            <map:serialize type="html" />
>          </map:act>
>        </map:match>

> I can only assume the addition of the login validation caused the
> problem, as the page was generated successfully prior to the addition of
> the action, but cannot see what is going wrong,

If you had looked at your sitemap.log you would have seen

...

Current Sitemap Parameters:
LEVEL 1
PARAM: '0' VALUE: 'CMUsers.html'
PARAM: '1' VALUE: 'CMUsers'

...

Current Sitemap Parameters:
LEVEL 1

LEVEL 2
PARAM: '../0' VALUE: 'CMUsers.html'
PARAM: '../1' VALUE: 'CMUsers'

...

By nesting your generate inside an action, you add another level of
sitemap parameters. Obviously, you need to go one level up...

> Is there any way of debugging actions?

You could attach a debugger.

You could issue debug statements. See other actions on how to do it.

	Chris.
-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>