Author: markt
Date: Mon Mar 25 23:21:34 2013
New Revision: 1460928
URL: http://svn.apache.org/r1460928
Log:
Add some plumbing in preparation for wss support on the client side
Added:
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapper.java
(with props)
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperNonSecure.java
(with props)
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java
(with props)
tomcat/trunk/java/org/apache/tomcat/websocket/SendHandlerToCompletionHandler.java
(with props)
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties
tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java
tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java
tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
Added: tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapper.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapper.java?rev=1460928&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapper.java
(added)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapper.java Mon
Mar 25 23:21:34 2013
@@ -0,0 +1,38 @@
+/*
+ * 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.nio.ByteBuffer;
+import java.nio.channels.CompletionHandler;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+public interface AsyncChannelWrapper {
+
+ Future<Integer> read(ByteBuffer dst);
+
+ <A> void read(ByteBuffer dst, A attachment,
+ CompletionHandler<Integer,? super A> handler);
+
+ Future<Integer> write(ByteBuffer src);
+
+ <A> void write(ByteBuffer[] srcs, int offset, int length, long timeout,
+ TimeUnit unit, A attachment,
+ CompletionHandler<Long,? super A> handler);
+
+ void close();
+}
Propchange:
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperNonSecure.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperNonSecure.java?rev=1460928&view=auto
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperNonSecure.java
(added)
+++
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperNonSecure.java
Mon Mar 25 23:21:34 2013
@@ -0,0 +1,67 @@
+/*
+ * 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.nio.channels.AsynchronousSocketChannel;
+import java.nio.channels.CompletionHandler;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+public class AsyncChannelWrapperNonSecure implements AsyncChannelWrapper {
+
+ private final AsynchronousSocketChannel socketChannel;
+
+ public AsyncChannelWrapperNonSecure(
+ AsynchronousSocketChannel socketChannel) {
+ this.socketChannel = socketChannel;
+ }
+
+ @Override
+ public Future<Integer> read(ByteBuffer dst) {
+ return socketChannel.read(dst);
+ }
+
+ @Override
+ public <A> void read(ByteBuffer dst, A attachment,
+ CompletionHandler<Integer,? super A> handler) {
+ socketChannel.read(dst, attachment, handler);
+ }
+
+ @Override
+ public Future<Integer> write(ByteBuffer src) {
+ return socketChannel.write(src);
+ }
+
+ @Override
+ public <A> void write(ByteBuffer[] srcs, int offset, int length,
+ long timeout, TimeUnit unit, A attachment,
+ CompletionHandler<Long,? super A> handler) {
+ socketChannel.write(
+ srcs, offset, length, timeout, unit, attachment, handler);
+ }
+
+ @Override
+ public void close() {
+ try {
+ socketChannel.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+}
Propchange:
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperNonSecure.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java?rev=1460928&view=auto
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java
(added)
+++
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java
Mon Mar 25 23:21:34 2013
@@ -0,0 +1,65 @@
+/*
+ * 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.nio.ByteBuffer;
+import java.nio.channels.AsynchronousSocketChannel;
+import java.nio.channels.CompletionHandler;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+public class AsyncChannelWrapperSecure implements AsyncChannelWrapper {
+
+ private final AsynchronousSocketChannel socketChannel;
+
+ public AsyncChannelWrapperSecure(AsynchronousSocketChannel socketChannel) {
+ this.socketChannel = socketChannel;
+ }
+
+ @Override
+ public Future<Integer> read(ByteBuffer dst) {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <A> void read(ByteBuffer dst, A attachment,
+ CompletionHandler<Integer,? super A> handler) {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Future<Integer> write(ByteBuffer src) {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public <A> void write(ByteBuffer[] srcs, int offset, int length,
+ long timeout, TimeUnit unit, A attachment,
+ CompletionHandler<Long,? super A> handler) {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void close() {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+}
Propchange:
tomcat/trunk/java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties?rev=1460928&r1=1460927&r2=1460928&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties Mon
Mar 25 23:21:34 2013
@@ -66,6 +66,7 @@ wsWebSocketContainer.defaultConfigurator
wsWebSocketContainer.endpointCreateFail=Failed to create a local endpoint of
type [{0}]
wsWebSocketContainer.httpRequestFailed=The HTTP request to initiate the
WebSocket conenction failed
wsWebSocketContainer.invalidHeader=Unable to parse HTTP header as no colon is
present to delimit header name and header value in [{0}]. The header has been
skipped.
+wsWebSocketContainer.invalidScheme=The requested scheme, [{0}], is not
supported. The supported schemes are ws and wss
wsWebSocketContainer.invalidStatus=The HTTP response from the server [{0}] did
not permit the HTTP upgrade to WebSocket
wsWebSocketContainer.invalidSubProtocol=The WebSocket server returned multiple
values for the Sec-WebSocket-Protocol header
wsWebSocketContainer.maxBuffer=This implementation limits the maximum size of
a buffer to Integer.MAX_VALUE
Added:
tomcat/trunk/java/org/apache/tomcat/websocket/SendHandlerToCompletionHandler.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/SendHandlerToCompletionHandler.java?rev=1460928&view=auto
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/websocket/SendHandlerToCompletionHandler.java
(added)
+++
tomcat/trunk/java/org/apache/tomcat/websocket/SendHandlerToCompletionHandler.java
Mon Mar 25 23:21:34 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.nio.channels.CompletionHandler;
+
+import javax.websocket.SendHandler;
+import javax.websocket.SendResult;
+
+public class SendHandlerToCompletionHandler
+ implements CompletionHandler<Long,Void> {
+
+ private SendHandler handler;
+
+ public SendHandlerToCompletionHandler(SendHandler handler) {
+ this.handler = handler;
+ }
+
+ @Override
+ public void completed(Long result, Void attachment) {
+ handler.onResult(new SendResult());
+ }
+
+ @Override
+ public void failed(Throwable exc, Void attachment) {
+ handler.onResult(new SendResult(exc));
+ }
+}
Propchange:
tomcat/trunk/java/org/apache/tomcat/websocket/SendHandlerToCompletionHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java?rev=1460928&r1=1460927&r2=1460928&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsFrameClient.java Mon Mar 25
23:21:34 2013
@@ -18,7 +18,6 @@ package org.apache.tomcat.websocket;
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;
import javax.websocket.CloseReason;
@@ -27,10 +26,10 @@ import javax.websocket.CloseReason.Close
public class WsFrameClient extends WsFrameBase {
private final ByteBuffer response;
- private final AsynchronousSocketChannel channel;
+ private final AsyncChannelWrapper channel;
private final CompletionHandler<Integer,Void> handler;
- public WsFrameClient(ByteBuffer response, AsynchronousSocketChannel
channel,
+ public WsFrameClient(ByteBuffer response, AsyncChannelWrapper channel,
WsSession wsSession) {
super(wsSession);
this.response = response;
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java?rev=1460928&r1=1460927&r2=1460928&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplClient.java
Mon Mar 25 23:21:34 2013
@@ -16,20 +16,16 @@
*/
package org.apache.tomcat.websocket;
-import java.io.IOException;
import java.nio.ByteBuffer;
-import java.nio.channels.AsynchronousSocketChannel;
-import java.nio.channels.CompletionHandler;
import java.util.concurrent.TimeUnit;
import javax.websocket.SendHandler;
-import javax.websocket.SendResult;
public class WsRemoteEndpointImplClient extends WsRemoteEndpointImplBase {
- private final AsynchronousSocketChannel channel;
+ private final AsyncChannelWrapper channel;
- public WsRemoteEndpointImplClient(AsynchronousSocketChannel channel) {
+ public WsRemoteEndpointImplClient(AsyncChannelWrapper channel) {
this.channel = channel;
}
@@ -55,31 +51,6 @@ public class WsRemoteEndpointImplClient
@Override
protected void close() {
- try {
- channel.close();
- } catch (IOException ignore) {
- // Ignore
- }
- }
-
-
- private static class SendHandlerToCompletionHandler
- implements CompletionHandler<Long,Void> {
-
- private SendHandler handler;
-
- public SendHandlerToCompletionHandler(SendHandler handler) {
- this.handler = handler;
- }
-
- @Override
- public void completed(Long result, Void attachment) {
- handler.onResult(new SendResult());
- }
-
- @Override
- public void failed(Throwable exc, Void attachment) {
- handler.onResult(new SendResult(exc));
- }
+ channel.close();
}
}
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=1460928&r1=1460927&r2=1460928&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsWebSocketContainer.java Mon
Mar 25 23:21:34 2013
@@ -169,6 +169,8 @@ public class WsWebSocketContainer
ClientEndpointConfig clientEndpointConfiguration, URI path)
throws DeploymentException {
+ boolean secure = false;
+
String scheme = path.getScheme();
if (!("ws".equalsIgnoreCase(scheme) ||
"wss".equalsIgnoreCase(scheme))) {
@@ -192,28 +194,38 @@ public class WsWebSocketContainer
if (port == -1) {
if ("ws".equalsIgnoreCase(scheme)) {
sa = new InetSocketAddress(host, 80);
+ } else if ("wss".equalsIgnoreCase(scheme)) {
+ sa = new InetSocketAddress(host, 443);
+ secure = true;
} else {
- // TODO HTTPS support
- // sa = new InetSocketAddress(host, 443);
- throw new DeploymentException("TODO: HTTPS");
+ throw new DeploymentException(
+ sm.getString("wsWebSocketContainer.invalidScheme"));
}
} else {
sa = new InetSocketAddress(host, port);
}
- AsynchronousSocketChannel channel;
+ AsynchronousSocketChannel socketChannel;
try {
- channel = AsynchronousSocketChannel.open();
+ socketChannel = AsynchronousSocketChannel.open();
} catch (IOException ioe) {
throw new DeploymentException("TODO", ioe);
}
- Future<Void> fConnect = channel.connect(sa);
+
+ Future<Void> fConnect = socketChannel.connect(sa);
+
+ AsyncChannelWrapper channel;
+ if (secure) {
+ channel = new AsyncChannelWrapperSecure(socketChannel);
+ } else {
+ channel = new AsyncChannelWrapperNonSecure(socketChannel);
+ }
+
ByteBuffer response;
String subProtocol;
try {
fConnect.get();
-
int toWrite = request.limit();
Future<Integer> fWrite = channel.write(request);
@@ -427,7 +439,7 @@ public class WsWebSocketContainer
* @throws DeploymentException
*/
private HandshakeResponse processResponse(ByteBuffer response,
- AsynchronousSocketChannel channel) throws InterruptedException,
+ AsyncChannelWrapper channel) throws InterruptedException,
ExecutionException, DeploymentException {
Map<String,List<String>> headers = new HashMap<>();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]