Skip to content

Commit

Permalink
Merge pull request #9356 from eclipse/jetty-12.0.x-websocket-JPMS
Browse files Browse the repository at this point in the history
cleanup of websocket to fix JPMS warnings
  • Loading branch information
lachlan-roberts authored Feb 17, 2023
2 parents a8737cd + 41d5500 commit 8104665
Show file tree
Hide file tree
Showing 243 changed files with 532 additions and 594 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>*,org.eclipse.jetty.websocket.core.client.internal.*</Export-Package>
<Export-Package>*</Export-Package>
</instructions>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
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.WebSocketCoreSession;
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 @@ -480,8 +480,8 @@ else if (values.length == 1)
HttpClient httpClient = wsClient.getHttpClient();
ByteBufferPool bufferPool = wsClient.getWebSocketComponents().getByteBufferPool();
WebSocketConnection wsConnection = new WebSocketConnection(endPoint, httpClient.getExecutor(), httpClient.getScheduler(), bufferPool, coreSession);
wsClient.getEventListeners().forEach(wsConnection::addEventListener);
coreSession.setWebSocketConnection(wsConnection);
wsClient.getEventListeners().forEach(wsConnection::addEventListener);
Throwable listenerError = notifyUpgradeListeners((listener) -> listener.onHandshakeResponse(request, response));
if (listenerError != null)
throw new WebSocketException("onHandshakeResponse error", listenerError);
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.WebSocketUtils;

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 = WebSocketUtils.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 @@ -38,7 +38,7 @@
<configuration>
<instructions>
<Bundle-Description>Jetty Websocket Core Common</Bundle-Description>
<Export-Package>*,org.eclipse.jetty.websocket.core.common.internal.*</Export-Package>
<Export-Package>*</Export-Package>
<Require-Capability>
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"; resolution:=optional
</Require-Capability>
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 @@ -25,13 +25,8 @@
/**
* 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.
*/
String getNegotiatedSubProtocol();

/**
Expand Down Expand Up @@ -120,11 +115,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 @@ -270,6 +262,12 @@ public boolean isOutputOpen()
return true;
}

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

@Override
public void flush(Callback callback)
{
Expand All @@ -293,6 +291,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 Down
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.util.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;
}
}
}
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.net.URI;
import java.net.URISyntaxException;
Expand All @@ -23,11 +23,9 @@
import java.util.stream.Collectors;

import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.util.MultiMap;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.UrlEncoded;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.WebSocketConstants;

public class Negotiated
{
Expand Down Expand Up @@ -56,11 +54,11 @@ public Negotiated(URI requestURI, String subProtocol, boolean secure,
else
{
map = new HashMap<>();
MultiMap<String> params = new MultiMap<>();
UrlEncoded.decodeUtf8To(rawQuery, params);
for (String p : params.keySet())
Fields fields = new Fields();
UrlEncoded.decodeUtf8To(rawQuery, fields);
for (Fields.Field field : fields)
{
map.put(p, Collections.unmodifiableList(params.getValues(p)));
map.put(field.getValue(), Collections.unmodifiableList(field.getValues()));
}
}
this.parameterMap = Collections.unmodifiableMap(map);
Expand Down
Loading

0 comments on commit 8104665

Please sign in to comment.