osgi-messages Mailing List for Papoose OSGi Framework
Status: Beta
Brought to you by:
maguro
You can subscribe to this list here.
| 2007 |
Jan
(14) |
Feb
|
Mar
(1) |
Apr
(3) |
May
(1) |
Jun
(11) |
Jul
(12) |
Aug
(12) |
Sep
(20) |
Oct
(8) |
Nov
(3) |
Dec
(6) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(3) |
Feb
(5) |
Mar
(15) |
Apr
|
May
(2) |
Jun
|
Jul
(1) |
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
(4) |
| 2009 |
Jan
(7) |
Feb
(7) |
Mar
(1) |
Apr
(15) |
May
(41) |
Jun
(13) |
Jul
|
Aug
(6) |
Sep
(9) |
Oct
|
Nov
(4) |
Dec
|
| 2010 |
Jan
(1) |
Feb
(35) |
Mar
(2) |
Apr
(3) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <osg...@li...> - 2010-04-20 19:31:11
|
Revision: 268
http://osgi.svn.sourceforge.net/osgi/?rev=268&view=rev
Author: maguro
Date: 2010-04-20 19:31:05 +0000 (Tue, 20 Apr 2010)
Log Message:
-----------
Intermediate checkin
Modified Paths:
--------------
papoose-core/trunk/core/src/main/java/org/papoose/core/BundleController.java
papoose-core/trunk/core/src/main/java/org/papoose/core/BundleManager.java
papoose-core/trunk/core/src/main/java/org/papoose/core/Generation.java
papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/BundleFileStore.java
papoose-core/trunk/tck/tests/src/test/java/org/papoose/tck/core/PapooseFrameworkFactoryTest.java
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/BundleController.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/BundleController.java 2010-04-20 19:30:34 UTC (rev 267)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/BundleController.java 2010-04-20 19:31:05 UTC (rev 268)
@@ -50,6 +50,7 @@
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.SynchronousBundleListener;
import org.osgi.framework.Version;
+
import org.papoose.core.spi.ArchiveStore;
import org.papoose.core.spi.BundleStore;
import org.papoose.core.util.AttributeUtils;
@@ -203,7 +204,7 @@
if (getState() == UNINSTALLED) throw new IllegalStateException("This bundle is uninstalled");
Papoose framework = getFramework();
- BundleGeneration bundleGeneration = (BundleGeneration)getCurrentGeneration();
+ BundleGeneration bundleGeneration = (BundleGeneration) getCurrentGeneration();
framework.requestStart(bundleGeneration, options);
}
@@ -218,7 +219,7 @@
if (getState() == UNINSTALLED) throw new IllegalStateException("This bundle is uninstalled");
Papoose framework = getFramework();
- BundleGeneration bundleGeneration = (BundleGeneration)getCurrentGeneration();
+ BundleGeneration bundleGeneration = (BundleGeneration) getCurrentGeneration();
framework.requestStop(bundleGeneration, options);
}
@@ -356,11 +357,11 @@
if (currentGeneration instanceof BundleGeneration)
{
- bundleGeneration = (BundleGeneration)currentGeneration;
+ bundleGeneration = (BundleGeneration) currentGeneration;
}
else
{
- bundleGeneration = (BundleGeneration)getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
+ bundleGeneration = (BundleGeneration) getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
}
return bundleGeneration.getClassLoader().getResource(name);
@@ -460,16 +461,16 @@
if (currentGeneration instanceof BundleGeneration)
{
- bundleGeneration = (BundleGeneration)currentGeneration;
+ bundleGeneration = (BundleGeneration) currentGeneration;
}
else if (currentGeneration instanceof FragmentGeneration)
{
- FragmentGeneration fragmentGeneration = (FragmentGeneration)currentGeneration;
+ FragmentGeneration fragmentGeneration = (FragmentGeneration) currentGeneration;
bundleGeneration = fragmentGeneration.getHost();
}
else
{
- bundleGeneration = (BundleGeneration)getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
+ bundleGeneration = (BundleGeneration) getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
}
return bundleGeneration.getClassLoader().loadClass(name);
@@ -527,11 +528,11 @@
if (currentGeneration instanceof BundleGeneration)
{
- bundleGeneration = (BundleGeneration)currentGeneration;
+ bundleGeneration = (BundleGeneration) currentGeneration;
}
else
{
- bundleGeneration = (BundleGeneration)getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
+ bundleGeneration = (BundleGeneration) getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
}
return bundleGeneration.getClassLoader().findResources(name);
@@ -665,7 +666,7 @@
if (currentGeneration instanceof BundleGeneration)
{
- BundleGeneration bundleGeneration = (BundleGeneration)currentGeneration;
+ BundleGeneration bundleGeneration = (BundleGeneration) currentGeneration;
for (FragmentGeneration fragment : bundleGeneration.getFragments())
{
@@ -783,7 +784,7 @@
{
if (syncBundleListeners == null) syncBundleListeners = new CopyOnWriteArraySet<SynchronousBundleListener>();
- syncBundleListeners.add((SynchronousBundleListener)bundleListener);
+ syncBundleListeners.add((SynchronousBundleListener) bundleListener);
}
else
{
@@ -918,7 +919,7 @@
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
- ServiceListenerWithFilter that = (ServiceListenerWithFilter)o;
+ ServiceListenerWithFilter that = (ServiceListenerWithFilter) o;
return delegate == that.delegate;
}
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/BundleManager.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/BundleManager.java 2010-04-20 19:30:34 UTC (rev 267)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/BundleManager.java 2010-04-20 19:31:05 UTC (rev 268)
@@ -607,11 +607,14 @@
{
try
{
- long bundleId = bundleCounter.incrementAndGet();
+ while (bundleCounter.get() < bundleStore.getBundleId()) bundleCounter.incrementAndGet();
+ long bundleId = bundleStore.getBundleId();
+
String location = bundleStore.getLocation();
ArchiveStore archiveStore = store.loadArchiveStore(framework, bundleId);
+ // todo: this always seemed kinda a wacky way to do this
archiveStore.assignNativeCodeDescriptions(resolveNativeCodeDependencies(archiveStore.getBundleNativeCodeList()));
confirmRequiredExecutionEnvironment(archiveStore.getBundleRequiredExecutionEnvironment());
@@ -631,6 +634,12 @@
locations.put(location, bundle);
installedbundles.put(bundleId, bundle);
bundles.put(bundleId, bundle);
+
+ bundleStore.markModified();
+
+ generation.setState(Bundle.INSTALLED);
+
+ fireBundleEvent(new BundleEvent(BundleEvent.INSTALLED, bundle));
}
catch (BundleException e)
{
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/Generation.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/Generation.java 2010-04-20 19:30:34 UTC (rev 267)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/Generation.java 2010-04-20 19:31:05 UTC (rev 268)
@@ -21,6 +21,7 @@
import java.util.Enumeration;
import java.util.SortedSet;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;
@@ -35,7 +36,7 @@
{
private final BundleController bundleController;
private final ArchiveStore archiveStore;
- private volatile int state;
+ private volatile int state = Bundle.INSTALLED;
private volatile ProtectionDomain protectionDomain;
protected Generation(BundleController bundleController, ArchiveStore archiveStore)
Modified: papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/BundleFileStore.java
===================================================================
--- papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/BundleFileStore.java 2010-04-20 19:30:34 UTC (rev 267)
+++ papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/BundleFileStore.java 2010-04-20 19:31:05 UTC (rev 268)
@@ -164,6 +164,12 @@
}
}
+ @Override
+ public String toString()
+ {
+ return "[" + bundleId + ", " + location + ", " + bundleRoot + "]";
+ }
+
private void save() throws IOException
{
Properties properties = new Properties();
Modified: papoose-core/trunk/tck/tests/src/test/java/org/papoose/tck/core/PapooseFrameworkFactoryTest.java
===================================================================
--- papoose-core/trunk/tck/tests/src/test/java/org/papoose/tck/core/PapooseFrameworkFactoryTest.java 2010-04-20 19:30:34 UTC (rev 267)
+++ papoose-core/trunk/tck/tests/src/test/java/org/papoose/tck/core/PapooseFrameworkFactoryTest.java 2010-04-20 19:31:05 UTC (rev 268)
@@ -52,8 +52,8 @@
Map<String, String> configuration = new HashMap<String, String>();
configuration.put(Constants.FRAMEWORK_STORAGE, "target/papoose");
- FrameworkFactory factory = new PapooseFrameworkFactory();
- final Framework framework = factory.newFramework(configuration);
+ final FrameworkFactory factory = new PapooseFrameworkFactory();
+ Framework framework = factory.newFramework(configuration);
framework.init();
@@ -77,6 +77,7 @@
framework.stop();
+ framework = factory.newFramework(configuration);
framework.init();
systemBundle = framework.getBundleContext().getBundle(0);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-04-20 19:30:40
|
Revision: 267
http://osgi.svn.sourceforge.net/osgi/?rev=267&view=rev
Author: maguro
Date: 2010-04-20 19:30:34 +0000 (Tue, 20 Apr 2010)
Log Message:
-----------
Minor cleanup
Modified Paths:
--------------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/log/LogServiceImplTest.java
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java 2010-04-13 03:13:32 UTC (rev 266)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java 2010-04-20 19:30:34 UTC (rev 267)
@@ -112,7 +112,6 @@
}
catch (Exception e)
{
- System.err.println(e);
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
Modified: papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java
===================================================================
--- papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java 2010-04-13 03:13:32 UTC (rev 266)
+++ papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java 2010-04-20 19:30:34 UTC (rev 267)
@@ -71,9 +71,9 @@
// papoose(),
compendiumProfile(),
// vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
- // this is necessary to let junit runner not timout the remote process before attaching debugger
+ // this is necessary to let junit runner not timeout the remote process before attaching debugger
// setting timeout to 0 means wait as long as the remote service comes available.
- // starting with version 0.5.0 of PAx Exam this is no longer required as by default the framework tests
+ // starting with version 0.5.0 of PAX Exam this is no longer required as by default the framework tests
// will not be triggered till the framework is not started
// waitForFrameworkStartup()
provision(
@@ -85,6 +85,7 @@
);
}
+ @Test
public void testRegistrations() throws Exception
{
Assert.assertNotNull(bundleContext);
@@ -118,6 +119,7 @@
}
}
+ @Test
public void testResourceAbsolute() throws Exception
{
Assert.assertNotNull(bundleContext);
Modified: papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/log/LogServiceImplTest.java
===================================================================
--- papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/log/LogServiceImplTest.java 2010-04-13 03:13:32 UTC (rev 266)
+++ papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/log/LogServiceImplTest.java 2010-04-20 19:30:34 UTC (rev 267)
@@ -72,9 +72,9 @@
// papoose(),
compendiumProfile(),
// vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
- // this is necessary to let junit runner not timout the remote process before attaching debugger
+ // this is necessary to let junit runner not timeout the remote process before attaching debugger
// setting timeout to 0 means wait as long as the remote service comes available.
- // starting with version 0.5.0 of PAx Exam this is no longer required as by default the framework tests
+ // starting with version 0.5.0 of PAX Exam this is no longer required as by default the framework tests
// will not be triggered till the framework is not started
// waitForFrameworkStartup()
provision(
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-04-13 03:13:39
|
Revision: 266
http://osgi.svn.sourceforge.net/osgi/?rev=266&view=rev
Author: maguro
Date: 2010-04-13 03:13:32 +0000 (Tue, 13 Apr 2010)
Log Message:
-----------
Intermediate checkin
Modified Paths:
--------------
papoose-core/trunk/cnd-perm-admin/pom.xml
papoose-core/trunk/core/pom.xml
papoose-core/trunk/core/src/main/java/org/papoose/core/AbstractArchiveStore.java
papoose-core/trunk/core/src/main/java/org/papoose/core/BundleContextProxy.java
papoose-core/trunk/core/src/main/java/org/papoose/core/BundleController.java
papoose-core/trunk/core/src/main/java/org/papoose/core/BundleGeneration.java
papoose-core/trunk/core/src/main/java/org/papoose/core/BundleManager.java
papoose-core/trunk/core/src/main/java/org/papoose/core/Papoose.java
papoose-core/trunk/core/src/main/java/org/papoose/core/descriptions/LazyActivationDescription.java
papoose-core/trunk/core/src/main/java/org/papoose/core/util/Util.java
papoose-core/trunk/pom.xml
papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/ArchiveFileStore.java
papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/BundleFileStore.java
papoose-core/trunk/tck/bundles/pom.xml
papoose-core/trunk/tck/tests/pom.xml
papoose-core/trunk/test-support/test-bundle/src/main/java/com/acme/impl/Activator.java
Added Paths:
-----------
papoose-core/trunk/tck/bundles/simple/
papoose-core/trunk/tck/bundles/simple/pom.xml
papoose-core/trunk/tck/bundles/simple/src/
papoose-core/trunk/tck/bundles/simple/src/main/
papoose-core/trunk/tck/bundles/simple/src/main/java/
papoose-core/trunk/tck/bundles/simple/src/main/java/com/
papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/
papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/api/
papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/api/AnvilApi.java
papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/impl/
papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/impl/Activator.java
papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/impl/AnvilImpl.java
papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pub/
papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pub/Primary.java
papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pvt/
papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pvt/Hidden.java
papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pvt/Private.java
papoose-core/trunk/tck/bundles/simple/src/main/resources/
papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/
papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/
papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle.properties
papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en.properties
papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en_GB.properties
papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en_GB_welsh.properties
papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_fr.properties
papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_fr_FR.properties
papoose-core/trunk/tck/bundles/simple/src/main/resources/com/
papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/
papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/anvil.xml
papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/resource/
papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/resource/camera.xml
papoose-core/trunk/tck/tests/src/
papoose-core/trunk/tck/tests/src/test/
papoose-core/trunk/tck/tests/src/test/java/
papoose-core/trunk/tck/tests/src/test/java/org/
papoose-core/trunk/tck/tests/src/test/java/org/papoose/
papoose-core/trunk/tck/tests/src/test/java/org/papoose/tck/
papoose-core/trunk/tck/tests/src/test/java/org/papoose/tck/core/
papoose-core/trunk/tck/tests/src/test/java/org/papoose/tck/core/PapooseFrameworkFactoryTest.java
Removed Paths:
-------------
papoose-core/trunk/test-support/test-bundle/src/test/
Modified: papoose-core/trunk/cnd-perm-admin/pom.xml
===================================================================
--- papoose-core/trunk/cnd-perm-admin/pom.xml 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/cnd-perm-admin/pom.xml 2010-04-13 03:13:32 UTC (rev 266)
@@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>cnd-perm-admin</artifactId>
<packaging>jar</packaging>
- <name>Papoose :: OSGi R4 Conditional Permission Admin Service</name>
+ <name>Papoose :: OSGi R4 Conditional Perm Admin Service</name>
<description>OSGi R4 Conditional Permission Admin Service</description>
<build/>
Modified: papoose-core/trunk/core/pom.xml
===================================================================
--- papoose-core/trunk/core/pom.xml 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/core/pom.xml 2010-04-13 03:13:32 UTC (rev 266)
@@ -58,16 +58,16 @@
</dependency>
<dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.papoose.test-support</groupId>
<artifactId>test-support-bundle</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- </dependency>
-
</dependencies>
</project>
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/AbstractArchiveStore.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/AbstractArchiveStore.java 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/AbstractArchiveStore.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -87,7 +87,7 @@
this.bundleSymbolicName = tokens[0];
- String singletonString = Boolean.FALSE.toString();
+ String singletonString = "false";
String fragmentAttachmentString = Constants.FRAGMENT_ATTACHMENT_ALWAYS;
for (int i = 1; i < tokens.length; i++)
{
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/BundleContextProxy.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/BundleContextProxy.java 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/BundleContextProxy.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -21,8 +21,6 @@
import java.lang.ref.WeakReference;
import java.util.Dictionary;
-import org.papoose.core.spi.LocationMapper;
-
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -34,7 +32,10 @@
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
+import org.papoose.core.spi.LocationMapper;
+import org.papoose.core.util.Util;
+
/**
* @version $Revision$ $Date$
*/
@@ -183,7 +184,7 @@
}
else
{
- return "[" + pinned.getBundleId() + "] " + pinned.getSymbolicName() + " - " + pinned.getVersion();
+ return "[" + pinned.getBundleId() + "]:" + Util.bundleStateToString(pinned.getState()) + " " + pinned.getSymbolicName() + " - " + pinned.getVersion();
}
}
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/BundleController.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/BundleController.java 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/BundleController.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -33,13 +33,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import org.papoose.core.spi.ArchiveStore;
-import org.papoose.core.spi.BundleStore;
-import org.papoose.core.util.AttributeUtils;
-import org.papoose.core.util.I18nUtils;
-import org.papoose.core.util.SecurityUtils;
-import org.papoose.core.util.SerialExecutor;
-
import org.osgi.framework.AdminPermission;
import org.osgi.framework.AllServiceListener;
import org.osgi.framework.Bundle;
@@ -57,6 +50,13 @@
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.SynchronousBundleListener;
import org.osgi.framework.Version;
+import org.papoose.core.spi.ArchiveStore;
+import org.papoose.core.spi.BundleStore;
+import org.papoose.core.util.AttributeUtils;
+import org.papoose.core.util.I18nUtils;
+import org.papoose.core.util.SecurityUtils;
+import org.papoose.core.util.SerialExecutor;
+import org.papoose.core.util.Util;
/**
@@ -203,7 +203,7 @@
if (getState() == UNINSTALLED) throw new IllegalStateException("This bundle is uninstalled");
Papoose framework = getFramework();
- BundleGeneration bundleGeneration = (BundleGeneration) getCurrentGeneration();
+ BundleGeneration bundleGeneration = (BundleGeneration)getCurrentGeneration();
framework.requestStart(bundleGeneration, options);
}
@@ -218,7 +218,7 @@
if (getState() == UNINSTALLED) throw new IllegalStateException("This bundle is uninstalled");
Papoose framework = getFramework();
- BundleGeneration bundleGeneration = (BundleGeneration) getCurrentGeneration();
+ BundleGeneration bundleGeneration = (BundleGeneration)getCurrentGeneration();
framework.requestStop(bundleGeneration, options);
}
@@ -309,7 +309,7 @@
{
if (getState() == UNINSTALLED) throw new IllegalStateException("This bundle is uninstalled");
- return new ServiceReference[0]; //To change body of implemented methods use File | Settings | File Templates.
+ return new ServiceReference[0]; //Todo change body of implemented methods use File | Settings | File Templates.
}
/**
@@ -327,7 +327,6 @@
*/
public URL getResource(String name)
{
- SecurityManager sm = System.getSecurityManager();
try
{
SecurityUtils.checkAdminPermission(this, AdminPermission.RESOURCE);
@@ -357,11 +356,11 @@
if (currentGeneration instanceof BundleGeneration)
{
- bundleGeneration = (BundleGeneration) currentGeneration;
+ bundleGeneration = (BundleGeneration)currentGeneration;
}
else
{
- bundleGeneration = (BundleGeneration) getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
+ bundleGeneration = (BundleGeneration)getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
}
return bundleGeneration.getClassLoader().getResource(name);
@@ -461,16 +460,16 @@
if (currentGeneration instanceof BundleGeneration)
{
- bundleGeneration = (BundleGeneration) currentGeneration;
+ bundleGeneration = (BundleGeneration)currentGeneration;
}
else if (currentGeneration instanceof FragmentGeneration)
{
- FragmentGeneration fragmentGeneration = (FragmentGeneration) currentGeneration;
+ FragmentGeneration fragmentGeneration = (FragmentGeneration)currentGeneration;
bundleGeneration = fragmentGeneration.getHost();
}
else
{
- bundleGeneration = (BundleGeneration) getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
+ bundleGeneration = (BundleGeneration)getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
}
return bundleGeneration.getClassLoader().loadClass(name);
@@ -528,11 +527,11 @@
if (currentGeneration instanceof BundleGeneration)
{
- bundleGeneration = (BundleGeneration) currentGeneration;
+ bundleGeneration = (BundleGeneration)currentGeneration;
}
else
{
- bundleGeneration = (BundleGeneration) getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
+ bundleGeneration = (BundleGeneration)getFramework().getBundleManager().getBundle(0).getCurrentGeneration();
}
return bundleGeneration.getClassLoader().findResources(name);
@@ -666,7 +665,7 @@
if (currentGeneration instanceof BundleGeneration)
{
- BundleGeneration bundleGeneration = (BundleGeneration) currentGeneration;
+ BundleGeneration bundleGeneration = (BundleGeneration)currentGeneration;
for (FragmentGeneration fragment : bundleGeneration.getFragments())
{
@@ -773,7 +772,7 @@
@Override
public String toString()
{
- return "[" + getBundleId() + "] " + getSymbolicName() + " - " + getCurrentGeneration().getVersion() + "/" + getGenerations().size();
+ return "[" + getBundleId() + "]:" + Util.bundleStateToString(getState()) + " " + getSymbolicName() + " - " + getCurrentGeneration().getVersion() + "/" + getGenerations().size();
}
void addBundleListener(BundleListener bundleListener)
@@ -784,7 +783,7 @@
{
if (syncBundleListeners == null) syncBundleListeners = new CopyOnWriteArraySet<SynchronousBundleListener>();
- syncBundleListeners.add((SynchronousBundleListener) bundleListener);
+ syncBundleListeners.add((SynchronousBundleListener)bundleListener);
}
else
{
@@ -908,11 +907,6 @@
this.filter = filter;
}
- public Filter getFilter()
- {
- return filter;
- }
-
public void serviceChanged(ServiceEvent event)
{
if (filter.match(event.getServiceReference())) delegate.serviceChanged(event);
@@ -924,7 +918,7 @@
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
- ServiceListenerWithFilter that = (ServiceListenerWithFilter) o;
+ ServiceListenerWithFilter that = (ServiceListenerWithFilter)o;
return delegate == that.delegate;
}
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/BundleGeneration.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/BundleGeneration.java 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/BundleGeneration.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -29,6 +29,7 @@
import org.papoose.core.descriptions.NativeCodeDescription;
import org.papoose.core.spi.ArchiveStore;
import org.papoose.core.util.ToStringCreator;
+import org.papoose.core.util.Util;
/**
@@ -104,13 +105,6 @@
@Override
public String toString()
{
- ToStringCreator creator = new ToStringCreator(this);
-
- creator.append("bundleId", getBundleId());
- creator.append("generation", getGeneration());
- creator.append("symbolicName", getSymbolicName());
- creator.append("version", getVersion());
-
- return creator.toString();
+ return "[" + getBundleId() + "]:" + Util.bundleStateToString(getState()) + " " + getSymbolicName() + " - " + getVersion();
}
}
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/BundleManager.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/BundleManager.java 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/BundleManager.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -52,6 +52,7 @@
import org.osgi.framework.ServiceReference;
import org.osgi.framework.SynchronousBundleListener;
import org.osgi.framework.Version;
+
import org.papoose.core.descriptions.ExportDescription;
import org.papoose.core.descriptions.Extension;
import org.papoose.core.descriptions.FragmentDescription;
@@ -65,7 +66,6 @@
import org.papoose.core.spi.Solution;
import org.papoose.core.spi.Store;
import org.papoose.core.util.SecurityUtils;
-import org.papoose.core.util.ToStringCreator;
/**
@@ -176,7 +176,7 @@
framework.getResolver().added(systemBundle.getCurrentGeneration());
- insertSystemClassLoader((BundleGeneration)systemBundle.getCurrentGeneration());
+ insertSystemClassLoader((BundleGeneration) systemBundle.getCurrentGeneration());
bundleStore.markModified();
@@ -279,8 +279,8 @@
public Bundle installBundle(String location, InputStream inputStream) throws BundleException
{
- LOGGER.entering(CLASS_NAME, "installBundle", new Object[]{location, inputStream});
-
+ LOGGER.entering(CLASS_NAME, "installBundle", new Object[]{ location, inputStream });
+
if (locations.containsKey(location)) return locations.get(location);
long bundleId = bundleCounter.incrementAndGet();
@@ -377,7 +377,7 @@
if (!bundleNativeCodeList.isEmpty())
{
- VersionRange osVersionRange = VersionRange.parseVersionRange((String)framework.getProperty(Constants.FRAMEWORK_OS_VERSION));
+ VersionRange osVersionRange = VersionRange.parseVersionRange((String) framework.getProperty(Constants.FRAMEWORK_OS_VERSION));
nextDescription:
for (NativeCodeDescription description : bundleNativeCodeList)
@@ -405,7 +405,7 @@
{
try
{
- Filter selectionFilter = new DefaultFilter(framework.getParser().parse((String)parameters.get(key)));
+ Filter selectionFilter = new DefaultFilter(framework.getParser().parse((String) parameters.get(key)));
if (!selectionFilter.match(framework.getProperties())) continue nextDescription;
}
catch (InvalidSyntaxException ise)
@@ -426,7 +426,7 @@
{
if (!bundleExecutionEnvironment.isEmpty())
{
- String string = (String)framework.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
+ String string = (String) framework.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
if (string == null) throw new BundleException(Constants.FRAMEWORK_EXECUTIONENVIRONMENT + " not set");
String[] environments = string.split(",");
@@ -448,7 +448,7 @@
try
{
- BundleController bundleController = (BundleController)target;
+ BundleController bundleController = (BundleController) target;
Set<Solution> solutions = framework.getResolver().resolve(bundleController.getCurrentGeneration());
if (solutions.isEmpty()) return false;
@@ -475,8 +475,8 @@
try
{
- BundleController targetController = (BundleController)target;
- BundleGeneration targetGeneration = (BundleGeneration)targetController.getCurrentGeneration();
+ BundleController targetController = (BundleController) target;
+ BundleGeneration targetGeneration = (BundleGeneration) targetController.getCurrentGeneration();
Set<Solution> solutions = framework.getResolver().resolve(targetGeneration, importDescription);
if (solutions.isEmpty()) return null;
@@ -676,7 +676,7 @@
{
if (generation.getArchiveStore().getBundleActivatorClass() != null)
{
- framework.getStartManager().start((BundleGeneration)generation, 0); // todo: this is probably wrong
+ framework.getStartManager().start((BundleGeneration) generation, 0); // todo: this is probably wrong
}
}
}
@@ -765,7 +765,7 @@
if (bundleActivatorClass == null) throw new BundleException("Bundle activator class " + bundleActivatorClassName + " not found");
- final BundleActivator bundleActivator = (BundleActivator)bundleActivatorClass.newInstance();
+ final BundleActivator bundleActivator = (BundleActivator) bundleActivatorClass.newInstance();
bundleController.setBundleActivator(bundleActivator);
@@ -897,8 +897,8 @@
public void uninstall(Bundle bundle) throws BundleException
{
- BundleController bundleController = (BundleController)bundle;
- BundleGeneration bundleGeneration = (BundleGeneration)bundleController.getCurrentGeneration();
+ BundleController bundleController = (BundleController) bundle;
+ BundleGeneration bundleGeneration = (BundleGeneration) bundleController.getCurrentGeneration();
try
{
@@ -916,21 +916,21 @@
}
}
- Set<Generation> unused = new HashSet<Generation>();
+ Set<Generation> unused = new HashSet<Generation>(bundleController.getGenerations().values());
boolean remove = true;
for (Generation generation : bundleController.getGenerations().values())
{
- boolean removed = false;
+ boolean inUse = false;
for (ExportDescription description : generation.getArchiveStore().getExportDescriptions())
{
if (description.getReferenceCount() > 0)
{
- removed = true;
- unused.add(generation);
+ inUse = true;
+ unused.remove(generation);
break;
}
}
- if (removed) remove = false;
+ if (inUse) remove = false;
}
for (Generation generation : unused)
@@ -1000,6 +1000,8 @@
{
assert false;
}
+
+ store.removeBundleStore(bundleId);
}
bundleGeneration.setState(Bundle.UNINSTALLED);
@@ -1103,7 +1105,7 @@
public void fireServiceEvent(ServiceEvent event)
{
ServiceReference reference = event.getServiceReference();
- String[] classes = (String[])reference.getProperty(Constants.OBJECTCLASS);
+ String[] classes = (String[]) reference.getProperty(Constants.OBJECTCLASS);
for (BundleController bundle : installedbundles.values())
{
@@ -1178,7 +1180,7 @@
}
else
{
- BootClasspathManager manager = (BootClasspathManager)framework.getProperty(BootClasspathManager.BOOT_CLASSPATH_MANAGER);
+ BootClasspathManager manager = (BootClasspathManager) framework.getProperty(BootClasspathManager.BOOT_CLASSPATH_MANAGER);
if (manager == null || !manager.isSupported()) throw new BundleException("Boot classpath extensions not supported in this framework configuration");
return new BootClassExtensionGeneration(bundle, archiveStore);
@@ -1225,7 +1227,7 @@
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
- NameVersionKey that = (NameVersionKey)o;
+ NameVersionKey that = (NameVersionKey) o;
//noinspection SimplifiableIfStatement
if (!symbolicName.equals(that.symbolicName)) return false;
@@ -1244,12 +1246,7 @@
@Override
public String toString()
{
- ToStringCreator creator = new ToStringCreator(this);
-
- creator.append("symbolicName", symbolicName);
- creator.append("version", version);
-
- return creator.toString();
+ return "[" + symbolicName + ", " + version + "]";
}
}
}
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/Papoose.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/Papoose.java 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/Papoose.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -562,20 +562,19 @@
private void doStart() throws PapooseException
{
-
+ this.startManager.setStartLevel(startLevel);
}
private void doStop() throws PapooseException
{
- BundleManager manager = getBundleManager();
-
+ this.startManager.setStartLevel(0);
serviceRegistry.stop();
}
@Override
public String toString()
{
- return "[" + frameworkId + "] " + frameworkName + " - " + state;
+ return "[" + frameworkId + "]:" + state + " " + frameworkName;
}
static Papoose getFramework(Integer frameworkId)
@@ -718,7 +717,7 @@
Util.callStart(pojo, this);
- if (LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("Starting " + pojo);
+ if (LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("Started " + pojo);
bootServices.add(pojo);
}
@@ -870,8 +869,6 @@
public void init() throws PapooseException
{
- doInitialize();
-
state = new Starting();
}
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/descriptions/LazyActivationDescription.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/descriptions/LazyActivationDescription.java 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/descriptions/LazyActivationDescription.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -19,6 +19,7 @@
import java.util.Collections;
import java.util.Set;
+
/**
* @version $Revision$ $Date$
*/
@@ -57,4 +58,10 @@
{
this.exclude = exclude;
}
+
+ @Override
+ public String toString()
+ {
+ return (lazyActivation ? "LAZY" : "EAGER");
+ }
}
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/util/Util.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/util/Util.java 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/util/Util.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -37,6 +37,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.papoose.core.FatalError;
@@ -54,6 +55,26 @@
private final static String CLASS_NAME = Util.class.getName();
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ public static String bundleStateToString(int state)
+ {
+ switch (state)
+ {
+ case Bundle.INSTALLED:
+ return "INSTALLED";
+ case Bundle.STARTING:
+ return "STARTING";
+ case Bundle.ACTIVE:
+ return "ACTIVE";
+ case Bundle.STOPPING:
+ return "STOPPING";
+ case Bundle.RESOLVED:
+ return "RESOLVED";
+ case Bundle.UNINSTALLED:
+ return "UNINSTALLED";
+ }
+ return "UNKNOWN";
+ }
+
public static void copy(InputStream input, OutputStream output) throws IOException
{
LOGGER.entering(CLASS_NAME, "copy", new Object[]{ input, output });
Modified: papoose-core/trunk/pom.xml
===================================================================
--- papoose-core/trunk/pom.xml 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/pom.xml 2010-04-13 03:13:32 UTC (rev 266)
@@ -71,6 +71,13 @@
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.8.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.2.0</version>
@@ -91,6 +98,12 @@
<dependency>
<groupId>org.papoose.core</groupId>
+ <artifactId>framework</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.core</groupId>
<artifactId>perm-admin</artifactId>
<version>${pom.version}</version>
</dependency>
@@ -140,8 +153,15 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
Modified: papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/ArchiveFileStore.java
===================================================================
--- papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/ArchiveFileStore.java 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/ArchiveFileStore.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -45,6 +45,7 @@
import org.apache.xbean.classloader.ResourceLocation;
import org.osgi.framework.BundleException;
import org.osgi.framework.InvalidSyntaxException;
+import static org.papoose.core.util.Assert.assertTrue;
import org.papoose.core.AbstractArchiveStore;
import org.papoose.core.L18nResourceBundle;
@@ -54,7 +55,6 @@
import org.papoose.core.util.FileUtils;
import org.papoose.core.util.SecurityUtils;
import org.papoose.core.util.Util;
-import static org.papoose.core.util.Assert.assertTrue;
/**
@@ -510,18 +510,29 @@
}
}
- private static Attributes loadAndProvideAttributes(File bundleRoot, InputStream inputStream) throws BundleException
+ // todo: what and why are we copying anything here?
+ private static Attributes loadAndProvideAttributes(File generationRoot, InputStream inputStream) throws BundleException
{
try
{
- File archiveFile = new File(bundleRoot, ARCHIVE_JAR_NAME);
- OutputStream outputStream = new FileOutputStream(archiveFile);
+ File archiveFile = new File(generationRoot, ARCHIVE_JAR_NAME);
- Util.copy(inputStream, outputStream);
+ if (!archiveFile.exists())
+ {
+ OutputStream outputStream = null;
+ try
+ {
+ outputStream = new FileOutputStream(archiveFile);
- outputStream.close();
+ Util.copy(inputStream, outputStream);
+ }
+ finally
+ {
+ Util.close(outputStream);
+ }
+ }
- File archiveDir = new File(bundleRoot, ARCHIVE_NAME);
+ File archiveDir = new File(generationRoot, ARCHIVE_NAME);
assertTrue(archiveDir.mkdirs());
JarInputStream jarInputStream = new JarInputStream(new FileInputStream(archiveFile));
Modified: papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/BundleFileStore.java
===================================================================
--- papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/BundleFileStore.java 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/store/file-store/src/main/java/org/papoose/store/file/BundleFileStore.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -97,8 +97,7 @@
try
{
- Properties properties = new Properties();
- properties.load(new FileInputStream(bundleRoot));
+ Properties properties = load();
this.location = properties.getProperty(LOCATION_KEY);
this.lastModified = System.currentTimeMillis();
this.setting = AutostartSetting.valueOf(properties.getProperty(AUTOSTART_KEY));
@@ -172,4 +171,11 @@
properties.setProperty(AUTOSTART_KEY, setting.toString());
properties.store(new FileOutputStream(new File(bundleRoot, "bundle.properties")), " bundle id: " + bundleId + " location: " + location);
}
+
+ private Properties load() throws IOException
+ {
+ Properties properties = new Properties();
+ properties.load(new FileInputStream(new File(bundleRoot, "bundle.properties")));
+ return properties;
+ }
}
Modified: papoose-core/trunk/tck/bundles/pom.xml
===================================================================
--- papoose-core/trunk/tck/bundles/pom.xml 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/tck/bundles/pom.xml 2010-04-13 03:13:32 UTC (rev 266)
@@ -12,6 +12,7 @@
<name>Papoose :: OSGi Compatibility Tests :: Bundles</name>
<modules>
+ <module>simple</module>
</modules>
</project>
Added: papoose-core/trunk/tck/bundles/simple/pom.xml
===================================================================
--- papoose-core/trunk/tck/bundles/simple/pom.xml (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/pom.xml 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1,56 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.papoose.core.tck</groupId>
+ <artifactId>tck-bundles</artifactId>
+ <version>1.0.0.SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>tck-simple-bundle</artifactId>
+ <packaging>bundle</packaging>
+ <name>Papoose :: OSGi Compatibility Tests :: Bundles :: Simple</name>
+ <description>OSGi R4 Test Bundle</description>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Embed-Dependency>test-support-jar;inline=false</Embed-Dependency>
+ <Export-Package>com.acme.api</Export-Package>
+ <Private-Package>com.acme.pub;com.acme.pvt;com.acme.impl;-split-package:=first</Private-Package>
+ <Bundle-Activator>com.acme.impl.Activator</Bundle-Activator>
+ <L10N-Bundle>%bundle</L10N-Bundle>
+ <L10N-Test>%test</L10N-Test>
+ <L10N-NoTranslation>%no translation for this entry</L10N-NoTranslation>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.test-support</groupId>
+ <artifactId>test-support-jar</artifactId>
+ <version>${pom.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
Property changes on: papoose-core/trunk/tck/bundles/simple/pom.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:keywords
+ Date Revision
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/api/AnvilApi.java
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/api/AnvilApi.java (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/api/AnvilApi.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1,24 @@
+/**
+ *
+ * Copyright 2007 (C) The original author or authors
+ *
+ * Licensed 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 com.acme.api;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public interface AnvilApi
+{
+}
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/api/AnvilApi.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision Id Author
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/impl/Activator.java
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/impl/Activator.java (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/impl/Activator.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1,34 @@
+/**
+ *
+ * Copyright 2007 (C) The original author or authors
+ *
+ * Licensed 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 com.acme.impl;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class Activator implements BundleActivator
+{
+ public void start(BundleContext bundleContext) throws Exception
+ {
+ }
+
+ public void stop(BundleContext bundleContext) throws Exception
+ {
+ }
+}
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/impl/Activator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision Id Author
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/impl/AnvilImpl.java
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/impl/AnvilImpl.java (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/impl/AnvilImpl.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1,26 @@
+/**
+ *
+ * Copyright 2007 (C) The original author or authors
+ *
+ * Licensed 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 com.acme.impl;
+
+import com.acme.api.AnvilApi;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class AnvilImpl implements AnvilApi
+{
+}
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/impl/AnvilImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision Id Author
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pub/Primary.java
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pub/Primary.java (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pub/Primary.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1,24 @@
+/**
+ *
+ * Copyright 2007 (C) The original author or authors
+ *
+ * Licensed 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 com.acme.pub;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class Primary
+{
+}
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pub/Primary.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision Id Author
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pvt/Hidden.java
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pvt/Hidden.java (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pvt/Hidden.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1,24 @@
+/**
+ *
+ * Copyright 2007 (C) The original author or authors
+ *
+ * Licensed 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 com.acme.pvt;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class Hidden
+{
+}
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pvt/Hidden.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision Id Author
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pvt/Private.java
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pvt/Private.java (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pvt/Private.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1,24 @@
+/**
+ *
+ * Copyright 2009 (C) The original author or authors
+ *
+ * Licensed 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 com.acme.pvt;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class Private
+{
+}
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/java/com/acme/pvt/Private.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision Id Author
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle.properties
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle.properties (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle.properties 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1 @@
+bundle=bundle
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en.properties
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en.properties (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en.properties 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1,2 @@
+bundle=bundle_en
+test=In the year 1815 Monseigneur Charles-Francois-Bienvenu Myriel was Bishop of Digne.
\ No newline at end of file
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en_GB.properties
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en_GB.properties (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en_GB.properties 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1 @@
+bundle=bundle_en_GB
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en_GB.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en_GB_welsh.properties
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en_GB_welsh.properties (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en_GB_welsh.properties 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1 @@
+bundle=bundle_en_GB_welsh
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_en_GB_welsh.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_fr.properties
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_fr.properties (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_fr.properties 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1,2 @@
+bundle=bundle_fr
+test=En 1815, M. Charles-Fran\x8Dois-Bienvenu Myriel \x8Etait \x8Ev\x90que de Digne.
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_fr.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_fr_FR.properties
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_fr_FR.properties (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_fr_FR.properties 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1 @@
+bundle=bundle_fr_FR
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/resources/OSGI-INF/l10n/bundle_fr_FR.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/anvil.xml
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/anvil.xml (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/anvil.xml 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1 @@
+<anvil>How now brown cow.</anvil>
\ No newline at end of file
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/anvil.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:keywords
+ Date Revision
Added: svn:eol-style
+ native
Added: papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/resource/camera.xml
===================================================================
--- papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/resource/camera.xml (rev 0)
+++ papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/resource/camera.xml 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1 @@
+<status>Canon</status>
\ No newline at end of file
Property changes on: papoose-core/trunk/tck/bundles/simple/src/main/resources/com/acme/resource/camera.xml
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:keywords
+ Date Revision
Added: svn:eol-style
+ native
Modified: papoose-core/trunk/tck/tests/pom.xml
===================================================================
--- papoose-core/trunk/tck/tests/pom.xml 2010-03-06 18:50:37 UTC (rev 265)
+++ papoose-core/trunk/tck/tests/pom.xml 2010-04-13 03:13:32 UTC (rev 266)
@@ -11,8 +11,89 @@
<packaging>pom</packaging>
<name>Papoose :: OSGi Compatibility Tests :: Tests</name>
- <modules>
- </modules>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.papoose.test-support</groupId>
+ <artifactId>test-support-bundle</artifactId>
+ <version>${papooseVersion}</version>
+ <type>jar</type>
+ <overWrite>true</overWrite>
+ <outputDirectory>target</outputDirectory>
+ <destFileName>bundle.jar</destFileName>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>cnd-perm-admin</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>framework</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>perm-admin</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>pkg-admin</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>start-level</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>store-file</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>store-memory</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>url-handlers</artifactId>
+ </dependency>
+
+ </dependencies>
</project>
Added: papoose-core/trunk/tck/tests/src/test/java/org/papoose/tck/core/PapooseFrameworkFactoryTest.java
===================================================================
--- papoose-core/trunk/tck/tests/src/test/java/org/papoose/tck/core/PapooseFrameworkFactoryTest.java (rev 0)
+++ papoose-core/trunk/tck/tests/src/test/java/org/papoose/tck/core/PapooseFrameworkFactoryTest.java 2010-04-13 03:13:32 UTC (rev 266)
@@ -0,0 +1,147 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.tck.core;
+
+import java.io.File;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+import org.papoose.core.PapooseFrameworkFactory;
+
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class PapooseFrameworkFactoryTest
+{
+ @Test
+ public void test() throws Exception
+ {
+ File f = new File("./target/bundle.jar");
+ String location = f.toURI().normalize().toString();
+
+ Map<String, String> configuration = new HashMap<String, String>();
+ configuration.put(Constants.FRAMEWORK_STORAGE, "target/papoose");
+
+ FrameworkFactory factory = new PapooseFrameworkFactory();
+ final Framework framework = factory.newFramework(configuration);
+
+ framework.init();
+
+ Bundle systemBundle = framework.getBundleContext().getBundle(0);
+ BundleContext context = systemBundle.getBundleContext();
+
+ Bundle testBundle = context.installBundle(location);
+
+ long testBundleId = testBundle.getBundleId();
+
+ assertTrue(testBundleId > 0);
+
+ try
+ {
+ framework.uninstall();
+ fail("Should have thrown an exception");
+ }
+ catch (BundleException e)
+ {
+ }
+
+ framework.stop();
+
+ framework.init();
+
+ systemBundle = framework.getBundleContext().getBundle(0);
+ context = systemBundle.getBundleContext();
+
+ testBundle = context.getBundle(testBundleId);
+ assertNotNull(testBundleId);
+
+ framework.start();
+ testBundle.start();
+
+ assertEquals(Bundle.ACTIVE, framework.getState());
+ assertEquals(Bundle.ACTIVE, testBundle.getState());
+
+ testBundle.uninstall();
+
+ Dictionary headers = testBundle.getHeaders("en");
+ Assert.assertEquals("org.papoose.test-support.bundle", headers.get("Bundle-SymbOLicName"));
+
+ headers = testBundle.getHeaders("en");
+ Assert.assertEquals("bundle_en", headers.get("L10N-Bundle"));
+
+ headers = testBundle.getHeaders();
+ Assert.assertEquals("bundle_en", headers.get("L10N-Bundle"));
+
+ headers = testBundle.getHeaders(null);
+ Assert.assertEquals("bundle_en", headers.get("L10N-Bundle"));
+
+ headers = testBundle.getHeaders("en_US");
+ Assert.assertEquals("bundle_en", headers.get("L10N-Bundle"));
+
+ headers = testBundle.getHeaders("fr");
+ Assert.assertEquals("bundle_fr", headers.get("L10N-Bundle"));
+
+ headers = testBundle.getHeaders("fr_FR");
+ Assert.assertEquals("bundle_fr_FR", headers.get("L10N-Bundle"));
+
+ headers = testBundle.getHeaders("");
+ Assert.assertEquals("%bundle", headers.get("L10N-Bundle"));
+
+ headers = testBundle.getHeaders("en");
+ Assert.assertEquals("no translation for this entry", headers.get("L10N-NoTranslation"));
+
+ try
+ {
+ testBundle.start();
+ fail("Cannot start an uninstalled bundle");
+ }
+ catch (IllegalStateException e)
+ {
+ }
+
+ testBundle = context.getBundle(testBundleId);
+ assertNull(testBundle);
+
+ framework.stop();
+
+ framework.init();
+
+ systemBundle = framework.getBundleContext().getBundle(0);
+ context = systemBundle.getBundleContext();
+
+ testBundle = context.getBundle(testBundleId);
+ assertNull(testBundle);
+
+ framework.stop();
+ }
+}
Property changes on: papoose-core/trunk/tck/tests/src/test/java/org/papoose/tck/core/PapooseFrameworkFactoryTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Revision Id Author
Added: svn:eol-style
+ native
Modified: papoose-core/trunk/test-support/test-bundle/src/main/java/com/acme/impl/Activator.java
==================...
[truncated message content] |
|
From: <osg...@li...> - 2010-03-06 18:50:44
|
Revision: 265
http://osgi.svn.sourceforge.net/osgi/?rev=265&view=rev
Author: maguro
Date: 2010-03-06 18:50:37 +0000 (Sat, 06 Mar 2010)
Log Message:
-----------
Some more tests
Modified Paths:
--------------
papoose-cmpn/trunk/http/pom.xml
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java
papoose-cmpn/trunk/pom.xml
papoose-cmpn/trunk/tck/tests/pom.xml
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java
Added Paths:
-----------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServer.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/JettyHttpServer.java
papoose-cmpn/trunk/http/src/test/java/org/papoose/http/JettyHttpServerTest.java
papoose-cmpn/trunk/http/src/test/resources/car/
papoose-cmpn/trunk/http/src/test/resources/car/c
Modified: papoose-cmpn/trunk/http/pom.xml
===================================================================
--- papoose-cmpn/trunk/http/pom.xml 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/http/pom.xml 2010-03-06 18:50:37 UTC (rev 265)
@@ -23,7 +23,7 @@
<instructions>
<Bundle-SymbolicName>org.papoose.cmpn.event</Bundle-SymbolicName>
<Export-Package>org.papoose.http</Export-Package>
- <Import-Package>org.papoose.core;resolution:=optional,javax.servlet;version="[2.4,3)",javax.servlet.http;version="[2.4,3)",org.osgi.framework;version="[1,2)",org.osgi.service.http;version="[1.2,2)"</Import-Package>
+ <Import-Package>org.mortbay.jetty;version="[6.1,6.2)",org.mortbay.jetty.nio;version="[6.1,6.2)",org.mortbay.jetty.security;version="[6.1,6.2)",org.mortbay.jetty.servlet;version="[6.1,6.2)",org.mortbay.thread;version="[6.1,6.2)",org.papoose.core;resolution:=optional,javax.servlet;version="[2.4,3)",javax.servlet.http;version="[2.4,3)",org.osgi.framework;version="[1,2)",org.osgi.service.http;version="[1.2,2)"</Import-Package>
<Private-Package>org.papoose.http.util</Private-Package>
</instructions>
</configuration>
@@ -46,6 +46,13 @@
</dependency>
<dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>${jettyVersion}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServer.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServer.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServer.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -0,0 +1,38 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public interface HttpServer
+{
+ public final static String HTTP_MAX_THREAD_SIZE = "org.osgi.service.http.pool.size";
+ public final static String HTTP_PORT = "org.osgi.service.http.port";
+ public final static String HTTP_PORT_SECURE = "org.osgi.service.http.port.secure";
+ public final static String HTTP_KEYSTORE = "org.papoose.service.http.keystore";
+ public final static String HTTP_KEYSTORE_PASSWORD = "org.papoose.service.http.keystore.password";
+ public final static String HTTP_TRUSTSTORE = "org.papoose.service.http.truststore";
+ public final static String HTTP_TRUSTSTORE_PASSWORD = "org.papoose.service.http.truststore.password";
+ public final static String HTTP_SERVER_PASSWORD = "org.papoose.service.http.server.password";
+
+ ServletDispatcher getServletDispatcher();
+
+ void start();
+
+ void stop();
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/JettyHttpServer.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/JettyHttpServer.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/JettyHttpServer.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -0,0 +1,135 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.security.SslSocketConnector;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.thread.QueuedThreadPool;
+
+import org.papoose.http.util.Util;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class JettyHttpServer implements HttpServer
+{
+ private final static String CLASS_NAME = JettyHttpServer.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final Server server = new Server();
+ private final ServletDispatcher servletDispatcher = new ServletDispatcher();
+
+ public ServletDispatcher getServletDispatcher()
+ {
+ return servletDispatcher;
+ }
+
+ public void start()
+ {
+ LOGGER.entering(CLASS_NAME, "start");
+
+ try
+ {
+ server.start();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error starting container", e);
+ }
+
+ LOGGER.exiting(CLASS_NAME, "start");
+ }
+
+ public void stop()
+ {
+ LOGGER.entering(CLASS_NAME, "stop");
+
+ try
+ {
+ server.stop();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error stopping container", e);
+ }
+
+ LOGGER.exiting(CLASS_NAME, "stop");
+ }
+
+ public static HttpServer generate(Properties properties)
+ {
+ LOGGER.entering(CLASS_NAME, "generate", properties);
+
+ JettyHttpServer server = new JettyHttpServer(properties);
+
+ LOGGER.exiting(CLASS_NAME, "generate", server);
+
+ return server;
+ }
+
+ private JettyHttpServer(Properties properties)
+ {
+ int maxThreads = Util.parseInt(properties.getProperty(HTTP_MAX_THREAD_SIZE), 5);
+
+ if (LOGGER.isLoggable(Level.CONFIG)) LOGGER.config("Max threads: " + maxThreads);
+
+ server.setThreadPool(new QueuedThreadPool(maxThreads));
+
+ Context root = new Context(server, "/", Context.SESSIONS);
+
+ root.addServlet(new ServletHolder(servletDispatcher), "/*");
+
+ int port = Util.parseInt(properties.getProperty(HTTP_PORT), -1);
+ int securePort = Util.parseInt(properties.getProperty(HTTP_PORT_SECURE), -1);
+
+ if (port != -1)
+ {
+ if (LOGGER.isLoggable(Level.CONFIG)) LOGGER.config("port: " + port);
+
+ SelectChannelConnector connector = new SelectChannelConnector();
+
+ connector.setPort(port);
+
+ server.addConnector(connector);
+ }
+
+ if (securePort != -1)
+ {
+ if (LOGGER.isLoggable(Level.CONFIG)) LOGGER.config("securePort: " + securePort);
+
+ SslSocketConnector sslConnector = new SslSocketConnector();
+
+ if (properties.containsKey(HTTP_KEYSTORE)) sslConnector.setKeystore(properties.getProperty(HTTP_KEYSTORE));
+ if (properties.containsKey(HTTP_TRUSTSTORE)) sslConnector.setTruststore(properties.getProperty(HTTP_TRUSTSTORE));
+ if (properties.containsKey(HTTP_KEYSTORE_PASSWORD)) sslConnector.setPassword(properties.getProperty(HTTP_KEYSTORE_PASSWORD));
+ if (properties.containsKey(HTTP_TRUSTSTORE_PASSWORD)) sslConnector.setTrustPassword(properties.getProperty(HTTP_TRUSTSTORE_PASSWORD));
+ if (properties.containsKey(HTTP_SERVER_PASSWORD)) sslConnector.setKeyPassword(properties.getProperty(HTTP_SERVER_PASSWORD));
+
+ sslConnector.setMaxIdleTime(30000);
+ sslConnector.setPort(securePort);
+
+ server.addConnector(sslConnector);
+ }
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/JettyHttpServer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -16,8 +16,12 @@
*/
package org.papoose.http;
+import java.util.logging.Level;
import java.util.logging.Logger;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.http.HttpService;
+
import org.papoose.core.Papoose;
@@ -28,16 +32,51 @@
{
private final static String CLASS_NAME = PapooseBootLevelService.class.getName();
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private volatile HttpServer server;
+ private volatile HttpServiceImpl httpService;
public void start(Papoose papoose)
{
LOGGER.entering(CLASS_NAME, "start", papoose);
+
+ if (papoose == null) throw new IllegalArgumentException("Papoose instance is null");
+
+ if (server != null)
+ {
+ LOGGER.log(Level.WARNING, "Http service already started");
+ return;
+ }
+
+ LOGGER.finest("Provisioning Jetty server");
+ server = JettyHttpServer.generate(papoose.getProperties());
+
+ server.start();
+
+ BundleContext bundleContext = papoose.getSystemBundleContext();
+
+ httpService = new HttpServiceImpl(bundleContext, server.getServletDispatcher());
+
+ httpService.start();
+ bundleContext.registerService(HttpService.class.getName(), httpService, null);
+
LOGGER.exiting(CLASS_NAME, "start");
}
public void stop()
{
LOGGER.entering(CLASS_NAME, "stop");
+
+ if (server == null)
+ {
+ LOGGER.log(Level.WARNING, "Http service already stopped");
+ return;
+ }
+
+ httpService.stop();
+ httpService = null;
+ server.stop();
+ server = null;
+
LOGGER.exiting(CLASS_NAME, "stop");
}
}
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -104,7 +104,7 @@
if (exception instanceof ServletException) throw (ServletException) exception;
if (exception instanceof IOException) throw (IOException) exception;
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
catch (IOException ioe)
{
@@ -112,7 +112,8 @@
}
catch (Exception e)
{
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ System.err.println(e);
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
LOGGER.exiting(CLASS_NAME, "service");
@@ -131,7 +132,7 @@
if (lastModified == 0 || modifiedSince == -1 || lastModified > modifiedSince)
{
resp.setContentLength(copyResource(conn.getInputStream(), resp.getOutputStream()));
- resp.setStatus(HttpServletResponse.SC_FOUND);
+ resp.setStatus(HttpServletResponse.SC_OK);
}
else
{
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -69,7 +69,7 @@
catch (Throwable t)
{
LOGGER.log(Level.WARNING, "Problems calling ", t);
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
}
@@ -86,7 +86,7 @@
path = path.substring(0, index);
}
- resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ resp.sendError(HttpServletResponse.SC_NOT_FOUND);
}
void register(ServletRegistration registration)
Added: papoose-cmpn/trunk/http/src/test/java/org/papoose/http/JettyHttpServerTest.java
===================================================================
--- papoose-cmpn/trunk/http/src/test/java/org/papoose/http/JettyHttpServerTest.java (rev 0)
+++ papoose-cmpn/trunk/http/src/test/java/org/papoose/http/JettyHttpServerTest.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -0,0 +1,44 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import java.util.Properties;
+
+import org.junit.Test;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class JettyHttpServerTest
+{
+ @Test
+ public void test() throws Exception
+ {
+ Properties properties = new Properties();
+
+ properties.setProperty(HttpServer.HTTP_PORT, "8080");
+
+ HttpServer server = JettyHttpServer.generate(properties);
+
+ server.start();
+
+ Thread.sleep(1 * 1000);
+
+ server.stop();
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/test/java/org/papoose/http/JettyHttpServerTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java
===================================================================
--- papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -51,7 +51,7 @@
dispatcher.service(request, response);
- verify(response, only()).setStatus(HttpServletResponse.SC_NOT_FOUND);
+ verify(response, only()).sendError(HttpServletResponse.SC_NOT_FOUND);
}
@Test
@@ -158,7 +158,7 @@
dispatcher.service(request, response);
verify(context, only()).handleSecurity(request, response);
- verify(response, only()).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ verify(response, only()).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
@Test
@@ -186,7 +186,7 @@
}
verify(context, only()).handleSecurity(request, response);
- verify(response, never()).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ verify(response, never()).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
@Test
@@ -215,7 +215,7 @@
dispatcher.service(request, response);
verify(context, never()).handleSecurity(request, response);
- verify(response, only()).setStatus(HttpServletResponse.SC_NOT_FOUND);
+ verify(response, only()).sendError(HttpServletResponse.SC_NOT_FOUND);
}
@Test
@@ -244,6 +244,6 @@
dispatcher.service(request, response);
verify(context, never()).handleSecurity(request, response);
- verify(response, only()).setStatus(HttpServletResponse.SC_NOT_FOUND);
+ verify(response, only()).sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
Added: papoose-cmpn/trunk/http/src/test/resources/car/c
===================================================================
--- papoose-cmpn/trunk/http/src/test/resources/car/c (rev 0)
+++ papoose-cmpn/trunk/http/src/test/resources/car/c 2010-03-06 18:50:37 UTC (rev 265)
@@ -0,0 +1 @@
+HOW NOW BROWN COW
Property changes on: papoose-cmpn/trunk/http/src/test/resources/car/c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/pom.xml
===================================================================
--- papoose-cmpn/trunk/pom.xml 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/pom.xml 2010-03-06 18:50:37 UTC (rev 265)
@@ -25,6 +25,7 @@
</modules>
<properties>
+ <jettyVersion>6.1.19</jettyVersion>
<paxExamVersion>1.2.0</paxExamVersion>
<papooseTestVersion>1.0-SNAPSHOT</papooseTestVersion>
</properties>
@@ -77,7 +78,7 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>com.springsource.javax.servlet</artifactId>
- <version>2.4.0</version>
+ <version>2.5.0</version>
</dependency>
<dependency>
Modified: papoose-cmpn/trunk/tck/tests/pom.xml
===================================================================
--- papoose-cmpn/trunk/tck/tests/pom.xml 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/tck/tests/pom.xml 2010-03-06 18:50:37 UTC (rev 265)
@@ -43,6 +43,20 @@
</dependency>
<dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>${jettyVersion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>${jettyVersion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
<scope>test</scope>
Modified: papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java
===================================================================
--- papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -16,16 +16,21 @@
*/
package org.papoose.tck.http;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
import org.junit.Assert;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.knopflerfish;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;
@@ -37,10 +42,13 @@
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
+import org.papoose.http.HttpServer;
import org.papoose.http.HttpServiceImpl;
+import org.papoose.http.JettyHttpServer;
import org.papoose.http.ServletDispatcher;
@@ -58,8 +66,8 @@
{
return options(
equinox(),
- // felix(),
- // knopflerfish(),
+ felix(),
+ knopflerfish(),
// papoose(),
compendiumProfile(),
// vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
@@ -70,16 +78,16 @@
// waitForFrameworkStartup()
provision(
mavenBundle().groupId("javax.servlet").artifactId("com.springsource.javax.servlet").version(asInProject()),
+ mavenBundle().groupId("org.mortbay.jetty").artifactId("jetty").version(asInProject()),
+ mavenBundle().groupId("org.mortbay.jetty").artifactId("jetty-util").version(asInProject()),
mavenBundle().groupId("org.papoose.cmpn").artifactId("papoose-cmpn-http").version(asInProject())
)
);
}
- @Test
- public void test() throws Exception
+ public void testRegistrations() throws Exception
{
Assert.assertNotNull(bundleContext);
- ExecutorService executor = new ThreadPoolExecutor(1, 5, 100, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
ServletDispatcher dispatcher = new ServletDispatcher();
HttpServiceImpl httpService = new HttpServiceImpl(bundleContext, dispatcher);
@@ -107,7 +115,127 @@
finally
{
httpService.stop();
- executor.shutdown();
}
}
-}
\ No newline at end of file
+
+ public void testResourceAbsolute() throws Exception
+ {
+ Assert.assertNotNull(bundleContext);
+
+ Properties properties = new Properties();
+
+ properties.setProperty(HttpServer.HTTP_PORT, "8080");
+
+ HttpServer server = JettyHttpServer.generate(properties);
+
+ server.start();
+
+ HttpServiceImpl httpService = new HttpServiceImpl(bundleContext, server.getServletDispatcher());
+
+ httpService.start();
+ bundleContext.registerService(HttpService.class.getName(), httpService, null);
+
+ try
+ {
+ ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
+ HttpService service = (HttpService) bundleContext.getService(sr);
+
+ service.registerResources("/a/b", "/org/papoose/tck", new HttpContext()
+ {
+ public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
+ {
+ return true;
+ }
+
+ public URL getResource(String name)
+ {
+ return HttpServiceImplTest.class.getResource(name);
+ }
+
+ public String getMimeType(String name)
+ {
+ return null;
+ }
+ });
+
+ URL url = new URL("http://localhost:8080/a/b/http/HttpServiceImplTest.class");
+
+ DataInputStream reader = new DataInputStream(url.openStream());
+
+ assertEquals((byte) 0xca, reader.readByte());
+ assertEquals((byte) 0xfe, reader.readByte());
+
+ assertEquals((byte) 0xba, reader.readByte());
+ assertEquals((byte) 0xbe, reader.readByte());
+
+ service.unregister("/a/b");
+ }
+ finally
+ {
+ httpService.stop();
+ server.stop();
+ }
+ }
+
+ @Test
+ public void testResourceRelative() throws Exception
+ {
+ Assert.assertNotNull(bundleContext);
+
+ Properties properties = new Properties();
+
+ properties.setProperty(HttpServer.HTTP_PORT, "8080");
+
+ HttpServer server = JettyHttpServer.generate(properties);
+
+ server.start();
+
+ HttpServiceImpl httpService = new HttpServiceImpl(bundleContext, server.getServletDispatcher());
+
+ httpService.start();
+ bundleContext.registerService(HttpService.class.getName(), httpService, null);
+
+ try
+ {
+ ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
+ HttpService service = (HttpService) bundleContext.getService(sr);
+
+ service.registerResources("/a/b", ".", new HttpContext()
+ {
+ public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
+ {
+ return true;
+ }
+
+ public URL getResource(String name)
+ {
+ name = name.replaceAll("^\\./", "");
+ name = name.replaceAll("/\\./", "/");
+ return HttpServiceImplTest.class.getResource(name);
+ }
+
+ public String getMimeType(String name)
+ {
+ return null;
+ }
+ });
+
+ URL url = new URL("http://localhost:8080/a/b/HttpServiceImplTest.class");
+
+ DataInputStream reader = new DataInputStream(url.openStream());
+
+ assertEquals((byte) 0xca, reader.readByte());
+ assertEquals((byte) 0xfe, reader.readByte());
+
+ assertEquals((byte) 0xba, reader.readByte());
+ assertEquals((byte) 0xbe, reader.readByte());
+
+ service.unregister("/a/b");
+ }
+ finally
+ {
+ httpService.stop();
+ server.stop();
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-03-04 18:28:55
|
Revision: 264
http://osgi.svn.sourceforge.net/osgi/?rev=264&view=rev
Author: maguro
Date: 2010-03-04 18:28:49 +0000 (Thu, 04 Mar 2010)
Log Message:
-----------
Minor cleanup
Modified Paths:
--------------
papoose-core/trunk/core/src/main/java/org/papoose/core/Papoose.java
papoose-core/trunk/core/src/main/java/org/papoose/core/util/Util.java
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/Papoose.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/Papoose.java 2010-02-27 15:54:12 UTC (rev 263)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/Papoose.java 2010-03-04 18:28:49 UTC (rev 264)
@@ -21,12 +21,10 @@
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Hashtable;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -69,8 +67,8 @@
private final static Properties DEFAULTS = new Properties();
private static int FRAMEWORK_COUNTER = 0;
- private final static Map<Integer, Reference<Papoose>> FRAMEWORKS_BY_ID = new HashMap<Integer, Reference<Papoose>>();
- private final static Map<String, Reference<Papoose>> FRAMEWORKS_BY_NAME = new HashMap<String, Reference<Papoose>>();
+ private final static Map<Integer, Reference<Papoose>> FRAMEWORKS_BY_ID = new Hashtable<Integer, Reference<Papoose>>();
+ private final static Map<String, Reference<Papoose>> FRAMEWORKS_BY_NAME = new Hashtable<String, Reference<Papoose>>();
private final Object lock = new Object();
private volatile State state = new Installed();
@@ -181,7 +179,7 @@
synchronized (FRAMEWORKS_BY_NAME)
{
- ensureUrlHandling();
+ Util.ensureUrlHandling();
this.frameworkId = FRAMEWORK_COUNTER++;
@@ -355,11 +353,6 @@
}
}
- public Properties getClientProperties()
- {
- return clientProperties;
- }
-
public Object getProperty(String key)
{
return properties.get(key);
@@ -520,7 +513,7 @@
startManager.stop(bundle, options);
}
- private void doInitialze() throws PapooseException
+ private void doInitialize() throws PapooseException
{
BundleManager manager = getBundleManager();
@@ -552,10 +545,10 @@
serviceRegistry.start();
- startBootLevelServices();
-
SystemBundleController systemBundleController = (SystemBundleController) manager.installSystemBundle(new Version(properties.getProperty(PapooseConstants.PAPOOSE_VERSION)));
+ startBootLevelServices();
+
manager.loadBundles();
manager.fireFrameworkEvent(new FrameworkEvent(FrameworkEvent.STARTED, systemBundleController, null));
@@ -603,52 +596,6 @@
return result;
}
- private static void ensureUrlHandling()
- {
- LOGGER.entering(CLASS_NAME, "ensureUrlHandling");
-
- try
- {
- new URL("codesource://1:0...@or....0");
-
- LOGGER.finest("Handler for codesource protocol found");
- }
- catch (MalformedURLException e)
- {
- LOGGER.finest("Handler for codesource protocol not found");
-
- String prefixes = System.getProperty("java.protocol.handler.pkgs");
-
- if (prefixes == null)
- {
- prefixes = "org.papoose.core.protocols";
- }
- else
- {
- prefixes = prefixes + "|org.papoose.core.protocols";
- }
-
- if (LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("java.protocol.handler.pkgs: " + prefixes);
-
- System.setProperty("java.protocol.handler.pkgs", prefixes);
-
- try
- {
- new URL("codesource://1:0...@or...-0");
-
- LOGGER.finest("Handler for codesource protocol found");
- }
- catch (MalformedURLException mue)
- {
- LOGGER.severe("Unable to pick up Papoose protocol handlers");
-
- throw new FatalError("Unable to pick up Papoose protocol handlers", mue);
- }
- }
-
- LOGGER.exiting(CLASS_NAME, "ensureUrlHandling");
- }
-
private Properties assembleProperties(Properties properties)
{
Properties result = new Properties();
@@ -884,7 +831,7 @@
public void init() throws PapooseException
{
- doInitialze();
+ doInitialize();
state = new Starting();
}
@@ -893,7 +840,7 @@
{
futureStop = new FutureFrameworkEvent();
- doInitialze();
+ doInitialize();
doStart();
state = new Active();
@@ -923,7 +870,7 @@
public void init() throws PapooseException
{
- doInitialze();
+ doInitialize();
state = new Starting();
}
Modified: papoose-core/trunk/core/src/main/java/org/papoose/core/util/Util.java
===================================================================
--- papoose-core/trunk/core/src/main/java/org/papoose/core/util/Util.java 2010-02-27 15:54:12 UTC (rev 263)
+++ papoose-core/trunk/core/src/main/java/org/papoose/core/util/Util.java 2010-03-04 18:28:49 UTC (rev 264)
@@ -24,6 +24,8 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigInteger;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -37,6 +39,7 @@
import org.osgi.framework.BundleException;
+import org.papoose.core.FatalError;
import org.papoose.core.Papoose;
import org.papoose.core.descriptions.Extension;
import org.papoose.core.descriptions.Resolution;
@@ -777,6 +780,52 @@
return builder.toString();
}
+ public static void ensureUrlHandling()
+ {
+ LOGGER.entering(CLASS_NAME, "ensureUrlHandling");
+
+ try
+ {
+ new URL("codesource://1:0...@or....0");
+
+ LOGGER.finest("Handler for codesource protocol found");
+ }
+ catch (MalformedURLException e)
+ {
+ LOGGER.finest("Handler for codesource protocol not found");
+
+ String prefixes = System.getProperty("java.protocol.handler.pkgs");
+
+ if (prefixes == null)
+ {
+ prefixes = "org.papoose.core.protocols";
+ }
+ else
+ {
+ prefixes = prefixes + "|org.papoose.core.protocols";
+ }
+
+ if (LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("java.protocol.handler.pkgs: " + prefixes);
+
+ System.setProperty("java.protocol.handler.pkgs", prefixes);
+
+ try
+ {
+ new URL("codesource://1:0...@or...-0");
+
+ LOGGER.finest("Handler for codesource protocol found");
+ }
+ catch (MalformedURLException mue)
+ {
+ LOGGER.severe("Unable to pick up Papoose protocol handlers");
+
+ throw new FatalError("Unable to pick up Papoose protocol handlers", mue);
+ }
+ }
+
+ LOGGER.exiting(CLASS_NAME, "ensureUrlHandling");
+ }
+
public static <T> Iterable<List<T>> combinations(final List<T> set)
{
final List<T> list = new ArrayList<T>(set);
@@ -870,7 +919,6 @@
};
}
-
private static BigInteger getFactorial(int n)
{
BigInteger fact = BigInteger.ONE;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-27 15:54:31
|
Revision: 263
http://osgi.svn.sourceforge.net/osgi/?rev=263&view=rev
Author: maguro
Date: 2010-02-27 15:54:12 +0000 (Sat, 27 Feb 2010)
Log Message:
-----------
Neglected to register services
Modified Paths:
--------------
papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java
papoose-cmpn/trunk/log/src/main/java/org/papoose/log/PapooseBootLevelService.java
Modified: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java
===================================================================
--- papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java 2010-02-26 16:04:16 UTC (rev 262)
+++ papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java 2010-02-27 15:54:12 UTC (rev 263)
@@ -26,7 +26,8 @@
import java.util.logging.Logger;
import org.osgi.framework.BundleContext;
-
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.event.EventAdmin;
import org.papoose.core.Papoose;
import org.papoose.event.util.Util;
@@ -45,6 +46,7 @@
public final static String LOG_SERVICE_SCHEDULE_CORE_POOL_SIZE = CLASS_NAME + ".scheduleCorePoolSize";
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
private volatile EventAdminImpl eventAdminService;
+ private volatile ServiceRegistration registration;
public void start(Papoose papoose)
{
@@ -97,6 +99,8 @@
eventAdminService.start();
+ registration = bundleContext.registerService(EventAdmin.class.getName(), eventAdminService, null);
+
LOGGER.exiting(CLASS_NAME, "start");
}
@@ -110,6 +114,9 @@
return;
}
+ registration.unregister();
+ registration = null;
+
eventAdminService.stop();
eventAdminService = null;
Modified: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/PapooseBootLevelService.java
===================================================================
--- papoose-cmpn/trunk/log/src/main/java/org/papoose/log/PapooseBootLevelService.java 2010-02-26 16:04:16 UTC (rev 262)
+++ papoose-cmpn/trunk/log/src/main/java/org/papoose/log/PapooseBootLevelService.java 2010-02-27 15:54:12 UTC (rev 263)
@@ -24,7 +24,8 @@
import java.util.logging.Logger;
import org.osgi.framework.BundleContext;
-
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.log.LogService;
import org.papoose.core.Papoose;
import org.papoose.log.util.Util;
@@ -42,6 +43,7 @@
public final static String LOG_SERVICE_TIME_UNIT = CLASS_NAME + ".timeUnit";
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
private volatile LogServiceImpl logService;
+ private volatile ServiceRegistration registration;
public void start(Papoose papoose)
{
@@ -88,6 +90,8 @@
logService.start();
+ registration = bundleContext.registerService(LogService.class.getName(), logService, null);
+
LOGGER.exiting(CLASS_NAME, "start");
}
@@ -101,6 +105,9 @@
return;
}
+ registration.unregister();
+ registration = null;
+
logService.stop();
logService = null;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-26 16:04:48
|
Revision: 262
http://osgi.svn.sourceforge.net/osgi/?rev=262&view=rev
Author: maguro
Date: 2010-02-26 16:04:16 +0000 (Fri, 26 Feb 2010)
Log Message:
-----------
POM update and more test
Modified Paths:
--------------
papoose-cmpn/trunk/event/pom.xml
papoose-cmpn/trunk/http/pom.xml
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
papoose-cmpn/trunk/log/pom.xml
papoose-cmpn/trunk/pom.xml
papoose-cmpn/trunk/tck/tests/pom.xml
Added Paths:
-----------
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java
Modified: papoose-cmpn/trunk/event/pom.xml
===================================================================
--- papoose-cmpn/trunk/event/pom.xml 2010-02-26 14:08:08 UTC (rev 261)
+++ papoose-cmpn/trunk/event/pom.xml 2010-02-26 16:04:16 UTC (rev 262)
@@ -23,7 +23,7 @@
<instructions>
<Bundle-SymbolicName>org.papoose.cmpn.event</Bundle-SymbolicName>
<Export-Package>org.papoose.event</Export-Package>
- <Import-Package>org.papoose.core;resolution:=optional,org.osgi.framework;version="[1.0,1.6)",org.osgi.service.event;version="[1.1,1.3)",org.osgi.service.log;version="[1.1,1.4)",org.osgi.util.tracker;version="[1.3,1.5)"</Import-Package>
+ <Import-Package>org.papoose.core;resolution:=optional,org.osgi.framework;version="[1,2)",org.osgi.service.event;version="[1.1,2)",org.osgi.service.log;version="[1.1,2)",org.osgi.util.tracker;version="[1.3,2)"</Import-Package>
<Private-Package>org.papoose.event.util</Private-Package>
</instructions>
</configuration>
Modified: papoose-cmpn/trunk/http/pom.xml
===================================================================
--- papoose-cmpn/trunk/http/pom.xml 2010-02-26 14:08:08 UTC (rev 261)
+++ papoose-cmpn/trunk/http/pom.xml 2010-02-26 16:04:16 UTC (rev 262)
@@ -23,7 +23,7 @@
<instructions>
<Bundle-SymbolicName>org.papoose.cmpn.event</Bundle-SymbolicName>
<Export-Package>org.papoose.http</Export-Package>
- <Import-Package>org.papoose.core;resolution:=optional,javax.servlet;version="2.4",javax.servlet.http;version="2.4",org.osgi.framework;version="1.4",org.osgi.service.http;version="1.2"</Import-Package>
+ <Import-Package>org.papoose.core;resolution:=optional,javax.servlet;version="[2.4,3)",javax.servlet.http;version="[2.4,3)",org.osgi.framework;version="[1,2)",org.osgi.service.http;version="[1.2,2)"</Import-Package>
<Private-Package>org.papoose.http.util</Private-Package>
</instructions>
</configuration>
@@ -35,8 +35,7 @@
<dependency>
<groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
+ <artifactId>com.springsource.javax.servlet</artifactId>
<scope>provided</scope>
</dependency>
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-26 14:08:08 UTC (rev 261)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-26 16:04:16 UTC (rev 262)
@@ -70,6 +70,15 @@
}
}
+ public void start() {}
+
+ public void stop()
+ {
+ dispatcher.clear();
+ contexts.clear();
+ registrations.clear();
+ }
+
/**
* {@inheritDoc}
*/
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java 2010-02-26 14:08:08 UTC (rev 261)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java 2010-02-26 16:04:16 UTC (rev 262)
@@ -19,6 +19,6 @@
/**
* @version $Revision: $ $Date: $
*/
-public class ResourceNotFoundException extends RuntimeException
+class ResourceNotFoundException extends RuntimeException
{
}
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-26 14:08:08 UTC (rev 261)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-26 16:04:16 UTC (rev 262)
@@ -98,4 +98,9 @@
{
registrations.remove(registration);
}
+
+ void clear()
+ {
+ registrations.clear();
+ }
}
Modified: papoose-cmpn/trunk/log/pom.xml
===================================================================
--- papoose-cmpn/trunk/log/pom.xml 2010-02-26 14:08:08 UTC (rev 261)
+++ papoose-cmpn/trunk/log/pom.xml 2010-02-26 16:04:16 UTC (rev 262)
@@ -23,7 +23,7 @@
<instructions>
<Bundle-SymbolicName>org.papoose.cmpn.log</Bundle-SymbolicName>
<Export-Package>org.papoose.log</Export-Package>
- <Import-Package>org.papoose.core;resolution:=optional,org.osgi.framework;version="[1.0,1.6)",org.osgi.service.event;version="[1.1,1.3)",org.osgi.service.log;version="[1.1,1.4)",org.osgi.util.tracker;version="[1.3,1.5)"</Import-Package>
+ <Import-Package>org.papoose.core;resolution:=optional,org.osgi.framework;version="[1,2)",org.osgi.service.event;version="[1.1,2)",org.osgi.service.log;version="[1.1,2)",org.osgi.util.tracker;version="[1.3,2)"</Import-Package>
<Private-Package>org.papoose.log.util</Private-Package>
<Private-Package>org.papoose.log.util</Private-Package>
</instructions>
Modified: papoose-cmpn/trunk/pom.xml
===================================================================
--- papoose-cmpn/trunk/pom.xml 2010-02-26 14:08:08 UTC (rev 261)
+++ papoose-cmpn/trunk/pom.xml 2010-02-26 16:04:16 UTC (rev 262)
@@ -75,6 +75,12 @@
<dependencies>
<dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>com.springsource.javax.servlet</artifactId>
+ <version>2.4.0</version>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
@@ -153,6 +159,28 @@
<enabled>true</enabled>
</snapshots>
</repository>
+
+ <repository>
+ <id>com.springsource.repository.bundles.release</id>
+ <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
+ <url>http://repository.springsource.com/maven/bundles/release</url>
+ </repository>
+ <repository>
+ <id>com.springsource.repository.bundles.external</id>
+ <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
+ <url>http://repository.springsource.com/maven/bundles/external</url>
+ </repository>
+
+ <repository>
+ <id>com.springsource.repository.libraries.release</id>
+ <name>SpringSource Enterprise Bundle Repository - SpringSource Library Releases</name>
+ <url>http://repository.springsource.com/maven/libraries/release</url>
+ </repository>
+ <repository>
+ <id>com.springsource.repository.libraries.external</id>
+ <name>SpringSource Enterprise Bundle Repository - External Library Releases</name>
+ <url>http://repository.springsource.com/maven/libraries/external</url>
+ </repository>
</repositories>
<pluginRepositories>
Modified: papoose-cmpn/trunk/tck/tests/pom.xml
===================================================================
--- papoose-cmpn/trunk/tck/tests/pom.xml 2010-02-26 14:08:08 UTC (rev 261)
+++ papoose-cmpn/trunk/tck/tests/pom.xml 2010-02-26 16:04:16 UTC (rev 262)
@@ -31,20 +31,12 @@
<dependencies>
<dependency>
- <groupId>org.papoose.cmpn</groupId>
- <artifactId>papoose-cmpn-event</artifactId>
- <version>${project.version}</version>
+ <groupId>javax.servlet</groupId>
+ <artifactId>com.springsource.javax.servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.papoose.cmpn</groupId>
- <artifactId>papoose-cmpn-log</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
@@ -78,6 +70,27 @@
<artifactId>org.osgi.core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.papoose.cmpn</groupId>
+ <artifactId>papoose-cmpn-event</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.cmpn</groupId>
+ <artifactId>papoose-cmpn-http</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.cmpn</groupId>
+ <artifactId>papoose-cmpn-log</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
Copied: papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java (from rev 260, papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/log/LogServiceImplTest.java)
===================================================================
--- papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java (rev 0)
+++ papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java 2010-02-26 16:04:16 UTC (rev 262)
@@ -0,0 +1,113 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.tck.http;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Assert;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import org.ops4j.pax.exam.Inject;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+import org.ops4j.pax.exam.Option;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.compendiumProfile;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+
+import org.papoose.http.HttpServiceImpl;
+import org.papoose.http.ServletDispatcher;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+@RunWith(JUnit4TestRunner.class)
+public class HttpServiceImplTest
+{
+ @Inject
+ private BundleContext bundleContext = null;
+
+ @Configuration
+ public static Option[] configure()
+ {
+ return options(
+ equinox(),
+ // felix(),
+ // knopflerfish(),
+ // papoose(),
+ compendiumProfile(),
+ // vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+ // this is necessary to let junit runner not timout the remote process before attaching debugger
+ // setting timeout to 0 means wait as long as the remote service comes available.
+ // starting with version 0.5.0 of PAx Exam this is no longer required as by default the framework tests
+ // will not be triggered till the framework is not started
+ // waitForFrameworkStartup()
+ provision(
+ mavenBundle().groupId("javax.servlet").artifactId("com.springsource.javax.servlet").version(asInProject()),
+ mavenBundle().groupId("org.papoose.cmpn").artifactId("papoose-cmpn-http").version(asInProject())
+ )
+ );
+ }
+
+ @Test
+ public void test() throws Exception
+ {
+ Assert.assertNotNull(bundleContext);
+ ExecutorService executor = new ThreadPoolExecutor(1, 5, 100, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
+
+ ServletDispatcher dispatcher = new ServletDispatcher();
+ HttpServiceImpl httpService = new HttpServiceImpl(bundleContext, dispatcher);
+
+ httpService.start();
+ bundleContext.registerService(HttpService.class.getName(), httpService, null);
+
+ try
+ {
+ ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
+ HttpService service = (HttpService) bundleContext.getService(sr);
+
+ service.registerResources("/a/b", "/car", service.createDefaultHttpContext());
+ try
+ {
+ service.registerResources("/a/b", "/car", service.createDefaultHttpContext());
+ fail("Should not be able to register with same alias");
+ }
+ catch (NamespaceException ignore)
+ {
+ }
+
+ service.unregister("/a/b");
+ }
+ finally
+ {
+ httpService.stop();
+ executor.shutdown();
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-26 14:08:15
|
Revision: 261
http://osgi.svn.sourceforge.net/osgi/?rev=261&view=rev
Author: maguro
Date: 2010-02-26 14:08:08 +0000 (Fri, 26 Feb 2010)
Log Message:
-----------
Thoughts on using the access control context
Modified Paths:
--------------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
Added Paths:
-----------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java
papoose-cmpn/trunk/http/src/main/resources/mime.properties
Removed Paths:
-------------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-25 23:56:06 UTC (rev 260)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-26 14:08:08 UTC (rev 261)
@@ -22,7 +22,6 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
-import java.security.AccessControlContext;
import java.security.AccessController;
import java.util.Dictionary;
import java.util.HashMap;
@@ -46,6 +45,7 @@
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
private final static Properties EMPTY_PARAMS = new Properties();
private final Object lock = new Object();
+ private final Properties mime;
private final Map<HttpContext, ServletContextImpl> contexts = new HashMap<HttpContext, ServletContextImpl>();
private final Map<String, ServletRegistration> registrations = new HashMap<String, ServletRegistration>();
private final BundleContext context;
@@ -58,6 +58,16 @@
this.context = context;
this.dispatcher = dispatcher;
+ this.mime = new Properties();
+
+ try
+ {
+ this.mime.load(HttpServiceImpl.class.getClassLoader().getResourceAsStream("mime.properties"));
+ }
+ catch (IOException ioe)
+ {
+ LOGGER.log(Level.WARNING, "Unable to load default MIME mapping", ioe);
+ }
}
/**
@@ -120,7 +130,7 @@
try
{
- registerServlet(alias, new ServletWrapper(alias, name, httpContext, AccessController.getContext()), EMPTY_PARAMS, httpContext);
+ registerServlet(alias, new ResourceServletWrapper(alias, name, httpContext, AccessController.getContext(), mime), EMPTY_PARAMS, httpContext);
}
catch (ServletException se)
{
Copied: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java (from rev 260, papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java)
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java 2010-02-26 14:08:08 UTC (rev 261)
@@ -0,0 +1,171 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import org.osgi.service.http.HttpContext;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+class ResourceServletWrapper extends HttpServlet
+{
+ private final static String CLASS_NAME = ResourceServletWrapper.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final String alias;
+ private final String name;
+ private final HttpContext httpContext;
+ private final AccessControlContext acc;
+ private final Properties mime;
+
+ ResourceServletWrapper(String alias, String name, HttpContext httpContext, AccessControlContext acc, Properties mime)
+ {
+ this.alias = alias;
+ this.name = name;
+ this.httpContext = httpContext;
+ this.acc = acc;
+ this.mime = mime;
+ }
+
+ @Override
+ protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException
+ {
+ LOGGER.entering(CLASS_NAME, "service", new Object[]{ req, resp });
+
+ String path = req.getPathInfo();
+
+ path = path.substring(alias.length());
+ path = name + path;
+
+ final URL url = httpContext.getResource(path);
+
+ if (url == null) throw new ResourceNotFoundException();
+
+ String contentType = httpContext.getMimeType(path);
+ if (contentType == null)
+ {
+ int index = path.lastIndexOf(".");
+ if (index > 0) contentType = mime.getProperty(path.substring(index + 1));
+ }
+ if (contentType != null) resp.setContentType(contentType);
+
+ try
+ {
+ if (System.getSecurityManager() == null)
+ {
+ generateResponse(url, resp, req);
+ }
+ else
+ {
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
+ {
+ public Void run() throws Exception
+ {
+ generateResponse(url, resp, req);
+
+ return null;
+ }
+ }, acc);
+ }
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Exception exception = pae.getException();
+ if (exception instanceof ServletException) throw (ServletException) exception;
+ if (exception instanceof IOException) throw (IOException) exception;
+
+ resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+ catch (IOException ioe)
+ {
+ throw ioe;
+ }
+ catch (Exception e)
+ {
+ resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ LOGGER.exiting(CLASS_NAME, "service");
+ }
+
+ private void generateResponse(URL url, HttpServletResponse resp, HttpServletRequest req) throws IOException
+ {
+ LOGGER.entering(CLASS_NAME, "generateResponse", new Object[]{ url, resp, req });
+
+ URLConnection conn = url.openConnection();
+
+ long lastModified = conn.getLastModified();
+ if (lastModified != 0) resp.setDateHeader("Last-Modified", lastModified);
+
+ long modifiedSince = req.getDateHeader("If-Modified-Since");
+ if (lastModified == 0 || modifiedSince == -1 || lastModified > modifiedSince)
+ {
+ resp.setContentLength(copyResource(conn.getInputStream(), resp.getOutputStream()));
+ resp.setStatus(HttpServletResponse.SC_FOUND);
+ }
+ else
+ {
+ resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ }
+
+ LOGGER.exiting(CLASS_NAME, "generateResponse");
+ }
+
+ private int copyResource(InputStream in, OutputStream out) throws IOException
+ {
+ LOGGER.entering(CLASS_NAME, "copyResource", new Object[]{ in, out });
+
+ byte[] buf = new byte[4096];
+ int length = 0;
+ int n;
+
+ try
+ {
+ while ((n = in.read(buf, 0, buf.length)) != -1)
+ {
+ out.write(buf, 0, n);
+ length += n;
+ }
+
+ LOGGER.exiting(CLASS_NAME, "copyResource", length);
+
+ return length;
+ }
+ finally
+ {
+ in.close();
+ out.close();
+ }
+ }
+
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Deleted: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java 2010-02-25 23:56:06 UTC (rev 260)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java 2010-02-26 14:08:08 UTC (rev 261)
@@ -1,135 +0,0 @@
-/**
- *
- * Copyright 2010 (C) The original author or authors
- *
- * Licensed 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.papoose.http;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.logging.Logger;
-
-import org.osgi.service.http.HttpContext;
-
-
-/**
- * @version $Revision: $ $Date: $
- */
-class ServletWrapper extends HttpServlet
-{
- private final static String CLASS_NAME = ServletWrapper.class.getName();
- private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
- private final String alias;
- private final String name;
- private final HttpContext httpContext;
- private final AccessControlContext acc;
-
- ServletWrapper(String alias, String name, HttpContext httpContext, AccessControlContext acc)
- {
- this.alias = alias;
- this.name = name;
- this.httpContext = httpContext;
- this.acc = acc;
- }
-
- @Override
- protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException
- {
-
- final URL url = httpContext.getResource(name);
-
- if (url == null) throw new ResourceNotFoundException();
-
- String contentType = getServletContext().getMimeType(name);
- if (contentType != null) resp.setContentType(contentType);
-
- try
- {
- AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
- {
- public Void run() throws Exception
- {
- URLConnection conn = url.openConnection();
-
- long lastModified = conn.getLastModified();
- if (lastModified != 0) resp.setDateHeader("Last-Modified", lastModified);
-
- long modifiedSince = req.getDateHeader("If-Modified-Since");
- if (lastModified == 0 || modifiedSince == -1 || lastModified > modifiedSince)
- {
- resp.setContentLength(copyResource(conn.getInputStream(), resp.getOutputStream()));
- resp.setStatus(HttpServletResponse.SC_FOUND);
- }
- else
- {
- resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
- }
-
- return null;
- }
- }, acc);
- }
- catch (PrivilegedActionException pae)
- {
- Exception exception = pae.getException();
- if (exception instanceof ServletException) throw (ServletException) exception;
- if (exception instanceof IOException) throw (IOException) exception;
-
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- catch (Exception e)
- {
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- }
-
- private int copyResource(InputStream in, OutputStream out) throws IOException
- {
- LOGGER.entering(CLASS_NAME, "copyResource", new Object[]{ in, out });
-
- byte[] buf = new byte[4096];
- int length = 0;
- int n;
-
- try
- {
- while ((n = in.read(buf, 0, buf.length)) != -1)
- {
- out.write(buf, 0, n);
- length += n;
- }
-
- LOGGER.exiting(CLASS_NAME, "copyResource", length);
-
- return length;
- }
- finally
- {
- in.close();
- out.close();
- }
- }
-
-}
Added: papoose-cmpn/trunk/http/src/main/resources/mime.properties
===================================================================
--- papoose-cmpn/trunk/http/src/main/resources/mime.properties (rev 0)
+++ papoose-cmpn/trunk/http/src/main/resources/mime.properties 2010-02-26 14:08:08 UTC (rev 261)
@@ -0,0 +1,444 @@
+3dm=x-world/x-3dmf
+3dmf=x-world/x-3dmf
+a=application/octet-stream
+aab=application/x-authorware-bin
+aam=application/x-authorware-map
+aas=application/x-authorware-seg
+abc=text/vnd.abc
+acgi=text/html
+afl=video/animaflex
+ai=application/postscript
+aif=audio/aiff
+aifc=audio/aiff
+aiff=audio/aiff
+aim=application/x-aim
+aip=text/x-audiosoft-intra
+ani=application/x-navi-animation
+aos=application/x-nokia-9000-communicator-add-on-software
+aps=application/mime
+arc=application/octet-stream
+arj=application/arj
+art=image/x-jg
+asf=video/x-ms-asf
+asm=text/x-asm
+asp=text/asp
+asx=application/x-mplayer2
+au=audio/basic
+avi=video/avi
+avs=video/avs-video
+bcpio=application/x-bcpio
+bin=application/octet-stream
+bm=image/bmp
+bmp=image/bmp
+boo=application/book
+book=application/book
+boz=application/x-bzip2
+bsh=application/x-bsh
+bz=application/x-bzip
+bz2=application/x-bzip2
+c=text/plain
+c++=text/plain
+cat=application/vnd.ms-pki.seccat
+cc=text/plain
+ccad=application/clariscad
+cco=application/x-cocoa
+cdf=application/cdf
+cer=application/pkix-cert
+cha=application/x-chat
+chat=application/x-chat
+class=application/java
+com=application/octet-stream
+conf=text/plain
+cpio=application/x-cpio
+cpp=text/x-c
+cpt=application/mac-compactpro
+crl=application/pkcs-crl
+crt=application/pkix-cert
+csh=application/x-csh
+css=text/css
+dcr=application/x-director
+deepv=application/x-deepv
+def=text/plain
+der=application/x-x509-ca-cert
+dif=video/x-dv
+dir=application/x-director
+dl=video/dl
+doc=application/msword
+dot=application/msword
+dp=application/commonground
+drw=application/drafting
+dump=application/octet-stream
+dv=video/x-dv
+dvi=application/x-dvi
+dwf=model/vnd.dwf
+dwg=application/acad
+dxf=application/dxf
+dxr=application/x-director
+el=text/x-script.elisp
+elc=application/x-elc
+env=application/x-envoy
+eps=application/postscript
+es=application/x-esrehber
+etx=text/x-setext
+evy=application/envoy
+exe=application/octet-stream
+f=text/plain
+f77=text/x-fortran
+f90=text/plain
+fdf=application/vnd.fdf
+fif=image/fif
+fli=video/fli
+flo=image/florian
+flx=text/vnd.fmi.flexstor
+fmf=video/x-atomic3d-feature
+for=text/plain
+fpx=image/vnd.fpx
+frl=application/freeloader
+funk=audio/make
+g=text/plain
+g3=image/g3fax
+gif=image/gif
+gl=video/gl
+gsd=audio/x-gsm
+gsm=audio/x-gsm
+gsp=application/x-gsp
+gss=application/x-gss
+gtar=application/x-gtar
+gz=application/x-gzip
+gzip=application/x-gzip
+h=text/plain
+hdf=application/x-hdf
+help=application/x-helpfile
+hgl=application/vnd.hp-hpgl
+hh=text/plain
+hlb=text/x-script
+hlp=application/hlp
+hpg=application/vnd.hp-hpgl
+hpgl=application/vnd.hp-hpgl
+hqx=application/binhex
+hta=application/hta
+htc=text/x-component
+htm=text/html
+html=text/html
+htmls=text/html
+htt=text/webviewhtml
+htx=text/html
+ice=x-conference/x-cooltalk
+ico=image/x-icon
+idc=text/plain
+ief=image/ief
+iefs=image/ief
+iges=application/iges
+igs=application/iges
+ima=application/x-ima
+imap=application/x-httpd-imap
+inf=application/inf
+ins=application/x-internett-signup
+ip=application/x-ip2
+isu=video/x-isvideo
+it=audio/it
+iv=application/x-inventor
+ivr=i-world/i-vrml
+ivy=application/x-livescreen
+jam=audio/x-jam
+jav=text/plain
+java=text/plain
+jcm=application/x-java-commerce
+jfif=image/jpeg
+jfif-tbnl=image/jpeg
+jpe=image/jpeg
+jpeg=image/jpeg
+jpg=image/jpeg
+jps=image/x-jps
+js=application/x-javascript
+jut=image/jutvision
+kar=audio/midi
+ksh=application/x-ksh
+la=audio/nspaudio
+lam=audio/x-liveaudio
+latex=application/x-latex
+lha=application/lha
+lhx=application/octet-stream
+list=text/plain
+lma=audio/nspaudio
+log=text/plain
+lsp=application/x-lisp
+lst=text/plain
+lsx=text/x-la-asf
+ltx=application/x-latex
+lzh=application/octet-stream
+lzx=application/lzx
+m=text/plain
+m1v=video/mpeg
+m2a=audio/mpeg
+m2v=video/mpeg
+m3u=audio/x-mpequrl
+man=application/x-troff-man
+map=application/x-navimap
+mar=text/plain
+mbd=application/mbedlet
+mc$=application/x-magic-cap-package-1.0
+mcd=application/mcad
+mcf=image/vasa
+mcp=application/netmc
+me=application/x-troff-me
+mht=message/rfc822
+mhtml=message/rfc822
+mid=audio/midi
+midi=audio/midi
+mif=application/x-mif
+mime=message/rfc822
+mjf=audio/x-vnd.audioexplosion.mjuicemediafile
+mjpg=video/x-motion-jpeg
+mm=application/base64
+mme=application/base64
+mod=audio/mod
+moov=video/quicktime
+mov=video/quicktime
+movie=video/x-sgi-movie
+mp2=audio/mpeg
+mp3=audio/mpeg3
+mpa=audio/mpeg
+mpc=application/x-project
+mpe=video/mpeg
+mpeg=video/mpeg
+mpg=audio/mpeg
+mpga=audio/mpeg
+mpp=application/vnd.ms-project
+mpt=application/x-project
+mpv=application/x-project
+mpx=application/x-project
+mrc=application/marc
+ms=application/x-troff-ms
+mv=video/x-sgi-movie
+my=audio/make
+mzz=application/x-vnd.audioexplosion.mzz
+nap=image/naplps
+naplps=image/naplps
+nc=application/x-netcdf
+ncm=application/vnd.nokia.configuration-message
+nif=image/x-niff
+niff=image/x-niff
+nix=application/x-mix-transfer
+nsc=application/x-conference
+nvd=application/x-navidoc
+o=application/octet-stream
+oda=application/oda
+omc=application/x-omc
+omcd=application/x-omcdatamaker
+omcr=application/x-omcregerator
+p=text/x-pascal
+p10=application/pkcs10
+p12=application/pkcs-12
+p7a=application/x-pkcs7-signature
+p7c=application/pkcs7-mime
+p7m=application/pkcs7-mime
+p7r=application/x-pkcs7-certreqresp
+p7s=application/pkcs7-signature
+part=application/pro_eng
+pas=text/pascal
+pbm=image/x-portable-bitmap
+pcl=application/vnd.hp-pcl
+pct=image/x-pict
+pcx=image/x-pcx
+pdb=chemical/x-pdb
+pdf=application/pdf
+pfunk=audio/make
+pgm=image/x-portable-graymap
+pic=image/pict
+pict=image/pict
+pkg=application/x-newton-compatible-pkg
+pko=application/vnd.ms-pki.pko
+pl=text/plain
+plx=application/x-pixclscript
+pm=image/x-xpixmap
+pm4=application/x-pagemaker
+pm5=application/x-pagemaker
+png=image/png
+pnm=application/x-portable-anymap
+pot=application/mspowerpoint
+pov=model/x-pov
+ppa=application/vnd.ms-powerpoint
+ppm=image/x-portable-pixmap
+pps=application/mspowerpoint
+ppt=application/mspowerpoint
+ppz=application/mspowerpoint
+pre=application/x-freelance
+prt=application/pro_eng
+ps=application/postscript
+psd=application/octet-stream
+pvu=paleovu/x-pv
+pwz=application/vnd.ms-powerpoint
+py=text/x-script.phyton
+pyc=applicaiton/x-bytecode.python
+qcp=audio/vnd.qcelp
+qd3=x-world/x-3dmf
+qd3d=x-world/x-3dmf
+qif=image/x-quicktime
+qt=video/quicktime
+qtc=video/x-qtc
+qti=image/x-quicktime
+qtif=image/x-quicktime
+ra=audio/x-realaudio
+ram=audio/x-pn-realaudio
+ras=image/cmu-raster
+rast=image/cmu-raster
+rexx=text/x-script.rexx
+rf=image/vnd.rn-realflash
+rgb=image/x-rgb
+rm=application/vnd.rn-realmedia
+rmi=audio/mid
+rmm=audio/x-pn-realaudio
+rmp=audio/x-pn-realaudio
+rng=application/ringing-tones
+rnx=application/vnd.rn-realplayer
+roff=application/x-troff
+rp=image/vnd.rn-realpix
+rpm=audio/x-pn-realaudio-plugin
+rt=text/richtext
+rtx=text/richtext
+rv=video/vnd.rn-realvideo
+s=text/x-asm
+s3m=audio/s3m
+saveme=application/octet-stream
+sbk=application/x-tbook
+scm=video/x-scm
+sdml=text/plain
+sdp=application/sdp
+sdr=application/sounder
+sea=application/sea
+set=application/set
+sgm=text/sgml
+sgml=text/sgml
+sh=application/x-sh
+shar=application/x-shar
+shtml=text/html
+sid=audio/x-psid
+sit=application/x-sit
+skd=application/x-koan
+skm=application/x-koan
+skp=application/x-koan
+skt=application/x-koan
+sl=application/x-seelogo
+smi=application/smil
+smil=application/smil
+snd=audio/basic
+sol=application/solids
+spc=text/x-speech
+spl=application/futuresplash
+spr=application/x-sprite
+sprite=application/x-sprite
+src=application/x-wais-source
+ssi=text/x-server-parsed-html
+ssm=application/streamingmedia
+sst=application/vnd.ms-pki.certstore
+step=application/step
+stl=application/sla
+stp=application/step
+sv4cpio=application/x-sv4cpio
+sv4crc=application/x-sv4crc
+svf=image/vnd.dwg
+svr=application/x-world
+swf=application/x-shockwave-flash
+t=application/x-troff
+talk=text/x-speech
+tar=application/x-tar
+tbk=application/toolbook
+tcl=application/x-tcl
+tcsh=text/x-script.tcsh
+tex=application/x-tex
+texi=application/x-texinfo
+texinfo=application/x-texinfo
+text=text/plain
+tgz=application/gnutar
+tif=image/tiff
+tr=application/x-troff
+tsi=audio/tsp-audio
+tsp=application/dsptype
+tsv=text/tab-separated-values
+turbot=image/florian
+txt=text/plain
+uil=text/x-uil
+uni=text/uri-list
+unis=text/uri-list
+unv=application/i-deas
+uri=text/uri-list
+uris=text/uri-list
+ustar=application/x-ustar
+uu=application/octet-stream
+uue=text/x-uuencode
+vcd=application/x-cdlink
+vcs=text/x-vcalendar
+vda=application/vda
+vdo=video/vdo
+vew=application/groupwise
+viv=video/vivo
+vivo=video/vivo
+vmd=application/vocaltec-media-desc
+vmf=application/vocaltec-media-file
+voc=audio/voc
+vos=video/vosaic
+vox=audio/voxware
+vqe=audio/x-twinvq-plugin
+vqf=audio/x-twinvq
+vql=audio/x-twinvq-plugin
+vrml=application/x-vrml
+vrt=x-world/x-vrt
+vsd=application/x-visio
+vst=application/x-visio
+vsw=application/x-visio
+w60=application/wordperfect6.0
+w61=application/wordperfect6.1
+w6w=application/msword
+wav=audio/wav
+wb1=application/x-qpro
+wbmp=image/vnd.wap.wbmp
+web=application/vnd.xara
+wiz=application/msword
+wk1=application/x-123
+wmf=windows/metafile
+wml=text/vnd.wap.wml
+wmlc=application/vnd.wap.wmlc
+wmls=text/vnd.wap.wmlscript
+wmlsc=application/vnd.wap.wmlscriptc
+word=application/msword
+wp=application/wordperfect
+wp5=application/wordperfect
+wp6=application/wordperfect
+wpd=application/wordperfect
+wq1=application/x-lotus
+wri=application/mswrite
+wrl=application/x-world
+wrz=model/vrml
+wsc=text/scriplet
+wsrc=application/x-wais-source
+wtk=application/x-wintalk
+xbm=image/xbm
+xdr=video/x-amt-demorun
+xgz=xgl/drawing
+xif=image/vnd.xiff
+xl=application/excel
+xla=application/excel
+xlb=application/excel
+xlc=application/excel
+xld=application/excel
+xlk=application/excel
+xll=application/excel
+xlm=application/excel
+xls=application/excel
+xlt=application/excel
+xlv=application/excel
+xlw=application/excel
+xm=audio/xm
+xml=text/xml
+xmz=xgl/movie
+xpix=application/x-vnd.ls-xpix
+xpm=image/xpm
+x-png=image/png
+xsr=video/x-amt-showrun
+xwd=image/x-xwd
+xyz=chemical/x-pdb
+z=application/x-compress
+zip=application/zip
+zoo=application/octet-stream
+zsh=text/x-script.zsh
\ No newline at end of file
Property changes on: papoose-cmpn/trunk/http/src/main/resources/mime.properties
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-25 23:56:12
|
Revision: 260
http://osgi.svn.sourceforge.net/osgi/?rev=260&view=rev
Author: maguro
Date: 2010-02-25 23:56:06 +0000 (Thu, 25 Feb 2010)
Log Message:
-----------
Removed test
Removed Paths:
-------------
papoose-cmpn/trunk/test.java
Deleted: papoose-cmpn/trunk/test.java
===================================================================
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-25 23:55:57
|
Revision: 259
http://osgi.svn.sourceforge.net/osgi/?rev=259&view=rev
Author: maguro
Date: 2010-02-25 23:55:50 +0000 (Thu, 25 Feb 2010)
Log Message:
-----------
More sketchwork
Modified Paths:
--------------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java
Added Paths:
-----------
papoose-cmpn/trunk/config/src/main/java/org/
papoose-cmpn/trunk/config/src/main/java/org/papoose/
papoose-cmpn/trunk/config/src/main/java/org/papoose/config/
papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationAdminImpl.java
papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java
papoose-cmpn/trunk/test.java
Added: papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationAdminImpl.java
===================================================================
--- papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationAdminImpl.java (rev 0)
+++ papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationAdminImpl.java 2010-02-25 23:55:50 UTC (rev 259)
@@ -0,0 +1,59 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.config;
+
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ConfigurationAdminImpl implements ConfigurationAdmin
+{
+ private final static String CLASS_NAME = ConfigurationAdminImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+
+ public Configuration createFactoryConfiguration(String factoryPid) throws IOException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Configuration createFactoryConfiguration(String factoryPid, String location) throws IOException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Configuration getConfiguration(String pid, String location) throws IOException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Configuration getConfiguration(String pid) throws IOException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException
+ {
+ return new Configuration[0]; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationAdminImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationImpl.java
===================================================================
--- papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationImpl.java (rev 0)
+++ papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationImpl.java 2010-02-25 23:55:50 UTC (rev 259)
@@ -0,0 +1,73 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.config;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.logging.Logger;
+
+import org.osgi.service.cm.Configuration;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ConfigurationImpl implements Configuration
+{
+ private final static String CLASS_NAME = ConfigurationImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+
+ public String getPid()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Dictionary getProperties()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void update(Dictionary properties) throws IOException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void delete() throws IOException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getFactoryPid()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void update() throws IOException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setBundleLocation(String bundleLocation)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getBundleLocation()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java 2010-02-25 23:55:50 UTC (rev 259)
@@ -0,0 +1,24 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ResourceNotFoundException extends RuntimeException
+{
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-25 20:22:55 UTC (rev 258)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-25 23:55:50 UTC (rev 259)
@@ -41,9 +41,6 @@
{
String path = req.getPathInfo();
- ServletRegistration r = null;
-
- done:
while (true)
{
for (ServletRegistration registration : registrations)
@@ -52,8 +49,29 @@
{
if (registration.getContext().handleSecurity(req, resp))
{
- r = registration;
- break done;
+ try
+ {
+ registration.getServlet().service(req, resp);
+ return;
+ }
+ catch (ServletException e)
+ {
+ throw e;
+ }
+ catch (IOException e)
+ {
+ throw e;
+ }
+ catch (ResourceNotFoundException e)
+ {
+ if (LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("Registration at " + registration.getAlias() + " has no resource");
+ }
+ catch (Throwable t)
+ {
+ LOGGER.log(Level.WARNING, "Problems calling ", t);
+ resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return;
+ }
}
else
{
@@ -68,30 +86,7 @@
path = path.substring(0, index);
}
- if (r != null)
- {
- try
- {
- r.getServlet().service(req, resp);
- }
- catch (ServletException e)
- {
- throw e;
- }
- catch (IOException e)
- {
- throw e;
- }
- catch (Throwable t)
- {
- LOGGER.log(Level.WARNING, "Problems calling ", t);
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- }
- else
- {
- resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
- }
+ resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
void register(ServletRegistration registration)
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java 2010-02-25 20:22:55 UTC (rev 258)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java 2010-02-25 23:55:50 UTC (rev 259)
@@ -21,7 +21,14 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.logging.Logger;
import org.osgi.service.http.HttpContext;
@@ -48,8 +55,81 @@
}
@Override
- protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException
{
- super.service(req, resp); //Todo change body of overridden methods use File | Settings | File Templates.
+
+ final URL url = httpContext.getResource(name);
+
+ if (url == null) throw new ResourceNotFoundException();
+
+ String contentType = getServletContext().getMimeType(name);
+ if (contentType != null) resp.setContentType(contentType);
+
+ try
+ {
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
+ {
+ public Void run() throws Exception
+ {
+ URLConnection conn = url.openConnection();
+
+ long lastModified = conn.getLastModified();
+ if (lastModified != 0) resp.setDateHeader("Last-Modified", lastModified);
+
+ long modifiedSince = req.getDateHeader("If-Modified-Since");
+ if (lastModified == 0 || modifiedSince == -1 || lastModified > modifiedSince)
+ {
+ resp.setContentLength(copyResource(conn.getInputStream(), resp.getOutputStream()));
+ resp.setStatus(HttpServletResponse.SC_FOUND);
+ }
+ else
+ {
+ resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ }
+
+ return null;
+ }
+ }, acc);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Exception exception = pae.getException();
+ if (exception instanceof ServletException) throw (ServletException) exception;
+ if (exception instanceof IOException) throw (IOException) exception;
+
+ resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+ catch (Exception e)
+ {
+ resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
}
+
+ private int copyResource(InputStream in, OutputStream out) throws IOException
+ {
+ LOGGER.entering(CLASS_NAME, "copyResource", new Object[]{ in, out });
+
+ byte[] buf = new byte[4096];
+ int length = 0;
+ int n;
+
+ try
+ {
+ while ((n = in.read(buf, 0, buf.length)) != -1)
+ {
+ out.write(buf, 0, n);
+ length += n;
+ }
+
+ LOGGER.exiting(CLASS_NAME, "copyResource", length);
+
+ return length;
+ }
+ finally
+ {
+ in.close();
+ out.close();
+ }
+ }
+
}
Property changes on: papoose-cmpn/trunk/test.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-25 20:23:02
|
Revision: 258
http://osgi.svn.sourceforge.net/osgi/?rev=258&view=rev
Author: maguro
Date: 2010-02-25 20:22:55 +0000 (Thu, 25 Feb 2010)
Log Message:
-----------
Need AccessControlContext for URL handling context
Modified Paths:
--------------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-25 03:17:24 UTC (rev 257)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-25 20:22:55 UTC (rev 258)
@@ -22,6 +22,8 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
+import java.security.AccessControlContext;
+import java.security.AccessController;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Map;
@@ -118,7 +120,7 @@
try
{
- registerServlet(alias, new ServletWrapper(alias, name, httpContext), EMPTY_PARAMS, httpContext);
+ registerServlet(alias, new ServletWrapper(alias, name, httpContext, AccessController.getContext()), EMPTY_PARAMS, httpContext);
}
catch (ServletException se)
{
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java 2010-02-25 03:17:24 UTC (rev 257)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java 2010-02-25 20:22:55 UTC (rev 258)
@@ -21,6 +21,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.security.AccessControlContext;
import java.util.logging.Logger;
import org.osgi.service.http.HttpContext;
@@ -29,19 +30,21 @@
/**
* @version $Revision: $ $Date: $
*/
- class ServletWrapper extends HttpServlet
+class ServletWrapper extends HttpServlet
{
private final static String CLASS_NAME = ServletWrapper.class.getName();
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
private final String alias;
private final String name;
private final HttpContext httpContext;
+ private final AccessControlContext acc;
- ServletWrapper(String alias, String name, HttpContext httpContext)
+ ServletWrapper(String alias, String name, HttpContext httpContext, AccessControlContext acc)
{
this.alias = alias;
this.name = name;
this.httpContext = httpContext;
+ this.acc = acc;
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-25 03:17:30
|
Revision: 257
http://osgi.svn.sourceforge.net/osgi/?rev=257&view=rev
Author: maguro
Date: 2010-02-25 03:17:24 +0000 (Thu, 25 Feb 2010)
Log Message:
-----------
Fixed failed security check
Modified Paths:
--------------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-25 01:37:32 UTC (rev 256)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-25 03:17:24 UTC (rev 257)
@@ -55,6 +55,10 @@
r = registration;
break done;
}
+ else
+ {
+ return;
+ }
}
}
Modified: papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java
===================================================================
--- papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java 2010-02-25 01:37:32 UTC (rev 256)
+++ papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java 2010-02-25 03:17:24 UTC (rev 257)
@@ -84,6 +84,34 @@
}
@Test
+ public void testFailedSecurityCheck() throws Exception
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ ServletDispatcher dispatcher = new ServletDispatcher();
+ Servlet servlet = mock(Servlet.class);
+ HttpContext context = mock(HttpContext.class);
+ ServletRegistration registration = new ServletRegistration("/a/b", servlet, context);
+
+ when(context.handleSecurity(request, response)).thenAnswer(new Answer()
+ {
+ public Boolean answer(InvocationOnMock invocation)
+ {
+ HttpServletResponse resp = (HttpServletResponse) invocation.getArguments()[1];
+ resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ return false;
+ }
+ });
+ when(request.getPathInfo()).thenReturn("/a/b/c");
+
+ dispatcher.register(registration);
+ dispatcher.service(request, response);
+
+ verify(context, only()).handleSecurity(request, response);
+ verify(response, only()).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ }
+
+ @Test
public void testSimplePathRegistrant() throws Exception
{
HttpServletRequest request = mock(HttpServletRequest.class);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-25 01:37:46
|
Revision: 256
http://osgi.svn.sourceforge.net/osgi/?rev=256&view=rev
Author: maguro
Date: 2010-02-25 01:37:32 +0000 (Thu, 25 Feb 2010)
Log Message:
-----------
Minor cleanup
Modified Paths:
--------------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-24 23:41:47 UTC (rev 255)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-25 01:37:32 UTC (rev 256)
@@ -21,9 +21,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -60,26 +58,12 @@
}
}
+ path = path.substring(0, Math.max(0, path.length() - 1));
int index = path.lastIndexOf('/');
- if (index == 0) break;
+ if (index == -1) break;
path = path.substring(0, index);
}
- if (r == null)
- {
- for (ServletRegistration registration : registrations)
- {
- if ("/".equals(registration.getAlias()))
- {
- if (registration.getContext().handleSecurity(req, resp))
- {
- r = registration;
- break;
- }
- }
- }
- }
-
if (r != null)
{
try
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java 2010-02-24 23:41:47 UTC (rev 255)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java 2010-02-25 01:37:32 UTC (rev 256)
@@ -32,7 +32,7 @@
ServletRegistration(String alias, Servlet servlet, HttpContext context)
{
- this.alias = alias;
+ this.alias = ("/".equals(alias) ? "" : alias);
this.servlet = servlet;
this.context = context;
}
Modified: papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java
===================================================================
--- papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java 2010-02-24 23:41:47 UTC (rev 255)
+++ papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java 2010-02-25 01:37:32 UTC (rev 256)
@@ -23,7 +23,6 @@
import static junit.framework.Assert.fail;
import org.junit.Test;
-import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-24 23:41:54
|
Revision: 255
http://osgi.svn.sourceforge.net/osgi/?rev=255&view=rev
Author: maguro
Date: 2010-02-24 23:41:47 +0000 (Wed, 24 Feb 2010)
Log Message:
-----------
More HTTP service work
Modified Paths:
--------------
papoose-cmpn/trunk/http/pom.xml
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
papoose-cmpn/trunk/pom.xml
Added Paths:
-----------
papoose-cmpn/trunk/http/src/test/java/org/
papoose-cmpn/trunk/http/src/test/java/org/papoose/
papoose-cmpn/trunk/http/src/test/java/org/papoose/http/
papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java
Modified: papoose-cmpn/trunk/http/pom.xml
===================================================================
--- papoose-cmpn/trunk/http/pom.xml 2010-02-24 23:38:32 UTC (rev 254)
+++ papoose-cmpn/trunk/http/pom.xml 2010-02-24 23:41:47 UTC (rev 255)
@@ -41,6 +41,12 @@
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-24 23:38:32 UTC (rev 254)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-24 23:41:47 UTC (rev 255)
@@ -63,6 +63,8 @@
*/
public void registerServlet(String alias, Servlet servlet, Dictionary initParams, HttpContext httpContext) throws ServletException, NamespaceException
{
+ LOGGER.entering(CLASS_NAME, "registerServlet", new Object[]{ alias, servlet, initParams, httpContext });
+
ServletRegistration registration;
ServletContextImpl servletContext;
synchronized (lock)
@@ -97,9 +99,13 @@
if (servletContext.getReferenceCount() == 0) contexts.remove(registration.getContext());
}
+ LOGGER.throwing(CLASS_NAME, "registerServlet", t);
+
if (t instanceof ServletException) throw (ServletException) t;
throw (RuntimeException) t;
}
+
+ LOGGER.exiting(CLASS_NAME, "registerServlet");
}
@@ -108,6 +114,8 @@
*/
public void registerResources(String alias, String name, HttpContext httpContext) throws NamespaceException
{
+ LOGGER.entering(CLASS_NAME, "registerResources", new Object[]{ alias, name, httpContext });
+
try
{
registerServlet(alias, new ServletWrapper(alias, name, httpContext), EMPTY_PARAMS, httpContext);
@@ -116,6 +124,8 @@
{
LOGGER.log(Level.SEVERE, "Error registering resource wrapper servlet", se);
}
+
+ LOGGER.exiting(CLASS_NAME, "registerResources");
}
/**
@@ -123,6 +133,8 @@
*/
public void unregister(String alias)
{
+ LOGGER.entering(CLASS_NAME, "unregister", alias);
+
ServletRegistration registration;
synchronized (lock)
{
@@ -146,6 +158,8 @@
{
LOGGER.log(Level.WARNING, "Error destroying servlet", t);
}
+
+ LOGGER.exiting(CLASS_NAME, "unregister");
}
/**
@@ -153,7 +167,9 @@
*/
public HttpContext createDefaultHttpContext()
{
- return new HttpContext()
+ LOGGER.entering(CLASS_NAME, "createDefaultHttpContext");
+
+ HttpContext defaultContext = new HttpContext()
{
public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
{
@@ -172,5 +188,9 @@
return null;
}
};
+
+ LOGGER.exiting(CLASS_NAME, "createDefaultHttpContext", defaultContext);
+
+ return defaultContext;
}
}
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-24 23:38:32 UTC (rev 254)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-24 23:41:47 UTC (rev 255)
@@ -21,7 +21,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -41,40 +43,76 @@
{
String path = req.getPathInfo();
- for (ServletRegistration registration : registrations)
+ ServletRegistration r = null;
+
+ done:
+ while (true)
{
- if (path.startsWith(registration.getAlias()))
+ for (ServletRegistration registration : registrations)
{
- if (registration.getContext().handleSecurity(req, resp))
+ if (path.equals(registration.getAlias()))
{
- try
+ if (registration.getContext().handleSecurity(req, resp))
{
- registration.getServlet().service(req, resp);
+ r = registration;
+ break done;
}
- catch (ServletException e)
+ }
+ }
+
+ int index = path.lastIndexOf('/');
+ if (index == 0) break;
+ path = path.substring(0, index);
+ }
+
+ if (r == null)
+ {
+ for (ServletRegistration registration : registrations)
+ {
+ if ("/".equals(registration.getAlias()))
+ {
+ if (registration.getContext().handleSecurity(req, resp))
{
- throw e;
+ r = registration;
+ break;
}
- catch (IOException e)
- {
- throw e;
- }
- catch(Throwable t)
- {
- LOGGER.log(Level.WARNING, "Problems calling ", t);
- }
}
}
}
+
+ if (r != null)
+ {
+ try
+ {
+ r.getServlet().service(req, resp);
+ }
+ catch (ServletException e)
+ {
+ throw e;
+ }
+ catch (IOException e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ LOGGER.log(Level.WARNING, "Problems calling ", t);
+ resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+ }
+ else
+ {
+ resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ }
}
void register(ServletRegistration registration)
{
-
+ registrations.add(registration);
}
void unregister(ServletRegistration registration)
{
-
+ registrations.remove(registration);
}
}
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java 2010-02-24 23:38:32 UTC (rev 254)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java 2010-02-24 23:41:47 UTC (rev 255)
@@ -17,8 +17,6 @@
package org.papoose.http;
import javax.servlet.Servlet;
-import java.util.Dictionary;
-import java.util.logging.Logger;
import org.osgi.service.http.HttpContext;
@@ -28,8 +26,6 @@
*/
class ServletRegistration
{
- private final static String CLASS_NAME = ServletRegistration.class.getName();
- private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
private final String alias;
private final Servlet servlet;
private final HttpContext context;
@@ -55,4 +51,21 @@
{
return servlet;
}
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ServletRegistration that = (ServletRegistration) o;
+
+ return alias.equals(that.alias);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return alias.hashCode();
+ }
}
Added: papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java
===================================================================
--- papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java (rev 0)
+++ papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java 2010-02-24 23:41:47 UTC (rev 255)
@@ -0,0 +1,222 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import static junit.framework.Assert.fail;
+import org.junit.Test;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.only;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.osgi.service.http.HttpContext;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ServletDispatcherTest
+{
+ @Test
+ public void testNoRegistrants() throws Exception
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ ServletDispatcher dispatcher = new ServletDispatcher();
+
+ when(request.getPathInfo()).thenReturn("/a/b/c");
+
+ dispatcher.service(request, response);
+
+ verify(response, only()).setStatus(HttpServletResponse.SC_NOT_FOUND);
+ }
+
+ @Test
+ public void testOneRegistrant() throws Exception
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ ServletDispatcher dispatcher = new ServletDispatcher();
+ Servlet servlet = mock(Servlet.class);
+ HttpContext context = mock(HttpContext.class);
+ ServletRegistration registration = new ServletRegistration("/a/b", servlet, context);
+
+ doAnswer(new Answer()
+ {
+ public Object answer(InvocationOnMock invocation)
+ {
+ HttpServletResponse resp = (HttpServletResponse) invocation.getArguments()[1];
+ resp.setStatus(HttpServletResponse.SC_OK);
+ return null;
+ }
+ }).when(servlet).service(request, response);
+ when(context.handleSecurity(request, response)).thenReturn(true);
+ when(request.getPathInfo()).thenReturn("/a/b/c");
+
+ dispatcher.register(registration);
+ dispatcher.service(request, response);
+
+ verify(context, only()).handleSecurity(request, response);
+ verify(response, only()).setStatus(HttpServletResponse.SC_OK);
+ }
+
+ @Test
+ public void testSimplePathRegistrant() throws Exception
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ ServletDispatcher dispatcher = new ServletDispatcher();
+ Servlet servlet = mock(Servlet.class);
+ HttpContext context = mock(HttpContext.class);
+ ServletRegistration registration = new ServletRegistration("/", servlet, context);
+
+ doAnswer(new Answer()
+ {
+ public Object answer(InvocationOnMock invocation)
+ {
+ HttpServletResponse resp = (HttpServletResponse) invocation.getArguments()[1];
+ resp.setStatus(HttpServletResponse.SC_OK);
+ return null;
+ }
+ }).when(servlet).service(request, response);
+ when(context.handleSecurity(request, response)).thenReturn(true);
+ when(request.getPathInfo()).thenReturn("/a/b/c");
+
+ dispatcher.register(registration);
+ dispatcher.service(request, response);
+
+ verify(context, only()).handleSecurity(request, response);
+ verify(response, only()).setStatus(HttpServletResponse.SC_OK);
+ }
+
+ @Test
+ public void testNaughtyRegistrant() throws Exception
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ ServletDispatcher dispatcher = new ServletDispatcher();
+ Servlet servlet = mock(Servlet.class);
+ HttpContext context = mock(HttpContext.class);
+ ServletRegistration registration = new ServletRegistration("/a/b", servlet, context);
+
+ doThrow(new NullPointerException()).when(servlet).service(request, response);
+ when(context.handleSecurity(request, response)).thenReturn(true);
+ when(request.getPathInfo()).thenReturn("/a/b/c");
+
+ dispatcher.register(registration);
+ dispatcher.service(request, response);
+
+ verify(context, only()).handleSecurity(request, response);
+ verify(response, only()).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ @Test
+ public void testStumblingRegistrant() throws Exception
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ ServletDispatcher dispatcher = new ServletDispatcher();
+ Servlet servlet = mock(Servlet.class);
+ HttpContext context = mock(HttpContext.class);
+ ServletRegistration registration = new ServletRegistration("/a/b", servlet, context);
+
+ doThrow(new ServletException()).when(servlet).service(request, response);
+ when(context.handleSecurity(request, response)).thenReturn(true);
+ when(request.getPathInfo()).thenReturn("/a/b/c");
+
+ dispatcher.register(registration);
+ try
+ {
+ dispatcher.service(request, response);
+ fail("Should have passed on the exception");
+ }
+ catch (ServletException ignore)
+ {
+ }
+
+ verify(context, only()).handleSecurity(request, response);
+ verify(response, never()).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ @Test
+ public void testWrongPathRegistrant() throws Exception
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ ServletDispatcher dispatcher = new ServletDispatcher();
+ Servlet servlet = mock(Servlet.class);
+ HttpContext context = mock(HttpContext.class);
+ ServletRegistration registration = new ServletRegistration("/cad", servlet, context);
+
+ doAnswer(new Answer()
+ {
+ public Object answer(InvocationOnMock invocation)
+ {
+ HttpServletResponse resp = (HttpServletResponse) invocation.getArguments()[1];
+ resp.setStatus(HttpServletResponse.SC_OK);
+ return null;
+ }
+ }).when(servlet).service(request, response);
+ when(context.handleSecurity(request, response)).thenReturn(true);
+ when(request.getPathInfo()).thenReturn("/a/b/c");
+
+ dispatcher.register(registration);
+ dispatcher.service(request, response);
+
+ verify(context, never()).handleSecurity(request, response);
+ verify(response, only()).setStatus(HttpServletResponse.SC_NOT_FOUND);
+ }
+
+ @Test
+ public void testMatchingRegistrant() throws Exception
+ {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ ServletDispatcher dispatcher = new ServletDispatcher();
+ Servlet servlet = mock(Servlet.class);
+ HttpContext context = mock(HttpContext.class);
+ ServletRegistration registration = new ServletRegistration("/a/b", servlet, context);
+
+ doAnswer(new Answer()
+ {
+ public Object answer(InvocationOnMock invocation)
+ {
+ HttpServletResponse resp = (HttpServletResponse) invocation.getArguments()[1];
+ resp.setStatus(HttpServletResponse.SC_OK);
+ return null;
+ }
+ }).when(servlet).service(request, response);
+ when(context.handleSecurity(request, response)).thenReturn(true);
+ when(request.getPathInfo()).thenReturn("/a/bar");
+
+ dispatcher.register(registration);
+ dispatcher.service(request, response);
+
+ verify(context, never()).handleSecurity(request, response);
+ verify(response, only()).setStatus(HttpServletResponse.SC_NOT_FOUND);
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/pom.xml
===================================================================
--- papoose-cmpn/trunk/pom.xml 2010-02-24 23:38:32 UTC (rev 254)
+++ papoose-cmpn/trunk/pom.xml 2010-02-24 23:41:47 UTC (rev 255)
@@ -82,6 +82,13 @@
</dependency>
<dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.8.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
<version>${paxExamVersion}</version>
@@ -122,12 +129,6 @@
<version>1.0.0.SNAPSHOT</version>
</dependency>
- <dependency>
- <groupId>org.papoose.test</groupId>
- <artifactId>papoose-test-bundle</artifactId>
- <version>${papooseTestVersion}</version>
- </dependency>
-
</dependencies>
</dependencyManagement>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-24 23:38:38
|
Revision: 254
http://osgi.svn.sourceforge.net/osgi/?rev=254&view=rev
Author: maguro
Date: 2010-02-24 23:38:32 +0000 (Wed, 24 Feb 2010)
Log Message:
-----------
Papoose boot level service for event admin
Modified Paths:
--------------
papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java
Modified: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java
===================================================================
--- papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java 2010-02-24 18:28:47 UTC (rev 253)
+++ papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java 2010-02-24 23:38:32 UTC (rev 254)
@@ -16,9 +16,19 @@
*/
package org.papoose.event;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
import java.util.logging.Logger;
+import org.osgi.framework.BundleContext;
+
import org.papoose.core.Papoose;
+import org.papoose.event.util.Util;
/**
@@ -27,17 +37,82 @@
public class PapooseBootLevelService
{
private final static String CLASS_NAME = PapooseBootLevelService.class.getName();
+ public final static String LOG_SERVICE_USE_PAPOOSE_THREAD_POOL = CLASS_NAME + ".usePapooseThreadPool";
+ public final static String LOG_SERVICE_CORE_POOL_SIZE = CLASS_NAME + ".corePoolSize";
+ public final static String LOG_SERVICE_MAX_POOL_SIZE = CLASS_NAME + ".maximumPoolSize";
+ public final static String LOG_SERVICE_KEEP_ALIVE_TIME = CLASS_NAME + ".keepAliveTime";
+ public final static String LOG_SERVICE_TIME_UNIT = CLASS_NAME + ".timeUnit";
+ public final static String LOG_SERVICE_SCHEDULE_CORE_POOL_SIZE = CLASS_NAME + ".scheduleCorePoolSize";
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private volatile EventAdminImpl eventAdminService;
public void start(Papoose papoose)
{
LOGGER.entering(CLASS_NAME, "start", papoose);
+
+ if (papoose == null) throw new IllegalArgumentException("Papoose instance is null");
+
+ if (eventAdminService != null)
+ {
+ LOGGER.log(Level.WARNING, "Event Admin service already started");
+ return;
+ }
+
+ ExecutorService executor;
+
+ if (papoose.getProperty(LOG_SERVICE_USE_PAPOOSE_THREAD_POOL) != null)
+ {
+ LOGGER.finest("Using Papoose's thread pool");
+
+ executor = papoose.getExecutorService();
+ }
+ else
+ {
+ int corePoolSize = Util.parseInt(papoose.getProperty(LOG_SERVICE_CORE_POOL_SIZE), 1);
+ int maximumPoolSize = Util.parseInt(papoose.getProperty(LOG_SERVICE_MAX_POOL_SIZE), 5);
+ int keepAliveTime = Util.parseInt(papoose.getProperty(LOG_SERVICE_KEEP_ALIVE_TIME), 1);
+ TimeUnit unit = Util.parseTimeUnit(papoose.getProperty(LOG_SERVICE_TIME_UNIT), TimeUnit.SECONDS);
+
+ if (LOGGER.isLoggable(Level.FINEST))
+ {
+ LOGGER.finest("Creating own thread pool");
+ LOGGER.finest("corePoolSize: " + corePoolSize);
+ LOGGER.finest("maximumPoolSize: " + maximumPoolSize);
+ LOGGER.finest("keepAliveTime: " + keepAliveTime);
+ LOGGER.finest("unit: " + unit);
+ }
+
+ executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, new LinkedBlockingQueue<Runnable>());
+ }
+
+ int scheduleCorePoolSize = Util.parseInt(papoose.getProperty(LOG_SERVICE_SCHEDULE_CORE_POOL_SIZE), 1);
+
+ if (LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("scheduleCorePoolSize: " + scheduleCorePoolSize);
+
+ ScheduledExecutorService scheduledExecutor = new ScheduledThreadPoolExecutor(scheduleCorePoolSize);
+
+ BundleContext bundleContext = papoose.getSystemBundleContext();
+
+ eventAdminService = new EventAdminImpl(bundleContext, executor, scheduledExecutor);
+
+ eventAdminService.start();
+
LOGGER.exiting(CLASS_NAME, "start");
}
public void stop()
{
LOGGER.entering(CLASS_NAME, "stop");
+
+ if (eventAdminService == null)
+ {
+ LOGGER.log(Level.WARNING, "Event Admin service already stopped");
+ return;
+ }
+
+ eventAdminService.stop();
+ eventAdminService = null;
+
LOGGER.exiting(CLASS_NAME, "stop");
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-24 18:28:55
|
Revision: 253
http://osgi.svn.sourceforge.net/osgi/?rev=253&view=rev
Author: maguro
Date: 2010-02-24 18:28:47 +0000 (Wed, 24 Feb 2010)
Log Message:
-----------
Check arguments
Modified Paths:
--------------
papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java
Modified: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java
===================================================================
--- papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java 2010-02-24 18:16:15 UTC (rev 252)
+++ papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java 2010-02-24 18:28:47 UTC (rev 253)
@@ -76,6 +76,10 @@
public EventAdminImpl(BundleContext context, ExecutorService executor, ScheduledExecutorService scheduledExecutor)
{
+ if (context == null) throw new IllegalArgumentException("Bundle context is null");
+ if (executor == null) throw new IllegalArgumentException("Executor service is null");
+ if (scheduledExecutor == null) throw new IllegalArgumentException("Scheduled executor service is null");
+
this.context = context;
this.tracker = new ServiceTracker(context, EventHandler.class.getName(), new ServiceTrackerCustomizer()
{
@@ -106,6 +110,7 @@
public void setTimeout(int timeout)
{
+ if (timeout < 1) return;
this.timeout = timeout;
}
@@ -116,6 +121,7 @@
public void setTimeUnit(TimeUnit timeUnit)
{
+ if (timeUnit == null) return;
this.timeUnit = timeUnit;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-24 18:16:22
|
Revision: 252
http://osgi.svn.sourceforge.net/osgi/?rev=252&view=rev
Author: maguro
Date: 2010-02-24 18:16:15 +0000 (Wed, 24 Feb 2010)
Log Message:
-----------
Having Event Admin extend a service tracker is kindof an implementation leak
Modified Paths:
--------------
papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/event/EventAdminImplTest.java
Modified: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java
===================================================================
--- papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java 2010-02-24 15:37:28 UTC (rev 251)
+++ papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java 2010-02-24 18:16:15 UTC (rev 252)
@@ -44,6 +44,7 @@
import org.osgi.service.event.TopicPermission;
import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
import org.papoose.event.util.LogServiceTracker;
import org.papoose.event.util.SerialExecutor;
@@ -52,7 +53,7 @@
/**
* @version $Revision: $ $Date: $
*/
-public class EventAdminImpl extends ServiceTracker implements EventAdmin
+public class EventAdminImpl implements EventAdmin
{
private final static String CLASS_NAME = EventAdminImpl.class.getName();
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
@@ -65,6 +66,8 @@
public boolean matchCase(Dictionary dictionary) { return true; }
};
private final Listeners listeners = new Listeners();
+ private final BundleContext context;
+ private final ServiceTracker tracker;
private final ExecutorService executor;
private final ScheduledExecutorService scheduledExecutor;
private final LogServiceTracker loggers;
@@ -73,8 +76,24 @@
public EventAdminImpl(BundleContext context, ExecutorService executor, ScheduledExecutorService scheduledExecutor)
{
- super(context, EventHandler.class.getName(), null);
+ this.context = context;
+ this.tracker = new ServiceTracker(context, EventHandler.class.getName(), new ServiceTrackerCustomizer()
+ {
+ public Object addingService(ServiceReference reference)
+ {
+ return EventAdminImpl.this.addingService(reference);
+ }
+ public void modifiedService(ServiceReference reference, Object service)
+ {
+ EventAdminImpl.this.modifiedService(reference, service);
+ }
+
+ public void removedService(ServiceReference reference, Object service)
+ {
+ EventAdminImpl.this.removedService(reference, service);
+ }
+ });
this.executor = executor;
this.scheduledExecutor = scheduledExecutor;
this.loggers = new LogServiceTracker(context);
@@ -100,6 +119,67 @@
this.timeUnit = timeUnit;
}
+ public void start()
+ {
+ tracker.open();
+ loggers.open();
+ }
+
+ public void stop()
+ {
+ tracker.close();
+ loggers.close();
+ }
+
+ public void postEvent(final Event event)
+ {
+ LOGGER.entering(CLASS_NAME, "postEvent", event);
+
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) sm.checkPermission(new TopicPermission(event.getTopic(), TopicPermission.PUBLISH));
+
+ Set<EventListener> set = collectListeners(event);
+
+ for (final EventListener el : set)
+ {
+ el.executor.execute(new TimeoutRunnable(el, event));
+ }
+
+ LOGGER.exiting(CLASS_NAME, "postEvent");
+ }
+
+ public void sendEvent(final Event event)
+ {
+ LOGGER.entering(CLASS_NAME, "sendEvent", event);
+
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) sm.checkPermission(new TopicPermission(event.getTopic(), TopicPermission.PUBLISH));
+
+ Set<EventListener> set = collectListeners(event);
+
+ if (!set.isEmpty())
+ {
+ final CountDownLatch latch = new CountDownLatch(set.size());
+ for (final EventListener listener : set)
+ {
+ listener.executor.execute(new TimeoutRunnable(latch, listener, event));
+ }
+
+ try
+ {
+ latch.await();
+ }
+ catch (InterruptedException ie)
+ {
+ LOGGER.log(Level.WARNING, "Wait interrupted", ie);
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ LOGGER.exiting(CLASS_NAME, "sendEvent");
+ }
+
+
/**
* This service tracker customizer culls services that do not have
* an event topic or do not have the proper topic subscription
@@ -111,8 +191,7 @@
* service or <code>null</code> if the specified referenced service
* should not be tracked.
*/
- @Override
- public Object addingService(ServiceReference reference)
+ private Object addingService(ServiceReference reference)
{
LOGGER.entering(CLASS_NAME, "addingService", reference);
@@ -199,8 +278,7 @@
}
}
- @Override
- public void modifiedService(ServiceReference reference, Object service)
+ private void modifiedService(ServiceReference reference, Object service)
{
LOGGER.entering(CLASS_NAME, "modifiedService", new Object[]{ reference, service });
@@ -210,8 +288,7 @@
LOGGER.exiting(CLASS_NAME, "modifiedService", null);
}
- @Override
- public void removedService(ServiceReference reference, Object service)
+ private void removedService(ServiceReference reference, Object service)
{
LOGGER.entering(CLASS_NAME, "removedService", new Object[]{ reference, service });
@@ -220,54 +297,6 @@
LOGGER.exiting(CLASS_NAME, "removedService", null);
}
- public void postEvent(final Event event)
- {
- LOGGER.entering(CLASS_NAME, "postEvent", event);
-
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) sm.checkPermission(new TopicPermission(event.getTopic(), TopicPermission.PUBLISH));
-
- Set<EventListener> set = collectListeners(event);
-
- for (final EventListener el : set)
- {
- el.executor.execute(new TimeoutRunnable(el, event));
- }
-
- LOGGER.exiting(CLASS_NAME, "postEvent");
- }
-
- public void sendEvent(final Event event)
- {
- LOGGER.entering(CLASS_NAME, "sendEvent", event);
-
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) sm.checkPermission(new TopicPermission(event.getTopic(), TopicPermission.PUBLISH));
-
- Set<EventListener> set = collectListeners(event);
-
- if (!set.isEmpty())
- {
- final CountDownLatch latch = new CountDownLatch(set.size());
- for (final EventListener listener : set)
- {
- listener.executor.execute(new TimeoutRunnable(latch, listener, event));
- }
-
- try
- {
- latch.await();
- }
- catch (InterruptedException ie)
- {
- LOGGER.log(Level.WARNING, "Wait interrupted", ie);
- Thread.currentThread().interrupt();
- }
- }
-
- LOGGER.exiting(CLASS_NAME, "sendEvent");
- }
-
private void add(EventListener listener)
{
LOGGER.entering(CLASS_NAME, "add", listener);
Modified: papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/event/EventAdminImplTest.java
===================================================================
--- papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/event/EventAdminImplTest.java 2010-02-24 15:37:28 UTC (rev 251)
+++ papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/event/EventAdminImplTest.java 2010-02-24 18:16:15 UTC (rev 252)
@@ -91,7 +91,7 @@
EventAdminImpl eventAdmin = new EventAdminImpl(bundleContext, executor, scheduledExecutor);
- eventAdmin.open();
+ eventAdmin.start();
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(EventConstants.EVENT_TOPIC, "a/b/c/d");
@@ -137,7 +137,7 @@
{
sr.unregister();
- eventAdmin.close();
+ eventAdmin.stop();
executor.shutdown();
scheduledExecutor.shutdown();
@@ -153,7 +153,7 @@
EventAdminImpl eventAdmin = new EventAdminImpl(bundleContext, executor, scheduledExecutor);
- eventAdmin.open();
+ eventAdmin.start();
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*");
@@ -198,7 +198,7 @@
{
sr.unregister();
- eventAdmin.close();
+ eventAdmin.stop();
executor.shutdown();
scheduledExecutor.shutdown();
@@ -214,7 +214,7 @@
EventAdminImpl eventAdmin = new EventAdminImpl(bundleContext, executor, scheduledExecutor);
- eventAdmin.open();
+ eventAdmin.start();
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(EventConstants.EVENT_TOPIC, "a/*");
@@ -259,7 +259,7 @@
{
sr.unregister();
- eventAdmin.close();
+ eventAdmin.stop();
executor.shutdown();
scheduledExecutor.shutdown();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-24 15:37:35
|
Revision: 251
http://osgi.svn.sourceforge.net/osgi/?rev=251&view=rev
Author: maguro
Date: 2010-02-24 15:37:28 +0000 (Wed, 24 Feb 2010)
Log Message:
-----------
Start of papoose boot level services
Modified Paths:
--------------
papoose-cmpn/trunk/event/pom.xml
papoose-cmpn/trunk/http/pom.xml
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java
papoose-cmpn/trunk/log/pom.xml
papoose-cmpn/trunk/pom.xml
Added Paths:
-----------
papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java
papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/Util.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/util/Util.java
papoose-cmpn/trunk/log/src/main/java/org/papoose/log/PapooseBootLevelService.java
papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/Util.java
Removed Paths:
-------------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java
Modified: papoose-cmpn/trunk/event/pom.xml
===================================================================
--- papoose-cmpn/trunk/event/pom.xml 2010-02-24 03:57:10 UTC (rev 250)
+++ papoose-cmpn/trunk/event/pom.xml 2010-02-24 15:37:28 UTC (rev 251)
@@ -23,7 +23,7 @@
<instructions>
<Bundle-SymbolicName>org.papoose.cmpn.event</Bundle-SymbolicName>
<Export-Package>org.papoose.event</Export-Package>
- <Import-Package>org.osgi.framework;version="[1.0,1.6)",org.osgi.service.event;version="[1.1,1.3)",org.osgi.service.log;version="[1.1,1.4)",org.osgi.util.tracker;version="[1.3,1.5)"</Import-Package>
+ <Import-Package>org.papoose.core;resolution:=optional,org.osgi.framework;version="[1.0,1.6)",org.osgi.service.event;version="[1.1,1.3)",org.osgi.service.log;version="[1.1,1.4)",org.osgi.util.tracker;version="[1.3,1.5)"</Import-Package>
<Private-Package>org.papoose.event.util</Private-Package>
</instructions>
</configuration>
@@ -43,6 +43,12 @@
<artifactId>org.osgi.core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
</project>
Added: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java
===================================================================
--- papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java (rev 0)
+++ papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java 2010-02-24 15:37:28 UTC (rev 251)
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.event;
+
+import java.util.logging.Logger;
+
+import org.papoose.core.Papoose;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class PapooseBootLevelService
+{
+ private final static String CLASS_NAME = PapooseBootLevelService.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+
+ public void start(Papoose papoose)
+ {
+ LOGGER.entering(CLASS_NAME, "start", papoose);
+ LOGGER.exiting(CLASS_NAME, "start");
+ }
+
+ public void stop()
+ {
+ LOGGER.entering(CLASS_NAME, "stop");
+ LOGGER.exiting(CLASS_NAME, "stop");
+ }
+}
Property changes on: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/PapooseBootLevelService.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/Util.java
===================================================================
--- papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/Util.java (rev 0)
+++ papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/Util.java 2010-02-24 15:37:28 UTC (rev 251)
@@ -0,0 +1,59 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.event.util;
+
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class Util
+{
+ public static int parseInt(Object property, int defaultValue)
+ {
+ try
+ {
+ if (property instanceof String) return Integer.parseInt((String) property);
+ if (property instanceof Integer) return (Integer) property;
+ if (property instanceof Long) return ((Long) property).intValue();
+ if (property != null) return Integer.parseInt(property.toString());
+ }
+ catch (NumberFormatException ignore)
+ {
+ }
+
+ return defaultValue;
+ }
+
+ public static TimeUnit parseTimeUnit(Object property, TimeUnit defaultValue)
+ {
+ try
+ {
+ if (property instanceof String) return TimeUnit.valueOf((String) property);
+ if (property instanceof TimeUnit) return (TimeUnit) property;
+ if (property != null) return TimeUnit.valueOf(property.toString());
+ }
+ catch (Exception ignore)
+ {
+ }
+
+ return defaultValue;
+ }
+
+ private Util() {}
+}
Property changes on: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/Util.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/http/pom.xml
===================================================================
--- papoose-cmpn/trunk/http/pom.xml 2010-02-24 03:57:10 UTC (rev 250)
+++ papoose-cmpn/trunk/http/pom.xml 2010-02-24 15:37:28 UTC (rev 251)
@@ -22,9 +22,9 @@
<configuration>
<instructions>
<Bundle-SymbolicName>org.papoose.cmpn.event</Bundle-SymbolicName>
- <Export-Package>org.papoose.event</Export-Package>
- <Import-Package>org.osgi.framework;version="[1.0,1.6)",org.osgi.service.event;version="[1.1,1.3)",org.osgi.service.log;version="[1.1,1.4)",org.osgi.util.tracker;version="[1.3,1.5)"</Import-Package>
- <Private-Package>org.papoose.event.util</Private-Package>
+ <Export-Package>org.papoose.http</Export-Package>
+ <Import-Package>org.papoose.core;resolution:=optional,javax.servlet;version="2.4",javax.servlet.http;version="2.4",org.osgi.framework;version="1.4",org.osgi.service.http;version="1.2"</Import-Package>
+ <Private-Package>org.papoose.http.util</Private-Package>
</instructions>
</configuration>
</plugin>
@@ -50,6 +50,12 @@
<artifactId>org.osgi.core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
</project>
Deleted: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java 2010-02-24 03:57:10 UTC (rev 250)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java 2010-02-24 15:37:28 UTC (rev 251)
@@ -1,51 +0,0 @@
-/**
- *
- * Copyright 2010 (C) The original author or authors
- *
- * Licensed 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.papoose.http;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import java.io.IOException;
-import java.util.logging.Logger;
-
-
-/**
- * @version $Revision: $ $Date: $
- */
-public class FilterImpl implements Filter
-{
- private final static String CLASS_NAME = FilterImpl.class.getName();
- private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
-
- public void init(FilterConfig filterConfig) throws ServletException
- {
- //Todo change body of implemented methods use File | Settings | File Templates.
- }
-
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
- {
- //Todo change body of implemented methods use File | Settings | File Templates.
- }
-
- public void destroy()
- {
- //Todo change body of implemented methods use File | Settings | File Templates.
- }
-}
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java 2010-02-24 15:37:28 UTC (rev 251)
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import java.util.logging.Logger;
+
+import org.papoose.core.Papoose;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class PapooseBootLevelService
+{
+ private final static String CLASS_NAME = PapooseBootLevelService.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+
+ public void start(Papoose papoose)
+ {
+ LOGGER.entering(CLASS_NAME, "start", papoose);
+ LOGGER.exiting(CLASS_NAME, "start");
+ }
+
+ public void stop()
+ {
+ LOGGER.entering(CLASS_NAME, "stop");
+ LOGGER.exiting(CLASS_NAME, "stop");
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java 2010-02-24 03:57:10 UTC (rev 250)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java 2010-02-24 15:37:28 UTC (rev 251)
@@ -38,13 +38,21 @@
this.alias = alias;
this.servletContext = servletContext;
- if (initParams == null) this.initParams = EMPTY;
+ if (initParams == null)
+ {
+ this.initParams = EMPTY;
+ }
else
{
+ this.initParams = new Properties();
+
Enumeration enumeration = initParams.keys();
- while (enumeration.)
+ while (enumeration.hasMoreElements())
+ {
+ Object key = enumeration.nextElement();
+ this.initParams.put(key, initParams.get(key));
+ }
}
- this.initParams = initParams;
}
public String getServletName()
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/util/Util.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/util/Util.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/util/Util.java 2010-02-24 15:37:28 UTC (rev 251)
@@ -0,0 +1,59 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http.util;
+
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class Util
+{
+ public static int parseInt(Object property, int defaultValue)
+ {
+ try
+ {
+ if (property instanceof String) return Integer.parseInt((String) property);
+ if (property instanceof Integer) return (Integer) property;
+ if (property instanceof Long) return ((Long) property).intValue();
+ if (property != null) return Integer.parseInt(property.toString());
+ }
+ catch (NumberFormatException ignore)
+ {
+ }
+
+ return defaultValue;
+ }
+
+ public static TimeUnit parseTimeUnit(Object property, TimeUnit defaultValue)
+ {
+ try
+ {
+ if (property instanceof String) return TimeUnit.valueOf((String) property);
+ if (property instanceof TimeUnit) return (TimeUnit) property;
+ if (property != null) return TimeUnit.valueOf(property.toString());
+ }
+ catch (Exception ignore)
+ {
+ }
+
+ return defaultValue;
+ }
+
+ private Util() {}
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/util/Util.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/log/pom.xml
===================================================================
--- papoose-cmpn/trunk/log/pom.xml 2010-02-24 03:57:10 UTC (rev 250)
+++ papoose-cmpn/trunk/log/pom.xml 2010-02-24 15:37:28 UTC (rev 251)
@@ -23,7 +23,7 @@
<instructions>
<Bundle-SymbolicName>org.papoose.cmpn.log</Bundle-SymbolicName>
<Export-Package>org.papoose.log</Export-Package>
- <Import-Package>org.osgi.framework;version="[1.0,1.6)",org.osgi.service.event;version="[1.1,1.3)",org.osgi.service.log;version="[1.1,1.4)",org.osgi.util.tracker;version="[1.3,1.5)"</Import-Package>
+ <Import-Package>org.papoose.core;resolution:=optional,org.osgi.framework;version="[1.0,1.6)",org.osgi.service.event;version="[1.1,1.3)",org.osgi.service.log;version="[1.1,1.4)",org.osgi.util.tracker;version="[1.3,1.5)"</Import-Package>
<Private-Package>org.papoose.log.util</Private-Package>
<Private-Package>org.papoose.log.util</Private-Package>
</instructions>
@@ -44,6 +44,12 @@
<artifactId>org.osgi.core</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
</project>
Added: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/PapooseBootLevelService.java
===================================================================
--- papoose-cmpn/trunk/log/src/main/java/org/papoose/log/PapooseBootLevelService.java (rev 0)
+++ papoose-cmpn/trunk/log/src/main/java/org/papoose/log/PapooseBootLevelService.java 2010-02-24 15:37:28 UTC (rev 251)
@@ -0,0 +1,109 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.log;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.osgi.framework.BundleContext;
+
+import org.papoose.core.Papoose;
+import org.papoose.log.util.Util;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class PapooseBootLevelService
+{
+ private final static String CLASS_NAME = PapooseBootLevelService.class.getName();
+ public final static String LOG_SERVICE_USE_PAPOOSE_THREAD_POOL = CLASS_NAME + ".usePapooseThreadPool";
+ public final static String LOG_SERVICE_CORE_POOL_SIZE = CLASS_NAME + ".corePoolSize";
+ public final static String LOG_SERVICE_MAX_POOL_SIZE = CLASS_NAME + ".maximumPoolSize";
+ public final static String LOG_SERVICE_KEEP_ALIVE_TIME = CLASS_NAME + ".keepAliveTime";
+ public final static String LOG_SERVICE_TIME_UNIT = CLASS_NAME + ".timeUnit";
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private volatile LogServiceImpl logService;
+
+ public void start(Papoose papoose)
+ {
+ LOGGER.entering(CLASS_NAME, "start", papoose);
+
+ if (papoose == null) throw new IllegalArgumentException("Papoose instance is null");
+
+ if (logService != null)
+ {
+ LOGGER.log(Level.WARNING, "Log service already started");
+ return;
+ }
+
+ ExecutorService executor;
+
+ if (papoose.getProperty(LOG_SERVICE_USE_PAPOOSE_THREAD_POOL) != null)
+ {
+ LOGGER.finest("Using Papoose's thread pool");
+
+ executor = papoose.getExecutorService();
+ }
+ else
+ {
+ int corePoolSize = Util.parseInt(papoose.getProperty(LOG_SERVICE_CORE_POOL_SIZE), 1);
+ int maximumPoolSize = Util.parseInt(papoose.getProperty(LOG_SERVICE_MAX_POOL_SIZE), 5);
+ int keepAliveTime = Util.parseInt(papoose.getProperty(LOG_SERVICE_KEEP_ALIVE_TIME), 1);
+ TimeUnit unit = Util.parseTimeUnit(papoose.getProperty(LOG_SERVICE_TIME_UNIT), TimeUnit.SECONDS);
+
+ if (LOGGER.isLoggable(Level.FINEST))
+ {
+ LOGGER.finest("Creating own thread pool");
+ LOGGER.finest("corePoolSize: " + corePoolSize);
+ LOGGER.finest("maximumPoolSize: " + maximumPoolSize);
+ LOGGER.finest("keepAliveTime: " + keepAliveTime);
+ LOGGER.finest("unit: " + unit);
+ }
+
+ executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, unit, new LinkedBlockingQueue<Runnable>());
+ }
+
+ BundleContext bundleContext = papoose.getSystemBundleContext();
+
+ logService = new LogServiceImpl(bundleContext, executor);
+
+ logService.start();
+
+ LOGGER.exiting(CLASS_NAME, "start");
+ }
+
+ public void stop()
+ {
+ LOGGER.entering(CLASS_NAME, "stop");
+
+ if (logService == null)
+ {
+ LOGGER.log(Level.WARNING, "Log service already stopped");
+ return;
+ }
+
+ logService.stop();
+ logService = null;
+
+ LOGGER.exiting(CLASS_NAME, "stop");
+ }
+}
Property changes on: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/PapooseBootLevelService.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/Util.java
===================================================================
--- papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/Util.java (rev 0)
+++ papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/Util.java 2010-02-24 15:37:28 UTC (rev 251)
@@ -0,0 +1,59 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.log.util;
+
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class Util
+{
+ public static int parseInt(Object property, int defaultValue)
+ {
+ try
+ {
+ if (property instanceof String) return Integer.parseInt((String) property);
+ if (property instanceof Integer) return (Integer) property;
+ if (property instanceof Long) return ((Long) property).intValue();
+ if (property != null) return Integer.parseInt(property.toString());
+ }
+ catch (NumberFormatException ignore)
+ {
+ }
+
+ return defaultValue;
+ }
+
+ public static TimeUnit parseTimeUnit(Object property, TimeUnit defaultValue)
+ {
+ try
+ {
+ if (property instanceof String) return TimeUnit.valueOf((String) property);
+ if (property instanceof TimeUnit) return (TimeUnit) property;
+ if (property != null) return TimeUnit.valueOf(property.toString());
+ }
+ catch (Exception ignore)
+ {
+ }
+
+ return defaultValue;
+ }
+
+ private Util() {}
+}
Property changes on: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/Util.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/pom.xml
===================================================================
--- papoose-cmpn/trunk/pom.xml 2010-02-24 03:57:10 UTC (rev 250)
+++ papoose-cmpn/trunk/pom.xml 2010-02-24 15:37:28 UTC (rev 251)
@@ -117,6 +117,12 @@
</dependency>
<dependency>
+ <groupId>org.papoose.core</groupId>
+ <artifactId>core</artifactId>
+ <version>1.0.0.SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
<groupId>org.papoose.test</groupId>
<artifactId>papoose-test-bundle</artifactId>
<version>${papooseTestVersion}</version>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-24 03:57:19
|
Revision: 250
http://osgi.svn.sourceforge.net/osgi/?rev=250&view=rev
Author: maguro
Date: 2010-02-24 03:57:10 +0000 (Wed, 24 Feb 2010)
Log Message:
-----------
More work
Modified Paths:
--------------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
Added Paths:
-----------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-23 19:45:40 UTC (rev 249)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-24 03:57:10 UTC (rev 250)
@@ -18,11 +18,18 @@
import javax.servlet.Servlet;
import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URL;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
+import java.util.logging.Level;
import java.util.logging.Logger;
+import org.osgi.framework.BundleContext;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
@@ -35,47 +42,135 @@
{
private final static String CLASS_NAME = HttpServiceImpl.class.getName();
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final static Properties EMPTY_PARAMS = new Properties();
+ private final Object lock = new Object();
private final Map<HttpContext, ServletContextImpl> contexts = new HashMap<HttpContext, ServletContextImpl>();
private final Map<String, ServletRegistration> registrations = new HashMap<String, ServletRegistration>();
+ private final BundleContext context;
+ private final ServletDispatcher dispatcher;
- public void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext httpContext) throws ServletException, NamespaceException
+ public HttpServiceImpl(BundleContext context, ServletDispatcher dispatcher)
{
- if (registrations.containsKey(alias)) throw new NamespaceException("Alias " + alias + " already registered");
- if (httpContext == null) httpContext = createDefaultHttpContext();
- ServletRegistration registration = new ServletRegistration(alias, servlet, initparams, httpContext);
- registrations.put(alias, registration);
+ if (context == null) throw new IllegalArgumentException("Bundle context is null");
+ if (dispatcher == null) throw new IllegalArgumentException("Servlet dispatcher is null");
- ServletContextImpl servletContext = contexts.get(httpContext);
- if (servletContext == null) contexts.put(httpContext, servletContext = new ServletContextImpl(httpContext));
- servletContext.incrementReferenceCount();
+ this.context = context;
+ this.dispatcher = dispatcher;
+ }
- servlet.init(new ServletConfigImpl(alias, servletContext, initparams));
+ /**
+ * {@inheritDoc}
+ */
+ public void registerServlet(String alias, Servlet servlet, Dictionary initParams, HttpContext httpContext) throws ServletException, NamespaceException
+ {
+ ServletRegistration registration;
+ ServletContextImpl servletContext;
+ synchronized (lock)
+ {
+ if (registrations.containsKey(alias)) throw new NamespaceException("Alias " + alias + " already registered");
+ if (httpContext == null) httpContext = createDefaultHttpContext();
- //Todo change body of implemented methods use File | Settings | File Templates.
+ registration = new ServletRegistration(alias, servlet, httpContext);
+ registrations.put(alias, registration);
+
+ servletContext = contexts.get(httpContext);
+ if (servletContext == null) contexts.put(httpContext, servletContext = new ServletContextImpl(httpContext));
+
+ servletContext.incrementReferenceCount();
+ }
+
+ try
+ {
+ servlet.init(new ServletConfigImpl(alias, servletContext, initParams));
+
+ dispatcher.register(registration);
+ }
+ catch (Throwable t)
+ {
+ LOGGER.log(Level.WARNING, "Error initializing servlet", t);
+
+ synchronized (lock)
+ {
+ servletContext = contexts.get(httpContext);
+ servletContext.decrementReferenceCount();
+ if (servletContext.getReferenceCount() == 0) contexts.remove(registration.getContext());
+ }
+
+ if (t instanceof ServletException) throw (ServletException) t;
+ throw (RuntimeException) t;
+ }
}
- public void registerResources(String alias, String name, HttpContext context) throws NamespaceException
+
+ /**
+ * {@inheritDoc}
+ */
+ public void registerResources(String alias, String name, HttpContext httpContext) throws NamespaceException
{
- //Todo change body of implemented methods use File | Settings | File Templates.
+ try
+ {
+ registerServlet(alias, new ServletWrapper(alias, name, httpContext), EMPTY_PARAMS, httpContext);
+ }
+ catch (ServletException se)
+ {
+ LOGGER.log(Level.SEVERE, "Error registering resource wrapper servlet", se);
+ }
}
+ /**
+ * {@inheritDoc}
+ */
public void unregister(String alias)
{
- ServletRegistration registration = registrations.get(alias);
+ ServletRegistration registration;
+ synchronized (lock)
+ {
+ registration = registrations.remove(alias);
- registration.getServlet().destroy();
- ServletContextImpl servletContext = contexts.get(registration.getContext());
+ if (registration == null) return;
- servletContext.decrementReferenceCount();
- if (servletContext.getReferenceCount() == 0) contexts.remove(registration.getContext());
+ ServletContextImpl servletContext = contexts.get(registration.getContext());
+ servletContext.decrementReferenceCount();
+ if (servletContext.getReferenceCount() == 0) contexts.remove(registration.getContext());
+ }
- //Todo change body of implemented methods use File | Settings | File Templates.
+ try
+ {
+ dispatcher.unregister(registration);
+
+ registration.getServlet().destroy();
+ }
+ catch (Throwable t)
+ {
+ LOGGER.log(Level.WARNING, "Error destroying servlet", t);
+ }
}
+ /**
+ * {@inheritDoc}
+ */
public HttpContext createDefaultHttpContext()
{
- return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ return new HttpContext()
+ {
+ public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
+ {
+ return true;
+ }
+
+ public URL getResource(String name)
+ {
+ if (name.startsWith("/")) name = name.substring(1);
+
+ return context.getBundle().getResource(name);
+ }
+
+ public String getMimeType(String name)
+ {
+ return null;
+ }
+ };
}
}
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java 2010-02-23 19:45:40 UTC (rev 249)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java 2010-02-24 03:57:10 UTC (rev 250)
@@ -20,42 +20,50 @@
import javax.servlet.ServletContext;
import java.util.Dictionary;
import java.util.Enumeration;
-import java.util.logging.Logger;
+import java.util.Properties;
-import org.osgi.service.http.HttpContext;
-
/**
* @version $Revision: $ $Date: $
*/
-public class ServletConfigImpl implements ServletConfig
+class ServletConfigImpl implements ServletConfig
{
- private final static String CLASS_NAME = ServletConfigImpl.class.getName();
- private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final static Properties EMPTY = new Properties();
+ private final String alias;
+ private final ServletContextImpl servletContext;
+ private final Properties initParams;
- public ServletConfigImpl(String alias, ServletContextImpl servletContext, Dictionary httpContext)
+ ServletConfigImpl(String alias, ServletContextImpl servletContext, Dictionary initParams)
{
+ this.alias = alias;
+ this.servletContext = servletContext;
-
+ if (initParams == null) this.initParams = EMPTY;
+ else
+ {
+ Enumeration enumeration = initParams.keys();
+ while (enumeration.)
+ }
+ this.initParams = initParams;
}
public String getServletName()
{
- return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ return alias;
}
public ServletContext getServletContext()
{
- return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ return servletContext;
}
public String getInitParameter(String name)
{
- return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ return (String) initParams.get(name);
}
public Enumeration getInitParameterNames()
{
- return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ return initParams.keys();
}
}
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java 2010-02-23 19:45:40 UTC (rev 249)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java 2010-02-24 03:57:10 UTC (rev 250)
@@ -33,14 +33,14 @@
/**
* @version $Revision: $ $Date: $
*/
-public class ServletContextImpl implements ServletContext
+ class ServletContextImpl implements ServletContext
{
private final static String CLASS_NAME = ServletContextImpl.class.getName();
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
private final HttpContext httpContext;
private int referenceCount;
- public ServletContextImpl(HttpContext httpContext)
+ ServletContextImpl(HttpContext httpContext)
{
this.httpContext = httpContext;
}
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java 2010-02-23 19:45:40 UTC (rev 249)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java 2010-02-24 03:57:10 UTC (rev 250)
@@ -26,20 +26,18 @@
/**
* @version $Revision: $ $Date: $
*/
-public class ServletRegistration
+class ServletRegistration
{
private final static String CLASS_NAME = ServletRegistration.class.getName();
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
private final String alias;
private final Servlet servlet;
- private final Dictionary initparams;
private final HttpContext context;
- public ServletRegistration(String alias, Servlet servlet, Dictionary initparams, HttpContext context)
+ ServletRegistration(String alias, Servlet servlet, HttpContext context)
{
this.alias = alias;
this.servlet = servlet;
- this.initparams = initparams;
this.context = context;
}
@@ -57,9 +55,4 @@
{
return servlet;
}
-
- public Dictionary getInitparams()
- {
- return initparams;
- }
}
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java 2010-02-24 03:57:10 UTC (rev 250)
@@ -0,0 +1,52 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import org.osgi.service.http.HttpContext;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+ class ServletWrapper extends HttpServlet
+{
+ private final static String CLASS_NAME = ServletWrapper.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final String alias;
+ private final String name;
+ private final HttpContext httpContext;
+
+ ServletWrapper(String alias, String name, HttpContext httpContext)
+ {
+ this.alias = alias;
+ this.name = name;
+ this.httpContext = httpContext;
+ }
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ super.service(req, resp); //Todo change body of overridden methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-23 19:46:00
|
Revision: 249
http://osgi.svn.sourceforge.net/osgi/?rev=249&view=rev
Author: maguro
Date: 2010-02-23 19:45:40 +0000 (Tue, 23 Feb 2010)
Log Message:
-----------
Starting sketch of http
Modified Paths:
--------------
papoose-cmpn/trunk/http/pom.xml
papoose-cmpn/trunk/pom.xml
Added Paths:
-----------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/util/
Modified: papoose-cmpn/trunk/http/pom.xml
===================================================================
--- papoose-cmpn/trunk/http/pom.xml 2010-02-21 20:17:14 UTC (rev 248)
+++ papoose-cmpn/trunk/http/pom.xml 2010-02-23 19:45:40 UTC (rev 249)
@@ -9,17 +9,23 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>papoose-cmpn-http</artifactId>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<name>Papoose :: HTTP Service</name>
<description>HTTP Service</description>
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
<configuration>
- <argLine>-enableassertions</argLine>
+ <instructions>
+ <Bundle-SymbolicName>org.papoose.cmpn.event</Bundle-SymbolicName>
+ <Export-Package>org.papoose.event</Export-Package>
+ <Import-Package>org.osgi.framework;version="[1.0,1.6)",org.osgi.service.event;version="[1.1,1.3)",org.osgi.service.log;version="[1.1,1.4)",org.osgi.util.tracker;version="[1.3,1.5)"</Import-Package>
+ <Private-Package>org.papoose.event.util</Private-Package>
+ </instructions>
</configuration>
</plugin>
</plugins>
@@ -28,6 +34,13 @@
<dependencies>
<dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,51 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.IOException;
+import java.util.logging.Logger;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class FilterImpl implements Filter
+{
+ private final static String CLASS_NAME = FilterImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+
+ public void init(FilterConfig filterConfig) throws ServletException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void destroy()
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,81 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class HttpServiceImpl implements HttpService
+{
+ private final static String CLASS_NAME = HttpServiceImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final Map<HttpContext, ServletContextImpl> contexts = new HashMap<HttpContext, ServletContextImpl>();
+ private final Map<String, ServletRegistration> registrations = new HashMap<String, ServletRegistration>();
+
+ public void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext httpContext) throws ServletException, NamespaceException
+ {
+ if (registrations.containsKey(alias)) throw new NamespaceException("Alias " + alias + " already registered");
+ if (httpContext == null) httpContext = createDefaultHttpContext();
+ ServletRegistration registration = new ServletRegistration(alias, servlet, initparams, httpContext);
+ registrations.put(alias, registration);
+
+ ServletContextImpl servletContext = contexts.get(httpContext);
+ if (servletContext == null) contexts.put(httpContext, servletContext = new ServletContextImpl(httpContext));
+ servletContext.incrementReferenceCount();
+
+ servlet.init(new ServletConfigImpl(alias, servletContext, initparams));
+
+
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void registerResources(String alias, String name, HttpContext context) throws NamespaceException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void unregister(String alias)
+ {
+ ServletRegistration registration = registrations.get(alias);
+
+ registration.getServlet().destroy();
+ ServletContextImpl servletContext = contexts.get(registration.getContext());
+
+ servletContext.decrementReferenceCount();
+ if (servletContext.getReferenceCount() == 0) contexts.remove(registration.getContext());
+
+
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public HttpContext createDefaultHttpContext()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,61 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.logging.Logger;
+
+import org.osgi.service.http.HttpContext;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ServletConfigImpl implements ServletConfig
+{
+ private final static String CLASS_NAME = ServletConfigImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+
+ public ServletConfigImpl(String alias, ServletContextImpl servletContext, Dictionary httpContext)
+ {
+
+
+ }
+
+ public String getServletName()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public ServletContext getServletContext()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getInitParameter(String name)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,187 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import org.osgi.service.http.HttpContext;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ServletContextImpl implements ServletContext
+{
+ private final static String CLASS_NAME = ServletContextImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final HttpContext httpContext;
+ private int referenceCount;
+
+ public ServletContextImpl(HttpContext httpContext)
+ {
+ this.httpContext = httpContext;
+ }
+
+ public int getReferenceCount()
+ {
+ return referenceCount;
+ }
+
+ public void incrementReferenceCount()
+ {
+ referenceCount--;
+ }
+
+ public void decrementReferenceCount()
+ {
+ referenceCount++;
+ }
+
+ public String getContextPath()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public ServletContext getContext(String uripath)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int getMajorVersion()
+ {
+ return 0; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int getMinorVersion()
+ {
+ return 0; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getMimeType(String file)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Set getResourcePaths(String path)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public URL getResource(String path) throws MalformedURLException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public InputStream getResourceAsStream(String path)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public RequestDispatcher getRequestDispatcher(String path)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public RequestDispatcher getNamedDispatcher(String name)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Servlet getServlet(String name) throws ServletException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Enumeration getServlets()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Enumeration getServletNames()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void log(String msg)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void log(Exception exception, String msg)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void log(String message, Throwable throwable)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getRealPath(String path)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getServerInfo()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getInitParameter(String name)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object getAttribute(String name)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Enumeration getAttributeNames()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setAttribute(String name, Object object)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeAttribute(String name)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getServletContextName()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,80 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ServletDispatcher extends HttpServlet
+{
+ private final static String CLASS_NAME = ServletDispatcher.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final List<ServletRegistration> registrations = new CopyOnWriteArrayList<ServletRegistration>();
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ String path = req.getPathInfo();
+
+ for (ServletRegistration registration : registrations)
+ {
+ if (path.startsWith(registration.getAlias()))
+ {
+ if (registration.getContext().handleSecurity(req, resp))
+ {
+ try
+ {
+ registration.getServlet().service(req, resp);
+ }
+ catch (ServletException e)
+ {
+ throw e;
+ }
+ catch (IOException e)
+ {
+ throw e;
+ }
+ catch(Throwable t)
+ {
+ LOGGER.log(Level.WARNING, "Problems calling ", t);
+ }
+ }
+ }
+ }
+ }
+
+ void register(ServletRegistration registration)
+ {
+
+ }
+
+ void unregister(ServletRegistration registration)
+ {
+
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,65 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.http;
+
+import javax.servlet.Servlet;
+import java.util.Dictionary;
+import java.util.logging.Logger;
+
+import org.osgi.service.http.HttpContext;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ServletRegistration
+{
+ private final static String CLASS_NAME = ServletRegistration.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final String alias;
+ private final Servlet servlet;
+ private final Dictionary initparams;
+ private final HttpContext context;
+
+ public ServletRegistration(String alias, Servlet servlet, Dictionary initparams, HttpContext context)
+ {
+ this.alias = alias;
+ this.servlet = servlet;
+ this.initparams = initparams;
+ this.context = context;
+ }
+
+ public HttpContext getContext()
+ {
+ return context;
+ }
+
+ public String getAlias()
+ {
+ return alias;
+ }
+
+ public Servlet getServlet()
+ {
+ return servlet;
+ }
+
+ public Dictionary getInitparams()
+ {
+ return initparams;
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/pom.xml
===================================================================
--- papoose-cmpn/trunk/pom.xml 2010-02-21 20:17:14 UTC (rev 248)
+++ papoose-cmpn/trunk/pom.xml 2010-02-23 19:45:40 UTC (rev 249)
@@ -25,7 +25,6 @@
</modules>
<properties>
- <jettyVersion>6.1.9</jettyVersion>
<paxExamVersion>1.2.0</paxExamVersion>
<papooseTestVersion>1.0-SNAPSHOT</papooseTestVersion>
</properties>
@@ -35,12 +34,6 @@
<pluginManagement>
<plugins>
<plugin>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>maven-jetty-plugin</artifactId>
- <version>${jettyVersion}</version>
- </plugin>
-
- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
@@ -89,12 +82,6 @@
</dependency>
<dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty-embedded</artifactId>
- <version>${jettyVersion}</version>
- </dependency>
-
- <dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
<version>${paxExamVersion}</version>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-21 20:17:34
|
Revision: 248
http://osgi.svn.sourceforge.net/osgi/?rev=248&view=rev
Author: maguro
Date: 2010-02-21 20:17:14 +0000 (Sun, 21 Feb 2010)
Log Message:
-----------
Some tests and fixes
Modified Paths:
--------------
papoose-cmpn/trunk/event/pom.xml
papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java
papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/LogServiceTracker.java
papoose-cmpn/trunk/log/pom.xml
papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/EventAdminTracker.java
papoose-cmpn/trunk/pom.xml
papoose-cmpn/trunk/tck/pom.xml
Added Paths:
-----------
papoose-cmpn/trunk/http/src/main/java/org/
papoose-cmpn/trunk/http/src/main/java/org/papoose/
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/
papoose-cmpn/trunk/tck/tests/pom.xml
papoose-cmpn/trunk/tck/tests/src/
papoose-cmpn/trunk/tck/tests/src/main/
papoose-cmpn/trunk/tck/tests/src/main/java/
papoose-cmpn/trunk/tck/tests/src/test/
papoose-cmpn/trunk/tck/tests/src/test/java/
papoose-cmpn/trunk/tck/tests/src/test/java/org/
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/event/
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/event/EventAdminImplTest.java
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/log/
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/log/LogServiceImplTest.java
Modified: papoose-cmpn/trunk/event/pom.xml
===================================================================
--- papoose-cmpn/trunk/event/pom.xml 2010-02-19 23:47:52 UTC (rev 247)
+++ papoose-cmpn/trunk/event/pom.xml 2010-02-21 20:17:14 UTC (rev 248)
@@ -23,7 +23,7 @@
<instructions>
<Bundle-SymbolicName>org.papoose.cmpn.event</Bundle-SymbolicName>
<Export-Package>org.papoose.event</Export-Package>
- <Import-Package>org.osgi.framework;version="[1.4,1.5]",org.osgi.service.event;version="[1.1,1.2]",org.osgi.service.log;version="[1.2,1.3]",org.osgi.util.tracker;version="[1.3,1.4]"</Import-Package>
+ <Import-Package>org.osgi.framework;version="[1.0,1.6)",org.osgi.service.event;version="[1.1,1.3)",org.osgi.service.log;version="[1.1,1.4)",org.osgi.util.tracker;version="[1.3,1.5)"</Import-Package>
<Private-Package>org.papoose.event.util</Private-Package>
</instructions>
</configuration>
Modified: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java
===================================================================
--- papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java 2010-02-19 23:47:52 UTC (rev 247)
+++ papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java 2010-02-21 20:17:14 UTC (rev 248)
@@ -215,7 +215,6 @@
{
LOGGER.entering(CLASS_NAME, "removedService", new Object[]{ reference, service });
- context.ungetService(reference);
remove((EventListener) service);
LOGGER.exiting(CLASS_NAME, "removedService", null);
@@ -247,21 +246,24 @@
Set<EventListener> set = collectListeners(event);
- final CountDownLatch latch = new CountDownLatch(set.size());
- for (final EventListener listener : set)
+ if (!set.isEmpty())
{
- listener.executor.execute(new TimeoutRunnable(latch, listener, event));
- }
+ final CountDownLatch latch = new CountDownLatch(set.size());
+ for (final EventListener listener : set)
+ {
+ listener.executor.execute(new TimeoutRunnable(latch, listener, event));
+ }
- try
- {
- latch.await();
+ try
+ {
+ latch.await();
+ }
+ catch (InterruptedException ie)
+ {
+ LOGGER.log(Level.WARNING, "Wait interrupted", ie);
+ Thread.currentThread().interrupt();
+ }
}
- catch (InterruptedException ie)
- {
- LOGGER.log(Level.WARNING, "Wait interrupted", ie);
- Thread.currentThread().interrupt();
- }
LOGGER.exiting(CLASS_NAME, "sendEvent");
}
@@ -302,6 +304,8 @@
{
LOGGER.entering(CLASS_NAME, "remove", listener);
+ context.ungetService(listener.reference);
+
for (String[] tokens : listener.paths)
{
Listeners lPtr = listeners;
@@ -354,9 +358,13 @@
{
LOGGER.entering(CLASS_NAME, "addListeners", new Object[]{ to, from, event });
- for (EventListener eventListener : from)
+ if (from != null)
{
- if (event.matches(eventListener.filter)) to.add(eventListener);
+
+ for (EventListener eventListener : from)
+ {
+ if (event.matches(eventListener.filter)) to.add(eventListener);
+ }
}
LOGGER.exiting(CLASS_NAME, "addListeners");
Modified: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/LogServiceTracker.java
===================================================================
--- papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/LogServiceTracker.java 2010-02-19 23:47:52 UTC (rev 247)
+++ papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/LogServiceTracker.java 2010-02-21 20:17:14 UTC (rev 248)
@@ -34,7 +34,7 @@
public void log(int level, String message)
{
- for (LogService service : (LogService[]) getServices())
+ for (LogService service : getLogServices())
{
service.log(level, message);
}
@@ -42,7 +42,7 @@
public void log(int level, String message, Throwable exception)
{
- for (LogService service : (LogService[]) getServices())
+ for (LogService service : getLogServices())
{
service.log(level, message, exception);
}
@@ -50,7 +50,7 @@
public void log(ServiceReference sr, int level, String message)
{
- for (LogService service : (LogService[]) getServices())
+ for (LogService service : getLogServices())
{
service.log(sr, level, message);
}
@@ -58,9 +58,20 @@
public void log(ServiceReference sr, int level, String message, Throwable exception)
{
- for (LogService service : (LogService[]) getServices())
+ for (LogService service : getLogServices())
{
service.log(sr, level, message, exception);
}
}
+
+ private final static LogService[] EMPTY = new LogService[0];
+
+ private LogService[] getLogServices()
+ {
+ LogService[] services = (LogService[]) getServices();
+
+ if (services == null) services = EMPTY;
+
+ return services;
+ }
}
Modified: papoose-cmpn/trunk/log/pom.xml
===================================================================
--- papoose-cmpn/trunk/log/pom.xml 2010-02-19 23:47:52 UTC (rev 247)
+++ papoose-cmpn/trunk/log/pom.xml 2010-02-21 20:17:14 UTC (rev 248)
@@ -23,8 +23,9 @@
<instructions>
<Bundle-SymbolicName>org.papoose.cmpn.log</Bundle-SymbolicName>
<Export-Package>org.papoose.log</Export-Package>
- <Import-Package>org.osgi.framework;version="[1.4,1.5]",org.osgi.service.event;version="[1.1,1.2]",org.osgi.service.log;version="[1.2,1.3]",org.osgi.util.tracker;version="[1.3,1.4]"</Import-Package>
+ <Import-Package>org.osgi.framework;version="[1.0,1.6)",org.osgi.service.event;version="[1.1,1.3)",org.osgi.service.log;version="[1.1,1.4)",org.osgi.util.tracker;version="[1.3,1.5)"</Import-Package>
<Private-Package>org.papoose.log.util</Private-Package>
+ <Private-Package>org.papoose.log.util</Private-Package>
</instructions>
</configuration>
</plugin>
Modified: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/EventAdminTracker.java
===================================================================
--- papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/EventAdminTracker.java 2010-02-19 23:47:52 UTC (rev 247)
+++ papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/EventAdminTracker.java 2010-02-21 20:17:14 UTC (rev 248)
@@ -34,7 +34,7 @@
public void postEvent(Event event)
{
- for (EventAdmin service : (EventAdmin[]) getServices())
+ for (EventAdmin service : getEventAdminServices())
{
service.postEvent(event);
}
@@ -42,9 +42,20 @@
public void sendEvent(Event event)
{
- for (EventAdmin service : (EventAdmin[]) getServices())
+ for (EventAdmin service : getEventAdminServices())
{
service.sendEvent(event);
}
}
+
+ private final static EventAdmin[] EMPTY = new EventAdmin[0];
+
+ private EventAdmin[] getEventAdminServices()
+ {
+ EventAdmin[] services = (EventAdmin[]) getServices();
+
+ if (services == null) services = EMPTY;
+
+ return services;
+ }
}
Modified: papoose-cmpn/trunk/pom.xml
===================================================================
--- papoose-cmpn/trunk/pom.xml 2010-02-19 23:47:52 UTC (rev 247)
+++ papoose-cmpn/trunk/pom.xml 2010-02-21 20:17:14 UTC (rev 248)
@@ -26,6 +26,7 @@
<properties>
<jettyVersion>6.1.9</jettyVersion>
+ <paxExamVersion>1.2.0</paxExamVersion>
<papooseTestVersion>1.0-SNAPSHOT</papooseTestVersion>
</properties>
@@ -94,6 +95,27 @@
</dependency>
<dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <version>${paxExamVersion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit</artifactId>
+ <version>${paxExamVersion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-default</artifactId>
+ <version>${paxExamVersion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>4.2.0</version>
Modified: papoose-cmpn/trunk/tck/pom.xml
===================================================================
--- papoose-cmpn/trunk/tck/pom.xml 2010-02-19 23:47:52 UTC (rev 247)
+++ papoose-cmpn/trunk/tck/pom.xml 2010-02-21 20:17:14 UTC (rev 248)
@@ -3,7 +3,7 @@
<parent>
<groupId>org.papoose.cmpn</groupId>
<artifactId>papoose-cmpn</artifactId>
- <version>1.0.0.SNAPSHOT</version>
+ <version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -13,8 +13,6 @@
<name>Papoose :: OSGi Compatibility Tests</name>
<modules>
- <module>bundles</module>
- <module>test-support</module>
<module>tests</module>
</modules>
Added: papoose-cmpn/trunk/tck/tests/pom.xml
===================================================================
--- papoose-cmpn/trunk/tck/tests/pom.xml (rev 0)
+++ papoose-cmpn/trunk/tck/tests/pom.xml 2010-02-21 20:17:14 UTC (rev 248)
@@ -0,0 +1,83 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.papoose.core.tck</groupId>
+ <artifactId>tck</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>papoose-cmpn-tests</artifactId>
+ <name>Papoose :: OSGi Compatibility Tests :: Tests</name>
+ <packaging>jar</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-depends-file</id>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.papoose.cmpn</groupId>
+ <artifactId>papoose-cmpn-event</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.papoose.cmpn</groupId>
+ <artifactId>papoose-cmpn-log</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-default</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+
+ </dependencies>
+
+</project>
Property changes on: papoose-cmpn/trunk/tck/tests/pom.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/event/EventAdminImplTest.java
===================================================================
--- papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/event/EventAdminImplTest.java (rev 0)
+++ papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/event/EventAdminImplTest.java 2010-02-21 20:17:14 UTC (rev 248)
@@ -0,0 +1,268 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.tck.event;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static junit.framework.Assert.assertEquals;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.knopflerfish;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import org.ops4j.pax.exam.Inject;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+import org.ops4j.pax.exam.Option;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.compendiumProfile;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+
+import org.papoose.event.EventAdminImpl;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+@RunWith(JUnit4TestRunner.class)
+public class EventAdminImplTest
+{
+ @Inject
+ private BundleContext bundleContext = null;
+
+ @Configuration
+ public static Option[] configure()
+ {
+ return options(
+ equinox(),
+ felix(),
+ knopflerfish(),
+ // papoose(),
+ compendiumProfile(),
+ // vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+ // this is necessary to let junit runner not timout the remote process before attaching debugger
+ // setting timeout to 0 means wait as long as the remote service comes available.
+ // starting with version 0.5.0 of PAx Exam this is no longer required as by default the framework tests
+ // will not be triggered till the framework is not started
+ // waitForFrameworkStartup()
+ provision(
+ mavenBundle().groupId("org.papoose.cmpn").artifactId("papoose-cmpn-event").version(asInProject())
+ )
+ );
+ }
+
+ @Test
+ public void testSingleEvent() throws Exception
+ {
+ Assert.assertNotNull(bundleContext);
+ ExecutorService executor = new ThreadPoolExecutor(1, 5, 100, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
+ ScheduledExecutorService scheduledExecutor = new ScheduledThreadPoolExecutor(2);
+
+ EventAdminImpl eventAdmin = new EventAdminImpl(bundleContext, executor, scheduledExecutor);
+
+ eventAdmin.open();
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(EventConstants.EVENT_TOPIC, "a/b/c/d");
+
+ final CountDownLatch latch = new CountDownLatch(1);
+ final AtomicInteger count = new AtomicInteger();
+ ServiceRegistration sr = bundleContext.registerService(EventHandler.class.getName(), new EventHandler()
+ {
+ public void handleEvent(Event event)
+ {
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException ie)
+ {
+ Thread.currentThread().interrupt();
+ }
+ finally
+ {
+ count.incrementAndGet();
+ latch.countDown();
+ }
+ }
+ }, properties);
+
+ try
+ {
+ eventAdmin.postEvent(new Event("a/b/c/d", (Dictionary) null));
+
+ latch.await();
+
+ assertEquals(1, count.get());
+
+ eventAdmin.sendEvent(new Event("a/b/c/d", (Dictionary) null));
+ eventAdmin.sendEvent(new Event("a/b/c/d/e", (Dictionary) null));
+ eventAdmin.sendEvent(new Event("z/b/c/d", (Dictionary) null));
+ eventAdmin.sendEvent(new Event("a/b/c", (Dictionary) null));
+
+ assertEquals(2, count.get());
+ }
+ finally
+ {
+ sr.unregister();
+
+ eventAdmin.close();
+
+ executor.shutdown();
+ scheduledExecutor.shutdown();
+ }
+ }
+
+ @Test
+ public void testWildcard() throws Exception
+ {
+ Assert.assertNotNull(bundleContext);
+ ExecutorService executor = new ThreadPoolExecutor(1, 5, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ ScheduledExecutorService scheduledExecutor = new ScheduledThreadPoolExecutor(2);
+
+ EventAdminImpl eventAdmin = new EventAdminImpl(bundleContext, executor, scheduledExecutor);
+
+ eventAdmin.open();
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(EventConstants.EVENT_TOPIC, "a/b/c/*");
+
+ final CountDownLatch latch = new CountDownLatch(1);
+ final AtomicInteger count = new AtomicInteger();
+ ServiceRegistration sr = bundleContext.registerService(EventHandler.class.getName(), new EventHandler()
+ {
+ public void handleEvent(Event event)
+ {
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException ie)
+ {
+ Thread.currentThread().interrupt();
+ }
+ finally
+ {
+ count.incrementAndGet();
+ latch.countDown();
+ }
+ }
+ }, properties);
+
+ try
+ {
+ eventAdmin.postEvent(new Event("a/b/c/d", (Dictionary) null));
+
+ latch.await();
+
+ assertEquals(1, count.get());
+
+ eventAdmin.sendEvent(new Event("a/b/c", (Dictionary) null));
+ eventAdmin.sendEvent(new Event("a/b/c/d", (Dictionary) null));
+ eventAdmin.sendEvent(new Event("a/b/c/d/e", (Dictionary) null));
+
+ assertEquals(3, count.get());
+ }
+ finally
+ {
+ sr.unregister();
+
+ eventAdmin.close();
+
+ executor.shutdown();
+ scheduledExecutor.shutdown();
+ }
+ }
+
+ @Test
+ public void testRootWildcard() throws Exception
+ {
+ Assert.assertNotNull(bundleContext);
+ ExecutorService executor = new ThreadPoolExecutor(1, 5, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+ ScheduledExecutorService scheduledExecutor = new ScheduledThreadPoolExecutor(2);
+
+ EventAdminImpl eventAdmin = new EventAdminImpl(bundleContext, executor, scheduledExecutor);
+
+ eventAdmin.open();
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put(EventConstants.EVENT_TOPIC, "a/*");
+
+ final CountDownLatch latch = new CountDownLatch(1);
+ final AtomicInteger count = new AtomicInteger();
+ ServiceRegistration sr = bundleContext.registerService(EventHandler.class.getName(), new EventHandler()
+ {
+ public void handleEvent(Event event)
+ {
+ try
+ {
+ Thread.sleep(100);
+ }
+ catch (InterruptedException ie)
+ {
+ Thread.currentThread().interrupt();
+ }
+ finally
+ {
+ count.incrementAndGet();
+ latch.countDown();
+ }
+ }
+ }, properties);
+
+ try
+ {
+ eventAdmin.postEvent(new Event("a/b/c/d", (Dictionary) null));
+
+ latch.await();
+
+ assertEquals(1, count.get());
+
+ eventAdmin.sendEvent(new Event("a/b/c", (Dictionary) null));
+ eventAdmin.sendEvent(new Event("a/b/c/d", (Dictionary) null));
+ eventAdmin.sendEvent(new Event("z/b/c/d", (Dictionary) null));
+
+ assertEquals(3, count.get());
+ }
+ finally
+ {
+ sr.unregister();
+
+ eventAdmin.close();
+
+ executor.shutdown();
+ scheduledExecutor.shutdown();
+ }
+ }
+}
Property changes on: papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/event/EventAdminImplTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/log/LogServiceImplTest.java
===================================================================
--- papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/log/LogServiceImplTest.java (rev 0)
+++ papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/log/LogServiceImplTest.java 2010-02-21 20:17:14 UTC (rev 248)
@@ -0,0 +1,171 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.tck.log;
+
+import java.util.Enumeration;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.junit.Assert;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.knopflerfish;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import org.ops4j.pax.exam.Inject;
+import static org.ops4j.pax.exam.MavenUtils.asInProject;
+import org.ops4j.pax.exam.Option;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.compendiumProfile;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogListener;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+
+import org.papoose.log.LogServiceImpl;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+@RunWith(JUnit4TestRunner.class)
+public class LogServiceImplTest
+{
+ @Inject
+ private BundleContext bundleContext = null;
+
+ @Configuration
+ public static Option[] configure()
+ {
+ return options(
+ equinox(),
+ felix(),
+ knopflerfish(),
+ // papoose(),
+ compendiumProfile(),
+ // vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+ // this is necessary to let junit runner not timout the remote process before attaching debugger
+ // setting timeout to 0 means wait as long as the remote service comes available.
+ // starting with version 0.5.0 of PAx Exam this is no longer required as by default the framework tests
+ // will not be triggered till the framework is not started
+ // waitForFrameworkStartup()
+ provision(
+ mavenBundle().groupId("org.papoose.cmpn").artifactId("papoose-cmpn-log").version(asInProject())
+ )
+ );
+ }
+
+ @Test
+ public void test() throws Exception
+ {
+ Assert.assertNotNull(bundleContext);
+ ExecutorService executor = new ThreadPoolExecutor(1, 5, 100, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
+
+ LogServiceImpl logServiceImpl = new LogServiceImpl(bundleContext, executor);
+ logServiceImpl.setLimit(100);
+
+ logServiceImpl.start();
+
+ bundleContext.registerService(new String[]{ LogService.class.getName(), LogReaderService.class.getName() }, logServiceImpl, null);
+
+ try
+ {
+ ServiceReference sr = bundleContext.getServiceReference(LogService.class.getName());
+ LogService logService = (LogService) bundleContext.getService(sr);
+ sr = bundleContext.getServiceReference(LogReaderService.class.getName());
+ LogReaderService logReaderService = (LogReaderService) bundleContext.getService(sr);
+
+ final int NUM_LISTENERS = 100;
+ final int NUM_MESSAGES = 1000;
+ final AtomicReference<CountDownLatch> latch = new AtomicReference<CountDownLatch>();
+ final AtomicInteger count = new AtomicInteger();
+ final AtomicBoolean error = new AtomicBoolean(false);
+ LogListener listener;
+ logReaderService.addLogListener(listener = new LogListener()
+ {
+ int counter = 0;
+
+ public void logged(LogEntry entry)
+ {
+ error.set(error.get() || !("Test" + (counter++)).equals(entry.getMessage()));
+
+ count.incrementAndGet();
+ latch.get().countDown();
+ }
+ });
+
+ for (int i = 1; i < NUM_LISTENERS; i++)
+ {
+ logReaderService.addLogListener(new LogListener()
+ {
+ int counter = 0;
+
+ public void logged(LogEntry entry)
+ {
+ error.set(error.get() || !("Test" + (counter++)).equals(entry.getMessage()));
+ latch.get().countDown();
+ }
+ });
+ }
+
+ latch.set(new CountDownLatch(NUM_LISTENERS * NUM_MESSAGES));
+ for (int i = 0; i < NUM_MESSAGES; i++) logService.log(LogService.LOG_INFO, "Test" + i);
+
+ Enumeration enumeration = logReaderService.getLog();
+ for (int i = 0; i < 100; i++)
+ {
+ LogEntry logEntry = (LogEntry) enumeration.nextElement();
+ assertEquals("Test" + (999 - i), logEntry.getMessage());
+ }
+
+ assertFalse(enumeration.hasMoreElements());
+
+ latch.get().await();
+
+ assertEquals(NUM_MESSAGES, count.get());
+ assertFalse(error.get());
+
+ logReaderService.removeLogListener(listener);
+
+ latch.set(new CountDownLatch((NUM_LISTENERS - 1) * NUM_MESSAGES));
+ for (int i = 0; i < NUM_MESSAGES; i++) logService.log(LogService.LOG_INFO, "Test" + i);
+
+ latch.get().await();
+
+ assertEquals(NUM_MESSAGES, count.get());
+ }
+ finally
+ {
+ logServiceImpl.stop();
+ executor.shutdown();
+ }
+ }
+}
Property changes on: papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/log/LogServiceImplTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-19 23:48:00
|
Revision: 247
http://osgi.svn.sourceforge.net/osgi/?rev=247&view=rev
Author: maguro
Date: 2010-02-19 23:47:52 +0000 (Fri, 19 Feb 2010)
Log Message:
-----------
Bundlize the jar
Modified Paths:
--------------
papoose-cmpn/trunk/log/pom.xml
Modified: papoose-cmpn/trunk/log/pom.xml
===================================================================
--- papoose-cmpn/trunk/log/pom.xml 2010-02-19 23:44:49 UTC (rev 246)
+++ papoose-cmpn/trunk/log/pom.xml 2010-02-19 23:47:52 UTC (rev 247)
@@ -9,17 +9,23 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>papoose-cmpn-log</artifactId>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<name>Papoose :: Log Service</name>
<description>Log Service</description>
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
<configuration>
- <argLine>-enableassertions</argLine>
+ <instructions>
+ <Bundle-SymbolicName>org.papoose.cmpn.log</Bundle-SymbolicName>
+ <Export-Package>org.papoose.log</Export-Package>
+ <Import-Package>org.osgi.framework;version="[1.4,1.5]",org.osgi.service.event;version="[1.1,1.2]",org.osgi.service.log;version="[1.2,1.3]",org.osgi.util.tracker;version="[1.3,1.4]"</Import-Package>
+ <Private-Package>org.papoose.log.util</Private-Package>
+ </instructions>
</configuration>
</plugin>
</plugins>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-19 23:44:56
|
Revision: 246
http://osgi.svn.sourceforge.net/osgi/?rev=246&view=rev
Author: maguro
Date: 2010-02-19 23:44:49 +0000 (Fri, 19 Feb 2010)
Log Message:
-----------
Initial sketch of log service
Added Paths:
-----------
papoose-cmpn/trunk/log/src/main/java/org/
papoose-cmpn/trunk/log/src/main/java/org/papoose/
papoose-cmpn/trunk/log/src/main/java/org/papoose/log/
papoose-cmpn/trunk/log/src/main/java/org/papoose/log/LogEntryImpl.java
papoose-cmpn/trunk/log/src/main/java/org/papoose/log/LogServiceImpl.java
papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/
papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/EventAdminTracker.java
papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/LogListenerHolder.java
papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/SerialExecutor.java
Added: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/LogEntryImpl.java
===================================================================
--- papoose-cmpn/trunk/log/src/main/java/org/papoose/log/LogEntryImpl.java (rev 0)
+++ papoose-cmpn/trunk/log/src/main/java/org/papoose/log/LogEntryImpl.java 2010-02-19 23:44:49 UTC (rev 246)
@@ -0,0 +1,74 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.log;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogEntry;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+class LogEntryImpl implements LogEntry
+{
+ private final Bundle bundle;
+ private final ServiceReference serviceReference;
+ private final int level;
+ private final String message;
+ private final Throwable exception;
+ private final long time = System.currentTimeMillis();
+
+ LogEntryImpl(Bundle bundle, ServiceReference serviceReference, int level, String message, Throwable exception)
+ {
+ this.bundle = bundle;
+ this.serviceReference = serviceReference;
+ this.level = level;
+ this.message = message;
+ this.exception = exception;
+ }
+
+ public long getTime()
+ {
+ return time;
+ }
+
+ public Bundle getBundle()
+ {
+ return bundle;
+ }
+
+ public ServiceReference getServiceReference()
+ {
+ return serviceReference;
+ }
+
+ public int getLevel()
+ {
+ return level;
+ }
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ public Throwable getException()
+ {
+ return exception;
+ }
+}
Property changes on: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/LogEntryImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/LogServiceImpl.java
===================================================================
--- papoose-cmpn/trunk/log/src/main/java/org/papoose/log/LogServiceImpl.java (rev 0)
+++ papoose-cmpn/trunk/log/src/main/java/org/papoose/log/LogServiceImpl.java 2010-02-19 23:44:49 UTC (rev 246)
@@ -0,0 +1,471 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.log;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ExecutorService;
+import java.util.logging.Logger;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.event.Event;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogListener;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+
+import org.papoose.log.util.EventAdminTracker;
+import org.papoose.log.util.LogListenerHolder;
+import org.papoose.log.util.SerialExecutor;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class LogServiceImpl implements LogService, LogReaderService, BundleListener, ServiceListener, FrameworkListener
+{
+ private final static String CLASS_NAME = LogServiceImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final List<LogListenerHolder> listeners = new CopyOnWriteArrayList<LogListenerHolder>();
+ private final LinkedList<LogEntry> log = new LinkedList<LogEntry>();
+ private final ExecutorService executorService;
+ private final EventAdminTracker eventAdmin;
+ private int limit = 1000;
+
+ /**
+ * Create an instance of a log service that implements both the
+ * <code>LogService</code> and <code>LogReaderService</code>.
+ * <p/>
+ * The default log limit is 1000.
+ *
+ * @param context the bundle context to use to search for event admins
+ * @param executorService the executor service used to deliver log entries to log listeners
+ */
+ public LogServiceImpl(BundleContext context, ExecutorService executorService)
+ {
+ if (context == null) throw new IllegalArgumentException("Bundle context is null");
+ if (executorService == null) throw new IllegalArgumentException("Executor service is null");
+
+ this.executorService = executorService;
+ this.eventAdmin = new EventAdminTracker(context);
+ }
+
+ /**
+ * The number of log entries kept in ths log service is not unbounded. Use
+ * this method to obtain the maximum number of log entries kept in the log
+ * service.
+ *
+ * @return the maximum number of log entries kept in the log service
+ */
+ public int getLimit()
+ {
+ return limit;
+ }
+
+ /**
+ * Use this method to set the maximum number of log entries kept in the
+ * log service.
+ *
+ * @param limit the maximum number of log entries kept in the log service
+ */
+ public void setLimit(int limit)
+ {
+ this.limit = limit;
+ }
+
+ /**
+ * Start this logging service.
+ */
+ public void start()
+ {
+ eventAdmin.open();
+ }
+
+
+ /**
+ * Stop this logging service.
+ */
+ public void stop()
+ {
+ eventAdmin.close();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void log(int level, String message)
+ {
+ LOGGER.entering(CLASS_NAME, "log", new Object[]{ level, message });
+
+ log(level, message, null);
+
+ LOGGER.exiting(CLASS_NAME, "log");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void log(int level, String message, Throwable exception)
+ {
+ LOGGER.entering(CLASS_NAME, "log", new Object[]{ level, message, exception });
+
+ LogEntryImpl entry = new LogEntryImpl(null, null, level, message, exception);
+
+ insert(entry);
+ broadcast(entry);
+
+ LOGGER.exiting(CLASS_NAME, "log");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void log(ServiceReference sr, int level, String message)
+ {
+ LOGGER.entering(CLASS_NAME, "log", new Object[]{ sr, level, message });
+
+ log(sr, level, message, null);
+
+ LOGGER.exiting(CLASS_NAME, "log");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void log(ServiceReference sr, int level, String message, Throwable exception)
+ {
+ LOGGER.entering(CLASS_NAME, "log", new Object[]{ sr, level, message, exception });
+
+ LogEntryImpl entry = new LogEntryImpl(sr.getBundle(), sr, level, message, exception);
+
+ insert(entry);
+ broadcast(entry);
+
+ LOGGER.exiting(CLASS_NAME, "log");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addLogListener(LogListener listener)
+ {
+ LOGGER.entering(CLASS_NAME, "addLogListener", listener);
+
+ listeners.add(new LogListenerHolder(listener, new SerialExecutor(executorService)));
+
+ LOGGER.exiting(CLASS_NAME, "addLogListener");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeLogListener(LogListener listener)
+ {
+ LOGGER.entering(CLASS_NAME, "removeLogListener", listener);
+
+ listeners.remove(new LogListenerHolder(listener));
+
+ LOGGER.exiting(CLASS_NAME, "removeLogListener");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Enumeration getLog()
+ {
+ LOGGER.entering(CLASS_NAME, "getLog");
+
+ synchronized (log)
+ {
+ Enumeration enumeration = new Enumeration()
+ {
+ private final Iterator<LogEntry> iterator = log.iterator();
+
+ public boolean hasMoreElements()
+ {
+ return iterator.hasNext();
+ }
+
+ public Object nextElement()
+ {
+ return iterator.next();
+ }
+ };
+
+ LOGGER.exiting(CLASS_NAME, "getLog", enumeration);
+
+ return enumeration;
+ }
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void bundleChanged(BundleEvent event)
+ {
+ LOGGER.entering(CLASS_NAME, "bundleChanged", event);
+
+ String message = null;
+ switch (event.getType())
+ {
+ case BundleEvent.INSTALLED:
+ message = "BundleEvent INSTALLED";
+ break;
+
+ case BundleEvent.STARTED:
+ message = "BundleEvent STARTED";
+ break;
+
+ case BundleEvent.STOPPED:
+ message = "BundleEvent STOPPED";
+ break;
+
+ case BundleEvent.UPDATED:
+ message = "BundleEvent UPDATED";
+ break;
+
+ case BundleEvent.UNINSTALLED:
+ message = "BundleEvent UNINSTALLED";
+ break;
+
+ case BundleEvent.RESOLVED:
+ message = "BundleEvent RESOLVED";
+ break;
+
+ case BundleEvent.UNRESOLVED:
+ message = "BundleEvent UNRESOLVED";
+ break;
+ }
+
+ insert(new LogEntryImpl(event.getBundle(), null, LOG_INFO, message, null));
+
+ LOGGER.exiting(CLASS_NAME, "bundleChanged");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void serviceChanged(ServiceEvent event)
+ {
+ LOGGER.entering(CLASS_NAME, "serviceChanged", event);
+
+ int type = event.getType();
+ String message = null;
+ switch (type)
+ {
+ case ServiceEvent.REGISTERED:
+ message = "ServiceEvent REGISTERED";
+ break;
+
+ case ServiceEvent.MODIFIED:
+ message = "ServiceEvent MODIFIED";
+ break;
+
+ case ServiceEvent.UNREGISTERING:
+ message = "ServiceEvent UNREGISTERING";
+ break;
+ }
+
+ ServiceReference reference = event.getServiceReference();
+
+ insert(new LogEntryImpl(reference.getBundle(), reference, type == ServiceEvent.MODIFIED ? LOG_DEBUG : LOG_INFO, message, null));
+
+ LOGGER.exiting(CLASS_NAME, "serviceChanged");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void frameworkEvent(FrameworkEvent event)
+ {
+ LOGGER.entering(CLASS_NAME, "frameworkEvent", event);
+
+ int type = event.getType();
+ String message = null;
+ switch (type)
+ {
+ case FrameworkEvent.STARTED:
+ message = "FrameworkEvent STARTED";
+ break;
+
+ case FrameworkEvent.ERROR:
+ message = "FrameworkEvent ERROR";
+ break;
+
+ case FrameworkEvent.PACKAGES_REFRESHED:
+ message = "FrameworkEvent PACKAGES_REFRESHED";
+ break;
+
+ case FrameworkEvent.STARTLEVEL_CHANGED:
+ message = "FrameworkEvent STARTLEVEL_CHANGED";
+ break;
+
+ case FrameworkEvent.WARNING:
+ message = "FrameworkEvent WARNING";
+ break;
+
+ case FrameworkEvent.INFO:
+ message = "FrameworkEvent INFO";
+ break;
+ }
+
+ insert(new LogEntryImpl(event.getBundle(), null, type == FrameworkEvent.ERROR ? LOG_ERROR : LOG_INFO, message, event.getThrowable()));
+
+ LOGGER.exiting(CLASS_NAME, "frameworkEvent");
+ }
+
+ /**
+ * Insert a log entry into the log. Make sure that the log does not
+ * exceed the limit.
+ *
+ * @param entry the log entry to be inserted into the log
+ */
+ private void insert(final LogEntry entry)
+ {
+ LOGGER.entering(CLASS_NAME, "insert", entry);
+
+ synchronized (log)
+ {
+ log.addFirst(entry);
+ while (log.size() > limit) log.removeLast();
+ }
+
+ for (LogListenerHolder holder : listeners)
+ {
+ final LogListener listener = holder.getListener();
+ holder.getExecutor().execute(new Runnable()
+ {
+ public void run()
+ {
+ listener.logged(entry);
+ }
+ });
+ }
+
+ LOGGER.exiting(CLASS_NAME, "insert");
+ }
+
+ /**
+ * Log events must be delivered by the Log Service implementation to the
+ * Event Admin service (if present) asynchronously.
+ * <p/>
+ * The properties of a log event are:
+ * <ol>
+ * <li>bundle.id \xD0 (Long) The source bundle's id.</li>
+ * <li> bundle.symbolicName \xD0 (String) The source bundle's symbolic name. Only set if not null.</li>
+ * <li> bundle \xD0 (Bundle) The source bundle.</li>
+ * <li> log.level \xD0 (Integer) The log level.</li>
+ * <li> message \xD0 (String) The log message.</li>
+ * <li> timestamp \xD0 (Long) The log entry's timestamp.</li>
+ * <li> log.entry \xD0 (LogEntry) The LogEntry object.</li>
+ * </ol>
+ * If the log entry has an associated Exception:
+ * <ol>
+ * <li> exception.class \xD0 (String) The fully-qualified class name of the attached exception. Only set if the getExceptionmethod returns a non-null value.</li>
+ * <li> exception.message \xD0 (String) The message of the attached Exception. Only set if the Exception message is not null.</li>
+ * <li> exception \xD0 (Throwable) The Exception returned by the getException method.</li>
+ * </ol>
+ * If the getServiceReference method returns a non-null value:
+ * <ol>
+ * <li> service \xD0 (ServiceReference) The result of the getServiceReference method.</li>
+ * <li> service.id \xD0 (Long) The id of the service.</li>
+ * <li> service.pid \xD0 (String) The service's persistent identity. Only set if the service.pid service property is not null.</li>
+ * <li> service.objectClass \xD0 (String[]) The object class of the service object.</li>
+ * </ol>
+ *
+ * @param entry the log entry to be mapped to an event and delivered via the Event Admin service
+ */
+ private void broadcast(final LogEntry entry)
+ {
+ LOGGER.entering(CLASS_NAME, "broadcast", entry);
+
+ String code;
+ switch (entry.getLevel())
+ {
+ case LOG_ERROR:
+ code = "ERROR";
+ break;
+
+ case LOG_WARNING:
+ code = "WARNING";
+ break;
+
+ case LOG_INFO:
+ code = "INFO";
+ break;
+
+ case LOG_DEBUG:
+ code = "DEBUG";
+ break;
+
+ default:
+ code = "OTHER";
+ break;
+ }
+
+ Map<String, Object> map = new HashMap<String, Object>();
+
+ Bundle bundle = entry.getBundle();
+ if (bundle != null)
+ {
+ map.put("bundle.id", bundle.getBundleId());
+ map.put("bundle", bundle);
+ if (bundle.getSymbolicName() != null) map.put("bundle.symbolicName", bundle.getSymbolicName());
+ }
+
+ map.put("log.level", entry.getLevel());
+ map.put("message", entry.getMessage());
+ map.put("timestamp", entry.getTime());
+ map.put("log.entry", entry);
+
+ Throwable exception = entry.getException();
+ if (exception != null)
+ {
+ map.put("exception.class", exception.getClass().getName());
+ map.put("exception.message", exception.getMessage());
+ map.put("exception", exception);
+ }
+
+ ServiceReference reference = entry.getServiceReference();
+ if (reference != null)
+ {
+ map.put("service", reference);
+ map.put("service.id", reference.getProperty(Constants.SERVICE_ID));
+ if (reference.getProperty(Constants.SERVICE_PID) != null) map.put("service.pid", reference.getProperty(Constants.SERVICE_PID));
+ map.put("service.objectClass", reference.getProperty(Constants.OBJECTCLASS));
+ }
+
+ eventAdmin.postEvent(new Event("org/osgi/service/log/LogEntry/" + code, map));
+
+ LOGGER.exiting(CLASS_NAME, "broadcast");
+ }
+}
Property changes on: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/LogServiceImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/EventAdminTracker.java
===================================================================
--- papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/EventAdminTracker.java (rev 0)
+++ papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/EventAdminTracker.java 2010-02-19 23:44:49 UTC (rev 246)
@@ -0,0 +1,50 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.log.util;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class EventAdminTracker extends ServiceTracker implements EventAdmin
+{
+ public EventAdminTracker(BundleContext context)
+ {
+ super(context, EventAdmin.class.getName(), null);
+ }
+
+ public void postEvent(Event event)
+ {
+ for (EventAdmin service : (EventAdmin[]) getServices())
+ {
+ service.postEvent(event);
+ }
+ }
+
+ public void sendEvent(Event event)
+ {
+ for (EventAdmin service : (EventAdmin[]) getServices())
+ {
+ service.sendEvent(event);
+ }
+ }
+}
Property changes on: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/EventAdminTracker.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/LogListenerHolder.java
===================================================================
--- papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/LogListenerHolder.java (rev 0)
+++ papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/LogListenerHolder.java 2010-02-19 23:44:49 UTC (rev 246)
@@ -0,0 +1,67 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.log.util;
+
+import org.osgi.service.log.LogListener;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public final class LogListenerHolder
+{
+ private final LogListener listener;
+ private final SerialExecutor executor;
+
+ public LogListenerHolder(LogListener listener)
+ {
+ this(listener, null);
+ }
+
+ public LogListenerHolder(LogListener listener, SerialExecutor executor)
+ {
+ this.listener = listener;
+ this.executor = executor;
+ }
+
+ public SerialExecutor getExecutor()
+ {
+ return executor;
+ }
+
+ public LogListener getListener()
+ {
+ return listener;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ LogListenerHolder that = (LogListenerHolder) o;
+
+ return listener.equals(that.listener);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return listener.hashCode();
+ }
+}
Property changes on: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/LogListenerHolder.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/SerialExecutor.java
===================================================================
--- papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/SerialExecutor.java (rev 0)
+++ papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/SerialExecutor.java 2010-02-19 23:44:49 UTC (rev 246)
@@ -0,0 +1,110 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.log.util;
+
+import java.util.Queue;
+import java.util.concurrent.Executor;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+/**
+ * A handy wrapper class that conveniently queues runnables for execution.
+ * <p/>
+ * Use this class when you need to have multiple queues feeding a single
+ * thread pool.
+ *
+ * @version $Revision: 228 $ $Date: 2010-01-12 13:40:06 -0800 (Tue, 12 Jan 2010) $
+ */
+public class SerialExecutor implements Executor
+{
+ private final static String CLASS_NAME = SerialExecutor.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final Queue<Runnable> tasks = new LinkedBlockingQueue<Runnable>();
+ private final Executor executor;
+ private Runnable active;
+
+ /**
+ * Initialzed the serial executor with a shared executor delegate.
+ *
+ * @param executor the shared executor that is fed by this queue
+ */
+ public SerialExecutor(Executor executor)
+ {
+ if (executor == null) throw new IllegalArgumentException("Executor is null");
+
+ if (LOGGER.isLoggable(Level.CONFIG)) LOGGER.config("executor: " + executor);
+
+ this.executor = executor;
+ }
+
+ /**
+ * Executes the given command at some time in the future. The command
+ * may execute in a new thread, in a pooled thread, or in the calling
+ * thread, at the discretion of the <tt>Executor</tt> that this class was
+ * constructed with.
+ *
+ * @param runnable the runnable task
+ * @throws java.util.concurrent.RejectedExecutionException
+ * if this task cannot be accepted for execution.
+ * @throws NullPointerException if command is null
+ */
+ public synchronized void execute(final Runnable runnable)
+ {
+ LOGGER.entering(CLASS_NAME, "execute", runnable);
+
+ tasks.offer(new Runnable()
+ {
+ public void run()
+ {
+ LOGGER.entering(CLASS_NAME, "execute.Runnable", runnable);
+
+ try
+ {
+ runnable.run();
+ }
+ finally
+ {
+ scheduleNext();
+ }
+
+ LOGGER.exiting(CLASS_NAME, "execute.Runnable");
+ }
+ });
+
+ if (active == null) scheduleNext();
+
+ LOGGER.exiting(CLASS_NAME, "execute");
+ }
+
+ /**
+ * Poll the queue for more work. If a runnable is found then send it to
+ * executor.
+ */
+ protected synchronized void scheduleNext()
+ {
+ LOGGER.entering(CLASS_NAME, "scheduleNext");
+
+ if ((active = tasks.poll()) != null)
+ {
+ executor.execute(active);
+ }
+
+ LOGGER.exiting(CLASS_NAME, "scheduleNext");
+ }
+}
Property changes on: papoose-cmpn/trunk/log/src/main/java/org/papoose/log/util/SerialExecutor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-19 19:41:45
|
Revision: 245
http://osgi.svn.sourceforge.net/osgi/?rev=245&view=rev
Author: maguro
Date: 2010-02-19 19:41:39 +0000 (Fri, 19 Feb 2010)
Log Message:
-----------
No need to constantly get service
Modified Paths:
--------------
papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java
Modified: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java
===================================================================
--- papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java 2010-02-19 19:28:25 UTC (rev 244)
+++ papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java 2010-02-19 19:41:39 UTC (rev 245)
@@ -125,8 +125,6 @@
return null;
}
- Object service = context.getService(reference);
-
String[] topics;
if (test instanceof String)
{
@@ -144,6 +142,7 @@
return null;
}
+ EventHandler service = (EventHandler) context.getService(reference);
SecurityManager sm = System.getSecurityManager();
if (sm != null)
{
@@ -169,6 +168,7 @@
{
if ("*".equals(paths[i][j]))
{
+ loggers.log(reference, LogService.LOG_WARNING, "Service has an ill formatted topic " + topics[i] + ", ignoring");
LOGGER.finest("Service has an ill formatted topic " + topics[i] + ", ignoring");
LOGGER.exiting(CLASS_NAME, "addingService", null);
@@ -182,7 +182,7 @@
String filter = (String) reference.getProperty(EventConstants.EVENT_FILTER);
try
{
- EventListener listener = new EventListener(paths, reference, filter);
+ EventListener listener = new EventListener(paths, reference, service, filter);
add(listener);
@@ -433,20 +433,21 @@
private final Executor executor;
private final String[][] paths;
private final ServiceReference reference;
+ private final EventHandler handler;
private final Filter filter;
- private EventListener(String[][] paths, ServiceReference reference, String filter) throws InvalidSyntaxException
+ private EventListener(String[][] paths, ServiceReference reference, EventHandler handler, String filter) throws InvalidSyntaxException
{
this.executor = new SerialExecutor(EventAdminImpl.this.executor);
this.paths = paths;
this.reference = reference;
+ this.handler = handler;
this.filter = (filter == null ? DEFAULT_FILTER : context.createFilter(filter));
}
public void handleEvent(Event event)
{
- EventHandler handler = (EventHandler) context.getService(reference);
- if (handler != null) handler.handleEvent(event);
+ handler.handleEvent(event);
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <osg...@li...> - 2010-02-19 19:28:31
|
Revision: 244
http://osgi.svn.sourceforge.net/osgi/?rev=244&view=rev
Author: maguro
Date: 2010-02-19 19:28:25 +0000 (Fri, 19 Feb 2010)
Log Message:
-----------
Logging added
Modified Paths:
--------------
papoose-cmpn/trunk/event/pom.xml
papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java
Added Paths:
-----------
papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/LogServiceTracker.java
Modified: papoose-cmpn/trunk/event/pom.xml
===================================================================
--- papoose-cmpn/trunk/event/pom.xml 2010-02-19 16:02:59 UTC (rev 243)
+++ papoose-cmpn/trunk/event/pom.xml 2010-02-19 19:28:25 UTC (rev 244)
@@ -23,7 +23,7 @@
<instructions>
<Bundle-SymbolicName>org.papoose.cmpn.event</Bundle-SymbolicName>
<Export-Package>org.papoose.event</Export-Package>
- <Import-Package>org.osgi.framework;version="[1.4,1.5]",org.osgi.service.event;version="[1.1,1.2]",org.osgi.util.tracker;version="[1.3,1.4]"</Import-Package>
+ <Import-Package>org.osgi.framework;version="[1.4,1.5]",org.osgi.service.event;version="[1.1,1.2]",org.osgi.service.log;version="[1.2,1.3]",org.osgi.util.tracker;version="[1.3,1.4]"</Import-Package>
<Private-Package>org.papoose.event.util</Private-Package>
</instructions>
</configuration>
Modified: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java
===================================================================
--- papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java 2010-02-19 16:02:59 UTC (rev 243)
+++ papoose-cmpn/trunk/event/src/main/java/org/papoose/event/EventAdminImpl.java 2010-02-19 19:28:25 UTC (rev 244)
@@ -26,6 +26,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -41,8 +42,10 @@
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.osgi.service.event.TopicPermission;
+import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
+import org.papoose.event.util.LogServiceTracker;
import org.papoose.event.util.SerialExecutor;
@@ -64,6 +67,7 @@
private final Listeners listeners = new Listeners();
private final ExecutorService executor;
private final ScheduledExecutorService scheduledExecutor;
+ private final LogServiceTracker loggers;
private int timeout = 60;
private TimeUnit timeUnit = TimeUnit.SECONDS;
@@ -73,6 +77,7 @@
this.executor = executor;
this.scheduledExecutor = scheduledExecutor;
+ this.loggers = new LogServiceTracker(context);
}
public int getTimeout()
@@ -187,6 +192,7 @@
}
catch (InvalidSyntaxException e)
{
+ loggers.log(reference, LogService.LOG_WARNING, "Service had an invalid filter " + filter + ", ignoring", e);
LOGGER.finest("Service had an invalid filter " + filter + ", ignoring");
LOGGER.exiting(CLASS_NAME, "addingService", null);
return null;
@@ -262,6 +268,8 @@
private void add(EventListener listener)
{
+ LOGGER.entering(CLASS_NAME, "add", listener);
+
for (String[] tokens : listener.paths)
{
Listeners lPtr = listeners;
@@ -286,10 +294,14 @@
set.add(listener);
}
}
+
+ LOGGER.exiting(CLASS_NAME, "add");
}
private void remove(EventListener listener)
{
+ LOGGER.entering(CLASS_NAME, "remove", listener);
+
for (String[] tokens : listener.paths)
{
Listeners lPtr = listeners;
@@ -307,10 +319,14 @@
if (set == null) return;
set.remove(listener);
}
+
+ LOGGER.exiting(CLASS_NAME, "remove");
}
private Set<EventListener> collectListeners(Event event)
{
+ LOGGER.entering(CLASS_NAME, "collectListeners", event);
+
Listeners lPtr = listeners;
Set<EventListener> set = new HashSet<EventListener>();
@@ -329,15 +345,21 @@
addListeners(set, lPtr.handlers.get(tokens[tokens.length - 1]), event);
}
+ LOGGER.exiting(CLASS_NAME, "collectListeners", set);
+
return set;
}
private static void addListeners(Set<EventListener> to, Set<EventListener> from, Event event)
{
+ LOGGER.entering(CLASS_NAME, "addListeners", new Object[]{ to, from, event });
+
for (EventListener eventListener : from)
{
if (event.matches(eventListener.filter)) to.add(eventListener);
}
+
+ LOGGER.exiting(CLASS_NAME, "addListeners");
}
private class TimeoutRunnable implements Runnable
@@ -367,14 +389,23 @@
{
public void run()
{
+ loggers.log(listener.reference, LogService.LOG_WARNING, "Listener timeout, will be blacklisted");
+ LOGGER.log(Level.WARNING, "Listener timeout, will be blacklisted");
+
remove(listener);
}
}, timeout, timeUnit);
listener.handleEvent(event);
}
+ catch (RejectedExecutionException ree)
+ {
+ loggers.log(listener.reference, LogService.LOG_WARNING, "Unable to schedule timeout for listener call, call skipped", ree);
+ LOGGER.log(Level.WARNING, "Unable to schedule timeout for listener call, call skipped", ree);
+ }
catch (Throwable t)
{
+ loggers.log(listener.reference, LogService.LOG_WARNING, "Listener threw exception", t);
LOGGER.log(Level.WARNING, "Listener threw exception", t);
}
finally
@@ -383,6 +414,12 @@
if (latch != null) latch.countDown();
}
}
+
+ @Override
+ public String toString()
+ {
+ return getClass().getName() + " [listener=" + listener + " event=" + event + "]";
+ }
}
private static class Listeners
@@ -411,5 +448,20 @@
EventHandler handler = (EventHandler) context.getService(reference);
if (handler != null) handler.handleEvent(event);
}
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder("(");
+ for (String[] path : paths)
+ {
+ if (builder.length() > 1) builder.append(", ");
+ builder.append(path[0]);
+ for (int i = 1; i < path.length; i++) builder.append("/").append(path[i]);
+ }
+ builder.append(")");
+
+ return getClass().getName() + " [paths=" + builder + " reference=" + reference + " filter=" + filter + "]";
+ }
}
}
Added: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/LogServiceTracker.java
===================================================================
--- papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/LogServiceTracker.java (rev 0)
+++ papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/LogServiceTracker.java 2010-02-19 19:28:25 UTC (rev 244)
@@ -0,0 +1,66 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * Licensed 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.papoose.event.util;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class LogServiceTracker extends ServiceTracker implements LogService
+{
+ public LogServiceTracker(BundleContext context)
+ {
+ super(context, LogService.class.getName(), null);
+ }
+
+ public void log(int level, String message)
+ {
+ for (LogService service : (LogService[]) getServices())
+ {
+ service.log(level, message);
+ }
+ }
+
+ public void log(int level, String message, Throwable exception)
+ {
+ for (LogService service : (LogService[]) getServices())
+ {
+ service.log(level, message, exception);
+ }
+ }
+
+ public void log(ServiceReference sr, int level, String message)
+ {
+ for (LogService service : (LogService[]) getServices())
+ {
+ service.log(sr, level, message);
+ }
+ }
+
+ public void log(ServiceReference sr, int level, String message, Throwable exception)
+ {
+ for (LogService service : (LogService[]) getServices())
+ {
+ service.log(sr, level, message, exception);
+ }
+ }
+}
Property changes on: papoose-cmpn/trunk/event/src/main/java/org/papoose/event/util/LogServiceTracker.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|