Author: jacopoc
Date: Mon Sep 19 12:03:13 2016 New Revision: 1761424 URL: http://svn.apache.org/viewvc?rev=1761424&view=rev Log: Improved: a series of cleanup mostly related to no more necessary handling of default encoding for the requests and some fine tuning of ControlFilter settings; removed no more used code. Modified: ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/view/SimpleContentViewHandler.java ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java ofbiz/trunk/specialpurpose/cmssite/src/main/java/org/apache/ofbiz/cmssite/multisite/WebSiteFilter.java ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/WEB-INF/web.xml ofbiz/trunk/specialpurpose/solr/webapp/solr/WEB-INF/controller.xml Modified: ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/view/SimpleContentViewHandler.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/view/SimpleContentViewHandler.java?rev=1761424&r1=1761423&r2=1761424&view=diff ============================================================================== --- ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/view/SimpleContentViewHandler.java (original) +++ ofbiz/trunk/applications/content/src/main/java/org/apache/ofbiz/content/view/SimpleContentViewHandler.java Mon Sep 19 12:03:13 2016 @@ -57,15 +57,10 @@ public class SimpleContentViewHandler ex public static final String module = SimpleContentViewHandler.class.getName(); private String rootDir = null; private String https = null; - private String defaultCharset = null; public void init(ServletContext context) throws ViewHandlerException { rootDir = context.getRealPath("/"); https = (String) context.getAttribute("https"); - defaultCharset = context.getInitParameter("charset"); - if (UtilValidate.isEmpty(defaultCharset)) { - defaultCharset = "UTF-8"; - } } /** * @see org.apache.ofbiz.webapp.view.ViewHandler#render(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) @@ -131,10 +126,10 @@ public class SimpleContentViewHandler ex // DEJ20080717: why are we rendering the DataResource directly instead of rendering the content? ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, dataResourceId, https, webSiteId, locale, rootDir); ByteArrayInputStream bais = new ByteArrayInputStream(byteBuffer.array()); - // setup chararcter encoding and content type + // setup character encoding and content type String charset = dataResource.getString("characterSetId"); if (UtilValidate.isEmpty(charset)) { - charset = defaultCharset; + charset = encoding; } if (UtilValidate.isEmpty(mimeTypeId)) { mimeTypeId = DataResourceWorker.getMimeType(dataResource); Modified: ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java?rev=1761424&r1=1761423&r2=1761424&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java (original) +++ ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/WebAppUtil.java Mon Sep 19 12:03:13 2016 @@ -22,7 +22,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -144,17 +143,6 @@ public final class WebAppUtil { return dispatcher; } - public static void setCharacterEncoding(ServletRequest request) throws UnsupportedEncodingException { - String charset = request.getServletContext().getInitParameter("charset"); - if (UtilValidate.isEmpty(charset)) charset = request.getCharacterEncoding(); - if (UtilValidate.isEmpty(charset)) charset = "UTF-8"; - if (Debug.verboseOn()) Debug.logVerbose("The character encoding of the request is: [" + request.getCharacterEncoding() + "]. The character encoding we will use for the request is: [" + charset + "]", module); - - if (!"none".equals(charset)) { - request.setCharacterEncoding(charset); - } - } - public static void setAttributesFromRequestBody(ServletRequest request) { // read the body (for JSON requests) and set the parameters as attributes: Map<String, Object> requestBodyMap = null; Modified: ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java?rev=1761424&r1=1761423&r2=1761424&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java (original) +++ ofbiz/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java Mon Sep 19 12:03:13 2016 @@ -22,7 +22,6 @@ import static org.apache.ofbiz.base.util import java.io.IOException; import java.io.Serializable; -import java.io.UnsupportedEncodingException; import java.net.URL; import java.security.cert.X509Certificate; import java.util.Enumeration; @@ -41,7 +40,6 @@ import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.SSLUtil; import org.apache.ofbiz.base.util.StringUtil; import org.apache.ofbiz.base.util.UtilCodec; -import org.apache.ofbiz.base.util.UtilFormatOut; import org.apache.ofbiz.base.util.UtilGenerics; import org.apache.ofbiz.base.util.UtilHttp; import org.apache.ofbiz.base.util.UtilMisc; @@ -76,7 +74,6 @@ public class RequestHandler { private final URL controllerConfigURL; private final boolean trackServerHit; private final boolean trackVisit; - private final String charset; public static RequestHandler getRequestHandler(ServletContext servletContext) { RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_"); @@ -101,7 +98,6 @@ public class RequestHandler { this.trackServerHit = !"false".equalsIgnoreCase(context.getInitParameter("track-serverhit")); this.trackVisit = !"false".equalsIgnoreCase(context.getInitParameter("track-visit")); - this.charset = context.getInitParameter("charset"); } public ConfigXMLReader.ControllerConfig getControllerConfig() { @@ -923,33 +919,21 @@ public class RequestHandler { long viewStartTime = System.currentTimeMillis(); - // setup character encoding and content type - String charset = UtilFormatOut.checkEmpty(this.charset, req.getCharacterEncoding(), "UTF-8"); - + // setup character encoding and content type of the response: + // encoding/charset: use the one set in the view or, if not set, the one set in the request + // content type: use the one set in the view or, if not set, use "text/html" + String charset = req.getCharacterEncoding(); String viewCharset = viewMap.encoding; //NOTE: if the viewCharset is "none" then no charset will be used if (UtilValidate.isNotEmpty(viewCharset)) { charset = viewCharset; } - - if (!"none".equals(charset)) { - try { - req.setCharacterEncoding(charset); - } catch (UnsupportedEncodingException e) { - throw new RequestHandlerException("Could not set character encoding to " + charset, e); - } catch (IllegalStateException e) { - Debug.logInfo(e, "Could not set character encoding to " + charset + ", something has probably already committed the stream", module); - } - } - - // setup content type String contentType = "text/html"; String viewContentType = viewMap.contentType; if (UtilValidate.isNotEmpty(viewContentType)) { contentType = viewContentType; } - - if (charset.length() > 0 && !"none".equals(charset)) { + if (UtilValidate.isNotEmpty(charset) && !"none".equals(charset)) { resp.setContentType(contentType + "; charset=" + charset); } else { resp.setContentType(contentType); Modified: ofbiz/trunk/specialpurpose/cmssite/src/main/java/org/apache/ofbiz/cmssite/multisite/WebSiteFilter.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/cmssite/src/main/java/org/apache/ofbiz/cmssite/multisite/WebSiteFilter.java?rev=1761424&r1=1761423&r2=1761424&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/cmssite/src/main/java/org/apache/ofbiz/cmssite/multisite/WebSiteFilter.java (original) +++ ofbiz/trunk/specialpurpose/cmssite/src/main/java/org/apache/ofbiz/cmssite/multisite/WebSiteFilter.java Mon Sep 19 12:03:13 2016 @@ -47,7 +47,6 @@ import org.apache.ofbiz.security.Securit import org.apache.ofbiz.security.SecurityConfigurationException; import org.apache.ofbiz.security.SecurityFactory; import org.apache.ofbiz.service.LocalDispatcher; -import org.apache.ofbiz.webapp.WebAppUtil; import org.apache.ofbiz.webapp.control.RequestHandler; import org.apache.ofbiz.webapp.stats.VisitHandler; @@ -77,16 +76,8 @@ public class WebSiteFilter implements Fi Delegator delegator = (Delegator) httpRequest.getSession().getServletContext().getAttribute("delegator"); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); - WebAppUtil.setCharacterEncoding(request); - WebAppUtil.setAttributesFromRequestBody(request); - - // set the web context in the request for future use - dispatcher = WebAppUtil.makeWebappDispatcher(session.getServletContext(), delegator); setWebContextObjects(httpRequest, httpResponse, delegator, dispatcher); - request.setAttribute("servletContext", httpRequest.getSession().getServletContext()); - request.setAttribute("delegator", delegator); - GenericValue webSite = null; try { if (UtilValidate.isNotEmpty(webSiteAlias) && UtilValidate.isEmpty(webSite)) { Modified: ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/WEB-INF/web.xml?rev=1761424&r1=1761423&r2=1761424&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/WEB-INF/web.xml (original) +++ ofbiz/trunk/specialpurpose/cmssite/webapp/cmssite/WEB-INF/web.xml Mon Sep 19 12:03:13 2016 @@ -49,7 +49,7 @@ under the License. </init-param> <init-param> <param-name>redirectPath</param-name> - <param-value>/control/main</param-value> + <param-value>/cms</param-value> </init-param> </filter> <filter> Modified: ofbiz/trunk/specialpurpose/solr/webapp/solr/WEB-INF/controller.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/solr/webapp/solr/WEB-INF/controller.xml?rev=1761424&r1=1761423&r2=1761424&view=diff ============================================================================== --- ofbiz/trunk/specialpurpose/solr/webapp/solr/WEB-INF/controller.xml (original) +++ ofbiz/trunk/specialpurpose/solr/webapp/solr/WEB-INF/controller.xml Mon Sep 19 12:03:13 2016 @@ -8,9 +8,6 @@ <description>Solr Configuration File</description> - <handler name="simplecontent" type="view" class="org.apache.ofbiz.content.view.SimpleContentViewHandler"/> - <handler name="jsp" type="view" class="org.apache.ofbiz.ecommerce.webapp.view.JspViewHandler"/> - <!-- Events to run on every request before security (chains exempt) --> <preprocessor> <event name="checkExternalLoginKey" type="java" path="org.apache.ofbiz.webapp.control.LoginWorker" invoke="checkExternalLoginKey" /> |
Free forum by Nabble | Edit this page |