You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ga...@apache.org on 2010/02/09 20:58:45 UTC
svn commit: r908187 - in /incubator/aries/trunk/web/web-urlhandler/src:
main/java/org/apache/aries/web/converter/impl/
main/java/org/apache/aries/web/url/
test/java/org/apache/aries/web/converter/impl/
Author: gawor
Date: Tue Feb 9 19:58:45 2010
New Revision: 908187
URL: http://svn.apache.org/viewvc?rev=908187&view=rev
Log:
ARIES-155: Url handler parameter names are supposed to be case insensitive
Added:
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/CaseInsensitiveMap.java (with props)
Modified:
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/url/WARConnection.java
incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/url/WAR_URLServiceHandler.java
incubator/aries/trunk/web/web-urlhandler/src/test/java/org/apache/aries/web/converter/impl/WabConverterTest.java
Added: incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/CaseInsensitiveMap.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/CaseInsensitiveMap.java?rev=908187&view=auto
==============================================================================
--- incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/CaseInsensitiveMap.java (added)
+++ incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/CaseInsensitiveMap.java Tue Feb 9 19:58:45 2010
@@ -0,0 +1,97 @@
+/*
+ * 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 WARRANTIESOR 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.aries.web.converter.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.aries.web.converter.WarToWabConverter;
+import org.osgi.framework.Constants;
+
+/**
+ * Simple key case-insensitive map where only selected set of keys are
+ * treated in case-insensitive way.
+ */
+public class CaseInsensitiveMap extends HashMap<String, String> {
+
+ private static final Map<String, String> DEFAULT_KEY_MAP = new HashMap<String, String>();
+ static {
+ addKeyMapping(DEFAULT_KEY_MAP, Constants.BUNDLE_SYMBOLICNAME);
+ addKeyMapping(DEFAULT_KEY_MAP, Constants.BUNDLE_VERSION);
+ addKeyMapping(DEFAULT_KEY_MAP, Constants.BUNDLE_MANIFESTVERSION);
+ addKeyMapping(DEFAULT_KEY_MAP, Constants.IMPORT_PACKAGE);
+ addKeyMapping(DEFAULT_KEY_MAP, Constants.BUNDLE_CLASSPATH);
+ addKeyMapping(DEFAULT_KEY_MAP, WarToWabConverter.WEB_CONTEXT_PATH);
+ }
+
+ private static void addKeyMapping(Map<String, String> mappings, String name) {
+ mappings.put(name.toLowerCase(), name);
+ }
+
+ private Map<String, String> keyMap;
+
+ public CaseInsensitiveMap() {
+ this.keyMap = new HashMap<String, String>(DEFAULT_KEY_MAP);
+ }
+
+ public CaseInsensitiveMap(Map<String, String> source) {
+ this();
+ putAll(source);
+ }
+
+ public CaseInsensitiveMap(Properties source) {
+ this();
+ for (Map.Entry<Object, Object> entry : source.entrySet()) {
+ String key = entry.getKey().toString();
+ String value = entry.getValue().toString();
+ put(key, value);
+ }
+ }
+
+ @Override
+ public String put(String name, String value) {
+ return super.put(getMappedName(name), value);
+ }
+
+ @Override
+ public String get(Object name) {
+ if (!(name instanceof String)) {
+ return null;
+ }
+ return super.get(getMappedName((String) name));
+ }
+
+ @Override
+ public boolean containsKey(Object name) {
+ if (!(name instanceof String)) {
+ return false;
+ }
+ return super.containsKey(getMappedName((String) name));
+ }
+
+ private String getMappedName(String name) {
+ String mappedName = keyMap.get(name.toLowerCase());
+ if (mappedName == null) {
+ mappedName = name;
+ }
+ return mappedName;
+ }
+}
+
Propchange: incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/CaseInsensitiveMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/CaseInsensitiveMap.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/CaseInsensitiveMap.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java?rev=908187&r1=908186&r2=908187&view=diff
==============================================================================
--- incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java (original)
+++ incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/converter/impl/WarToWabConverterImpl.java Tue Feb 9 19:58:45 2010
@@ -63,7 +63,7 @@
private static final String DEFAULT_IMPORT_PACKAGE_LIST =
SERVLET_IMPORTS + "," + JSP_IMPORTS;
- private Properties properties;
+ private CaseInsensitiveMap properties;
// InputStream for the new WAB file
private byte[] wabFile;
@@ -80,6 +80,10 @@
private ArrayList<String> classPath;
public WarToWabConverterImpl(InputStreamProvider warFile, String name, Properties properties) throws IOException {
+ this(warFile, name, new CaseInsensitiveMap(properties));
+ }
+
+ public WarToWabConverterImpl(InputStreamProvider warFile, String name, CaseInsensitiveMap properties) throws IOException {
this.properties = properties;
classPath = new ArrayList<String>();
importPackages = new HashSet<String>();
@@ -87,7 +91,7 @@
input = warFile;
this.warName = name;
}
-
+
private void convert() throws IOException {
ZipEntry entry;
@@ -214,7 +218,7 @@
}
protected Manifest updateBundleManifest(Manifest manifest) throws IOException {
- String webCPath = properties.getProperty(WEB_CONTEXT_PATH);
+ String webCPath = properties.get(WEB_CONTEXT_PATH);
if (webCPath == null) {
webCPath = manifest.getMainAttributes().getValue(WEB_CONTEXT_PATH);
}
@@ -239,7 +243,7 @@
private void checkParameter(String parameter) throws IOException {
if (properties.containsKey(parameter)) {
- throw new IOException("Cannot override " + parameter + " parameter when converting a bundle");
+ throw new IOException("Cannot override " + parameter + " header when converting a bundle");
}
}
@@ -257,9 +261,9 @@
// Web-ContextPath
//
- String webCPath = properties.getProperty(WEB_CONTEXT_PATH);
+ String webCPath = properties.get(WEB_CONTEXT_PATH);
if (webCPath == null) {
- throw new IOException(WEB_CONTEXT_PATH + " parameter is required.");
+ throw new IOException(WEB_CONTEXT_PATH + " parameter is missing.");
}
properties.put(WEB_CONTEXT_PATH, addSlash(webCPath));
@@ -276,7 +280,7 @@
// Bundle-ManifestVersion
//
- String manifestVersion = properties.getProperty(Constants.BUNDLE_MANIFESTVERSION);
+ String manifestVersion = properties.get(Constants.BUNDLE_MANIFESTVERSION);
if (manifestVersion == null) {
manifestVersion = manifest.getMainAttributes().getValue(Constants.BUNDLE_MANIFESTVERSION);
if (manifestVersion == null) {
@@ -309,7 +313,7 @@
classpath.addAll(classPath);
// Get the list from the URL and add to classpath (removing duplicates)
- mergePathList(properties.getProperty(Constants.BUNDLE_CLASSPATH), classpath, ",");
+ mergePathList(properties.get(Constants.BUNDLE_CLASSPATH), classpath, ",");
// Get the existing list from the manifest file and add to classpath
// (removing duplicates)
@@ -358,7 +362,7 @@
packages.clear();
// Get the list from the URL and add to classpath (removing duplicates)
- mergePathList(properties.getProperty(Constants.IMPORT_PACKAGE), packages, ",");
+ mergePathList(properties.get(Constants.IMPORT_PACKAGE), packages, ",");
// Get the existing list from the manifest file and add to classpath
// (removing duplicates)
@@ -391,9 +395,9 @@
}
// Take the properties map and add them to the manifest file
- for (Map.Entry<Object, Object> entry : properties.entrySet()) {
- String key = entry.getKey().toString();
- String value = entry.getValue().toString();
+ for (Map.Entry<String, String> entry : properties.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue();
manifest.getMainAttributes().put(new Attributes.Name(key), value);
}
Modified: incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/url/WARConnection.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/url/WARConnection.java?rev=908187&r1=908186&r2=908187&view=diff
==============================================================================
--- incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/url/WARConnection.java (original)
+++ incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/url/WARConnection.java Tue Feb 9 19:58:45 2010
@@ -23,17 +23,17 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
-import java.util.Properties;
import org.apache.aries.web.converter.WarToWabConverter.InputStreamProvider;
+import org.apache.aries.web.converter.impl.CaseInsensitiveMap;
import org.apache.aries.web.converter.impl.WarToWabConverterImpl;
public class WARConnection extends URLConnection
{
private WarToWabConverterImpl converter = null;
- private Properties properties;
+ private CaseInsensitiveMap properties;
- protected WARConnection(URL url, Properties properties) throws MalformedURLException
+ protected WARConnection(URL url, CaseInsensitiveMap properties) throws MalformedURLException
{
super(url);
this.properties = properties;
Modified: incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/url/WAR_URLServiceHandler.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/url/WAR_URLServiceHandler.java?rev=908187&r1=908186&r2=908187&view=diff
==============================================================================
--- incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/url/WAR_URLServiceHandler.java (original)
+++ incubator/aries/trunk/web/web-urlhandler/src/main/java/org/apache/aries/web/url/WAR_URLServiceHandler.java Tue Feb 9 19:58:45 2010
@@ -23,9 +23,9 @@
import java.net.URLConnection;
import java.util.Dictionary;
import java.util.Hashtable;
-import java.util.Properties;
import java.util.StringTokenizer;
+import org.apache.aries.web.converter.impl.CaseInsensitiveMap;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.service.url.AbstractURLStreamHandlerService;
@@ -46,7 +46,7 @@
public URLConnection openConnection(URL url) throws IOException
{
// Create properties object
- Properties properties = new Properties();
+ CaseInsensitiveMap properties = new CaseInsensitiveMap();
if (url.getQuery() != null)
{
String propString = url.getQuery();
Modified: incubator/aries/trunk/web/web-urlhandler/src/test/java/org/apache/aries/web/converter/impl/WabConverterTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/web/web-urlhandler/src/test/java/org/apache/aries/web/converter/impl/WabConverterTest.java?rev=908187&r1=908186&r2=908187&view=diff
==============================================================================
--- incubator/aries/trunk/web/web-urlhandler/src/test/java/org/apache/aries/web/converter/impl/WabConverterTest.java (original)
+++ incubator/aries/trunk/web/web-urlhandler/src/test/java/org/apache/aries/web/converter/impl/WabConverterTest.java Tue Feb 9 19:58:45 2010
@@ -84,7 +84,7 @@
WarToWabConverterImpl sut = new WarToWabConverterImpl(makeTestFile(new byte[0]), WAR_FILE_NAME, properties);
Manifest input = new Manifest();
- input.getMainAttributes().putValue("Import-Package", "com.ibm.test,javax.servlet.http");
+ input.getMainAttributes().putValue(Constants.IMPORT_PACKAGE, "com.ibm.test,javax.servlet.http");
Manifest res = sut.updateManifest(input);
Attributes attrs = res.getMainAttributes();
@@ -94,7 +94,7 @@
"javax.servlet.http,"+
"javax.servlet;version=2.5,"+
JSP_IMPORTS,
- attrs.getValue("Import-Package"));
+ attrs.getValue(Constants.IMPORT_PACKAGE));
}
@Test
@@ -104,7 +104,7 @@
WarToWabConverter.WEB_CONTEXT_PATH, "/test",
Constants.IMPORT_PACKAGE, "javax.servlet.jsp; version=\"[2.0,2.1]\",javax.servlet.jsp.tagext; version=\"[2.0,2.1]\"");
- String actual = attrs.getValue("Import-Package");
+ String actual = attrs.getValue(Constants.IMPORT_PACKAGE);
System.out.println(actual);
assertEquals(
"javax.servlet.jsp; version=\"[2.0,2.1]\"," +
@@ -161,6 +161,19 @@
}
@Test
+ public void testPropertyCaseInsensitiveSupport() throws Exception {
+ Attributes attrs = convertWithProperties(
+ "web-contextpath", "WebFiles",
+ "bundle-VErsion", "1.0",
+ "import-PACKAGE", "org.apache.aries.test;version=2.5,org.apache.aries.test.eba;version=1.0");
+
+ assertEquals("/WebFiles", attrs.getValue(WarToWabConverter.WEB_CONTEXT_PATH));
+ assertEquals("1.0", attrs.getValue(Constants.BUNDLE_VERSION));
+ assertEquals("org.apache.aries.test;version=2.5,org.apache.aries.test.eba;version=1.0," + DEFAULT_IMPORTS,
+ attrs.getValue(Constants.IMPORT_PACKAGE));
+ }
+
+ @Test
public void testBundleContextPathOverride() throws Exception {
Manifest m = new Manifest();
Attributes attrs = m.getMainAttributes();