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/02/25 11:39:03 UTC
svn commit: r1449652 - in /tomcat/trunk: java/javax/websocket/
java/javax/websocket/server/ java/org/apache/tomcat/websocket/
java/org/apache/tomcat/websocket/pojo/
java/org/apache/tomcat/websocket/server/ test/org/apache/tomcat/websocket/
webapps/exam...
Author: markt
Date: Mon Feb 25 10:39:02 2013
New Revision: 1449652
URL: http://svn.apache.org/r1449652
Log:
First stage of updating to WebSocket draft 13
- Some new TODOs to complete
- Configuration changes not made
- Compiles but not tested
Added:
tomcat/trunk/java/javax/websocket/ClientEndpoint.java
- copied, changed from r1448701, tomcat/trunk/java/javax/websocket/WebSocketClient.java
tomcat/trunk/java/javax/websocket/OnClose.java
- copied, changed from r1448701, tomcat/trunk/java/javax/websocket/WebSocketClose.java
tomcat/trunk/java/javax/websocket/OnError.java
- copied, changed from r1448701, tomcat/trunk/java/javax/websocket/WebSocketError.java
tomcat/trunk/java/javax/websocket/OnMessage.java
- copied, changed from r1448701, tomcat/trunk/java/javax/websocket/WebSocketMessage.java
tomcat/trunk/java/javax/websocket/OnOpen.java
- copied, changed from r1448701, tomcat/trunk/java/javax/websocket/WebSocketOpen.java
tomcat/trunk/java/javax/websocket/server/PathParam.java
- copied, changed from r1448701, tomcat/trunk/java/javax/websocket/server/WebSocketPathParam.java
tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointAsync.java (with props)
tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointBasic.java (with props)
Removed:
tomcat/trunk/java/javax/websocket/WebSocketClient.java
tomcat/trunk/java/javax/websocket/WebSocketClose.java
tomcat/trunk/java/javax/websocket/WebSocketError.java
tomcat/trunk/java/javax/websocket/WebSocketMessage.java
tomcat/trunk/java/javax/websocket/WebSocketOpen.java
tomcat/trunk/java/javax/websocket/server/WebSocketPathParam.java
Modified:
tomcat/trunk/java/javax/websocket/EndpointConfiguration.java
tomcat/trunk/java/javax/websocket/RemoteEndpoint.java
tomcat/trunk/java/javax/websocket/SendHandler.java
tomcat/trunk/java/javax/websocket/Session.java
tomcat/trunk/java/javax/websocket/WebSocketContainer.java
tomcat/trunk/java/javax/websocket/server/HandshakeRequest.java
tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java
tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointBase.java
tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointClient.java
tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerBase.java
tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java
tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoPathParam.java
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointServer.java
tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java
tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
tomcat/trunk/test/org/apache/tomcat/websocket/TesterEchoServer.java
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/Snake.java
tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java
Copied: tomcat/trunk/java/javax/websocket/ClientEndpoint.java (from r1448701, tomcat/trunk/java/javax/websocket/WebSocketClient.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/ClientEndpoint.java?p2=tomcat/trunk/java/javax/websocket/ClientEndpoint.java&p1=tomcat/trunk/java/javax/websocket/WebSocketClient.java&r1=1448701&r2=1449652&rev=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/WebSocketClient.java (original)
+++ tomcat/trunk/java/javax/websocket/ClientEndpoint.java Mon Feb 25 10:39:02 2013
@@ -1,30 +1,30 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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.
- */
-package javax.websocket;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface WebSocketClient {
- String[] subprotocols();
- Class<? extends Decoder>[] decoders();
- Class<? extends Encoder>[] encoders();
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package javax.websocket;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface ClientEndpoint {
+ String[] subprotocols();
+ Class<? extends Decoder>[] decoders();
+ Class<? extends Encoder>[] encoders();
+}
Modified: tomcat/trunk/java/javax/websocket/EndpointConfiguration.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/EndpointConfiguration.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/EndpointConfiguration.java (original)
+++ tomcat/trunk/java/javax/websocket/EndpointConfiguration.java Mon Feb 25 10:39:02 2013
@@ -17,10 +17,13 @@
package javax.websocket;
import java.util.List;
+//import java.util.Map;
public interface EndpointConfiguration {
List<Encoder> getEncoders();
List<Decoder> getDecoders();
+
+ //Map<String,Object> getUserProperties();
}
Copied: tomcat/trunk/java/javax/websocket/OnClose.java (from r1448701, tomcat/trunk/java/javax/websocket/WebSocketClose.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/OnClose.java?p2=tomcat/trunk/java/javax/websocket/OnClose.java&p1=tomcat/trunk/java/javax/websocket/WebSocketClose.java&r1=1448701&r2=1449652&rev=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/WebSocketClose.java (original)
+++ tomcat/trunk/java/javax/websocket/OnClose.java Mon Feb 25 10:39:02 2013
@@ -23,5 +23,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
-public @interface WebSocketClose {
+public @interface OnClose {
}
Copied: tomcat/trunk/java/javax/websocket/OnError.java (from r1448701, tomcat/trunk/java/javax/websocket/WebSocketError.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/OnError.java?p2=tomcat/trunk/java/javax/websocket/OnError.java&p1=tomcat/trunk/java/javax/websocket/WebSocketError.java&r1=1448701&r2=1449652&rev=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/WebSocketError.java (original)
+++ tomcat/trunk/java/javax/websocket/OnError.java Mon Feb 25 10:39:02 2013
@@ -23,5 +23,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
-public @interface WebSocketError {
+public @interface OnError {
}
Copied: tomcat/trunk/java/javax/websocket/OnMessage.java (from r1448701, tomcat/trunk/java/javax/websocket/WebSocketMessage.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/OnMessage.java?p2=tomcat/trunk/java/javax/websocket/OnMessage.java&p1=tomcat/trunk/java/javax/websocket/WebSocketMessage.java&r1=1448701&r2=1449652&rev=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/WebSocketMessage.java (original)
+++ tomcat/trunk/java/javax/websocket/OnMessage.java Mon Feb 25 10:39:02 2013
@@ -23,6 +23,6 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
-public @interface WebSocketMessage {
+public @interface OnMessage {
long maxMessageSize() default -1;
}
Copied: tomcat/trunk/java/javax/websocket/OnOpen.java (from r1448701, tomcat/trunk/java/javax/websocket/WebSocketOpen.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/OnOpen.java?p2=tomcat/trunk/java/javax/websocket/OnOpen.java&p1=tomcat/trunk/java/javax/websocket/WebSocketOpen.java&r1=1448701&r2=1449652&rev=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/WebSocketOpen.java (original)
+++ tomcat/trunk/java/javax/websocket/OnOpen.java Mon Feb 25 10:39:02 2013
@@ -23,5 +23,5 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
-public @interface WebSocketOpen {
+public @interface OnOpen {
}
Modified: tomcat/trunk/java/javax/websocket/RemoteEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/RemoteEndpoint.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/RemoteEndpoint.java (original)
+++ tomcat/trunk/java/javax/websocket/RemoteEndpoint.java Mon Feb 25 10:39:02 2013
@@ -25,6 +25,108 @@ import java.util.concurrent.Future;
public interface RemoteEndpoint {
+ interface Async extends RemoteEndpoint {
+
+ /**
+ * Obtain the timeout (in milliseconds) for sending a message
+ * asynchronously. A non-positive value means an infinite timeout. The
+ * default value is determined by
+ * {@link WebSocketContainer#getDefaultAsyncSendTimeout()}.
+ */
+ long getSendTimeout();
+
+ /**
+ * Set the timeout (in milliseconds) for sending a message asynchronously. A
+ * non-positive value means an infinite timeout. The default value is
+ * determined by {@link WebSocketContainer#getDefaultAsyncSendTimeout()}.
+ */
+ void setSendTimeout(long timeout);
+
+ /**
+ * Send the message asynchronously, using the SendHandler to signal to the
+ * client when the message has been sent.
+ * @param text The text message to send
+ * @param completion Used to signal to the client when the message has
+ * been sent
+ */
+ void sendText(String text, SendHandler completion);
+
+ /**
+ * Send the message asynchronously, using the Future to signal to the client
+ * when the message has been sent.
+ * @param text The text message to send
+ */
+ Future<Void> sendText(String text);
+
+ /**
+ * Send the message asynchronously, using the Future to signal to the client
+ * when the message has been sent.
+ * @param data The text message to send
+ */
+ Future<Void> sendBinary(ByteBuffer data);
+
+ /**
+ * Send the message asynchronously, using the SendHandler to signal to the
+ * client when the message has been sent.
+ * @param data The text message to send
+ * @param completion Used to signal to the client when the message has
+ * been sent
+ */
+ void sendBinary(ByteBuffer data, SendHandler completion);
+
+ Future<Void> sendObject(Object obj);
+
+ void sendObject(Object obj, SendHandler completion);
+
+ }
+
+ interface Basic extends RemoteEndpoint {
+
+ /**
+ * Send the message, blocking until the message is sent.
+ * @param text The text message to send.
+ * @throws IOException
+ */
+ void sendText(String text) throws IOException;
+
+ /**
+ * Send the message, blocking until the message is sent.
+ * @param data The binary message to send
+ * @throws IOException
+ */
+ void sendBinary(ByteBuffer data) throws IOException;
+
+ /**
+ * Sends part of a text message to the remote endpoint. Once the first part
+ * of a message has been sent, no other text or binary messages may be sent
+ * until all remaining parts of this message have been sent.
+ *
+ * @param fragment The partial message to send
+ * @param isLast <code>true</code> if this is the last part of the
+ * message, otherwise <code>false</code>
+ * @throws IOException
+ */
+ void sendText(String fragment, boolean isLast) throws IOException;
+
+ /**
+ * Sends part of a binary message to the remote endpoint. Once the first
+ * part of a message has been sent, no other text or binary messages may be
+ * sent until all remaining parts of this message have been sent.
+ *
+ * @param partialByte The partial message to send
+ * @param isLast <code>true</code> if this is the last part of the
+ * message, otherwise <code>false</code>
+ * @throws IOException
+ */
+ void sendBinary(ByteBuffer partialByte, boolean isLast) throws IOException;
+
+ OutputStream getSendStream() throws IOException;
+
+ Writer getSendWriter() throws IOException;
+
+ void sendObject(Object o) throws IOException, EncodeException;
+
+ }
/**
* Enable or disable the batching of outgoing messages for this endpoint. If
* batching is disabled when it was previously enabled then this method will
@@ -49,101 +151,6 @@ public interface RemoteEndpoint {
void flushBatch() throws IOException;
/**
- * Obtain the timeout (in milliseconds) for sending a message
- * asynchronously. A non-positive value means an infinite timeout. The
- * default value is determined by
- * {@link WebSocketContainer#getDefaultAsyncSendTimeout()}.
- */
- long getAsyncSendTimeout();
-
- /**
- * Set the timeout (in milliseconds) for sending a message asynchronously. A
- * non-positive value means an infinite timeout. The default value is
- * determined by {@link WebSocketContainer#getDefaultAsyncSendTimeout()}.
- */
- void setAsyncSendTimeout(long timeout);
-
- /**
- * Send the message, blocking until the message is sent.
- * @param text The text message to send.
- * @throws IOException
- */
- void sendString(String text) throws IOException;
-
- /**
- * Send the message, blocking until the message is sent.
- * @param data The binary message to send
- * @throws IOException
- */
- void sendBytes(ByteBuffer data) throws IOException;
-
- /**
- * Sends part of a text message to the remote endpoint. Once the first part
- * of a message has been sent, no other text or binary messages may be sent
- * until all remaining parts of this message have been sent.
- *
- * @param fragment The partial message to send
- * @param isLast <code>true</code> if this is the last part of the
- * message, otherwise <code>false</code>
- * @throws IOException
- */
- void sendPartialString(String fragment, boolean isLast) throws IOException;
-
- /**
- * Sends part of a binary message to the remote endpoint. Once the first
- * part of a message has been sent, no other text or binary messages may be
- * sent until all remaining parts of this message have been sent.
- *
- * @param partialByte The partial message to send
- * @param isLast <code>true</code> if this is the last part of the
- * message, otherwise <code>false</code>
- * @throws IOException
- */
- void sendPartialBytes(ByteBuffer partialByte, boolean isLast) throws IOException;
-
- OutputStream getSendStream() throws IOException;
-
- Writer getSendWriter() throws IOException;
-
- void sendObject(Object o) throws IOException, EncodeException;
-
- /**
- * Send the message asynchronously, using the SendHandler to signal to the
- * client when the message has been sent.
- * @param text The text message to send
- * @param completion Used to signal to the client when the message has
- * been sent
- */
- void sendStringByCompletion(String text, SendHandler completion);
-
- /**
- * Send the message asynchronously, using the Future to signal to the client
- * when the message has been sent.
- * @param text The text message to send
- */
- Future<SendResult> sendStringByFuture(String text);
-
- /**
- * Send the message asynchronously, using the Future to signal to the client
- * when the message has been sent.
- * @param data The text message to send
- */
- Future<SendResult> sendBytesByFuture(ByteBuffer data);
-
- /**
- * Send the message asynchronously, using the SendHandler to signal to the
- * client when the message has been sent.
- * @param data The text message to send
- * @param completion Used to signal to the client when the message has
- * been sent
- */
- void sendBytesByCompletion(ByteBuffer data, SendHandler completion);
-
- Future<SendResult> sendObjectByFuture(Object obj);
-
- void sendObjectByCompletion(Object obj, SendHandler completion);
-
- /**
* Send a ping message blocking until the message has been sent. Note that
* if a message is in the process of being sent asynchronously, this method
* will block until that message and this ping has been sent.
Modified: tomcat/trunk/java/javax/websocket/SendHandler.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/SendHandler.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/SendHandler.java (original)
+++ tomcat/trunk/java/javax/websocket/SendHandler.java Mon Feb 25 10:39:02 2013
@@ -18,5 +18,5 @@ package javax.websocket;
public interface SendHandler {
- void setResult(SendResult result);
+ void onResult(SendResult result);
}
Modified: tomcat/trunk/java/javax/websocket/Session.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/Session.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/Session.java (original)
+++ tomcat/trunk/java/javax/websocket/Session.java Mon Feb 25 10:39:02 2013
@@ -52,13 +52,13 @@ public interface Session extends Closeab
* Get the idle timeout for this session in milliseconds. Zero or negative
* values indicate an infinite timeout.
*/
- long getTimeout();
+ long getMaxIdleTimeout();
/**
* Set the idle timeout for this session in milliseconds. Zero or negative
* values indicate an infinite timeout.
*/
- void setTimeout(long seconds);
+ void setMaxIdleTimeout(long seconds);
/**
* Set the current maximum buffer size (in bytes) for binary messages.
@@ -80,7 +80,9 @@ public interface Session extends Closeab
*/
int getMaxTextMessageBufferSize();
- RemoteEndpoint getRemote();
+ RemoteEndpoint.Async getAsyncRemote();
+
+ RemoteEndpoint.Basic getBasicRemote();
String getId();
Modified: tomcat/trunk/java/javax/websocket/WebSocketContainer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/WebSocketContainer.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/WebSocketContainer.java (original)
+++ tomcat/trunk/java/javax/websocket/WebSocketContainer.java Mon Feb 25 10:39:02 2013
@@ -16,6 +16,7 @@
*/
package javax.websocket;
+import java.io.IOException;
import java.net.URI;
import java.util.Set;
@@ -34,7 +35,7 @@ public interface WebSocketContainer {
void setAsyncSendTimeout(long timeout);
Session connectToServer(Class<?> annotatedEndpointClass, URI path)
- throws DeploymentException;
+ throws DeploymentException, IOException;
/**
* Creates a new connection to the WebSocket.
@@ -53,19 +54,19 @@ public interface WebSocketContainer {
*/
Session connectToServer(Class<? extends Endpoint> endpoint,
ClientEndpointConfiguration clientEndpointConfiguration, URI path)
- throws DeploymentException;
+ throws DeploymentException, IOException;
/**
* Get the current default session idle timeout in milliseconds. Zero or
* negative values indicate an infinite timeout.
*/
- long getMaxSessionIdleTimeout();
+ long getDefaultMaxSessionIdleTimeout();
/**
* Set the current default session idle timeout in milliseconds. Zero or
* negative values indicate an infinite timeout.
*/
- void setMaxSessionIdleTimeout(long timeout);
+ void setDefaultMaxSessionIdleTimeout(long timeout);
/**
* Get the default maximum buffer size (in bytes) for binary messages.
Modified: tomcat/trunk/java/javax/websocket/server/HandshakeRequest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/server/HandshakeRequest.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/server/HandshakeRequest.java (original)
+++ tomcat/trunk/java/javax/websocket/server/HandshakeRequest.java Mon Feb 25 10:39:02 2013
@@ -40,7 +40,7 @@ public interface HandshakeRequest {
* Get the HTTP Session object associated with this request. Object is used
* to avoid a direct dependency on the Servlet API.
*/
- Object getSession();
+ Object getHttpSession();
Map<String, List<String>> getParameterMap();
Copied: tomcat/trunk/java/javax/websocket/server/PathParam.java (from r1448701, tomcat/trunk/java/javax/websocket/server/WebSocketPathParam.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/server/PathParam.java?p2=tomcat/trunk/java/javax/websocket/server/PathParam.java&p1=tomcat/trunk/java/javax/websocket/server/WebSocketPathParam.java&r1=1448701&r2=1449652&rev=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/server/WebSocketPathParam.java (original)
+++ tomcat/trunk/java/javax/websocket/server/PathParam.java Mon Feb 25 10:39:02 2013
@@ -23,6 +23,6 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
-public @interface WebSocketPathParam {
+public @interface PathParam {
String value();
}
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameBase.java Mon Feb 25 10:39:02 2013
@@ -286,7 +286,7 @@ public abstract class WsFrameBase {
wsSession.close(new CloseReason(Util.getCloseCode(code), reason));
} else if (opCode == Constants.OPCODE_PING) {
if (wsSession.isOpen()) {
- wsSession.getRemote().sendPong(controlBufferBinary);
+ wsSession.getBasicRemote().sendPong(controlBufferBinary);
}
} else if (opCode == Constants.OPCODE_PONG) {
MessageHandler.Basic<PongMessage> mhPong =
Added: tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointAsync.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointAsync.java?rev=1449652&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointAsync.java (added)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointAsync.java Mon Feb 25 10:39:02 2013
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.tomcat.websocket;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.concurrent.Future;
+
+import javax.websocket.RemoteEndpoint;
+import javax.websocket.SendHandler;
+
+// TODO Use a common base class
+public class WsRemoteEndpointAsync implements RemoteEndpoint.Async {
+
+ private final WsRemoteEndpointBase base;
+
+
+ WsRemoteEndpointAsync(WsRemoteEndpointBase base) {
+ this.base = base;
+ }
+
+
+ @Override
+ public void setBatchingAllowed(boolean batchingAllowed) throws IOException {
+ base.setBatchingAllowed(batchingAllowed);
+ }
+
+
+ @Override
+ public boolean getBatchingAllowed() {
+ return base.getBatchingAllowed();
+ }
+
+
+ @Override
+ public void flushBatch() throws IOException {
+ base.flushBatch();
+ }
+
+
+ @Override
+ public void sendPing(ByteBuffer applicationData) throws IOException,
+ IllegalArgumentException {
+ base.sendPing(applicationData);
+ }
+
+
+ @Override
+ public void sendPong(ByteBuffer applicationData) throws IOException,
+ IllegalArgumentException {
+ base.sendPong(applicationData);
+ }
+
+
+ @Override
+ public long getSendTimeout() {
+ return base.getSendTimeout();
+ }
+
+
+ @Override
+ public void setSendTimeout(long timeout) {
+ base.setSendTimeout(timeout);
+ }
+
+
+ @Override
+ public void sendText(String text, SendHandler completion) {
+ base.sendStringByCompletion(text, completion);
+ }
+
+
+ @Override
+ public Future<Void> sendText(String text) {
+ return base.sendStringByFuture(text);
+ }
+
+
+ @Override
+ public Future<Void> sendBinary(ByteBuffer data) {
+ return base.sendBytesByFuture(data);
+ }
+
+
+ @Override
+ public void sendBinary(ByteBuffer data, SendHandler completion) {
+ base.sendBytesByCompletion(data, completion);
+ }
+
+
+ @Override
+ public Future<Void> sendObject(Object obj) {
+ return base.sendObjectByFuture(obj);
+ }
+
+
+ @Override
+ public void sendObject(Object obj, SendHandler completion) {
+ base.sendObjectByCompletion(obj, completion);
+ }
+}
Propchange: tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointAsync.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointBase.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointBase.java Mon Feb 25 10:39:02 2013
@@ -70,20 +70,18 @@ public abstract class WsRemoteEndpointBa
private final CharsetEncoder encoder = Charset.forName("UTF8").newEncoder();
private final ByteBuffer encoderBuffer = ByteBuffer.allocate(8192);
private final AtomicBoolean batchingAllowed = new AtomicBoolean(false);
- private volatile long asyncSendTimeout = -1;
+ private volatile long sendTimeout = -1;
private WsSession wsSession;
private List<EncoderEntry> encoderEntries = new ArrayList<>();
- @Override
- public long getAsyncSendTimeout() {
- return asyncSendTimeout;
+ public long getSendTimeout() {
+ return sendTimeout;
}
- @Override
- public void setAsyncSendTimeout(long timeout) {
- this.asyncSendTimeout = timeout;
+ public void setSendTimeout(long timeout) {
+ this.sendTimeout = timeout;
}
@@ -109,27 +107,23 @@ public abstract class WsRemoteEndpointBa
}
- @Override
public void sendBytes(ByteBuffer data) throws IOException {
startMessageBlock(Constants.OPCODE_BINARY, data, true);
}
- @Override
- public Future<SendResult> sendBytesByFuture(ByteBuffer data) {
+ public Future<Void> sendBytesByFuture(ByteBuffer data) {
FutureToSendHandler f2sh = new FutureToSendHandler();
sendBytesByCompletion(data, f2sh);
return f2sh;
}
- @Override
public void sendBytesByCompletion(ByteBuffer data, SendHandler handler) {
startMessage(Constants.OPCODE_BINARY, data, true, handler);
}
- @Override
public void sendPartialBytes(ByteBuffer partialByte, boolean last)
throws IOException {
startMessageBlock(Constants.OPCODE_BINARY, partialByte, last);
@@ -150,21 +144,18 @@ public abstract class WsRemoteEndpointBa
}
- @Override
public void sendString(String text) throws IOException {
sendPartialString(CharBuffer.wrap(text), true);
}
- @Override
- public Future<SendResult> sendStringByFuture(String text) {
+ public Future<Void> sendStringByFuture(String text) {
FutureToSendHandler f2sh = new FutureToSendHandler();
sendStringByCompletion(text, f2sh);
return f2sh;
}
- @Override
public void sendStringByCompletion(String text, SendHandler handler) {
TextMessageSendHandler tmsh = new TextMessageSendHandler(handler,
CharBuffer.wrap(text), true, encoder, encoderBuffer, this);
@@ -172,30 +163,22 @@ public abstract class WsRemoteEndpointBa
}
- @Override
public void sendPartialString(String fragment, boolean isLast)
throws IOException {
sendPartialString(CharBuffer.wrap(fragment), isLast);
}
- @Override
- public OutputStream getSendStream() throws IOException {
+ public OutputStream getSendStream() {
return new WsOutputStream(this);
}
- @Override
- public Writer getSendWriter() throws IOException {
+ public Writer getSendWriter() {
return new WsWriter(this);
}
-
-
-
-
-
void sendPartialString(CharBuffer part, boolean last) throws IOException {
try {
FutureToSendHandler f2sh = new FutureToSendHandler();
@@ -214,14 +197,7 @@ public abstract class WsRemoteEndpointBa
FutureToSendHandler f2sh = new FutureToSendHandler();
startMessage(opCode, payload, last, f2sh);
try {
- SendResult sr = f2sh.get();
- if (!sr.isOK()) {
- if (sr.getException() == null) {
- throw new IOException();
- } else {
- throw new IOException(sr.getException());
- }
- }
+ f2sh.get();
} catch (InterruptedException | ExecutionException e) {
throw new IOException(e);
}
@@ -286,7 +262,7 @@ public abstract class WsRemoteEndpointBa
wsSession.updateLastActive();
- handler.setResult(result);
+ handler.onResult(result);
}
@@ -421,15 +397,14 @@ public abstract class WsRemoteEndpointBa
@Override
- public void setResult(SendResult result) {
+ public void onResult(SendResult result) {
endpoint.endMessage(handler, result, dataMessage);
}
}
- @Override
- public void sendObject(Object obj) throws IOException, EncodeException {
- Future<SendResult> f = sendObjectByFuture(obj);
+ public void sendObject(Object obj) throws IOException {
+ Future<Void> f = sendObjectByFuture(obj);
try {
f.get();
} catch (InterruptedException | ExecutionException e) {
@@ -437,8 +412,7 @@ public abstract class WsRemoteEndpointBa
}
}
- @Override
- public Future<SendResult> sendObjectByFuture(Object obj) {
+ public Future<Void> sendObjectByFuture(Object obj) {
FutureToSendHandler f2sh = new FutureToSendHandler();
sendObjectByCompletion(obj, f2sh);
return f2sh;
@@ -446,7 +420,6 @@ public abstract class WsRemoteEndpointBa
@SuppressWarnings({"unchecked", "rawtypes"})
- @Override
public void sendObjectByCompletion(Object obj, SendHandler completion) {
Encoder encoder = findEncoder(obj);
@@ -470,7 +443,7 @@ public abstract class WsRemoteEndpointBa
}
} catch (EncodeException | IOException e) {
SendResult sr = new SendResult(e);
- completion.setResult(sr);
+ completion.onResult(sr);
}
}
@@ -592,9 +565,9 @@ public abstract class WsRemoteEndpointBa
}
@Override
- public void setResult(SendResult result) {
+ public void onResult(SendResult result) {
if (isDone || !result.isOK()) {
- handler.setResult(result);
+ handler.onResult(result);
} else {
write();
}
@@ -665,18 +638,18 @@ public abstract class WsRemoteEndpointBa
flushRequired = false;
return;
} else {
- handler.setResult(new SendResult());
+ handler.onResult(new SendResult());
}
}
// ------------------------------------------------- SendHandler methods
@Override
- public void setResult(SendResult result) {
+ public void onResult(SendResult result) {
outputBuffer.clear();
if (result.isOK()) {
write();
} else {
- handler.setResult(result);
+ handler.onResult(result);
}
}
}
@@ -685,7 +658,7 @@ public abstract class WsRemoteEndpointBa
* Converts a Future to a SendHandler.
*/
private static class FutureToSendHandler
- implements Future<SendResult>, SendHandler {
+ implements Future<Void>, SendHandler {
private final CountDownLatch latch = new CountDownLatch(1);
private volatile SendResult result = null;
@@ -693,7 +666,7 @@ public abstract class WsRemoteEndpointBa
// --------------------------------------------------------- SendHandler
@Override
- public void setResult(SendResult result) {
+ public void onResult(SendResult result) {
this.result = result;
latch.countDown();
}
@@ -719,21 +692,27 @@ public abstract class WsRemoteEndpointBa
}
@Override
- public SendResult get() throws InterruptedException,
+ public Void get() throws InterruptedException,
ExecutionException {
latch.await();
- return result;
+ if (result.getException() != null) {
+ throw new ExecutionException(result.getException());
+ }
+ return null;
}
@Override
- public SendResult get(long timeout, TimeUnit unit)
+ public Void get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException,
TimeoutException {
boolean retval = latch.await(timeout, unit);
if (retval == false) {
throw new TimeoutException();
}
- return result;
+ if (result.getException() != null) {
+ throw new ExecutionException(result.getException());
+ }
+ return null;
}
}
Added: tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointBasic.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointBasic.java?rev=1449652&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointBasic.java (added)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointBasic.java Mon Feb 25 10:39:02 2013
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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.
+ */
+package org.apache.tomcat.websocket;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.ByteBuffer;
+
+import javax.websocket.EncodeException;
+import javax.websocket.RemoteEndpoint;
+
+//TODO Use a common base class
+public class WsRemoteEndpointBasic implements RemoteEndpoint.Basic {
+
+ private final WsRemoteEndpointBase base;
+
+
+ WsRemoteEndpointBasic(WsRemoteEndpointBase base) {
+ this.base = base;
+ }
+
+
+ @Override
+ public void setBatchingAllowed(boolean batchingAllowed) throws IOException {
+ base.setBatchingAllowed(batchingAllowed);
+ }
+
+
+ @Override
+ public boolean getBatchingAllowed() {
+ return base.getBatchingAllowed();
+ }
+
+
+ @Override
+ public void flushBatch() throws IOException {
+ base.flushBatch();
+ }
+
+
+ @Override
+ public void sendPing(ByteBuffer applicationData) throws IOException,
+ IllegalArgumentException {
+ base.sendPing(applicationData);
+ }
+
+
+ @Override
+ public void sendPong(ByteBuffer applicationData) throws IOException,
+ IllegalArgumentException {
+ base.sendPong(applicationData);
+ }
+
+
+ @Override
+ public void sendText(String text) throws IOException {
+ base.sendString(text);
+ }
+
+
+ @Override
+ public void sendBinary(ByteBuffer data) throws IOException {
+ base.sendBytes(data);
+ }
+
+
+ @Override
+ public void sendText(String fragment, boolean isLast) throws IOException {
+ base.sendPartialString(fragment, isLast);
+ }
+
+
+ @Override
+ public void sendBinary(ByteBuffer partialByte, boolean isLast)
+ throws IOException {
+ base.sendPartialBytes(partialByte, isLast);
+ }
+
+
+ @Override
+ public OutputStream getSendStream() throws IOException {
+ return base.getSendStream();
+ }
+
+
+ @Override
+ public Writer getSendWriter() throws IOException {
+ return base.getSendWriter();
+ }
+
+
+ @Override
+ public void sendObject(Object o) throws IOException, EncodeException {
+ base.sendObject(o);
+ }
+}
Propchange: tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointBasic.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointClient.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointClient.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointClient.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointClient.java Mon Feb 25 10:39:02 2013
@@ -42,14 +42,14 @@ public class WsRemoteEndpointClient exte
@Override
protected void doWrite(SendHandler handler, ByteBuffer... data) {
- long timeout = getAsyncSendTimeout();
+ long timeout = getSendTimeout();
if (timeout < 1) {
timeout = Long.MAX_VALUE;
}
SendHandlerToCompletionHandler sh2ch =
new SendHandlerToCompletionHandler(handler);
- channel.write(data, 0, data.length, getAsyncSendTimeout(),
+ channel.write(data, 0, data.length, getSendTimeout(),
TimeUnit.MILLISECONDS, null, sh2ch);
}
@@ -74,12 +74,12 @@ public class WsRemoteEndpointClient exte
@Override
public void completed(Long result, Void attachment) {
- handler.setResult(new SendResult());
+ handler.onResult(new SendResult());
}
@Override
public void failed(Throwable exc, Void attachment) {
- handler.setResult(new SendResult(exc));
+ handler.onResult(new SendResult(exc));
}
}
}
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Mon Feb 25 10:39:02 2013
@@ -71,7 +71,7 @@ public class WsSession implements Sessio
Constants.DEFAULT_BUFFER_SIZE;
private volatile int maxTextMessageBufferSize =
Constants.DEFAULT_BUFFER_SIZE;
- private volatile long sessionIdleTimeout = 0;
+ private volatile long maxIdleTimeout = 0;
private volatile long lastActive = System.currentTimeMillis();
@@ -95,14 +95,14 @@ public class WsSession implements Sessio
this.wsRemoteEndpoint.setSession(this);
this.webSocketContainer = wsWebSocketContainer;
applicationClassLoader = Thread.currentThread().getContextClassLoader();
- wsRemoteEndpoint.setAsyncSendTimeout(
+ wsRemoteEndpoint.setSendTimeout(
wsWebSocketContainer.getDefaultAsyncSendTimeout());
this.maxBinaryMessageBufferSize =
webSocketContainer.getDefaultMaxBinaryMessageBufferSize();
this.maxTextMessageBufferSize =
webSocketContainer.getDefaultMaxTextMessageBufferSize();
- this.sessionIdleTimeout =
- webSocketContainer.getMaxSessionIdleTimeout();
+ this.maxIdleTimeout =
+ webSocketContainer.getDefaultMaxSessionIdleTimeout();
this.request = request;
this.subProtocol = subProtocol;
this.pathParameters = pathParameters;
@@ -220,14 +220,14 @@ public class WsSession implements Sessio
@Override
- public long getTimeout() {
- return sessionIdleTimeout;
+ public long getMaxIdleTimeout() {
+ return maxIdleTimeout;
}
@Override
- public void setTimeout(long timeout) {
- this.sessionIdleTimeout = timeout;
+ public void setMaxIdleTimeout(long timeout) {
+ this.maxIdleTimeout = timeout;
}
@@ -262,8 +262,16 @@ public class WsSession implements Sessio
@Override
- public RemoteEndpoint getRemote() {
- return wsRemoteEndpoint;
+ public RemoteEndpoint.Async getAsyncRemote() {
+ // TODO Don't create new wrappers on every call
+ return new WsRemoteEndpointAsync(wsRemoteEndpoint);
+ }
+
+
+ @Override
+ public RemoteEndpoint.Basic getBasicRemote() {
+ // TODO Don't create new wrappers on every call
+ return new WsRemoteEndpointBasic(wsRemoteEndpoint);
}
@@ -391,7 +399,7 @@ public class WsSession implements Sessio
protected void expire() {
- long timeout = sessionIdleTimeout;
+ long timeout = maxIdleTimeout;
if (timeout < 1) {
return;
}
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java Mon Feb 25 10:39:02 2013
@@ -65,7 +65,7 @@ public class WsWebSocketContainer
private long defaultAsyncTimeout = -1;
private int maxBinaryMessageBufferSize = Constants.DEFAULT_BUFFER_SIZE;
private int maxTextMessageBufferSize = Constants.DEFAULT_BUFFER_SIZE;
- private volatile long maxSessionIdleTimeout = 0;
+ private volatile long defaultMaxSessionIdleTimeout = 0;
private int backgroundProcessCount = 0;
private int processPeriod = 10;
@@ -413,14 +413,14 @@ public class WsWebSocketContainer
@Override
- public long getMaxSessionIdleTimeout() {
- return maxSessionIdleTimeout;
+ public long getDefaultMaxSessionIdleTimeout() {
+ return defaultMaxSessionIdleTimeout;
}
@Override
- public void setMaxSessionIdleTimeout(long timeout) {
- this.maxSessionIdleTimeout = timeout;
+ public void setDefaultMaxSessionIdleTimeout(long timeout) {
+ this.defaultMaxSessionIdleTimeout = timeout;
}
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerBase.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMessageHandlerBase.java Mon Feb 25 10:39:02 2013
@@ -58,7 +58,7 @@ public abstract class PojoMessageHandler
return;
}
- RemoteEndpoint remoteEndpoint = session.getRemote();
+ RemoteEndpoint.Basic remoteEndpoint = session.getBasicRemote();
// TODO: Remove this once sendXxx is implemented?
if (remoteEndpoint == null) {
return;
@@ -66,11 +66,11 @@ public abstract class PojoMessageHandler
try {
if (result instanceof String) {
- remoteEndpoint.sendString((String) result);
+ remoteEndpoint.sendText((String) result);
} else if (result instanceof ByteBuffer) {
- remoteEndpoint.sendBytes((ByteBuffer) result);
+ remoteEndpoint.sendBinary((ByteBuffer) result);
} else if (result instanceof byte[]) {
- remoteEndpoint.sendBytes(ByteBuffer.wrap((byte[]) result));
+ remoteEndpoint.sendBinary(ByteBuffer.wrap((byte[]) result));
} else {
remoteEndpoint.sendObject(result);
}
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java Mon Feb 25 10:39:02 2013
@@ -25,13 +25,13 @@ import java.util.Map;
import java.util.Set;
import javax.websocket.MessageHandler;
+import javax.websocket.OnClose;
+import javax.websocket.OnError;
+import javax.websocket.OnMessage;
+import javax.websocket.OnOpen;
import javax.websocket.PongMessage;
import javax.websocket.Session;
-import javax.websocket.WebSocketClose;
-import javax.websocket.WebSocketError;
-import javax.websocket.WebSocketMessage;
-import javax.websocket.WebSocketOpen;
-import javax.websocket.server.WebSocketPathParam;
+import javax.websocket.server.PathParam;
/**
* For a POJO class annotated with
@@ -58,15 +58,15 @@ public class PojoMethodMapping {
Method error = null;
for (Method method : clazzPojo.getMethods()) {
if (open == null &&
- method.getAnnotation(WebSocketOpen.class) != null) {
+ method.getAnnotation(OnOpen.class) != null) {
open = method;
} else if (close == null &&
- method.getAnnotation(WebSocketClose.class) != null) {
+ method.getAnnotation(OnClose.class) != null) {
close = method;
} else if (error == null &&
- method.getAnnotation(WebSocketError.class) != null) {
+ method.getAnnotation(OnError.class) != null) {
error = method;
- } else if (method.getAnnotation(WebSocketMessage.class) != null) {
+ } else if (method.getAnnotation(OnMessage.class) != null) {
onMessage.add(new MessageMethod(method));
}
}
@@ -146,9 +146,9 @@ public class PojoMethodMapping {
Annotation[] paramAnnotations = paramsAnnotations[i];
for (Annotation paramAnnotation : paramAnnotations) {
if (paramAnnotation.annotationType().equals(
- WebSocketPathParam.class)) {
+ PathParam.class)) {
result[i] = new PojoPathParam(type,
- ((WebSocketPathParam) paramAnnotation).value());
+ ((PathParam) paramAnnotation).value());
break;
}
}
@@ -240,10 +240,10 @@ public class PojoMethodMapping {
Annotation[] paramAnnotations = paramsAnnotations[i];
for (Annotation paramAnnotation : paramAnnotations) {
if (paramAnnotation.annotationType().equals(
- WebSocketPathParam.class)) {
+ PathParam.class)) {
indexPathParams.put(
Integer.valueOf(i), new PojoPathParam(types[i],
- ((WebSocketPathParam) paramAnnotation).value()));
+ ((PathParam) paramAnnotation).value()));
break;
}
}
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoPathParam.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoPathParam.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoPathParam.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoPathParam.java Mon Feb 25 10:39:02 2013
@@ -20,7 +20,7 @@ package org.apache.tomcat.websocket.pojo
* Stores the parameter type and name for a parameter that needs to be passed to
* an onXxx method of {@link javax.websocket.Endpoint}. The name is only present
* for parameters annotated with
- * {@link javax.websocket.server.WebSocketPathParam}. For the
+ * {@link javax.websocket.server.PathParam}. For the
* {@link javax.websocket.Session} and {@link java.lang.Throwable} parameters,
* {@link #getName()} will always return <code>null</code>.
*/
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=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointServer.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointServer.java Mon Feb 25 10:39:02 2013
@@ -98,7 +98,7 @@ public class WsRemoteEndpointServer exte
// message.
SendHandler sh = handler;
handler = null;
- sh.setResult(new SendResult());
+ sh.onResult(new SendResult());
break;
}
}
@@ -108,12 +108,12 @@ public class WsRemoteEndpointServer exte
close();
SendHandler sh = handler;
handler = null;
- sh.setResult(new SendResult(ioe));
+ sh.onResult(new SendResult(ioe));
}
if (!complete) {
// Async write is in progress
- long timeout = getAsyncSendTimeout();
+ long timeout = getSendTimeout();
if (timeout > 0) {
// Register with timeout thread
timeoutExpiry = timeout + System.currentTimeMillis();
@@ -143,7 +143,7 @@ public class WsRemoteEndpointServer exte
protected void onTimeout() {
close();
- handler.setResult(new SendResult(new SocketTimeoutException()));
+ handler.onResult(new SendResult(new SocketTimeoutException()));
handler = null;
}
}
Modified: tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TestWsRemoteEndpoint.java Mon Feb 25 10:39:02 2013
@@ -74,7 +74,7 @@ public class TestWsRemoteEndpoint extend
wsSession.addMessageHandler(handler);
- Writer w = wsSession.getRemote().getSendWriter();
+ Writer w = wsSession.getBasicRemote().getSendWriter();
for (int i = 0; i < 8; i++) {
w.write(TEST_MESSAGE_5K);
Modified: tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java Mon Feb 25 10:39:02 2013
@@ -32,10 +32,9 @@ import javax.websocket.DeploymentExcepti
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfiguration;
import javax.websocket.MessageHandler;
-import javax.websocket.SendResult;
+import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
-import javax.websocket.WebSocketMessage;
import javax.websocket.server.DefaultServerConfiguration;
import org.junit.Assert;
@@ -88,7 +87,7 @@ public class TestWsWebSocketContainer ex
CountDownLatch latch = new CountDownLatch(1);
BasicText handler = new BasicText(latch);
wsSession.addMessageHandler(handler);
- wsSession.getRemote().sendString(MESSAGE_STRING_1);
+ wsSession.getBasicRemote().sendText(MESSAGE_STRING_1);
boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS);
@@ -232,9 +231,10 @@ public class TestWsWebSocketContainer ex
wsSession.addMessageHandler(handler);
if (isTextMessage) {
- wsSession.getRemote().sendString(MESSAGE_TEXT_4K);
+ wsSession.getBasicRemote().sendText(MESSAGE_TEXT_4K);
} else {
- wsSession.getRemote().sendBytes(ByteBuffer.wrap(MESSAGE_BINARY_4K));
+ wsSession.getBasicRemote().sendBinary(
+ ByteBuffer.wrap(MESSAGE_BINARY_4K));
}
boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS);
@@ -292,21 +292,23 @@ public class TestWsWebSocketContainer ex
getPort() + BlockingConfig.PATH));
if (!setTimeoutOnContainer) {
- wsSession.getRemote().setAsyncSendTimeout(TIMEOUT_MS);
+ wsSession.getAsyncRemote().setSendTimeout(TIMEOUT_MS);
}
long lastSend = 0;
- boolean isOK = true;
- SendResult sr = null;
// Should send quickly until the network buffers fill up and then block
// until the timeout kicks in
- while (isOK) {
- Future<SendResult> f = wsSession.getRemote().sendBytesByFuture(
- ByteBuffer.wrap(MESSAGE_BINARY_4K));
- lastSend = System.currentTimeMillis();
- sr = f.get();
- isOK = sr.isOK();
+ Exception exception = null;
+ try {
+ while (true) {
+ Future<Void> f = wsSession.getAsyncRemote().sendBinary(
+ ByteBuffer.wrap(MESSAGE_BINARY_4K));
+ lastSend = System.currentTimeMillis();
+ f.get();
+ }
+ } catch (Exception e) {
+ exception = e;
}
long timeout = System.currentTimeMillis() - lastSend;
@@ -320,11 +322,7 @@ public class TestWsWebSocketContainer ex
// Check the timeout wasn't too long
Assert.assertTrue(msg, timeout < TIMEOUT_MS * 2);
- if (sr == null) {
- Assert.fail();
- } else {
- Assert.assertNotNull(sr.getException());
- }
+ Assert.assertNotNull(exception);
}
@@ -394,13 +392,7 @@ public class TestWsWebSocketContainer ex
// Check the timeout wasn't too long
Assert.assertTrue(ConstantTxEndpoint.getTimeout() < TIMEOUT_MS*2);
- if (ConstantTxEndpoint.getSendResult() == null) {
- Assert.fail();
- } else {
- Assert.assertNotNull(
- ConstantTxEndpoint.getSendResult().getException());
- }
-
+ Assert.assertNotNull(ConstantTxEndpoint.getException());
}
@@ -419,7 +411,7 @@ public class TestWsWebSocketContainer ex
public static class BlockingPojo {
@SuppressWarnings("unused")
- @WebSocketMessage
+ @OnMessage
public void echoTextMessage(Session session, String msg, boolean last) {
try {
Thread.sleep(60000);
@@ -430,7 +422,7 @@ public class TestWsWebSocketContainer ex
@SuppressWarnings("unused")
- @WebSocketMessage
+ @OnMessage
public void echoBinaryMessage(Session session, ByteBuffer msg,
boolean last) {
try {
@@ -460,8 +452,6 @@ public class TestWsWebSocketContainer ex
// Have to be static to be able to retrieve results from test case
private static volatile long timeout = -1;
- private static volatile boolean ok = true;
- private static volatile SendResult sr = null;
private static volatile Exception exception = null;
private static volatile boolean running = true;
@@ -471,13 +461,11 @@ public class TestWsWebSocketContainer ex
// Reset everything
timeout = -1;
- ok = true;
- sr = null;
exception = null;
running = true;
if (!TestWsWebSocketContainer.timoutOnContainer) {
- session.getRemote().setAsyncSendTimeout(TIMEOUT_MS);
+ session.getAsyncRemote().setSendTimeout(TIMEOUT_MS);
}
long lastSend = 0;
@@ -485,12 +473,11 @@ public class TestWsWebSocketContainer ex
// Should send quickly until the network buffers fill up and then
// block until the timeout kicks in
try {
- while (ok) {
+ while (true) {
lastSend = System.currentTimeMillis();
- Future<SendResult> f = session.getRemote().sendBytesByFuture(
+ Future<Void> f = session.getAsyncRemote().sendBinary(
ByteBuffer.wrap(MESSAGE_BINARY_4K));
- sr = f.get();
- ok = sr.isOK();
+ f.get();
}
} catch (ExecutionException | InterruptedException e) {
exception = e;
@@ -503,14 +490,6 @@ public class TestWsWebSocketContainer ex
return timeout;
}
- public static boolean isOK() {
- return ok;
- }
-
- public static SendResult getSendResult() {
- return sr;
- }
-
public static Exception getException() {
return exception;
}
@@ -599,7 +578,7 @@ public class TestWsWebSocketContainer ex
ContainerProvider.getWebSocketContainer();
// 5 second timeout
- wsContainer.setMaxSessionIdleTimeout(5000);
+ wsContainer.setDefaultMaxSessionIdleTimeout(5000);
wsContainer.setProcessPeriod(1);
connectToEchoServerBasic(wsContainer, EndpointA.class);
@@ -640,15 +619,15 @@ public class TestWsWebSocketContainer ex
ContainerProvider.getWebSocketContainer();
// 5 second timeout
- wsContainer.setMaxSessionIdleTimeout(5000);
+ wsContainer.setDefaultMaxSessionIdleTimeout(5000);
wsContainer.setProcessPeriod(1);
Session s1a = connectToEchoServerBasic(wsContainer, EndpointA.class);
- s1a.setTimeout(3000);
+ s1a.setMaxIdleTimeout(3000);
Session s2a = connectToEchoServerBasic(wsContainer, EndpointA.class);
- s2a.setTimeout(6000);
+ s2a.setMaxIdleTimeout(6000);
Session s3a = connectToEchoServerBasic(wsContainer, EndpointA.class);
- s3a.setTimeout(9000);
+ s3a.setMaxIdleTimeout(9000);
// Check all three sessions are open
Set<Session> setA = s3a.getOpenSessions();
Modified: tomcat/trunk/test/org/apache/tomcat/websocket/TesterEchoServer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/websocket/TesterEchoServer.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/websocket/TesterEchoServer.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/websocket/TesterEchoServer.java Mon Feb 25 10:39:02 2013
@@ -20,8 +20,8 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import javax.servlet.ServletContextEvent;
+import javax.websocket.OnMessage;
import javax.websocket.Session;
-import javax.websocket.WebSocketMessage;
import org.apache.tomcat.websocket.server.ServerContainerImpl;
import org.apache.tomcat.websocket.server.WsListener;
@@ -45,10 +45,10 @@ public class TesterEchoServer {
public static class Async {
- @WebSocketMessage
+ @OnMessage
public void echoTextMessage(Session session, String msg, boolean last) {
try {
- session.getRemote().sendPartialString(msg, last);
+ session.getBasicRemote().sendText(msg, last);
} catch (IOException e) {
try {
session.close();
@@ -59,11 +59,11 @@ public class TesterEchoServer {
}
- @WebSocketMessage
+ @OnMessage
public void echoBinaryMessage(Session session, ByteBuffer msg,
boolean last) {
try {
- session.getRemote().sendPartialBytes(msg, last);
+ session.getBasicRemote().sendBinary(msg, last);
} catch (IOException e) {
try {
session.close();
@@ -75,10 +75,10 @@ public class TesterEchoServer {
}
public static class Basic {
- @WebSocketMessage
+ @OnMessage
public void echoTextMessage(Session session, String msg) {
try {
- session.getRemote().sendString(msg);
+ session.getBasicRemote().sendText(msg);
} catch (IOException e) {
try {
session.close();
@@ -89,10 +89,10 @@ public class TesterEchoServer {
}
- @WebSocketMessage
+ @OnMessage
public void echoBinaryMessage(Session session, ByteBuffer msg) {
try {
- session.getRemote().sendBytes(msg);
+ session.getBasicRemote().sendBinary(msg);
} catch (IOException e) {
try {
session.close();
Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/chat/ChatAnnotation.java Mon Feb 25 10:39:02 2013
@@ -21,10 +21,10 @@ import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
+import javax.websocket.OnClose;
+import javax.websocket.OnMessage;
+import javax.websocket.OnOpen;
import javax.websocket.Session;
-import javax.websocket.WebSocketClose;
-import javax.websocket.WebSocketMessage;
-import javax.websocket.WebSocketOpen;
import javax.websocket.server.WebSocketEndpoint;
import util.HTMLFilter;
@@ -45,7 +45,7 @@ public class ChatAnnotation {
}
- @WebSocketOpen
+ @OnOpen
public void start(Session session) {
this.session = session;
connections.add(this);
@@ -54,7 +54,7 @@ public class ChatAnnotation {
}
- @WebSocketClose
+ @OnClose
public void end() {
try {
session.close();
@@ -69,7 +69,7 @@ public class ChatAnnotation {
}
- @WebSocketMessage
+ @OnMessage
public void incoming(String message) {
// Never trust the client
String filteredMessage = String.format("%s: %s",
@@ -81,7 +81,7 @@ public class ChatAnnotation {
private static void broadcast(String msg) {
for (ChatAnnotation client : connections) {
try {
- client.session.getRemote().sendString(msg);
+ client.session.getBasicRemote().sendText(msg);
} catch (IOException e) {
connections.remove(client);
try {
Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoAnnotation.java Mon Feb 25 10:39:02 2013
@@ -19,19 +19,19 @@ package websocket.echo;
import java.io.IOException;
import java.nio.ByteBuffer;
+import javax.websocket.OnMessage;
import javax.websocket.PongMessage;
import javax.websocket.Session;
-import javax.websocket.WebSocketMessage;
import javax.websocket.server.WebSocketEndpoint;
@WebSocketEndpoint("/websocket/echoAnnotation")
public class EchoAnnotation {
- @WebSocketMessage
+ @OnMessage
public void echoTextMessage(Session session, String msg, boolean last) {
try {
if (session.isOpen()) {
- session.getRemote().sendPartialString(msg, last);
+ session.getBasicRemote().sendText(msg, last);
}
} catch (IOException e) {
try {
@@ -42,12 +42,12 @@ public class EchoAnnotation {
}
}
- @WebSocketMessage
+ @OnMessage
public void echoBinaryMessage(Session session, ByteBuffer bb,
boolean last) {
try {
if (session.isOpen()) {
- session.getRemote().sendPartialBytes(bb, last);
+ session.getBasicRemote().sendBinary(bb, last);
}
} catch (IOException e) {
try {
@@ -63,7 +63,7 @@ public class EchoAnnotation {
*
* @param pm Ignored.
*/
- @WebSocketMessage
+ @OnMessage
public void echoPongMessage(PongMessage pm) {
// NO-OP
}
Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/echo/EchoEndpoint.java Mon Feb 25 10:39:02 2013
@@ -30,8 +30,8 @@ public class EchoEndpoint extends Endpoi
@Override
public void onOpen(Session session, EndpointConfiguration endpointConfig) {
- RemoteEndpoint remoteEndpoint = session.getRemote();
- session.addMessageHandler(new EchoMessageHandler(remoteEndpoint));
+ RemoteEndpoint.Basic remoteEndpointBasic = session.getBasicRemote();
+ session.addMessageHandler(new EchoMessageHandler(remoteEndpointBasic));
}
@Override
@@ -47,17 +47,17 @@ public class EchoEndpoint extends Endpoi
private static class EchoMessageHandler
implements MessageHandler.Basic<String> {
- private final RemoteEndpoint remoteEndpoint;
+ private final RemoteEndpoint.Basic remoteEndpointBasic;
- private EchoMessageHandler(RemoteEndpoint remoteEndpoint) {
- this.remoteEndpoint = remoteEndpoint;
+ private EchoMessageHandler(RemoteEndpoint.Basic remoteEndpointBasic) {
+ this.remoteEndpointBasic = remoteEndpointBasic;
}
@Override
public void onMessage(String message) {
try {
- if (remoteEndpoint != null) {
- remoteEndpoint.sendString(message);
+ if (remoteEndpointBasic != null) {
+ remoteEndpointBasic.sendText(message);
}
} catch (IOException e) {
// TODO Auto-generated catch block
Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/Snake.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/Snake.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/Snake.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/Snake.java Mon Feb 25 10:39:02 2013
@@ -63,7 +63,7 @@ public class Snake {
protected void sendMessage(String msg) {
try {
- session.getRemote().sendString(msg);
+ session.getBasicRemote().sendText(msg);
} catch (IOException ioe) {
// Ignore
}
Modified: tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java?rev=1449652&r1=1449651&r2=1449652&view=diff
==============================================================================
--- tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java (original)
+++ tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/snake/SnakeAnnotation.java Mon Feb 25 10:39:02 2013
@@ -21,10 +21,10 @@ import java.util.Iterator;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
+import javax.websocket.OnClose;
+import javax.websocket.OnMessage;
+import javax.websocket.OnOpen;
import javax.websocket.Session;
-import javax.websocket.WebSocketClose;
-import javax.websocket.WebSocketMessage;
-import javax.websocket.WebSocketOpen;
import javax.websocket.server.WebSocketEndpoint;
@WebSocketEndpoint(value = "/websocket/snake")
@@ -71,7 +71,7 @@ public class SnakeAnnotation {
}
- @WebSocketOpen
+ @OnOpen
public void onOpen(Session session) {
this.snake = new Snake(id, session);
SnakeTimer.addSnake(snake);
@@ -90,7 +90,7 @@ public class SnakeAnnotation {
}
- @WebSocketMessage
+ @OnMessage
public void onTextMessage(String message) {
if ("west".equals(message)) {
snake.setDirection(Direction.WEST);
@@ -104,7 +104,7 @@ public class SnakeAnnotation {
}
- @WebSocketClose
+ @OnClose
public void onClose() {
SnakeTimer.removeSnake(snake);
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}",
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org