You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2010/05/25 22:36:09 UTC
svn commit: r948200 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-api/src:
main/java/org/apache/axiom/util/stax/xop/XOPUtils.java
test/java/org/apache/axiom/util/stax/xop/XOPUtilsTest.java
Author: veithen
Date: Tue May 25 20:36:08 2010
New Revision: 948200
URL: http://svn.apache.org/viewvc?rev=948200&view=rev
Log:
When converting from a content ID to a cid URL, limit percent-encoding to what is strictly necessary. URLEncoder#encode causes an interop issue with Sun's SAAJ implementation.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPUtilsTest.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPUtils.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPUtils.java?rev=948200&r1=948199&r2=948200&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPUtils.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPUtils.java Tue May 25 20:36:08 2010
@@ -22,7 +22,6 @@ package org.apache.axiom.util.stax.xop;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
-import java.net.URLEncoder;
import javax.activation.DataHandler;
import javax.xml.stream.XMLStreamReader;
@@ -70,17 +69,36 @@ public class XOPUtils {
/**
* Build a cid URL from the given content ID as described in RFC2392.
+ * <p>
+ * Note that this implementation only encodes the percent character (replacing it by "%25"). The
+ * reason is given by the following quotes from RFC3986:
+ * <blockquote>
+ * If a reserved character is
+ * found in a URI component and no delimiting role is known for that character, then it must be
+ * interpreted as representing the data octet corresponding to that character's encoding in
+ * US-ASCII. [...]
+ * <p>
+ * Under normal circumstances, the only time when octets within a URI are percent-encoded is
+ * during the process of producing the URI from its component parts. This is when an
+ * implementation determines which of the reserved characters are to be used as subcomponent
+ * delimiters and which can be safely used as data. [...]
+ * <p>
+ * Because the percent ("%") character serves as the indicator for percent-encoded octets, it
+ * must be percent-encoded as "%25" for that octet to be used as data within a URI.
+ * </blockquote>
+ * <p>
+ * Since RFC2392 doesn't define any subcomponents for the cid scheme and since RFC2045 specifies
+ * that only US-ASCII characters are allowed in content IDs, the percent character (which is
+ * specifically allowed by RFC2045) is the only character that needs URL encoding.
+ * <p>
+ * Another reason to strictly limit the set of characters to be encoded is that some
+ * applications fail to decode cid URLs correctly if they contain percent encoded octets.
*
* @param contentID the content ID (without enclosing angle brackets)
* @return the corresponding URL in the cid scheme
*/
public static String getURLForContentID(String contentID) {
- try {
- return "cid:" + URLEncoder.encode(contentID, "ascii");
- } catch (UnsupportedEncodingException ex) {
- // We should never get here
- throw new Error(ex);
- }
+ return "cid:" + contentID.replaceAll("%", "%25");
}
/**
Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPUtilsTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPUtilsTest.java?rev=948200&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPUtilsTest.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPUtilsTest.java Tue May 25 20:36:08 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.axiom.util.stax.xop;
+
+import junit.framework.TestCase;
+
+public class XOPUtilsTest extends TestCase {
+ public void testGetURLForContentID() {
+ // We should not unnecessarily encode characters such as '@', because some implementations
+ // don't decode cid URLs correctly
+ assertEquals("cid:test@apache.org", XOPUtils.getURLForContentID("test@apache.org"));
+ }
+
+ public void testGetURLForContentIDWithPercent() {
+ // '%' is the only character that really needs encoding
+ assertEquals("cid:xxx%25xxx@apache.org", XOPUtils.getURLForContentID("xxx%xxx@apache.org"));
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/xop/XOPUtilsTest.java
------------------------------------------------------------------------------
svn:eol-style = native