Author: fmeschbe
Date: Mon Jun 16 07:16:40 2008
New Revision: 668173
URL: http://svn.apache.org/viewvc?rev=668173&view=rev
Log:
SLING-508 Give parameter decoding another try by trying to get the
servlet container into decoding the URL encoded request parameters
as plain ISO-8859-1. Only after that encoding will we recode all
parameters (also the container parameters) to the encoding defined
by the _charset_ request parameter.
Added:
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/SlingUnsupportedEncodingException.java
Modified:
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/ContainerRequestParameter.java
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/ParameterSupport.java
Modified:
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/ContainerRequestParameter.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/ContainerRequestParameter.java?rev=668173&r1=668172&r2=668173&view=diff
==============================================================================
---
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/ContainerRequestParameter.java
(original)
+++
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/ContainerRequestParameter.java
Mon Jun 16 07:16:40 2008
@@ -27,7 +27,7 @@
*/
public class ContainerRequestParameter extends AbstractRequestParameter {
- private final String value;
+ private String value;
private byte[] content;
@@ -39,8 +39,15 @@
@Override
void setEncoding(String encoding) {
+ // recode this parameter by encoding the string with the current
+ // encoding and decode the bytes with the encoding
+ try {
+ this.value = getString(encoding);
+ } catch (UnsupportedEncodingException uee) {
+ throw new SlingUnsupportedEncodingException(uee);
+ }
+
super.setEncoding(encoding);
- content = null;
}
/**
@@ -100,8 +107,7 @@
*/
public String getString(String encoding)
throws UnsupportedEncodingException {
- // we ignore the provided encoding as we're using the correct encoding
anyway :)
- return value;
+ return new String(this.get(), encoding);
}
/**
Modified:
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/ParameterSupport.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/ParameterSupport.java?rev=668173&r1=668172&r2=668173&view=diff
==============================================================================
---
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/ParameterSupport.java
(original)
+++
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/ParameterSupport.java
Mon Jun 16 07:16:40 2008
@@ -18,6 +18,7 @@
*/
package org.apache.sling.engine.impl.parameters;
+import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
@@ -118,6 +119,18 @@
private void getContainerParameters(ParameterMap parameters) {
+ // SLING-508 Try to force servlet container to decode parameters
+ // as ISO-8859-1 such that we can recode later
+ String encoding = getServletRequest().getCharacterEncoding();
+ if (encoding == null) {
+ encoding = Util.ENCODING_DIRECT;
+ try {
+ getServletRequest().setCharacterEncoding(encoding);
+ } catch (UnsupportedEncodingException uee) {
+ throw new SlingUnsupportedEncodingException(uee);
+ }
+ }
+
final Map<?, ?> pMap = getServletRequest().getParameterMap();
for (Map.Entry<?, ?> entry : pMap.entrySet()) {
@@ -126,7 +139,7 @@
for (int i = 0; i < values.length; i++) {
parameters.addParameter(name, new ContainerRequestParameter(
- values[i], Util.ENCODING_DEFAULT));
+ values[i], encoding));
}
}
Added:
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/SlingUnsupportedEncodingException.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/SlingUnsupportedEncodingException.java?rev=668173&view=auto
==============================================================================
---
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/SlingUnsupportedEncodingException.java
(added)
+++
incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/SlingUnsupportedEncodingException.java
Mon Jun 16 07:16:40 2008
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.engine.impl.parameters;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.sling.api.SlingIOException;
+
+public class SlingUnsupportedEncodingException extends SlingIOException {
+
+ SlingUnsupportedEncodingException(UnsupportedEncodingException uee) {
+ super(uee);
+ }
+
+}