CCM NG/ccm-core: Bugfixes for handeling or wrapped ServletRequests and Multipart requests
CCM NG/ccm-cms: Base form for binary assets now works git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4682 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
8b308f4fa4
commit
7798f38c1f
|
|
@ -20,7 +20,6 @@ package com.arsdigita.cms.ui.assets.forms;
|
|||
|
||||
import com.arsdigita.bebop.BoxPanel;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.FormSection;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.Text;
|
||||
|
|
@ -30,13 +29,14 @@ import com.arsdigita.cms.ui.FileUploadSection;
|
|||
import com.arsdigita.cms.ui.assets.AssetForm;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import javax.activation.MimeType;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.BinaryAsset;
|
||||
import org.librecms.contentsection.Asset;
|
||||
|
|
@ -95,6 +95,8 @@ public abstract class BinaryAssetForm extends AssetForm {
|
|||
panel.add(fileUpload);
|
||||
|
||||
add(panel);
|
||||
|
||||
setEncType(CmsConstants.FORM_ENCTYPE_MULTIPART);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -217,6 +219,7 @@ public abstract class BinaryAssetForm extends AssetForm {
|
|||
throw new FormProcessException(ex);
|
||||
}
|
||||
binaryAsset.setData(data);
|
||||
binaryAsset.setFileName(fileUpload.getFileName(event));
|
||||
binaryAsset.setSize(data.length);
|
||||
|
||||
binaryAsset.setMimeType(fileUpload.getMimeType(event));
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ public class CmsConstants {
|
|||
public static final String FOLDER_BROWSER_KEY_PREFIX_ASSET = "asset-";
|
||||
public static final String FOLDER_BROWSER_KEY_PREFIX_ITEM = "item-";
|
||||
|
||||
public static final String FORM_ENCTYPE_MULTIPART = "multipart/form-data";
|
||||
|
||||
/**
|
||||
* Constant string used as key for creating service package as a legacy
|
||||
* application.
|
||||
|
|
|
|||
|
|
@ -49,7 +49,10 @@ import java.util.SortedMap;
|
|||
import java.util.TreeMap;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletRequestWrapper;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
|
|
@ -712,17 +715,24 @@ public class Page extends SimpleComponent implements Container {
|
|||
* calling generateXML on each. Does NOT do the rendering. If the HTTP
|
||||
* response has already been committed, does not build the XML document.
|
||||
*
|
||||
* @param req
|
||||
* @param res
|
||||
* @return a DOM ready for rendering, or null if the response has already
|
||||
* been committed.
|
||||
* @throws javax.servlet.ServletException
|
||||
*
|
||||
* @post res.isCommitted() == (return == null)
|
||||
*/
|
||||
public Document buildDocument(HttpServletRequest req,
|
||||
HttpServletResponse res)
|
||||
public Document buildDocument(final HttpServletRequest req,
|
||||
final HttpServletResponse res)
|
||||
throws ServletException {
|
||||
try {
|
||||
Document doc = new Document();
|
||||
PageState state = process(req, res);
|
||||
|
||||
final ServletRequest request = unwrapRequest(req);
|
||||
if (!(request instanceof HttpServletRequest)) {
|
||||
throw new ServletException("Request is not a HttpServletRequest.");
|
||||
}
|
||||
final PageState state = process((HttpServletRequest) request, res);
|
||||
|
||||
// only generate XML document if the response is not already
|
||||
// committed
|
||||
|
|
@ -740,6 +750,16 @@ public class Page extends SimpleComponent implements Container {
|
|||
}
|
||||
}
|
||||
|
||||
private ServletRequest unwrapRequest(final HttpServletRequest request) {
|
||||
|
||||
ServletRequest current = request;
|
||||
while (current instanceof ServletRequestWrapper) {
|
||||
current = ((ServletRequestWrapper) current).getRequest();
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes building the page. The tree of components is traversed and each
|
||||
* component is told to add its state parameters to the page's state model.
|
||||
|
|
|
|||
|
|
@ -172,7 +172,10 @@ public abstract class BaseServlet extends HttpServlet {
|
|||
getServletConfig().getServletName(),
|
||||
getClass().getName());
|
||||
|
||||
internalService(request, response);
|
||||
final HttpServletRequest wrappedRequest = DispatcherHelper
|
||||
.maybeWrapRequest(request);
|
||||
|
||||
internalService(wrappedRequest, response);
|
||||
}
|
||||
|
||||
private URL getRequestURL(final HttpServletRequest request) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package com.arsdigita.web;
|
||||
|
||||
import com.arsdigita.dispatcher.DispatcherHelper;
|
||||
import com.arsdigita.dispatcher.MultipartHttpServletRequest;
|
||||
import com.arsdigita.ui.UI;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
|
|
@ -272,7 +273,7 @@ public class CCMDispatcherServlet extends BaseServlet {
|
|||
getServletContext(), context);
|
||||
|
||||
forward(getServletContext().getRequestDispatcher(target),
|
||||
request,
|
||||
DispatcherHelper.restoreOriginalRequest(request),
|
||||
response);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue