-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactoring: get rid of OSGiClientStaticResource #9277
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
flow-client/src/main/java/com/vaadin/flow/client/osgi/OSGiClientStaticResource.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,17 +64,20 @@ public class VaadinBundleTracker extends BundleTracker<Bundle> { | |
|
||
private Executor executor = Executors.newSingleThreadExecutor(); | ||
|
||
private final AtomicReference<ServiceRegistration<Servlet>> servletRegistration = new AtomicReference<>(); | ||
private final AtomicReference<ServiceRegistration<Servlet>> servletPushRegistration = new AtomicReference<>(); | ||
private final AtomicReference<ServiceRegistration<Servlet>> 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,24 +147,52 @@ private void registerPushResources(Bundle pushBundle) { | |
Hashtable<String, Object> 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<Servlet> registration = servletRegistration.get(); | ||
ServiceRegistration<Servlet> 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<String, Object> properties = new Hashtable<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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<Servlet> registration = servletClientRegistration | ||
.get(); | ||
if (registration != null && registration.getReference().getBundle() | ||
.getBundleId() == clientBundle.getBundleId()) { | ||
registration.unregister(); | ||
servletClientRegistration.compareAndSet(registration, null); | ||
} | ||
} | ||
|
||
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<Long, Collection<Class<?>>> map = new HashMap<>(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.