You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by bajji m <jo...@yahoo.com> on 2004/01/09 14:56:52 UTC
File Uploading using cocoon issues. Unable to catch request/session object
Hi all,
This regarding File Uploading using cocoon framework.
-----------------------------------------------------------------------------
I am able to upload the file. I configured everything in web.xml and am able to calling the Action class and from the sitemap.xmap entry. I am using cocoon 2.0 version. I am able get the Fil object from the FilePartFile object from the Request object.
I stored that file in local directory successfuly.
But now need to pass or forward this File object to other XSP. This XSP will be in remote PC with Cocoon Framework.
I need to catch that file object in that XSP and need to store that FIle in that remote PC in specific folder.
For that i add this File Object to Session/request with some name and trying to get that File object in that XSP page. But ia m getting null File Object in that XSP.
My Action class
--------------------
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.cocoon.acting.Action;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.components.request.multipart.FilePart;
import org.apache.cocoon.components.request.multipart.FilePartFile;
import java.util.ArrayList;
import org.apache.cocoon.environment.Context;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
import java.util.Collections;
import java.io.*;
public class FileUpload
extends AbstractLogEnabled
implements Action, ThreadSafe
{
public Map act(Redirector redirector, SourceResolver resolver,
Map objectModel, String source, Parameters par)
throws Exception
{
Map sitemapParams = new HashMap();
Request request = ObjectModelHelper.getRequest(objectModel);
Context context= ObjectModelHelper.getContext(objectModel);
Session session=request.getSession();
String userName=session.getAttribute("userName").toString();
System.out.println("Enter into action class. 1 username.."+userName);
//getting uploaded file object from request
FilePart filePart = (FilePart) request.get("uploadfile");
//getting a file object from FilePartFile of FilePart
File file = ((FilePartFile)filePart).getFile();
//Creating Directory for user
String path="E:"+File.separator+"upfiles"+File.separator+"files"+File.separator+userName;
System.out.println("dyanamic path..."+path);
File dirCreation=new File(path);
System.out.println("dir creating...");
dirCreation.mkdir();
System.out.println("created..");
path=path+"\\"+file.getName();
System.out.println("new fiel name"+path);
boolean flag=file.renameTo(new File(path));
System.out.println("writing.........."+flag);
System.out.println("..finish");
//session.setAttribute("uploadedfile",file);
session.setAttribute("userName",userName);
String wsdlURL="http://localhost:8080/ssfsoap/services/Service?wsdl";
request.setAttribute("uploadedfile",file);
sitemapParams.put("wsdl",wsdlURL);
System.out.println("FilePart value"+filePart);
System.out.println("File value"+file);
return sitemapParams;
}
}
And Sitemap.xmap:
----------------------------
<map:match pattern="body-*/fileUpload.xml">
<map:act type="file-Upload">
<map:generate type="wapi">
<map:parameter name="wsdlURL" type="String" value="{wsdl}"/>
<map:parameter name="methodName" type="String" value="uploadToTarget" />
<map:parameter name="secure" type="String" value="false" />
</map:generate>
<map:transform src="content/xdocs/services/xsl/fileUploadResult2Html.xsl">
<map:parameter name="use-request-parameters" value="true"/>
</map:transform>
</map:act>
<map:serialize/>
</map:match>
And XSP follows
-----------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page language="java"
xmlns:xsp="http://apache.org/xsp">
<!-- xmlns:session="http://apache.org/xsp/session/2.0"
xmlns:xsp-request="http://apache.org/xsp/request/2.0"> -->
<xsp:structure>
<xsp:include>java.io.File</xsp:include>
<xsp:include>org.apache.cocoon.environment.*</xsp:include>
<xsp:include>org.apache.cocoon.components.request.multipart.*</xsp:include>
</xsp:structure>
<uploadToTarget>
<xsp:logic>
System.out.println("Enter into xsp 1");
Request request = ObjectModelHelper.getRequest(objectModel);
Session session=request.getSession();
File file =(File)session.getAttribute("uploadedfile");
System.out.println("Enter into xsp 1"+file);
//String username=sessio.getAttribute(userName).toString();
// System.out.println("username"+username);
// String bb=request.getAttribute("hello");
// System.out.println("Enter into xsp 1"+bb);
<status>File...uploaded</status>
</xsp:logic>
</uploadToTarget>
</xsp:page>
So i am getting null file object from session or request in this XSP . I tryed both combinations.
Why i am unable to pass that request or session object into that XSP.
Pls help me
Thanks
bajji
---------------------------------
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes