Stubbing out mux client/server specific pieces

This commit is contained in:
Joakim Erdfelt 2012-11-01 13:43:33 -07:00
parent 171fa2db67
commit 88ed9ff710
8 changed files with 211 additions and 14 deletions

View File

@ -0,0 +1,33 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.client.mux;
import org.eclipse.jetty.websocket.core.extensions.mux.add.MuxAddClient;
import org.eclipse.jetty.websocket.core.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.core.io.WebSocketSession;
public class MuxClientAddHandler implements MuxAddClient
{
@Override
public WebSocketSession createSession(MuxAddChannelResponse response)
{
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,31 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.client.mux;
import org.eclipse.jetty.websocket.core.extensions.mux.AbstractMuxExtension;
import org.eclipse.jetty.websocket.core.extensions.mux.Muxer;
public class MuxClientExtension extends AbstractMuxExtension
{
@Override
public void configureMuxer(Muxer muxer)
{
muxer.setAddClient(new MuxClientAddHandler());
}
}

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.core.extensions.mux;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.api.Extension; import org.eclipse.jetty.websocket.core.api.Extension;
import org.eclipse.jetty.websocket.core.api.WebSocketConnection;
import org.eclipse.jetty.websocket.core.api.WebSocketException; import org.eclipse.jetty.websocket.core.api.WebSocketException;
import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame; import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
@ -28,34 +29,27 @@ import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
* <p> * <p>
* Supporting <a href="https://tools.ietf.org/html/draft-ietf-hybi-websocket-multiplexing-08">draft-ietf-hybi-websocket-multiplexing-08</a> Specification. * Supporting <a href="https://tools.ietf.org/html/draft-ietf-hybi-websocket-multiplexing-08">draft-ietf-hybi-websocket-multiplexing-08</a> Specification.
*/ */
public class MuxExtension extends Extension public abstract class AbstractMuxExtension extends Extension
{ {
private Muxer muxer; private Muxer muxer;
public MuxExtension() public AbstractMuxExtension()
{ {
super(); super();
} }
public synchronized Muxer getMuxer() public abstract void configureMuxer(Muxer muxer);
{
if (this.muxer == null)
{
this.muxer = new Muxer(super.getConnection(),this);
}
return muxer;
}
@Override @Override
public void incoming(WebSocketException e) public void incoming(WebSocketException e)
{ {
getMuxer().incoming(e); muxer.incoming(e);
} }
@Override @Override
public void incoming(WebSocketFrame frame) public void incoming(WebSocketFrame frame)
{ {
getMuxer().incoming(frame); muxer.incoming(frame);
} }
@Override @Override
@ -63,4 +57,16 @@ public class MuxExtension extends Extension
{ {
nextOutput(context,callback,frame); nextOutput(context,callback,frame);
} }
@Override
public void setConnection(WebSocketConnection connection)
{
super.setConnection(connection);
if (muxer != null)
{
throw new RuntimeException("Cannot reset muxer physical connection once established");
}
this.muxer = new Muxer(connection,this);
configureMuxer(this.muxer);
}
} }

View File

@ -37,7 +37,7 @@ public interface MuxAddServer
* @param requestHandshake * @param requestHandshake
* the request handshake (request headers) * the request handshake (request headers)
* @return the response handshake (the response headers) * @return the response handshake (the response headers)
* @throws MuxException * @throws AbstractMuxException
* if unable to handshake * if unable to handshake
* @throws IOException * @throws IOException
* if unable to parse request headers * if unable to parse request headers

View File

@ -31,6 +31,7 @@ import java.util.regex.Pattern;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.websocket.core.api.Extension;
import org.eclipse.jetty.websocket.core.api.WebSocketPolicy; import org.eclipse.jetty.websocket.core.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.core.protocol.IncomingFramesCapture; import org.eclipse.jetty.websocket.core.protocol.IncomingFramesCapture;
import org.eclipse.jetty.websocket.core.protocol.OpCode; import org.eclipse.jetty.websocket.core.protocol.OpCode;
@ -41,13 +42,22 @@ import org.junit.Test;
public class MuxParserRFCTest public class MuxParserRFCTest
{ {
public static class DummyMuxExtension extends AbstractMuxExtension
{
@Override
public void configureMuxer(Muxer muxer)
{
/* nothing to do */
}
}
private LinkedList<WebSocketFrame> asFrames(byte[] buf) private LinkedList<WebSocketFrame> asFrames(byte[] buf)
{ {
IncomingFramesCapture capture = new IncomingFramesCapture(); IncomingFramesCapture capture = new IncomingFramesCapture();
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy(); WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
Parser parser = new Parser(policy); Parser parser = new Parser(policy);
parser.setIncomingFramesHandler(capture); parser.setIncomingFramesHandler(capture);
List<MuxExtension> muxList = Collections.singletonList(new MuxExtension()); List<? extends Extension> muxList = Collections.singletonList(new DummyMuxExtension());
parser.configureFromExtensions(muxList); parser.configureFromExtensions(muxList);
ByteBuffer bbuf = ByteBuffer.wrap(buf); ByteBuffer bbuf = ByteBuffer.wrap(buf);
parser.parse(bbuf); parser.parse(bbuf);

View File

@ -0,0 +1,38 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.server.mux;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpChannel;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpInput;
import org.eclipse.jetty.server.HttpTransport;
/**
* Process incoming AddChannelRequest headers within the existing Jetty framework. Benefitting from Server container knowledge and various webapp configuration
* knowledge.
*/
public class HttpChannelOverMux extends HttpChannel<String>
{
public HttpChannelOverMux(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport, HttpInput<String> input)
{
super(connector,configuration,endPoint,transport,input);
}
}

View File

@ -0,0 +1,48 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.server.mux;
import java.io.IOException;
import org.eclipse.jetty.websocket.core.extensions.mux.MuxChannel;
import org.eclipse.jetty.websocket.core.extensions.mux.MuxException;
import org.eclipse.jetty.websocket.core.extensions.mux.add.MuxAddServer;
/**
* Handler for incoming MuxAddChannel requests.
*/
public class MuxAddHandler implements MuxAddServer
{
/**
* An incoming MuxAddChannel request.
*
* @param the
* channel this request should be bound to
* @param requestHandshake
* the incoming request headers
* @return the outgoing response headers
*/
@Override
public String handshake(MuxChannel channel, String requestHandshake) throws MuxException, IOException
{
// Need to call into HttpChannel to get the websocket properly setup.
return null;
}
}

View File

@ -0,0 +1,31 @@
//
// ========================================================================
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.websocket.server.mux;
import org.eclipse.jetty.websocket.core.extensions.mux.AbstractMuxExtension;
import org.eclipse.jetty.websocket.core.extensions.mux.Muxer;
public class MuxServerExtension extends AbstractMuxExtension
{
@Override
public void configureMuxer(Muxer muxer)
{
muxer.setAddServer(new MuxAddHandler());
}
}