diff options
author | Martin Vysny <martin@vysny.me> | 2020-10-12 15:38:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 15:38:22 +0300 |
commit | e3b0a113b112724923f326806c7e618e1f01cee0 (patch) | |
tree | 8888be44e27209d5df72c213c61917259eee565b /server | |
parent | b817d61d6ab3f22057a85018a68701cb9ed5473f (diff) | |
download | vaadin-framework-e3b0a113b112724923f326806c7e618e1f01cee0.tar.gz vaadin-framework-e3b0a113b112724923f326806c7e618e1f01cee0.zip |
Log informative message instead of failing with ClassCastException when polling an obsolete resource (#12115)
https://github.com/vaadin/framework/issues/12113
Diffstat (limited to 'server')
-rw-r--r-- | server/src/main/java/com/vaadin/server/AbstractClientConnector.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/server/AbstractClientConnector.java b/server/src/main/java/com/vaadin/server/AbstractClientConnector.java index fe16736465..1a16743105 100644 --- a/server/src/main/java/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/main/java/com/vaadin/server/AbstractClientConnector.java @@ -31,6 +31,8 @@ import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.WeakHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; import com.vaadin.event.EventRouter; import com.vaadin.event.MethodEventSource; @@ -50,6 +52,8 @@ import com.vaadin.util.ReflectTools; import elemental.json.JsonObject; import elemental.json.JsonValue; +import javax.servlet.http.HttpServletResponse; + /** * An abstract base class for ClientConnector implementations. This class * provides all the basic functionality required for connectors. @@ -59,6 +63,11 @@ import elemental.json.JsonValue; */ public abstract class AbstractClientConnector implements ClientConnector, MethodEventSource { + + private static Logger getLogger() { + return Logger.getLogger(AbstractClientConnector.class.getName()); + } + /** * A map from client to server RPC interface class name to the RPC call * manager that handles incoming RPC calls for that interface. @@ -669,11 +678,18 @@ public abstract class AbstractClientConnector VaadinSession session = getSession(); session.lock(); try { - ConnectorResource resource = (ConnectorResource) getResource(key); + Resource resource = getResource(key); if (resource == null) { return false; + } else if (!(resource instanceof ConnectorResource)) { + response.sendError(HttpServletResponse.SC_NOT_FOUND, + "Resource is no longer present"); + getLogger().log(Level.INFO, "The resource '" + key + "' is a " + + resource.getClass().getSimpleName() + + " now; it is no longer a ConnectorResource and request could not be handled"); + return true; } - stream = resource.getStream(); + stream = ((ConnectorResource) resource).getStream(); } finally { session.unlock(); } |