[xwiki-commits] r1023 - in xwiki/trunk/src/main: java/com/xpn/xwiki/doc java/com/xpn/xwiki/plugin/fileupload java/com/xpn/xwiki/web web web/templates
jeremi joslin
jeremi23 at gmail.com
Fri Mar 31 07:01:50 CEST 2006
I don't know if you read xwiki-commits.
You broke the build, maybe you forget to commit a file (XWikiException).
http://build.xpertnet.biz/cc/buildresults/xwiki?log=log20060331062732
Jérémi
On 3/31/06, Nguyen Viet Chung <chungnv at users.forge.objectweb.org> wrote:
> Author: chungnv
> Date: 2006-03-31 06:19:54 +0200 (Fri, 31 Mar 2006)
> New Revision: 1023
>
> Removed:
> xwiki/trunk/src/main/web/xwiki.js
> Modified:
> xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
> xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java
> xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
> xwiki/trunk/src/main/java/com/xpn/xwiki/web/UploadAction.java
> xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java
> xwiki/trunk/src/main/web/templates/attach.vm
> Log:
> fixed bug Xwiki-170 Java heap space OutOfMemory when upload big file and delete big file .
>
> Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
> ===================================================================
> --- xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java 2006-03-31 01:04:11 UTC (rev 1022)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java 2006-03-31 04:19:54 UTC (rev 1023)
> @@ -39,10 +39,7 @@
> import com.xpn.xwiki.render.XWikiVelocityRenderer;
> import com.xpn.xwiki.store.XWikiStoreInterface;
> import com.xpn.xwiki.util.Util;
> -import com.xpn.xwiki.web.EditForm;
> -import com.xpn.xwiki.web.ObjectAddForm;
> -import com.xpn.xwiki.web.PrepareEditForm;
> -import com.xpn.xwiki.web.Utils;
> +import com.xpn.xwiki.web.*;
> import org.apache.commons.jrcs.diff.Diff;
> import org.apache.commons.jrcs.diff.DifferentiationFailedException;
> import org.apache.commons.jrcs.diff.Revision;
> @@ -494,7 +491,7 @@
> URL url = context.getURLFactory().createAttachmentURL(filename, getWeb(), getName(), action, querystring, context);
> return context.getURLFactory().getURL(url, context);
> }
> -
> +
> public String getAttachmentRevisionURL(String filename, String revision, XWikiContext context) {
> URL url = context.getURLFactory().createAttachmentRevisionURL(filename, getWeb(), getName(), revision, null, context);
> return context.getURLFactory().getURL(url, context);
> @@ -1657,9 +1654,17 @@
> // get the translated content
> if (getDatabase() != null)
> context.setDatabase(getDatabase());
> -
> - context.getWiki().getAttachmentStore().saveAttachmentContent(attachment, context, true);
> - } finally {
> + /* File Upload is big can throws Exception ERROR_XWIKI_APP_JAVA_HEAP_SPACE
> + when saveAttachmentContent */
> + context.getWiki().getAttachmentStore().saveAttachmentContent(attachment, context,true);
> + }catch(java.lang.OutOfMemoryError e){
> + context.getWiki().getAttachmentStore().cleanUp(context);
> + context.getWiki().flushCache();
> + throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
> + XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,
> + "Out Of Memory Exception");
> + }
> + finally {
> if (database != null)
> context.setDatabase(database);
> }
> @@ -1687,8 +1692,15 @@
> // get the translated content
> if (getDatabase() != null)
> context.setDatabase(getDatabase());
> + try{
> + context.getWiki().getAttachmentStore().deleteXWikiAttachment(attachment, context, true);
> + }catch(java.lang.OutOfMemoryError e){
> + context.getWiki().getAttachmentStore().cleanUp(context);
> + throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
> + XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,
> + "Out Of Memory Exception");
> + }
>
> - context.getWiki().getAttachmentStore().deleteXWikiAttachment(attachment, context, true);
> } finally {
> if (database != null)
> context.setDatabase(database);
>
> Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java
> ===================================================================
> --- xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java 2006-03-31 01:04:11 UTC (rev 1022)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/plugin/fileupload/FileUploadPlugin.java 2006-03-31 04:19:54 UTC (rev 1023)
> @@ -1,25 +1,25 @@
> -/*
> - * Copyright 2006, XpertNet SARL, and individual contributors as indicated
> - * by the contributors.txt.
> - *
> - * This is free software; you can redistribute it and/or modify it
> - * under the terms of the GNU Lesser General Public License as
> - * published by the Free Software Foundation; either version 2.1 of
> - * the License, or (at your option) any later version.
> - *
> - * This software is distributed in the hope that it will be useful,
> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> - * Lesser General Public License for more details.
> - *
> - * You should have received a copy of the GNU Lesser General Public
> - * License along with this software; if not, write to the Free
> - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> - * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
> - *
> - * @author ludovic
> - * @author sdumitriu
> - */
> +/*
> + * Copyright 2006, XpertNet SARL, and individual contributors as indicated
> + * by the contributors.txt.
> + *
> + * This is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as
> + * published by the Free Software Foundation; either version 2.1 of
> + * the License, or (at your option) any later version.
> + *
> + * This software is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this software; if not, write to the Free
> + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
> + *
> + * @author ludovic
> + * @author sdumitriu
> + */
>
> package com.xpn.xwiki.plugin.fileupload;
>
> @@ -29,10 +29,7 @@
> import java.util.ArrayList;
> import java.util.List;
>
> -import org.apache.commons.fileupload.DefaultFileItem;
> -import org.apache.commons.fileupload.DiskFileUpload;
> -import org.apache.commons.fileupload.FileItem;
> -import org.apache.commons.fileupload.FileUploadException;
> +import org.apache.commons.fileupload.*;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
>
> @@ -72,7 +69,7 @@
> public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
> return new FileUploadPluginApi((FileUploadPlugin) plugin, context);
> }
> -
> +
> /**
> * endRendering to make sure we don't leave files in temp directories
> * @param context Context of the request
> @@ -127,8 +124,9 @@
> fileupload.setSizeMax(uploadMaxSize);
> fileupload.setSizeThreshold(uploadSizeThreashold);
> context.put("fileupload", fileupload);
> + XWikiRequest request = context.getRequest() ;
>
> - if (tempdir!=null) {
> + if (tempdir != null) {
> fileupload.setRepositoryPath(tempdir);
> (new File(tempdir)).mkdirs();
> }
> @@ -137,11 +135,14 @@
> }
>
> try {
> - XWikiRequest request = context.getRequest();
> List list = fileupload.parseRequest(request.getHttpServletRequest());
> - // We store the file list in the context
> + // We store the file list in the context, throw Exception ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE
> context.put("fileuploadlist", list);
> - } catch (FileUploadException e) {
> + }catch (FileUploadBase.SizeLimitExceededException e) {
> + throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
> + XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE,
> + "Exception uploaded file");
> + }catch(FileUploadException e){
> throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
> XWikiException.ERROR_XWIKI_APP_UPLOAD_PARSE_EXCEPTION,
> "Exception while parsing uploaded file", e);
> @@ -185,16 +186,35 @@
> if (fileitem==null)
> return null;
>
> - byte[] data = new byte[(int)fileitem.getSize()];
> - InputStream fileis = null;
> + byte[] data = null ;
> + if(fileitem.getSize() > Integer.MAX_VALUE){
> + data = new byte[Integer.MAX_VALUE] ;
> + }else{
> + try{
> + data = new byte[(int)fileitem.getSize()];
> + }catch(Exception e ){
> + XWikiException exp = new XWikiException(XWikiException.MODULE_XWIKI_APP,
> + XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,"Java Heap Space, Out of memory exception");
> +
> + }
> +
> + }
> try {
> - fileis = fileitem.getInputStream();
> - fileis.read(data);
> - fileis.close();
> + InputStream fileis = fileitem.getInputStream();
> + if(fileis != null){
> + fileis.read(data);
> + fileis.close();
> + }
> +
> } catch (IOException e) {
> + XWikiException exp = new XWikiException(XWikiException.MODULE_XWIKI_APP,
> + XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE,"Java Heap Space, Out of memory exception");
> +
> + /*
> throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
> XWikiException.ERROR_XWIKI_APP_UPLOAD_FILE_EXCEPTION,
> "Exception while reading uploaded parsed file", e);
> + */
> }
> return data;
> }
>
> Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java
> ===================================================================
> --- xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java 2006-03-31 01:04:11 UTC (rev 1022)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/DeleteAttachmentAction.java 2006-03-31 04:19:54 UTC (rev 1023)
> @@ -31,8 +31,8 @@
> XWikiRequest request = context.getRequest();
> XWikiResponse response = context.getResponse();
> XWikiDocument doc = context.getDoc();
> - XWikiAttachment attachment = null;
> - String filename;
> + XWikiAttachment attachment =null;
> + String filename = null;
> String path = request.getPathInfo();
> if (context.getMode() == XWikiContext.MODE_PORTLET)
> filename = request.getParameter("filename");
> @@ -42,14 +42,37 @@
> if (request.getParameter("id") != null) {
> int id = Integer.parseInt(request.getParameter("id"));
> attachment = (XWikiAttachment) doc.getAttachmentList().get(id);
> + doc.deleteAttachment(attachment, context);
> } else {
> - attachment = doc.getAttachment(filename);
> +
> + try{
> + attachment = doc.getAttachment(filename);
> + }catch(Exception e){
> + if(attachment != null){
> + return false ;
> + }
> + }
> + try{
> + doc.deleteAttachment(attachment, context);
> + }catch(XWikiException e){
> + if(e.getCode()==XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE){
> + context.put("message","javaheapspace");
> + return true;
> + }else{
> + e.printStackTrace();
> + }
> + }
> +
> +
> +
> }
>
> - doc.deleteAttachment(attachment, context);
> // forward to attach page
> String redirect = Utils.getRedirect("attach", context);
> sendRedirect(response, redirect);
> return false;
> }
> + public String render(XWikiContext context) throws XWikiException {
> + return "exception";
> + }
> }
>
> Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/UploadAction.java
> ===================================================================
> --- xwiki/trunk/src/main/java/com/xpn/xwiki/web/UploadAction.java 2006-03-31 01:04:11 UTC (rev 1022)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/UploadAction.java 2006-03-31 04:19:54 UTC (rev 1023)
> @@ -35,47 +35,60 @@
> public boolean action(XWikiContext context) throws XWikiException {
> XWikiResponse response = context.getResponse();
> XWikiDocument doc = context.getDoc();
> -
> String username = context.getUser();
> -
> + Object exception = context.get("exception");
> + // check Exception File upload is large
> + if(exception != null){
> + if(exception instanceof XWikiException){
> + XWikiException exp = (XWikiException) exception ;
> + if(exp.getCode() == XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE) {
> + context.put("message","fileuploadislarge");
> + return true ;
> + }
> + }
> + }
> FileUploadPlugin fileupload = (FileUploadPlugin) context.get("fileuploadplugin");
> -
> String filename = fileupload.getFileItem("filename", context);
> - if (filename!=null) {
> - if (filename.indexOf("/") != -1 || filename.indexOf("\\") != -1 || filename.indexOf(";") != -1){
> - context.put("message","notsupportcharacters");
> - return true ;
> - }
> - }
> - byte[] data = fileupload.getFileItemData("filepath", context);
>
> + byte[] data = data = fileupload.getFileItemData("filepath", context);
> if (filename==null) {
> String fname = fileupload.getFileName("filepath", context);
> int i = fname.indexOf("\\");
> if (i==-1)
> - i = fname.indexOf ("/");
> + i = fname.indexOf("/");
> filename = fname.substring(i+1);
> }
> filename = filename.replaceAll("\\+"," ");
> +
> + //XWikiDocument olddoc = (XWikiDocument) doc.clone();
> // Read XWikiAttachment
> XWikiAttachment attachment = doc.getAttachment(filename);
> -
> if (attachment==null) {
> attachment = new XWikiAttachment();
> doc.getAttachmentList().add(attachment);
> }
> attachment.setContent(data);
> attachment.setFilename(filename);
> -
> // TODO: handle Author
> attachment.setAuthor(username);
>
> +
> // Add the attachment to the document
> attachment.setDoc(doc);
>
> // Save the content and the archive
> - doc.saveAttachmentContent(attachment, context);
> -
> + try{
> + doc.saveAttachmentContent(attachment, context);
> + }catch(XWikiException e){
> + // check Exception is ERROR_XWIKI_APP_JAVA_HEAP_SPACE when saving Attachment
> + if(e.getCode() == XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE){
> + context.put("message","javaheapspace");
> + return true ;
> + }else{
> + e.printStackTrace();
> + }
> + }
> + //context.getWiki().saveDocument(doc,olddoc,context);
> // forward to attach page
> String redirect = fileupload.getFileItem("xredirect", context);
> if ((redirect == null)||(redirect.equals("")))
> @@ -83,7 +96,9 @@
> sendRedirect(response, redirect);
> return false;
> }
> +
> public String render(XWikiContext context) throws XWikiException {
> return "exception";
> }
> +
> }
> \ No newline at end of file
>
> Modified: xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java
> ===================================================================
> --- xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java 2006-03-31 01:04:11 UTC (rev 1022)
> +++ xwiki/trunk/src/main/java/com/xpn/xwiki/web/Utils.java 2006-03-31 04:19:54 UTC (rev 1023)
> @@ -38,9 +38,7 @@
> import org.apache.struts.upload.MultipartRequestWrapper;
>
> import javax.servlet.http.HttpServletRequest;
> -import java.io.IOException;
> -import java.io.InputStream;
> -import java.io.UnsupportedEncodingException;
> +import java.io.*;
> import java.net.URL;
> import java.net.URLDecoder;
> import java.net.URLEncoder;
> @@ -428,8 +426,16 @@
> }
> }
> }
> - catch (Exception e) {
> - e.printStackTrace();
> + catch (XWikiException e) {
> + if(e.getCode() ==XWikiException.ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE){
> + /* Check Exception is ERROR_XWIKI_APP_FILE_EXCEPTION_MAXSIZE = true
> + then put Exception so UploadAction can catching and return messenge
> + */
> + context.put("exception",e);
> + }else {
> + e.printStackTrace();
> + }
> +
> }
> return fileupload;
> }
>
> Modified: xwiki/trunk/src/main/web/templates/attach.vm
> ===================================================================
> --- xwiki/trunk/src/main/web/templates/attach.vm 2006-03-31 01:04:11 UTC (rev 1022)
> +++ xwiki/trunk/src/main/web/templates/attach.vm 2006-03-31 04:19:54 UTC (rev 1023)
> @@ -56,8 +56,18 @@
> if (form.filename.value=="")
> form.filename.value = fname;
> else {
> - if (confirm("$msg.get("doyouwanttoreplace") '" + fname + "' ?"))
> + if (confirm("$msg.get("doyouwanttoreplace") '" + fname + "' ?")){
> form.filename.value = fname;
> + }else{
> +
> + fname = form.filename.value;
> + if(fname.indexOf('\\') != -1 || fname.indexOf('/') != -1
> + || fname.indexOf(':') != -1 || fname.indexOf(';') != -1 ){
> + alert("filename cannot contain any of the following characters \n '\\' '/' ':' ';'");
> + return false ;
> + }
> + return true ;
> + }
> }
> return true;
> }
> @@ -73,4 +83,4 @@
> </form>
> </div>
> #template("basefooter.vm")
> -#template("footer.vm")
> +#template("footer.vm")
> \ No newline at end of file
>
> Deleted: xwiki/trunk/src/main/web/xwiki.js
> ===================================================================
> --- xwiki/trunk/src/main/web/xwiki.js 2006-03-31 01:04:11 UTC (rev 1022)
> +++ xwiki/trunk/src/main/web/xwiki.js 2006-03-31 04:19:54 UTC (rev 1023)
> @@ -1,48 +0,0 @@
> -Ajax.XWikiRequest = Class.create();
> -
> -Object.extend(Object.extend(Ajax.XWikiRequest.prototype, Ajax.Request.prototype), {
> - initialize: function(space, docName, options) {
> -
> - this.transport = Ajax.getTransport();
> - this.setOptions(options);
> - this.baseUrl = "/xwiki/bin/view";
> -
> - var onComplete = this.options.onComplete || Prototype.emptyFunction;
> - this.options.onComplete = (function() {
> - this.returnValue(onComplete);
> - //onComplete(this.transport);
> - }).bind(this);
> -
> - this.request(this.generateUrl(space, docName));
> - },
> -
> - generateUrl: function(space, docName){
> - return this.baseUrl + "/" + space + "/" + docName;
> - },
> -
> - returnValue: function(callBack) {
> -
> - if (callBack)
> - callBack(this.transport);
> - else
> - alert("error, callback");
> - }
> -});
> -
> -
> -
> -var XWiki = Class.create();
> -
> -XWiki.prototype = {
> - initialize: function(wikiUrl){this.wikiUrl = wikiUrl;},
> - getSpaces: function(callBack){
> - var params = '';
> - var myAjax = new Ajax.XWikiRequest( "Ajax", "getSpaces", {method: 'get', parameters: params, onComplete: getSpacesCallBack} );
> - },
> -
> - getSpacesCallBack: function(ajaxResponse){
> - var xml = ajaxResponse.responseXML;
> -
> - }
> -}
> -
>
>
>
>
>
> --
> You receive this message as a subscriber of the xwiki-commits at objectweb.org mailing list.
> To unsubscribe: mailto:xwiki-commits-unsubscribe at objectweb.org
> For general help: mailto:sympa at objectweb.org?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>
>
>
--
Blog: http://www.jeremi.info
LinkedIn: https://www.linkedin.com/profile?viewProfile=&key=1437724
Project Manager XWiki: http://www.xwiki.org
skype: jeremi23 -- msn et gtalk : jeremi23 at gmail.com
More information about the Xwiki-notifications
mailing list