voyent
FileUploadServlet source code  XML
Forum Index -> Components
Author Message
lindabaja

Joined: 10/Sep/2008 00:00:00
Messages: 7
Offline


Hi,
Is there any place where I could get the source code for the FileUploadServlet class for IceFaces 1.7.1
The source zips do not have the source from release 1.6 onwards, and it looks like the implementation has significantly changed.

Thanks in advance for any pointers

karthik
jmind

Joined: 07/Jul/2008 00:00:00
Messages: 54
Offline


try downloading the src distro. Also missing are all the sources for the tag handlers. see the other topic for details

italian coder
lindabaja

Joined: 10/Sep/2008 00:00:00
Messages: 7
Offline


jmind wrote:
try downloading the src distro. Also missing are all the sources for the tag handlers. see the other topic for details 

The source distro does not have the code (Actually FileUploadServlet code is missing in the distro since 1.6.0 release. This is when the class started extending BlockingServlet instead of icefaces...FileUploadServlet)
So, if anyone has access to the latest source code, and can upload or point to it, that would be great.

Thanks
Karthik
jmind

Joined: 07/Jul/2008 00:00:00
Messages: 54
Offline


i thought icefaces was opensource

italian coder
lindabaja

Joined: 10/Sep/2008 00:00:00
Messages: 7
Offline


Here is why I need this code.

I am looking to use ice:inputFile for file upload, but the requirement is that the data should NOT be stored in the disk but it should be read as a stream.
IS there any way to do this other than to re-write a servlet similar to FileUploadServlet, that reads the stream instead of saving to disk.
If not, is there any way to get the FileUploadServlet source code, so that it is possible to identify where to make the necessary changes.

Thanks
Karthik
asherwin

Joined: 27/Jun/2008 00:00:00
Messages: 108
Offline


I had to write my own servlet that reads as a stream and keeps in memory until it is (sometimes) persisted to DB.

I found the ice:inputFile component to be pretty much unusable the way it creates an embedded iframe, it gets pretty ugly. The issue we had was that it actually didnt work at all with any significant network latency (app hosted in Massachusetts, someone in London trying to use it would always fail to upload file)

I ended up writing a standard Servlet class, examined the JSF 1.2 standard FacesServlet class to see how it got a reference to the FacesContext, extracted and used that code... and then used that to use the EL resolver to put my InputStream onto a Session Bean inside the ICEFaces JSF EL
jmind

Joined: 07/Jul/2008 00:00:00
Messages: 54
Offline


asherwin wrote:
examined the JSF 1.2 standard FacesServlet class to see how it got a reference to the FacesContext, 


could you post the code to do that?

italian coder
asherwin

Joined: 27/Jun/2008 00:00:00
Messages: 108
Offline


I cant c/p my Servlet entirely, but I can give you snippets of what to do

Create a Class that extends HttpServlet, put the following members in the servlet
Code:
   private ServletConfig servletConfig;
   private ServletContext servletContext;
   private FacesContextFactory facesContextFactory;
   private Lifecycle lifecycle;
 


Override the init(ServletConfig sc) throws ServletException function, here is an example
Code:
 @Override
   public void init(final ServletConfig newConfig) throws ServletException {
     if (LOG.isDebugEnabled()) {
       LOG.debug("UploadServlet > init(ServletConfig)");
     }
     servletConfig = newConfig;
     servletContext = servletConfig.getServletContext();
 
     try {
       facesContextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
     } catch (FacesException e) {
       LOG.error("Caught Exception [" + e.getMessage() + "]");
       throw new UnavailableException(e.getMessage());
     }
 
     try {
       final LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
       String lifecycleId = servletConfig.getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
 
       if (null == lifecycleId) {
         lifecycleId = servletConfig.getServletContext().getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR);
       }
 
       if (lifecycleId == null) {
         lifecycleId = LifecycleFactory.DEFAULT_LIFECYCLE;
       }
       lifecycle = lifecycleFactory.getLifecycle(lifecycleId);
     } catch (FacesException e) {
       final Throwable rootCause = e.getCause();
       if (rootCause == null) {
         throw e;
       } else {
         throw new ServletException(e.getMessage(), rootCause);
       }
     }
 
     super.init(servletConfig);
   }
 


Now, you can use the facesContextFactory to during each request to get the FacesContext. So, in something like doRequest (which I call from doGet, doPost etc) you can do this to get the current FacesContext
Code:
 private void doRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
   final FacesContext facesContext = facesContextFactory.getFacesContext(servletConfig.getServletContext(), request, response, lifecycle);
 }
 


Now, the sky is the limit... you can use the EL resolver on the FacesContext to get whatever beans you're interested in (probably Session or Application scoped beans, Request scope wont do you much good since your request is not on a JSF page, and you will probably have to redirect back to one)
Code:
 facesContext .getApplication().evaluateExpressionGet(facesContext , "#{SomeSessionBean}", SomeSessionBean.class);
 


Have fun




jmind

Joined: 07/Jul/2008 00:00:00
Messages: 54
Offline


many thanks, i always wondered how to do that

italian coder
 
Forum Index -> Components
Go to:   
Powered by JForum 2.1.7ice © JForum Team