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-94f89814c4df
ccm-docs
jensp 2017-04-19 06:18:41 +00:00
parent 8b308f4fa4
commit 7798f38c1f
5 changed files with 39 additions and 10 deletions

View File

@ -20,7 +20,6 @@ package com.arsdigita.cms.ui.assets.forms;
import com.arsdigita.bebop.BoxPanel; import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.FormSection;
import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Text; 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.AssetForm;
import com.arsdigita.cms.ui.assets.AssetPane; import com.arsdigita.cms.ui.assets.AssetPane;
import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.globalization.GlobalizedMessage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import javax.activation.MimeType;
import org.librecms.CmsConstants; import org.librecms.CmsConstants;
import org.librecms.assets.BinaryAsset; import org.librecms.assets.BinaryAsset;
import org.librecms.contentsection.Asset; import org.librecms.contentsection.Asset;
@ -95,6 +95,8 @@ public abstract class BinaryAssetForm extends AssetForm {
panel.add(fileUpload); panel.add(fileUpload);
add(panel); add(panel);
setEncType(CmsConstants.FORM_ENCTYPE_MULTIPART);
} }
@Override @Override
@ -217,6 +219,7 @@ public abstract class BinaryAssetForm extends AssetForm {
throw new FormProcessException(ex); throw new FormProcessException(ex);
} }
binaryAsset.setData(data); binaryAsset.setData(data);
binaryAsset.setFileName(fileUpload.getFileName(event));
binaryAsset.setSize(data.length); binaryAsset.setSize(data.length);
binaryAsset.setMimeType(fileUpload.getMimeType(event)); binaryAsset.setMimeType(fileUpload.getMimeType(event));

View File

@ -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_ASSET = "asset-";
public static final String FOLDER_BROWSER_KEY_PREFIX_ITEM = "item-"; 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 * Constant string used as key for creating service package as a legacy
* application. * application.

View File

@ -49,7 +49,10 @@ import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestWrapper;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.ParserConfigurationException; 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 * calling generateXML on each. Does NOT do the rendering. If the HTTP
* response has already been committed, does not build the XML document. * 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 * @return a DOM ready for rendering, or null if the response has already
* been committed. * been committed.
* @throws javax.servlet.ServletException
* *
* @post res.isCommitted() == (return == null)
*/ */
public Document buildDocument(HttpServletRequest req, public Document buildDocument(final HttpServletRequest req,
HttpServletResponse res) final HttpServletResponse res)
throws ServletException { throws ServletException {
try { try {
Document doc = new Document(); 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 // only generate XML document if the response is not already
// committed // 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 * 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. * component is told to add its state parameters to the page's state model.

View File

@ -172,7 +172,10 @@ public abstract class BaseServlet extends HttpServlet {
getServletConfig().getServletName(), getServletConfig().getServletName(),
getClass().getName()); getClass().getName());
internalService(request, response); final HttpServletRequest wrappedRequest = DispatcherHelper
.maybeWrapRequest(request);
internalService(wrappedRequest, response);
} }
private URL getRequestURL(final HttpServletRequest request) { private URL getRequestURL(final HttpServletRequest request) {

View File

@ -19,6 +19,7 @@
package com.arsdigita.web; package com.arsdigita.web;
import com.arsdigita.dispatcher.DispatcherHelper; import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.dispatcher.MultipartHttpServletRequest;
import com.arsdigita.ui.UI; import com.arsdigita.ui.UI;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
@ -272,7 +273,7 @@ public class CCMDispatcherServlet extends BaseServlet {
getServletContext(), context); getServletContext(), context);
forward(getServletContext().getRequestDispatcher(target), forward(getServletContext().getRequestDispatcher(target),
request, DispatcherHelper.restoreOriginalRequest(request),
response); response);
} }