bug 373336: Fixed service lookup when "osgi.jndi.service.name" is used and it contains "/" in the name.
diff --git a/framework/src/main/java/org/eclipse/gemini/naming/OSGiURLParser.java b/framework/src/main/java/org/eclipse/gemini/naming/OSGiURLParser.java
index 5367502..21e496c 100644
--- a/framework/src/main/java/org/eclipse/gemini/naming/OSGiURLParser.java
+++ b/framework/src/main/java/org/eclipse/gemini/naming/OSGiURLParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle.
+ * Copyright (c) 2010, 2012 Oracle.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
@@ -80,7 +80,11 @@
private void parseURLData(final String prefix) {
String urlData = m_osgiURL.substring(prefix.length());
- int indexOfSlash = urlData.indexOf("/");
+ if ('/' == urlData.charAt(0)) {
+ throw new IllegalStateException(
+ "URL did not conform to the OSGi URL Syntax - No Service Interface specified");
+ }
+ int indexOfSlash = urlData.indexOf("/(");
if (indexOfSlash != -1) {
// interpret everything after the slash to be an OSGi filter
// string
diff --git a/org.eclipse.gemini.naming.utests/src/test/java/org/eclipse/gemini/naming/OSGiURLParserTestCase.java b/org.eclipse.gemini.naming.utests/src/test/java/org/eclipse/gemini/naming/OSGiURLParserTestCase.java
index 5b4c2f2..eafb3df 100644
--- a/org.eclipse.gemini.naming.utests/src/test/java/org/eclipse/gemini/naming/OSGiURLParserTestCase.java
+++ b/org.eclipse.gemini.naming.utests/src/test/java/org/eclipse/gemini/naming/OSGiURLParserTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Oracle.
+ * Copyright (c) 2010, 2012 Oracle.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
@@ -49,21 +49,49 @@
urlParserServiceList.hasFilter());
assertTrue("Parser did not correctly interpret URL, servicelist",
urlParserServiceList.isServiceListURL());
+
+
+ OSGiURLParser urlParserJndiName =
+ new OSGiURLParser("osgi:service/another/TestService");
+ // should return without exception
+ urlParserJndiName.parse();
+ // verify correct information was parsed
+ assertEquals("Parser did not correctly return service interface",
+ "another/TestService", urlParserJndiName.getServiceInterface());
+ assertNull("Parser did not correctly return a null filter", urlParserJndiName.getFilter());
+ assertFalse("Parser did not correctly parse URL, no filter present",
+ urlParserJndiName.hasFilter());
+ assertFalse("Parser did not correctly interpret URL, servicelist",
+ urlParserJndiName.isServiceListURL());
}
public void testParseFilter() throws Exception {
- OSGiURLParser urlParser = new OSGiURLParser("osgi:service/com.oracle.TestService/testFilter");
+ OSGiURLParser urlParser = new OSGiURLParser("osgi:service/com.oracle.TestService/(testFilter)");
// should return without exception
urlParser.parse();
// verify correct information was parsed
assertEquals("Parser did not correctly return service interface",
"com.oracle.TestService", urlParser.getServiceInterface());
- assertEquals("Parser did not correctly return the expected filter",
- "testFilter", urlParser.getFilter());
assertTrue("Parser did not correctly parse URL, filter present",
urlParser.hasFilter());
+ assertEquals("Parser did not correctly return the expected filter",
+ "(testFilter)", urlParser.getFilter());
assertFalse("Parser did not correctly interpret URL, no servicelist",
urlParser.isServiceListURL());
+
+
+ OSGiURLParser urlParserJndiName = new OSGiURLParser("osgi:service/another/TestService/(testFilter)");
+ // should return without exception
+ urlParserJndiName.parse();
+ // verify correct information was parsed
+ assertEquals("Parser did not correctly return service interface",
+ "another/TestService", urlParserJndiName.getServiceInterface());
+ assertTrue("Parser did not correctly parse URL, filter present",
+ urlParserJndiName.hasFilter());
+ assertEquals("Parser did not correctly return the expected filter",
+ "(testFilter)", urlParserJndiName.getFilter());
+ assertFalse("Parser did not correctly interpret URL, no servicelist",
+ urlParserJndiName.isServiceListURL());
}
public void testParseError() throws Exception {