Skip to content

Logger logs to err instead of info & Allow Uploads of files > maxint #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.googlecode.gwtupload</groupId>
<artifactId>gwtupload-project</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.4-p1</version>
</parent>

<dependencies>
Expand All @@ -19,6 +19,12 @@
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiChild;
import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/java/gwtupload/client/IUploadStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
import java.util.List;
import java.util.Set;

import gwtupload.client.IUploadStatus.CancelBehavior;

import com.google.appengine.api.datastore.Link;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.i18n.client.Constants;
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/gwtupload/client/IUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public String toString() {
/**
* Size in bytes calculated in the server
*/
public int size = 0;
public long size = 0;

/**
* Used when the server sends a special key to identify the file.
Expand Down Expand Up @@ -143,7 +143,7 @@ public String getCtype() {
return ctype;
}

public int getSize() {
public long getSize() {
return size;
}

Expand All @@ -163,7 +163,7 @@ public void setCtype(String ctype) {
this.ctype = ctype;
}

public void setSize(int size) {
public void setSize(long size) {
this.size = size;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.InputElement;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.FileUpload;

/**
Expand Down
27 changes: 11 additions & 16 deletions core/src/main/java/gwtupload/client/Uploader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2010 Manuel Carrasco Moñino. (manolo at apache/org)
* Copyright 2017 Sven Strickroth <[email protected]>
* http://code.google.com/p/gwtupload
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
Expand All @@ -19,7 +20,6 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.dom.client.AnchorElement;
import com.google.gwt.dom.client.FormElement;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
Expand Down Expand Up @@ -48,7 +48,6 @@
import com.google.gwt.xml.client.Node;
import com.google.gwt.xml.client.NodeList;
import com.google.gwt.xml.client.XMLParser;
import com.google.gwt.xml.client.impl.DOMParseException;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -76,15 +75,10 @@
import static gwtupload.shared.UConsts.TAG_CANCELED;
import static gwtupload.shared.UConsts.TAG_CTYPE;
import static gwtupload.shared.UConsts.TAG_CURRENT_BYTES;
import static gwtupload.shared.UConsts.TAG_FIELD;
import static gwtupload.shared.UConsts.TAG_FILE;
import static gwtupload.shared.UConsts.TAG_FINISHED;
import static gwtupload.shared.UConsts.TAG_KEY;
import static gwtupload.shared.UConsts.TAG_MESSAGE;
import static gwtupload.shared.UConsts.TAG_MSG_END;
import static gwtupload.shared.UConsts.TAG_MSG_GT;
import static gwtupload.shared.UConsts.TAG_MSG_LT;
import static gwtupload.shared.UConsts.TAG_MSG_START;
import static gwtupload.shared.UConsts.TAG_NAME;
import static gwtupload.shared.UConsts.TAG_PERCENT;
import static gwtupload.shared.UConsts.TAG_SIZE;
Expand Down Expand Up @@ -439,13 +433,14 @@ public void onSubmitComplete(SubmitCompleteEvent event) {
updateStatusTimer.cancel();
onSubmitComplete = true;
serverRawResponse = event.getResults();
if (serverRawResponse != null) {
serverRawResponse = serverRawResponse.replaceFirst(".*" + TAG_MSG_START + "([\\s\\S]*?)" + TAG_MSG_END + ".*", "$1");
serverRawResponse = serverRawResponse.replace(TAG_MSG_LT, "<").replace(TAG_MSG_GT, ">").replace("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&nbsp;", " ");
}
try {
// Parse the xml and extract UploadedInfos
Document doc = XMLParser.parse(serverRawResponse);
// for some reason the response is put inside a "pre" tag
if (doc.getDocumentElement().getNodeName().equals("pre")) {
serverRawResponse = doc.getFirstChild().getFirstChild().getNodeValue();
doc = XMLParser.parse(serverRawResponse);
}
// If the server response is a valid xml
parseAjaxResponse(serverRawResponse);
} catch (Exception e) {
Expand Down Expand Up @@ -1144,7 +1139,8 @@ private JavaScriptObject getDataInfo(UploadedInfo info) {
getDataImpl(info.fileUrl, info.field, info.name, Utils.basename(info.name), serverRawResponse, info.message, getStatus().toString(), info.size);
}

private native JavaScriptObject getDataImpl(String url, String inputName, String fileName, String baseName, String serverResponse, String serverMessage, String status, int size) /*-{
@com.google.gwt.core.client.UnsafeNativeLong
private native JavaScriptObject getDataImpl(String url, String inputName, String fileName, String baseName, String serverResponse, String serverMessage, String status, long size) /*-{
return {
url: url,
name: inputName,
Expand Down Expand Up @@ -1176,7 +1172,6 @@ private void parseAjaxResponse(String responseTxt) {
// POST response or FINISHED status
String msg = Utils.getXmlNodeValue(doc, TAG_MESSAGE);
serverMessage.setMessage(msg);
String fld = Utils.getXmlNodeValue(doc, TAG_FIELD);
NodeList list = doc.getElementsByTagName(TAG_FILE);
for (int i = 0, l = list.getLength(); i < l; i++) {
UploadedInfo info = new UploadedInfo();
Expand All @@ -1195,15 +1190,15 @@ private void parseAjaxResponse(String responseTxt) {

String size = Utils.getXmlNodeValue(doc, TAG_SIZE, i);
if (size != null) {
info.setSize(Integer.parseInt(size));
info.setSize(Long.parseLong(size));
}
serverMessage.getUploadedInfos().add(info);
}
}
} catch (Exception e) {
if (responseTxt.toLowerCase().matches("error")) {
// if (responseTxt.toLowerCase().matches("error")) {
error = i18nStrs.uploaderServerError() + "\nAction: " + getServletPath() + "\nException: " + e.getMessage() + responseTxt;
}
// }
}

if (error != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@external GWTUpld;
@external gwt-*;
@external upld*;
@external DecoratedFileUpload*;
@external status*;
@external prgbar*;
@external 'gwt-*';
@external 'upld*';
@external 'DecoratedFileUpload*';
@external 'status*';
@external 'prgbar*';
@external cancel;
@external changed;
@external filename;
Expand All @@ -26,7 +26,7 @@
font-weight: bold;
}

@if user.agent ie6 ie8 ie9 {
@if (is("ie6") || is("ie8") || is("ie9")) {
.GWTUpld .upld-status div.cancel {
width: 14px;
height: 10px;
Expand All @@ -42,12 +42,12 @@
}
}

@sprite .GWTUpld .upld-status div.cancel {
gwt-image: 'imgCancelUpload';
.GWTUpld .upld-status div.cancel {
gwt-sprite: 'imgCancelUpload';
}

@sprite .GWTUpld .upld-status div.cancel:hover {
gwt-image: 'imgCancelUploadHover';
.GWTUpld .upld-status div.cancel:hover {
gwt-sprite: 'imgCancelUploadHover';
}

.GWTUpld .upld-status .filename {
Expand Down Expand Up @@ -86,7 +86,7 @@
padding: 1px;
}

@if user.agent ie6 ie8 ie9 {
@if (is("ie6") || is("ie8") || is("ie9")) {
.GWTUpld .GWTUpld .prgbar-back {
height: 12px;
margin-top: 2px;
Expand All @@ -107,7 +107,7 @@
margin-left: 3px;
}

@if user.agent ie6 ie8 ie9 {
@if (is("ie6") || is("ie8") || is("ie9")) {
.GWTUpld .prgbar-msg {
top: 0px;
left: 4px;
Expand All @@ -134,7 +134,7 @@
opacity: 0.3;
}

@if user.agent ie6 ie8 ie9 {
@if (is("ie6") || is("ie8") || is("ie9")) {
.upld-modal-glass {
filter: literal('alpha(opacity=30)');
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/gwtupload/client/bundle/UploadCss.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public interface UploadCss extends ClientBundle {
public static final UploadCss INSTANCE = GWT.create(UploadCss.class);

@Source("Upload.css")
@Source("Upload.gss")
public CssResource css();

@Source("cancel-upld.gif")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static AbstractUploadListener current(String sessionId) {

protected boolean exceptionTrhown = false;

private String postResponse = null;
private XMLResponse postResponse = null;

protected int frozenTimeout = 60000;

Expand Down Expand Up @@ -160,7 +160,7 @@ public void setException(RuntimeException e) {
save();
}

public void setFinished(String postResponse) {
public void setFinished(XMLResponse postResponse) {
this.postResponse = postResponse;
save();
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public void update(long done, long total, int item) {
}
}

public String getPostResponse() {
public XMLResponse getPostResponse() {
return postResponse;
}
}
31 changes: 16 additions & 15 deletions core/src/main/java/gwtupload/server/UploadAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2010 Manuel Carrasco Moñino. (manolo at apache/org)
* Copyright 2017 Sven Strickroth <[email protected]>
* http://code.google.com/p/gwtupload
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
Expand All @@ -24,9 +25,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
Expand Down Expand Up @@ -148,6 +147,7 @@ public void removeItem(HttpServletRequest request, String fieldName) throws Upl
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
XMLResponse xmlResponse = new XMLResponse();
String parameter = request.getParameter(UConsts.PARAM_REMOVE);
if (parameter != null) {
try {
Expand All @@ -159,7 +159,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
removeItem(request, item);
}
} catch (Exception e) {
renderXmlResponse(request, response, "<" + TAG_ERROR + ">" + e.getMessage() + "</" + TAG_ERROR + ">");
xmlResponse.addResponseTag(TAG_ERROR, e.getMessage());
renderXmlResponse(request, response, xmlResponse);
return;
}
// Remove the item saved in session in the case it was not removed yet
Expand All @@ -172,20 +173,20 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
String error = null;
String message = null;
Map<String, String> tags = new HashMap<String, String>();

XMLResponse xmlResponse = new XMLResponse();
perThreadRequest.set(request);
try {
// Receive the files and form elements, updating the progress status
error = super.parsePostRequest(request, response);
if (error == null) {
// Fill files status before executing user code which could remove session files
getFileItemsSummary(request, tags);
getFileItemsSummary(request, xmlResponse);
// Call to the user code
message = executeAction(request, getMyLastReceivedFileItems(request));
}
} catch (UploadCanceledException e) {
renderXmlResponse(request, response, "<" + TAG_CANCELED + ">true</" + TAG_CANCELED + ">");
xmlResponse.addResponseTag(TAG_CANCELED, "true");
renderXmlResponse(request, response, xmlResponse);
return;
} catch (UploadActionException e) {
logger.info("ExecuteUploadActionException when receiving a file.", e);
Expand All @@ -197,24 +198,24 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
perThreadRequest.set(null);
}

String postResponse = null;
AbstractUploadListener listener = getCurrentListener(request);
if (error != null) {
postResponse = "<" + TAG_ERROR + ">" + error + "</" + TAG_ERROR + ">";
renderXmlResponse(request, response, postResponse);
xmlResponse.addResponseTag(TAG_ERROR, error);
renderXmlResponse(request, response, xmlResponse);
if (listener != null) {
listener.setException(new RuntimeException(error));
}
UploadServlet.removeSessionFileItems(request);
} else {
if (message != null) {
// see issue #139
tags.put("message", "<![CDATA[" + message + "]]>");
xmlResponse.addResponseTag("message", message);
}
postResponse = statusToString(tags);
renderXmlResponse(request, response, postResponse, true);
renderXmlResponse(request, response, xmlResponse, true);
}
finish(request, xmlResponse);
if(listener != null && listener.isFinished()) {
removeCurrentListener(request);
}
finish(request, postResponse);

if (removeSessionFiles) {
removeSessionFileItems(request, removeData);
Expand Down
Loading