Author: markt Date: Tue Oct 21 11:16:17 2014 New Revision: 1633342 URL: http://svn.apache.org/r1633342 Log: Ensure that that an EncodeException is thrown by RemoteEndpoint.Basic.sendObject(Object) rather than an IOException when no suitable Encoder is configured for the given Object.
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java tomcat/trunk/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java?rev=1633342&r1=1633341&r2=1633342&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java Tue Oct 21 11:16:17 2014 @@ -509,12 +509,21 @@ public abstract class WsRemoteEndpointIm } - public void sendObject(Object obj) throws IOException { + public void sendObject(Object obj) throws IOException, EncodeException { Future<Void> f = sendObjectByFuture(obj); try { f.get(); - } catch (InterruptedException | ExecutionException e) { + } catch (InterruptedException e) { throw new IOException(e); + } catch (ExecutionException e) { + Throwable cause = e.getCause(); + if (cause instanceof IOException) { + throw (IOException) cause; + } else if (cause instanceof EncodeException) { + throw (EncodeException) cause; + } else { + throw new IOException(e); + } } } Modified: tomcat/trunk/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java?rev=1633342&r1=1633341&r2=1633342&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java (original) +++ tomcat/trunk/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java Tue Oct 21 11:16:17 2014 @@ -598,4 +598,36 @@ public class TestEncodingDecoding extend } } } + + + @Test + public void testUnsupportedObject() throws Exception{ + Tomcat tomcat = getTomcatInstance(); + // Must have a real docBase - just use temp + Context ctx = tomcat.addContext("", System.getProperty("java.io.tmpdir")); + ctx.addApplicationListener(ProgramaticServerEndpointConfig.class.getName()); + Tomcat.addServlet(ctx, "default", new DefaultServlet()); + ctx.addServletMapping("/", "default"); + + WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer(); + + tomcat.start(); + + Client client = new Client(); + URI uri = new URI("ws://localhost:" + getPort() + PATH_PROGRAMMATIC_EP); + Session session = wsContainer.connectToServer(client, uri); + + // This should fail + Object msg1 = new Object(); + try { + session.getBasicRemote().sendObject(msg1); + Assert.fail("No exception thrown "); + } catch (EncodeException e) { + // Expected + } catch (Throwable t) { + Assert.fail("Wrong exception type"); + } finally { + session.close(); + } + } } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1633342&r1=1633341&r2=1633342&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue Oct 21 11:16:17 2014 @@ -220,6 +220,12 @@ <fix> Add null checks for arguments in remote endpoint. (remm/kkolinko) </fix> + <fix> + <bug>57118</bug>: Ensure that that an <code>EncodeException</code> is + thrown by <code>RemoteEndpoint.Basic.sendObject(Object)</code> rather + than an <code>IOException</code> when no suitable <code>Encoder</code> + is configured for the given Object. (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