aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorS.W <wimmesberger@gmail.com>2018-12-04 10:47:07 +0100
committerSun Zhe <31067185+ZheSun88@users.noreply.github.com>2018-12-11 16:58:38 +0200
commit56c70954b2dc4a95caabc2533f9e683d365e1e15 (patch)
tree629d879f0939194a24dfa92cd740ec4e55f435d5
parente6a243bfb7473691be75d46759464accce09253e (diff)
downloadvaadin-framework-56c70954b2dc4a95caabc2533f9e683d365e1e15.tar.gz
vaadin-framework-56c70954b2dc4a95caabc2533f9e683d365e1e15.zip
OSGi: Fixing dynamic resource registration after activation (#11334)
* Fixing dynamic resource registration after activation * Fixed formatting * Fixed formatting * Merge branch 'master' into osgi-dynamic-fix
-rw-r--r--shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceTrackerComponent.java46
1 files changed, 31 insertions, 15 deletions
diff --git a/shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceTrackerComponent.java b/shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceTrackerComponent.java
index b05223052e..1ca6e26510 100644
--- a/shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceTrackerComponent.java
+++ b/shared/src/main/java/com/vaadin/osgi/resources/impl/VaadinResourceTrackerComponent.java
@@ -15,6 +15,8 @@
*/
package com.vaadin.osgi.resources.impl;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
@@ -23,9 +25,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -67,7 +66,7 @@ public class VaadinResourceTrackerComponent {
@Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OsgiVaadinTheme.class, policy = ReferencePolicy.DYNAMIC)
void bindTheme(ServiceReference<OsgiVaadinTheme> themeRef)
- throws ResourceBundleInactiveException {
+ throws ResourceBundleInactiveException, NamespaceException {
Bundle bundle = themeRef.getBundle();
BundleContext context = bundle.getBundleContext();
@@ -94,7 +93,7 @@ public class VaadinResourceTrackerComponent {
@Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OsgiVaadinWidgetset.class, policy = ReferencePolicy.DYNAMIC)
void bindWidgetset(ServiceReference<OsgiVaadinWidgetset> widgetsetRef)
- throws ResourceBundleInactiveException {
+ throws ResourceBundleInactiveException, NamespaceException {
Bundle bundle = widgetsetRef.getBundle();
BundleContext context = bundle.getBundleContext();
@@ -120,7 +119,7 @@ public class VaadinResourceTrackerComponent {
@Reference(cardinality = ReferenceCardinality.MULTIPLE, service = OsgiVaadinResource.class, policy = ReferencePolicy.DYNAMIC)
void bindResource(ServiceReference<OsgiVaadinResource> resourceRef)
- throws ResourceBundleInactiveException {
+ throws ResourceBundleInactiveException, NamespaceException {
Bundle bundle = resourceRef.getBundle();
BundleContext context = bundle.getBundleContext();
@@ -180,7 +179,7 @@ public class VaadinResourceTrackerComponent {
Long serviceId = (Long) contributorRef
.getProperty(Constants.SERVICE_ID);
List<ServiceRegistration<? extends OsgiVaadinResource>> registrations = contributorToRegistrations
- .get(serviceId);
+ .remove(serviceId);
if (registrations != null) {
for (ServiceRegistration<? extends OsgiVaadinResource> reg : registrations) {
reg.unregister();
@@ -204,9 +203,8 @@ public class VaadinResourceTrackerComponent {
*/
@Activate
protected void activate() throws NamespaceException {
- for(Delegate registration : resourceToRegistration.values()) {
- registration.init(httpService);
- httpService.registerResources(registration.alias, registration.path, registration);
+ for (Delegate registration : resourceToRegistration.values()) {
+ registerResource(registration);
}
}
@@ -229,7 +227,8 @@ public class VaadinResourceTrackerComponent {
}
private void registerTheme(VaadinResourceService resourceService,
- Bundle bundle, Long serviceId, OsgiVaadinTheme theme) {
+ Bundle bundle, Long serviceId, OsgiVaadinTheme theme)
+ throws NamespaceException {
String pathPrefix = resourceService.getResourcePathPrefix();
String alias = PathFormatHelper.getThemeAlias(theme.getName(),
@@ -240,7 +239,8 @@ public class VaadinResourceTrackerComponent {
}
private void registerWidget(VaadinResourceService resourceService,
- Bundle bundle, Long serviceId, OsgiVaadinWidgetset widgetset) {
+ Bundle bundle, Long serviceId, OsgiVaadinWidgetset widgetset)
+ throws NamespaceException {
String pathPrefix = resourceService.getResourcePathPrefix();
String alias = PathFormatHelper.getWidgetsetAlias(widgetset.getName(),
@@ -251,7 +251,8 @@ public class VaadinResourceTrackerComponent {
}
private void registerResource(VaadinResourceService resourceService,
- Bundle bundle, Long serviceId, OsgiVaadinResource resource) {
+ Bundle bundle, Long serviceId, OsgiVaadinResource resource)
+ throws NamespaceException {
String pathPrefix = resourceService.getResourcePathPrefix();
String alias = PathFormatHelper.getRootResourceAlias(resource.getName(),
@@ -262,8 +263,19 @@ public class VaadinResourceTrackerComponent {
}
private void registerResource(String alias, String path, Bundle bundle,
- Long serviceId) {
- resourceToRegistration.put(serviceId, new Delegate(alias, path, bundle));
+ Long serviceId) throws NamespaceException {
+ Delegate registration = new Delegate(alias, path, bundle);
+ resourceToRegistration.put(serviceId, registration);
+ registerResource(registration);
+ }
+
+ private void registerResource(Delegate registration)
+ throws NamespaceException {
+ if (this.httpService != null && !registration.isInitialized()) {
+ registration.init(httpService);
+ httpService.registerResources(registration.alias, registration.path,
+ registration);
+ }
}
private void unregisterResource(Long serviceId) {
@@ -294,6 +306,10 @@ public class VaadinResourceTrackerComponent {
context = service.createDefaultHttpContext();
}
+ public boolean isInitialized() {
+ return context != null;
+ }
+
@Override
public boolean handleSecurity(HttpServletRequest request,
HttpServletResponse response) throws IOException {