This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit fdf2614f0159724fc0824c1b531733dab8ab6485 Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Aug 7 17:23:32 2024 +0100 Encoding error on send should not automatically close the connection --- .../apache/tomcat/websocket/pojo/LocalStrings.properties | 2 ++ .../tomcat/websocket/pojo/PojoMessageHandlerBase.java | 15 ++++++++++++++- webapps/docs/changelog.xml | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/java/org/apache/tomcat/websocket/pojo/LocalStrings.properties b/java/org/apache/tomcat/websocket/pojo/LocalStrings.properties index afefa8c8af..c9ef340cba 100644 --- a/java/org/apache/tomcat/websocket/pojo/LocalStrings.properties +++ b/java/org/apache/tomcat/websocket/pojo/LocalStrings.properties @@ -19,6 +19,8 @@ pojoEndpointBase.onError=No error handling configured for [{0}] and the followin pojoEndpointBase.onErrorFail=Failed to call onError method of POJO end point for POJO of type [{0}] pojoEndpointBase.onOpenFail=Failed to call onOpen method of POJO end point for POJO of type [{0}] +pojoMessageHandlerBase.encodeFail=Encoding failed for POJO of tyoe [{0}] in session [{1}] + pojoMessageHandlerWhole.decodeIoFail=IO error while decoding message pojoMessageHandlerWhole.maxBufferSize=The maximum supported message size for this implementation is Integer.MAX_VALUE diff --git a/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerBase.java b/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerBase.java index a52c79d084..6d24132c62 100644 --- a/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerBase.java +++ b/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerBase.java @@ -25,8 +25,12 @@ import javax.websocket.MessageHandler; import javax.websocket.RemoteEndpoint; import javax.websocket.Session; +import org.apache.juli.logging.Log; +import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.ExceptionUtils; +import org.apache.tomcat.util.res.StringManager; import org.apache.tomcat.websocket.WrappedMessageHandler; +import org.apache.tomcat.websocket.WsSession; /** * Common implementation code for the POJO message handlers. @@ -35,6 +39,9 @@ import org.apache.tomcat.websocket.WrappedMessageHandler; */ public abstract class PojoMessageHandlerBase<T> implements WrappedMessageHandler { + private final Log log = LogFactory.getLog(PojoMessageHandlerBase.class); // must not be static + private static final StringManager sm = StringManager.getManager(PojoMessageHandlerBase.class); + protected final Object pojo; protected final Method method; protected final Session session; @@ -110,7 +117,13 @@ public abstract class PojoMessageHandlerBase<T> implements WrappedMessageHandler protected final void handlePojoMethodException(Throwable t) { t = ExceptionUtils.unwrapInvocationTargetException(t); ExceptionUtils.handleThrowable(t); - if (t instanceof RuntimeException) { + if (t instanceof EncodeException) { + if (log.isDebugEnabled()) { + log.debug(sm.getString("pojoMessageHandlerBase.encodeFail", pojo.getClass().getName(), session.getId()), + t); + } + ((WsSession) session).getLocal().onError(session, t); + } else if (t instanceof RuntimeException) { throw (RuntimeException) t; } else { throw new RuntimeException(t.getMessage(), t); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 1d7a2ca6ad..1763969077 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -119,6 +119,12 @@ If a blocking message write exceeds the timeout, don't attempt the write again before throwing the exception. (markt) </fix> + <fix> + An EncodeException being thrown during a message write should not + automatically cause the connection to close. The application should + handle the exception and make the decision whether or not to close the + connection. (markt) + </fix> </changelog> </subsection> <subsection name="Web applications"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org