Author: markt
Date: Tue Oct 21 12:36:06 2014
New Revision: 1633359

URL: http://svn.apache.org/r1633359
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/tc7.0.x/trunk/   (props changed)
    
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
    
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1633342

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java?rev=1633359&r1=1633358&r2=1633359&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
 Tue Oct 21 12:36:06 2014
@@ -512,14 +512,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 e) {
             throw new IOException(e);
         } catch (ExecutionException e) {
-            throw new IOException(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/tc7.0.x/trunk/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java?rev=1633359&r1=1633358&r2=1633359&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java
 (original)
+++ 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/websocket/pojo/TestEncodingDecoding.java
 Tue Oct 21 12:36:06 2014
@@ -603,4 +603,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/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1633359&r1=1633358&r2=1633359&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue Oct 21 12:36:06 2014
@@ -138,6 +138,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

Reply via email to