You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by cd...@apache.org on 2006/08/28 01:55:44 UTC
svn commit: r437476 - in /portals/pluto/branches/pluto-1.0.2/portal: ./
src/java/org/apache/pluto/portlet/admin/controller/
src/java/org/apache/pluto/portlet/admin/services/ src/webapp/WEB-INF/
src/webapp/portlets/admin/
Author: cdoremus
Date: Sun Aug 27 16:55:41 2006
New Revision: 437476
URL: http://svn.apache.org/viewvc?rev=437476&view=rev
Log:
Updated admin portlet to use commons-fileupload 1.1 to do file uploads. Added a 'maxuploadsize' init-parm to Pluto's portlet.xml for the admin portlet to allow configuring of the maximum upload size allowed by the admin portlet.
Modified:
portals/pluto/branches/pluto-1.0.2/portal/project.xml
portals/pluto/branches/pluto-1.0.2/portal/src/java/org/apache/pluto/portlet/admin/controller/DeployWarPortlet.java
portals/pluto/branches/pluto-1.0.2/portal/src/java/org/apache/pluto/portlet/admin/services/DeployWarService.java
portals/pluto/branches/pluto-1.0.2/portal/src/webapp/WEB-INF/portlet.xml
portals/pluto/branches/pluto-1.0.2/portal/src/webapp/portlets/admin/DeployWarHelp.html
Modified: portals/pluto/branches/pluto-1.0.2/portal/project.xml
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/portal/project.xml?rev=437476&r1=437475&r2=437476&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/portal/project.xml (original)
+++ portals/pluto/branches/pluto-1.0.2/portal/project.xml Sun Aug 27 16:55:41 2006
@@ -100,8 +100,17 @@
<dependency>
<id>commons-fileupload</id>
- <version>1.0</version>
+ <version>1.1</version>
<url>http://jakarta.apache.org/commons/fileupload</url>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
+ </dependency>
+
+ <dependency>
+ <id>commons-io</id>
+ <version>1.1</version>
+ <url>http://jakarta.apache.org/commons/io</url>
<properties>
<war.bundle>true</war.bundle>
</properties>
Modified: portals/pluto/branches/pluto-1.0.2/portal/src/java/org/apache/pluto/portlet/admin/controller/DeployWarPortlet.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/portal/src/java/org/apache/pluto/portlet/admin/controller/DeployWarPortlet.java?rev=437476&r1=437475&r2=437476&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/portal/src/java/org/apache/pluto/portlet/admin/controller/DeployWarPortlet.java (original)
+++ portals/pluto/branches/pluto-1.0.2/portal/src/java/org/apache/pluto/portlet/admin/controller/DeployWarPortlet.java Sun Aug 27 16:55:41 2006
@@ -19,6 +19,7 @@
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletSession;
@@ -37,10 +38,13 @@
* record to portletentityregistry.xml and pageregistry.xml.
*
* @author Ken Atherton
+ * @author <a href="mailto:cdoremus@apache.org">Craig Doremus</a>
*
*/
public class DeployWarPortlet extends ControllerPortlet {
private DeployWarService service;
+ private static final String MAX_FILE_UPLOAD_SIZE_PARAM = "maxuploadsize";
+ private static int MAX_FILE_UPLOAD_SIZE = 10;//default max upload size in MB
protected void doEdit(RenderRequest request, RenderResponse response)
@@ -59,9 +63,19 @@
/* (non-Javadoc)
* @see javax.portlet.GenericPortlet#init()
*/
- public void init() throws PortletException {
- super.init();
+ public void init(PortletConfig config) throws PortletException {
+ super.init(config);
service = new DeployWarService();
+ String tmp = config.getInitParameter(MAX_FILE_UPLOAD_SIZE_PARAM);
+ if (tmp != null && !tmp.equals("")) {
+ try {
+ int size = Integer.parseInt(tmp);
+ MAX_FILE_UPLOAD_SIZE = size;
+ } catch (NumberFormatException e) {
+ String msg = "WARNING! Problem converting " + MAX_FILE_UPLOAD_SIZE_PARAM + " init-param to integer. Ignoring value.";
+ log(msg, e);
+ }
+ }
}
/* (non-Javadoc)
@@ -81,9 +95,10 @@
if (action == null) {
//process file upload
- String fileName = service.processFileUpload(request,response);
-
- //Remove .war from the name
+ String fileName = service.processFileUpload(request,response, MAX_FILE_UPLOAD_SIZE);
+ log("File upload done with max file size: " + MAX_FILE_UPLOAD_SIZE);
+
+ //Remove .war from the name
int index = fileName.indexOf(".war");
String name = null;
if ( index != -1) {
Modified: portals/pluto/branches/pluto-1.0.2/portal/src/java/org/apache/pluto/portlet/admin/services/DeployWarService.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/portal/src/java/org/apache/pluto/portlet/admin/services/DeployWarService.java?rev=437476&r1=437475&r2=437476&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/portal/src/java/org/apache/pluto/portlet/admin/services/DeployWarService.java (original)
+++ portals/pluto/branches/pluto-1.0.2/portal/src/java/org/apache/pluto/portlet/admin/services/DeployWarService.java Sun Aug 27 16:55:41 2006
@@ -37,9 +37,13 @@
import javax.portlet.ActionResponse;
import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.PortletDiskFileUpload;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.portlet.PortletFileUpload;
import org.apache.pluto.descriptors.portlet.PortletDD;
+//import org.apache.pluto.driver.portlets.admin.FileUploadPortlet;
import org.apache.pluto.portalImpl.om.entity.impl.PortletApplicationEntityImpl;
import org.apache.pluto.portlet.admin.BaseAdminObject;
import org.apache.pluto.portlet.admin.PlutoAdminConstants;
@@ -86,8 +90,9 @@
* @param request DeployWarService request object.
* @param response DeployWarService response object.
*/
- public String processFileUpload(ActionRequest request, ActionResponse response) {
+ public String processFileUpload(ActionRequest request, ActionResponse response, int mbMaxSize) {
final String METHOD_NAME = "processFileUpload(request,response)";
+ logDebug(METHOD_NAME, "Doing file upload with max upload size = " + mbMaxSize);
String fileName = null;
String serverFileName = null;
boolean modifyWebXml = true;
@@ -96,18 +101,19 @@
if (PortletDiskFileUpload.isMultipartContent(request))
{
- PortletDiskFileUpload dfu = new PortletDiskFileUpload();
+ //Create a factory for disk-based file items
+ FileItemFactory factory = new DiskFileItemFactory();
- //maximum allowed file upload size (10 MB)
- dfu.setSizeMax(10 * 1000 * 1000);
+ //Create a new file upload handler
+ PortletFileUpload pfu = new PortletFileUpload(factory);
- //maximum size in memory (vs disk) (100 KB)
- dfu.setSizeThreshold(100 * 1000);
+ //Set overall request size constraint
+ pfu.setSizeMax(mbMaxSize * 1000 * 1000);
- try
+ try
{
//get the FileItems
- List fileItems = dfu.parseRequest(request);
+ List fileItems = pfu.parseRequest(request);
Iterator iter = fileItems.iterator();
while (iter.hasNext())
{
Modified: portals/pluto/branches/pluto-1.0.2/portal/src/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/portal/src/webapp/WEB-INF/portlet.xml?rev=437476&r1=437475&r2=437476&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/portal/src/webapp/WEB-INF/portlet.xml (original)
+++ portals/pluto/branches/pluto-1.0.2/portal/src/webapp/WEB-INF/portlet.xml Sun Aug 27 16:55:41 2006
@@ -6,6 +6,11 @@
<display-name>Deploy War Portlet</display-name>
<portlet-class>org.apache.pluto.portlet.admin.controller.DeployWarPortlet</portlet-class>
<init-param>
+ <description>Maximum file upload size in megabytes</description>
+ <name>maxuploadsize</name>
+ <value>10</value>
+ </init-param>
+ <init-param>
<name>view_include</name>
<value>/portlets/admin/DeployWarView.jsp</value>
</init-param>
Modified: portals/pluto/branches/pluto-1.0.2/portal/src/webapp/portlets/admin/DeployWarHelp.html
URL: http://svn.apache.org/viewvc/portals/pluto/branches/pluto-1.0.2/portal/src/webapp/portlets/admin/DeployWarHelp.html?rev=437476&r1=437475&r2=437476&view=diff
==============================================================================
--- portals/pluto/branches/pluto-1.0.2/portal/src/webapp/portlets/admin/DeployWarHelp.html (original)
+++ portals/pluto/branches/pluto-1.0.2/portal/src/webapp/portlets/admin/DeployWarHelp.html Sun Aug 27 16:55:41 2006
@@ -122,4 +122,9 @@
If deployment of a new portlet causes an error that breaks Pluto, manually <a href="#undeploy">undeploy</a> the portlet
and restart Pluto. Make sure that your web.xml and portlet.xml file is correct and retry the deployment after you
fix any problems.
+</p>
+<p class="portlet-font">
+If deployment of a new portlet is prevented because the size of the portlet war is greater than the maximum size allowed (10 MB by default),
+change the 'maxuploadsize' init-param in Pluto's portlet.xml in <CATALINA_HOME>/webapps/pluto/WEB-INF to a size that encompasses your
+war file. The value needs to be in megabytes. Also, you need to restart the server in order for this new value to take effect.
</p>