cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nico Verwer" <nver...@be-value.nl>
Subject SourceResolver does not send parameters?
Date Wed, 08 Oct 2003 15:07:27 GMT
Hello Cocoon developers,

I am trying to fetch a zip-file from a remote server and use this in a
generator and in cincludes later in my pipeline.
The zip-file is stored locally, because I do not want to repeat requests.
More importantly, the zip-file is *generated* on the remote server in
response to a HTTP POST request with a parameter named 'query'.

In order to achieve this, I wrote an action (this may a totally wrong
approach, please tell me) 'HttpFileAction' (code follows at the end of this
message). This requests the zip-file, stores it in a temporary file and sets
the sitemap variables filepath and fileurl (indicating where the file is
stored).
I use the action in my sitemap as follows:

      <map:match pattern="test">
        <map:act type="httpFile" src="http://remoteserver/zipfile-url">
          <map:parameter name="query" value="{request-param:query}"/>
          <map:generate type="file" src="jar:{fileurl}/!contents.xml"/>
        </map:act>
        <map:serialize type="xml"/>
      </map:match>

The zip-file contains a document called 'contents.xml', which is what I'd
like to see when I request 'test'.

The problem is that the remote server does not get the 'query' parameter. I
tested this by substituting a URL on my own server for the remoteserver URL:

      <map:match pattern="test">
        <map:act type="httpFile" src="http://myserver/showrequest">
          <map:parameter name="query" value="{request-param:query}"/>
          <map:generate type="file" src="{fileurl}"/> <!-- no /!contents.xml
! -->
        </map:act>
        <map:serialize type="xml"/>
      </map:match>

The showrequest is dealt with in the following pipeline:

      <map:match pattern="showrequest">
        <map:generate type="request"/>
        <map:serialize type="xml"/>
      </map:match>


This shows me the request, as expected, but the <h:requestParameters /> is
empty!
It seems that the parameters are not sent by the SourceResolver that was
passed to my action (see code below). The SourceResolver appears to be a
org.apache.cocoon.environment.http.HttpEnvironment, which uses another
SourceResolver in a protected variable that I can't see.
I also don't see a way to indicate that the request should be POST, not GET.

Does anyone know how to pass parameters? Is there a better way that I didn't
think of?

Cheers, Nico.

--- Code of my action ---

package nl.kluwer; <!-- The people who hire me at the moment. -->

import java.io.*;
import java.util.Map;
import java.util.HashMap;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.excalibur.source.Source;

public class HttpFileAction extends AbstractAction {
  public Map act (Redirector redirector,
                  SourceResolver resolver,
                  Map objectModel,
                  String source,
                  Parameters params) {
    Map sitemapParams = new HashMap();
    Source actionSource = null;
    try {
      actionSource = resolver.resolveURI(source, null,
Parameters.toProperties(params));
      <!-- I have tried building a HashMap for the parameters instead, with
the same result. -->
    } catch (Exception e) {
      getLogger().error("Cannot resolve HTTP-file action: "+e.toString());
      return null;
    }
    try {
      File tmpFile = File.createTempFile(source.replaceAll("[:/]", "_"),
".zip");
      InputStream tmpIn = actionSource.getInputStream();
      FileWriter tmpOut = new FileWriter(tmpFile.getPath());
      for (int c = tmpIn.read(); c >= 0; c = tmpIn.read()) {
        tmpOut.write(c);
      }
      tmpOut.close();
      sitemapParams.put("filepath", tmpFile.getPath());
      sitemapParams.put("fileurl", tmpFile.toURI().toString());
    } catch (Exception e) {
      getLogger().error("Cannot write file for HTTP-file action:
"+e.toString());
      return null;
    }
    return sitemapParams;
  }
}


Mime
View raw message