Skip to content

Commit

Permalink
Merge branch 2.1.x into 2.x
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol committed Jan 31, 2024
2 parents 3288c77 + fd1e9ea commit ba325a0
Show file tree
Hide file tree
Showing 100 changed files with 553 additions and 268 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ for easy development of WebSocket applications.Eclipse Tyrus is also
a Jakarta WebSocket 2.0 compatible implementation.

WebSocket protocol defined by IETF
provides bi-directional communication between the server and the remote host. The
provides bidirectional communication between the server and the remote host. The
pros are mainly the ability to communicate both ways, low latency and small
communication overhead. Therefore Tyrus and WebSocket in general are suitable for web
communication overhead. Therefore, Tyrus and WebSocket in general are suitable for web
applications that require sending a huge volume of relatively small messages like
online games or market ticker broadcasting.

Expand All @@ -23,6 +23,15 @@ This is Jakarta EE 11 / Jakarta WebSocket 2.2.0 compatible branch of Tyrus
Building Tyrus can be done using `mvn clean install`, but sometimes (such as for building 2.x from a tag)
`mvn clean install -Pstaging` would be required.

## Tyrus Git Branches

| branch | Jakarta Version | Tyrus Version |
|--------|---------------------------------|---------------|
| master | Java EE 8 / Jakarta EE 8 branch | Tyrus 1.x |
| 2.0.x | Jakarta EE 9 branch | Tyrus 2.0.x |
| 2.1.x | Jakarta EE 10 branch | Tyrus 2.1.x |
| 2.x | Jakarta EE 11 branch | Tyrus 2.2.x |

## Licensing

- [Eclipse Public License 2.0](https://projects.eclipse.org/license/epl-2.0)
Expand Down
2 changes: 1 addition & 1 deletion archetypes/echo/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2014, 2023 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down
2 changes: 1 addition & 1 deletion archetypes/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2014, 2022 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down
2 changes: 1 addition & 1 deletion bundles/client-jdk/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Copyright (c) 2014, 2022 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down
2 changes: 1 addition & 1 deletion bundles/client/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down
2 changes: 1 addition & 1 deletion bundles/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down
2 changes: 1 addition & 1 deletion bundles/samples/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down
2 changes: 1 addition & 1 deletion bundles/websocket-ri-archive/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down
2 changes: 1 addition & 1 deletion bundles/websocket-ri-bundle/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down
6 changes: 1 addition & 5 deletions client/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2011, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -54,10 +54,6 @@
<inherited>true</inherited>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>org.glassfish.tyrus.client;version=${project.version}</Export-Package>
<!-- <Import-Package>jakarta.websocket;version=${apijar.bundle.version},*</Import-Package>-->
</instructions>
<unpackBundle>true</unpackBundle>
</configuration>
</plugin>
Expand Down
3 changes: 2 additions & 1 deletion client/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -26,4 +26,5 @@

exports org.glassfish.tyrus.client;
exports org.glassfish.tyrus.client.auth;
exports org.glassfish.tyrus.client.exception;
}
83 changes: 22 additions & 61 deletions client/src/main/java/org/glassfish/tyrus/client/ClientManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -42,6 +42,7 @@
import jakarta.websocket.Session;
import jakarta.websocket.WebSocketContainer;

import org.glassfish.tyrus.client.exception.Exceptions;
import org.glassfish.tyrus.core.AnnotatedEndpoint;
import org.glassfish.tyrus.core.BaseContainer;
import org.glassfish.tyrus.core.ComponentProviderService;
Expand All @@ -52,6 +53,7 @@
import org.glassfish.tyrus.core.TyrusFuture;
import org.glassfish.tyrus.core.TyrusSession;
import org.glassfish.tyrus.core.Utils;
import org.glassfish.tyrus.core.collection.SupplierWithEx;
import org.glassfish.tyrus.core.monitoring.EndpointEventListener;
import org.glassfish.tyrus.spi.ClientContainer;
import org.glassfish.tyrus.spi.ClientEngine;
Expand Down Expand Up @@ -288,81 +290,46 @@ public boolean evaluate() {
}

@Override
public Session connectToServer(Class annotatedEndpointClass, URI path) throws DeploymentException, IOException {
public Session connectToServer(final Class annotatedEndpointClass, final URI path) throws DeploymentException, IOException {
if (annotatedEndpointClass.getAnnotation(ClientEndpoint.class) == null) {
throw new DeploymentException(
String.format(
"Class argument in connectToServer(Class, URI) is to be annotated endpoint class. Class "
+ "%s does not have @ClientEndpoint", annotatedEndpointClass.getName()));
}
try {
return connectToServer(annotatedEndpointClass, null, path.toString(), true).get();
} catch (InterruptedException e) {
throw new DeploymentException(e.getMessage(), e);
} catch (ExecutionException e) {
final Throwable cause = e.getCause();
if (cause instanceof DeploymentException) {
throw (DeploymentException) cause;
} else if (cause instanceof IOException) {
throw (IOException) cause;
} else {
throw new DeploymentException(cause.getMessage(), cause);
}
}
return tryCatchInterruptedExecutionEx(() -> connectToServer(annotatedEndpointClass, null, path.toString(), true));
}

@Override
public Session connectToServer(Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, URI path) throws
DeploymentException, IOException {
try {
return connectToServer(endpointClass, cec, path.toString(), true).get();
} catch (InterruptedException e) {
throw new DeploymentException(e.getMessage(), e);
} catch (ExecutionException e) {
final Throwable cause = e.getCause();
if (cause instanceof DeploymentException) {
throw (DeploymentException) cause;
} else if (cause instanceof IOException) {
throw (IOException) cause;
} else {
throw new DeploymentException(cause.getMessage(), cause);
}
}
public Session connectToServer(final Class<? extends Endpoint> endpointClass,
final ClientEndpointConfig cec,
final URI path) throws DeploymentException, IOException {
return tryCatchInterruptedExecutionEx(() -> connectToServer(endpointClass, cec, path.toString(), true));
}

@Override
public Session connectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, URI path) throws
public Session connectToServer(final Endpoint endpointInstance, final ClientEndpointConfig cec, final URI path) throws
DeploymentException, IOException {
try {
return connectToServer(endpointInstance, cec, path.toString(), true).get();
} catch (InterruptedException e) {
throw new DeploymentException(e.getMessage(), e);
} catch (ExecutionException e) {
final Throwable cause = e.getCause();
if (cause instanceof DeploymentException) {
throw (DeploymentException) cause;
} else if (cause instanceof IOException) {
throw (IOException) cause;
} else {
throw new DeploymentException(cause.getMessage(), cause);
}
}
return tryCatchInterruptedExecutionEx(() -> connectToServer(endpointInstance, cec, path.toString(), true));
}

@Override
public Session connectToServer(Object obj, URI path) throws DeploymentException, IOException {
public Session connectToServer(final Object obj, final URI path) throws DeploymentException, IOException {
return tryCatchInterruptedExecutionEx(() -> connectToServer(obj, null, path.toString(), true));
}

private Session tryCatchInterruptedExecutionEx(SupplierWithEx<Future<Session>, DeploymentException> supplier)
throws DeploymentException, IOException {
try {
return connectToServer(obj, null, path.toString(), true).get();
return supplier.get().get();
} catch (InterruptedException e) {
throw new DeploymentException(e.getMessage(), e);
} catch (ExecutionException e) {
final Throwable cause = e.getCause();
if (cause instanceof DeploymentException) {
throw (DeploymentException) cause;
} else if (cause instanceof IOException) {
if (cause instanceof IOException) {
throw (IOException) cause;
} else {
throw new DeploymentException(cause.getMessage(), cause);
throw Exceptions.deploymentException(cause.getMessage(), cause);
}
}
}
Expand Down Expand Up @@ -652,11 +619,7 @@ public void onClose(TyrusSession session,
if (countedDown) {
final Throwable exception = listener.getThrowable();
if (exception != null) {
if (exception instanceof DeploymentException) {
throw (DeploymentException) exception;
} else {
throw new DeploymentException("Handshake error.", exception);
}
throw Exceptions.deploymentException("Handshake error.", exception);
}

future.setResult(listener.getSession());
Expand All @@ -669,10 +632,8 @@ public void onClose(TyrusSession session,
timeoutHandler.handleTimeout();
}
}
} catch (DeploymentException e) {
throw e;
} catch (Exception e) {
throw new DeploymentException("Handshake response not received.", e);
throw Exceptions.deploymentException("Handshake response not received.", e);
}

throw new DeploymentException("Handshake response not received.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -65,6 +65,7 @@
import org.glassfish.tyrus.spi.ClientEngine;
import org.glassfish.tyrus.spi.Connection;
import org.glassfish.tyrus.spi.ReadHandler;
import org.glassfish.tyrus.spi.TyrusClientEndpointConfigurator;
import org.glassfish.tyrus.spi.UpgradeRequest;
import org.glassfish.tyrus.spi.UpgradeResponse;
import org.glassfish.tyrus.spi.Writer;
Expand Down Expand Up @@ -169,6 +170,9 @@ public UpgradeRequest createUpgradeRequest(TimeoutHandler timeoutHandler) {
clientHandShake.prepareRequest();

UpgradeRequest upgradeRequest = clientHandShake.getRequest();
if (TyrusClientEndpointConfigurator.class.isInstance(config.getConfigurator())) {
((TyrusClientEndpointConfigurator) config.getConfigurator()).beforeRequest(upgradeRequest);
}
config.getConfigurator().beforeRequest(upgradeRequest.getHeaders());

clientEngineState = TyrusClientEngineState.UPGRADE_REQUEST_CREATED;
Expand Down Expand Up @@ -251,6 +255,7 @@ public ClientUpgradeInfo processResponse(final UpgradeResponse upgradeResponse,
throw new IllegalArgumentException(LocalizationMessages.ARGUMENT_NOT_NULL("upgradeResponse"));
}

final ClientEngine.ClientUpgradeInfo upgradeInfo;
switch (upgradeResponse.getStatus()) {
case 101:
return handleSwitchProtocol(upgradeResponse, writer, closeListener);
Expand All @@ -262,7 +267,8 @@ public ClientUpgradeInfo processResponse(final UpgradeResponse upgradeResponse,
case 308:
return handleRedirect(upgradeResponse);
case 401:
return handleAuth(upgradeResponse);
upgradeInfo = handleAuth(upgradeResponse);
break;
case 503:

// get Retry-After header
Expand Down Expand Up @@ -293,19 +299,21 @@ public ClientUpgradeInfo processResponse(final UpgradeResponse upgradeResponse,

listener.onError(new RetryAfterException(
LocalizationMessages.HANDSHAKE_HTTP_RETRY_AFTER_MESSAGE(), delay));
return UPGRADE_INFO_FAILED;
upgradeInfo = UPGRADE_INFO_FAILED;
break;
default:
((ClientEndpointConfig) endpointWrapper.getEndpointConfig()).getConfigurator().afterResponse(upgradeResponse);

clientEngineState = TyrusClientEngineState.FAILED;
HandshakeException e = new HandshakeException(
upgradeResponse.getStatus(),
LocalizationMessages.INVALID_RESPONSE_CODE(101, upgradeResponse.getStatus()));
listener.onError(e);
redirectUriHistory.clear();
return UPGRADE_INFO_FAILED;
upgradeInfo = UPGRADE_INFO_FAILED;
break;
}

((ClientEndpointConfig) endpointWrapper.getEndpointConfig()).getConfigurator().afterResponse(upgradeResponse);
return upgradeInfo;
}

redirectUriHistory.clear();
Expand Down
Loading

0 comments on commit ba325a0

Please sign in to comment.