Repository: aries-jax-rs-whiteboard Updated Branches: refs/heads/master 39c19a133 -> 62ec3b4af
Source formatting Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo Commit: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/6541cc07 Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/6541cc07 Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/6541cc07 Branch: refs/heads/master Commit: 6541cc07bbc45c96e291090516d8ac297a4f33a9 Parents: 39c19a1 Author: Carlos Sierra <[email protected]> Authored: Tue Nov 29 17:26:53 2016 +0100 Committer: Carlos Sierra <[email protected]> Committed: Tue Nov 29 17:26:53 2016 +0100 ---------------------------------------------------------------------- jax-rs.example-run/pom.xml | 128 ++++++------ .../aries/jax/rs/example/ExampleAddon.java | 31 ++- .../jax/rs/example/ExampleApplication.java | 27 ++- .../aries/jax/rs/example/ExampleFilter.java | 23 +- jax-rs.itests-run/pom.xml | 126 +++++------ jax-rs.itests/pom.xml | 48 ++--- jax-rs.itests/src/main/java/test/JaxrsTest.java | 52 ++--- .../src/main/java/test/types/TestAddon.java | 22 +- .../main/java/test/types/TestApplication.java | 20 +- .../src/main/java/test/types/TestFilter.java | 18 +- jax-rs.whiteboard/pom.xml | 4 +- .../activator/CXFJaxRsBundleActivator.java | 83 ++++---- .../activator/ServicesRegistrator.java | 209 +++++++++---------- .../AddonsServiceTrackerCustomizer.java | 117 +++++------ .../ApplicationServiceTrackerCustomizer.java | 147 +++++++------ .../internal/BusServiceTrackerCustomizer.java | 127 ++++++----- .../internal/CXFJaxRsServiceRegistrator.java | 167 ++++++++------- ...AndInterceptorsServiceTrackerCustomizer.java | 149 +++++++------ .../ServicesServiceTrackerCustomizer.java | 101 +++++---- .../SingletonServiceTrackerCustomizer.java | 193 +++++++++-------- 20 files changed, 878 insertions(+), 914 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.example-run/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.example-run/pom.xml b/jax-rs.example-run/pom.xml index 616f3c9..1fe66a1 100644 --- a/jax-rs.example-run/pom.xml +++ b/jax-rs.example-run/pom.xml @@ -16,33 +16,33 @@ under the License. --> <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/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.aries.jax.rs</groupId> - <artifactId>org.apache.aries.jax.rs</artifactId> - <version>0.0.1-SNAPSHOT</version> - </parent> + <parent> + <groupId>org.apache.aries.jax.rs</groupId> + <artifactId>org.apache.aries.jax.rs</artifactId> + <version>0.0.1-SNAPSHOT</version> + </parent> - <artifactId>org.apache.aries.jax.rs.example-run</artifactId> - <description>Apache Aries JAX-RS Example Run Configuration</description> - <name>Apache Aries JAX-RS Example Run Configuration</name> - <packaging>pom</packaging> + <artifactId>org.apache.aries.jax.rs.example-run</artifactId> + <description>Apache Aries JAX-RS Example Run Configuration</description> + <name>Apache Aries JAX-RS Example Run Configuration</name> + <packaging>pom</packaging> - <build> - <plugins> - <plugin> - <groupId>biz.aQute.bnd</groupId> - <artifactId>bnd-export-maven-plugin</artifactId> - <version>3.4.0-SNAPSHOT</version> - <configuration> - <failOnChanges>false</failOnChanges> - <resolve>false</resolve> - <bndruns> - <bndrun>example.bndrun</bndrun> - </bndruns> - <targetDir>.</targetDir> + <build> + <plugins> + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-export-maven-plugin</artifactId> + <version>3.4.0-SNAPSHOT</version> + <configuration> + <failOnChanges>false</failOnChanges> + <resolve>false</resolve> + <bndruns> + <bndrun>example.bndrun</bndrun> + </bndruns> + <targetDir>.</targetDir> </configuration> <executions> <execution> @@ -51,44 +51,44 @@ </goals> </execution> </executions> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>org.apache.aries.jax.rs</groupId> - <artifactId>org.apache.aries.jax.rs.example</artifactId> - <version>0.0.1-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.aries.jax.rs</groupId> - <artifactId>org.apache.aries.jax.rs.log4j-configuration</artifactId> - <version>0.0.1-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.aries.jax.rs</groupId> - <artifactId>org.apache.aries.jax.rs.whiteboard</artifactId> - <version>0.0.1-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.http.jetty</artifactId> - <version>3.4.0</version> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.gogo.command</artifactId> - <version>1.0.0</version> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.gogo.jline</artifactId> - <version>1.0.0</version> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>osgi.enroute.pom.distro</artifactId> - <version>2.0.0</version> - </dependency> - </dependencies> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.apache.aries.jax.rs</groupId> + <artifactId>org.apache.aries.jax.rs.example</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.aries.jax.rs</groupId> + <artifactId>org.apache.aries.jax.rs.log4j-configuration</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.aries.jax.rs</groupId> + <artifactId>org.apache.aries.jax.rs.whiteboard</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.http.jetty</artifactId> + <version>3.4.0</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.gogo.command</artifactId> + <version>1.0.0</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.gogo.jline</artifactId> + <version>1.0.0</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.enroute.pom.distro</artifactId> + <version>2.0.0</version> + </dependency> + </dependencies> </project> http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleAddon.java ---------------------------------------------------------------------- diff --git a/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleAddon.java b/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleAddon.java index 8384877..0be9571 100644 --- a/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleAddon.java +++ b/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleAddon.java @@ -26,28 +26,25 @@ import javax.ws.rs.PathParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.UriInfo; -/** - * @author Carlos Sierra Andrés - */ @Component( - immediate = true, - property = "osgi.jaxrs.resource.base=/examples/example-addon", - service = ExampleAddon.class + immediate = true, + property = "osgi.jaxrs.resource.base=/examples/example-addon", + service = ExampleAddon.class ) public class ExampleAddon { - @GET - @Path("/{name}") - public String sayHello(@PathParam("name") String name) { - return "Hello " + name; - } + @GET + @Path("/{name}") + public String sayHello(@PathParam("name") String name) { + return "Hello " + name; + } - @PostConstruct - public void init() { - System.out.println("URIINFO: " + _uriInfo); - } + @PostConstruct + public void init() { + System.out.println("URIINFO: " + _uriInfo); + } - @Context - UriInfo _uriInfo; + @Context + UriInfo _uriInfo; } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleApplication.java ---------------------------------------------------------------------- diff --git a/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleApplication.java b/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleApplication.java index c1de37b..6148beb 100644 --- a/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleApplication.java +++ b/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleApplication.java @@ -25,25 +25,22 @@ import javax.ws.rs.core.Application; import java.util.Collections; import java.util.Set; -/** - * @author Carlos Sierra Andrés - */ @Component( - immediate = true, - property = "osgi.jaxrs.application.base=/example-application", - service = Application.class + immediate = true, + property = "osgi.jaxrs.application.base=/example-application", + service = Application.class ) public class ExampleApplication extends Application { - @Override - public Set<Object> getSingletons() { - return Collections.<Object>singleton(this); - } + @Override + public Set<Object> getSingletons() { + return Collections.<Object>singleton(this); + } - @GET - @Produces("text/plain") - public String sayHello() { - return "Hello world"; - } + @GET + @Produces("text/plain") + public String sayHello() { + return "Hello world"; + } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleFilter.java ---------------------------------------------------------------------- diff --git a/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleFilter.java b/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleFilter.java index e741ef5..4486de5 100644 --- a/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleFilter.java +++ b/jax-rs.example/src/main/java/org/apache/aries/jax/rs/example/ExampleFilter.java @@ -24,24 +24,21 @@ import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.ext.Provider; import java.io.IOException; -/** - * @author Carlos Sierra Andrés - */ @Component( - immediate = true, - property = { - "jaxrs.application.select=(component.name=ExampleApplication)", - "osgi.jaxrs.filter.base=/examples" - } + immediate = true, + property = { + "jaxrs.application.select=(component.name=ExampleApplication)", + "osgi.jaxrs.filter.base=/examples" + } ) @Provider public class ExampleFilter implements ContainerRequestFilter { - @Override - public void filter(ContainerRequestContext requestContext) - throws IOException { + @Override + public void filter(ContainerRequestContext requestContext) + throws IOException { - System.out.println("FILTERED!"); - } + System.out.println("FILTERED!"); + } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.itests-run/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.itests-run/pom.xml b/jax-rs.itests-run/pom.xml index 868a1f0..09d6f48 100644 --- a/jax-rs.itests-run/pom.xml +++ b/jax-rs.itests-run/pom.xml @@ -16,72 +16,72 @@ under the License. --> <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/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> + 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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.aries.jax.rs</groupId> - <artifactId>org.apache.aries.jax.rs</artifactId> - <version>0.0.1-SNAPSHOT</version> - <relativePath>..</relativePath> - </parent> + <parent> + <groupId>org.apache.aries.jax.rs</groupId> + <artifactId>org.apache.aries.jax.rs</artifactId> + <version>0.0.1-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> - <artifactId>org.apache.aries.jax.rs.itests-run</artifactId> + <artifactId>org.apache.aries.jax.rs.itests-run</artifactId> <description>Apache Aries JAX-RS Integration Test Plan</description> <name>Apache Aries JAX-RS Integration Test Plan</name> - <packaging>pom</packaging> + <packaging>pom</packaging> - <build> - <plugins> - <plugin> - <groupId>biz.aQute.bnd</groupId> - <artifactId>bnd-testing-maven-plugin</artifactId> - <version>3.4.0-SNAPSHOT</version> - <configuration> - <failOnChanges>false</failOnChanges> - <resolve>false</resolve> - <bndruns> - <bndrun>itest.bndrun</bndrun> - </bndruns> - <targetDir>.</targetDir> - </configuration> - <executions> - <execution> - <goals> - <goal>testing</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>org.apache.aries.jax.rs</groupId> - <artifactId>org.apache.aries.jax.rs.itests</artifactId> - <version>0.0.1-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.aries.jax.rs</groupId> - <artifactId>org.apache.aries.jax.rs.log4j-configuration</artifactId> - <version>0.0.1-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.aries.jax.rs</groupId> - <artifactId>org.apache.aries.jax.rs.whiteboard</artifactId> - <version>0.0.1-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.http.jetty</artifactId> - <version>3.4.0</version> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>osgi.enroute.pom.distro</artifactId> - <version>2.0.0</version> - </dependency> - </dependencies> + <build> + <plugins> + <plugin> + <groupId>biz.aQute.bnd</groupId> + <artifactId>bnd-testing-maven-plugin</artifactId> + <version>3.4.0-SNAPSHOT</version> + <configuration> + <failOnChanges>false</failOnChanges> + <resolve>false</resolve> + <bndruns> + <bndrun>itest.bndrun</bndrun> + </bndruns> + <targetDir>.</targetDir> + </configuration> + <executions> + <execution> + <goals> + <goal>testing</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.apache.aries.jax.rs</groupId> + <artifactId>org.apache.aries.jax.rs.itests</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.aries.jax.rs</groupId> + <artifactId>org.apache.aries.jax.rs.log4j-configuration</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.aries.jax.rs</groupId> + <artifactId>org.apache.aries.jax.rs.whiteboard</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.http.jetty</artifactId> + <version>3.4.0</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.enroute.pom.distro</artifactId> + <version>2.0.0</version> + </dependency> + </dependencies> </project> http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.itests/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.itests/pom.xml b/jax-rs.itests/pom.xml index 3bd6936..02a468f 100644 --- a/jax-rs.itests/pom.xml +++ b/jax-rs.itests/pom.xml @@ -16,37 +16,37 @@ under the License. --> <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/xsd/maven-4.0.0.xsd"> + 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/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.aries.jax.rs</groupId> - <artifactId>org.apache.aries.jax.rs</artifactId> - <version>0.0.1-SNAPSHOT</version> - </parent> + <parent> + <groupId>org.apache.aries.jax.rs</groupId> + <artifactId>org.apache.aries.jax.rs</artifactId> + <version>0.0.1-SNAPSHOT</version> + </parent> - <artifactId>org.apache.aries.jax.rs.itests</artifactId> - <description>Apache Aries JAX-RS Integration Tests</description> - <name>Apache Aries JAX-RS Integration Tests</name> + <artifactId>org.apache.aries.jax.rs.itests</artifactId> + <description>Apache Aries JAX-RS Integration Tests</description> + <name>Apache Aries JAX-RS Integration Tests</name> - <dependencies> + <dependencies> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>2.0.1</version> </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <version>5.0.0</version> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>osgi.enroute.junit.wrapper</artifactId> - <version>4.12.0</version> - </dependency> - </dependencies> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <version>5.0.0</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.enroute.junit.wrapper</artifactId> + <version>4.12.0</version> + </dependency> + </dependencies> </project> http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.itests/src/main/java/test/JaxrsTest.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/JaxrsTest.java b/jax-rs.itests/src/main/java/test/JaxrsTest.java index 4e1fbce..0570e17 100644 --- a/jax-rs.itests/src/main/java/test/JaxrsTest.java +++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java @@ -31,40 +31,40 @@ import test.types.TestAddon; public class JaxrsTest extends TestCase { - static BundleContext bundleContext = FrameworkUtil.getBundle( - JaxrsTest.class).getBundleContext(); + static BundleContext bundleContext = FrameworkUtil.getBundle( + JaxrsTest.class).getBundleContext(); - public void testEndPoint() throws Exception { - ServiceRegistration<?> serviceRegistration = null; + public void testEndPoint() throws Exception { + ServiceRegistration<?> serviceRegistration = null; - try { - TestAddon testAddon = new TestAddon(); + try { + TestAddon testAddon = new TestAddon(); - Dictionary<String, Object> properties = new Hashtable<>(); - properties.put("osgi.jaxrs.resource.base", "/test-addon"); + Dictionary<String, Object> properties = new Hashtable<>(); + properties.put("osgi.jaxrs.resource.base", "/test-addon"); - serviceRegistration = bundleContext.registerService( - Object.class, testAddon, properties); + serviceRegistration = bundleContext.registerService( + Object.class, testAddon, properties); - // TODO this availability should be checked through a jaxrs runtime service + // TODO this availability should be checked through a jaxrs runtime service - Filter filter = bundleContext.createFilter("(CXF_ENDPOINT_ADDRESS=/test-addon)"); + Filter filter = bundleContext.createFilter("(CXF_ENDPOINT_ADDRESS=/test-addon)"); - ServiceTracker<?, ?> st = new ServiceTracker<>(bundleContext, filter, null); + ServiceTracker<?, ?> st = new ServiceTracker<>(bundleContext, filter, null); - st.open(); + st.open(); - if (st.waitForService(5000) == null) { - fail(); - } + if (st.waitForService(5000) == null) { + fail(); + } - // TODO add http client to connect to the endpoint - } - finally { - if (serviceRegistration != null) { - serviceRegistration.unregister(); - } - } - } + // TODO add http client to connect to the endpoint + } + finally { + if (serviceRegistration != null) { + serviceRegistration.unregister(); + } + } + } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.itests/src/main/java/test/types/TestAddon.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/types/TestAddon.java b/jax-rs.itests/src/main/java/test/types/TestAddon.java index 3378140..0811b8b 100644 --- a/jax-rs.itests/src/main/java/test/types/TestAddon.java +++ b/jax-rs.itests/src/main/java/test/types/TestAddon.java @@ -27,18 +27,18 @@ import javax.ws.rs.core.UriInfo; //property = "osgi.jaxrs.resource.base=/test-addon", public class TestAddon { - @GET - @Path("/{name}") - public String sayHello(@PathParam("name") String name) { - return "Hello " + name; - } + @GET + @Path("/{name}") + public String sayHello(@PathParam("name") String name) { + return "Hello " + name; + } - @PostConstruct - public void init() { - System.out.println("URIINFO: " + _uriInfo); - } + @PostConstruct + public void init() { + System.out.println("URIINFO: " + _uriInfo); + } - @Context - UriInfo _uriInfo; + @Context + UriInfo _uriInfo; } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.itests/src/main/java/test/types/TestApplication.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/types/TestApplication.java b/jax-rs.itests/src/main/java/test/types/TestApplication.java index 5c8c762..a665c4d 100644 --- a/jax-rs.itests/src/main/java/test/types/TestApplication.java +++ b/jax-rs.itests/src/main/java/test/types/TestApplication.java @@ -24,18 +24,18 @@ import javax.ws.rs.GET; import javax.ws.rs.Produces; import javax.ws.rs.core.Application; -// property = "osgi.jaxrs.application.base=/example-application", +// property = "osgi.jaxrs.application.base=/example-application", public class TestApplication extends Application { - @Override - public Set<Object> getSingletons() { - return Collections.<Object>singleton(this); - } + @Override + public Set<Object> getSingletons() { + return Collections.<Object>singleton(this); + } - @GET - @Produces("text/plain") - public String sayHello() { - return "Hello world"; - } + @GET + @Produces("text/plain") + public String sayHello() { + return "Hello world"; + } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.itests/src/main/java/test/types/TestFilter.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/types/TestFilter.java b/jax-rs.itests/src/main/java/test/types/TestFilter.java index dd8e1e9..e5893a1 100644 --- a/jax-rs.itests/src/main/java/test/types/TestFilter.java +++ b/jax-rs.itests/src/main/java/test/types/TestFilter.java @@ -23,18 +23,18 @@ import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.ext.Provider; -// property = { -// "jaxrs.application.select=(component.name=org.apache.aries.jax.rs.example.ExampleApplication)", -// "osgi.jaxrs.filter.base=/examples" -// } +// property = { +// "jaxrs.application.select=(component.name=org.apache.aries.jax.rs.example.ExampleApplication)", +// "osgi.jaxrs.filter.base=/examples" +// } @Provider public class TestFilter implements ContainerRequestFilter { - @Override - public void filter(ContainerRequestContext requestContext) - throws IOException { + @Override + public void filter(ContainerRequestContext requestContext) + throws IOException { - System.out.println("FILTERED!"); - } + System.out.println("FILTERED!"); + } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.whiteboard/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/pom.xml b/jax-rs.whiteboard/pom.xml index 13ec2f0..0456b69 100644 --- a/jax-rs.whiteboard/pom.xml +++ b/jax-rs.whiteboard/pom.xml @@ -87,12 +87,12 @@ <artifactId>org.osgi.compendium</artifactId> <version>5.0.0</version> </dependency> - <dependency> + <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.apache.felix.http.api</artifactId> <version>3.0.0</version> </dependency> - <dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.2</version> http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java index 9bff510..6c98993 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java @@ -34,70 +34,67 @@ import org.osgi.util.tracker.ServiceTracker; import org.apache.aries.jax.rs.whiteboard.internal.BusServiceTrackerCustomizer; import org.apache.aries.jax.rs.whiteboard.internal.ServicesServiceTrackerCustomizer; -/** - * @author Carlos Sierra Andrés - */ public class CXFJaxRsBundleActivator implements BundleActivator { - private ServiceTracker<?, ?> _busServiceTracker; - private ServiceTracker<?, ?> _singletonsTracker; - private ServicesRegistrator _servicesRegistrator; + private ServiceTracker<?, ?> _busServiceTracker; + private ServiceTracker<?, ?> _singletonsTracker; + private ServicesRegistrator _servicesRegistrator; - @Override - public void start(BundleContext bundleContext) throws Exception { - Thread thread = Thread.currentThread(); + @Override + public void start(BundleContext bundleContext) throws Exception { + Thread thread = Thread.currentThread(); - ClassLoader contextClassLoader = thread.getContextClassLoader(); + ClassLoader contextClassLoader = thread.getContextClassLoader(); - Bundle bundle = bundleContext.getBundle(); + Bundle bundle = bundleContext.getBundle(); - BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); + BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); - thread.setContextClassLoader(bundleWiring.getClassLoader()); + thread.setContextClassLoader(bundleWiring.getClassLoader()); - try { + try { - // Initialize instance so it is never looked up again + // Initialize instance so it is never looked up again - RuntimeDelegate.getInstance(); - } - finally { - thread.setContextClassLoader(contextClassLoader); - } + RuntimeDelegate.getInstance(); + } + finally { + thread.setContextClassLoader(contextClassLoader); + } - Dictionary<String, Object> runtimeProperties = new Hashtable<>(); + Dictionary<String, Object> runtimeProperties = new Hashtable<>(); - runtimeProperties.put("endpoints", new ArrayList<String>()); + runtimeProperties.put("endpoints", new ArrayList<String>()); - // TODO make the context path of the JAX-RS Whiteboard configurable. + // TODO make the context path of the JAX-RS Whiteboard configurable. - _servicesRegistrator = new ServicesRegistrator(bundleContext); + _servicesRegistrator = new ServicesRegistrator(bundleContext); - _servicesRegistrator.start(); + _servicesRegistrator.start(); - _busServiceTracker = new ServiceTracker<>( - bundleContext, Bus.class, - new BusServiceTrackerCustomizer(bundleContext)); + _busServiceTracker = new ServiceTracker<>( + bundleContext, Bus.class, + new BusServiceTrackerCustomizer(bundleContext)); - _busServiceTracker.open(); + _busServiceTracker.open(); - Filter filter = bundleContext.createFilter( - "(jaxrs.application.select=*)"); + Filter filter = bundleContext.createFilter( + "(jaxrs.application.select=*)"); - _singletonsTracker = new ServiceTracker<>( - bundleContext, filter, - new ServicesServiceTrackerCustomizer(bundleContext)); + _singletonsTracker = new ServiceTracker<>( + bundleContext, filter, + new ServicesServiceTrackerCustomizer(bundleContext)); - _singletonsTracker.open(); - } + _singletonsTracker.open(); + } - @Override - public void stop(BundleContext context) throws Exception { - _busServiceTracker.close(); + @Override + public void stop(BundleContext context) throws Exception { + _busServiceTracker.close(); - _singletonsTracker.close(); + _singletonsTracker.close(); - _servicesRegistrator.stop(); - } + _servicesRegistrator.stop(); + } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/ServicesRegistrator.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/ServicesRegistrator.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/ServicesRegistrator.java index 1aeee29..1061ff5 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/ServicesRegistrator.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/ServicesRegistrator.java @@ -37,111 +37,108 @@ import javax.servlet.Servlet; import java.util.Dictionary; import java.util.Hashtable; -/** - * @author Carlos Sierra Andrés - */ -public class ServicesRegistrator - implements ServiceTrackerCustomizer<ServletContextHelper, Object> { - - public ServicesRegistrator(BundleContext bundleContext) { - _bundleContext = bundleContext; - } - - @Override - public Object addingService( - ServiceReference<ServletContextHelper> reference) { - - String contextPath = (String)reference.getProperty( - HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH); - - CXFNonSpringServlet cxfNonSpringServlet = new CXFNonSpringServlet(); - - CXFBusFactory cxfBusFactory = - (CXFBusFactory) CXFBusFactory.newInstance( - CXFBusFactory.class.getName()); - - Bus bus = cxfBusFactory.createBus(); - - Dictionary<String, Object> properties = new Hashtable<>(); - - properties.put( - HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, - "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" + - HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME + ")"); - properties.put( - HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/*"); - properties.put(Constants.SERVICE_RANKING, -1); - - cxfNonSpringServlet.setBus(bus); - - _servletServiceRegistration = _bundleContext.registerService( - Servlet.class, cxfNonSpringServlet, properties); - - properties = new Hashtable<>(); - - properties.put( - HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, - contextPath); - - _busServiceRegistration = _bundleContext.registerService( - Bus.class, bus, properties); - - return new Object(); - } - - @Override - public void modifiedService( - ServiceReference<ServletContextHelper> reference, Object object) { - } - - @Override - public void removedService( - ServiceReference<ServletContextHelper> reference, Object object) { - - try { - _busServiceRegistration.unregister(); - } - catch (Exception e) { - if (_logger.isWarnEnabled()) { - _logger.warn( - "Unable to unregister CXF bus service registration " + - _busServiceRegistration); - } - } - - try { - _servletServiceRegistration.unregister(); - } - catch (Exception e) { - if (_logger.isWarnEnabled()) { - _logger.warn( - "Unable to unregister servlet service registration " + - _servletServiceRegistration); - } - } - } - - public void start() throws InvalidSyntaxException { - Filter filter = _bundleContext.createFilter( - "(&(objectClass=" + ServletContextHelper.class.getName() + ")(" + - HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" + - HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME +"))"); - - _serviceTracker = new ServiceTracker<>(_bundleContext, filter, this); - - _serviceTracker.open(); - } - - public void stop() { - _serviceTracker.close(); - } - - private static final Logger _logger = LoggerFactory.getLogger( - ServicesRegistrator.class); - - private final BundleContext _bundleContext; - private ServiceRegistration<Bus> _busServiceRegistration; - private ServiceTracker<ServletContextHelper, Object> _serviceTracker; - private ServiceRegistration<Servlet> _servletServiceRegistration; +public class ServicesRegistrator + implements ServiceTrackerCustomizer<ServletContextHelper, Object> { + + public ServicesRegistrator(BundleContext bundleContext) { + _bundleContext = bundleContext; + } + + @Override + public Object addingService( + ServiceReference<ServletContextHelper> reference) { + + String contextPath = (String)reference.getProperty( + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH); + + CXFNonSpringServlet cxfNonSpringServlet = new CXFNonSpringServlet(); + + CXFBusFactory cxfBusFactory = + (CXFBusFactory) CXFBusFactory.newInstance( + CXFBusFactory.class.getName()); + + Bus bus = cxfBusFactory.createBus(); + + Dictionary<String, Object> properties = new Hashtable<>(); + + properties.put( + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, + "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" + + HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME + ")"); + properties.put( + HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/*"); + properties.put(Constants.SERVICE_RANKING, -1); + + cxfNonSpringServlet.setBus(bus); + + _servletServiceRegistration = _bundleContext.registerService( + Servlet.class, cxfNonSpringServlet, properties); + + properties = new Hashtable<>(); + + properties.put( + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, + contextPath); + + _busServiceRegistration = _bundleContext.registerService( + Bus.class, bus, properties); + + return new Object(); + } + + @Override + public void modifiedService( + ServiceReference<ServletContextHelper> reference, Object object) { + } + + @Override + public void removedService( + ServiceReference<ServletContextHelper> reference, Object object) { + + try { + _busServiceRegistration.unregister(); + } + catch (Exception e) { + if (_logger.isWarnEnabled()) { + _logger.warn( + "Unable to unregister CXF bus service registration " + + _busServiceRegistration); + } + } + + try { + _servletServiceRegistration.unregister(); + } + catch (Exception e) { + if (_logger.isWarnEnabled()) { + _logger.warn( + "Unable to unregister servlet service registration " + + _servletServiceRegistration); + } + } + } + + public void start() throws InvalidSyntaxException { + Filter filter = _bundleContext.createFilter( + "(&(objectClass=" + ServletContextHelper.class.getName() + ")(" + + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" + + HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME +"))"); + + _serviceTracker = new ServiceTracker<>(_bundleContext, filter, this); + + _serviceTracker.open(); + } + + public void stop() { + _serviceTracker.close(); + } + + private static final Logger _logger = LoggerFactory.getLogger( + ServicesRegistrator.class); + + private final BundleContext _bundleContext; + private ServiceRegistration<Bus> _busServiceRegistration; + private ServiceTracker<ServletContextHelper, Object> _serviceTracker; + private ServiceRegistration<Servlet> _servletServiceRegistration; } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AddonsServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AddonsServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AddonsServiceTrackerCustomizer.java index 4e7a60a..ddf4cb2 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AddonsServiceTrackerCustomizer.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AddonsServiceTrackerCustomizer.java @@ -23,85 +23,82 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer; import javax.ws.rs.ext.Provider; -/** - * @author Carlos Sierra Andrés - */ public class AddonsServiceTrackerCustomizer - implements - ServiceTrackerCustomizer<CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> { + implements + ServiceTrackerCustomizer<CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> { - private final BundleContext _bundleContext; - private final ClassLoader _classLoader; - private final Class<?> _serviceClass; - private final Object _service; + private final BundleContext _bundleContext; + private final ClassLoader _classLoader; + private final Class<?> _serviceClass; + private final Object _service; - public AddonsServiceTrackerCustomizer( - BundleContext bundleContext, ClassLoader classLoader, - Object service) { + public AddonsServiceTrackerCustomizer( + BundleContext bundleContext, ClassLoader classLoader, + Object service) { - _bundleContext = bundleContext; - _classLoader = classLoader; - _service = service; + _bundleContext = bundleContext; + _classLoader = classLoader; + _service = service; - _serviceClass = service.getClass(); - } + _serviceClass = service.getClass(); + } - @Override - public CXFJaxRsServiceRegistrator addingService( - ServiceReference<CXFJaxRsServiceRegistrator> reference) { + @Override + public CXFJaxRsServiceRegistrator addingService( + ServiceReference<CXFJaxRsServiceRegistrator> reference) { - Thread thread = Thread.currentThread(); + Thread thread = Thread.currentThread(); - ClassLoader contextClassLoader = - thread.getContextClassLoader(); + ClassLoader contextClassLoader = + thread.getContextClassLoader(); - CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = - _bundleContext.getService(reference); + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = + _bundleContext.getService(reference); - try { - thread.setContextClassLoader(_classLoader); + try { + thread.setContextClassLoader(_classLoader); - if (_serviceClass.isAnnotationPresent(Provider.class)) { - cxfJaxRsServiceRegistrator.addProvider(_service); - } else { - cxfJaxRsServiceRegistrator.addService(_service); - } + if (_serviceClass.isAnnotationPresent(Provider.class)) { + cxfJaxRsServiceRegistrator.addProvider(_service); + } else { + cxfJaxRsServiceRegistrator.addService(_service); + } - return cxfJaxRsServiceRegistrator; - } - catch (Exception e) { - _bundleContext.ungetService(reference); + return cxfJaxRsServiceRegistrator; + } + catch (Exception e) { + _bundleContext.ungetService(reference); - throw e; - } - finally { - thread.setContextClassLoader(contextClassLoader); - } - } + throw e; + } + finally { + thread.setContextClassLoader(contextClassLoader); + } + } - @Override - public void modifiedService( - ServiceReference<CXFJaxRsServiceRegistrator> reference, - CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator) { + @Override + public void modifiedService( + ServiceReference<CXFJaxRsServiceRegistrator> reference, + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator) { - removedService(reference, cxfJaxRsServiceRegistrator); + removedService(reference, cxfJaxRsServiceRegistrator); - addingService(reference); - } + addingService(reference); + } - @Override - public void removedService( - ServiceReference<CXFJaxRsServiceRegistrator> reference, - CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator) { + @Override + public void removedService( + ServiceReference<CXFJaxRsServiceRegistrator> reference, + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator) { - if (_serviceClass.isAnnotationPresent(Provider.class)) { - cxfJaxRsServiceRegistrator.removeProvider(_service); - } else { - cxfJaxRsServiceRegistrator.removeService(_service); - } + if (_serviceClass.isAnnotationPresent(Provider.class)) { + cxfJaxRsServiceRegistrator.removeProvider(_service); + } else { + cxfJaxRsServiceRegistrator.removeService(_service); + } - _bundleContext.ungetService(reference); - } + _bundleContext.ungetService(reference); + } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ApplicationServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ApplicationServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ApplicationServiceTrackerCustomizer.java index 8f7acc0..01edbbc 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ApplicationServiceTrackerCustomizer.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ApplicationServiceTrackerCustomizer.java @@ -29,107 +29,104 @@ import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; import org.osgi.util.tracker.ServiceTrackerCustomizer; -/** - * @author Carlos Sierra Andrés - */ class ApplicationServiceTrackerCustomizer - implements ServiceTrackerCustomizer - <Application, ApplicationServiceTrackerCustomizer.Tracked> { + implements ServiceTrackerCustomizer + <Application, ApplicationServiceTrackerCustomizer.Tracked> { - private BundleContext _bundleContext; - private Bus _bus; + private BundleContext _bundleContext; + private Bus _bus; - public ApplicationServiceTrackerCustomizer( - BundleContext bundleContext, Bus bus) { + public ApplicationServiceTrackerCustomizer( + BundleContext bundleContext, Bus bus) { - _bundleContext = bundleContext; - _bus = bus; - } + _bundleContext = bundleContext; + _bus = bus; + } - @Override - public Tracked addingService( - ServiceReference<Application> serviceReference) { + @Override + public Tracked addingService( + ServiceReference<Application> serviceReference) { - Application application = _bundleContext.getService( - serviceReference); + Application application = _bundleContext.getService( + serviceReference); - try { - String[] propertyKeys = serviceReference.getPropertyKeys(); + try { + String[] propertyKeys = serviceReference.getPropertyKeys(); - Map<String, Object> properties = new HashMap<>( - propertyKeys.length); + Map<String, Object> properties = new HashMap<>( + propertyKeys.length); - for (String propertyKey : propertyKeys) { - properties.put( - propertyKey, serviceReference.getProperty(propertyKey)); - } + for (String propertyKey : propertyKeys) { + properties.put( + propertyKey, serviceReference.getProperty(propertyKey)); + } - properties.put( - "CXF_ENDPOINT_ADDRESS", - serviceReference.getProperty("osgi.jaxrs.application.base"). - toString()); + properties.put( + "CXF_ENDPOINT_ADDRESS", + serviceReference.getProperty("osgi.jaxrs.application.base"). + toString()); - CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = - new CXFJaxRsServiceRegistrator(_bus, application, properties); + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = + new CXFJaxRsServiceRegistrator(_bus, application, properties); - ServiceRegistration<CXFJaxRsServiceRegistrator> - cxfJaxRsServiceRegistratorRegistration = - _bundleContext.registerService( - CXFJaxRsServiceRegistrator.class, - cxfJaxRsServiceRegistrator, - new Hashtable<>(properties)); + ServiceRegistration<CXFJaxRsServiceRegistrator> + cxfJaxRsServiceRegistratorRegistration = + _bundleContext.registerService( + CXFJaxRsServiceRegistrator.class, + cxfJaxRsServiceRegistrator, + new Hashtable<>(properties)); - return new Tracked( - cxfJaxRsServiceRegistrator, application, - cxfJaxRsServiceRegistratorRegistration); - } - catch (Throwable e) { - _bundleContext.ungetService(serviceReference); + return new Tracked( + cxfJaxRsServiceRegistrator, application, + cxfJaxRsServiceRegistratorRegistration); + } + catch (Throwable e) { + _bundleContext.ungetService(serviceReference); - throw e; - } - } + throw e; + } + } - @Override - public void modifiedService( - ServiceReference<Application> serviceReference, Tracked tracked) { + @Override + public void modifiedService( + ServiceReference<Application> serviceReference, Tracked tracked) { - removedService(serviceReference, tracked); + removedService(serviceReference, tracked); - addingService(serviceReference); - } + addingService(serviceReference); + } - @Override - public void removedService( - ServiceReference<Application> reference, Tracked tracked) { + @Override + public void removedService( + ServiceReference<Application> reference, Tracked tracked) { - _bundleContext.ungetService(reference); + _bundleContext.ungetService(reference); - tracked._cxfJaxRsServiceRegistrator.close(); + tracked._cxfJaxRsServiceRegistrator.close(); - tracked._cxfJaxRsServiceRegistratorServiceRegistration.unregister(); - } + tracked._cxfJaxRsServiceRegistratorServiceRegistration.unregister(); + } - public static class Tracked { + public static class Tracked { - private final CXFJaxRsServiceRegistrator _cxfJaxRsServiceRegistrator; - private final Application _application; - private final ServiceRegistration<CXFJaxRsServiceRegistrator> - _cxfJaxRsServiceRegistratorServiceRegistration; + private final CXFJaxRsServiceRegistrator _cxfJaxRsServiceRegistrator; + private final Application _application; + private final ServiceRegistration<CXFJaxRsServiceRegistrator> + _cxfJaxRsServiceRegistratorServiceRegistration; - public Tracked( - CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator, - Application application, - ServiceRegistration<CXFJaxRsServiceRegistrator> - cxfJaxRsServiceRegistratorServiceRegistration) { + public Tracked( + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator, + Application application, + ServiceRegistration<CXFJaxRsServiceRegistrator> + cxfJaxRsServiceRegistratorServiceRegistration) { - _cxfJaxRsServiceRegistrator = cxfJaxRsServiceRegistrator; - _application = application; - _cxfJaxRsServiceRegistratorServiceRegistration = - cxfJaxRsServiceRegistratorServiceRegistration; - } + _cxfJaxRsServiceRegistrator = cxfJaxRsServiceRegistrator; + _application = application; + _cxfJaxRsServiceRegistratorServiceRegistration = + cxfJaxRsServiceRegistratorServiceRegistration; + } - } + } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/BusServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/BusServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/BusServiceTrackerCustomizer.java index 59d5323..2801146 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/BusServiceTrackerCustomizer.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/BusServiceTrackerCustomizer.java @@ -30,92 +30,89 @@ import org.osgi.framework.ServiceReference; import org.osgi.util.tracker.ServiceTracker; import org.osgi.util.tracker.ServiceTrackerCustomizer; -/** - * @author Carlos Sierra Andrés - */ public class BusServiceTrackerCustomizer - implements ServiceTrackerCustomizer<Bus, Collection<ServiceTracker<?, ?>>> { + implements ServiceTrackerCustomizer<Bus, Collection<ServiceTracker<?, ?>>> { - private BundleContext _bundleContext; + private BundleContext _bundleContext; - public BusServiceTrackerCustomizer(BundleContext bundleContext) { - _bundleContext = bundleContext; - } + public BusServiceTrackerCustomizer(BundleContext bundleContext) { + _bundleContext = bundleContext; + } - @Override - public Collection<ServiceTracker<?, ?>> - addingService(ServiceReference<Bus> serviceReference) { + @Override + public Collection<ServiceTracker<?, ?>> + addingService(ServiceReference<Bus> serviceReference) { - Bus bus = _bundleContext.getService(serviceReference); + Bus bus = _bundleContext.getService(serviceReference); - try { - ServiceTracker<Application,?> applicationTracker = - new ServiceTracker<>(_bundleContext, getApplicationFilter(), - new ApplicationServiceTrackerCustomizer( - _bundleContext, bus)); + try { + ServiceTracker<Application,?> applicationTracker = + new ServiceTracker<>(_bundleContext, getApplicationFilter(), + new ApplicationServiceTrackerCustomizer( + _bundleContext, bus)); - applicationTracker.open(); + applicationTracker.open(); - ServiceTracker<Object, ?> singletonsServiceTracker = - new ServiceTracker<>(_bundleContext, getSingletonsFilter(), - new SingletonServiceTrackerCustomizer(_bundleContext, bus)); + ServiceTracker<Object, ?> singletonsServiceTracker = + new ServiceTracker<>(_bundleContext, getSingletonsFilter(), + new SingletonServiceTrackerCustomizer(_bundleContext, bus)); - singletonsServiceTracker.open(); + singletonsServiceTracker.open(); - ServiceTracker<Object, ?> filtersAndInterceptorsServiceTracker = - new ServiceTracker<>(_bundleContext, getFiltersFilter(), - new FiltersAndInterceptorsServiceTrackerCustomizer( - _bundleContext)); + ServiceTracker<Object, ?> filtersAndInterceptorsServiceTracker = + new ServiceTracker<>(_bundleContext, getFiltersFilter(), + new FiltersAndInterceptorsServiceTrackerCustomizer( + _bundleContext)); - filtersAndInterceptorsServiceTracker.open(); + filtersAndInterceptorsServiceTracker.open(); - return Arrays.asList(applicationTracker, singletonsServiceTracker, - filtersAndInterceptorsServiceTracker); - } - catch (InvalidSyntaxException ise) { - throw new RuntimeException(ise); - } - catch (Exception e) { - _bundleContext.ungetService(serviceReference); + return Arrays.asList(applicationTracker, singletonsServiceTracker, + filtersAndInterceptorsServiceTracker); + } + catch (InvalidSyntaxException ise) { + throw new RuntimeException(ise); + } + catch (Exception e) { + _bundleContext.ungetService(serviceReference); - throw e; - } - } + throw e; + } + } - private Filter getFiltersFilter() throws InvalidSyntaxException { - return _bundleContext.createFilter("(osgi.jaxrs.filter.base=*)"); - } + private Filter getFiltersFilter() throws InvalidSyntaxException { + return _bundleContext.createFilter("(osgi.jaxrs.filter.base=*)"); + } - private Filter getApplicationFilter() throws InvalidSyntaxException { - return _bundleContext.createFilter( - "(&(objectClass=" + Application.class.getName() + ")" + - "(osgi.jaxrs.application.base=*))"); - } + private Filter getApplicationFilter() throws InvalidSyntaxException { + return _bundleContext.createFilter( + "(&(objectClass=" + Application.class.getName() + ")" + + "(osgi.jaxrs.application.base=*))"); + } - private Filter getSingletonsFilter() throws InvalidSyntaxException { - return _bundleContext.createFilter("(osgi.jaxrs.resource.base=*)"); - } + private Filter getSingletonsFilter() throws InvalidSyntaxException { + return _bundleContext.createFilter("(osgi.jaxrs.resource.base=*)"); + } - @Override - public void modifiedService( - ServiceReference<Bus> reference, - Collection<ServiceTracker<?, ?>> serviceTrackers) { + @Override + public void modifiedService( + ServiceReference<Bus> reference, + Collection<ServiceTracker<?, ?>> serviceTrackers) { - removedService(reference, serviceTrackers); + removedService(reference, serviceTrackers); - addingService(reference); - } + addingService(reference); + } - @Override - public void removedService( - ServiceReference<Bus> serviceReference, - Collection<ServiceTracker<?, ?>> serviceTrackers) { + @Override + public void removedService( + ServiceReference<Bus> serviceReference, + Collection<ServiceTracker<?, ?>> serviceTrackers) { - _bundleContext.ungetService(serviceReference); + _bundleContext.ungetService(serviceReference); - for (ServiceTracker<?, ?> serviceTracker : serviceTrackers) { - serviceTracker.close(); - } - } + for (ServiceTracker<?, ?> serviceTracker : serviceTrackers) { + serviceTracker.close(); + } + } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java index 6cfc4d1..e6ab988 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java @@ -30,122 +30,119 @@ import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; import org.apache.cxf.jaxrs.provider.json.JSONProvider; -/** - * @author Carlos Sierra Andrés - */ public class CXFJaxRsServiceRegistrator { - public CXFJaxRsServiceRegistrator( - Bus bus, Application application, Map<String, Object> properties) { + public CXFJaxRsServiceRegistrator( + Bus bus, Application application, Map<String, Object> properties) { - _bus = bus; - _application = application; - _properties = properties; + _bus = bus; + _application = application; + _properties = properties; - rewire(); - } + rewire(); + } - public void close() { - if (_closed) { - return; - } + public void close() { + if (_closed) { + return; + } - if (_server != null) { - _server.destroy(); - } + if (_server != null) { + _server.destroy(); + } - _closed = true; - } + _closed = true; + } - public void addProvider(Object provider) { - if (_closed) { - return; - } + public void addProvider(Object provider) { + if (_closed) { + return; + } - _providers.add(provider); + _providers.add(provider); - rewire(); - } + rewire(); + } - public void addService(Object service) { - if (_closed) { - return; - } + public void addService(Object service) { + if (_closed) { + return; + } - _services.add(service); + _services.add(service); - rewire(); - } + rewire(); + } - public void removeProvider(Object provider) { - if (_closed) { - return; - } + public void removeProvider(Object provider) { + if (_closed) { + return; + } - _providers.remove(provider); + _providers.remove(provider); - rewire(); - } + rewire(); + } - public void removeService(Object service) { - if (_closed) { - return; - } + public void removeService(Object service) { + if (_closed) { + return; + } - _services.remove(service); + _services.remove(service); - rewire(); - } + rewire(); + } - protected synchronized void rewire() { - if (_server != null) { - _server.destroy(); - } + protected synchronized void rewire() { + if (_server != null) { + _server.destroy(); + } - RuntimeDelegate runtimeDelegate = RuntimeDelegate.getInstance(); + RuntimeDelegate runtimeDelegate = RuntimeDelegate.getInstance(); - JAXRSServerFactoryBean jaxRsServerFactoryBean = - runtimeDelegate.createEndpoint( - _application, JAXRSServerFactoryBean.class); + JAXRSServerFactoryBean jaxRsServerFactoryBean = + runtimeDelegate.createEndpoint( + _application, JAXRSServerFactoryBean.class); - jaxRsServerFactoryBean.setBus(_bus); - jaxRsServerFactoryBean.setProperties(_properties); + jaxRsServerFactoryBean.setBus(_bus); + jaxRsServerFactoryBean.setProperties(_properties); - JSONProvider<Object> jsonProvider = new JSONProvider<>(); + JSONProvider<Object> jsonProvider = new JSONProvider<>(); - jsonProvider.setDropCollectionWrapperElement(true); - jsonProvider.setDropRootElement(true); - jsonProvider.setSerializeAsArray(true); - jsonProvider.setSupportUnwrapped(true); + jsonProvider.setDropCollectionWrapperElement(true); + jsonProvider.setDropRootElement(true); + jsonProvider.setSerializeAsArray(true); + jsonProvider.setSupportUnwrapped(true); - jaxRsServerFactoryBean.setProvider(jsonProvider); + jaxRsServerFactoryBean.setProvider(jsonProvider); - for (Object provider : _providers) { - jaxRsServerFactoryBean.setProvider(provider); - } + for (Object provider : _providers) { + jaxRsServerFactoryBean.setProvider(provider); + } - for (Object service : _services) { - jaxRsServerFactoryBean.setResourceProvider( - new SingletonResourceProvider(service, true)); - } + for (Object service : _services) { + jaxRsServerFactoryBean.setResourceProvider( + new SingletonResourceProvider(service, true)); + } - String address = _properties.get("CXF_ENDPOINT_ADDRESS").toString(); + String address = _properties.get("CXF_ENDPOINT_ADDRESS").toString(); - if (address != null) { - jaxRsServerFactoryBean.setAddress(address); - } + if (address != null) { + jaxRsServerFactoryBean.setAddress(address); + } - _server = jaxRsServerFactoryBean.create(); + _server = jaxRsServerFactoryBean.create(); - _server.start(); - } + _server.start(); + } - private volatile boolean _closed = false; - private final Application _application; - private final Bus _bus; - private final Map<String, Object> _properties; - private final Collection<Object> _providers = new ArrayList<>(); - private Server _server; - private final Collection<Object> _services = new ArrayList<>(); + private volatile boolean _closed = false; + private final Application _application; + private final Bus _bus; + private final Map<String, Object> _properties; + private final Collection<Object> _providers = new ArrayList<>(); + private Server _server; + private final Collection<Object> _services = new ArrayList<>(); -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java index 671a413..0635c64 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java @@ -22,105 +22,102 @@ import org.osgi.framework.ServiceReference; import org.osgi.util.tracker.ServiceTracker; import org.osgi.util.tracker.ServiceTrackerCustomizer; -/** - * @author Carlos Sierra Andrés - */ public class FiltersAndInterceptorsServiceTrackerCustomizer - implements ServiceTrackerCustomizer<Object, ServiceTracker<?, ?>> { + implements ServiceTrackerCustomizer<Object, ServiceTracker<?, ?>> { - private BundleContext _bundleContext; + private BundleContext _bundleContext; - public FiltersAndInterceptorsServiceTrackerCustomizer( - BundleContext bundleContext) { + public FiltersAndInterceptorsServiceTrackerCustomizer( + BundleContext bundleContext) { - _bundleContext = bundleContext; - } + _bundleContext = bundleContext; + } - @Override - public ServiceTracker<?, ?> addingService(final ServiceReference<Object> reference) { - final String filterBase = - reference.getProperty("osgi.jaxrs.filter.base").toString(); + @Override + public ServiceTracker<?, ?> addingService(final ServiceReference<Object> reference) { + final String filterBase = + reference.getProperty("osgi.jaxrs.filter.base").toString(); - final Object service = _bundleContext.getService(reference); + final Object service = _bundleContext.getService(reference); - ServiceTracker<CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> serviceTracker = new ServiceTracker<>( - _bundleContext, CXFJaxRsServiceRegistrator.class, - new ServiceTrackerCustomizer - <CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator>() { + ServiceTracker<CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> serviceTracker = new ServiceTracker<>( + _bundleContext, CXFJaxRsServiceRegistrator.class, + new ServiceTrackerCustomizer + <CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator>() { - @Override - public CXFJaxRsServiceRegistrator addingService( - ServiceReference<CXFJaxRsServiceRegistrator> cxfReference) { + @Override + public CXFJaxRsServiceRegistrator addingService( + ServiceReference<CXFJaxRsServiceRegistrator> cxfReference) { - Object resourceBaseObject = - cxfReference.getProperty("CXF_ENDPOINT_ADDRESS"); + Object resourceBaseObject = + cxfReference.getProperty("CXF_ENDPOINT_ADDRESS"); - if (resourceBaseObject == null) { - return null; - } + if (resourceBaseObject == null) { + return null; + } - String resourceBase = resourceBaseObject.toString(); + String resourceBase = resourceBaseObject.toString(); - if (resourceBase.startsWith(filterBase)) { - CXFJaxRsServiceRegistrator serviceRegistrator = - _bundleContext.getService(cxfReference); - try { - serviceRegistrator.addProvider(service); + if (resourceBase.startsWith(filterBase)) { + CXFJaxRsServiceRegistrator serviceRegistrator = + _bundleContext.getService(cxfReference); + try { + serviceRegistrator.addProvider(service); - return serviceRegistrator; - } - finally { - _bundleContext.ungetService(reference); - } - } + return serviceRegistrator; + } + finally { + _bundleContext.ungetService(reference); + } + } - return null; - } + return null; + } - @Override - public void modifiedService( - ServiceReference<CXFJaxRsServiceRegistrator> reference, - CXFJaxRsServiceRegistrator service) { + @Override + public void modifiedService( + ServiceReference<CXFJaxRsServiceRegistrator> reference, + CXFJaxRsServiceRegistrator service) { - removedService(reference, service); - addingService(reference); - } + removedService(reference, service); + addingService(reference); + } - @Override - public void removedService( - ServiceReference<CXFJaxRsServiceRegistrator> reference, - CXFJaxRsServiceRegistrator service) { + @Override + public void removedService( + ServiceReference<CXFJaxRsServiceRegistrator> reference, + CXFJaxRsServiceRegistrator service) { - CXFJaxRsServiceRegistrator serviceRegistrator = - _bundleContext.getService(reference); - try { - serviceRegistrator.removeProvider(service); - } - finally { - _bundleContext.ungetService(reference); - } - } - }); + CXFJaxRsServiceRegistrator serviceRegistrator = + _bundleContext.getService(reference); + try { + serviceRegistrator.removeProvider(service); + } + finally { + _bundleContext.ungetService(reference); + } + } + }); - serviceTracker.open(); + serviceTracker.open(); - return serviceTracker; - } + return serviceTracker; + } - @Override - public void modifiedService( - ServiceReference<Object> reference, ServiceTracker<?, ?> serviceTracker) { + @Override + public void modifiedService( + ServiceReference<Object> reference, ServiceTracker<?, ?> serviceTracker) { - removedService(reference, serviceTracker); - addingService(reference); - } + removedService(reference, serviceTracker); + addingService(reference); + } - @Override - public void removedService( - ServiceReference<Object> reference, ServiceTracker<?, ?> serviceTracker) { + @Override + public void removedService( + ServiceReference<Object> reference, ServiceTracker<?, ?> serviceTracker) { - _bundleContext.ungetService(reference); + _bundleContext.ungetService(reference); - serviceTracker.close(); - } + serviceTracker.close(); + } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ServicesServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ServicesServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ServicesServiceTrackerCustomizer.java index b1e6484..fa5410b 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ServicesServiceTrackerCustomizer.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/ServicesServiceTrackerCustomizer.java @@ -26,77 +26,74 @@ import org.osgi.framework.wiring.BundleWiring; import org.osgi.util.tracker.ServiceTracker; import org.osgi.util.tracker.ServiceTrackerCustomizer; -/** - * @author Carlos Sierra Andrés - */ public class ServicesServiceTrackerCustomizer - implements ServiceTrackerCustomizer - <Object, ServiceTracker - <CXFJaxRsServiceRegistrator, ?>> { + implements ServiceTrackerCustomizer + <Object, ServiceTracker + <CXFJaxRsServiceRegistrator, ?>> { - private final BundleContext _bundleContext; + private final BundleContext _bundleContext; - public ServicesServiceTrackerCustomizer(BundleContext bundleContext) { - _bundleContext = bundleContext; - } + public ServicesServiceTrackerCustomizer(BundleContext bundleContext) { + _bundleContext = bundleContext; + } - @Override - public ServiceTracker - <CXFJaxRsServiceRegistrator, ?> - addingService(ServiceReference<Object> reference) { + @Override + public ServiceTracker + <CXFJaxRsServiceRegistrator, ?> + addingService(ServiceReference<Object> reference) { - String applicationSelector = - reference.getProperty("jaxrs.application.select").toString(); + String applicationSelector = + reference.getProperty("jaxrs.application.select").toString(); - Bundle bundle = reference.getBundle(); + Bundle bundle = reference.getBundle(); - BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); + BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); - ClassLoader classLoader = bundleWiring.getClassLoader(); + ClassLoader classLoader = bundleWiring.getClassLoader(); - Object service = _bundleContext.getService(reference); + Object service = _bundleContext.getService(reference); - try { - Filter filter = _bundleContext.createFilter( - "(&(objectClass=" + CXFJaxRsServiceRegistrator.class.getName() + - ")" + applicationSelector + ")"); + try { + Filter filter = _bundleContext.createFilter( + "(&(objectClass=" + CXFJaxRsServiceRegistrator.class.getName() + + ")" + applicationSelector + ")"); - ServiceTracker - <CXFJaxRsServiceRegistrator, ?> - serviceTracker = new ServiceTracker<>( - _bundleContext, filter, - new AddonsServiceTrackerCustomizer( - _bundleContext, classLoader, service)); + ServiceTracker + <CXFJaxRsServiceRegistrator, ?> + serviceTracker = new ServiceTracker<>( + _bundleContext, filter, + new AddonsServiceTrackerCustomizer( + _bundleContext, classLoader, service)); - serviceTracker.open(); + serviceTracker.open(); - return serviceTracker; - } - catch (InvalidSyntaxException ise) { - _bundleContext.ungetService(reference); + return serviceTracker; + } + catch (InvalidSyntaxException ise) { + _bundleContext.ungetService(reference); - throw new RuntimeException(ise); - } - } + throw new RuntimeException(ise); + } + } - @Override - public void modifiedService( - ServiceReference<Object> reference, - ServiceTracker<CXFJaxRsServiceRegistrator, ?> serviceTracker) { + @Override + public void modifiedService( + ServiceReference<Object> reference, + ServiceTracker<CXFJaxRsServiceRegistrator, ?> serviceTracker) { - removedService(reference, serviceTracker); + removedService(reference, serviceTracker); - addingService(reference); - } + addingService(reference); + } - @Override - public void removedService( - ServiceReference<Object> reference, - ServiceTracker<CXFJaxRsServiceRegistrator, ?> serviceTracker) { + @Override + public void removedService( + ServiceReference<Object> reference, + ServiceTracker<CXFJaxRsServiceRegistrator, ?> serviceTracker) { - serviceTracker.close(); + serviceTracker.close(); - _bundleContext.ungetService(reference); - } + _bundleContext.ungetService(reference); + } } http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/6541cc07/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/SingletonServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/SingletonServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/SingletonServiceTrackerCustomizer.java index 8ed83da..64bab69 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/SingletonServiceTrackerCustomizer.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/SingletonServiceTrackerCustomizer.java @@ -30,132 +30,129 @@ import java.util.Hashtable; import java.util.Map; import java.util.Set; -/** - * @author Carlos Sierra Andrés - */ class SingletonServiceTrackerCustomizer - implements ServiceTrackerCustomizer - <Object, SingletonServiceTrackerCustomizer.Tracked> { + implements ServiceTrackerCustomizer + <Object, SingletonServiceTrackerCustomizer.Tracked> { - private BundleContext _bundleContext; - private Bus _bus; + private BundleContext _bundleContext; + private Bus _bus; - public SingletonServiceTrackerCustomizer( - BundleContext bundleContext, Bus bus) { + public SingletonServiceTrackerCustomizer( + BundleContext bundleContext, Bus bus) { - _bundleContext = bundleContext; - _bus = bus; - } + _bundleContext = bundleContext; + _bus = bus; + } - @Override - public Tracked addingService( - ServiceReference<Object> serviceReference) { + @Override + public Tracked addingService( + ServiceReference<Object> serviceReference) { - final Object service = _bundleContext.getService( - serviceReference); - - try { - String[] propertyKeys = serviceReference.getPropertyKeys(); + final Object service = _bundleContext.getService( + serviceReference); + + try { + String[] propertyKeys = serviceReference.getPropertyKeys(); - Map<String, Object> properties = new HashMap<>( - propertyKeys.length); + Map<String, Object> properties = new HashMap<>( + propertyKeys.length); - for (String propertyKey : propertyKeys) { - if (propertyKey.equals("osgi.jaxrs.resource.base")) { - continue; - } - properties.put( - propertyKey, serviceReference.getProperty(propertyKey)); - } + for (String propertyKey : propertyKeys) { + if (propertyKey.equals("osgi.jaxrs.resource.base")) { + continue; + } + properties.put( + propertyKey, serviceReference.getProperty(propertyKey)); + } - properties.put( - "CXF_ENDPOINT_ADDRESS", - serviceReference.getProperty("osgi.jaxrs.resource.base"). - toString()); + properties.put( + "CXF_ENDPOINT_ADDRESS", + serviceReference.getProperty("osgi.jaxrs.resource.base"). + toString()); - CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = - new CXFJaxRsServiceRegistrator( - _bus, - new Application() { - @Override - public Set<Object> getSingletons() { - return Collections.singleton(service); - } - }, - properties); + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = + new CXFJaxRsServiceRegistrator( + _bus, + new Application() { + @Override + public Set<Object> getSingletons() { + return Collections.singleton(service); + } + }, + properties); - return new Tracked( - cxfJaxRsServiceRegistrator, service, - _bundleContext.registerService( - CXFJaxRsServiceRegistrator.class, - cxfJaxRsServiceRegistrator, new Hashtable<>(properties))); - } - catch (Exception e) { - _bundleContext.ungetService(serviceReference); + return new Tracked( + cxfJaxRsServiceRegistrator, service, + _bundleContext.registerService( + CXFJaxRsServiceRegistrator.class, + cxfJaxRsServiceRegistrator, new Hashtable<>(properties))); + } + catch (Exception e) { + _bundleContext.ungetService(serviceReference); - throw e; - } - } + throw e; + } + } - @Override - public void modifiedService( - ServiceReference<Object> serviceReference, Tracked tracked) { + @Override + public void modifiedService( + ServiceReference<Object> serviceReference, Tracked tracked) { - removedService(serviceReference, tracked); + removedService(serviceReference, tracked); - addingService(serviceReference); - } + addingService(serviceReference); + } - @Override - public void removedService( - ServiceReference<Object> reference, Tracked tracked) { + @Override + public void removedService( + ServiceReference<Object> reference, Tracked tracked) { - _bundleContext.ungetService(reference); + _bundleContext.ungetService(reference); - Object service = tracked.getService(); + Object service = tracked.getService(); - CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = - tracked.getCxfJaxRsServiceRegistrator(); + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = + tracked.getCxfJaxRsServiceRegistrator(); - cxfJaxRsServiceRegistrator.close(); + cxfJaxRsServiceRegistrator.close(); - tracked.getCxfJaxRsServiceRegistratorServiceRegistration().unregister(); - } + tracked.getCxfJaxRsServiceRegistratorServiceRegistration().unregister(); + } - public static class Tracked { + public static class Tracked { - private final CXFJaxRsServiceRegistrator _cxfJaxRsServiceRegistrator; - private final Object _service; - private final ServiceRegistration<CXFJaxRsServiceRegistrator> - _cxfJaxRsServiceRegistratorServiceRegistration; + private final CXFJaxRsServiceRegistrator _cxfJaxRsServiceRegistrator; + private final Object _service; + private final ServiceRegistration<CXFJaxRsServiceRegistrator> + _cxfJaxRsServiceRegistratorServiceRegistration; - public Object getService() { - return _service; - } + public Object getService() { + return _service; + } - public CXFJaxRsServiceRegistrator getCxfJaxRsServiceRegistrator() { - return _cxfJaxRsServiceRegistrator; - } + public CXFJaxRsServiceRegistrator getCxfJaxRsServiceRegistrator() { + return _cxfJaxRsServiceRegistrator; + } - public ServiceRegistration<CXFJaxRsServiceRegistrator> - getCxfJaxRsServiceRegistratorServiceRegistration() { + public ServiceRegistration<CXFJaxRsServiceRegistrator> + getCxfJaxRsServiceRegistratorServiceRegistration() { - return _cxfJaxRsServiceRegistratorServiceRegistration; - } + return _cxfJaxRsServiceRegistratorServiceRegistration; + } - public Tracked( - CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator, - Object service, - ServiceRegistration<CXFJaxRsServiceRegistrator> - cxfJaxRsServiceRegistratorServiceRegistration) { - - _cxfJaxRsServiceRegistrator = cxfJaxRsServiceRegistrator; - _service = service; - _cxfJaxRsServiceRegistratorServiceRegistration = - cxfJaxRsServiceRegistratorServiceRegistration; - } - - } + public Tracked( + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator, + Object service, + ServiceRegistration<CXFJaxRsServiceRegistrator> + cxfJaxRsServiceRegistratorServiceRegistration) { + + _cxfJaxRsServiceRegistrator = cxfJaxRsServiceRegistrator; + _service = service; + _cxfJaxRsServiceRegistratorServiceRegistration = + cxfJaxRsServiceRegistratorServiceRegistration; + } + + } }
