You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/01/23 21:23:24 UTC
svn commit: r1437716 - in
/tomcat/trunk/java/org/apache/tomcat/websocket/server:
LocalStrings.properties ServerContainerImpl.java WsFrameServer.java
WsProtocolHandler.java WsRemoteEndpointServer.java WsSci.java
Author: markt
Date: Wed Jan 23 20:23:23 2013
New Revision: 1437716
URL: http://svn.apache.org/viewvc?rev=1437716&view=rev
Log:
Fix a few logging TODOs
Cleanup
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
tomcat/trunk/java/org/apache/tomcat/websocket/server/ServerContainerImpl.java
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsFrameServer.java
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointServer.java
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsSci.java
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties?rev=1437716&r1=1437715&r2=1437716&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/LocalStrings.properties Wed Jan 23 20:23:23 2013
@@ -18,3 +18,5 @@ serverContainer.missingEndpoint=An Endpo
serverContainer.pojoDeploy=POJO class [{0}] deploying to path [{1}] in ServletContext [{2}]
serverContainer.servletContextMismatch=Attempted to register a POJO annotated for WebSocket at path [{0}] in the ServletContext with context path [{1}] when the WebSocket ServerContainer is allocated to the ServletContext with context path [{2}]
serverContainer.servletContextMissing=No ServletContext was specified
+wsProtocolHandler.closeFailed=Failed to close the WebSocket connection cleanly
+wsRemoteEndpointServer.closeFailed=Failed to close the ServletOutputStream connection cleanly
\ No newline at end of file
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/ServerContainerImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/ServerContainerImpl.java?rev=1437716&r1=1437715&r2=1437716&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/ServerContainerImpl.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/ServerContainerImpl.java Wed Jan 23 20:23:23 2013
@@ -48,7 +48,7 @@ public class ServerContainerImpl extends
private static Object classLoaderContainerMapLock = new Object();
private static StringManager sm =
StringManager.getManager(Constants.PACKAGE_NAME);
- protected Log log = LogFactory.getLog(ServerContainerImpl.class);
+ protected final Log log = LogFactory.getLog(ServerContainerImpl.class);
public static ServerContainerImpl getServerContainer() {
@@ -63,6 +63,8 @@ public class ServerContainerImpl extends
}
return result;
}
+
+
private volatile ServletContext servletContext = null;
private Map<String,ServerEndpointConfiguration> configMap =
new ConcurrentHashMap<>();
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsFrameServer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsFrameServer.java?rev=1437716&r1=1437715&r2=1437716&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsFrameServer.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsFrameServer.java Wed Jan 23 20:23:23 2013
@@ -29,6 +29,7 @@ public class WsFrameServer extends WsFra
private final ServletInputStream sis;
private final Object connectionReadLock = new Object();
+
public WsFrameServer(ServletInputStream sis, WsSession wsSession) {
super(wsSession);
this.sis = sis;
@@ -36,22 +37,11 @@ public class WsFrameServer extends WsFra
/**
- * Allows sub-classes to control whether the read loop in
- * {@link #onDataAvailable()} should continue or terminate.
- *
- * @return <code>true</code> if the data source is ready to be read
- */
- private boolean isDataAvailable() {
- return sis.isReady();
- }
-
-
- /**
* Called when there is data in the ServletInputStream to process.
*/
public void onDataAvailable() throws IOException {
synchronized (connectionReadLock) {
- while (isDataAvailable()) {
+ while (sis.isReady()) {
// Fill up the input buffer with as much data as we can
int read = sis.read(
inputBuffer, writePos, inputBuffer.length - writePos);
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java?rev=1437716&r1=1437715&r2=1437716&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsProtocolHandler.java Wed Jan 23 20:23:23 2013
@@ -30,6 +30,9 @@ import javax.websocket.CloseReason.Close
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfiguration;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.res.StringManager;
import org.apache.tomcat.websocket.WsIOException;
import org.apache.tomcat.websocket.WsSession;
@@ -38,6 +41,11 @@ import org.apache.tomcat.websocket.WsSes
*/
public class WsProtocolHandler implements ProtocolHandler {
+ private static StringManager sm =
+ StringManager.getManager(Constants.PACKAGE_NAME);
+ private static final Log log =
+ LogFactory.getLog(WsProtocolHandler.class);
+
private final Endpoint ep;
private final EndpointConfiguration endpointConfig;
private final ClassLoader applicationClassLoader;
@@ -71,7 +79,7 @@ public class WsProtocolHandler implement
t.setContextClassLoader(applicationClassLoader);
try {
WsFrameServer wsFrame = new WsFrameServer(sis, wsSession);
- sis.setReadListener(new WsReadListener(this, wsFrame, wsSession));
+ sis.setReadListener(new WsReadListener(this, wsFrame));
WsRemoteEndpointServer wsRemoteEndpointServer =
new WsRemoteEndpointServer(sos);
wsSession.setRemote(wsRemoteEndpointServer);
@@ -96,18 +104,41 @@ public class WsProtocolHandler implement
}
}
+
+ private void close(CloseReason cr) {
+ // Need to call onClose using the web application's class loader
+ Thread t = Thread.currentThread();
+ ClassLoader cl = t.getContextClassLoader();
+ t.setContextClassLoader(applicationClassLoader);
+ try {
+ ep.onClose(wsSession, cr);
+ } finally {
+ t.setContextClassLoader(cl);
+ }
+ // Explicitly close the session if it wasn't closed during the
+ // onClose() event
+ if (wsSession.isOpen()) {
+ try {
+ wsSession.close(cr);
+ } catch (IOException e) {
+ if (log.isInfoEnabled()) {
+ log.info(sm.getString("wsProtocolHandler.closeFailed"), e);
+ }
+ }
+ }
+ }
+
+
private static class WsReadListener implements ReadListener {
private final WsProtocolHandler wsProtocolHandler;
private final WsFrameServer wsFrame;
- private final WsSession wsSession;
private WsReadListener(WsProtocolHandler wsProtocolHandler,
- WsFrameServer wsFrame, WsSession wsSession) {
+ WsFrameServer wsFrame) {
this.wsProtocolHandler = wsProtocolHandler;
this.wsFrame = wsFrame;
- this.wsSession = wsSession;
}
@@ -116,26 +147,11 @@ public class WsProtocolHandler implement
try {
wsFrame.onDataAvailable();
} catch (WsIOException ws) {
- CloseReason cr = ws.getCloseReason();
- wsSession.onClose(cr);
- // Explicitly close the session if it wasn't closed during the
- // onClose() event
- if (wsSession.isOpen()) {
- try {
- wsSession.close(cr);
- } catch (IOException e) {
- // TODO Log
- }
- }
+ wsProtocolHandler.close(ws.getCloseReason());
} catch (EOFException eof) {
- try {
- CloseReason cr = new CloseReason(
- CloseCodes.CLOSED_ABNORMALLY, eof.getMessage());
- wsSession.onClose(cr);
- wsSession.close(cr);
- } catch (IOException e1) {
- // TODO Log?
- }
+ CloseReason cr = new CloseReason(
+ CloseCodes.CLOSED_ABNORMALLY, eof.getMessage());
+ wsProtocolHandler.close(cr);
} catch (IOException ioe) {
onError(ioe);
}
@@ -155,6 +171,7 @@ public class WsProtocolHandler implement
}
}
+
private static class WsWriteListener implements WriteListener {
private final WsProtocolHandler wsProtocolHandler;
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointServer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointServer.java?rev=1437716&r1=1437715&r2=1437716&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointServer.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointServer.java Wed Jan 23 20:23:23 2013
@@ -20,6 +20,9 @@ import java.io.IOException;
import javax.servlet.ServletOutputStream;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.res.StringManager;
import org.apache.tomcat.websocket.WsRemoteEndpointBase;
/**
@@ -29,6 +32,11 @@ import org.apache.tomcat.websocket.WsRem
*/
public class WsRemoteEndpointServer extends WsRemoteEndpointBase {
+ private static StringManager sm =
+ StringManager.getManager(Constants.PACKAGE_NAME);
+ private static final Log log =
+ LogFactory.getLog(WsProtocolHandler.class);
+
private final ServletOutputStream sos;
private volatile WsCompletionHandler handler = null;
private volatile boolean close;
@@ -36,6 +44,7 @@ public class WsRemoteEndpointServer exte
private volatile boolean headerWritten = false;
private volatile boolean payloadWritten = false;
+
public WsRemoteEndpointServer(ServletOutputStream sos) {
this.sos = sos;
}
@@ -92,8 +101,9 @@ public class WsRemoteEndpointServer exte
try {
sos.close();
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ if (log.isInfoEnabled()) {
+ log.info(sm.getString("wsRemoteEndpointServer.closeFailed"), e);
+ }
}
}
}
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/server/WsSci.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsSci.java?rev=1437716&r1=1437715&r2=1437716&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsSci.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsSci.java Wed Jan 23 20:23:23 2013
@@ -24,7 +24,6 @@ import javax.servlet.ServletException;
import javax.servlet.annotation.HandlesTypes;
import javax.websocket.server.WebSocketEndpoint;
-
/**
* Registers an interest in any class that is annotated with
* {@link WebSocketEndpoint} so that Endpoint can be published via the WebSocket
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org