renaming and restructuring
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/76e7db85 Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/76e7db85 Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/76e7db85 Branch: refs/heads/master Commit: 76e7db853f4adfd8ae1d1cd13162972fabf1d906 Parents: 17c51be Author: Raymond Auge <[email protected]> Authored: Mon Nov 7 15:00:24 2016 -0500 Committer: Raymond Auge <[email protected]> Committed: Mon Nov 7 15:00:24 2016 -0500 ---------------------------------------------------------------------- jax-rs.example-run/augments.bnd | 77 +++++++++ jax-rs.example-run/example.bndrun | 47 ++++++ jax-rs.example-run/pom.xml | 71 +++++++++ jax-rs.example/.gitignore | 2 + jax-rs.example/pom.xml | 27 ++++ .../portal/rest/example/ExampleAddon.java | 50 ++++++ .../portal/rest/example/ExampleApplication.java | 46 ++++++ .../portal/rest/example/ExampleFilter.java | 44 +++++ jax-rs.itests-run/itest.bndrun | 50 ++++++ jax-rs.itests-run/pom.xml | 64 ++++++++ jax-rs.itests/bnd.bnd | 5 + jax-rs.itests/pom.xml | 33 ++++ jax-rs.itests/src/main/java/test/JaxrsTest.java | 53 +++++++ .../src/main/java/test/types/TestAddon.java | 41 +++++ .../main/java/test/types/TestApplication.java | 38 +++++ .../src/main/java/test/types/TestFilter.java | 37 +++++ jax-rs.whiteboard/.gitignore | 2 + jax-rs.whiteboard/bnd.bnd | 61 +++++++ jax-rs.whiteboard/pom.xml | 82 ++++++++++ .../activator/CXFJaxRsBundleActivator.java | 101 ++++++++++++ .../extender/activator/ServicesRegistrator.java | 144 +++++++++++++++++ .../AddonsServiceTrackerCustomizer.java | 102 ++++++++++++ .../ApplicationServiceTrackerCustomizer.java | 141 ++++++++++++++++ .../internal/BusServiceTrackerCustomizer.java | 117 ++++++++++++++ .../internal/CXFJaxRsServiceRegistrator.java | 148 +++++++++++++++++ ...AndInterceptorsServiceTrackerCustomizer.java | 123 ++++++++++++++ .../ServicesServiceTrackerCustomizer.java | 104 ++++++++++++ .../SingletonServiceTrackerCustomizer.java | 159 +++++++++++++++++++ org.apache.aries.jax-rs.bndrun/augments.bnd | 82 ---------- org.apache.aries.jax-rs.bndrun/pom.xml | 69 -------- org.apache.aries.jax-rs.bndrun/run.bndrun | 52 ------ org.apache.aries.jax-rs.example/.gitignore | 2 - org.apache.aries.jax-rs.example/pom.xml | 27 ---- .../portal/rest/example/ExampleAddon.java | 50 ------ .../portal/rest/example/ExampleApplication.java | 46 ------ .../portal/rest/example/ExampleFilter.java | 44 ----- org.apache.aries.jax-rs.extender/.gitignore | 2 - org.apache.aries.jax-rs.extender/bnd.bnd | 58 ------- org.apache.aries.jax-rs.extender/pom.xml | 82 ---------- .../activator/CXFJaxRsBundleActivator.java | 102 ------------ .../extender/activator/ServicesRegistrator.java | 151 ------------------ .../AddonsServiceTrackerCustomizer.java | 102 ------------ .../ApplicationServiceTrackerCustomizer.java | 141 ---------------- .../internal/BusServiceTrackerCustomizer.java | 117 -------------- .../internal/CXFJaxRsServiceRegistrator.java | 148 ----------------- ...AndInterceptorsServiceTrackerCustomizer.java | 123 -------------- .../ServicesServiceTrackerCustomizer.java | 104 ------------ .../SingletonServiceTrackerCustomizer.java | 159 ------------------- .../integration-test.bndrun | 50 ------ .../pom.xml | 64 -------- org.apache.aries.jax-rs.tests/bnd.bnd | 5 - org.apache.aries.jax-rs.tests/pom.xml | 33 ---- .../src/main/java/test/JaxrsTest.java | 55 ------- .../src/main/java/test/types/TestAddon.java | 41 ----- .../main/java/test/types/TestApplication.java | 38 ----- .../src/main/java/test/types/TestFilter.java | 37 ----- pom.xml | 12 +- 57 files changed, 1975 insertions(+), 1990 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.example-run/augments.bnd ---------------------------------------------------------------------- diff --git a/jax-rs.example-run/augments.bnd b/jax-rs.example-run/augments.bnd new file mode 100644 index 0000000..aa1cca1 --- /dev/null +++ b/jax-rs.example-run/augments.bnd @@ -0,0 +1,77 @@ +-augment.javax.servlet-api: \ + javax.servlet-api; \ + requirement:="osgi.implementation;filter:='(osgi.implementation=osgi.http)'" + +-augment.javax.ws.rs-api: \ + javax.ws.rs-api; \ + requirement:="osgi.implementation;filter:='(osgi.implementation=aries.jax-rs)'" + +-augment.org.apache.commons.fileupload: \ + org.apache.commons.fileupload; \ + capability:=" generic.dependency;generic.dependency='commons.fileupload'" + +-augment.org.apache.felix.gogo.command: \ + org.apache.felix.gogo.command; \ + capability:=" generic.dependency;generic.dependency='gogo.shell.command';version:Version='1.0.0'"; \ + version='1.0.0' + +-augment.org.apache.felix.gogo.shell: \ + org.apache.felix.gogo.shell; \ + capability:=" osgi.implementation;osgi.implementation='gogo.shell';version:Version='1.0.0'"; \ + requirement:="generic.dependency;filter:='(generic.dependency=gogo.shell.command)';effective:=active"; \ + version='1.0.0' + +-augment.org.apache.felix.gogo.jline: \ + org.apache.felix.gogo.jline; \ + capability:=" osgi.implementation;osgi.implementation='gogo.jline';version:Version='1.0.0'"; \ + requirement:="generic.dependency;filter:='(generic.dependency=gogo.shell.command)';effective:=active"; \ + version='1.0.0' + +-augment.org.apache.felix.log: \ + org.apache.felix.log; \ + capability:=" osgi.implementation;osgi.implementation=osgi.log" + +-augment.org.apache.felix.scr: \ + org.apache.felix.scr; \ + requirement:="osgi.implementation;filter:='(osgi.implementation=osgi.metatype)'" + +-augment.org.eclipse.equinox.coordinator: \ + org.eclipse.equinox.coordinator; \ + capability:=" osgi.service;objectClass=org.osgi.service.coordinator.Coordinator;effective:=active, \ + osgi.implementation;osgi.implementation=osgi.coordinator" + +-augment.org.eclipse.equinox.event: \ + org.eclipse.equinox.event; \ + capability:=" osgi.service;objectClass=org.osgi.service.event.EventAdmin;effective:=active, \ + osgi.implementation;osgi.implementation=osgi.event"; \ + requirement:="osgi.extender;filter:='(osgi.extender=osgi.component)'" + +-augment.org.eclipse.equinox.http.jetty: \ + org.eclipse.equinox.http.jetty; \ + capability:=" equinox.module.data;activation.policy=eager, \ + generic.dependency;generic.dependency='osgi.servlet.container';version:Version='1.0.0'" + +-augment.org.eclipse.equinox.http.servlet: \ + org.eclipse.equinox.http.servlet; \ + capability:=" equinox.module.data;activation.policy=eager"; \ + requirement:="generic.dependency;filter:='(generic.dependency=commons.fileupload)';effective:=active,\ + generic.dependency;filter:='(generic.dependency=osgi.servlet.container)';effective:=active" + +-augment.org.knopflerfish.bundle.useradmin: \ + org.knopflerfish.bundle.useradmin; \ + capability:=" osgi.service;objectClass:List<String>=org.osgi.service.useradmin.UserAdmin;effective:=active, \ + osgi.implementation;osgi.implementation=osgi.useradmin" + +-augment.org.osgi.service.event: \ + org.osgi.service.event; \ + requirement:="osgi.implementation;filter:='(osgi.implementation=osgi.event)'" + +-augment.org.osgi.service.metatype: \ + org.osgi.service.metatype; \ + requirement:="osgi.implementation;filter:='(osgi.implementation=osgi.metatype)'" + +-augment.org.osgi.service.remoteserviceadmin: \ + org.osgi.service.remoteserviceadmin; \ + requirement:="osgi.remoteserviceadmin.distribution;filter:='(configs=*)', \ + osgi.remoteserviceadmin.topology;filter:='(policy=*)', \ + osgi.remoteserviceadmin.discovery;filter:='(protocols=*)'" http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.example-run/example.bndrun ---------------------------------------------------------------------- diff --git a/jax-rs.example-run/example.bndrun b/jax-rs.example-run/example.bndrun new file mode 100644 index 0000000..0a28b1b --- /dev/null +++ b/jax-rs.example-run/example.bndrun @@ -0,0 +1,47 @@ +-standalone: +-include: ${.}/augments.bnd +-resourceonly: true + +-plugin.A.pom.repo = \ + aQute.bnd.repository.maven.pom.provider.BndPomRepository; \ + snapshotUrls=https://oss.sonatype.org/content/repositories/osgi/; \ + releaseUrls=https://repo1.maven.org/maven2/; \ + pom=${.}/pom.xml; \ + name=pom.repo; \ + location=${.}/target/cached.xml + +-runrequires: \ + osgi.identity;filter:='(osgi.identity=org.apache.aries.jax-rs.example)',\ + osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.jline)' + + # ,\ +# osgi.identity;filter:='(osgi.identity=org.apache.aries.jax-rs.whiteboard)' + +-runfw: org.eclipse.osgi;version='[3.10.100.v20150529-1857,3.10.100.v20150529-1857]' +-runbundles: \ + javax.annotation-api;version='[1.2.0,1.2.1)',\ + javax.json-api;version='[1.0.0,1.0.1)',\ + javax.ws.rs-api;version='[2.0.1,2.0.2)',\ + log4j;version='[1.2.17,1.2.18)',\ + org.apache.aries.jax-rs.example;version='[1.0.0,1.0.1)',\ + org.apache.aries.jax-rs.whiteboard;version='[1.0.0,1.0.1)',\ + org.apache.felix.configadmin;version='[1.8.8,1.8.9)',\ + org.apache.felix.http.jetty;version='[3.4.0,3.4.1)',\ + org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\ + org.apache.felix.scr;version='[2.0.2,2.0.3)',\ + org.apache.ws.xmlschema.core;version='[2.2.1,2.2.2)',\ + org.eclipse.equinox.event;version='[1.3.100,1.3.101)',\ + org.eclipse.equinox.metatype;version='[1.4.100,1.4.101)',\ + org.objectweb.asm;version='[5.0.4,5.0.5)',\ + org.osgi.service.event;version='[1.3.1,1.3.2)',\ + org.osgi.service.metatype;version='[1.3.0,1.3.1)',\ + slf4j.api;version='[1.7.21,1.7.22)',\ + slf4j.log4j12;version='[1.6.1,1.6.2)' + +-runee: JavaSE-1.8 +-resolve.effective: resolve, active +-runproperties.eqnx: \ + osgi.console.enable.builtin=false, \ + osgi.console=, \ + org.osgi.service.http.port=8080 +-runsystemcapabilities.dflt: ${native_capability} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.example-run/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.example-run/pom.xml b/jax-rs.example-run/pom.xml new file mode 100644 index 0000000..31407b2 --- /dev/null +++ b/jax-rs.example-run/pom.xml @@ -0,0 +1,71 @@ +<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> + + <parent> + <groupId>org.apache.aries</groupId> + <artifactId>org.apache.aries.jax-rs</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>org.apache.aries.jax-rs.example-run</artifactId> + + <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>true</resolve> + <bndruns> + <bndrun>example.bndrun</bndrun> + </bndruns> + <targetDir>.</targetDir> + </configuration> + <executions> + <execution> + <goals> + <goal>export</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.apache.aries</groupId> + <artifactId>org.apache.aries.jax-rs.example</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.aries</groupId> + <artifactId>org.apache.aries.jax-rs.whiteboard</artifactId> + <version>1.0.0-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/76e7db85/jax-rs.example/.gitignore ---------------------------------------------------------------------- diff --git a/jax-rs.example/.gitignore b/jax-rs.example/.gitignore new file mode 100644 index 0000000..83ccc54 --- /dev/null +++ b/jax-rs.example/.gitignore @@ -0,0 +1,2 @@ +/build/ +/bin/ http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.example/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.example/pom.xml b/jax-rs.example/pom.xml new file mode 100644 index 0000000..a6473c4 --- /dev/null +++ b/jax-rs.example/pom.xml @@ -0,0 +1,27 @@ +<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> + <parent> + <groupId>org.apache.aries</groupId> + <artifactId>org.apache.aries.jax-rs</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + <artifactId>org.apache.aries.jax-rs.example</artifactId> + <packaging>jar</packaging> + <description>Apache Aries JAX-RS Example</description> + <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.service.component.annotations</artifactId> + <version>1.3.0</version> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleAddon.java ---------------------------------------------------------------------- diff --git a/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleAddon.java b/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleAddon.java new file mode 100644 index 0000000..5431e76 --- /dev/null +++ b/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleAddon.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.rest.example; + +import org.osgi.service.component.annotations.Component; + +import javax.annotation.PostConstruct; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +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 +) +public class ExampleAddon { + + @GET + @Path("/{name}") + public String sayHello(@PathParam("name") String name) { + return "Hello " + name; + } + + @PostConstruct + public void init() { + System.out.println("URIINFO: " + _uriInfo); + } + + @Context + UriInfo _uriInfo; + +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleApplication.java ---------------------------------------------------------------------- diff --git a/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleApplication.java b/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleApplication.java new file mode 100644 index 0000000..25234b2 --- /dev/null +++ b/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleApplication.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p/> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p/> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.rest.example; + +import org.osgi.service.component.annotations.Component; + +import javax.ws.rs.GET; +import javax.ws.rs.Produces; +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 +) +public class ExampleApplication extends Application { + + @Override + public Set<Object> getSingletons() { + return Collections.<Object>singleton(this); + } + + @GET + @Produces("text/plain") + public String sayHello() { + return "Hello world"; + } + +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleFilter.java ---------------------------------------------------------------------- diff --git a/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleFilter.java b/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleFilter.java new file mode 100644 index 0000000..c2e89ac --- /dev/null +++ b/jax-rs.example/src/main/java/com/liferay/portal/rest/example/ExampleFilter.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.rest.example; + +import org.osgi.service.component.annotations.Component; + +import javax.ws.rs.container.ContainerRequestContext; +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=com.liferay.portal.rest.example.ExampleApplication)", + "osgi.jaxrs.filter.base=/examples" + } +) +@Provider +public class ExampleFilter implements ContainerRequestFilter { + + @Override + public void filter(ContainerRequestContext requestContext) + throws IOException { + + System.out.println("FILTERED!"); + } + +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.itests-run/itest.bndrun ---------------------------------------------------------------------- diff --git a/jax-rs.itests-run/itest.bndrun b/jax-rs.itests-run/itest.bndrun new file mode 100644 index 0000000..e610def --- /dev/null +++ b/jax-rs.itests-run/itest.bndrun @@ -0,0 +1,50 @@ +-standalone: + +-plugin.integration.test = \ + aQute.bnd.repository.maven.pom.provider.BndPomRepository; \ + snapshotUrls=https://oss.sonatype.org/content/repositories/osgi/; \ + releaseUrls=https://repo1.maven.org/maven2/; \ + pom=${.}/pom.xml; \ + name=integration.test; \ + location=${.}/target/cached.xml + +-runrequires: \ + osgi.identity;filter:='(osgi.identity=org.apache.aries.jax-rs.itests)' + +-runfw: org.eclipse.osgi;version='[3.10.100.v20150529-1857,3.10.100.v20150529-1857]' + +#-runtrace: true + +-runee: JavaSE-1.8 +-resolve.effective: resolve, active + +-runsystempackages.eqnx: javax.script +-runsystemcapabilities.dflt: ${native_capability} +-runproperties.eqnx: \ + osgi.console.enable.builtin=false, \ + osgi.console=, \ + org.osgi.service.http.port=8080 +-runbundles: \ + javax.annotation-api; version='[1.2.0,1.2.1)',\ + javax.json-api; version='[1.0.0,1.0.1)',\ + javax.ws.rs-api; version='[2.0.1,2.0.2)',\ + log4j; version='[1.2.17,1.2.18)',\ + org.apache.aries.jax-rs.itests; version='[1.0.0,1.0.1)',\ + org.apache.aries.jax-rs.whiteboard; version='[1.0.0,1.0.1)',\ + org.apache.felix.bundlerepository; version='[1.6.0,1.6.1)',\ + org.apache.felix.configadmin; version='[1.8.8,1.8.9)',\ + org.apache.felix.http.api; version='[3.0.0,3.0.1)',\ + org.apache.felix.http.jetty; version='[3.4.0,3.4.1)',\ + org.apache.felix.http.servlet-api; version='[1.1.2,1.1.3)',\ + org.apache.felix.scr; version='[2.0.2,2.0.3)',\ + org.apache.ws.xmlschema.core; version='[2.2.1,2.2.2)',\ + org.eclipse.equinox.event; version='[1.3.100,1.3.101)',\ + org.eclipse.equinox.metatype; version='[1.4.100,1.4.101)',\ + org.objectweb.asm; version='[5.0.4,5.0.5)',\ + org.osgi.compendium; version='[4.1.0,4.1.1)',\ + org.osgi.service.event; version='[1.3.1,1.3.2)',\ + org.osgi.service.metatype; version='[1.3.0,1.3.1)',\ + osgi.enroute.hamcrest.wrapper; version='[1.3.0,1.3.1)',\ + osgi.enroute.junit.wrapper; version='[4.12.0,4.12.1)',\ + slf4j.api; version='[1.7.21,1.7.22)',\ + slf4j.log4j12; version='[1.6.1,1.6.2)' http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.itests-run/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.itests-run/pom.xml b/jax-rs.itests-run/pom.xml new file mode 100644 index 0000000..63ea8fe --- /dev/null +++ b/jax-rs.itests-run/pom.xml @@ -0,0 +1,64 @@ +<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> + + <parent> + <groupId>org.apache.aries</groupId> + <artifactId>org.apache.aries.jax-rs</artifactId> + <version>1.0.0-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + + <artifactId>org.apache.aries.jax-rs.itests-run</artifactId> + + <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</groupId> + <artifactId>org.apache.aries.jax-rs.itests</artifactId> + <version>1.0.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.aries</groupId> + <artifactId>org.apache.aries.jax-rs.whiteboard</artifactId> + <version>1.0.0-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/76e7db85/jax-rs.itests/bnd.bnd ---------------------------------------------------------------------- diff --git a/jax-rs.itests/bnd.bnd b/jax-rs.itests/bnd.bnd new file mode 100644 index 0000000..264db93 --- /dev/null +++ b/jax-rs.itests/bnd.bnd @@ -0,0 +1,5 @@ +Bundle-Description: Integration Test bundle for the JAX-RS extender + +Test-Cases: \ + ${classes;CONCRETE;EXTENDS;junit.framework.TestCase},\ + ${classes;CONCRETE;ANNOTATED;org.junit.Test} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.itests/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.itests/pom.xml b/jax-rs.itests/pom.xml new file mode 100644 index 0000000..42ed192 --- /dev/null +++ b/jax-rs.itests/pom.xml @@ -0,0 +1,33 @@ +<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> + + <parent> + <groupId>org.apache.aries</groupId> + <artifactId>org.apache.aries.jax-rs</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>org.apache.aries.jax-rs.itests</artifactId> + + <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> +</project> http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/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 new file mode 100644 index 0000000..c4afe0a --- /dev/null +++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java @@ -0,0 +1,53 @@ +package test; + +import java.util.Dictionary; +import java.util.Hashtable; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.Filter; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceRegistration; +import org.osgi.util.tracker.ServiceTracker; + +import junit.framework.TestCase; +import test.types.TestAddon; + +public class JaxrsTest extends TestCase { + + static BundleContext bundleContext = FrameworkUtil.getBundle( + JaxrsTest.class).getBundleContext(); + + public void testEndPoint() throws Exception { + ServiceRegistration<?> serviceRegistration = null; + + try { + TestAddon testAddon = new TestAddon(); + + Dictionary<String, Object> properties = new Hashtable<>(); + properties.put("osgi.jaxrs.resource.base", "/test-addon"); + + serviceRegistration = bundleContext.registerService( + Object.class, testAddon, properties); + + // TODO this availability should be checked through a jaxrs runtime service + + Filter filter = bundleContext.createFilter("(CXF_ENDPOINT_ADDRESS=/test-addon)"); + + ServiceTracker<?, ?> st = new ServiceTracker<>(bundleContext, filter, null); + + st.open(); + + if (st.waitForService(5000) == null) { + fail(); + } + + // 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/76e7db85/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 new file mode 100644 index 0000000..849d582 --- /dev/null +++ b/jax-rs.itests/src/main/java/test/types/TestAddon.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package test.types; + +import javax.annotation.PostConstruct; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Context; +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; + } + + @PostConstruct + public void init() { + System.out.println("URIINFO: " + _uriInfo); + } + + @Context + UriInfo _uriInfo; + +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/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 new file mode 100644 index 0000000..c7e65f3 --- /dev/null +++ b/jax-rs.itests/src/main/java/test/types/TestApplication.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p/> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p/> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package test.types; + +import java.util.Collections; +import java.util.Set; + +import javax.ws.rs.GET; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Application; + +// property = "osgi.jaxrs.application.base=/example-application", +public class TestApplication extends Application { + + @Override + public Set<Object> getSingletons() { + return Collections.<Object>singleton(this); + } + + @GET + @Produces("text/plain") + public String sayHello() { + return "Hello world"; + } + +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/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 new file mode 100644 index 0000000..928221a --- /dev/null +++ b/jax-rs.itests/src/main/java/test/types/TestFilter.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package test.types; + +import java.io.IOException; + +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerRequestFilter; +import javax.ws.rs.ext.Provider; + +// property = { +// "jaxrs.application.select=(component.name=com.liferay.portal.rest.example.ExampleApplication)", +// "osgi.jaxrs.filter.base=/examples" +// } +@Provider +public class TestFilter implements ContainerRequestFilter { + + @Override + public void filter(ContainerRequestContext requestContext) + throws IOException { + + System.out.println("FILTERED!"); + } + +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/.gitignore ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/.gitignore b/jax-rs.whiteboard/.gitignore new file mode 100644 index 0000000..83ccc54 --- /dev/null +++ b/jax-rs.whiteboard/.gitignore @@ -0,0 +1,2 @@ +/build/ +/bin/ http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/bnd.bnd ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/bnd.bnd b/jax-rs.whiteboard/bnd.bnd new file mode 100644 index 0000000..c18bdf6 --- /dev/null +++ b/jax-rs.whiteboard/bnd.bnd @@ -0,0 +1,61 @@ +Bundle-Activator: com.liferay.portal.remote.rest.extender.activator.CXFJaxRsBundleActivator +Provide-Capability: \ + osgi.implementation; \ + osgi.implementation='aries.jax-rs'; \ + version:Version='${Bundle-Version}' +Require-Capability: \ + osgi.implementation; \ + filter:='(osgi.implementation=osgi.http)' +Import-Package:\ + !com.sun.*,\ + !com.ctc.wstx.*,\ + !javax.imageio.*,\ + !javax.jws.*,\ + !javax.net.*,\ + !javax.security.*,\ + !javax.tools.*,\ + !javax.validation.*,\ + !javax.wsdl.*,\ + !net.sf.cglib.proxy.*,\ + !org.apache.abdera.*,\ + !org.apache.aries.*,\ + !org.apache.cxf.*,\ + !org.apache.neethi.*,\ + !org.apache.velocity.*,\ + !org.apache.xerces.*,\ + !org.apache.xml.resolver.*,\ + !org.apache.xmlbeans.*,\ + !org.codehaus.stax2.*,\ + !org.dom4j.*,\ + !org.junit.*,\ + !org.jvnet.fastinfoset.*,\ + !org.jvnet.staxex.*,\ + !org.ietf.jgss.*,\ + !org.osgi.service.blueprint.*,\ + !org.relaxng.datatype.*,\ + !org.slf4j.spi.*,\ + !org.springframework.*,\ + * + +#Provide-Capability:\ +# osgi.contract;\ +# osgi.contract=JavaJAXRS;\ +# uses:="javax.ws.rs,javax.ws.rs.core,javax.ws.rs.client,javax.ws.rs.container,javax.ws.rs.ext";\ +# version:Version=2,\ +# osgi.contract;\ +# osgi.contract=JavaJSONP;\ +# uses:="javax.json,javax.json.spi,javax.json.stream";\ +# version:Version=1 + +-exportcontents:\ + org.apache.cxf.jaxrs.ext.* + +-includeresource:\ + lib/cxf-core.jar=cxf-core-*.jar;lib:=true,\ + lib/cxf-rt-databinding-jaxb.jar=cxf-rt-databinding-jaxb-*.jar;lib:=true,\ + lib/cxf-rt-frontend-jaxrs.jar=cxf-rt-frontend-jaxrs-*.jar;lib:=true,\ + lib/cxf-rt-rs-extension-providers.jar=cxf-rt-rs-extension-providers-*.jar;lib:=true,\ + lib/cxf-rt-transports-http.jar=cxf-rt-transports-http-*.jar;lib:=true,\ + lib/cxf-tools-common.jar=cxf-tools-common-*.jar;lib:=true,\ + lib/cxf-tools-validator.jar=cxf-tools-validator-*.jar;lib:=true,\ + lib/jettison.jar=jettison-*.jar;lib:=true http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/pom.xml ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/pom.xml b/jax-rs.whiteboard/pom.xml new file mode 100644 index 0000000..10220a1 --- /dev/null +++ b/jax-rs.whiteboard/pom.xml @@ -0,0 +1,82 @@ +<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> + <parent> + <groupId>org.apache.aries</groupId> + <artifactId>org.apache.aries.jax-rs</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + <artifactId>org.apache.aries.jax-rs.whiteboard</artifactId> + <packaging>jar</packaging> + <description>Apache Aries JAX-RS Whiteboard</description> + <dependencies> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + <version>3.0.1</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-databinding-jaxb</artifactId> + <version>3.1.7</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-rs-extension-providers</artifactId> + <version>3.1.7</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxrs</artifactId> + <version>3.1.7</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-transports-http</artifactId> + <version>3.1.7</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-tools-common</artifactId> + <version>3.1.7</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-tools-validator</artifactId> + <version>3.1.7</version> + </dependency> + <dependency> + <groupId>org.codehaus.jettison</groupId> + <artifactId>jettison</artifactId> + <version>1.3.8</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.annotation</artifactId> + <version>6.0.0</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <version>5.0.0</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <version>5.0.0</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.http.api</artifactId> + <version>3.0.0</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.7.2</version> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/activator/CXFJaxRsBundleActivator.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/activator/CXFJaxRsBundleActivator.java b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/activator/CXFJaxRsBundleActivator.java new file mode 100644 index 0000000..d81ff31 --- /dev/null +++ b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/activator/CXFJaxRsBundleActivator.java @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.remote.rest.extender.activator; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Dictionary; +import java.util.Hashtable; + +import javax.ws.rs.ext.RuntimeDelegate; + +import org.apache.cxf.Bus; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Filter; +import org.osgi.framework.wiring.BundleWiring; +import org.osgi.util.tracker.ServiceTracker; + +import com.liferay.portal.remote.rest.extender.internal.BusServiceTrackerCustomizer; +import com.liferay.portal.remote.rest.extender.internal.ServicesServiceTrackerCustomizer; + +/** + * @author Carlos Sierra Andrés + */ +public class CXFJaxRsBundleActivator implements BundleActivator { + + private ServiceTracker<?, ?> _busServiceTracker; + private ServiceTracker<?, ?> _singletonsTracker; + private ServicesRegistrator _servicesRegistrator; + + @Override + public void start(BundleContext bundleContext) throws Exception { + Thread thread = Thread.currentThread(); + + ClassLoader contextClassLoader = thread.getContextClassLoader(); + + Bundle bundle = bundleContext.getBundle(); + + BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); + + thread.setContextClassLoader(bundleWiring.getClassLoader()); + + try { + + // Initialize instance so it is never looked up again + + RuntimeDelegate.getInstance(); + } + finally { + thread.setContextClassLoader(contextClassLoader); + } + + Dictionary<String, Object> runtimeProperties = new Hashtable<>(); + + runtimeProperties.put("endpoints", new ArrayList<String>()); + + // TODO make the context path of the JAX-RS Whiteboard configurable. + + _servicesRegistrator = new ServicesRegistrator(bundleContext); + + _servicesRegistrator.start(); + + _busServiceTracker = new ServiceTracker<>( + bundleContext, Bus.class, + new BusServiceTrackerCustomizer(bundleContext)); + + _busServiceTracker.open(); + + Filter filter = bundleContext.createFilter( + "(jaxrs.application.select=*)"); + + _singletonsTracker = new ServiceTracker<>( + bundleContext, filter, + new ServicesServiceTrackerCustomizer(bundleContext)); + + _singletonsTracker.open(); + } + + @Override + public void stop(BundleContext context) throws Exception { + _busServiceTracker.close(); + + _singletonsTracker.close(); + + _servicesRegistrator.stop(); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/activator/ServicesRegistrator.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/activator/ServicesRegistrator.java b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/activator/ServicesRegistrator.java new file mode 100644 index 0000000..e457674 --- /dev/null +++ b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/activator/ServicesRegistrator.java @@ -0,0 +1,144 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.remote.rest.extender.activator; + +import org.apache.cxf.Bus; +import org.apache.cxf.bus.CXFBusFactory; +import org.apache.cxf.transport.servlet.CXFNonSpringServlet; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.Filter; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.http.context.ServletContextHelper; +import org.osgi.service.http.whiteboard.HttpWhiteboardConstants; +import org.osgi.util.tracker.ServiceTracker; +import org.osgi.util.tracker.ServiceTrackerCustomizer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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; + +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/AddonsServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/AddonsServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/AddonsServiceTrackerCustomizer.java new file mode 100644 index 0000000..8900ded --- /dev/null +++ b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/AddonsServiceTrackerCustomizer.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.remote.rest.extender.internal; + +import com.liferay.portal.remote.rest.extender.internal.CXFJaxRsServiceRegistrator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTrackerCustomizer; + +import javax.ws.rs.ext.Provider; + +/** + * @author Carlos Sierra Andrés + */ +public class AddonsServiceTrackerCustomizer + implements ServiceTrackerCustomizer<CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> { + + private final BundleContext _bundleContext; + private final ClassLoader _classLoader; + private final Class<?> _serviceClass; + private final Object _service; + + public AddonsServiceTrackerCustomizer( + BundleContext bundleContext, ClassLoader classLoader, + Object service) { + + _bundleContext = bundleContext; + _classLoader = classLoader; + _service = service; + + _serviceClass = service.getClass(); + } + + @Override + public CXFJaxRsServiceRegistrator addingService( + ServiceReference<CXFJaxRsServiceRegistrator> reference) { + + Thread thread = Thread.currentThread(); + + ClassLoader contextClassLoader = + thread.getContextClassLoader(); + + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = + _bundleContext.getService(reference); + + try { + thread.setContextClassLoader(_classLoader); + + if (_serviceClass.isAnnotationPresent(Provider.class)) { + cxfJaxRsServiceRegistrator.addProvider(_service); + } else { + cxfJaxRsServiceRegistrator.addService(_service); + } + + return cxfJaxRsServiceRegistrator; + } + catch (Exception e) { + _bundleContext.ungetService(reference); + + throw e; + } + finally { + thread.setContextClassLoader(contextClassLoader); + } + } + + @Override + public void modifiedService( + ServiceReference<CXFJaxRsServiceRegistrator> reference, + CXFJaxRsServiceRegistrator registrator) { + + removedService(reference, registrator); + + addingService(reference); + } + + @Override + public void removedService( + ServiceReference<CXFJaxRsServiceRegistrator> reference, + CXFJaxRsServiceRegistrator registrator) { + + if (_serviceClass.isAnnotationPresent(Provider.class)) { + registrator.removeProvider(_service); + } else { + registrator.removeService(_service); + } + + _bundleContext.ungetService(reference); + } +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/ApplicationServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/ApplicationServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/ApplicationServiceTrackerCustomizer.java new file mode 100644 index 0000000..8296683 --- /dev/null +++ b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/ApplicationServiceTrackerCustomizer.java @@ -0,0 +1,141 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.remote.rest.extender.internal; + +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; + +import javax.ws.rs.core.Application; + +import org.apache.cxf.Bus; +import org.osgi.framework.BundleContext; +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> { + + private BundleContext _bundleContext; + private Bus _bus; + + public ApplicationServiceTrackerCustomizer( + BundleContext bundleContext, Bus bus) { + + _bundleContext = bundleContext; + _bus = bus; + } + + @Override + public Tracked addingService( + ServiceReference<Application> serviceReference) { + + Application application = _bundleContext.getService( + serviceReference); + + try { + String[] propertyKeys = serviceReference.getPropertyKeys(); + + Map<String, Object> properties = new HashMap<>( + propertyKeys.length); + + for (String propertyKey : propertyKeys) { + properties.put( + propertyKey, serviceReference.getProperty(propertyKey)); + } + + properties.put( + "CXF_ENDPOINT_ADDRESS", + serviceReference.getProperty("osgi.jaxrs.application.base"). + toString()); + + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = + new CXFJaxRsServiceRegistrator(_bus, application, properties); + + return new Tracked( + cxfJaxRsServiceRegistrator, application, + _bundleContext.registerService( + CXFJaxRsServiceRegistrator.class, + cxfJaxRsServiceRegistrator, new Hashtable<>(properties))); + } + catch (Throwable e) { + _bundleContext.ungetService(serviceReference); + + throw e; + } + } + + @Override + public void modifiedService( + ServiceReference<Application> serviceReference, Tracked tracked) { + + removedService(serviceReference, tracked); + + addingService(serviceReference); + } + + @Override + public void removedService( + ServiceReference<Application> reference, Tracked tracked) { + + _bundleContext.ungetService(reference); + + tracked.getCxfJaxRsServiceRegistrator().close(); + + tracked.getCxfJaxRsServiceRegistratorServiceRegistration().unregister(); + } + + public static class Tracked { + + private final CXFJaxRsServiceRegistrator _cxfJaxRsServiceRegistrator; + private final Application _application; + private final ServiceRegistration<CXFJaxRsServiceRegistrator> + _cxfJaxRsServiceRegistratorServiceRegistration; + + public Application getApplication() { + return _application; + } + + public CXFJaxRsServiceRegistrator getCxfJaxRsServiceRegistrator() { + return _cxfJaxRsServiceRegistrator; + } + + public ServiceRegistration<CXFJaxRsServiceRegistrator> + getCxfJaxRsServiceRegistratorServiceRegistration() { + + return _cxfJaxRsServiceRegistratorServiceRegistration; + } + + public Tracked( + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator, + Application application, + ServiceRegistration<CXFJaxRsServiceRegistrator> + cxfJaxRsServiceRegistratorServiceRegistration) { + + _cxfJaxRsServiceRegistrator = cxfJaxRsServiceRegistrator; + _application = application; + _cxfJaxRsServiceRegistratorServiceRegistration = + cxfJaxRsServiceRegistratorServiceRegistration; + } + + } +} + + http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/BusServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/BusServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/BusServiceTrackerCustomizer.java new file mode 100644 index 0000000..ba15c1e --- /dev/null +++ b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/BusServiceTrackerCustomizer.java @@ -0,0 +1,117 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.remote.rest.extender.internal; + +import java.util.Arrays; +import java.util.Collection; + +import javax.ws.rs.core.Application; + +import org.apache.cxf.Bus; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Filter; +import org.osgi.framework.InvalidSyntaxException; +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<?, ?>>> { + + private BundleContext _bundleContext; + + public BusServiceTrackerCustomizer(BundleContext bundleContext) { + _bundleContext = bundleContext; + } + + @Override + public Collection<ServiceTracker<?, ?>> + addingService(ServiceReference<Bus> serviceReference) { + + Bus bus = _bundleContext.getService(serviceReference); + + try { + ServiceTracker<Application,?> applicationTracker = + new ServiceTracker<>(_bundleContext, getApplicationFilter(), + new ApplicationServiceTrackerCustomizer( + _bundleContext, bus)); + + applicationTracker.open(); + + ServiceTracker<Object, ?> singletonsServiceTracker = + new ServiceTracker<>(_bundleContext, getSingletonsFilter(), + new SingletonServiceTrackerCustomizer(_bundleContext, bus)); + + singletonsServiceTracker.open(); + + ServiceTracker<Object, ?> filtersAndInterceptorsServiceTracker = + new ServiceTracker<>(_bundleContext, getFiltersFilter(), + new FiltersAndInterceptorsServiceTrackerCustomizer( + _bundleContext)); + + filtersAndInterceptorsServiceTracker.open(); + + return Arrays.asList(applicationTracker, singletonsServiceTracker, filtersAndInterceptorsServiceTracker); + } + catch (InvalidSyntaxException ise) { + throw new RuntimeException(ise); + } + catch (Exception e) { + _bundleContext.ungetService(serviceReference); + + throw e; + } + } + + 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 getSingletonsFilter() throws InvalidSyntaxException { + return _bundleContext.createFilter("(osgi.jaxrs.resource.base=*)"); + } + + @Override + public void modifiedService( + ServiceReference<Bus> reference, + Collection<ServiceTracker<?, ?>> serviceTrackers) { + + removedService(reference, serviceTrackers); + + addingService(reference); + } + + @Override + public void removedService( + ServiceReference<Bus> serviceReference, + Collection<ServiceTracker<?, ?>> serviceTrackers) { + + _bundleContext.ungetService(serviceReference); + + for (ServiceTracker<?, ?> serviceTracker : serviceTrackers) { + serviceTracker.close(); + } + } + +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/CXFJaxRsServiceRegistrator.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/CXFJaxRsServiceRegistrator.java b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/CXFJaxRsServiceRegistrator.java new file mode 100644 index 0000000..7449ec8 --- /dev/null +++ b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/CXFJaxRsServiceRegistrator.java @@ -0,0 +1,148 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.remote.rest.extender.internal; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +import javax.ws.rs.core.Application; +import javax.ws.rs.ext.RuntimeDelegate; + +import org.apache.cxf.Bus; +import org.apache.cxf.endpoint.Server; +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) { + + _bus = bus; + _application = application; + _properties = properties; + + rewire(); + } + + public void close() { + if (_closed) { + return; + } + + if (_server != null) { + _server.destroy(); + } + + _closed = true; + } + + public void addProvider(Object provider) { + if (_closed) { + return; + } + + _providers.add(provider); + + rewire(); + } + + public void addService(Object service) { + if (_closed) { + return; + } + + _services.add(service); + + rewire(); + } + + public void removeProvider(Object provider) { + if (_closed) { + return; + } + + _providers.remove(provider); + + rewire(); + } + + public void removeService(Object service) { + if (_closed) { + return; + } + + _services.remove(service); + + rewire(); + } + + protected synchronized void rewire() { + if (_server != null) { + _server.destroy(); + } + + RuntimeDelegate runtimeDelegate = RuntimeDelegate.getInstance(); + + JAXRSServerFactoryBean jaxRsServerFactoryBean = + runtimeDelegate.createEndpoint( + _application, JAXRSServerFactoryBean.class); + + jaxRsServerFactoryBean.setBus(_bus); + jaxRsServerFactoryBean.setProperties(_properties); + + JSONProvider<Object> jsonProvider = new JSONProvider<>(); + + jsonProvider.setDropCollectionWrapperElement(true); + jsonProvider.setDropRootElement(true); + jsonProvider.setSerializeAsArray(true); + jsonProvider.setSupportUnwrapped(true); + + jaxRsServerFactoryBean.setProvider(jsonProvider); + + for (Object provider : _providers) { + jaxRsServerFactoryBean.setProvider(provider); + } + + for (Object service : _services) { + jaxRsServerFactoryBean.setResourceProvider( + new SingletonResourceProvider(service, true)); + } + + String address = _properties.get("CXF_ENDPOINT_ADDRESS").toString(); + + if (address != null) { + jaxRsServerFactoryBean.setAddress(address); + } + + _server = jaxRsServerFactoryBean.create(); + + _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<>(); + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java new file mode 100644 index 0000000..07e8c7a --- /dev/null +++ b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/FiltersAndInterceptorsServiceTrackerCustomizer.java @@ -0,0 +1,123 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.remote.rest.extender.internal; + +import org.osgi.framework.BundleContext; +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<?, ?>> { + + private BundleContext _bundleContext; + + public FiltersAndInterceptorsServiceTrackerCustomizer( + BundleContext bundleContext) { + + _bundleContext = bundleContext; + } + + @Override + public ServiceTracker<?, ?> addingService(final ServiceReference<Object> reference) { + final String filterBase = + reference.getProperty("osgi.jaxrs.filter.base").toString(); + + final Object service = _bundleContext.getService(reference); + + ServiceTracker<CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> serviceTracker = new ServiceTracker<>( + _bundleContext, CXFJaxRsServiceRegistrator.class, + new ServiceTrackerCustomizer + <CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator>() { + + @Override + public CXFJaxRsServiceRegistrator addingService( + ServiceReference<CXFJaxRsServiceRegistrator> cxfReference) { + + Object resourceBaseObject = + cxfReference.getProperty("CXF_ENDPOINT_ADDRESS"); + + if (resourceBaseObject == null) { + return null; + } + + String resourceBase = resourceBaseObject.toString(); + + if (resourceBase.startsWith(filterBase)) { + CXFJaxRsServiceRegistrator serviceRegistrator = + _bundleContext.getService(cxfReference); + try { + serviceRegistrator.addProvider(service); + + return serviceRegistrator; + } + finally { + _bundleContext.ungetService(reference); + } + } + + return null; + } + + @Override + public void modifiedService( + ServiceReference<CXFJaxRsServiceRegistrator> reference, + CXFJaxRsServiceRegistrator service) { + + removedService(reference, service); + addingService(reference); + } + + @Override + public void removedService( + ServiceReference<CXFJaxRsServiceRegistrator> reference, + CXFJaxRsServiceRegistrator service) { + + CXFJaxRsServiceRegistrator serviceRegistrator = + _bundleContext.getService(reference); + try { + serviceRegistrator.removeProvider(service); + } + finally { + _bundleContext.ungetService(reference); + } + } + }); + + serviceTracker.open(); + + return serviceTracker; + } + + @Override + public void modifiedService( + ServiceReference<Object> reference, ServiceTracker<?, ?> serviceTracker) { + + removedService(reference, serviceTracker); + addingService(reference); + } + + @Override + public void removedService( + ServiceReference<Object> reference, ServiceTracker<?, ?> serviceTracker) { + + _bundleContext.ungetService(reference); + + serviceTracker.close(); + } +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/ServicesServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/ServicesServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/ServicesServiceTrackerCustomizer.java new file mode 100644 index 0000000..433f70c --- /dev/null +++ b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/ServicesServiceTrackerCustomizer.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.remote.rest.extender.internal; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Filter; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; +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, CXFJaxRsServiceRegistrator>> { + + private final BundleContext _bundleContext; + + public ServicesServiceTrackerCustomizer(BundleContext bundleContext) { + _bundleContext = bundleContext; + } + + @Override + public ServiceTracker + <CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> + addingService(ServiceReference<Object> reference) { + + String applicationSelector = + reference.getProperty("jaxrs.application.select").toString(); + + Bundle bundle = reference.getBundle(); + + BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); + + ClassLoader classLoader = bundleWiring.getClassLoader(); + + Object service = _bundleContext.getService(reference); + + try { + Filter filter = _bundleContext.createFilter( + "(&(objectClass=" + CXFJaxRsServiceRegistrator.class.getName() + ")" + + applicationSelector + ")"); + + ServiceTracker + <CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> + serviceTracker = new ServiceTracker<>( + _bundleContext, filter, + new AddonsServiceTrackerCustomizer( + _bundleContext, classLoader, + service)); + + serviceTracker.open(); + + return serviceTracker; + } + catch (InvalidSyntaxException ise) { + _bundleContext.ungetService(reference); + + throw new RuntimeException(ise); + } + } + + @Override + public void modifiedService( + ServiceReference<Object> reference, + ServiceTracker + <CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> + serviceTracker) { + + removedService(reference, serviceTracker); + + addingService(reference); + } + + @Override + public void removedService( + ServiceReference<Object> reference, + ServiceTracker + <CXFJaxRsServiceRegistrator, CXFJaxRsServiceRegistrator> + serviceTracker) { + + serviceTracker.close(); + + _bundleContext.ungetService(reference); + } + +} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/SingletonServiceTrackerCustomizer.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/SingletonServiceTrackerCustomizer.java b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/SingletonServiceTrackerCustomizer.java new file mode 100644 index 0000000..8645504 --- /dev/null +++ b/jax-rs.whiteboard/src/main/java/com/liferay/portal/remote/rest/extender/internal/SingletonServiceTrackerCustomizer.java @@ -0,0 +1,159 @@ +/** + * Copyright (c) 2000-present Liferay, Inc. All rights reserved. + * <p> + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * <p> + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + */ + +package com.liferay.portal.remote.rest.extender.internal; + +import org.apache.cxf.Bus; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.util.tracker.ServiceTrackerCustomizer; + +import javax.ws.rs.core.Application; +import java.util.Collections; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + +/** + * @author Carlos Sierra Andrés + */ +class SingletonServiceTrackerCustomizer + implements ServiceTrackerCustomizer + <Object, SingletonServiceTrackerCustomizer.Tracked> { + + private BundleContext _bundleContext; + private Bus _bus; + + public SingletonServiceTrackerCustomizer( + BundleContext bundleContext, Bus bus) { + + _bundleContext = bundleContext; + _bus = bus; + } + + @Override + public Tracked addingService( + ServiceReference<Object> serviceReference) { + + final Object service = _bundleContext.getService( + serviceReference); + + try { + String[] propertyKeys = serviceReference.getPropertyKeys(); + + 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)); + } + + 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); + + return new Tracked( + cxfJaxRsServiceRegistrator, service, + _bundleContext.registerService( + CXFJaxRsServiceRegistrator.class, + cxfJaxRsServiceRegistrator, new Hashtable<>(properties))); + } + catch (Exception e) { + _bundleContext.ungetService(serviceReference); + + throw e; + } + } + + @Override + public void modifiedService( + ServiceReference<Object> serviceReference, Tracked tracked) { + + removedService(serviceReference, tracked); + + addingService(serviceReference); + } + + @Override + public void removedService( + ServiceReference<Object> reference, Tracked tracked) { + + _bundleContext.ungetService(reference); + + Object service = tracked.getService(); + + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator = + tracked.getCxfJaxRsServiceRegistrator(); + + cxfJaxRsServiceRegistrator.close(); + + tracked.getCxfJaxRsServiceRegistratorServiceRegistration().unregister(); + } + + public static class Tracked { + + private final CXFJaxRsServiceRegistrator _cxfJaxRsServiceRegistrator; + private final Object _service; + private final ServiceRegistration<CXFJaxRsServiceRegistrator> + _cxfJaxRsServiceRegistratorServiceRegistration; + + public Object getService() { + return _service; + } + + public CXFJaxRsServiceRegistrator getCxfJaxRsServiceRegistrator() { + return _cxfJaxRsServiceRegistrator; + } + + public ServiceRegistration<CXFJaxRsServiceRegistrator> + getCxfJaxRsServiceRegistratorServiceRegistration() { + + return _cxfJaxRsServiceRegistratorServiceRegistration; + } + + public Tracked( + CXFJaxRsServiceRegistrator cxfJaxRsServiceRegistrator, + Object service, + ServiceRegistration<CXFJaxRsServiceRegistrator> + cxfJaxRsServiceRegistratorServiceRegistration) { + + _cxfJaxRsServiceRegistrator = cxfJaxRsServiceRegistrator; + _service = service; + _cxfJaxRsServiceRegistratorServiceRegistration = + cxfJaxRsServiceRegistratorServiceRegistration; + } + + } + +} + + http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/org.apache.aries.jax-rs.bndrun/augments.bnd ---------------------------------------------------------------------- diff --git a/org.apache.aries.jax-rs.bndrun/augments.bnd b/org.apache.aries.jax-rs.bndrun/augments.bnd deleted file mode 100644 index 4a16ea5..0000000 --- a/org.apache.aries.jax-rs.bndrun/augments.bnd +++ /dev/null @@ -1,82 +0,0 @@ --augment.javax.servlet-api: \ - javax.servlet-api; \ - requirement:="osgi.implementation;filter:='(osgi.implementation=osgi.http)'" - --augment.javax.ws.rs-api: \ - javax.ws.rs-api; \ - requirement:="osgi.implementation;filter:='(osgi.implementation=osgi.http)'" - --augment.org.apache.aries.jax-rs.cxf-common: \ - org.apache.aries.jax-rs.cxf-common; \ - requirement:="osgi.extender;filter:='(&(osgi.extender=aries.jax-rs)(version>=1.0.0)(!(version>=2.0.0)))', \ - osgi.implementation;filter:='(osgi.implementation=osgi.http)'" - --augment.org.apache.commons.fileupload: \ - org.apache.commons.fileupload; \ - capability:=" generic.dependency;generic.dependency='commons.fileupload'" - --augment.org.apache.felix.gogo.command: \ - org.apache.felix.gogo.command; \ - capability:=" generic.dependency;generic.dependency='gogo.shell.command';version:Version='1.0.0'"; \ - version='1.0.0' - --augment.org.apache.felix.gogo.shell: \ - org.apache.felix.gogo.shell; \ - capability:=" osgi.implementation;osgi.implementation='gogo.shell';version:Version='1.0.0'"; \ - requirement:="generic.dependency;filter:='(generic.dependency=gogo.shell.command)';effective:=active"; \ - version='1.0.0' - --augment.org.apache.felix.gogo.jline: \ - org.apache.felix.gogo.jline; \ - capability:=" osgi.implementation;osgi.implementation='gogo.jline';version:Version='1.0.0'"; \ - requirement:="generic.dependency;filter:='(generic.dependency=gogo.shell.command)';effective:=active"; \ - version='1.0.0' - --augment.org.apache.felix.log: \ - org.apache.felix.log; \ - capability:=" osgi.implementation;osgi.implementation=osgi.log" - --augment.org.apache.felix.scr: \ - org.apache.felix.scr; \ - requirement:="osgi.implementation;filter:='(osgi.implementation=osgi.metatype)'" - --augment.org.eclipse.equinox.coordinator: \ - org.eclipse.equinox.coordinator; \ - capability:=" osgi.service;objectClass=org.osgi.service.coordinator.Coordinator;effective:=active, \ - osgi.implementation;osgi.implementation=osgi.coordinator" - --augment.org.eclipse.equinox.event: \ - org.eclipse.equinox.event; \ - capability:=" osgi.service;objectClass=org.osgi.service.event.EventAdmin;effective:=active, \ - osgi.implementation;osgi.implementation=osgi.event"; \ - requirement:="osgi.extender;filter:='(osgi.extender=osgi.component)'" - --augment.org.eclipse.equinox.http.jetty: \ - org.eclipse.equinox.http.jetty; \ - capability:=" equinox.module.data;activation.policy=eager, \ - generic.dependency;generic.dependency='osgi.servlet.container';version:Version='1.0.0'" - --augment.org.eclipse.equinox.http.servlet: \ - org.eclipse.equinox.http.servlet; \ - capability:=" equinox.module.data;activation.policy=eager"; \ - requirement:="generic.dependency;filter:='(generic.dependency=commons.fileupload)';effective:=active,\ - generic.dependency;filter:='(generic.dependency=osgi.servlet.container)';effective:=active" - --augment.org.knopflerfish.bundle.useradmin: \ - org.knopflerfish.bundle.useradmin; \ - capability:=" osgi.service;objectClass:List<String>=org.osgi.service.useradmin.UserAdmin;effective:=active, \ - osgi.implementation;osgi.implementation=osgi.useradmin" - --augment.org.osgi.service.event: \ - org.osgi.service.event; \ - requirement:="osgi.implementation;filter:='(osgi.implementation=osgi.event)'" - --augment.org.osgi.service.metatype: \ - org.osgi.service.metatype; \ - requirement:="osgi.implementation;filter:='(osgi.implementation=osgi.metatype)'" - --augment.org.osgi.service.remoteserviceadmin: \ - org.osgi.service.remoteserviceadmin; \ - requirement:="osgi.remoteserviceadmin.distribution;filter:='(configs=*)', \ - osgi.remoteserviceadmin.topology;filter:='(policy=*)', \ - osgi.remoteserviceadmin.discovery;filter:='(protocols=*)'" \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/org.apache.aries.jax-rs.bndrun/pom.xml ---------------------------------------------------------------------- diff --git a/org.apache.aries.jax-rs.bndrun/pom.xml b/org.apache.aries.jax-rs.bndrun/pom.xml deleted file mode 100644 index eecbde1..0000000 --- a/org.apache.aries.jax-rs.bndrun/pom.xml +++ /dev/null @@ -1,69 +0,0 @@ -<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> - - <parent> - <groupId>org.apache.aries</groupId> - <artifactId>org.apache.aries.jax-rs</artifactId> - <version>1.0.0-SNAPSHOT</version> - </parent> - - <artifactId>org.apache.aries.jax-rs.bndrun</artifactId> - - <packaging>jar</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>true</resolve> - <bndruns> - <bndrun>run.bndrun</bndrun> - </bndruns> - <targetDir>.</targetDir> - </configuration> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>org.apache.aries</groupId> - <artifactId>org.apache.aries.jax-rs.example</artifactId> - <version>1.0.0-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.aries</groupId> - <artifactId>org.apache.aries.jax-rs.extender</artifactId> - <version>1.0.0-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.apache.felix</groupId> - <artifactId>org.apache.felix.gogo.runtime</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> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/org.apache.aries.jax-rs.bndrun/run.bndrun ---------------------------------------------------------------------- diff --git a/org.apache.aries.jax-rs.bndrun/run.bndrun b/org.apache.aries.jax-rs.bndrun/run.bndrun deleted file mode 100644 index 248a200..0000000 --- a/org.apache.aries.jax-rs.bndrun/run.bndrun +++ /dev/null @@ -1,52 +0,0 @@ --standalone: --include: ${.}/augments.bnd --resourceonly: true - --plugin.A.pom.repo = \ - aQute.bnd.repository.maven.pom.provider.BndPomRepository; \ - snapshotUrls=https://oss.sonatype.org/content/repositories/osgi/; \ - releaseUrls=https://repo1.maven.org/maven2/; \ - pom=${.}/pom.xml; \ - name=pom.repo; \ - location=${.}/target/cached.xml - --runrequires: \ - osgi.identity;filter:='(osgi.identity=org.apache.aries.jax-rs.example)',\ - osgi.identity;filter:='(osgi.identity=org.apache.aries.jax-rs.extender)',\ - osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.jline)' - --runfw: org.eclipse.osgi;version='[3.10.100.v20150529-1857,3.10.100.v20150529-1857]' --runbundles: \ - javax.annotation-api;version='[1.2.0,1.2.1)',\ - javax.json-api;version='[1.0.0,1.0.1)',\ - javax.ws.rs-api;version='[2.0.1,2.0.2)',\ - log4j;version='[1.2.17,1.2.18)',\ - org.apache.aries.jax-rs.example;version='[1.0.0,1.0.1)',\ - org.apache.aries.jax-rs.extender;version='[1.0.0,1.0.1)',\ - org.apache.felix.bundlerepository;version='[1.6.0,1.6.1)',\ - org.apache.felix.configadmin;version='[1.8.8,1.8.9)',\ - org.apache.felix.gogo.command;version='[1.0.0,1.0.1)',\ - org.apache.felix.gogo.jline;version='[1.0.0,1.0.1)',\ - org.apache.felix.gogo.runtime;version='[1.0.0,1.0.1)',\ - org.apache.felix.http.api;version='[3.0.0,3.0.1)',\ - org.apache.felix.http.jetty;version='[3.4.0,3.4.1)',\ - org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\ - org.apache.felix.scr;version='[2.0.2,2.0.3)',\ - org.apache.ws.xmlschema.core;version='[2.2.1,2.2.2)',\ - org.eclipse.equinox.event;version='[1.3.100,1.3.101)',\ - org.eclipse.equinox.metatype;version='[1.4.100,1.4.101)',\ - org.jline;version='[3.0.0,3.0.1)',\ - org.objectweb.asm;version='[5.0.4,5.0.5)',\ - org.osgi.compendium;version='[4.1.0,4.1.1)',\ - org.osgi.service.event;version='[1.3.1,1.3.2)',\ - org.osgi.service.metatype;version='[1.3.0,1.3.1)',\ - slf4j.api;version='[1.7.21,1.7.22)',\ - slf4j.log4j12;version='[1.6.1,1.6.2)' - --runee: JavaSE-1.8 --resolve.effective: resolve, active --runproperties.eqnx: \ - osgi.console.enable.builtin=false, \ - osgi.console=, \ - org.osgi.service.http.port=8080 --runsystemcapabilities.dflt: ${native_capability} http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/76e7db85/org.apache.aries.jax-rs.example/.gitignore ---------------------------------------------------------------------- diff --git a/org.apache.aries.jax-rs.example/.gitignore b/org.apache.aries.jax-rs.example/.gitignore deleted file mode 100644 index 83ccc54..0000000 --- a/org.apache.aries.jax-rs.example/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/build/ -/bin/
