Stubbing out mux client/server specific pieces
This commit is contained in:
parent
171fa2db67
commit
88ed9ff710
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.websocket.core.extensions.mux;
|
|||
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
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.protocol.WebSocketFrame;
|
||||
|
||||
|
@ -28,34 +29,27 @@ import org.eclipse.jetty.websocket.core.protocol.WebSocketFrame;
|
|||
* <p>
|
||||
* 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;
|
||||
|
||||
public MuxExtension()
|
||||
public AbstractMuxExtension()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public synchronized Muxer getMuxer()
|
||||
{
|
||||
if (this.muxer == null)
|
||||
{
|
||||
this.muxer = new Muxer(super.getConnection(),this);
|
||||
}
|
||||
return muxer;
|
||||
}
|
||||
public abstract void configureMuxer(Muxer muxer);
|
||||
|
||||
@Override
|
||||
public void incoming(WebSocketException e)
|
||||
{
|
||||
getMuxer().incoming(e);
|
||||
muxer.incoming(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incoming(WebSocketFrame frame)
|
||||
{
|
||||
getMuxer().incoming(frame);
|
||||
muxer.incoming(frame);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,4 +57,16 @@ public class MuxExtension extends Extension
|
|||
{
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ public interface MuxAddServer
|
|||
* @param requestHandshake
|
||||
* the request handshake (request headers)
|
||||
* @return the response handshake (the response headers)
|
||||
* @throws MuxException
|
||||
* @throws AbstractMuxException
|
||||
* if unable to handshake
|
||||
* @throws IOException
|
||||
* if unable to parse request headers
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
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.protocol.IncomingFramesCapture;
|
||||
import org.eclipse.jetty.websocket.core.protocol.OpCode;
|
||||
|
@ -41,13 +42,22 @@ import org.junit.Test;
|
|||
|
||||
public class MuxParserRFCTest
|
||||
{
|
||||
public static class DummyMuxExtension extends AbstractMuxExtension
|
||||
{
|
||||
@Override
|
||||
public void configureMuxer(Muxer muxer)
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
}
|
||||
|
||||
private LinkedList<WebSocketFrame> asFrames(byte[] buf)
|
||||
{
|
||||
IncomingFramesCapture capture = new IncomingFramesCapture();
|
||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
Parser parser = new Parser(policy);
|
||||
parser.setIncomingFramesHandler(capture);
|
||||
List<MuxExtension> muxList = Collections.singletonList(new MuxExtension());
|
||||
List<? extends Extension> muxList = Collections.singletonList(new DummyMuxExtension());
|
||||
parser.configureFromExtensions(muxList);
|
||||
ByteBuffer bbuf = ByteBuffer.wrap(buf);
|
||||
parser.parse(bbuf);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue