tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1293231 - in /tomcat/trunk/java/org/apache/catalina/websocket: LocalStrings.properties MessageInbound.java WsFrame.java WsInputStream.java WsOutbound.java
Date Fri, 24 Feb 2012 12:49:04 GMT
Author: markt
Date: Fri Feb 24 12:49:03 2012
New Revision: 1293231

URL: http://svn.apache.org/viewvc?rev=1293231&view=rev
Log:
Use a StringManger for exception messages etc. for i18n support

Modified:
    tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java
    tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java
    tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
    tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java

Modified: tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties?rev=1293231&r1=1293230&r2=1293231&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/LocalStrings.properties Fri Feb 24 12:49:03
2012
@@ -11,4 +11,15 @@
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
-# limitations under the License.
\ No newline at end of file
+# limitations under the License.
+
+frame.eos=The end of the stream was reached before the expected number of payload bytes could
be read
+frame.invalidUtf8=A sequence of bytes was received that did not represent valid UTF-8
+frame.notMasked=The client frame was not masked but all client frames must be masked
+
+is.notContinutation=A frame with the OpCode [{0}] was recieved when a continuation frame
was expected
+is.unknownOpCode=A frame with the unrecognized OpCode [{0}] was received
+
+message.bufferTooSmall=The buffer is not big enough to contain the message currently being
processed
+
+outbound.closed=The WebSocket connection has been closed
\ No newline at end of file

Modified: tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java?rev=1293231&r1=1293230&r2=1293231&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/MessageInbound.java Fri Feb 24 12:49:03
2012
@@ -22,6 +22,8 @@ import java.io.Reader;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 
+import org.apache.tomcat.util.res.StringManager;
+
 /**
  * Base implementation of the class used to process WebSocket connections based
  * on messages. Applications should extend this class to provide application
@@ -30,6 +32,10 @@ import java.nio.CharBuffer;
  */
 public abstract class MessageInbound extends StreamInbound {
 
+    private static final StringManager sm =
+            StringManager.getManager(Constants.Package);
+
+
     // 2MB - like maxPostSize
     private int byteBufferMaxSize = 2097152;
     private int charBufferMaxSize = 2097152;
@@ -73,8 +79,7 @@ public abstract class MessageInbound ext
     private void resizeByteBuffer() throws IOException {
         int maxSize = getByteBufferMaxSize();
         if (bb.limit() >= maxSize) {
-            // TODO i18n
-            throw new IOException("Buffer not big enough for message");
+            throw new IOException(sm.getString("message.bufferTooSmall"));
         }
 
         long newSize = bb.limit() * 2;
@@ -93,8 +98,7 @@ public abstract class MessageInbound ext
     private void resizeCharBuffer() throws IOException {
         int maxSize = getCharBufferMaxSize();
         if (cb.limit() >= maxSize) {
-            // TODO i18n
-            throw new IOException("Buffer not big enough for message");
+            throw new IOException(sm.getString("message.bufferTooSmall"));
         }
 
         long newSize = cb.limit() * 2;

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java?rev=1293231&r1=1293230&r2=1293231&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsFrame.java Fri Feb 24 12:49:03 2012
@@ -23,6 +23,7 @@ import java.nio.charset.CoderResult;
 
 import org.apache.catalina.util.Conversions;
 import org.apache.coyote.http11.upgrade.UpgradeProcessor;
+import org.apache.tomcat.util.res.StringManager;
 
 /**
  * Represents a complete WebSocket frame with the exception of the payload for
@@ -30,6 +31,10 @@ import org.apache.coyote.http11.upgrade.
  */
 public class WsFrame {
 
+    private static final StringManager sm =
+            StringManager.getManager(Constants.Package);
+
+
     private final boolean fin;
     private final int rsv;
     private final byte opCode;
@@ -58,8 +63,7 @@ public class WsFrame {
         b = processorRead(processor);
         // Client data must be masked
         if ((b & 0x80) == 0) {
-            // TODO: StringManager / i18n
-            throw new IOException("Client frame not masked");
+            throw new IOException(sm.getString("frame.notMasked"));
         }
 
         payloadLength = b & 0x7F;
@@ -99,8 +103,7 @@ public class WsFrame {
                 CoderResult cr = decoder.decode(payload, cb, true);
                 payload.position(0);
                 if (cr.isError()) {
-                    // TODO i18n
-                    throw new IOException("Not UTF-8");
+                    throw new IOException(sm.getString("frame.invalidUtf8"));
                 }
             }
         } else {
@@ -143,8 +146,7 @@ public class WsFrame {
             throws IOException {
         int result = processor.read();
         if (result == -1) {
-            // TODO i18n
-            throw new IOException("End of stream before end of frame");
+            throw new IOException(sm.getString("frame.eos"));
         }
         return result;
     }
@@ -157,8 +159,7 @@ public class WsFrame {
         while (read < bytes.length) {
             last = processor.read(bytes, read, bytes.length - read);
             if (last == -1) {
-                // TODO i18n
-                throw new IOException("End of stream before end of frame");
+                throw new IOException(sm.getString("frame.eos"));
             }
             read += last;
         }
@@ -174,8 +175,7 @@ public class WsFrame {
         while (bb.hasRemaining()) {
             last = processor.read();
             if (last == -1) {
-                // TODO i18n
-                throw new IOException("End of stream before end of frame");
+                throw new IOException(sm.getString("frame.eos"));
             }
             bb.put((byte) (last ^ mask[bb.position() % 4]));
         }

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java?rev=1293231&r1=1293230&r2=1293231&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsInputStream.java Fri Feb 24 12:49:03
2012
@@ -19,6 +19,7 @@ package org.apache.catalina.websocket;
 import java.io.IOException;
 
 import org.apache.coyote.http11.upgrade.UpgradeProcessor;
+import org.apache.tomcat.util.res.StringManager;
 
 /**
  * This class is used to read WebSocket frames from the underlying socket and
@@ -28,6 +29,10 @@ import org.apache.coyote.http11.upgrade.
  */
 public class WsInputStream extends java.io.InputStream {
 
+    private static final StringManager sm =
+            StringManager.getManager(Constants.Package);
+
+
     private UpgradeProcessor<?> processor;
     private WsOutbound outbound;
 
@@ -76,14 +81,14 @@ public class WsInputStream extends java.
                 } else if (getFrame().getOpCode() == Constants.OPCODE_CLOSE) {
                     outbound.close(frame);
                 } else{
-                    // TODO i18n
-                    throw new IOException("Unknown control frame");
+                    throw new IOException(sm.getString("is.unknownOpCode",
+                            Byte.valueOf(getFrame().getOpCode())));
                 }
                 processFrame();
             }
             if (getFrame().getOpCode() != Constants.OPCODE_CONTINUATION) {
-                // TODO i18n
-                error = "Not a continuation frame";
+                error = sm.getString("is.notContinutation",
+                        Byte.valueOf(getFrame().getOpCode()));
                 throw new IOException(error);
             }
         }

Modified: tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java?rev=1293231&r1=1293230&r2=1293231&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java (original)
+++ tomcat/trunk/java/org/apache/catalina/websocket/WsOutbound.java Fri Feb 24 12:49:03 2012
@@ -24,12 +24,15 @@ import java.nio.charset.CoderResult;
 
 import org.apache.coyote.http11.upgrade.UpgradeOutbound;
 import org.apache.tomcat.util.buf.B2CConverter;
+import org.apache.tomcat.util.res.StringManager;
 
 /**
  * Provides the means to write WebSocket messages to the client.
  */
 public class WsOutbound {
 
+    private static final StringManager sm =
+            StringManager.getManager(Constants.Package);
     private static final int DEFAULT_BUFFER_SIZE = 8192;
 
     private UpgradeOutbound upgradeOutbound;
@@ -62,7 +65,7 @@ public class WsOutbound {
      */
     public void writeBinaryData(int b) throws IOException {
         if (closed) {
-            throw new IOException("Closed");
+            throw new IOException(sm.getString("outbound.closed"));
         }
 
         if (bb.position() == bb.capacity()) {
@@ -92,7 +95,7 @@ public class WsOutbound {
      */
     public void writeTextData(char c) throws IOException {
         if (closed) {
-            throw new IOException("Closed");
+            throw new IOException(sm.getString("outbound.closed"));
         }
 
         if (cb.position() == cb.capacity()) {
@@ -121,7 +124,7 @@ public class WsOutbound {
      */
     public void writeBinaryMessage(ByteBuffer msgBb) throws IOException {
         if (closed) {
-            throw new IOException("Closed");
+            throw new IOException(sm.getString("outbound.closed"));
         }
 
         if (text != null) {
@@ -144,7 +147,7 @@ public class WsOutbound {
      */
     public void writeTextMessage(CharBuffer msgCb) throws IOException {
         if (closed) {
-            throw new IOException("Closed");
+            throw new IOException(sm.getString("outbound.closed"));
         }
 
         if (text != null) {
@@ -163,7 +166,7 @@ public class WsOutbound {
      */
     public void flush() throws IOException {
         if (closed) {
-            throw new IOException("Closed");
+            throw new IOException(sm.getString("outbound.closed"));
         }
         doFlush(true);
     }
@@ -283,7 +286,7 @@ public class WsOutbound {
         // TODO Think about threading requirements for writing. This is not
         // currently thread safe and writing almost certainly needs to be.
         if (closed) {
-            throw new IOException("Closed");
+            throw new IOException(sm.getString("outbound.closed"));
         }
 
         doFlush(true);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message