Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup of websocket to fix JPMS warnings #9356

Merged
merged 10 commits into from
Feb 17, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@
import org.eclipse.jetty.websocket.core.Configuration;
import org.eclipse.jetty.websocket.core.CoreSession;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.ExtensionStack;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.Negotiated;
import org.eclipse.jetty.websocket.core.WebSocketConnection;
import org.eclipse.jetty.websocket.core.WebSocketConstants;
import org.eclipse.jetty.websocket.core.client.internal.HttpUpgraderOverHTTP;
import org.eclipse.jetty.websocket.core.client.internal.HttpUpgraderOverHTTP2;
import org.eclipse.jetty.websocket.core.exception.UpgradeException;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
import org.eclipse.jetty.websocket.core.internal.ExtensionStack;
import org.eclipse.jetty.websocket.core.internal.Negotiated;
import org.eclipse.jetty.websocket.core.internal.WebSocketConnection;
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -473,7 +472,7 @@ else if (values.length == 1)
extensionStack,
WebSocketConstants.SPEC_VERSION_STRING);

WebSocketCoreSession coreSession = new WebSocketCoreSession(frameHandler, Behavior.CLIENT, negotiated, wsClient.getWebSocketComponents());
CoreSession coreSession = CoreSession.from(frameHandler, Behavior.CLIENT, negotiated, wsClient.getWebSocketComponents());
coreSession.setClassLoader(wsClient.getClassLoader());
customizer.customize(coreSession);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.WebSocketConstants;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.internal.WebSocketCore;
import org.eclipse.jetty.websocket.core.util.WebSocketUtil;

public class HttpUpgraderOverHTTP implements HttpUpgrader
{
Expand Down Expand Up @@ -85,7 +85,7 @@ public void upgrade(Response response, EndPoint endPoint, Callback callback)
{
// Check the Accept hash
String reqKey = requestHeaders.get(HttpHeader.SEC_WEBSOCKET_KEY);
String expectedHash = WebSocketCore.hashKey(reqKey);
String expectedHash = WebSocketUtil.hashKey(reqKey);
String respHash = responseHeaders.get(HttpHeader.SEC_WEBSOCKET_ACCEPT);
if (expectedHash.equalsIgnoreCase(respHash))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,11 @@

exports org.eclipse.jetty.websocket.core;
exports org.eclipse.jetty.websocket.core.exception;

exports org.eclipse.jetty.websocket.core.messages;
exports org.eclipse.jetty.websocket.core.util;
exports org.eclipse.jetty.websocket.core.internal to
org.eclipse.jetty.websocket.core.client,
org.eclipse.jetty.websocket.core.server,
org.eclipse.jetty.util; // Export to DecoratedObjectFactory.

// The Jetty & Jakarta API Layers need to access both access some internal utilities which we don't want to expose.
exports org.eclipse.jetty.websocket.core.internal.util to
org.eclipse.jetty.ee8.websocket.jetty.common,
org.eclipse.jetty.ee8.websocket.jetty.client,
org.eclipse.jetty.ee8.websocket.jetty.server,
org.eclipse.jetty.ee8.websocket.javax.common,
org.eclipse.jetty.ee8.websocket.javax.client,
org.eclipse.jetty.ee8.websocket.javax.server,
org.eclipse.jetty.ee9.websocket.jetty.common,
org.eclipse.jetty.ee9.websocket.jetty.client,
org.eclipse.jetty.ee9.websocket.jetty.server,
org.eclipse.jetty.ee9.websocket.jakarta.common,
org.eclipse.jetty.ee9.websocket.jakarta.client,
org.eclipse.jetty.ee9.websocket.jakarta.server,
org.eclipse.jetty.ee10.websocket.jetty.common,
org.eclipse.jetty.ee10.websocket.jetty.client,
org.eclipse.jetty.ee10.websocket.jetty.server,
org.eclipse.jetty.ee10.websocket.jakarta.common,
org.eclipse.jetty.ee10.websocket.jakarta.client,
org.eclipse.jetty.ee10.websocket.jakarta.server;

exports org.eclipse.jetty.websocket.core.internal.messages to
org.eclipse.jetty.ee8.websocket.jetty.common,
org.eclipse.jetty.ee8.websocket.jetty.client,
org.eclipse.jetty.ee8.websocket.jetty.server,
org.eclipse.jetty.ee8.websocket.javax.common,
org.eclipse.jetty.ee8.websocket.javax.client,
org.eclipse.jetty.ee8.websocket.javax.server,
org.eclipse.jetty.ee9.websocket.jetty.common,
org.eclipse.jetty.ee9.websocket.jetty.client,
org.eclipse.jetty.ee9.websocket.jetty.server,
org.eclipse.jetty.ee9.websocket.jakarta.common,
org.eclipse.jetty.ee9.websocket.jakarta.client,
org.eclipse.jetty.ee9.websocket.jakarta.server,
org.eclipse.jetty.ee10.websocket.jetty.common,
org.eclipse.jetty.ee10.websocket.jetty.client,
org.eclipse.jetty.ee10.websocket.jetty.server,
org.eclipse.jetty.ee10.websocket.jakarta.common,
org.eclipse.jetty.ee10.websocket.jakarta.client,
org.eclipse.jetty.ee10.websocket.jakarta.server;

uses org.eclipse.jetty.websocket.core.Extension;

provides org.eclipse.jetty.websocket.core.Extension with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,34 @@
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.websocket.core.internal.WebSocketCoreSession;

/**
* Represents the outgoing Frames.
*/
public interface CoreSession extends OutgoingFrames, Configuration
public interface CoreSession extends OutgoingFrames, IncomingFrames, Configuration
{
/**
* The negotiated WebSocket Sub-Protocol for this session.
*
* @return the negotiated WebSocket Sub-Protocol for this session.
*/
static CoreSession from(FrameHandler handler, Behavior behavior, Negotiated negotiated, WebSocketComponents components)
{
return new WebSocketCoreSession(handler, behavior, negotiated, components);
}

static CoreSession from(FrameHandler handler, Behavior behavior, Negotiated negotiated, WebSocketComponents components, Consumer<Runnable> handle)
{
return new WebSocketCoreSession(handler, behavior, negotiated, components)
{
@Override
protected void handle(Runnable runnable)
{
handle.accept(runnable);
}
};
}

String getNegotiatedSubProtocol();

/**
Expand Down Expand Up @@ -120,11 +134,8 @@ public interface CoreSession extends OutgoingFrames, Configuration
*/
boolean isOutputOpen();

/**
* If using BatchMode.ON or BatchMode.AUTO, trigger a flush of enqueued / batched frames.
*
* @param callback the callback to track close frame sent (or failed)
*/
boolean isClosed();

void flush(Callback callback);

/**
Expand Down Expand Up @@ -185,6 +196,47 @@ public interface CoreSession extends OutgoingFrames, Configuration
*/
boolean isRsv3Used();

/**
* Used to notify the {@link CoreSession} that EOF has been read or the connection has been closed.
*/
void onEof();

/**
* Used to notify the {@link CoreSession} that the connection has been opened.
*/
void onOpen();

/**
* Process an Error that originated from the connection.
* For protocol causes, send and abnormal close frame
* otherwise just close the connection.
*
* @param cause the cause
* @param callback the callback on completion of error handling
*/
void processConnectionError(Throwable cause, Callback callback);

/**
* Process an Error that originated from the handler.
* Send an abnormal close frame to ensure connection is closed.
*
* @param cause the cause
* @param callback the callback on completion of error handling
*/
void processHandlerError(Throwable cause, Callback callback);

/**
* Set the class loader to be used by this {@link CoreSession}.
* @param classLoader the ClassLoader.
*/
void setClassLoader(ClassLoader classLoader);
lachlan-roberts marked this conversation as resolved.
Show resolved Hide resolved

/**
* Used to set the WebSocketConnection on this {@link CoreSession}.
* @param connection the websocket connection.
*/
void setWebSocketConnection(WebSocketConnection connection);

class Empty extends ConfigurationCustomizer implements CoreSession
sbordet marked this conversation as resolved.
Show resolved Hide resolved
{
@Override
Expand Down Expand Up @@ -270,6 +322,12 @@ public boolean isOutputOpen()
return true;
}

@Override
public boolean isClosed()
{
return false;
}

@Override
public void flush(Callback callback)
{
Expand All @@ -293,6 +351,12 @@ public void demand(long n)
{
}

@Override
public void onFrame(Frame frame, Callback callback)
{
callback.succeeded();
}

@Override
public void sendFrame(Frame frame, Callback callback, boolean batch)
{
Expand All @@ -316,5 +380,37 @@ public boolean isRsv3Used()
{
return false;
}

@Override
public void onEof()
{
}

@Override
public void onOpen()
{
}

@Override
public void processConnectionError(Throwable cause, Callback callback)
{
callback.succeeded();
}

@Override
public void processHandlerError(Throwable cause, Callback callback)
{
callback.succeeded();
}

@Override
public void setClassLoader(ClassLoader classLoader)
{
}

@Override
public void setWebSocketConnection(WebSocketConnection connection)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// ========================================================================
//

package org.eclipse.jetty.websocket.core.internal;
package org.eclipse.jetty.websocket.core;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -26,14 +26,8 @@
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.websocket.core.Behavior;
import org.eclipse.jetty.websocket.core.Extension;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.Frame;
import org.eclipse.jetty.websocket.core.IncomingFrames;
import org.eclipse.jetty.websocket.core.OutgoingFrames;
import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.exception.WebSocketException;
import org.eclipse.jetty.websocket.core.internal.DemandChain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -258,7 +252,7 @@ public void sendFrame(Frame frame, Callback callback, boolean batch)
outgoing.sendFrame(frame, callback, batch);
}

public void initialize(IncomingFrames incoming, OutgoingFrames outgoing, WebSocketCoreSession coreSession)
public void initialize(IncomingFrames incoming, OutgoingFrames outgoing, CoreSession coreSession)
{
if (extensions == null)
throw new IllegalStateException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.eclipse.jetty.websocket.core;

import java.io.Closeable;
import java.nio.ByteBuffer;
import java.util.Arrays;

Expand Down Expand Up @@ -510,4 +511,54 @@ public Frame asReadOnly()
return this;
}
}

public static class Parsed extends Frame implements Closeable, CloseStatus.Supplier
{
final CloseStatus closeStatus;
final Runnable releaser;

public Parsed(byte firstByte, byte[] mask, ByteBuffer payload, Runnable releaser)
{
super(firstByte, mask, payload);
demask();
this.releaser = releaser;
if (getOpCode() == OpCode.CLOSE)
{
if (hasPayload())
closeStatus = new CloseStatus(payload.duplicate());
else
closeStatus = CloseStatus.NO_CODE_STATUS;
}
else
{
closeStatus = null;
}
}

@Override
public void close()
{
if (releaser != null)
releaser.run();
}

@Override
public CloseStatus getCloseStatus()
{
return closeStatus;
}

public boolean isReleaseable()
{
return releaser != null;
}

@Override
public String toString()
{
if (closeStatus == null)
return super.toString();
return super.toString() + ":" + closeStatus;
}
}
}
Loading