From b6aae6907f3d247e5d590bb25f6cb009e17584f8 Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Tue, 16 Jul 2019 18:49:53 +0200 Subject: [PATCH] Revert "openHAB JAX-RS publisher (#905)" This reverts commit ad81f040de3e155a03415f1029bcb25490cb0596. --- bom/compile/pom.xml | 4 +- bom/openhab-core/pom.xml | 2 +- bom/runtime/pom.xml | 6 +- bundles/org.openhab.core.io.rest.auth/pom.xml | 8 - .../internal/SmartHomeRestServletConfig.java | 3 +- .../rest/core/internal/RESTCoreActivator.java | 3 +- .../.classpath | 33 --- .../.project | 23 -- .../org.openhab.core.io.rest.publisher/NOTICE | 14 -- .../pom.xml | 61 ----- .../publisher/ApplicationConfiguration.java | 37 --- .../jaxrs/publisher/ResourceFilter.java | 45 ---- .../jaxrs/publisher/ServiceProperties.java | 27 -- .../jaxrs/publisher/ServletConfiguration.java | 51 ---- .../jaxrs/publisher/internal/Activator.java | 106 -------- .../publisher/internal/AllResourceFilter.java | 45 ---- .../ApplicationConfigurationTracker.java | 43 ---- .../publisher/internal/Configuration.java | 77 ------ .../DefaultApplicationConfiguration.java | 31 --- .../jaxrs/publisher/internal/HttpTracker.java | 40 --- .../publisher/internal/JAXRSConnector.java | 237 ------------------ .../publisher/internal/JerseyContext.java | 219 ---------------- .../publisher/internal/ResourcePublisher.java | 77 ------ .../publisher/internal/RootApplication.java | 104 -------- .../publisher/internal/ServiceContainer.java | 119 --------- .../internal/ServletConfigurationTracker.java | 44 ---- .../internal/ServletContainerBridge.java | 103 -------- .../internal/JAXRSConnectorProvider.java | 33 --- .../internal/ResourceRegistrator.java | 111 -------- .../smarthome/io/rest/JSONResponse.java | 2 +- .../smarthome/io/rest/OhJAXRSResource.java | 30 --- .../io/rest/internal/filter/ProxyFilter.java | 6 +- .../rest/internal/resources/RootResource.java | 5 +- bundles/pom.xml | 2 +- .../openhab-core/src/main/feature/feature.xml | 2 +- .../openhab-tp/src/main/feature/feature.xml | 1 + 36 files changed, 17 insertions(+), 1737 deletions(-) delete mode 100644 bundles/org.openhab.core.io.rest.publisher/.classpath delete mode 100644 bundles/org.openhab.core.io.rest.publisher/.project delete mode 100644 bundles/org.openhab.core.io.rest.publisher/NOTICE delete mode 100644 bundles/org.openhab.core.io.rest.publisher/pom.xml delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ApplicationConfiguration.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ResourceFilter.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ServiceProperties.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ServletConfiguration.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/Activator.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/AllResourceFilter.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ApplicationConfigurationTracker.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/Configuration.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/DefaultApplicationConfiguration.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/HttpTracker.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/JAXRSConnector.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/JerseyContext.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ResourcePublisher.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/RootApplication.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServiceContainer.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServletConfigurationTracker.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServletContainerBridge.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/main/java/org/openhab/core/io/rest/publisher/internal/JAXRSConnectorProvider.java delete mode 100644 bundles/org.openhab.core.io.rest.publisher/src/main/java/org/openhab/core/io/rest/publisher/internal/ResourceRegistrator.java delete mode 100644 bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/OhJAXRSResource.java diff --git a/bom/compile/pom.xml b/bom/compile/pom.xml index be3a6d9ac..6748c8a95 100644 --- a/bom/compile/pom.xml +++ b/bom/compile/pom.xml @@ -91,8 +91,8 @@ com.eclipsesource.jaxrs - jersey-all - 2.22.2 + publisher + 5.3.1 compile diff --git a/bom/openhab-core/pom.xml b/bom/openhab-core/pom.xml index babcbeb73..1046fb14b 100644 --- a/bom/openhab-core/pom.xml +++ b/bom/openhab-core/pom.xml @@ -233,7 +233,7 @@ org.openhab.core.bundles - org.openhab.core.io.rest.publisher + org.openhab.core.io.rest.optimize ${project.version} compile diff --git a/bom/runtime/pom.xml b/bom/runtime/pom.xml index e319b641a..71da00184 100644 --- a/bom/runtime/pom.xml +++ b/bom/runtime/pom.xml @@ -852,11 +852,11 @@ compile - + com.eclipsesource.jaxrs - jersey-all - 2.22.2 + publisher + 5.3.1 compile diff --git a/bundles/org.openhab.core.io.rest.auth/pom.xml b/bundles/org.openhab.core.io.rest.auth/pom.xml index 58ed5f1e0..476a6a5d3 100644 --- a/bundles/org.openhab.core.io.rest.auth/pom.xml +++ b/bundles/org.openhab.core.io.rest.auth/pom.xml @@ -13,12 +13,4 @@ openHAB Core :: Bundles :: Authentication Support for the REST Interface - - - org.openhab.core.bundles - org.openhab.core.io.rest.publisher - ${project.version} - - - diff --git a/bundles/org.openhab.core.io.rest.auth/src/main/java/org/eclipse/smarthome/io/rest/auth/internal/SmartHomeRestServletConfig.java b/bundles/org.openhab.core.io.rest.auth/src/main/java/org/eclipse/smarthome/io/rest/auth/internal/SmartHomeRestServletConfig.java index 4a6479462..b397a6a60 100644 --- a/bundles/org.openhab.core.io.rest.auth/src/main/java/org/eclipse/smarthome/io/rest/auth/internal/SmartHomeRestServletConfig.java +++ b/bundles/org.openhab.core.io.rest.auth/src/main/java/org/eclipse/smarthome/io/rest/auth/internal/SmartHomeRestServletConfig.java @@ -15,12 +15,13 @@ package org.eclipse.smarthome.io.rest.auth.internal; import java.util.Dictionary; import java.util.Hashtable; -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.ServletConfiguration; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import org.osgi.service.http.HttpContext; import org.osgi.service.http.HttpService; +import com.eclipsesource.jaxrs.publisher.ServletConfiguration; + /** * Custom servlet configuration for jaxrs handler. * diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/eclipse/smarthome/io/rest/core/internal/RESTCoreActivator.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/eclipse/smarthome/io/rest/core/internal/RESTCoreActivator.java index c5a023627..41e02ffc3 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/eclipse/smarthome/io/rest/core/internal/RESTCoreActivator.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/eclipse/smarthome/io/rest/core/internal/RESTCoreActivator.java @@ -13,7 +13,6 @@ package org.eclipse.smarthome.io.rest.core.internal; import org.eclipse.smarthome.io.rest.JSONResponse; -import org.eclipse.smarthome.io.rest.OhJAXRSResource; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; @@ -36,7 +35,7 @@ public class RESTCoreActivator implements BundleActivator { @Override public void start(BundleContext bc) throws Exception { context = bc; - mExcMapper = bc.registerService(OhJAXRSResource.class, new JSONResponse.ExceptionMapper(), null); + mExcMapper = bc.registerService(JSONResponse.ExceptionMapper.class.getName(), new JSONResponse.ExceptionMapper(), null); } /** diff --git a/bundles/org.openhab.core.io.rest.publisher/.classpath b/bundles/org.openhab.core.io.rest.publisher/.classpath deleted file mode 100644 index 8ae5ac7df..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/.classpath +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bundles/org.openhab.core.io.rest.publisher/.project b/bundles/org.openhab.core.io.rest.publisher/.project deleted file mode 100644 index 1ad0a94d7..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - org.openhab.core.io.rest.publisher - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - diff --git a/bundles/org.openhab.core.io.rest.publisher/NOTICE b/bundles/org.openhab.core.io.rest.publisher/NOTICE deleted file mode 100644 index 6c17d0d8a..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/NOTICE +++ /dev/null @@ -1,14 +0,0 @@ -This content is produced and maintained by the openHAB project. - -* Project home: https://www.openhab.org - -== Declared Project Licenses - -This program and the accompanying materials are made available under the terms -of the Eclipse Public License 2.0 which is available at -https://www.eclipse.org/legal/epl-2.0/. - -== Source Code - -https://github.com/openhab/openhab-core - diff --git a/bundles/org.openhab.core.io.rest.publisher/pom.xml b/bundles/org.openhab.core.io.rest.publisher/pom.xml deleted file mode 100644 index 6c39645d1..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/pom.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - 4.0.0 - - - org.openhab.core.bundles - org.openhab.core.reactor.bundles - 2.5.0-SNAPSHOT - - - org.openhab.core.io.rest.publisher - - openHAB Core :: Bundles :: REST Interface :: Publisher - - - - org.openhab.core.bundles - org.openhab.core.io.rest - ${project.version} - - - org.openhab.core.bundles - org.openhab.core.io.rest.sse - ${project.version} - - - - - - - org.openhab.tools.sat - sat-plugin - - - sat-all - none - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - - add-source - - generate-sources - - - src/3rdparty/java - - - - - - - - - diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ApplicationConfiguration.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ApplicationConfiguration.java deleted file mode 100644 index 1a6625000..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ApplicationConfiguration.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation, ongoing development - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher; - -import java.util.Map; - -import javax.ws.rs.core.Application; - -/** - *

- * Service that allows configuration of the JAX-RS {@link Application}. Multiple registrations will be tracked. - *

- * - * @since 4.3 - */ -public interface ApplicationConfiguration { - - /** - *

- * Will be called before the JAX-RS {@link Application} is registered. Please note that - * one {@link ApplicationConfiguration} can overwrite the values of other {@link ApplicationConfiguration}s. It - * depends on the order they are available in the OSGi container. - *

- * - * @see Application#getProperties() - */ - Map getProperties(); - -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ResourceFilter.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ResourceFilter.java deleted file mode 100644 index 29c18c918..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ResourceFilter.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher; - -import org.osgi.framework.Filter; -import org.osgi.util.tracker.ServiceTracker; - -/** - *

- * The JAX-RS publisher uses a {@link ServiceTracker} to track all services. If one has an @Path, @Provider etc. - * annotation it will be published. In rare cases it's necessary to modify the filter for the tracker e.g. to only - * publish resource starting with "com.foo.*". - *

- *

- * To accomplish this you can register a {@link ResourceFilter} as an OSGi service. The JAX-RS publisher will prefer - * use this service to construct it's {@link ServiceTracker}. - *

- * - *

- * Please Note: Right now the {@link ResourceFilter} service must be registered before the publisher bundle - * is started. Dynamic behavior may follow in future versions. - *

- * - * @see Filter - * - * @since 4.0 - */ -public interface ResourceFilter { - - /** - *

- * The OSGi filter to use for tracking the Resources. Must not return null. - *

- */ - Filter getFilter(); - -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ServiceProperties.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ServiceProperties.java deleted file mode 100644 index b60267bef..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ServiceProperties.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation, ongoing development - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher; - -public class ServiceProperties { - - /** - *

- * When registering a @Path or @Provider annotated object as an OSGi service the connector does publish - * this resource automatically. Anyway, in some scenarios it's not wanted to publish those services. If you - * want a resource not publish set this property as a service property with the value false. - *

- */ - public static String PUBLISH = "com.eclipsesource.jaxrs.publish"; - - private ServiceProperties() { - // prevent instantiation - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ServletConfiguration.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ServletConfiguration.java deleted file mode 100644 index 9432e9c2c..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/ServletConfiguration.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Ivan Iliev and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ivan Iliev - initial API and implementation - * Holger Staudacher - ongoing development - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher; - -import java.util.Dictionary; - -import org.osgi.service.http.HttpContext; -import org.osgi.service.http.HttpService; - -/** - *

- * Service that allows contribution of initial parameters and HttpContext for the Jersey servlet. - * Only the first tracked service implementing this interface will be used. - *

- * - * @since 4.2 - */ -public interface ServletConfiguration { - - /** - *

- * Returns an HttpContext or null for the given httpService and rootPath. - *

- * - * @param httpService the {@link HttpService} to configure the servlet for. - * @param rootPath the configured root path of the servlet to register. - * @return the {@link HttpContext} to use for the servlet registration. - */ - HttpContext getHttpContext(HttpService httpService, String rootPath); - - /** - *

- * Returns initial parameters or null for the given httpService and rootPath. - *

- * - * @param httpService the {@link HttpService} to configure the servlet for. - * @param rootPath the configured root path of the servlet to register. - * @return the init properties to use for the servlet registration. - */ - Dictionary getInitParams(HttpService httpService, String rootPath); - -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/Activator.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/Activator.java deleted file mode 100644 index f1e6493a8..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/Activator.java +++ /dev/null @@ -1,106 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012,2015 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation - * ProSyst Software GmbH. - compatibility with OSGi specification 4.2 APIs - * Ivan Iliev - added ServletConfigurationTracker - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import java.util.Dictionary; -import java.util.Hashtable; - -import javax.ws.rs.Path; - -import org.openhab.core.io.rest.publisher.internal.JAXRSConnectorProvider; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.Constants; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.cm.ManagedService; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Deactivate; - -@Component -public class Activator implements JAXRSConnectorProvider { - - private ServiceRegistration connectorRegistration; - private JAXRSConnector jaxRsConnector; - private HttpTracker httpTracker; - private ServletConfigurationTracker servletConfigurationTracker; - private ApplicationConfigurationTracker applicationConfigurationTracker; - private ServiceRegistration configRegistration; - - @Activate - public Activator(final BundleContext context) { - jaxRsConnector = new JAXRSConnector(context); - } - - @Activate - public void start(BundleContext context) throws Exception { - System.setProperty("javax.ws.rs.ext.RuntimeDelegate", - "org.glassfish.jersey.server.internal.RuntimeDelegateImpl"); - startJerseyServer(); - registerConfiguration(context); - connectorRegistration = context.registerService(JAXRSConnector.class, jaxRsConnector, null); - openHttpServiceTracker(context); - openServletConfigurationTracker(context); - openApplicationConfigurationTracker(context); - } - - @Deactivate - public void stop(BundleContext context) throws Exception { - httpTracker.close(); - servletConfigurationTracker.close(); - applicationConfigurationTracker.close(); - connectorRegistration.unregister(); - configRegistration.unregister(); - } - - private void registerConfiguration(BundleContext context) { - Dictionary properties = new Hashtable<>(); - properties.put(Constants.SERVICE_PID, Configuration.CONFIG_SERVICE_PID); - configRegistration = context.registerService(ManagedService.class, new Configuration(jaxRsConnector), - properties); - } - - private void startJerseyServer() throws BundleException { - Bundle bundle = getJerseyAPIBundle(); - if (bundle.getState() != Bundle.ACTIVE) { - bundle.start(); - } - } - - private void openHttpServiceTracker(BundleContext context) { - httpTracker = new HttpTracker(context, jaxRsConnector); - httpTracker.open(); - } - - private void openServletConfigurationTracker(BundleContext context) { - servletConfigurationTracker = new ServletConfigurationTracker(context, jaxRsConnector); - servletConfigurationTracker.open(); - } - - private void openApplicationConfigurationTracker(BundleContext context) { - applicationConfigurationTracker = new ApplicationConfigurationTracker(context, jaxRsConnector); - applicationConfigurationTracker.open(); - } - - // For testing purpose - Bundle getJerseyAPIBundle() { - return FrameworkUtil.getBundle(Path.class); - } - - @Override - public JAXRSConnector getJAXRSConnector() { - return jaxRsConnector; - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/AllResourceFilter.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/AllResourceFilter.java deleted file mode 100644 index 3be870f33..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/AllResourceFilter.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import static org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.ServiceProperties.PUBLISH; - -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.ResourceFilter; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.InvalidSyntaxException; - -public class AllResourceFilter implements ResourceFilter { - - static final String ANY_SERVICE_FILTER = "(&(objectClass=*)(!(" + PUBLISH + "=false)))"; - - private final BundleContext context; - - public AllResourceFilter(BundleContext context) { - validateContext(context); - this.context = context; - } - - private void validateContext(BundleContext context) { - if (context == null) { - throw new IllegalArgumentException("context must not be null"); - } - } - - @Override - public Filter getFilter() { - try { - return context.createFilter(ANY_SERVICE_FILTER); - } catch (InvalidSyntaxException willNotHappen) { - throw new IllegalStateException(willNotHappen); - } - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ApplicationConfigurationTracker.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ApplicationConfigurationTracker.java deleted file mode 100644 index 880eaa190..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ApplicationConfigurationTracker.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Holger Staudacher and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.ApplicationConfiguration; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; - -/** - *

- * Tracker for OSGi Services implementing the {@link ApplicationConfiguration} interface. - *

- */ -public class ApplicationConfigurationTracker extends ServiceTracker { - - private final JAXRSConnector connector; - - ApplicationConfigurationTracker(BundleContext context, JAXRSConnector connector) { - super(context, ApplicationConfiguration.class.getName(), null); - this.connector = connector; - } - - @Override - public Object addingService(ServiceReference reference) { - return connector.addApplicationConfiguration(reference); - } - - @Override - public void removedService(ServiceReference reference, Object service) { - if (service instanceof ApplicationConfiguration) { - connector.removeApplicationConfiguration(reference, (ApplicationConfiguration) service); - } - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/Configuration.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/Configuration.java deleted file mode 100644 index 8645e8434..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/Configuration.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012,2015 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation, ongoing development - * ProSyst Software GmbH. - compatibility with OSGi specification 4.2 APIs - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import java.util.Dictionary; - -import org.osgi.service.cm.ConfigurationException; -import org.osgi.service.cm.ManagedService; - -@SuppressWarnings("rawtypes") -public class Configuration implements ManagedService { - - static final String CONFIG_SERVICE_PID = "com.eclipsesource.jaxrs.connector"; - static final String PROPERTY_ROOT = "root"; - static final String PROPERTY_PUBLISH_DELAY = "publishDelay"; - static final long DEFAULT_PUBLISH_DELAY = 150; - - private final JAXRSConnector connector; - private long publishDelay; - private String rootPath; - - public Configuration(JAXRSConnector jaxRsConnector) { - this.connector = jaxRsConnector; - this.publishDelay = DEFAULT_PUBLISH_DELAY; - } - - @Override - public void updated(Dictionary properties) throws ConfigurationException { - if (properties != null) { - Object root = properties.get(PROPERTY_ROOT); - ensureRootIsPresent(root); - String rootPath = (String) root; - ensureRootIsValid(rootPath); - this.rootPath = rootPath; - this.publishDelay = getPublishDelay(properties); - connector.updateConfiguration(this); - } - } - - private void ensureRootIsValid(String rootPath) throws ConfigurationException { - if (!rootPath.startsWith("/")) { - throw new ConfigurationException(PROPERTY_ROOT, "Root path does not start with a /"); - } - } - - private void ensureRootIsPresent(Object root) throws ConfigurationException { - if (root == null || !(root instanceof String)) { - throw new ConfigurationException(PROPERTY_ROOT, "Property is not set or invalid."); - } - } - - private long getPublishDelay(Dictionary properties) { - Object interval = properties.get(PROPERTY_PUBLISH_DELAY); - if (interval == null) { - return DEFAULT_PUBLISH_DELAY; - } - return ((Long) interval); - } - - public long getPublishDelay() { - return publishDelay; - } - - public String getRoothPath() { - return rootPath == null ? "/services" : rootPath; - } - -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/DefaultApplicationConfiguration.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/DefaultApplicationConfiguration.java deleted file mode 100644 index cf5ee50f0..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/DefaultApplicationConfiguration.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation, ongoing development - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import java.util.HashMap; -import java.util.Map; - -import org.glassfish.jersey.server.ServerProperties; -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.ApplicationConfiguration; - -public class DefaultApplicationConfiguration implements ApplicationConfiguration { - - @Override - public Map getProperties() { - Map properties = new HashMap<>(); - // don't look for implementations described by META-INF/services/* - properties.put(ServerProperties.METAINF_SERVICES_LOOKUP_DISABLE, false); - // disable auto discovery on server, as it's handled via OSGI - properties.put(ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true); - return properties; - } - -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/HttpTracker.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/HttpTracker.java deleted file mode 100644 index 2e07dc912..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/HttpTracker.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011,2015 Frank Appel and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Frank Appel - initial API and implementation - * Holger Staudacher - ongoing development - * ProSyst Software GmbH. - compatibility with OSGi specification 4.2 APIs - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.http.HttpService; -import org.osgi.util.tracker.ServiceTracker; - -public class HttpTracker extends ServiceTracker { - - private final JAXRSConnector connector; - - HttpTracker(BundleContext context, JAXRSConnector connector) { - super(context, HttpService.class.getName(), null); - this.connector = connector; - } - - @Override - public Object addingService(ServiceReference reference) { - return connector.addHttpService(reference); - } - - @Override - public void removedService(ServiceReference reference, Object service) { - if (service instanceof HttpService) { - connector.removeHttpService((HttpService) service); - } - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/JAXRSConnector.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/JAXRSConnector.java deleted file mode 100644 index 6d418294d..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/JAXRSConnector.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012,2015 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation - * ProSyst Software GmbH. - compatibility with OSGi specification 4.2 APIs - * Ivan Iliev - Performance Optimizations - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.ApplicationConfiguration; -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.ServletConfiguration; -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal.ServiceContainer.ServiceHolder; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.http.HttpService; - -public class JAXRSConnector { - - private static final String HTTP_SERVICE_PORT_PROPERTY = "org.osgi.service.http.port"; - private static final String RESOURCE_HTTP_PORT_PROPERTY = "http.port"; - private static final String DEFAULT_HTTP_PORT = "80"; - - private final Object lock = new Object(); - private final ServiceContainer httpServices; - private final ServiceContainer resources; - private final Map contextMap; - private final BundleContext bundleContext; - private final List resourceCache; - private ServletConfiguration servletConfiguration; - private final ServiceContainer applicationConfigurations; - private Configuration configuration; - - JAXRSConnector(BundleContext bundleContext) { - this.bundleContext = bundleContext; - this.configuration = new Configuration(this); - this.httpServices = new ServiceContainer(bundleContext); - this.resources = new ServiceContainer(bundleContext); - this.contextMap = new HashMap<>(); - this.resourceCache = new ArrayList<>(); - this.applicationConfigurations = new ServiceContainer(bundleContext); - } - - void updateConfiguration(Configuration configuration) { - synchronized (lock) { - this.configuration = configuration; - doUpdateConfiguration(configuration); - } - } - - HttpService addHttpService(ServiceReference reference) { - synchronized (lock) { - return doAddHttpService(reference); - } - } - - ServletConfiguration setServletConfiguration(ServiceReference reference) { - if (servletConfiguration == null) { - servletConfiguration = (ServletConfiguration) bundleContext.getService(reference); - doUpdateServletConfiguration(); - return servletConfiguration; - } - return null; - } - - void unsetServletConfiguration(ServiceReference reference, ServletConfiguration service) { - if (servletConfiguration == service) { - servletConfiguration = null; - bundleContext.ungetService(reference); - doUpdateServletConfiguration(); - } - } - - ApplicationConfiguration addApplicationConfiguration(ServiceReference reference) { - synchronized (lock) { - ApplicationConfiguration service = (ApplicationConfiguration) applicationConfigurations.add(reference) - .getService(); - doUpdateAppConfiguration(); - return service; - } - } - - void removeApplicationConfiguration(ServiceReference reference, ApplicationConfiguration service) { - synchronized (lock) { - applicationConfigurations.remove(service); - doUpdateAppConfiguration(); - } - } - - private void doUpdateServletConfiguration() { - ServiceHolder[] services = httpServices.getServices(); - for (ServiceHolder serviceHolder : services) { - contextMap.get(serviceHolder.getService()).updateServletConfiguration(servletConfiguration); - } - } - - private void doUpdateAppConfiguration() { - ServiceHolder[] services = httpServices.getServices(); - for (ServiceHolder serviceHolder : services) { - contextMap.get(serviceHolder.getService()).updateAppConfiguration(applicationConfigurations); - } - } - - private void doUpdateConfiguration(Configuration configuration) { - ServiceHolder[] services = httpServices.getServices(); - for (ServiceHolder serviceHolder : services) { - contextMap.get(serviceHolder.getService()).updateConfiguration(configuration); - } - } - - HttpService doAddHttpService(ServiceReference reference) { - ServiceHolder serviceHolder = httpServices.add(reference); - HttpService service = (HttpService) serviceHolder.getService(); - contextMap.put(service, createJerseyContext(service, configuration, servletConfiguration)); - clearCache(); - return service; - } - - private void clearCache() { - List cache = new ArrayList<>(resourceCache); - resourceCache.clear(); - for (ServiceHolder serviceHolder : cache) { - registerResource(serviceHolder); - } - } - - void removeHttpService(HttpService service) { - synchronized (lock) { - doRemoveHttpService(service); - } - } - - void doRemoveHttpService(HttpService service) { - JerseyContext context = contextMap.remove(service); - if (context != null) { - cacheFreedResources(context); - } - httpServices.remove(service); - } - - private void cacheFreedResources(JerseyContext context) { - List freeResources = context.eliminate(); - for (Object resource : freeResources) { - resourceCache.add(resources.find(resource)); - } - } - - public Object addResource(ServiceReference reference) { - synchronized (lock) { - return doAddResource(reference); - } - } - - private Object doAddResource(ServiceReference reference) { - ServiceHolder serviceHolder = resources.add(reference); - registerResource(serviceHolder); - return serviceHolder.getService(); - } - - private void registerResource(ServiceHolder serviceHolder) { - Object port = getPort(serviceHolder); - registerResource(serviceHolder, port); - } - - private Object getPort(ServiceHolder serviceHolder) { - Object port = serviceHolder.getReference().getProperty(RESOURCE_HTTP_PORT_PROPERTY); - if (port == null) { - port = bundleContext.getProperty(HTTP_SERVICE_PORT_PROPERTY); - if (port == null) { - port = DEFAULT_HTTP_PORT; - } - } - return port; - } - - private void registerResource(ServiceHolder serviceHolder, Object port) { - HttpService service = findHttpServiceForPort(port); - if (service != null) { - JerseyContext jerseyContext = contextMap.get(service); - jerseyContext.addResource(serviceHolder.getService()); - } else { - cacheResource(serviceHolder); - } - } - - private void cacheResource(ServiceHolder serviceHolder) { - resourceCache.add(serviceHolder); - } - - private HttpService findHttpServiceForPort(Object port) { - ServiceHolder[] serviceHolders = httpServices.getServices(); - HttpService result = null; - for (ServiceHolder serviceHolder : serviceHolders) { - Object servicePort = getPort(serviceHolder); - if (servicePort.equals(port)) { - result = (HttpService) serviceHolder.getService(); - } - } - return result; - } - - public void removeResource(Object resource) { - synchronized (lock) { - doRemoveResource(resource); - } - } - - private void doRemoveResource(Object resource) { - ServiceHolder serviceHolder = resources.find(resource); - resourceCache.remove(serviceHolder); - HttpService httpService = findHttpServiceForPort(getPort(serviceHolder)); - removeResourcesFromContext(resource, httpService); - resources.remove(resource); - } - - private void removeResourcesFromContext(Object resource, HttpService httpService) { - JerseyContext jerseyContext = contextMap.get(httpService); - if (jerseyContext != null) { - jerseyContext.removeResource(resource); - } - } - - // For testing purpose - JerseyContext createJerseyContext(HttpService service, Configuration configuration, - ServletConfiguration servletConfiguration) { - return new JerseyContext(service, configuration, servletConfiguration, applicationConfigurations); - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/JerseyContext.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/JerseyContext.java deleted file mode 100644 index 26395e29a..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/JerseyContext.java +++ /dev/null @@ -1,219 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012,2015 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation - * Dragos Dascalita - disbaled autodiscovery - * Lars Pfannenschmidt - made WADL generation configurable - * Ivan Iliev - added ServletConfiguration handling, Optimized Performance - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import java.util.ArrayList; -import java.util.Dictionary; -import java.util.List; -import java.util.Map; - -import javax.servlet.ServletException; -import javax.ws.rs.core.Application; - -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.ApplicationConfiguration; -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.ServletConfiguration; -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal.ServiceContainer.ServiceHolder; -import org.osgi.service.http.HttpContext; -import org.osgi.service.http.HttpService; -import org.osgi.service.http.NamespaceException; - -@SuppressWarnings("rawtypes") -public class JerseyContext { - - private final RootApplication application; - private final HttpService httpService; - private final ServletContainerBridge servletContainerBridge; - private final ResourcePublisher resourcePublisher; - private volatile boolean isApplicationRegistered; - private ServletConfiguration servletConfiguration; - private String rootPath; - private ServiceContainer applicationConfigurations; - - public JerseyContext(HttpService httpService, Configuration configuration, - ServletConfiguration servletConfiguration, ServiceContainer applicationConfigurations) { - this.httpService = httpService; - this.rootPath = configuration.getRoothPath(); - this.application = new RootApplication(); - this.applicationConfigurations = applicationConfigurations; - applyApplicationConfigurations(applicationConfigurations); - this.servletContainerBridge = new ServletContainerBridge(application); - this.servletConfiguration = servletConfiguration; - this.resourcePublisher = new ResourcePublisher(servletContainerBridge, configuration.getPublishDelay()); - } - - void applyApplicationConfigurations(ServiceContainer applicationConfigurations) { - getRootApplication().addProperties(new DefaultApplicationConfiguration().getProperties()); - ServiceHolder[] services = applicationConfigurations.getServices(); - for (ServiceHolder serviceHolder : services) { - Object service = serviceHolder.getService(); - if (service instanceof ApplicationConfiguration) { - Map properties = ((ApplicationConfiguration) service).getProperties(); - if (properties != null) { - getRootApplication().addProperties(properties); - } - } - } - } - - public void addResource(Object resource) { - getRootApplication().addResource(resource); - registerServletWhenNotAlreadyRegistered(); - resourcePublisher.schedulePublishing(); - } - - public void updateConfiguration(Configuration configuration) { - resourcePublisher.setPublishDelay(configuration.getPublishDelay()); - String oldRootPath = this.rootPath; - this.rootPath = configuration.getRoothPath(); - handleRootPath(oldRootPath); - applyApplicationConfigurations(this.applicationConfigurations); - handeRepublish(); - } - - private void handleRootPath(String oldRootPath) { - // if rootPath has changed and we already have registered our servlet and we need to refresh it - if (isApplicationRegistered && !oldRootPath.equals(rootPath)) { - refreshServletRegistration(oldRootPath); - } - } - - public void updateAppConfiguration(ServiceContainer applicationConfigurations) { - this.applicationConfigurations = applicationConfigurations; - applyApplicationConfigurations(this.applicationConfigurations); - handeRepublish(); - } - - public void updateServletConfiguration(ServletConfiguration servletConfiguration) { - boolean isServletUpdateRequired = this.servletConfiguration != servletConfiguration; - this.servletConfiguration = servletConfiguration; - // if servletConfiguration object has changed and we already have a servlet - refresh it - if (isApplicationRegistered && isServletUpdateRequired) { - refreshServletRegistration(rootPath); - } - handeRepublish(); - } - - private void handeRepublish() { - // if application has been marked dirty and we have registered resources - we will republish - if (isApplicationRegistered) { - resourcePublisher.schedulePublishing(); - } - } - - private void refreshServletRegistration(String pathToUnregister) { - synchronized (servletContainerBridge) { - safeUnregister(pathToUnregister); - } - registerServletWhenNotAlreadyRegistered(); - } - - void registerServletWhenNotAlreadyRegistered() { - if (!isApplicationRegistered) { - isApplicationRegistered = true; - registerApplication(); - } - } - - private void registerApplication() { - ClassLoader loader = getContextClassloader(); - setContextClassloader(); - try { - registerServlet(); - } catch (ServletException shouldNotHappen) { - throw new IllegalStateException(shouldNotHappen); - } catch (NamespaceException shouldNotHappen) { - throw new IllegalStateException(shouldNotHappen); - } finally { - resetContextClassloader(loader); - } - } - - private ClassLoader getContextClassloader() { - return Thread.currentThread().getContextClassLoader(); - } - - private void setContextClassloader() { - Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); - } - - private void registerServlet() throws ServletException, NamespaceException { - ClassLoader original = getContextClassloader(); - try { - Thread.currentThread().setContextClassLoader(Application.class.getClassLoader()); - httpService.registerServlet(rootPath, servletContainerBridge, getInitParams(), getHttpContext()); - } finally { - resetContextClassloader(original); - } - } - - private Dictionary getInitParams() { - if (servletConfiguration != null) { - return servletConfiguration.getInitParams(httpService, rootPath); - } - return null; - } - - private HttpContext getHttpContext() { - if (servletConfiguration != null) { - return servletConfiguration.getHttpContext(httpService, rootPath); - } - return null; - } - - private void resetContextClassloader(ClassLoader loader) { - Thread.currentThread().setContextClassLoader(loader); - } - - public void removeResource(Object resource) { - getRootApplication().removeResource(resource); - unregisterServletWhenNoResourcePresents(); - resourcePublisher.schedulePublishing(); - } - - private void unregisterServletWhenNoResourcePresents() { - if (!getRootApplication().hasResources() && isApplicationRegistered) { - // unregistering while jersey context is being reloaded can lead to many exceptions - resourcePublisher.cancelPublishing(); - synchronized (servletContainerBridge) { - safeUnregister(this.rootPath); - } - } - } - - public List eliminate() { - resourcePublisher.cancelPublishing(); - resourcePublisher.shutdown(); - if (isApplicationRegistered) { - synchronized (servletContainerBridge) { - safeUnregister(this.rootPath); - } - } - return new ArrayList<>(getRootApplication().getResources()); - } - - void safeUnregister(String rootPath) { - try { - // this should call destroy on our servlet container - httpService.unregister(rootPath); - } catch (Exception jerseyShutdownException) { - // do nothing because jersey sometimes throws an exception during shutdown - } - isApplicationRegistered = false; - } - - // For testing purpose - RootApplication getRootApplication() { - return application; - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ResourcePublisher.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ResourcePublisher.java deleted file mode 100644 index 0ff2ebbf0..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ResourcePublisher.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation - * Ivan Iliev - Performance Optimizations - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import java.lang.Thread.UncaughtExceptionHandler; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; - -public class ResourcePublisher { - - private final ServletContainerBridge servletContainerBridge; - private final ScheduledExecutorService executor; - private long publishDelay; - private volatile ScheduledFuture scheduledFuture; - - public ResourcePublisher(ServletContainerBridge servletContainerBridge, long publishDelay) { - this(createExecutor(), servletContainerBridge, publishDelay); - } - - ResourcePublisher(ScheduledExecutorService executor, ServletContainerBridge servletContainerBridge, - long publishDelay) { - this.servletContainerBridge = servletContainerBridge; - this.publishDelay = publishDelay; - this.executor = executor; - } - - private static ScheduledExecutorService createExecutor() { - return Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { - - @Override - public Thread newThread(Runnable runnable) { - Thread thread = new Thread(runnable, "ResourcePublisher"); - thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { - - @Override - public void uncaughtException(Thread thread, Throwable exception) { - throw new IllegalStateException(exception); - } - }); - return thread; - } - }); - } - - public void setPublishDelay(long publishDelay) { - this.publishDelay = publishDelay; - } - - public void schedulePublishing() { - if (scheduledFuture != null) { - scheduledFuture.cancel(false); - } - scheduledFuture = executor.schedule(servletContainerBridge, publishDelay, TimeUnit.MILLISECONDS); - } - - public void shutdown() { - executor.shutdown(); - } - - public void cancelPublishing() { - if (scheduledFuture != null) { - scheduledFuture.cancel(true); - } - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/RootApplication.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/RootApplication.java deleted file mode 100644 index 07ec5d294..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/RootApplication.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012,2015 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation - * Dragos Dascalita - added properties - * Ivan Iliev - Performance Optimizations - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.ws.rs.core.Application; - -public class RootApplication extends Application { - - private final Map properties; - private final List resources; - private final Object lock = new Object(); - private volatile boolean dirty; - - public RootApplication() { - resources = new LinkedList<>(); - properties = new HashMap<>(); - } - - void addResource(Object resource) { - synchronized (lock) { - resources.add(resource); - dirty = true; - } - } - - void removeResource(Object resource) { - synchronized (lock) { - resources.remove(resource); - dirty = true; - } - } - - boolean hasResources() { - return !resources.isEmpty(); - } - - @Override - public Set getSingletons() { - synchronized (lock) { - Set currentResources = getResources(); - // when this method is called jersey has obtained our resources as they are now, we mark the - // application as not dirty, next time a resource is added it will mark it as dirty again. - dirty = false; - return currentResources; - } - } - - public Set getResources() { - Set singletons = new HashSet<>(super.getSingletons()); - singletons.addAll(resources); - return singletons; - } - - @Override - public Map getProperties() { - return properties; - } - - public void addProperty(String key, Object value) { - Object oldValue = properties.get(key); - properties.put(key, value); - // if application is not dirty but the current property is changed - mark it - synchronized (lock) { - if (!dirty && (value != oldValue && (value == null || !value.equals(oldValue)))) { - dirty = true; - } - } - } - - public void addProperties(Map properties) { - for (Map.Entry entry : properties.entrySet()) { - addProperty(entry.getKey(), entry.getValue()); - } - } - - public boolean isDirty() { - synchronized (lock) { - return dirty; - } - } - - public void setDirty(boolean isDirty) { - synchronized (lock) { - dirty = isDirty; - } - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServiceContainer.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServiceContainer.java deleted file mode 100644 index c1e11fec0..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServiceContainer.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011,2012 Frank Appel and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Frank Appel - initial API and implementation - * Holger Staudacher - ongoing development - * ProSyst Software GmbH. - compatibility with OSGi specification 4.2 APIs - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; - -public class ServiceContainer { - - private final Set services; - private final BundleContext bundleContext; - - ServiceContainer(BundleContext bundleContext) { - this.bundleContext = bundleContext; - this.services = new HashSet<>(); - } - - ServiceHolder add(ServiceReference reference) { - return add(bundleContext.getService(reference), reference); - } - - void remove(Object service) { - services.remove(find(service)); - } - - ServiceHolder[] getServices() { - Set result = new HashSet<>(); - Iterator iterator = services.iterator(); - while (iterator.hasNext()) { - result.add(iterator.next()); - } - return result.toArray(new ServiceHolder[result.size()]); - } - - ServiceHolder find(Object service) { - Finder finder = new Finder(); - return finder.findServiceHolder(service, services); - } - - void clear() { - services.clear(); - } - - int size() { - return services.size(); - } - - private ServiceHolder add(Object service, ServiceReference reference) { - ServiceHolder result = find(service); - if (notFound(result)) { - result = new ServiceHolder(service, reference); - services.add(result); - } else if (referenceIsMissing(reference, result)) { - result.setServiceReference(reference); - } - return result; - } - - private boolean notFound(ServiceHolder result) { - return result == null; - } - - private boolean referenceIsMissing(ServiceReference reference, ServiceHolder result) { - return reference != null && result.getReference() == null; - } - - static class ServiceHolder { - - private ServiceReference serviceReference; - private final Object service; - - ServiceHolder(Object service, ServiceReference serviceReference) { - this.service = service; - this.serviceReference = serviceReference; - } - - Object getService() { - return service; - } - - ServiceReference getReference() { - return serviceReference; - } - - void setServiceReference(ServiceReference serviceReference) { - this.serviceReference = serviceReference; - } - } - - static class Finder { - - ServiceHolder findServiceHolder(Object service, Set collection) { - Iterator iterator = collection.iterator(); - ServiceHolder result = null; - while (iterator.hasNext()) { - ServiceHolder serviceHolder = iterator.next(); - Object found = serviceHolder.getService(); - if (service.equals(found)) { - result = serviceHolder; - } - } - return result; - } - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServletConfigurationTracker.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServletConfigurationTracker.java deleted file mode 100644 index 06de526fc..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServletConfigurationTracker.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Ivan Iliev and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Ivan Iliev - initial API and implementation - * Holger Staudacher - ongoing development - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.ServletConfiguration; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; - -/** - *

- * Tracker for OSGi Services implementing the {@link ServletConfiguration} interface. - *

- */ -public class ServletConfigurationTracker extends ServiceTracker { - - private final JAXRSConnector connector; - - ServletConfigurationTracker(BundleContext context, JAXRSConnector connector) { - super(context, ServletConfiguration.class.getName(), null); - this.connector = connector; - } - - @Override - public Object addingService(ServiceReference reference) { - return connector.setServletConfiguration(reference); - } - - @Override - public void removedService(ServiceReference reference, Object service) { - if (service instanceof ServletConfiguration) { - connector.unsetServletConfiguration(reference, (ServletConfiguration) service); - } - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServletContainerBridge.java b/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServletContainerBridge.java deleted file mode 100644 index 703559701..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/3rdparty/java/org/openhab/core/thirdparty/com/eclipsesource/jaxrs/publisher/internal/ServletContainerBridge.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014,2015 EclipseSource and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Holger Staudacher - initial API and implementation - * Ivan Iliev - Performance Optimizations - ******************************************************************************/ -package org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal; - -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.Request; - -import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.servlet.ServletContainer; - -public class ServletContainerBridge extends HttpServlet implements Runnable { - - private final RootApplication application; - private ServletContainer servletContainer; - private ServletConfig servletConfig; - private volatile boolean isJerseyReady; - - public ServletContainerBridge(RootApplication application) { - this.servletContainer = new ServletContainer(ResourceConfig.forApplication(application)); - this.application = application; - this.isJerseyReady = false; - } - - @Override - public void run() { - if (application.isDirty()) { - ClassLoader original = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(Request.class.getClassLoader()); - synchronized (this) { - if (!isJerseyReady()) { - // if jersey has not been initialized - use the init method - getServletContainer().init(servletConfig); - } else { - // otherwise reload - isJerseyReady = false; - getServletContainer().reload(ResourceConfig.forApplication(application)); - } - isJerseyReady = true; - } - } catch (ServletException e) { - throw new RuntimeException(e); - } finally { - Thread.currentThread().setContextClassLoader(original); - } - } - } - - @Override - public void init(ServletConfig config) throws ServletException { - application.setDirty(true); - this.servletConfig = config; - } - - @Override - public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { - // if jersey has not yet been initialized return service unavailable - if (isJerseyReady()) { - getServletContainer().service(req, res); - } else { - ((HttpServletResponse) res).sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, - "Jersey is not ready yet!"); - } - } - - @Override - public void destroy() { - synchronized (this) { - if (isJerseyReady()) { - getServletContainer().destroy(); - this.isJerseyReady = false; - // create a new ServletContainer when the old one is destroyed. - this.servletContainer = new ServletContainer(ResourceConfig.forApplication(application)); - } - } - } - - // for testing purposes - ServletContainer getServletContainer() { - return servletContainer; - } - - // for testing purposes - boolean isJerseyReady() { - return isJerseyReady; - } -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/main/java/org/openhab/core/io/rest/publisher/internal/JAXRSConnectorProvider.java b/bundles/org.openhab.core.io.rest.publisher/src/main/java/org/openhab/core/io/rest/publisher/internal/JAXRSConnectorProvider.java deleted file mode 100644 index d94ed7461..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/main/java/org/openhab/core/io/rest/publisher/internal/JAXRSConnectorProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (c) 2010-2019 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.core.io.rest.publisher.internal; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal.JAXRSConnector; - -/** - * A provider of an JAX RS connector. - * - * @author Markus Rathgeb - Initial contribution - */ -@NonNullByDefault -public interface JAXRSConnectorProvider { - - /** - * Gets a JAX RS connector. - * - * @return JAX RS connector - */ - JAXRSConnector getJAXRSConnector(); - -} diff --git a/bundles/org.openhab.core.io.rest.publisher/src/main/java/org/openhab/core/io/rest/publisher/internal/ResourceRegistrator.java b/bundles/org.openhab.core.io.rest.publisher/src/main/java/org/openhab/core/io/rest/publisher/internal/ResourceRegistrator.java deleted file mode 100644 index 2c143a563..000000000 --- a/bundles/org.openhab.core.io.rest.publisher/src/main/java/org/openhab/core/io/rest/publisher/internal/ResourceRegistrator.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Copyright (c) 2010-2019 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.core.io.rest.publisher.internal; - -import javax.ws.rs.ext.MessageBodyReader; -import javax.ws.rs.ext.MessageBodyWriter; - -import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.smarthome.io.rest.OhJAXRSResource; -import org.eclipse.smarthome.io.rest.RESTResource; -import org.eclipse.smarthome.io.rest.sse.SseResource; -import org.glassfish.jersey.media.sse.SseFeature; -import org.glassfish.jersey.server.monitoring.ApplicationEventListener; -import org.openhab.core.thirdparty.com.eclipsesource.jaxrs.publisher.internal.JAXRSConnector; -import org.osgi.framework.ServiceReference; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Reference; -import org.osgi.service.component.annotations.ReferenceCardinality; -import org.osgi.service.component.annotations.ReferencePolicy; - -/** - * A registrator for JAX RS resources. - * - * @author Markus Rathgeb - Initial contribution - */ -@NonNullByDefault -@Component(immediate = true) -public class ResourceRegistrator { - - private JAXRSConnector jaxRsConnector; - - @Activate - public ResourceRegistrator(final @Reference JAXRSConnectorProvider provider) { - jaxRsConnector = provider.getJAXRSConnector(); - } - - @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) - public void addJaxRsMessageBodyReader(final ServiceReference> resource) { - jaxRsConnector.addResource(resource); - } - - public void removeJaxRsMessageBodyReader(final ServiceReference> resource) { - jaxRsConnector.removeResource(resource); - } - - @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) - public void addJaxRsMessageBodyWriter(final ServiceReference> resource) { - jaxRsConnector.addResource(resource); - } - - public void removeJaxRsMessageBodyWriter(final ServiceReference> resource) { - jaxRsConnector.removeResource(resource); - } - - @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) - public void addOhRESTResource(final ServiceReference resource) { - jaxRsConnector.addResource(resource); - } - - public void removeOhRESTResource(final ServiceReference resource) { - jaxRsConnector.removeResource(resource); - } - - @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) - public void addOhSSEResource(final ServiceReference resource) { - jaxRsConnector.addResource(resource); - } - - public void removeOhSSEResource(final ServiceReference resource) { - jaxRsConnector.removeResource(resource); - } - - @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) - public void addOhJaxRsResource(final ServiceReference resource) { - jaxRsConnector.addResource(resource); - } - - public void removeOhJaxRsResource(final ServiceReference resource) { - jaxRsConnector.removeResource(resource); - } - - @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) - public void addJerseySseFeature(final ServiceReference resource) { - jaxRsConnector.addResource(resource); - } - - public void removeJerseySseFeature(final ServiceReference resource) { - jaxRsConnector.removeResource(resource); - } - - @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) - public void addJerseyApplicationEventListener(final ServiceReference resource) { - jaxRsConnector.addResource(resource); - } - - public void removeJerseyApplicationEventListener(final ServiceReference resource) { - jaxRsConnector.removeResource(resource); - } - -} diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/JSONResponse.java b/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/JSONResponse.java index c725fd899..fb5f8b35a 100644 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/JSONResponse.java +++ b/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/JSONResponse.java @@ -187,7 +187,7 @@ public class JSONResponse { * @author Joerg Plewe */ @Provider - public static class ExceptionMapper implements OhJAXRSResource, javax.ws.rs.ext.ExceptionMapper { + public static class ExceptionMapper implements javax.ws.rs.ext.ExceptionMapper { private final Logger logger = LoggerFactory.getLogger(ExceptionMapper.class); diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/OhJAXRSResource.java b/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/OhJAXRSResource.java deleted file mode 100644 index 5c6a92210..000000000 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/OhJAXRSResource.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2010-2019 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.smarthome.io.rest; - -import org.eclipse.jdt.annotation.NonNullByDefault; - -/** - * Marker interface for an openHAB JAX RS resource that needs to be registered by the publisher. - * - *

- * This marker is for providing OSGi services for services that should be registered by the REST publisher. - * You should not use this. It is only for a migration path... - * - * @author Markus Rathgeb - Initial contribution - */ -@NonNullByDefault -@Deprecated -public interface OhJAXRSResource { - -} diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/internal/filter/ProxyFilter.java b/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/internal/filter/ProxyFilter.java index 2d27b885b..400b9e00b 100644 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/internal/filter/ProxyFilter.java +++ b/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/internal/filter/ProxyFilter.java @@ -25,7 +25,6 @@ import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; import javax.ws.rs.ext.Provider; -import org.eclipse.smarthome.io.rest.OhJAXRSResource; import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,9 +38,8 @@ import org.slf4j.LoggerFactory; */ @Provider @PreMatching -@Component(configurationPid = "org.eclipse.smarthome.io.rest.proxyfilter", immediate = true, service = { - OhJAXRSResource.class }) -public class ProxyFilter implements OhJAXRSResource, ContainerRequestFilter { +@Component(configurationPid = "org.eclipse.smarthome.io.rest.proxyfilter", immediate = true, service = ProxyFilter.class) +public class ProxyFilter implements ContainerRequestFilter { static final String PROTO_PROXY_HEADER = "x-forwarded-proto"; diff --git a/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/internal/resources/RootResource.java b/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/internal/resources/RootResource.java index c0a0c9daf..c163472c0 100644 --- a/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/internal/resources/RootResource.java +++ b/bundles/org.openhab.core.io.rest/src/main/java/org/eclipse/smarthome/io/rest/internal/resources/RootResource.java @@ -27,7 +27,6 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; -import org.eclipse.smarthome.io.rest.OhJAXRSResource; import org.eclipse.smarthome.io.rest.RESTConstants; import org.eclipse.smarthome.io.rest.RESTResource; import org.eclipse.smarthome.io.rest.internal.Constants; @@ -55,8 +54,8 @@ import org.slf4j.LoggerFactory; * @author Kai Kreuzer - Initial contribution and API */ @Path("/") -@Component(service = { OhJAXRSResource.class }, configurationPid = "org.eclipse.smarthome.io.rest.root") -public class RootResource implements OhJAXRSResource { +@Component(service = RootResource.class, configurationPid = "org.eclipse.smarthome.io.rest.root") +public class RootResource { private final transient Logger logger = LoggerFactory.getLogger(RootResource.class); diff --git a/bundles/pom.xml b/bundles/pom.xml index 2ade607e1..e80c93d48 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -62,7 +62,7 @@ org.openhab.core.io.rest.core org.openhab.core.io.rest.log org.openhab.core.io.rest.mdns - org.openhab.core.io.rest.publisher + org.openhab.core.io.rest.optimize org.openhab.core.io.rest.sitemap org.openhab.core.io.rest.sse org.openhab.core.io.rest.voice diff --git a/features/karaf/openhab-core/src/main/feature/feature.xml b/features/karaf/openhab-core/src/main/feature/feature.xml index 835677942..0bb6da4f0 100644 --- a/features/karaf/openhab-core/src/main/feature/feature.xml +++ b/features/karaf/openhab-core/src/main/feature/feature.xml @@ -56,7 +56,7 @@ pax-http-whiteboard mvn:org.openhab.core.bundles/org.openhab.core.io.http/${project.version} mvn:org.openhab.core.bundles/org.openhab.core.io.rest/${project.version} - mvn:org.openhab.core.bundles/org.openhab.core.io.rest.publisher/${project.version} + mvn:org.openhab.core.bundles/org.openhab.core.io.rest.optimize/${project.version} mvn:org.openhab.core.bundles/org.openhab.core.io.rest.core/${project.version} mvn:org.openhab.core.bundles/org.openhab.core.io.rest.sse/${project.version} diff --git a/features/karaf/openhab-tp/src/main/feature/feature.xml b/features/karaf/openhab-tp/src/main/feature/feature.xml index 46e4fd984..b149df274 100644 --- a/features/karaf/openhab-tp/src/main/feature/feature.xml +++ b/features/karaf/openhab-tp/src/main/feature/feature.xml @@ -79,6 +79,7 @@ openhab.tp;feature=jax-rs-min;version=5.3.1 http openhab.tp-kat.cpy-jersey-min-2.22.2 + mvn:com.eclipsesource.jaxrs/publisher/5.3.1 root=/rest