diff --git a/flow-client/bnd.bnd b/flow-client/bnd.bnd index 1a01e4d946c..97e25d612dc 100644 --- a/flow-client/bnd.bnd +++ b/flow-client/bnd.bnd @@ -3,6 +3,5 @@ Bundle-Name: Flow Client Engine Bundle-Version: ${osgi.bundle.version} Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-License: http://www.apache.org/licenses/LICENSE-2.0 -Import-Package: !*, com.vaadin.flow.client, org.osgi.framework, \ - org.osgi.service.http, com.vaadin.flow.osgi.support +Import-Package: !* Export-Package: !* diff --git a/flow-client/pom.xml b/flow-client/pom.xml index 90a2f9dd86a..0190822a495 100644 --- a/flow-client/pom.xml +++ b/flow-client/pom.xml @@ -39,12 +39,6 @@ ${project.version} provided - - com.vaadin - flow-osgi - ${project.version} - provided - com.google.gwt gwt-user diff --git a/flow-client/src/main/java/com/vaadin/flow/client/osgi/OSGiClientStaticResource.java b/flow-client/src/main/java/com/vaadin/flow/client/osgi/OSGiClientStaticResource.java deleted file mode 100644 index ed241d5755e..00000000000 --- a/flow-client/src/main/java/com/vaadin/flow/client/osgi/OSGiClientStaticResource.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2000-2020 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.flow.client.osgi; - -import org.osgi.service.component.annotations.Component; - -import com.vaadin.flow.osgi.support.OsgiVaadinStaticResource; - -/** - * Client resources registration. - * - * @author Vaadin Ltd - * @since 1.2 - */ -@Component(immediate = true, service = OsgiVaadinStaticResource.class) -public class OSGiClientStaticResource implements OsgiVaadinStaticResource { - - @Override - public String getPath() { - return "/META-INF/resources/VAADIN/static/client"; - } - - @Override - public String getAlias() { - return "/VAADIN/static/client"; - } - -} diff --git a/flow-server/src/main/java/com/vaadin/flow/server/osgi/VaadinBundleTracker.java b/flow-server/src/main/java/com/vaadin/flow/server/osgi/VaadinBundleTracker.java index 2fe37dd21d7..c3325084d89 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/osgi/VaadinBundleTracker.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/osgi/VaadinBundleTracker.java @@ -64,17 +64,20 @@ public class VaadinBundleTracker extends BundleTracker { private Executor executor = Executors.newSingleThreadExecutor(); - private final AtomicReference> servletRegistration = new AtomicReference<>(); + private final AtomicReference> servletPushRegistration = new AtomicReference<>(); + private final AtomicReference> servletClientRegistration = new AtomicReference<>(); /** * Dedicated servlet for serving resources in Flow bundles. */ - private static class PushResourceServlet extends HttpServlet { + private static class ResourceServlet extends HttpServlet { private final Bundle bundle; + private final String resourceDirPath; - public PushResourceServlet(Bundle pushBundle) { - bundle = pushBundle; + public ResourceServlet(Bundle bundle, String resourceDirPath) { + this.bundle = bundle; + this.resourceDirPath = resourceDirPath; } @Override @@ -84,8 +87,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) if (pathInfo == null) { resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND); } - URL resource = bundle.getResource( - "/META-INF/resources/VAADIN/static/push" + pathInfo); + URL resource = bundle.getResource(resourceDirPath + pathInfo); if (resource == null) { resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND); } @@ -119,6 +121,8 @@ public Bundle addingBundle(Bundle bundle, BundleEvent event) { executor.execute(this::scanActiveBundles); } else if (isPushModule(bundle)) { registerPushResources(bundle); + } else if (isClientModule(bundle)) { + registerClientResources(bundle); } else if ((flowServerBundle.getState() & Bundle.ACTIVE) != 0) { // If flow-server bundle is already active then scan bundle for // classes @@ -128,6 +132,8 @@ public Bundle addingBundle(Bundle bundle, BundleEvent event) { && ((event.getType() & BundleEvent.STOPPED) > 0)) { if (isPushModule(bundle)) { unregisterPushResource(bundle); + } else if (isClientModule(bundle)) { + unregisterClientResource(bundle); } else if (isVaadinExtender(bundle)) { // Remove all bundle classes once the bundle becomes stopped OSGiAccess.getInstance() @@ -141,17 +147,41 @@ private void registerPushResources(Bundle pushBundle) { Hashtable properties = new Hashtable<>(); properties.put("osgi.http.whiteboard.servlet.pattern", "/VAADIN/static/push/*"); - servletRegistration.compareAndSet(null, + servletPushRegistration.compareAndSet(null, pushBundle.getBundleContext().registerService(Servlet.class, - new PushResourceServlet(pushBundle), properties)); + new ResourceServlet(pushBundle, + "/META-INF/resources/VAADIN/static/push"), + properties)); } private void unregisterPushResource(Bundle pushBundle) { - ServiceRegistration registration = servletRegistration.get(); + ServiceRegistration registration = servletPushRegistration + .get(); if (registration != null && registration.getReference().getBundle() .getBundleId() == pushBundle.getBundleId()) { registration.unregister(); - servletRegistration.compareAndSet(registration, null); + servletPushRegistration.compareAndSet(registration, null); + } + } + + private void registerClientResources(Bundle clientBundle) { + Hashtable properties = new Hashtable<>(); + properties.put("osgi.http.whiteboard.servlet.pattern", + "/VAADIN/static/client/*"); + servletClientRegistration.compareAndSet(null, + clientBundle.getBundleContext().registerService(Servlet.class, + new ResourceServlet(clientBundle, + "/META-INF/resources/VAADIN/static/client"), + properties)); + } + + private void unregisterClientResource(Bundle clientBundle) { + ServiceRegistration registration = servletClientRegistration + .get(); + if (registration != null && registration.getReference().getBundle() + .getBundleId() == clientBundle.getBundleId()) { + registration.unregister(); + servletClientRegistration.compareAndSet(registration, null); } } @@ -159,6 +189,10 @@ private boolean isPushModule(Bundle bundle) { return "com.vaadin.flow.push".equals(bundle.getSymbolicName()); } + private boolean isClientModule(Bundle bundle) { + return "com.vaadin.flow.client".equals(bundle.getSymbolicName()); + } + @SuppressWarnings("unchecked") private void scanContextInitializers() { Map>> map = new HashMap<>();