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

Merge master to 2.0.x #851

Merged
merged 6 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:

steps:
- name: Checkout for build
uses: actions/checkout@v2.3.4
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: ${{ matrix.java_version }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023 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 @@ -162,7 +162,8 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException {
return ctx.getInvokeAction();
}

final String ATTR_NAME = "org.glassfish.tyrus.container.grizzly.WebSocketFilter.HANDSHAKE_PROCESSED";
// https://github.com/eclipse-ee4j/tyrus/issues/737: each GrizzlyServerFilet & each path have different ATTR_NAME
final String ATTR_NAME = "org.glassfish.tyrus.container.grizzly.WebSocketFilter.HANDSHAKE_PROCESSED." + contextPath;

final AttributeHolder attributeHolder = ctx.getAttributes();
if (attributeHolder != null) {
Expand Down
11 changes: 9 additions & 2 deletions core/src/main/java/org/glassfish/tyrus/core/ProtocolHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023 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 @@ -476,7 +476,14 @@ public synchronized Future<Frame> close(final int code, final String reason) {
outgoingCloseFrame = new CloseFrame(closeReason);
}

final Future<Frame> send = send(outgoingCloseFrame, null, CLOSE, false);
Future<Frame> send;
try {
send = send(outgoingCloseFrame, null, CLOSE, false);
} catch (Exception e) {
send = new TyrusFuture<>();
((TyrusFuture) send).setFailure(e);
LOGGER.warning(LocalizationMessages.EXCEPTION_CLOSE(e.getMessage()));
}

webSocket.onClose(new CloseFrame(closeReason));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,8 @@ public void setHeartbeatInterval(long heartbeatInterval) {
}

void restartIdleTimeoutExecutor() {
cancelIdleTimeoutExecutor();

synchronized (idleTimeoutLock) {
cancelIdleTimeoutExecutor();
idleTimeoutFuture =
service.schedule(new IdleTimeoutCommand(), this.getMaxIdleTimeout(), TimeUnit.MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2012, 2017 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2012, 2023 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 @@ -93,6 +93,7 @@ message.handler.illegal.argument=Illegal MessageHandler argument value: {0}.
connection.null=Connection is null.
send.message.infragment=Attempting to send a message while sending fragments of another.
ioexception.close=IOException thrown when closing connection.
exception.close=Exception thrown when closing connection with message: {0}
extension.exception=Extension ''{0}'' threw an exception during processOutgoing method invocation: "{1}".
control.frame.fragmented=Fragmented control frame.
control.frame.length=Control frame payloads must be no greater than 125 bytes.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2023 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
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.tyrus.core;

import org.glassfish.tyrus.spi.CompletionHandler;
import org.glassfish.tyrus.spi.Writer;
import org.glassfish.tyrus.spi.WriterInfo;
import org.junit.Assert;
import org.junit.Test;

import jakarta.websocket.CloseReason;
import jakarta.websocket.DeploymentException;
import jakarta.websocket.Endpoint;
import jakarta.websocket.EndpointConfig;
import jakarta.websocket.Session;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;

public class ProtocolHandlerTest {

public static class ProtocolHandlerOnCloseEndpoint extends Endpoint {
CountDownLatch onCloseLatch = new CountDownLatch(1);

public void onClose(Session session, CloseReason closeReason) {
onCloseLatch.countDown();
}

@Override
public void onOpen(Session session, EndpointConfig config) {

}
}

@Test
public void testOnCloseIsCalledWhenCloseThrowsError() throws DeploymentException {
ProtocolHandler handler = new ProtocolHandler(false, null);
handler.setWriter(new Writer() {
@Override
public void write(ByteBuffer buffer, CompletionHandler<ByteBuffer> completionHandler) {
throw new IllegalStateException("Not Expected");
}

@Override
public void write(ByteBuffer buffer, CompletionHandler<ByteBuffer> completionHandler, WriterInfo writerInfo) {
if (writerInfo.getMessageType() == WriterInfo.MessageType.CLOSE) {
throw new UncheckedIOException(new SocketException("Connection reset"));
}
}

@Override
public void close() throws IOException {
}
});

ProtocolHandlerOnCloseEndpoint endpoint = new ProtocolHandlerOnCloseEndpoint();
TyrusEndpointWrapper endpointWrapper = new TyrusEndpointWrapper(
endpoint, null, ComponentProviderService.create(), null, "path",
null, new TyrusEndpointWrapper.SessionListener() {}, null, null, null);

TyrusWebSocket tyrusWebSocket = new TyrusWebSocket(handler, endpointWrapper);
handler.setWebSocket(tyrusWebSocket);
endpointWrapper.createSessionForRemoteEndpoint(tyrusWebSocket, null, Collections.emptyList(), new DebugContext());
handler.close(1000, "TEST");
Assert.assertEquals(0, endpoint.onCloseLatch.getCount());
}
}
4 changes: 2 additions & 2 deletions 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, 2023 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 @@ -22,7 +22,7 @@
<parent>
<groupId>org.eclipse.ee4j</groupId>
<artifactId>project</artifactId>
<version>1.0.7</version>
<version>1.0.8</version>
</parent>

<groupId>org.glassfish.tyrus</groupId>
Expand Down
2 changes: 1 addition & 1 deletion tests/qa/lifecycle-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.41.v20210516</version>
<version>9.4.51.v20230217</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
Expand Down