mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 00:40:51 +01:00
Update jetty and drop javax.websocket-api
This commit is contained in:
parent
b96000148f
commit
16749e9e96
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<javafx.version>1.8</javafx.version>
|
<javafx.version>1.8</javafx.version>
|
||||||
<jettyVersion>9.4.48.v20220622</jettyVersion>
|
<jettyVersion>9.4.50.v20221201</jettyVersion>
|
||||||
<logback.version>1.3.5</logback.version>
|
<logback.version>1.3.5</logback.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
@ -238,14 +238,11 @@
|
|||||||
<artifactId>maven-artifact</artifactId>
|
<artifactId>maven-artifact</artifactId>
|
||||||
<version>3.6.3</version>
|
<version>3.6.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.websocket</groupId>
|
<groupId>javax.websocket</groupId>
|
||||||
<artifactId>javax.websocket-api</artifactId>
|
<artifactId>javax.websocket-api</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-server</artifactId>
|
<artifactId>jetty-server</artifactId>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package gearth.protocol.connection.proxy.nitro.websocket;
|
package gearth.protocol.connection.proxy.nitro.websocket;
|
||||||
|
|
||||||
import javax.websocket.Session;
|
import org.eclipse.jetty.websocket.api.Session;
|
||||||
|
|
||||||
public interface NitroSession {
|
public interface NitroSession {
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ public class NitroWebsocketClient implements NitroSession {
|
|||||||
|
|
||||||
activeSession = (JsrSession) session;
|
activeSession = (JsrSession) session;
|
||||||
activeSession.setMaxBinaryMessageBufferSize(NitroConstants.WEBSOCKET_BUFFER_SIZE);
|
activeSession.setMaxBinaryMessageBufferSize(NitroConstants.WEBSOCKET_BUFFER_SIZE);
|
||||||
|
activeSession.setMaxTextMessageBufferSize(NitroConstants.WEBSOCKET_BUFFER_SIZE);
|
||||||
|
|
||||||
// Set proper headers to spoof being a real client.
|
// Set proper headers to spoof being a real client.
|
||||||
final Map<String, List<String>> headers = new HashMap<>(activeSession.getUpgradeRequest().getHeaders());
|
final Map<String, List<String>> headers = new HashMap<>(activeSession.getUpgradeRequest().getHeaders());
|
||||||
@ -94,7 +95,7 @@ public class NitroWebsocketClient implements NitroSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Session getSession() {
|
public org.eclipse.jetty.websocket.api.Session getSession() {
|
||||||
return activeSession;
|
return activeSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,17 +5,21 @@ import gearth.protocol.HMessage;
|
|||||||
import gearth.protocol.connection.proxy.nitro.NitroConstants;
|
import gearth.protocol.connection.proxy.nitro.NitroConstants;
|
||||||
import gearth.protocol.packethandler.PacketHandler;
|
import gearth.protocol.packethandler.PacketHandler;
|
||||||
import gearth.protocol.packethandler.nitro.NitroPacketHandler;
|
import gearth.protocol.packethandler.nitro.NitroPacketHandler;
|
||||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
import org.eclipse.jetty.websocket.api.Session;
|
||||||
import org.eclipse.jetty.websocket.jsr356.JsrExtension;
|
import org.eclipse.jetty.websocket.api.WebSocketListener;
|
||||||
|
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
||||||
|
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.websocket.*;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class NitroWebsocketServer extends Endpoint implements NitroSession {
|
public class NitroWebsocketServer implements WebSocketListener, NitroSession {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(NitroWebsocketServer.class);
|
private static final Logger logger = LoggerFactory.getLogger(NitroWebsocketServer.class);
|
||||||
|
|
||||||
@ -39,66 +43,34 @@ public class NitroWebsocketServer extends Endpoint implements NitroSession {
|
|||||||
|
|
||||||
public void connect(String websocketUrl, Map<String, List<String>> clientHeaders) throws IOException {
|
public void connect(String websocketUrl, Map<String, List<String>> clientHeaders) throws IOException {
|
||||||
try {
|
try {
|
||||||
logger.info("Connecting to origin websocket at {}", websocketUrl);
|
logger.info("Building origin websocket connection ({})", websocketUrl);
|
||||||
|
|
||||||
ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
|
final WebSocketClient client = new WebSocketClient();
|
||||||
|
|
||||||
builder.extensions(Collections.singletonList(new JsrExtension(new ExtensionConfig("permessage-deflate;client_max_window_bits"))));
|
client.setMaxBinaryMessageBufferSize(NitroConstants.WEBSOCKET_BUFFER_SIZE);
|
||||||
|
client.setMaxTextMessageBufferSize(NitroConstants.WEBSOCKET_BUFFER_SIZE);
|
||||||
|
|
||||||
builder.configurator(new ClientEndpointConfig.Configurator() {
|
final ClientUpgradeRequest request = new ClientUpgradeRequest();
|
||||||
@Override
|
|
||||||
public void beforeRequest(Map<String, List<String>> headers) {
|
|
||||||
clientHeaders.forEach((key, value) -> {
|
|
||||||
if (SKIP_HEADERS.contains(key)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
headers.remove(key);
|
clientHeaders.forEach((key, value) -> {
|
||||||
headers.put(key, value);
|
if (SKIP_HEADERS.contains(key)) {
|
||||||
});
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request.setHeader(key, value);
|
||||||
});
|
});
|
||||||
|
|
||||||
ClientEndpointConfig config = builder.build();
|
logger.info("Connecting to origin websocket at {}", websocketUrl);
|
||||||
|
|
||||||
ContainerProvider.getWebSocketContainer().connectToServer(this, config, URI.create(websocketUrl));
|
client.start();
|
||||||
|
client.connect(this, URI.create(websocketUrl), request);
|
||||||
|
|
||||||
logger.info("Connected to origin websocket");
|
logger.info("Connected to origin websocket");
|
||||||
} catch (DeploymentException e) {
|
} catch (Exception e) {
|
||||||
throw new IOException("Failed to deploy websocket client", e);
|
throw new IOException("Failed to start websocket client to origin " + websocketUrl, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onOpen(Session session, EndpointConfig config) {
|
|
||||||
this.activeSession = session;
|
|
||||||
this.activeSession.setMaxBinaryMessageBufferSize(NitroConstants.WEBSOCKET_BUFFER_SIZE);
|
|
||||||
this.activeSession.addMessageHandler(new MessageHandler.Whole<byte[]>() {
|
|
||||||
@Override
|
|
||||||
public void onMessage(byte[] message) {
|
|
||||||
try {
|
|
||||||
packetHandler.act(message);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClose(Session session, CloseReason closeReason) {
|
|
||||||
// Hotel closed connection.
|
|
||||||
client.shutdownProxy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Session session, Throwable throwable) {
|
|
||||||
throwable.printStackTrace();
|
|
||||||
|
|
||||||
// Shutdown.
|
|
||||||
client.shutdownProxy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Session getSession() {
|
public Session getSession() {
|
||||||
return activeSession;
|
return activeSession;
|
||||||
@ -118,10 +90,43 @@ public class NitroWebsocketServer extends Endpoint implements NitroSession {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
activeSession.close();
|
activeSession.close();
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
activeSession = null;
|
activeSession = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWebSocketBinary(byte[] bytes, int i, int i1) {
|
||||||
|
try {
|
||||||
|
packetHandler.act(bytes);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Failed to handle packet", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWebSocketText(String s) {
|
||||||
|
logger.warn("Received text message from hotel");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWebSocketClose(int i, String s) {
|
||||||
|
// Hotel closed connection.
|
||||||
|
client.shutdownProxy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWebSocketConnect(org.eclipse.jetty.websocket.api.Session session) {
|
||||||
|
activeSession = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onWebSocketError(Throwable throwable) {
|
||||||
|
throwable.printStackTrace();
|
||||||
|
|
||||||
|
// Shutdown.
|
||||||
|
client.shutdownProxy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,17 @@ import gearth.protocol.connection.proxy.nitro.websocket.NitroSession;
|
|||||||
import gearth.protocol.packethandler.PacketHandler;
|
import gearth.protocol.packethandler.PacketHandler;
|
||||||
import gearth.protocol.packethandler.PayloadBuffer;
|
import gearth.protocol.packethandler.PayloadBuffer;
|
||||||
import gearth.services.extension_handler.ExtensionHandler;
|
import gearth.services.extension_handler.ExtensionHandler;
|
||||||
|
import org.eclipse.jetty.websocket.api.Session;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.websocket.Session;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class NitroPacketHandler extends PacketHandler {
|
public class NitroPacketHandler extends PacketHandler {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(NitroPacketHandler.class);
|
||||||
|
|
||||||
private final HMessage.Direction direction;
|
private final HMessage.Direction direction;
|
||||||
private final NitroSession session;
|
private final NitroSession session;
|
||||||
private final PayloadBuffer payloadBuffer;
|
private final PayloadBuffer payloadBuffer;
|
||||||
@ -39,7 +43,13 @@ public class NitroPacketHandler extends PacketHandler {
|
|||||||
buffer = buffer.clone();
|
buffer = buffer.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
localSession.getAsyncRemote().sendBinary(ByteBuffer.wrap(buffer));
|
try {
|
||||||
|
localSession.getRemote().sendBytes(ByteBuffer.wrap(buffer));
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Error sending packet to nitro client", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user