Skip to content
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

Use proper XML #30

Merged
merged 1 commit into from
Nov 3, 2020
Merged
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
16 changes: 6 additions & 10 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@cs-ware.de>
* http://code.google.com/p/gwtupload
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -76,15 +77,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;
@@ -439,13 +435,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) {
@@ -1176,7 +1173,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();
Original file line number Diff line number Diff line change
@@ -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;

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

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

public String getPostResponse() {
public XMLResponse getPostResponse() {
return postResponse;
}
}
26 changes: 13 additions & 13 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@cs-ware.de>
* http://code.google.com/p/gwtupload
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -148,6 +149,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 {
@@ -159,7 +161,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
@@ -172,20 +175,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);
@@ -197,24 +200,21 @@ 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, postResponse);
finish(request, xmlResponse);

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