Skip to content

Commit

Permalink
Merge pull request #856 from jansupol/r.214
Browse files Browse the repository at this point in the history
Merge 2.0.x into 2.x
  • Loading branch information
jansupol authored Oct 24, 2023
2 parents 6a23599 + 38c291a commit c0c732c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 8 deletions.
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
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, 2022 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 @@ -513,9 +513,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, 2022 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());
}
}
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

0 comments on commit c0c732c

Please sign in to comment.