Re: SourceResolver does not send parameters?

2003-10-10 Thread Bruno Dumon
On Wed, 2003-10-08 at 17:07, Nico Verwer wrote:
> Hello Cocoon developers,



> 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:



>   actionSource = resolver.resolveURI(source, null,
> Parameters.toProperties(params));

The parameters you supply here as third argument to the resolveURI
method aren't added to the request URI. Instead, the Map you supply
should contain a key SourceResolver.URI_PARAMETERS with as value an
instance of org.apache.excalibur.source.SourceParameters.

-- 
Bruno Dumon http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
[EMAIL PROTECTED]  [EMAIL PROTECTED]



SourceResolver does not send parameters?

2003-10-08 Thread Nico Verwer
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:

  
http://remoteserver/zipfile-url";>
  
  


  

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:

  
http://myserver/showrequest";>
  
   


  

The showrequest is dealt with in the following pipeline:

  


  


This shows me the request, as expected, but the  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; 

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));
  
} 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;
  }
}