0 Replies Latest reply on May 29, 2008 12:21 PM by rob_gar_esp

    portlet upload

    rob_gar_esp

      Hi,

      I'm implementing a very basic file uploader portlet such, actually I'm trying the portlet provided in the samples:

      public class ResumeTask extends GenericPortlet {
      
       public void processAction(ActionRequest req, ActionResponse resp) throws PortletException, PortletSecurityException, IOException
       {
      
       //
       List fileNames = new ArrayList();
       List fileSizes = new ArrayList();
       List descriptions = new ArrayList();
      
       //
       try
       {
       DiskFileItemFactory factory = new DiskFileItemFactory();
       PortletFileUpload upload = new PortletFileUpload(factory);
       List fileItems = upload.parseRequest(req);
       for (Iterator iterator = fileItems.iterator(); iterator.hasNext();)
       {
       FileItem item = (FileItem)iterator.next();
       if (item.getFieldName().equals("File"))
       {
       fileNames.add("" + item.getName());
       fileSizes.add("" + item.getSize());
       }
       else if (item.getFieldName().equals("Description"))
       {
       descriptions.add("" + item.getString(req.getCharacterEncoding()));
       }
       }
       }
       catch (FileUploadException e)
       {
       throw new PortletException(e);
       }
      
       //
       resp.setRenderParameter("fileNames", (String[])fileNames.toArray(new String[fileNames.size()]));
       resp.setRenderParameter("fileSizes", (String[])fileSizes.toArray(new String[fileSizes.size()]));
       resp.setRenderParameter("contents", (String[])descriptions.toArray(new String[descriptions.size()]));
       }
      
       protected void doView(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
       {
       //
       resp.setContentType("text/html");
      
       //
       PrintWriter writer = resp.getWriter();
      
       String[] fileNames = req.getParameterValues("fileNames");
       String[] fileSizes = req.getParameterValues("fileSizes");
       String[] descriptions = req.getParameterValues("contents");
       if (descriptions != null)
       {
       for (int i = 0; i < descriptions.length; i++)
       {
       writer.println("Received description " + descriptions + "<br/>");
       }
       }
       if (fileNames != null && fileSizes != null && fileNames.length == fileSizes.length)
       {
       for (int i = 0; i < fileNames.length; i++)
       {
       writer.println("Received file " + fileNames + " with size " + fileSizes + "<br/>");
       }
       }
      
       //
       writer.println("<form action=\"" + resp.createActionURL() + "\" method=\"post\" enctype=\"multipart/form-data\">");
       writer.println("<table>");
       writer.println("<tr><td>Description:</td>");
       writer.println("<td><input type=\"text\" name=\"Description\"></td></tr>");
       writer.println("<tr><td>File:</td>");
       writer.println("<td><input type=\"file\" name=\"File\"></td></tr>");
       writer.println("<tr><td><input type=\"submit\" name=\"Upload\"></td></tr>");
       writer.println("</table>");
       writer.println("</form>");
       }
       }
      



      But I'm getting a nasty exception:




      18:11:53,078 ERROR [DefaultPortalControlPolicy] Rendering portlet window produced an error
      org.jboss.portal.portlet.PortletInvokerException: javax.servlet.ServletException
      at org.jboss.portal.portlet.container.PortletContainerInvoker.invoke(PortletContainerInvoker.java:212)
      at org.jboss.portal.portlet.state.producer.ProducerPortletInvoker.invoke(ProducerPortletInvoker.java:233)
      at org.jboss.portal.core.impl.portlet.state.ProducerPortletInvoker.org$jboss$portal$core$impl$portlet$state$ProducerPortletInvoker$invoke$aop(ProducerPortletInvoker.java:53)
      at org.jboss.portal.core.impl.portlet.state.ProducerPortletInvoker$invoke_N8654503705355129869.invokeNext(ProducerPortletInvoker$invoke_N8654503705355129869.java)
      at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
      at org.jboss.portal.core.impl.portlet.state.ProducerPortletInvoker$invoke_N8654503705355129869.invokeNext(ProducerPortletInvoker$invoke_N8654503705355129869.java)
      at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
      at org.jboss.portal.core.impl.portlet.state.ProducerPortletInvoker$invoke_N8654503705355129869.invokeNext(ProducerPortletInvoker$invoke_N8654503705355129869.java)
      at org.jboss.portal.core.impl.portlet.state.ProducerPortletInvoker.invoke(ProducerPortletInvoker.java)
      at org.jboss.portal.portlet.federation.impl.FederatedPortletInvokerService.invoke(FederatedPortletInvokerService.java:147)
      at org.jboss.portal.portlet.federation.impl.FederatingPortletInvokerService.invoke(FederatingPortletInvokerService.java:150)
      at org.jboss.portal.core.impl.model.instance.InstanceContainerImpl$1.invoke(InstanceContainerImpl.java:99)
      at org.jboss.portal.common.invocation.Invocation.invokeNext(Invocation.java:131)
      at org.jboss.portal.portlet.management.PortletContainerManagementInterceptorImpl.invoke(PortletContainerManagementInterceptorImpl.java:58)
      at org.jboss.portal.portlet.invocation.PortletInterceptor.invoke(PortletInterceptor.java:38)





      Caused by: java.lang.LinkageError: loader constraints violated when linking org/apache/commons/fileupload/FileItemFactory class
      at com.mnemo.siwo.portlet.ResumeTask.processAction(ResumeTask.java:62)
      at org.jboss.portal.portlet.impl.jsr168.PortletContainerImpl.invokeAction(PortletContainerImpl.java:458)
      at org.jboss.portal.portlet.impl.jsr168.PortletContainerImpl.dispatch(PortletContainerImpl.java:401)
      at org.jboss.portal.portlet.container.PortletContainerInvoker$1.invoke(PortletContainerInvoker.java:86)
      at org.jboss.portal.common.invocation.Invocation.invokeNext(Invocation.java:131)
      at org.jboss.portal.core.aspects.portlet.TransactionInterceptor.org$jboss$portal$core$aspects$portlet$TransactionInterceptor$invokeNotSupported$aop(TransactionInterceptor.java:86)
      at org.jboss.portal.core.aspects.portlet.TransactionInterceptor$invokeNotSupported_N4547270787964792031.invokeNext(TransactionInterceptor$invokeNotSupported_N4547270787964792031.java)
      at org.jboss.aspects.tx.TxPolicy.invokeInNoTx(TxPolicy.java:66)
      at org.jboss.aspects.tx.TxInterceptor$NotSupported.invoke(TxInterceptor.java:112)
      at org.jboss.portal.core.aspects.portlet.TransactionInterceptor$invokeNotSupported_N4547270787964792031.invokeNext(TransactionInterceptor$invokeNotSupported_N4547270787964792031.java)
      at org.jboss.aspects.tx.TxPolicy.invokeInNoTx(TxPolicy.java:66)
      at org.jboss.aspects.tx.TxInterceptor$NotSupported.invoke(TxInterceptor.java:102)
      at org.jboss.portal.core.aspects.portlet.TransactionInterceptor$invokeNotSupported_N4547270787964792031.invokeNext(TransactionInterceptor$invokeNotSupported_N4547270787964792031.java)
      at org.jboss.portal.core.aspects.portlet.TransactionInterceptor.invokeNotSupported(TransactionInterceptor.java)
      at org.jboss.portal.core.aspects.portlet.TransactionInterceptor.invoke(TransactionInterceptor.java:56)





      The error occurs at line:

      PortletFileUpload upload = new PortletFileUpload(factory);


      Please advise. Tx!