diff --git a/glassfish-runner/pom.xml b/glassfish-runner/pom.xml index 55de0bb38b..a957c37e21 100644 --- a/glassfish-runner/pom.xml +++ b/glassfish-runner/pom.xml @@ -31,10 +31,10 @@ 3.1.0 jakarta-restful-ws-tck - 7.0.0-M8 + 7.0.2 glassfish7 - 5.7.2 + 5.9.1 diff --git a/glassfish-runner/websocket-platform-tck/j2ee.pass b/glassfish-runner/websocket-platform-tck/j2ee.pass new file mode 100644 index 0000000000..8859170690 --- /dev/null +++ b/glassfish-runner/websocket-platform-tck/j2ee.pass @@ -0,0 +1,17 @@ + +# +# 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 +# +AS_ADMIN_USERPASSWORD=j2ee \ No newline at end of file diff --git a/glassfish-runner/websocket-platform-tck/javajoe.pass b/glassfish-runner/websocket-platform-tck/javajoe.pass new file mode 100644 index 0000000000..d69a7520e5 --- /dev/null +++ b/glassfish-runner/websocket-platform-tck/javajoe.pass @@ -0,0 +1,16 @@ +# +# 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 +# +AS_ADMIN_USERPASSWORD=javajoe diff --git a/glassfish-runner/websocket-platform-tck/pom.xml b/glassfish-runner/websocket-platform-tck/pom.xml new file mode 100644 index 0000000000..13e9429065 --- /dev/null +++ b/glassfish-runner/websocket-platform-tck/pom.xml @@ -0,0 +1,358 @@ + + + jakarta + glassfish.websocket-platform-tck + 10.0.0-SNAPSHOT + jar + 4.0.0 + + + org.glassfish + standalone-tck + 10.0.0 + ../pom.xml + + + + jakarta.websocket-platform-tck + 2.1.0 + + + + + + org.junit + junit-bom + ${junit.jupiter.version} + pom + import + + + + + + + + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + + + jakartatck + common + ${project.version} + + + jakartatck + libutil + ${project.version} + + + jakartatck + runtime + ${project.version} + + + org.jboss.arquillian.container + arquillian-glassfish-managed-6 + 1.0.0.Alpha1 + + + org.glassfish.hk2 + hk2-locator + + + + + jakartatck + websocket-tck + 10.0.0-SNAPSHOT + + + org.glassfish.main.common + simple-glassfish-api + ${glassfish.container.version} + + + org.jboss.arquillian.junit5 + arquillian-junit5-container + 1.7.0.Alpha14 + + + org.jboss.arquillian.junit5 + arquillian-junit5-core + 1.7.0.Alpha14 + + + org.glassfish.hk2 + hk2-locator + 3.0.3 + + + + + + full + + true + + + glassfish + + + + web + + web + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.2.0 + + + unpack + pre-integration-test + + unpack + + + + + org.glassfish.main.distributions + ${glassfish-artifact-id} + ${glassfish.container.version} + zip + true + ${project.build.directory} + + + + + + + + exec-maven-plugin + org.codehaus.mojo + + + StopDomain1 + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + stop-domain + + + + + StartDomain1 + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + start-domain + + + + + Enable Trace requests + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + set + server-config.network-config.protocols.protocol.http-listener-1.http.trace-enabled=true + + + + + Delete User j2ee + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + --passwordfile + ${project.basedir}/j2ee.pass + delete-file-user + j2ee + + + 0 + 1 + + + + + Add User j2ee + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + --passwordfile + ${project.basedir}/j2ee.pass + create-file-user + --groups + staff:mgr + j2ee + + + + + Delete User javajoe + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + --passwordfile + ${project.basedir}/javajoe.pass + delete-file-user + javajoe + + + 0 + 1 + + + + + Add User javajoe + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + --passwordfile + ${project.basedir}/javajoe.pass + create-file-user + --groups + guest + javajoe + + + + + list users + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + list-file-users + + + + + StopDomain + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + stop-domain + + + + + + + maven-failsafe-plugin + 3.0.0-M5 + + + gf-tests + + integration-test + verify + + + + **/platform/** + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/jakarta.websocket-api.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/jakarta.websocket-client-api.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/jakarta.servlet-api.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/jakarta.enterprise.cdi-api.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-websocket-core.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-client.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-core.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-container-grizzly.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/glassfish-grizzly-extra-all.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/nucleus-grizzly-all.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-server.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-container-servlet.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-container-grizzly-client.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-spi.jar + + jakartatck:websocket-tck + + ${project.build.directory}/${glassfish.toplevel.dir} + localhost + 8080 + 8181 + 5 + websockettck + true + j2ee + j2ee + javajoe + javajoe + com.sun.ts.tests.websocket.lib.implementation.sun.common.SunRIURL + + + ${project.build.directory}/${glassfish.toplevel.dir} + + + + + + + + diff --git a/glassfish-runner/websocket-tck/j2ee.pass b/glassfish-runner/websocket-tck/j2ee.pass new file mode 100644 index 0000000000..8859170690 --- /dev/null +++ b/glassfish-runner/websocket-tck/j2ee.pass @@ -0,0 +1,17 @@ + +# +# 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 +# +AS_ADMIN_USERPASSWORD=j2ee \ No newline at end of file diff --git a/glassfish-runner/websocket-tck/javajoe.pass b/glassfish-runner/websocket-tck/javajoe.pass new file mode 100644 index 0000000000..d69a7520e5 --- /dev/null +++ b/glassfish-runner/websocket-tck/javajoe.pass @@ -0,0 +1,16 @@ +# +# 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 +# +AS_ADMIN_USERPASSWORD=javajoe diff --git a/glassfish-runner/websocket-tck/pom.xml b/glassfish-runner/websocket-tck/pom.xml new file mode 100644 index 0000000000..d748752cea --- /dev/null +++ b/glassfish-runner/websocket-tck/pom.xml @@ -0,0 +1,358 @@ + + + jakarta + glassfish.websocket-tck + 10.0.0-SNAPSHOT + jar + 4.0.0 + + + org.glassfish + standalone-tck + 10.0.0 + ../pom.xml + + + + jakarta.websocket-tck + 2.1.0 + + + + + + org.junit + junit-bom + ${junit.jupiter.version} + pom + import + + + + + + + + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + + + jakartatck + common + ${project.version} + + + jakartatck + libutil + ${project.version} + + + jakartatck + runtime + ${project.version} + + + org.jboss.arquillian.container + arquillian-glassfish-managed-6 + 1.0.0.Alpha1 + + + org.glassfish.hk2 + hk2-locator + + + + + jakartatck + websocket-tck + 10.0.0-SNAPSHOT + + + org.glassfish.main.common + simple-glassfish-api + ${glassfish.container.version} + + + org.jboss.arquillian.junit5 + arquillian-junit5-container + 1.7.0.Alpha14 + + + org.jboss.arquillian.junit5 + arquillian-junit5-core + 1.7.0.Alpha14 + + + org.glassfish.hk2 + hk2-locator + 3.0.3 + + + + + + full + + true + + + glassfish + + + + web + + web + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.2.0 + + + unpack + pre-integration-test + + unpack + + + + + org.glassfish.main.distributions + ${glassfish-artifact-id} + ${glassfish.container.version} + zip + true + ${project.build.directory} + + + + + + + + exec-maven-plugin + org.codehaus.mojo + + + StopDomain1 + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + stop-domain + + + + + StartDomain1 + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + start-domain + + + + + Enable Trace requests + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + set + server-config.network-config.protocols.protocol.http-listener-1.http.trace-enabled=true + + + + + Delete User j2ee + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + --passwordfile + ${project.basedir}/j2ee.pass + delete-file-user + j2ee + + + 0 + 1 + + + + + Add User j2ee + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + --passwordfile + ${project.basedir}/j2ee.pass + create-file-user + --groups + staff:mgr + j2ee + + + + + Delete User javajoe + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + --passwordfile + ${project.basedir}/javajoe.pass + delete-file-user + javajoe + + + 0 + 1 + + + + + Add User javajoe + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + --passwordfile + ${project.basedir}/javajoe.pass + create-file-user + --groups + guest + javajoe + + + + + list users + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + list-file-users + + + + + StopDomain + pre-integration-test + + exec + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin + + stop-domain + + + + + + + maven-failsafe-plugin + 3.0.0-M5 + + + gf-tests + + integration-test + verify + + + + **/platform/** + + + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/jakarta.websocket-api.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/jakarta.websocket-client-api.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/jakarta.servlet-api.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/jakarta.enterprise.cdi-api.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-websocket-core.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-client.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-core.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-container-grizzly.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/glassfish-grizzly-extra-all.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/nucleus-grizzly-all.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-server.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-container-servlet.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-container-grizzly-client.jar + ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/tyrus-spi.jar + + jakartatck:websocket-tck + + ${project.build.directory}/${glassfish.toplevel.dir} + localhost + 8080 + 8181 + 5 + websockettck + true + j2ee + j2ee + javajoe + javajoe + com.sun.ts.tests.websocket.lib.implementation.sun.common.SunRIURL + + + ${project.build.directory}/${glassfish.toplevel.dir} + + + + + + + + diff --git a/pom.xml b/pom.xml index 21ad1f3f47..aa9dfbbf24 100644 --- a/pom.xml +++ b/pom.xml @@ -116,7 +116,6 @@ jacc javaee javamail - jaxrs-platform-tck jaxws-common jaxws jdbc diff --git a/websocket/pom.xml b/websocket/pom.xml index fbb5a85857..56a92589ff 100644 --- a/websocket/pom.xml +++ b/websocket/pom.xml @@ -1,7 +1,7 @@ - 4.0.0 + 4.0.0 - - jakartatck - project - 10.0.0-SNAPSHOT - + + jakartatck + project + 10.0.0-SNAPSHOT + - websocket - jar + websocket-tck + jar - WEBSOCKET - WEBSOCKET + WEBSOCKET + WEBSOCKET - - - ${project.groupId} - common - - - javatest - javatest - - - commons-httpclient - commons-httpclient - - - jakarta.websocket - jakarta.websocket-api - - - jakarta.websocket - jakarta.websocket-client-api - - - jakarta.servlet - jakarta.servlet-api - - - jakarta.inject - jakarta.inject-api + + ${project.version} + 5.9.1 + + + + + + commons-httpclient + commons-httpclient + + + jakarta.websocket + jakarta.websocket-api + + + jakarta.websocket + jakarta.websocket-client-api + + + jakarta.enterprise + jakarta.enterprise.cdi-api + + + jakartatck + libutil + ${project.version} + + + org.slf4j + slf4j-api + 2.0.6 + + + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + + + org.jboss.arquillian.junit5 + arquillian-junit5-container + 1.7.0.Alpha14 - jakarta.enterprise - jakarta.enterprise.cdi-api + org.jboss.arquillian.junit5 + arquillian-junit5-core + 1.7.0.Alpha14 - - + + jakartatck + common + ${project.version} + + + jakartatck + runtime + ${project.version} + + + + + + tck-build + + true + + + + + maven-compiler-plugin + 2.3.2 + + + maven-surefire-plugin + 3.0.0-M5 + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + + src/main/java + + **/*.xml + + + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + + + + \ No newline at end of file diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/clientendpointconfig/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/clientendpointconfig/WSClient.java deleted file mode 100644 index c62a632b3b..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/clientendpointconfig/WSClient.java +++ /dev/null @@ -1,1167 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 - */ - -/* - * $Id:$ - */ -package com.sun.ts.tests.websocket.api.jakarta.websocket.clientendpointconfig; - -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import com.sun.javatest.Status; -import com.sun.ts.lib.harness.ServiceEETest; -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.common.TCKExtension; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.ClientEndpointConfig.Configurator; -import jakarta.websocket.Decoder; -import jakarta.websocket.Encoder; -import jakarta.websocket.Extension; -import jakarta.websocket.HandshakeResponse; - -public class WSClient extends ServiceEETest { - - public static void main(String[] args) { - WSClient theTests = new WSClient(); - Status s = theTests.run(args, new PrintWriter(System.out), - new PrintWriter(System.err)); - s.exit(); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; - */ - @SuppressWarnings("unused") - public void setup(String[] args, Properties p) throws Exception { - } - - /* Run test */ - /* - * @testName: constructortest - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:6; WebSocket:JAVADOC:7; WebSocket:JAVADOC:70; - * WebSocket:JAVADOC:71; WebSocket:SPEC:WSC-3.2.1-1; - * WebSocket:SPEC:WSC-3.2.2-1; - * - * @test_Strategy: Test constructor - */ - public void constructortest() throws Exception { - boolean passed = true; - - try { - ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create().build(); - - List tmp = dcc.getDecoders(); - if (tmp != null) { - TestUtil.logTrace("getDecoders() return non-null List"); - if (!tmp.isEmpty()) { - TestUtil.logErr("getDecoders() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = dcc.getEncoders(); - if (tmp != null) { - TestUtil.logTrace("getEncoders() return non-null List"); - if (!tmp.isEmpty()) { - TestUtil.logErr("getEncoders() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = dcc.getExtensions(); - if (tmp != null) { - TestUtil.logTrace("getExtensions() return non-null List"); - if (!tmp.isEmpty()) { - TestUtil.logErr("getExtensions() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = dcc.getPreferredSubprotocols(); - if (tmp != null) { - TestUtil.logTrace("getPreferredSubprotocols() return non-null List"); - if (!tmp.isEmpty()) { - TestUtil.logErr( - "getPreferredSubprotocols() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - } catch (Exception e) { - TestUtil.logErr(e.getMessage()); - throw new Exception(e); - } - - if (passed == false) { - throw new Exception("Test failed"); - } - } - - /* - * @testName: preferredSubprotocolsTest - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:7; WebSocket:JAVADOC:14; - * - * @test_Strategy: - */ - public void preferredSubprotocolsTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - try { - ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(expected_subprotocols).build(); - - List tmp = dcc.getPreferredSubprotocols(); - if (tmp != null) { - log.append("getPreferredSubprotocols() return non-null List|"); - if (!tmp.isEmpty()) { - log.append( - "getPreferredSubprotocols() return non-empty List with size " - + tmp.size() + "|"); - int size_actual = tmp.size(); - if (size_actual == expected_subprotocols.size()) { - for (String subpro : tmp) { - if (expected_subprotocols.contains(subpro)) { - log.append("sub protocol " + subpro + " found is expected|"); - } else { - passed = false; - log.append( - "sub protocol " + subpro + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getPreferredSubprotocols() returned not exactly the same size."); - log.append("Expecting seven, returned " + size_actual); - } - } else { - log.append("getPreferredSubprotocols() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getPreferredSubprotocols() return null list"); - } - } catch (Exception e) { - System.err.print(e.getMessage() + log.toString()); - throw new Exception(e); - } - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: extensionsTest - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:6; WebSocket:JAVADOC:13; - * - * @test_Strategy: - */ - public void extensionsTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() - .extensions(extensions).build(); - List tmp = dcc.getExtensions(); - if (tmp != null) { - log.append("getExtensions() return non-null List|"); - if (!tmp.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmp.size() + "|"); - int size_actual = tmp.size(); - if (size_actual == extensions.size()) { - for (Extension ext : tmp) { - if (extensions.contains(ext)) { - log.append("extension " + ext + " found is expected|"); - } else { - passed = false; - log.append("extension " + ext + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getExtensions() returned not exactly the same amount of extensions."); - log.append("Expecting two, returned " + size_actual); - } - } else { - log.append("getExtensions() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getExtensions() return null list|"); - } - } catch (Exception e) { - System.err.println(e.getMessage() + log.toString()); - throw new Exception(e); - } - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: constructorTest1 - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:6; WebSocket:JAVADOC:7; WebSocket:JAVADOC:13; - * WebSocket:JAVADOC:14; - * - * @test_Strategy: - */ - public void constructorTest1() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(expected_subprotocols).extensions(extensions) - .build(); - - List tmpe = dcc.getExtensions(); - List tmpp = dcc.getPreferredSubprotocols(); - - if (tmpe != null) { - log.append("getExtensions() return non-null List|"); - if (!tmpe.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmpe.size() + "|"); - int size_actual = tmpe.size(); - if (size_actual == extensions.size()) { - for (Extension ext : tmpe) { - if (extensions.contains(ext)) { - log.append("extension " + ext + " found is expected|"); - } else { - passed = false; - log.append("extension " + ext + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getExtensions() returned not exactly the same amount of extensions."); - log.append("Expecting two, returned " + size_actual); - } - } else { - log.append("getExtensions() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getExtensions() return null list|"); - } - - if (tmpp != null) { - log.append("getPreferredSubprotocols() return non-null List|"); - if (!tmpp.isEmpty()) { - log.append( - "getPreferredSubprotocols() return non-empty List with size " - + tmpp.size() + "|"); - int size_actual = tmpp.size(); - if (size_actual == expected_subprotocols.size()) { - for (String subpro : tmpp) { - if (expected_subprotocols.contains(subpro)) { - log.append("sub protocol " + subpro + " found is expected|"); - } else { - passed = false; - log.append( - "sub protocol " + subpro + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getPreferredSubprotocols() returned not exactly the same size."); - log.append("Expecting seven, returned " + size_actual); - } - } else { - log.append("getPreferredSubprotocols() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getPreferredSubprotocols() return null list"); - } - - } catch (Exception e) { - System.err.println(e.getMessage() + log.toString()); - throw new Exception(e); - } - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: encodersTest - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:12; WebSocket:JAVADOC:71; - * - * @test_Strategy: - */ - public void encodersTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List> expected_encoders = new ArrayList<>(); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); - - try { - ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() - .encoders(expected_encoders).build(); - - List> tmp = dcc.getEncoders(); - if (tmp != null) { - log.append("getEncoders() return non-null List"); - if (!tmp.isEmpty()) { - int size = tmp.size(); - log.append( - "getEncoders() return non-empty List with size " + size + "|"); - if (size == 2) { - for (Class encoder : tmp) { - log.append("Encoder " + encoder + " found "); - if (expected_encoders.contains(encoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getEncoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getEncoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getEncoders() return null list"); - } - } catch (Exception e) { - System.err.print(log.toString()); - throw new Exception(e); - } - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: decodersTest - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:11; WebSocket:JAVADOC:70; - * - * @test_Strategy: - */ - public void decodersTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List> expected_decoders = new ArrayList<>(); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); - - try { - ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() - .decoders(expected_decoders).build(); - - List> tmp = dcc.getDecoders(); - if (tmp != null) { - log.append("getDecoders() return non-null List|"); - if (!tmp.isEmpty()) { - int size = tmp.size(); - log.append("getDecoders() return non-empty List with size " - + tmp.size() + "|"); - if (size == 2) { - for (Class decoder : tmp) { - log.append("Decoder " + decoder + " found "); - if (expected_decoders.contains(decoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getDecoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getDecoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getDecoders() return null list|"); - } - - } catch (Exception e) { - System.err.println(e.getMessage() + log.toString()); - throw new Exception(e); - } - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: constructorTest2 - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:6; WebSocket:JAVADOC:7; WebSocket:JAVADOC:13; - * WebSocket:JAVADOC:14; WebSocket:JAVADOC:11; WebSocket:JAVADOC:70; - * - * @test_Strategy: - */ - public void constructorTest2() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - - List> expected_decoders = new ArrayList<>(); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(expected_subprotocols).extensions(extensions) - .decoders(expected_decoders).build(); - - List tmpe = dcc.getExtensions(); - List tmpp = dcc.getPreferredSubprotocols(); - List> tmpd = dcc.getDecoders(); - - if (tmpe != null) { - log.append("getExtensions() return non-null List|"); - if (!tmpe.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmpe.size() + "|"); - int size_actual = tmpe.size(); - if (size_actual == extensions.size()) { - for (Extension ext : tmpe) { - if (extensions.contains(ext)) { - log.append("extension " + ext + " found is expected|"); - } else { - passed = false; - log.append("extension " + ext + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getExtensions() returned not exactly the same amount of extensions."); - log.append("Expecting two, returned " + size_actual); - } - } else { - log.append("getExtensions() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getExtensions() return null list|"); - } - - if (tmpp != null) { - log.append("getPreferredSubprotocols() return non-null List|"); - if (!tmpp.isEmpty()) { - log.append( - "getPreferredSubprotocols() return non-empty List with size " - + tmpp.size() + "|"); - int size_actual = tmpp.size(); - if (size_actual == expected_subprotocols.size()) { - for (String subpro : tmpp) { - if (expected_subprotocols.contains(subpro)) { - log.append("sub protocol " + subpro + " found is expected|"); - } else { - passed = false; - log.append( - "sub protocol " + subpro + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getPreferredSubprotocols() returned not exactly the same size."); - log.append("Expecting seven, returned " + size_actual); - } - } else { - log.append("getPreferredSubprotocols() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getPreferredSubprotocols() return null list"); - } - - if (tmpd != null) { - log.append("getDecoders() return non-null List|"); - if (!tmpd.isEmpty()) { - int size = tmpd.size(); - log.append("getDecoders() return non-empty List with size " - + tmpd.size() + "|"); - if (size == 2) { - for (Class decoder : tmpd) { - log.append("Decoder " + decoder + " found "); - if (expected_decoders.contains(decoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getDecoders() returned not exactly the same size."); - log.append("Expecting seven, returned " + size); - } - } else { - log.append("getDecoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getDecoders() return null list|"); - } - } catch (Exception e) { - System.err.println(e.getMessage() + log.toString()); - throw new Exception(e); - } - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: constructorTest3 - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:6; WebSocket:JAVADOC:7; WebSocket:JAVADOC:13; - * WebSocket:JAVADOC:14; WebSocket:JAVADOC:11; WebSocket:JAVADOC:12; - * WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; - * - * @test_Strategy: - */ - public void constructorTest3() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - - List> expected_encoders = new ArrayList<>(); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); - - List> expected_decoders = new ArrayList<>(); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(expected_subprotocols).extensions(extensions) - .decoders(expected_decoders).encoders(expected_encoders).build(); - - List tmpe = dcc.getExtensions(); - List tmpp = dcc.getPreferredSubprotocols(); - List> tmpd = dcc.getDecoders(); - - if (tmpe != null) { - log.append("getExtensions() return non-null List|"); - if (!tmpe.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmpe.size() + "|"); - int size_actual = tmpe.size(); - if (size_actual == extensions.size()) { - for (Extension ext : tmpe) { - if (extensions.contains(ext)) { - log.append("extension " + ext + " found is expected|"); - } else { - passed = false; - log.append("extension " + ext + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getExtensions() returned not exactly the same amount of extensions."); - log.append("Expecting two, returned " + size_actual); - } - } else { - log.append("getExtensions() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getExtensions() return null list|"); - } - - if (tmpp != null) { - log.append("getPreferredSubprotocols() return non-null List|"); - if (!tmpp.isEmpty()) { - log.append( - "getPreferredSubprotocols() return non-empty List with size " - + tmpp.size() + "|"); - int size_actual = tmpp.size(); - if (size_actual == expected_subprotocols.size()) { - for (String subpro : tmpp) { - if (expected_subprotocols.contains(subpro)) { - log.append("sub protocol " + subpro + " found is expected|"); - } else { - passed = false; - log.append( - "sub protocol " + subpro + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getPreferredSubprotocols() returned not exactly the same size."); - log.append("Expecting seven, returned " + size_actual); - } - } else { - log.append("getPreferredSubprotocols() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getPreferredSubprotocols() return null list"); - } - - if (tmpd != null) { - log.append("getDecoders() return non-null List|"); - if (!tmpd.isEmpty()) { - int size = tmpd.size(); - log.append("getDecoders() return non-empty List with size " - + tmpd.size() + "|"); - if (size == 2) { - for (Class decoder : tmpd) { - log.append("Decoder " + decoder + " found "); - if (expected_decoders.contains(decoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getDecoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getDecoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getDecoders() return null list|"); - } - - List> tmpen = dcc.getEncoders(); - if (tmpen != null) { - log.append("getEncoders() return non-null List"); - if (!tmpen.isEmpty()) { - int size = tmpen.size(); - log.append( - "getEncoders() return non-empty List with size " + size + "|"); - if (size == 2) { - for (Class encoder : tmpen) { - log.append("Encoder " + encoder + " found "); - if (expected_encoders.contains(encoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getEncoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getEncoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getEncoders() return null list"); - } - } catch (Exception e) { - System.err.println(e.getMessage() + log.toString()); - throw new Exception(e); - } - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: configuratorTest - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:5; WebSocket:JAVADOC:9; - * - * @test_Strategy: - */ - public void configuratorTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - Configurator config = new TCKConfigurator(); - - try { - ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() - .configurator(config).build(); - - Configurator tmpc = dcc.getConfigurator(); - - if (!tmpc.getClass().equals( - com.sun.ts.tests.websocket.api.jakarta.websocket.clientendpointconfig.TCKConfigurator.class)) { - TestUtil.logErr("getConfigurator() returned a different Configurator: " - + tmpc.getClass().getName()); - passed = false; - } - - } catch (Exception e) { - System.err.print(log.toString()); - throw new Exception(e); - } - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: constructorTest4 - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:5; WebSocket:JAVADOC:9; WebSocket:JAVADOC:6; - * WebSocket:JAVADOC:7; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; - * - * @test_Strategy: - */ - public void constructorTest4() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - Configurator config = new TCKConfigurator(); - - try { - ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() - .configurator(config).build(); - List tmp = dcc.getDecoders(); - if (tmp != null) { - TestUtil.logTrace("getDecoders() return non-null List"); - if (!tmp.isEmpty()) { - TestUtil.logErr("getDecoders() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = dcc.getEncoders(); - if (tmp != null) { - TestUtil.logTrace("getEncoders() return non-null List"); - if (!tmp.isEmpty()) { - TestUtil.logErr("getEncoders() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = dcc.getExtensions(); - if (tmp != null) { - TestUtil.logTrace("getExtensions() return non-null List"); - if (!tmp.isEmpty()) { - TestUtil.logErr("getExtensions() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = dcc.getPreferredSubprotocols(); - if (tmp != null) { - TestUtil.logTrace("getPreferredSubprotocols() return non-null List"); - if (!tmp.isEmpty()) { - TestUtil.logErr( - "getPreferredSubprotocols() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - } catch (Exception e) { - System.err.print(log.toString()); - throw new Exception(e); - } - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: constructorTest5 - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:6; WebSocket:JAVADOC:7; WebSocket:JAVADOC:5; - * WebSocket:JAVADOC:9; WebSocket:JAVADOC:13; WebSocket:JAVADOC:14; - * WebSocket:JAVADOC:11; WebSocket:JAVADOC:12; WebSocket:JAVADOC:70; - * WebSocket:JAVADOC:71; - * - * @test_Strategy: - */ - public void constructorTest5() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List expected_subprotocols = Arrays.asList("JSON", "XML", "XMPP", - "Hessian", "Quake", "PUB/SUB", "Query"); - - List> expected_encoders = new ArrayList<>(); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); - - List> expected_decoders = new ArrayList<>(); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); - - Configurator config = new TCKConfigurator(); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(expected_subprotocols).extensions(extensions) - .decoders(expected_decoders).encoders(expected_encoders) - .configurator(config).build(); - - List tmpe = dcc.getExtensions(); - List tmpp = dcc.getPreferredSubprotocols(); - List> tmpd = dcc.getDecoders(); - - if (tmpe != null) { - log.append("getExtensions() return non-null List|"); - if (!tmpe.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmpe.size() + "|"); - int size_actual = tmpe.size(); - if (size_actual == extensions.size()) { - for (Extension ext : tmpe) { - if (extensions.contains(ext)) { - log.append("extension " + ext + " found is expected|"); - } else { - passed = false; - log.append("extension " + ext + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getExtensions() returned not exactly the same amount of extensions."); - log.append("Expecting two, returned " + size_actual); - } - } else { - log.append("getExtensions() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getExtensions() return null list|"); - } - - if (tmpp != null) { - log.append("getPreferredSubprotocols() return non-null List|"); - if (!tmpp.isEmpty()) { - log.append( - "getPreferredSubprotocols() return non-empty List with size " - + tmpp.size() + "|"); - int size_actual = tmpp.size(); - if (size_actual == expected_subprotocols.size()) { - for (String subpro : tmpp) { - if (expected_subprotocols.contains(subpro)) { - log.append("sub protocol " + subpro + " found is expected|"); - } else { - passed = false; - log.append( - "sub protocol " + subpro + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getPreferredSubprotocols() returned not exactly the same size."); - log.append("Expecting seven, returned " + size_actual); - } - } else { - log.append("getPreferredSubprotocols() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getPreferredSubprotocols() return null list"); - } - - if (tmpd != null) { - log.append("getDecoders() return non-null List|"); - if (!tmpd.isEmpty()) { - int size = tmpd.size(); - log.append("getDecoders() return non-empty List with size " - + tmpd.size() + "|"); - if (size == 2) { - for (Class decoder : tmpd) { - log.append("Decoder " + decoder + " found "); - if (expected_decoders.contains(decoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getDecoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getDecoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getDecoders() return null list|"); - } - - List> tmpen = dcc.getEncoders(); - if (tmpen != null) { - log.append("getEncoders() return non-null List"); - if (!tmpen.isEmpty()) { - int size = tmpen.size(); - log.append( - "getEncoders() return non-empty List with size " + size + "|"); - if (size == 2) { - for (Class encoder : tmpen) { - log.append("Encoder " + encoder + " found "); - if (expected_encoders.contains(encoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getEncoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getEncoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getEncoders() return null list"); - } - } catch (Exception e) { - System.err.println(e.getMessage() + log.toString()); - throw new Exception(e); - } - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - public void cleanup() { - } -} - -class TCKConfigurator extends Configurator { - - @Override - public void beforeRequest(Map> headers) { - } - - @Override - public void afterResponse(HandshakeResponse hr) { - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/clientendpointconfig/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/clientendpointconfig/WSClientIT.java new file mode 100644 index 0000000000..049b55ad36 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/clientendpointconfig/WSClientIT.java @@ -0,0 +1,1092 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $Id:$ + */ +package com.sun.ts.tests.websocket.api.jakarta.websocket.clientendpointconfig; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.TCKExtension; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.ClientEndpointConfig.Configurator; +import jakarta.websocket.Decoder; +import jakarta.websocket.Encoder; +import jakarta.websocket.Extension; +import jakarta.websocket.HandshakeResponse; + +public class WSClientIT { + + /* Run test */ + /* + * @testName: constructortest + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:6; WebSocket:JAVADOC:7; WebSocket:JAVADOC:70; + * WebSocket:JAVADOC:71; WebSocket:SPEC:WSC-3.2.1-1; WebSocket:SPEC:WSC-3.2.2-1; + * + * @test_Strategy: Test constructor + */ + @Test + public void constructortest() throws Exception { + boolean passed = true; + + try { + ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create().build(); + + List tmp = dcc.getDecoders(); + if (tmp != null) { + TestUtil.logTrace("getDecoders() return non-null List"); + if (!tmp.isEmpty()) { + TestUtil.logErr("getDecoders() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = dcc.getEncoders(); + if (tmp != null) { + TestUtil.logTrace("getEncoders() return non-null List"); + if (!tmp.isEmpty()) { + TestUtil.logErr("getEncoders() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = dcc.getExtensions(); + if (tmp != null) { + TestUtil.logTrace("getExtensions() return non-null List"); + if (!tmp.isEmpty()) { + TestUtil.logErr("getExtensions() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = dcc.getPreferredSubprotocols(); + if (tmp != null) { + TestUtil.logTrace("getPreferredSubprotocols() return non-null List"); + if (!tmp.isEmpty()) { + TestUtil.logErr("getPreferredSubprotocols() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + } catch (Exception e) { + TestUtil.logErr(e.getMessage()); + throw new Exception(e); + } + + if (passed == false) { + throw new Exception("Test failed"); + } + } + + /* + * @testName: preferredSubprotocolsTest + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:7; WebSocket:JAVADOC:14; + * + * @test_Strategy: + */ + @Test + public void preferredSubprotocolsTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + try { + ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() + .preferredSubprotocols(expected_subprotocols).build(); + + List tmp = dcc.getPreferredSubprotocols(); + if (tmp != null) { + log.append("getPreferredSubprotocols() return non-null List|"); + if (!tmp.isEmpty()) { + log.append("getPreferredSubprotocols() return non-empty List with size " + tmp.size() + "|"); + int size_actual = tmp.size(); + if (size_actual == expected_subprotocols.size()) { + for (String subpro : tmp) { + if (expected_subprotocols.contains(subpro)) { + log.append("sub protocol " + subpro + " found is expected|"); + } else { + passed = false; + log.append("sub protocol " + subpro + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getPreferredSubprotocols() returned not exactly the same size."); + log.append("Expecting seven, returned " + size_actual); + } + } else { + log.append("getPreferredSubprotocols() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getPreferredSubprotocols() return null list"); + } + } catch (Exception e) { + System.err.print(e.getMessage() + log.toString()); + throw new Exception(e); + } + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: extensionsTest + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:6; WebSocket:JAVADOC:13; + * + * @test_Strategy: + */ + @Test + public void extensionsTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create().extensions(extensions).build(); + List tmp = dcc.getExtensions(); + if (tmp != null) { + log.append("getExtensions() return non-null List|"); + if (!tmp.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmp.size() + "|"); + int size_actual = tmp.size(); + if (size_actual == extensions.size()) { + for (Extension ext : tmp) { + if (extensions.contains(ext)) { + log.append("extension " + ext + " found is expected|"); + } else { + passed = false; + log.append("extension " + ext + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getExtensions() returned not exactly the same amount of extensions."); + log.append("Expecting two, returned " + size_actual); + } + } else { + log.append("getExtensions() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getExtensions() return null list|"); + } + } catch (Exception e) { + System.err.println(e.getMessage() + log.toString()); + throw new Exception(e); + } + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: constructorTest1 + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:6; WebSocket:JAVADOC:7; WebSocket:JAVADOC:13; + * WebSocket:JAVADOC:14; + * + * @test_Strategy: + */ + @Test + public void constructorTest1() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() + .preferredSubprotocols(expected_subprotocols).extensions(extensions).build(); + + List tmpe = dcc.getExtensions(); + List tmpp = dcc.getPreferredSubprotocols(); + + if (tmpe != null) { + log.append("getExtensions() return non-null List|"); + if (!tmpe.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmpe.size() + "|"); + int size_actual = tmpe.size(); + if (size_actual == extensions.size()) { + for (Extension ext : tmpe) { + if (extensions.contains(ext)) { + log.append("extension " + ext + " found is expected|"); + } else { + passed = false; + log.append("extension " + ext + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getExtensions() returned not exactly the same amount of extensions."); + log.append("Expecting two, returned " + size_actual); + } + } else { + log.append("getExtensions() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getExtensions() return null list|"); + } + + if (tmpp != null) { + log.append("getPreferredSubprotocols() return non-null List|"); + if (!tmpp.isEmpty()) { + log.append("getPreferredSubprotocols() return non-empty List with size " + tmpp.size() + "|"); + int size_actual = tmpp.size(); + if (size_actual == expected_subprotocols.size()) { + for (String subpro : tmpp) { + if (expected_subprotocols.contains(subpro)) { + log.append("sub protocol " + subpro + " found is expected|"); + } else { + passed = false; + log.append("sub protocol " + subpro + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getPreferredSubprotocols() returned not exactly the same size."); + log.append("Expecting seven, returned " + size_actual); + } + } else { + log.append("getPreferredSubprotocols() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getPreferredSubprotocols() return null list"); + } + + } catch (Exception e) { + System.err.println(e.getMessage() + log.toString()); + throw new Exception(e); + } + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: encodersTest + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:12; WebSocket:JAVADOC:71; + * + * @test_Strategy: + */ + @Test + public void encodersTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List> expected_encoders = new ArrayList<>(); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); + + try { + ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create().encoders(expected_encoders).build(); + + List> tmp = dcc.getEncoders(); + if (tmp != null) { + log.append("getEncoders() return non-null List"); + if (!tmp.isEmpty()) { + int size = tmp.size(); + log.append("getEncoders() return non-empty List with size " + size + "|"); + if (size == 2) { + for (Class encoder : tmp) { + log.append("Encoder " + encoder + " found "); + if (expected_encoders.contains(encoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getEncoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getEncoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getEncoders() return null list"); + } + } catch (Exception e) { + System.err.print(log.toString()); + throw new Exception(e); + } + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: decodersTest + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:11; WebSocket:JAVADOC:70; + * + * @test_Strategy: + */ + @Test + public void decodersTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List> expected_decoders = new ArrayList<>(); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); + + try { + ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create().decoders(expected_decoders).build(); + + List> tmp = dcc.getDecoders(); + if (tmp != null) { + log.append("getDecoders() return non-null List|"); + if (!tmp.isEmpty()) { + int size = tmp.size(); + log.append("getDecoders() return non-empty List with size " + tmp.size() + "|"); + if (size == 2) { + for (Class decoder : tmp) { + log.append("Decoder " + decoder + " found "); + if (expected_decoders.contains(decoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getDecoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getDecoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getDecoders() return null list|"); + } + + } catch (Exception e) { + System.err.println(e.getMessage() + log.toString()); + throw new Exception(e); + } + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: constructorTest2 + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:6; WebSocket:JAVADOC:7; WebSocket:JAVADOC:13; + * WebSocket:JAVADOC:14; WebSocket:JAVADOC:11; WebSocket:JAVADOC:70; + * + * @test_Strategy: + */ + @Test + public void constructorTest2() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + + List> expected_decoders = new ArrayList<>(); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() + .preferredSubprotocols(expected_subprotocols).extensions(extensions).decoders(expected_decoders) + .build(); + + List tmpe = dcc.getExtensions(); + List tmpp = dcc.getPreferredSubprotocols(); + List> tmpd = dcc.getDecoders(); + + if (tmpe != null) { + log.append("getExtensions() return non-null List|"); + if (!tmpe.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmpe.size() + "|"); + int size_actual = tmpe.size(); + if (size_actual == extensions.size()) { + for (Extension ext : tmpe) { + if (extensions.contains(ext)) { + log.append("extension " + ext + " found is expected|"); + } else { + passed = false; + log.append("extension " + ext + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getExtensions() returned not exactly the same amount of extensions."); + log.append("Expecting two, returned " + size_actual); + } + } else { + log.append("getExtensions() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getExtensions() return null list|"); + } + + if (tmpp != null) { + log.append("getPreferredSubprotocols() return non-null List|"); + if (!tmpp.isEmpty()) { + log.append("getPreferredSubprotocols() return non-empty List with size " + tmpp.size() + "|"); + int size_actual = tmpp.size(); + if (size_actual == expected_subprotocols.size()) { + for (String subpro : tmpp) { + if (expected_subprotocols.contains(subpro)) { + log.append("sub protocol " + subpro + " found is expected|"); + } else { + passed = false; + log.append("sub protocol " + subpro + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getPreferredSubprotocols() returned not exactly the same size."); + log.append("Expecting seven, returned " + size_actual); + } + } else { + log.append("getPreferredSubprotocols() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getPreferredSubprotocols() return null list"); + } + + if (tmpd != null) { + log.append("getDecoders() return non-null List|"); + if (!tmpd.isEmpty()) { + int size = tmpd.size(); + log.append("getDecoders() return non-empty List with size " + tmpd.size() + "|"); + if (size == 2) { + for (Class decoder : tmpd) { + log.append("Decoder " + decoder + " found "); + if (expected_decoders.contains(decoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getDecoders() returned not exactly the same size."); + log.append("Expecting seven, returned " + size); + } + } else { + log.append("getDecoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getDecoders() return null list|"); + } + } catch (Exception e) { + System.err.println(e.getMessage() + log.toString()); + throw new Exception(e); + } + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: constructorTest3 + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:6; WebSocket:JAVADOC:7; WebSocket:JAVADOC:13; + * WebSocket:JAVADOC:14; WebSocket:JAVADOC:11; WebSocket:JAVADOC:12; + * WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; + * + * @test_Strategy: + */ + @Test + public void constructorTest3() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + + List> expected_encoders = new ArrayList<>(); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); + + List> expected_decoders = new ArrayList<>(); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() + .preferredSubprotocols(expected_subprotocols).extensions(extensions).decoders(expected_decoders) + .encoders(expected_encoders).build(); + + List tmpe = dcc.getExtensions(); + List tmpp = dcc.getPreferredSubprotocols(); + List> tmpd = dcc.getDecoders(); + + if (tmpe != null) { + log.append("getExtensions() return non-null List|"); + if (!tmpe.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmpe.size() + "|"); + int size_actual = tmpe.size(); + if (size_actual == extensions.size()) { + for (Extension ext : tmpe) { + if (extensions.contains(ext)) { + log.append("extension " + ext + " found is expected|"); + } else { + passed = false; + log.append("extension " + ext + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getExtensions() returned not exactly the same amount of extensions."); + log.append("Expecting two, returned " + size_actual); + } + } else { + log.append("getExtensions() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getExtensions() return null list|"); + } + + if (tmpp != null) { + log.append("getPreferredSubprotocols() return non-null List|"); + if (!tmpp.isEmpty()) { + log.append("getPreferredSubprotocols() return non-empty List with size " + tmpp.size() + "|"); + int size_actual = tmpp.size(); + if (size_actual == expected_subprotocols.size()) { + for (String subpro : tmpp) { + if (expected_subprotocols.contains(subpro)) { + log.append("sub protocol " + subpro + " found is expected|"); + } else { + passed = false; + log.append("sub protocol " + subpro + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getPreferredSubprotocols() returned not exactly the same size."); + log.append("Expecting seven, returned " + size_actual); + } + } else { + log.append("getPreferredSubprotocols() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getPreferredSubprotocols() return null list"); + } + + if (tmpd != null) { + log.append("getDecoders() return non-null List|"); + if (!tmpd.isEmpty()) { + int size = tmpd.size(); + log.append("getDecoders() return non-empty List with size " + tmpd.size() + "|"); + if (size == 2) { + for (Class decoder : tmpd) { + log.append("Decoder " + decoder + " found "); + if (expected_decoders.contains(decoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getDecoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getDecoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getDecoders() return null list|"); + } + + List> tmpen = dcc.getEncoders(); + if (tmpen != null) { + log.append("getEncoders() return non-null List"); + if (!tmpen.isEmpty()) { + int size = tmpen.size(); + log.append("getEncoders() return non-empty List with size " + size + "|"); + if (size == 2) { + for (Class encoder : tmpen) { + log.append("Encoder " + encoder + " found "); + if (expected_encoders.contains(encoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getEncoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getEncoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getEncoders() return null list"); + } + } catch (Exception e) { + System.err.println(e.getMessage() + log.toString()); + throw new Exception(e); + } + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: configuratorTest + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:5; WebSocket:JAVADOC:9; + * + * @test_Strategy: + */ + @Test + public void configuratorTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + Configurator config = new TCKConfigurator(); + + try { + ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create().configurator(config).build(); + + Configurator tmpc = dcc.getConfigurator(); + + if (!tmpc.getClass().equals( + com.sun.ts.tests.websocket.api.jakarta.websocket.clientendpointconfig.TCKConfigurator.class)) { + TestUtil.logErr("getConfigurator() returned a different Configurator: " + tmpc.getClass().getName()); + passed = false; + } + + } catch (Exception e) { + System.err.print(log.toString()); + throw new Exception(e); + } + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: constructorTest4 + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:5; WebSocket:JAVADOC:9; WebSocket:JAVADOC:6; + * WebSocket:JAVADOC:7; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; + * + * @test_Strategy: + */ + @Test + public void constructorTest4() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + Configurator config = new TCKConfigurator(); + + try { + ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create().configurator(config).build(); + List tmp = dcc.getDecoders(); + if (tmp != null) { + TestUtil.logTrace("getDecoders() return non-null List"); + if (!tmp.isEmpty()) { + TestUtil.logErr("getDecoders() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = dcc.getEncoders(); + if (tmp != null) { + TestUtil.logTrace("getEncoders() return non-null List"); + if (!tmp.isEmpty()) { + TestUtil.logErr("getEncoders() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = dcc.getExtensions(); + if (tmp != null) { + TestUtil.logTrace("getExtensions() return non-null List"); + if (!tmp.isEmpty()) { + TestUtil.logErr("getExtensions() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = dcc.getPreferredSubprotocols(); + if (tmp != null) { + TestUtil.logTrace("getPreferredSubprotocols() return non-null List"); + if (!tmp.isEmpty()) { + TestUtil.logErr("getPreferredSubprotocols() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + } catch (Exception e) { + System.err.print(log.toString()); + throw new Exception(e); + } + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: constructorTest5 + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:6; WebSocket:JAVADOC:7; WebSocket:JAVADOC:5; + * WebSocket:JAVADOC:9; WebSocket:JAVADOC:13; WebSocket:JAVADOC:14; + * WebSocket:JAVADOC:11; WebSocket:JAVADOC:12; WebSocket:JAVADOC:70; + * WebSocket:JAVADOC:71; + * + * @test_Strategy: + */ + @Test + public void constructorTest5() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List expected_subprotocols = Arrays.asList("JSON", "XML", "XMPP", "Hessian", "Quake", "PUB/SUB", + "Query"); + + List> expected_encoders = new ArrayList<>(); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); + + List> expected_decoders = new ArrayList<>(); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); + + Configurator config = new TCKConfigurator(); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ClientEndpointConfig dcc = ClientEndpointConfig.Builder.create() + .preferredSubprotocols(expected_subprotocols).extensions(extensions).decoders(expected_decoders) + .encoders(expected_encoders).configurator(config).build(); + + List tmpe = dcc.getExtensions(); + List tmpp = dcc.getPreferredSubprotocols(); + List> tmpd = dcc.getDecoders(); + + if (tmpe != null) { + log.append("getExtensions() return non-null List|"); + if (!tmpe.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmpe.size() + "|"); + int size_actual = tmpe.size(); + if (size_actual == extensions.size()) { + for (Extension ext : tmpe) { + if (extensions.contains(ext)) { + log.append("extension " + ext + " found is expected|"); + } else { + passed = false; + log.append("extension " + ext + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getExtensions() returned not exactly the same amount of extensions."); + log.append("Expecting two, returned " + size_actual); + } + } else { + log.append("getExtensions() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getExtensions() return null list|"); + } + + if (tmpp != null) { + log.append("getPreferredSubprotocols() return non-null List|"); + if (!tmpp.isEmpty()) { + log.append("getPreferredSubprotocols() return non-empty List with size " + tmpp.size() + "|"); + int size_actual = tmpp.size(); + if (size_actual == expected_subprotocols.size()) { + for (String subpro : tmpp) { + if (expected_subprotocols.contains(subpro)) { + log.append("sub protocol " + subpro + " found is expected|"); + } else { + passed = false; + log.append("sub protocol " + subpro + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getPreferredSubprotocols() returned not exactly the same size."); + log.append("Expecting seven, returned " + size_actual); + } + } else { + log.append("getPreferredSubprotocols() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getPreferredSubprotocols() return null list"); + } + + if (tmpd != null) { + log.append("getDecoders() return non-null List|"); + if (!tmpd.isEmpty()) { + int size = tmpd.size(); + log.append("getDecoders() return non-empty List with size " + tmpd.size() + "|"); + if (size == 2) { + for (Class decoder : tmpd) { + log.append("Decoder " + decoder + " found "); + if (expected_decoders.contains(decoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getDecoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getDecoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getDecoders() return null list|"); + } + + List> tmpen = dcc.getEncoders(); + if (tmpen != null) { + log.append("getEncoders() return non-null List"); + if (!tmpen.isEmpty()) { + int size = tmpen.size(); + log.append("getEncoders() return non-empty List with size " + size + "|"); + if (size == 2) { + for (Class encoder : tmpen) { + log.append("Encoder " + encoder + " found "); + if (expected_encoders.contains(encoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getEncoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getEncoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getEncoders() return null list"); + } + } catch (Exception e) { + System.err.println(e.getMessage() + log.toString()); + throw new Exception(e); + } + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + public void cleanup() { + } +} + +class TCKConfigurator extends Configurator { + + @Override + public void beforeRequest(Map> headers) { + } + + @Override + public void afterResponse(HandshakeResponse hr) { + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/closereason/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/closereason/WSClient.java deleted file mode 100644 index 613c545642..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/closereason/WSClient.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 - */ - -/* - * $Id:$ - */ -package com.sun.ts.tests.websocket.api.jakarta.websocket.closereason; - -import java.io.PrintWriter; -import java.util.Properties; - -import com.sun.javatest.Status; -import com.sun.ts.lib.harness.ServiceEETest; - -import jakarta.websocket.CloseReason; -import jakarta.websocket.CloseReason.CloseCode; -import jakarta.websocket.CloseReason.CloseCodes; - -public class WSClient extends ServiceEETest { - - final CloseCodes[] codes = { CloseReason.CloseCodes.CANNOT_ACCEPT, - CloseReason.CloseCodes.CLOSED_ABNORMALLY, - CloseReason.CloseCodes.GOING_AWAY, CloseReason.CloseCodes.NORMAL_CLOSURE, - CloseReason.CloseCodes.NOT_CONSISTENT, - CloseReason.CloseCodes.NO_EXTENSION, - CloseReason.CloseCodes.NO_STATUS_CODE, - CloseReason.CloseCodes.PROTOCOL_ERROR, CloseReason.CloseCodes.RESERVED, - CloseReason.CloseCodes.SERVICE_RESTART, - CloseReason.CloseCodes.TLS_HANDSHAKE_FAILURE, - CloseReason.CloseCodes.TOO_BIG, CloseReason.CloseCodes.TRY_AGAIN_LATER, - CloseReason.CloseCodes.UNEXPECTED_CONDITION, - CloseReason.CloseCodes.VIOLATED_POLICY }; - - final String[] codes_string = { "CANNOT_ACCEPT", "CLOSED_ABNORMALLY", - "GOING_AWAY", "NORMAL_CLOSURE", "NOT_CONSISTENT", "NO_EXTENSION", - "NO_STATUS_CODE", "PROTOCOL_ERROR", "RESERVED", "SERVICE_RESTART", - "TLS_HANDSHAKE_FAILURE", "TOO_BIG", "TRY_AGAIN_LATER", - "UNEXPECTED_CONDITION", "VIOLATED_POLICY" }; - - final int[] codes_number = { 1003, 1006, 1001, 1000, 1007, 1010, 1005, 1002, - 1004, 1012, 1015, 1009, 1013, 1011, 1008 }; - - final String[] tck_codes_reason = { "TCK_CANNOT_ACCEPT", - "TCK_CLOSED_ABNORMALLY", "TCK_GOING_AWAY", "TCK_NORMAL_CLOSURE", - "TCK_NOT_CONSISTENT", "TCK_NO_EXTENSION", "TCK_NO_STATUS_CODE", - "TCK_PROTOCOL_ERROR", "TCK_RESERVED", "TCK_SERVICE_RESTART", - "TCK_TLS_HANDSHAKE_FAILURE", "TCK_TOO_BIG", "TCK_TRY_AGAIN_LATER", - "TCK_UNEXPECTED_CONDITION", "TCK_VIOLATED_POLICY" }; - - public static void main(String[] args) { - WSClient theTests = new WSClient(); - Status s = theTests.run(args, new PrintWriter(System.out), - new PrintWriter(System.err)); - s.exit(); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ts_home; - */ - @SuppressWarnings("unused") - public void setup(String[] args, Properties p) throws Exception { - } - - /* Run test */ - /* - * @testName: getCodeTest - * - * @assertion_ids: WebSocket:JAVADOC:24; - * - * @test_Strategy: Test method CloseCodes.getCode() - */ - public void getCodeTest() throws Exception { - boolean passed = true; - - int size = codes_number.length; - for (int i = 0; i < size; i++) { - if (codes[i].getCode() != codes_number[i]) { - passed = false; - System.err.println("Expecting CloseCodes' number " + codes_number[i] - + "; got " + codes[i].getCode()); - } - } - - if (passed == false) { - throw new Exception("Test failed"); - } - } - - /* - * @testName: getCodeTest1 - * - * @assertion_ids: WebSocket:JAVADOC:22; - * - * @test_Strategy: Test method CloseCode.getCode() - */ - public void getCodeTest1() throws Exception { - boolean passed = true; - - int size = codes_number.length; - for (int i = 0; i < size; i++) { - if (((CloseCode) codes[i]).getCode() != codes_number[i]) { - passed = false; - System.err.println("Expecting CloseCode' number " + codes_number[i] - + "; got " + codes[i].getCode()); - } - } - - if (passed == false) { - throw new Exception("Test failed"); - } - } - - /* - * @testName: valueOfTest - * - * @assertion_ids: WebSocket:JAVADOC:25; - * - * @test_Strategy: Test method CloseCodes.valueOf(String) - */ - public void valueOfTest() throws Exception { - boolean passed = true; - - int size = codes_number.length; - - for (int i = 0; i < size; i++) { - if (!CloseReason.CloseCodes.valueOf(codes_string[i]).equals(codes[i])) { - passed = false; - System.err.println("Expecting CloseCodes " + codes[i] + "; got " - + CloseReason.CloseCodes.valueOf(codes_string[i])); - } - } - - if (passed == false) { - throw new Exception("Test failed"); - } - } - - /* - * @testName: valuesTest - * - * @assertion_ids: WebSocket:JAVADOC:26; - * - * @test_Strategy: Test method CloseCodes.values() - */ - public void valuesTest() throws Exception { - boolean passed = true; - - CloseCodes[] close_codes = CloseReason.CloseCodes.values(); - - int size = close_codes.length; - boolean[] passed_array = new boolean[size]; - for (int i = 0; i < size; i++) { - passed_array[i] = false; - for (int j = 0; j < size; j++) { - if (close_codes[i].equals(codes[j])) { - break; - } - } - passed_array[i] = true; - System.out.println("Expected CloseCodes " + codes[i] + " returned"); - System.out.println("Expected CloseCodes " + codes[i] + " returned"); - - } - - for (int i = 0; i < size; i++) { - if (passed_array[i] == false) { - passed = false; - } - } - - if (!passed) { - throw new Exception("Test failed"); - } - } - - /* - * @testName: constructorTest - * - * @assertion_ids: WebSocket:JAVADOC:18; WebSocket:JAVADOC:19; - * WebSocket:JAVADOC:20; - * - * @test_Strategy: Test constructor CloseReason( CloseCode, String ) - */ - public void constructorTest() throws Exception { - boolean passed = true; - - int size = codes_number.length; - CloseReason closereason; - - for (int i = 0; i < size; i++) { - closereason = new CloseReason(codes[i], tck_codes_reason[i]); - if (!closereason.getCloseCode().equals(codes[i])) { - passed = false; - System.err.println("Expected CloseCodes " + codes[i] + ", returned" - + closereason.getCloseCode()); - } - - if (!closereason.getReasonPhrase().equals(tck_codes_reason[i])) { - passed = false; - System.err.println("Expected reason phrase " + tck_codes_reason[i] - + ", returned" + closereason.getReasonPhrase()); - } - } - - if (!passed) { - throw new Exception("Test failed"); - } - } - - /* - * @testName: getCloseCodeTest - * - * @assertion_ids: WebSocket:JAVADOC:23; - * - * @test_Strategy: Test constructor CloseCodes.getCloseCode( int ) - */ - public void getCloseCodeTest() throws Exception { - boolean passed = true; - - int size = codes_number.length; - CloseCode tmp; - - for (int i = 0; i < size; i++) { - tmp = CloseReason.CloseCodes.getCloseCode(codes_number[i]); - if (!tmp.equals(codes[i])) { - passed = false; - System.err - .println("Expected CloseCode " + codes[i] + ", returned" + tmp); - } - } - - if (!passed) { - throw new Exception("Test failed"); - } - } - - public void cleanup() { - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/closereason/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/closereason/WSClientIT.java new file mode 100644 index 0000000000..a2a210857f --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/closereason/WSClientIT.java @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $Id:$ + */ +package com.sun.ts.tests.websocket.api.jakarta.websocket.closereason; + +import org.junit.jupiter.api.Test; + +import jakarta.websocket.CloseReason; +import jakarta.websocket.CloseReason.CloseCode; +import jakarta.websocket.CloseReason.CloseCodes; + +public class WSClientIT { + + final CloseCodes[] codes = { CloseReason.CloseCodes.CANNOT_ACCEPT, CloseReason.CloseCodes.CLOSED_ABNORMALLY, + CloseReason.CloseCodes.GOING_AWAY, CloseReason.CloseCodes.NORMAL_CLOSURE, + CloseReason.CloseCodes.NOT_CONSISTENT, CloseReason.CloseCodes.NO_EXTENSION, + CloseReason.CloseCodes.NO_STATUS_CODE, CloseReason.CloseCodes.PROTOCOL_ERROR, + CloseReason.CloseCodes.RESERVED, CloseReason.CloseCodes.SERVICE_RESTART, + CloseReason.CloseCodes.TLS_HANDSHAKE_FAILURE, CloseReason.CloseCodes.TOO_BIG, + CloseReason.CloseCodes.TRY_AGAIN_LATER, CloseReason.CloseCodes.UNEXPECTED_CONDITION, + CloseReason.CloseCodes.VIOLATED_POLICY }; + + final String[] codes_string = { "CANNOT_ACCEPT", "CLOSED_ABNORMALLY", "GOING_AWAY", "NORMAL_CLOSURE", + "NOT_CONSISTENT", "NO_EXTENSION", "NO_STATUS_CODE", "PROTOCOL_ERROR", "RESERVED", "SERVICE_RESTART", + "TLS_HANDSHAKE_FAILURE", "TOO_BIG", "TRY_AGAIN_LATER", "UNEXPECTED_CONDITION", "VIOLATED_POLICY" }; + + final int[] codes_number = { 1003, 1006, 1001, 1000, 1007, 1010, 1005, 1002, 1004, 1012, 1015, 1009, 1013, 1011, + 1008 }; + + final String[] tck_codes_reason = { "TCK_CANNOT_ACCEPT", "TCK_CLOSED_ABNORMALLY", "TCK_GOING_AWAY", + "TCK_NORMAL_CLOSURE", "TCK_NOT_CONSISTENT", "TCK_NO_EXTENSION", "TCK_NO_STATUS_CODE", "TCK_PROTOCOL_ERROR", + "TCK_RESERVED", "TCK_SERVICE_RESTART", "TCK_TLS_HANDSHAKE_FAILURE", "TCK_TOO_BIG", "TCK_TRY_AGAIN_LATER", + "TCK_UNEXPECTED_CONDITION", "TCK_VIOLATED_POLICY" }; + + /* Run test */ + /* + * @testName: getCodeTest + * + * @assertion_ids: WebSocket:JAVADOC:24; + * + * @test_Strategy: Test method CloseCodes.getCode() + */ + @Test + public void getCodeTest() throws Exception { + boolean passed = true; + + int size = codes_number.length; + for (int i = 0; i < size; i++) { + if (codes[i].getCode() != codes_number[i]) { + passed = false; + System.err.println("Expecting CloseCodes' number " + codes_number[i] + "; got " + codes[i].getCode()); + } + } + + if (passed == false) { + throw new Exception("Test failed"); + } + } + + /* + * @testName: getCodeTest1 + * + * @assertion_ids: WebSocket:JAVADOC:22; + * + * @test_Strategy: Test method CloseCode.getCode() + */ + @Test + public void getCodeTest1() throws Exception { + boolean passed = true; + + int size = codes_number.length; + for (int i = 0; i < size; i++) { + if (((CloseCode) codes[i]).getCode() != codes_number[i]) { + passed = false; + System.err.println("Expecting CloseCode' number " + codes_number[i] + "; got " + codes[i].getCode()); + } + } + + if (passed == false) { + throw new Exception("Test failed"); + } + } + + /* + * @testName: valueOfTest + * + * @assertion_ids: WebSocket:JAVADOC:25; + * + * @test_Strategy: Test method CloseCodes.valueOf(String) + */ + @Test + public void valueOfTest() throws Exception { + boolean passed = true; + + int size = codes_number.length; + + for (int i = 0; i < size; i++) { + if (!CloseReason.CloseCodes.valueOf(codes_string[i]).equals(codes[i])) { + passed = false; + System.err.println("Expecting CloseCodes " + codes[i] + "; got " + + CloseReason.CloseCodes.valueOf(codes_string[i])); + } + } + + if (passed == false) { + throw new Exception("Test failed"); + } + } + + /* + * @testName: valuesTest + * + * @assertion_ids: WebSocket:JAVADOC:26; + * + * @test_Strategy: Test method CloseCodes.values() + */ + @Test + public void valuesTest() throws Exception { + boolean passed = true; + + CloseCodes[] close_codes = CloseReason.CloseCodes.values(); + + int size = close_codes.length; + boolean[] passed_array = new boolean[size]; + for (int i = 0; i < size; i++) { + passed_array[i] = false; + for (int j = 0; j < size; j++) { + if (close_codes[i].equals(codes[j])) { + break; + } + } + passed_array[i] = true; + System.out.println("Expected CloseCodes " + codes[i] + " returned"); + System.out.println("Expected CloseCodes " + codes[i] + " returned"); + + } + + for (int i = 0; i < size; i++) { + if (passed_array[i] == false) { + passed = false; + } + } + + if (!passed) { + throw new Exception("Test failed"); + } + } + + /* + * @testName: constructorTest + * + * @assertion_ids: WebSocket:JAVADOC:18; WebSocket:JAVADOC:19; + * WebSocket:JAVADOC:20; + * + * @test_Strategy: Test constructor CloseReason( CloseCode, String ) + */ + @Test + public void constructorTest() throws Exception { + boolean passed = true; + + int size = codes_number.length; + CloseReason closereason; + + for (int i = 0; i < size; i++) { + closereason = new CloseReason(codes[i], tck_codes_reason[i]); + if (!closereason.getCloseCode().equals(codes[i])) { + passed = false; + System.err.println("Expected CloseCodes " + codes[i] + ", returned" + closereason.getCloseCode()); + } + + if (!closereason.getReasonPhrase().equals(tck_codes_reason[i])) { + passed = false; + System.err.println( + "Expected reason phrase " + tck_codes_reason[i] + ", returned" + closereason.getReasonPhrase()); + } + } + + if (!passed) { + throw new Exception("Test failed"); + } + } + + /* + * @testName: getCloseCodeTest + * + * @assertion_ids: WebSocket:JAVADOC:23; + * + * @test_Strategy: Test constructor CloseCodes.getCloseCode( int ) + */ + @Test + public void getCloseCodeTest() throws Exception { + boolean passed = true; + + int size = codes_number.length; + CloseCode tmp; + + for (int i = 0; i < size; i++) { + tmp = CloseReason.CloseCodes.getCloseCode(codes_number[i]); + if (!tmp.equals(codes[i])) { + passed = false; + System.err.println("Expected CloseCode " + codes[i] + ", returned" + tmp); + } + } + + if (!passed) { + throw new Exception("Test failed"); + } + } + + public void cleanup() { + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/decodeexception/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/decodeexception/WSClient.java deleted file mode 100644 index e1785ecf3e..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/decodeexception/WSClient.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 - */ - -/* - * $Id:$ - */ -package com.sun.ts.tests.websocket.api.jakarta.websocket.decodeexception; - -import java.io.PrintWriter; -import java.nio.ByteBuffer; -import java.util.Properties; - -import com.sun.javatest.Status; -import com.sun.ts.lib.harness.ServiceEETest; -import com.sun.ts.lib.util.RemoteLoggingInitException; -import com.sun.ts.lib.util.TestUtil; - -import jakarta.websocket.DecodeException; - -public class WSClient extends ServiceEETest { - // properties read from ts.jte file - - int ws_wait; - - String webServerHost; - - String webServerPort; - - public static void main(String[] args) { - WSClient theTests = new WSClient(); - Status s = theTests.run(args, new PrintWriter(System.out), - new PrintWriter(System.err)); - s.exit(); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; - */ - @SuppressWarnings("unused") - public void setup(String[] args, Properties p) throws Exception { - try { - TestUtil.init(p); - } catch (RemoteLoggingInitException rlex) { - System.err.println("Failed to initialize logging."); - } - - webServerHost = p.getProperty("webServerHost").trim(); - webServerPort = p.getProperty("webServerPort").trim(); - ws_wait = Integer.parseInt(p.getProperty("ws_wait")); - - // check props for errors - if (ws_wait < 1) { - throw new Exception("'ws_wait' (milliseconds) in ts.jte must be > 0"); - } - if (webServerHost == null) { - throw new Exception("'webServerHost' in ts.jte must not be null "); - } - if (webServerPort == null) { - throw new Exception("'webServerPort' in ts.jte must not be null "); - } - } - - /* Run test */ - /* - * @testName: constructorTest - * - * @assertion_ids: WebSocket:JAVADOC:32; WebSocket:JAVADOC:33; - * WebSocket:JAVADOC:34; - * - * @test_Strategy: Test constructor DecodeException(String, String) - */ - public void constructorTest() throws Exception { - boolean passed = true; - String reason = "TCK: Cannot decode the message"; - String encoded_message = "xyz for now"; - StringBuilder tmp = new StringBuilder(); - - DecodeException dex = new DecodeException(encoded_message, reason); - - if (!encoded_message.equals(dex.getText())) { - passed = false; - tmp.append("Expected message ").append(encoded_message) - .append(", returned").append(dex.getText()); - } - - if (dex.getBytes() != null) { - passed = false; - tmp.append("Expected ByteBuffer to be null, returned") - .append(dex.getBytes()); - } - - if (passed == false) { - throw new Exception("Test failed: " + tmp.toString()); - } - } - - /* - * @testName: constructorTest1 - * - * @assertion_ids: WebSocket:JAVADOC:31; WebSocket:JAVADOC:33; - * WebSocket:JAVADOC:34; - * - * @test_Strategy: Test constructor DecodeException(ByteBuffer, String) - */ - public void constructorTest1() throws Exception { - boolean passed = true; - String reason = "TCK: Cannot decode the message"; - ByteBuffer encoded_message = ByteBuffer.allocate(20); - encoded_message.put("xyz for now".getBytes()); - - DecodeException dex = new DecodeException(encoded_message, reason); - - if (dex.getText() != null) { - passed = false; - TestUtil - .logErr("Expected encoded_message null, returned" + dex.getText()); - } - - if (!encoded_message.equals(dex.getBytes())) { - passed = false; - TestUtil.logErr("Expected ByteBuffer " + encoded_message + ", returned" - + dex.getBytes()); - } - - if (passed == false) { - throw new Exception("Test failed"); - } - } - - /* - * @testName: constructorTest2 - * - * @assertion_ids: WebSocket:JAVADOC:30; WebSocket:JAVADOC:33; - * WebSocket:JAVADOC:34; - * - * @test_Strategy: Test constructor DecodeException(String, String, Throwable) - */ - public void constructorTest2() throws Exception { - boolean passed = true; - String reason = "TCK: Cannot decode the message"; - String encoded_message = "xyz for now"; - - DecodeException dex = new DecodeException(encoded_message, reason, - new Throwable("CocntructorTest2")); - - if (!encoded_message.equals(dex.getText())) { - passed = false; - TestUtil.logErr("Expected encoded_message " + encoded_message - + ", returned" + dex.getText()); - } - - if (dex.getBytes() != null) { - passed = false; - TestUtil.logErr("Expected ByteBuffer null, returned" + dex.getBytes()); - } - - if (passed == false) { - throw new Exception("Test failed"); - } - } - - /* - * @testName: constructorTest3 - * - * @assertion_ids: WebSocket:JAVADOC:29; WebSocket:JAVADOC:33; - * WebSocket:JAVADOC:34; - * - * @test_Strategy: Test constructor DecodeException(ByteBuffer, String, - * Throwable) - */ - public void constructorTest3() throws Exception { - boolean passed = true; - String reason = "TCK: Cannot decode the message"; - ByteBuffer encoded_message = ByteBuffer.allocate(20); - encoded_message.put("xyz for now".getBytes()); - - DecodeException dex = new DecodeException(encoded_message, reason, - new Throwable("constructorTest3")); - - if (dex.getText() != null) { - passed = false; - TestUtil - .logErr("Expected encoded_message null, returned" + dex.getText()); - } - - if (!encoded_message.equals(dex.getBytes())) { - passed = false; - TestUtil.logErr("Expected ByteBuffer " + encoded_message + ", returned" - + dex.getBytes()); - } - - if (passed == false) { - throw new Exception("Test failed"); - } - } - - public void cleanup() { - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/decodeexception/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/decodeexception/WSClientIT.java new file mode 100644 index 0000000000..8116dc4349 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/decodeexception/WSClientIT.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $Id:$ + */ +package com.sun.ts.tests.websocket.api.jakarta.websocket.decodeexception; + +import java.nio.ByteBuffer; + +import org.junit.jupiter.api.Test; + +import com.sun.ts.lib.util.TestUtil; + +import jakarta.websocket.DecodeException; + +public class WSClientIT { + + /* Run test */ + /* + * @testName: constructorTest + * + * @assertion_ids: WebSocket:JAVADOC:32; WebSocket:JAVADOC:33; + * WebSocket:JAVADOC:34; + * + * @test_Strategy: Test constructor DecodeException(String, String) + */ + @Test + public void constructorTest() throws Exception { + boolean passed = true; + String reason = "TCK: Cannot decode the message"; + String encoded_message = "xyz for now"; + StringBuilder tmp = new StringBuilder(); + + DecodeException dex = new DecodeException(encoded_message, reason); + + if (!encoded_message.equals(dex.getText())) { + passed = false; + tmp.append("Expected message ").append(encoded_message).append(", returned").append(dex.getText()); + } + + if (dex.getBytes() != null) { + passed = false; + tmp.append("Expected ByteBuffer to be null, returned").append(dex.getBytes()); + } + + if (passed == false) { + throw new Exception("Test failed: " + tmp.toString()); + } + } + + /* + * @testName: constructorTest1 + * + * @assertion_ids: WebSocket:JAVADOC:31; WebSocket:JAVADOC:33; + * WebSocket:JAVADOC:34; + * + * @test_Strategy: Test constructor DecodeException(ByteBuffer, String) + */ + @Test + public void constructorTest1() throws Exception { + boolean passed = true; + String reason = "TCK: Cannot decode the message"; + ByteBuffer encoded_message = ByteBuffer.allocate(20); + encoded_message.put("xyz for now".getBytes()); + + DecodeException dex = new DecodeException(encoded_message, reason); + + if (dex.getText() != null) { + passed = false; + TestUtil.logErr("Expected encoded_message null, returned" + dex.getText()); + } + + if (!encoded_message.equals(dex.getBytes())) { + passed = false; + TestUtil.logErr("Expected ByteBuffer " + encoded_message + ", returned" + dex.getBytes()); + } + + if (passed == false) { + throw new Exception("Test failed"); + } + } + + /* + * @testName: constructorTest2 + * + * @assertion_ids: WebSocket:JAVADOC:30; WebSocket:JAVADOC:33; + * WebSocket:JAVADOC:34; + * + * @test_Strategy: Test constructor DecodeException(String, String, Throwable) + */ + @Test + public void constructorTest2() throws Exception { + boolean passed = true; + String reason = "TCK: Cannot decode the message"; + String encoded_message = "xyz for now"; + + DecodeException dex = new DecodeException(encoded_message, reason, new Throwable("CocntructorTest2")); + + if (!encoded_message.equals(dex.getText())) { + passed = false; + TestUtil.logErr("Expected encoded_message " + encoded_message + ", returned" + dex.getText()); + } + + if (dex.getBytes() != null) { + passed = false; + TestUtil.logErr("Expected ByteBuffer null, returned" + dex.getBytes()); + } + + if (passed == false) { + throw new Exception("Test failed"); + } + } + + /* + * @testName: constructorTest3 + * + * @assertion_ids: WebSocket:JAVADOC:29; WebSocket:JAVADOC:33; + * WebSocket:JAVADOC:34; + * + * @test_Strategy: Test constructor DecodeException(ByteBuffer, String, + * Throwable) + */ + @Test + public void constructorTest3() throws Exception { + boolean passed = true; + String reason = "TCK: Cannot decode the message"; + ByteBuffer encoded_message = ByteBuffer.allocate(20); + encoded_message.put("xyz for now".getBytes()); + + DecodeException dex = new DecodeException(encoded_message, reason, new Throwable("constructorTest3")); + + if (dex.getText() != null) { + passed = false; + TestUtil.logErr("Expected encoded_message null, returned" + dex.getText()); + } + + if (!encoded_message.equals(dex.getBytes())) { + passed = false; + TestUtil.logErr("Expected ByteBuffer " + encoded_message + ", returned" + dex.getBytes()); + } + + if (passed == false) { + throw new Exception("Test failed"); + } + } + + public void cleanup() { + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/deploymentException/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/deploymentException/WSClient.java deleted file mode 100644 index 3a58581f77..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/deploymentException/WSClient.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 - */ - -/* - * $Id:$ - */ -package com.sun.ts.tests.websocket.api.jakarta.websocket.deploymentException; - -import java.io.PrintWriter; -import java.util.Properties; - -import com.sun.javatest.Status; -import com.sun.ts.lib.harness.ServiceEETest; - -import jakarta.websocket.DeploymentException; - -public class WSClient extends ServiceEETest { - - public static void main(String[] args) { - WSClient theTests = new WSClient(); - Status s = theTests.run(args, new PrintWriter(System.out), - new PrintWriter(System.err)); - s.exit(); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; - */ - @SuppressWarnings("unused") - public void setup(String[] args, Properties p) throws Exception { - } - - /* Run test */ - /* - * @testName: constructorTest - * - * @assertion_ids: WebSocket:JAVADOC:49; - * - * @test_Strategy: Test constructor DeploymentException(String) - */ - public void constructorTest() throws Exception { - String reason = "TCK: testing the DeploymentException(String)"; - - @SuppressWarnings("unused") - DeploymentException dex = new DeploymentException(reason); - - } - - /* - * @testName: constructorTest1 - * - * @assertion_ids: WebSocket:JAVADOC:50; - * - * @test_Strategy: Test constructor DeploymentException(String, Throwable) - */ - public void constructorTest1() throws Exception { - String reason = "TCK: testing the DeploymentException(String)"; - - @SuppressWarnings("unused") - DeploymentException dex = new DeploymentException(reason, - new Throwable("TCK_Test")); - } - - public void cleanup() { - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/deploymentException/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/deploymentException/WSClientIT.java new file mode 100644 index 0000000000..4beec5336d --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/deploymentException/WSClientIT.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $Id:$ + */ +package com.sun.ts.tests.websocket.api.jakarta.websocket.deploymentException; + +import org.junit.jupiter.api.Test; + +import jakarta.websocket.DeploymentException; + +public class WSClientIT { + + /* Run test */ + /* + * @testName: constructorTest + * + * @assertion_ids: WebSocket:JAVADOC:49; + * + * @test_Strategy: Test constructor DeploymentException(String) + */ + @Test + public void constructorTest() throws Exception { + String reason = "TCK: testing the DeploymentException(String)"; + + @SuppressWarnings("unused") + DeploymentException dex = new DeploymentException(reason); + + } + + /* + * @testName: constructorTest1 + * + * @assertion_ids: WebSocket:JAVADOC:50; + * + * @test_Strategy: Test constructor DeploymentException(String, Throwable) + */ + @Test + public void constructorTest1() throws Exception { + String reason = "TCK: testing the DeploymentException(String)"; + + @SuppressWarnings("unused") + DeploymentException dex = new DeploymentException(reason, new Throwable("TCK_Test")); + } + + public void cleanup() { + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/encodeexception/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/encodeexception/WSClient.java deleted file mode 100644 index 18c96153e7..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/encodeexception/WSClient.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 - */ - -/* - * $Id:$ - */ -package com.sun.ts.tests.websocket.api.jakarta.websocket.encodeexception; - -import java.io.PrintWriter; -import java.nio.ByteBuffer; -import java.util.Properties; - -import com.sun.javatest.Status; -import com.sun.ts.lib.harness.ServiceEETest; -import com.sun.ts.lib.util.TestUtil; - -import jakarta.websocket.EncodeException; - -public class WSClient extends ServiceEETest { - public static void main(String[] args) { - WSClient theTests = new WSClient(); - Status s = theTests.run(args, new PrintWriter(System.out), - new PrintWriter(System.err)); - s.exit(); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; - */ - @SuppressWarnings("unused") - public void setup(String[] args, Properties p) throws Exception { - } - - /* Run test */ - /* - * @testName: constructorTest - * - * @assertion_ids: WebSocket:JAVADOC:51; WebSocket:JAVADOC:53; - * - * @test_Strategy: Test constructor EncodeException(Object, String) - */ - public void constructorTest() throws Exception { - boolean passed = true; - String reason = "TCK: Cannot encode the message"; - String encoded_message = "xyz for now"; - - EncodeException eex = new EncodeException(encoded_message, reason); - - if (!encoded_message.equals(eex.getObject())) { - passed = false; - TestUtil.logErr("Expected message " + encoded_message + ", returned" - + eex.getObject()); - } - - if (passed == false) { - throw new Exception("Test failed"); - } - } - - /* - * @testName: constructorTest1 - * - * @assertion_ids: WebSocket:JAVADOC:52; WebSocket:JAVADOC:53; - * - * @test_Strategy: Test constructor EncodeException(Object, String, Throwable) - */ - public void constructorTest1() throws Exception { - boolean passed = true; - String reason = "TCK: Cannot decode the message"; - ByteBuffer encoded_message = ByteBuffer.allocate(20); - encoded_message.put("xyz for now".getBytes()); - - EncodeException eex = new EncodeException(encoded_message, reason, - new Throwable("TCK Cannot encode")); - - if (!encoded_message.equals(eex.getObject())) { - passed = false; - TestUtil.logErr("Expected message " + encoded_message + ", returned" - + eex.getObject()); - } - - if (passed == false) { - throw new Exception("Test failed"); - } - } - - public void cleanup() { - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/encodeexception/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/encodeexception/WSClientIT.java new file mode 100644 index 0000000000..d1d8f9f7ff --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/encodeexception/WSClientIT.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $Id:$ + */ +package com.sun.ts.tests.websocket.api.jakarta.websocket.encodeexception; + +import java.nio.ByteBuffer; + +import org.junit.jupiter.api.Test; + +import com.sun.ts.lib.util.TestUtil; + +import jakarta.websocket.EncodeException; + +public class WSClientIT { + + /* Run test */ + /* + * @testName: constructorTest + * + * @assertion_ids: WebSocket:JAVADOC:51; WebSocket:JAVADOC:53; + * + * @test_Strategy: Test constructor EncodeException(Object, String) + */ + @Test + public void constructorTest() throws Exception { + boolean passed = true; + String reason = "TCK: Cannot encode the message"; + String encoded_message = "xyz for now"; + + EncodeException eex = new EncodeException(encoded_message, reason); + + if (!encoded_message.equals(eex.getObject())) { + passed = false; + TestUtil.logErr("Expected message " + encoded_message + ", returned" + eex.getObject()); + } + + if (passed == false) { + throw new Exception("Test failed"); + } + } + + /* + * @testName: constructorTest1 + * + * @assertion_ids: WebSocket:JAVADOC:52; WebSocket:JAVADOC:53; + * + * @test_Strategy: Test constructor EncodeException(Object, String, Throwable) + */ + @Test + public void constructorTest1() throws Exception { + boolean passed = true; + String reason = "TCK: Cannot decode the message"; + ByteBuffer encoded_message = ByteBuffer.allocate(20); + encoded_message.put("xyz for now".getBytes()); + + EncodeException eex = new EncodeException(encoded_message, reason, new Throwable("TCK Cannot encode")); + + if (!encoded_message.equals(eex.getObject())) { + passed = false; + TestUtil.logErr("Expected message " + encoded_message + ", returned" + eex.getObject()); + } + + if (passed == false) { + throw new Exception("Test failed"); + } + } + + public void cleanup() { + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/server/serverendpointconfig/TCKEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/server/serverendpointconfig/TCKEndpoint.java index 79121495c2..b4977f042a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/server/serverendpointconfig/TCKEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/server/serverendpointconfig/TCKEndpoint.java @@ -26,8 +26,8 @@ public class TCKEndpoint extends Endpoint { - @Override - public void onOpen(Session session, EndpointConfig config) { - System.out.println("========TCKEndpoint"); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + System.out.println("========TCKEndpoint"); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/server/serverendpointconfig/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/server/serverendpointconfig/WSClient.java deleted file mode 100644 index f5b2b25833..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/server/serverendpointconfig/WSClient.java +++ /dev/null @@ -1,1263 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 - */ - -/* - * $Id:$ - */ -package com.sun.ts.tests.websocket.api.jakarta.websocket.server.serverendpointconfig; - -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Properties; - -import com.sun.javatest.Status; -import com.sun.ts.lib.harness.ServiceEETest; -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.common.TCKExtension; - -import jakarta.websocket.Decoder; -import jakarta.websocket.Encoder; -import jakarta.websocket.Extension; -import jakarta.websocket.server.ServerEndpointConfig; - -public class WSClient extends ServiceEETest { - - public static void main(String[] args) { - WSClient theTests = new WSClient(); - Status s = theTests.run(args, new PrintWriter(System.out), - new PrintWriter(System.err)); - s.exit(); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; - */ - @SuppressWarnings("unused") - public void setup(String[] args, Properties p) throws Exception { - } - - /* Run test */ - /* - * @testName: constructortest - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; WebSocket:JAVADOC:195; - * WebSocket:JAVADOC:197; - * - * - * @test_Strategy: Test constructor - */ - public void constructortest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer").build(); - - List tmp = sec.getDecoders(); - if (tmp != null) { - TestUtil.logTrace("getDecoders() return non-null List"); - if (!tmp.isEmpty()) { - log.append("getDecoders() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = sec.getEncoders(); - if (tmp != null) { - TestUtil.logTrace("getEncoders() return non-null List"); - if (!tmp.isEmpty()) { - log.append("getEncoders() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = sec.getExtensions(); - if (tmp != null) { - TestUtil.logTrace("getExtensions() return non-null List"); - if (!tmp.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = sec.getSubprotocols(); - if (tmp != null) { - TestUtil.logTrace("getSubprotocols() return non-null List"); - if (!tmp.isEmpty()) { - log.append("getSubprotocols() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - - if (passed == false) { - throw new Exception("Test failed"); - } - } - - /* - * @testName: subprotocolsTest - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:197; WebSocket:JAVADOC:204; - * - * @test_Strategy: - */ - public void subprotocolsTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer") - .subprotocols(expected_subprotocols).build(); - - List tmp = sec.getSubprotocols(); - if (tmp != null) { - log.append("getSubprotocols() return non-null List|"); - if (!tmp.isEmpty()) { - log.append("getSubprotocols() return non-empty List with size " - + tmp.size() + "|"); - int size_actual = tmp.size(); - if (size_actual == expected_subprotocols.size()) { - for (String subpro : tmp) { - if (expected_subprotocols.contains(subpro)) { - log.append("sub protocol " + subpro + " found is expected|"); - } else { - passed = false; - log.append( - "sub protocol " + subpro + " found is not expected|"); - } - } - } else { - passed = false; - log.append("getSubprotocols() returned not exactly the same size."); - log.append("Expecting seven, returned " + size_actual); - } - } else { - log.append("getSubprotocols() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getSubprotocols() return null list"); - } - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: extensionsTest - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:195; WebSocket:JAVADOC:203; - * - * @test_Strategy: - */ - public void extensionsTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer").extensions(extensions) - .build(); - List tmp = sec.getExtensions(); - if (tmp != null) { - log.append("getExtensions() return non-null List|"); - if (!tmp.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmp.size() + "|"); - int size_actual = tmp.size(); - if (size_actual == extensions.size()) { - for (Extension ext : tmp) { - if (extensions.contains(ext)) { - log.append("extension " + ext + " found is expected|"); - } else { - passed = false; - log.append("extension " + ext + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getExtensions() returned not exactly the same amount of extensions."); - log.append("Expecting two, returned " + size_actual); - } - } else { - log.append("getExtensions() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getExtensions() return null list|"); - } - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: constructorTest1 - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:195; WebSocket:JAVADOC:197; WebSocket:JAVADOC:203; - * WebSocket:JAVADOC:204; - * - * - * @test_Strategy: - */ - public void constructorTest1() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer") - .subprotocols(expected_subprotocols).extensions(extensions).build(); - - List tmpe = sec.getExtensions(); - List tmpp = sec.getSubprotocols(); - - if (tmpe != null) { - log.append("getExtensions() return non-null List|"); - if (!tmpe.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmpe.size() + "|"); - int size_actual = tmpe.size(); - if (size_actual == extensions.size()) { - for (Extension ext : tmpe) { - if (extensions.contains(ext)) { - log.append("extension " + ext + " found is expected|"); - } else { - passed = false; - log.append("extension " + ext + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getExtensions() returned not exactly the same amount of extensions."); - log.append("Expecting two, returned " + size_actual); - } - } else { - log.append("getExtensions() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getExtensions() return null list|"); - } - - if (tmpp != null) { - log.append("getSubprotocols() return non-null List|"); - if (!tmpp.isEmpty()) { - log.append("getSubprotocols() return non-empty List with size " - + tmpp.size() + "|"); - int size_actual = tmpp.size(); - if (size_actual == expected_subprotocols.size()) { - for (String subpro : tmpp) { - if (expected_subprotocols.contains(subpro)) { - log.append("sub protocol " + subpro + " found is expected|"); - } else { - passed = false; - log.append( - "sub protocol " + subpro + " found is not expected|"); - } - } - } else { - passed = false; - log.append("getSubprotocols() returned not exactly the same size."); - log.append("Expecting seven, returned " + size_actual); - } - } else { - log.append("getSubprotocols() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getSubprotocols() return null list"); - } - - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: encodersTest - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:71; WebSocket:JAVADOC:202; - * - * @test_Strategy: - */ - public void encodersTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List> expected_encoders = new ArrayList<>(); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer") - .encoders(expected_encoders).build(); - - List> tmp = sec.getEncoders(); - if (tmp != null) { - log.append("getEncoders() return non-null List"); - if (!tmp.isEmpty()) { - int size = tmp.size(); - log.append( - "getEncoders() return non-empty List with size " + size + "|"); - if (size == 2) { - for (Class encoder : tmp) { - log.append("Encoder " + encoder + " found "); - if (expected_encoders.contains(encoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getEncoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getEncoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getEncoders() return null list"); - } - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: decodersTest - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:70; WebSocket:JAVADOC:201; - * - * @test_Strategy: - */ - public void decodersTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List> expected_decoders = new ArrayList<>(); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer") - .decoders(expected_decoders).build(); - - List> tmp = sec.getDecoders(); - if (tmp != null) { - log.append("getDecoders() return non-null List|"); - if (!tmp.isEmpty()) { - int size = tmp.size(); - log.append("getDecoders() return non-empty List with size " - + tmp.size() + "|"); - if (size == 2) { - for (Class decoder : tmp) { - log.append("Decoder " + decoder + " found "); - if (expected_decoders.contains(decoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getDecoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getDecoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getDecoders() return null list|"); - } - - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: constructorTest2 - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:195; WebSocket:JAVADOC:197; WebSocket:JAVADOC:203; - * WebSocket:JAVADOC:204; WebSocket:JAVADOC:70; WebSocket:JAVADOC:201; - * - * @test_Strategy: - */ - public void constructorTest2() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - - List> expected_decoders = new ArrayList<>(); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer") - .subprotocols(expected_subprotocols).extensions(extensions) - .decoders(expected_decoders).build(); - - List tmpe = sec.getExtensions(); - List tmpp = sec.getSubprotocols(); - List> tmpd = sec.getDecoders(); - - if (tmpe != null) { - log.append("getExtensions() return non-null List|"); - if (!tmpe.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmpe.size() + "|"); - int size_actual = tmpe.size(); - if (size_actual == extensions.size()) { - for (Extension ext : tmpe) { - if (extensions.contains(ext)) { - log.append("extension " + ext + " found is expected|"); - } else { - passed = false; - log.append("extension " + ext + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getExtensions() returned not exactly the same amount of extensions."); - log.append("Expecting two, returned " + size_actual); - } - } else { - log.append("getExtensions() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getExtensions() return null list|"); - } - - if (tmpp != null) { - log.append("getSubprotocols() return non-null List|"); - if (!tmpp.isEmpty()) { - log.append("getSubprotocols() return non-empty List with size " - + tmpp.size() + "|"); - int size_actual = tmpp.size(); - if (size_actual == expected_subprotocols.size()) { - for (String subpro : tmpp) { - if (expected_subprotocols.contains(subpro)) { - log.append("sub protocol " + subpro + " found is expected|"); - } else { - passed = false; - log.append( - "sub protocol " + subpro + " found is not expected|"); - } - } - } else { - passed = false; - log.append("getSubprotocols() returned not exactly the same size."); - log.append("Expecting seven, returned " + size_actual); - } - } else { - log.append("getSubprotocols() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getSubprotocols() return null list"); - } - - if (tmpd != null) { - log.append("getDecoders() return non-null List|"); - if (!tmpd.isEmpty()) { - int size = tmpd.size(); - log.append("getDecoders() return non-empty List with size " - + tmpd.size() + "|"); - if (size == 2) { - for (Class decoder : tmpd) { - log.append("Decoder " + decoder + " found "); - if (expected_decoders.contains(decoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getDecoders() returned not exactly the same size."); - log.append("Expecting seven, returned " + size); - } - } else { - log.append("getDecoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getDecoders() return null list|"); - } - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: constructorTest3 - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:195; WebSocket:JAVADOC:197; WebSocket:JAVADOC:203; - * WebSocket:JAVADOC:204; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; - * WebSocket:JAVADOC:201; WebSocket:JAVADOC:202; - * - * @test_Strategy: - */ - public void constructorTest3() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - - List> expected_encoders = new ArrayList<>(); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); - - List> expected_decoders = new ArrayList<>(); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer") - .subprotocols(expected_subprotocols).extensions(extensions) - .decoders(expected_decoders).encoders(expected_encoders).build(); - - List tmpe = sec.getExtensions(); - List tmpp = sec.getSubprotocols(); - List> tmpd = sec.getDecoders(); - - if (tmpe != null) { - log.append("getExtensions() return non-null List|"); - if (!tmpe.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmpe.size() + "|"); - int size_actual = tmpe.size(); - if (size_actual == extensions.size()) { - for (Extension ext : tmpe) { - if (extensions.contains(ext)) { - log.append("extension " + ext + " found is expected|"); - } else { - passed = false; - log.append("extension " + ext + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getExtensions() returned not exactly the same amount of extensions."); - log.append("Expecting two, returned " + size_actual); - } - } else { - log.append("getExtensions() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getExtensions() return null list|"); - } - - if (tmpp != null) { - log.append("getSubprotocols() return non-null List|"); - if (!tmpp.isEmpty()) { - log.append("getSubprotocols() return non-empty List with size " - + tmpp.size() + "|"); - int size_actual = tmpp.size(); - if (size_actual == expected_subprotocols.size()) { - for (String subpro : tmpp) { - if (expected_subprotocols.contains(subpro)) { - log.append("sub protocol " + subpro + " found is expected|"); - } else { - passed = false; - log.append( - "sub protocol " + subpro + " found is not expected|"); - } - } - } else { - passed = false; - log.append("getSubprotocols() returned not exactly the same size."); - log.append("Expecting seven, returned " + size_actual); - } - } else { - log.append("getSubprotocols() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getSubprotocols() return null list"); - } - - if (tmpd != null) { - log.append("getDecoders() return non-null List|"); - if (!tmpd.isEmpty()) { - int size = tmpd.size(); - log.append("getDecoders() return non-empty List with size " - + tmpd.size() + "|"); - if (size == 2) { - for (Class decoder : tmpd) { - log.append("Decoder " + decoder + " found "); - if (expected_decoders.contains(decoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getDecoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getDecoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getDecoders() return null list|"); - } - - List> tmpen = sec.getEncoders(); - if (tmpen != null) { - log.append("getEncoders() return non-null List"); - if (!tmpen.isEmpty()) { - int size = tmpen.size(); - log.append( - "getEncoders() return non-empty List with size " + size + "|"); - if (size == 2) { - for (Class encoder : tmpen) { - log.append("Encoder " + encoder + " found "); - if (expected_encoders.contains(encoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getEncoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getEncoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getEncoders() return null list"); - } - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: configuratorTest - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:199; WebSocket:JAVADOC:193; WebSocket:JAVADOC:206; - * WebSocket:JAVADOC:207; WebSocket:JAVADOC:69; - * - * @test_Strategy: - */ - public void configuratorTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - ServerEndpointConfig.Configurator config = new TCKConfigurator(); - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer").configurator(config) - .build(); - - ServerEndpointConfig.Configurator tmpc = sec.getConfigurator(); - - if (!tmpc.getClass().equals( - com.sun.ts.tests.websocket.api.jakarta.websocket.server.serverendpointconfig.TCKConfigurator.class)) { - log.append("getConfigurator() returned a different Configurator: " - + tmpc.getClass().getName()); - passed = false; - } - - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: constructorTest4 - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:199; WebSocket:JAVADOC:193; WebSocket:JAVADOC:206; - * WebSocket:JAVADOC:207; WebSocket:JAVADOC:69; WebSocket:JAVADOC:70; - * WebSocket:JAVADOC:71; WebSocket:JAVADOC:195; WebSocket:JAVADOC:197; - * - * @test_Strategy: - */ - public void constructorTest4() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - ServerEndpointConfig.Configurator config = new TCKConfigurator(); - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer").configurator(config) - .build(); - List tmp = sec.getDecoders(); - if (tmp != null) { - TestUtil.logTrace("getDecoders() return non-null List"); - if (!tmp.isEmpty()) { - log.append("getDecoders() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = sec.getEncoders(); - if (tmp != null) { - TestUtil.logTrace("getEncoders() return non-null List"); - if (!tmp.isEmpty()) { - log.append("getEncoders() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = sec.getExtensions(); - if (tmp != null) { - TestUtil.logTrace("getExtensions() return non-null List"); - if (!tmp.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - tmp = sec.getSubprotocols(); - if (tmp != null) { - TestUtil.logTrace("getSubprotocols() return non-null List"); - if (!tmp.isEmpty()) { - log.append("getSubprotocols() return non-empty List with size " - + tmp.size() + "|"); - passed = false; - } - } - - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: getEndpointClassTest - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:194; - * - * @test_Strategy: - */ - public void getEndpointClassTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer").build(); - - Class tmp = sec.getEndpointClass(); - - if (!tmp.equals( - com.sun.ts.tests.websocket.api.jakarta.websocket.server.serverendpointconfig.TCKEndpoint.class)) { - log.append( - "getEndpointClass() returned a different Class: " + tmp.getName()); - passed = false; - } - - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: getPathTest - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:196; - * - * @test_Strategy: - */ - public void getPathTest() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - String path = "/TCKTestServer"; - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, path).build(); - - String tmp = sec.getPath(); - - if (!path.equals(tmp)) { - log.append("getPath() returned a different path: " + tmp); - passed = false; - } - - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - /* - * @testName: constructorTest5 - * - * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:199; WebSocket:JAVADOC:193; WebSocket:JAVADOC:206; - * WebSocket:JAVADOC:207; WebSocket:JAVADOC:69; WebSocket:JAVADOC:195; - * WebSocket:JAVADOC:197; WebSocket:JAVADOC:203; WebSocket:JAVADOC:204; - * WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; WebSocket:JAVADOC:201; - * WebSocket:JAVADOC:202; - * - * @test_Strategy: - */ - public void constructorTest5() throws Exception { - boolean passed = true; - StringBuffer log = new StringBuffer(); - - List expected_subprotocols = Arrays.asList("JSON", "XML", "XMPP", - "Hessian", "Quake", "PUB/SUB", "Query"); - - List> expected_encoders = new ArrayList<>(); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); - - List> expected_decoders = new ArrayList<>(); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); - - ServerEndpointConfig.Configurator config = new TCKConfigurator(); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ServerEndpointConfig sec = ServerEndpointConfig.Builder - .create(TCKEndpoint.class, "/TCKTestServer") - .subprotocols(expected_subprotocols).extensions(extensions) - .decoders(expected_decoders).encoders(expected_encoders) - .configurator(config).build(); - - List tmpe = sec.getExtensions(); - List tmpp = sec.getSubprotocols(); - List> tmpd = sec.getDecoders(); - - if (tmpe != null) { - log.append("getExtensions() return non-null List|"); - if (!tmpe.isEmpty()) { - log.append("getExtensions() return non-empty List with size " - + tmpe.size() + "|"); - int size_actual = tmpe.size(); - if (size_actual == extensions.size()) { - for (Extension ext : tmpe) { - if (extensions.contains(ext)) { - log.append("extension " + ext + " found is expected|"); - } else { - passed = false; - log.append("extension " + ext + " found is not expected|"); - } - } - } else { - passed = false; - log.append( - "getExtensions() returned not exactly the same amount of extensions."); - log.append("Expecting two, returned " + size_actual); - } - } else { - log.append("getExtensions() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getExtensions() return null list|"); - } - - if (tmpp != null) { - log.append("getSubprotocols() return non-null List|"); - if (!tmpp.isEmpty()) { - log.append("getSubprotocols() return non-empty List with size " - + tmpp.size() + "|"); - int size_actual = tmpp.size(); - if (size_actual == expected_subprotocols.size()) { - for (String subpro : tmpp) { - if (expected_subprotocols.contains(subpro)) { - log.append("sub protocol " + subpro + " found is expected|"); - } else { - passed = false; - log.append( - "sub protocol " + subpro + " found is not expected|"); - } - } - } else { - passed = false; - log.append("getSubprotocols() returned not exactly the same size."); - log.append("Expecting seven, returned " + size_actual); - } - } else { - log.append("getSubprotocols() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getSubprotocols() return null list"); - } - - if (tmpd != null) { - log.append("getDecoders() return non-null List|"); - if (!tmpd.isEmpty()) { - int size = tmpd.size(); - log.append("getDecoders() return non-empty List with size " - + tmpd.size() + "|"); - if (size == 2) { - for (Class decoder : tmpd) { - log.append("Decoder " + decoder + " found "); - if (expected_decoders.contains(decoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getDecoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getDecoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getDecoders() return null list|"); - } - - List> tmpen = sec.getEncoders(); - if (tmpen != null) { - log.append("getEncoders() return non-null List"); - if (!tmpen.isEmpty()) { - int size = tmpen.size(); - log.append( - "getEncoders() return non-empty List with size " + size + "|"); - if (size == 2) { - for (Class encoder : tmpen) { - log.append("Encoder " + encoder + " found "); - if (expected_encoders.contains(encoder)) { - log.append("is expected.|"); - } else { - passed = false; - log.append("is not expected.|"); - } - } - } else { - passed = false; - log.append("getEncoders() returned not exactly the same size."); - log.append("Expecting two, returned " + size); - } - } else { - log.append("getEncoders() return empty List|"); - passed = false; - } - } else { - passed = false; - log.append("getEncoders() return null list"); - } - } catch (Exception e) { - log.append(e.getMessage()); - passed = false; - } - - System.out.println(log.toString()); - - if (passed == false) { - throw new Exception("Test failed: " + log.toString()); - } - } - - public void cleanup() { - } -} - -class TCKConfigurator extends ServerEndpointConfig.Configurator { - - public static final TCKEndpoint testEndpoint = new TCKEndpoint(); - - @Override - public T getEndpointInstance(Class endpointClass) - throws InstantiationException { - if (endpointClass.equals(TCKEndpoint.class)) { - return (T) testEndpoint; - } - throw new InstantiationException(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/server/serverendpointconfig/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/server/serverendpointconfig/WSClientIT.java new file mode 100644 index 0000000000..ef4b4685e3 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/server/serverendpointconfig/WSClientIT.java @@ -0,0 +1,1208 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $Id:$ + */ +package com.sun.ts.tests.websocket.api.jakarta.websocket.server.serverendpointconfig; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.TCKExtension; + +import jakarta.websocket.Decoder; +import jakarta.websocket.Encoder; +import jakarta.websocket.Extension; +import jakarta.websocket.server.ServerEndpointConfig; + +@ExtendWith(ArquillianExtension.class) +public class WSClientIT { + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "websocket_serverendpointconfig.war"); + archive.addClasses(TCKEndpoint.class); + return archive; + } + + /* Run test */ + /* + * @testName: constructortest + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; WebSocket:JAVADOC:195; + * WebSocket:JAVADOC:197; + * + * + * @test_Strategy: Test constructor + */ + @Test + public void constructortest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer").build(); + + List tmp = sec.getDecoders(); + if (tmp != null) { + TestUtil.logTrace("getDecoders() return non-null List"); + if (!tmp.isEmpty()) { + log.append("getDecoders() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = sec.getEncoders(); + if (tmp != null) { + TestUtil.logTrace("getEncoders() return non-null List"); + if (!tmp.isEmpty()) { + log.append("getEncoders() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = sec.getExtensions(); + if (tmp != null) { + TestUtil.logTrace("getExtensions() return non-null List"); + if (!tmp.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = sec.getSubprotocols(); + if (tmp != null) { + TestUtil.logTrace("getSubprotocols() return non-null List"); + if (!tmp.isEmpty()) { + log.append("getSubprotocols() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + + if (passed == false) { + throw new Exception("Test failed"); + } + } + + /* + * @testName: subprotocolsTest + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:197; WebSocket:JAVADOC:204; + * + * @test_Strategy: + */ + @Test + public void subprotocolsTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer") + .subprotocols(expected_subprotocols).build(); + + List tmp = sec.getSubprotocols(); + if (tmp != null) { + log.append("getSubprotocols() return non-null List|"); + if (!tmp.isEmpty()) { + log.append("getSubprotocols() return non-empty List with size " + tmp.size() + "|"); + int size_actual = tmp.size(); + if (size_actual == expected_subprotocols.size()) { + for (String subpro : tmp) { + if (expected_subprotocols.contains(subpro)) { + log.append("sub protocol " + subpro + " found is expected|"); + } else { + passed = false; + log.append("sub protocol " + subpro + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getSubprotocols() returned not exactly the same size."); + log.append("Expecting seven, returned " + size_actual); + } + } else { + log.append("getSubprotocols() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getSubprotocols() return null list"); + } + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: extensionsTest + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:195; WebSocket:JAVADOC:203; + * + * @test_Strategy: + */ + @Test + public void extensionsTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer") + .extensions(extensions).build(); + List tmp = sec.getExtensions(); + if (tmp != null) { + log.append("getExtensions() return non-null List|"); + if (!tmp.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmp.size() + "|"); + int size_actual = tmp.size(); + if (size_actual == extensions.size()) { + for (Extension ext : tmp) { + if (extensions.contains(ext)) { + log.append("extension " + ext + " found is expected|"); + } else { + passed = false; + log.append("extension " + ext + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getExtensions() returned not exactly the same amount of extensions."); + log.append("Expecting two, returned " + size_actual); + } + } else { + log.append("getExtensions() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getExtensions() return null list|"); + } + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: constructorTest1 + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:195; WebSocket:JAVADOC:197; WebSocket:JAVADOC:203; + * WebSocket:JAVADOC:204; + * + * + * @test_Strategy: + */ + @Test + public void constructorTest1() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer") + .subprotocols(expected_subprotocols).extensions(extensions).build(); + + List tmpe = sec.getExtensions(); + List tmpp = sec.getSubprotocols(); + + if (tmpe != null) { + log.append("getExtensions() return non-null List|"); + if (!tmpe.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmpe.size() + "|"); + int size_actual = tmpe.size(); + if (size_actual == extensions.size()) { + for (Extension ext : tmpe) { + if (extensions.contains(ext)) { + log.append("extension " + ext + " found is expected|"); + } else { + passed = false; + log.append("extension " + ext + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getExtensions() returned not exactly the same amount of extensions."); + log.append("Expecting two, returned " + size_actual); + } + } else { + log.append("getExtensions() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getExtensions() return null list|"); + } + + if (tmpp != null) { + log.append("getSubprotocols() return non-null List|"); + if (!tmpp.isEmpty()) { + log.append("getSubprotocols() return non-empty List with size " + tmpp.size() + "|"); + int size_actual = tmpp.size(); + if (size_actual == expected_subprotocols.size()) { + for (String subpro : tmpp) { + if (expected_subprotocols.contains(subpro)) { + log.append("sub protocol " + subpro + " found is expected|"); + } else { + passed = false; + log.append("sub protocol " + subpro + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getSubprotocols() returned not exactly the same size."); + log.append("Expecting seven, returned " + size_actual); + } + } else { + log.append("getSubprotocols() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getSubprotocols() return null list"); + } + + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: encodersTest + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:71; WebSocket:JAVADOC:202; + * + * @test_Strategy: + */ + @Test + public void encodersTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List> expected_encoders = new ArrayList<>(); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer") + .encoders(expected_encoders).build(); + + List> tmp = sec.getEncoders(); + if (tmp != null) { + log.append("getEncoders() return non-null List"); + if (!tmp.isEmpty()) { + int size = tmp.size(); + log.append("getEncoders() return non-empty List with size " + size + "|"); + if (size == 2) { + for (Class encoder : tmp) { + log.append("Encoder " + encoder + " found "); + if (expected_encoders.contains(encoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getEncoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getEncoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getEncoders() return null list"); + } + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: decodersTest + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:70; WebSocket:JAVADOC:201; + * + * @test_Strategy: + */ + @Test + public void decodersTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List> expected_decoders = new ArrayList<>(); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer") + .decoders(expected_decoders).build(); + + List> tmp = sec.getDecoders(); + if (tmp != null) { + log.append("getDecoders() return non-null List|"); + if (!tmp.isEmpty()) { + int size = tmp.size(); + log.append("getDecoders() return non-empty List with size " + tmp.size() + "|"); + if (size == 2) { + for (Class decoder : tmp) { + log.append("Decoder " + decoder + " found "); + if (expected_decoders.contains(decoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getDecoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getDecoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getDecoders() return null list|"); + } + + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: constructorTest2 + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:195; WebSocket:JAVADOC:197; WebSocket:JAVADOC:203; + * WebSocket:JAVADOC:204; WebSocket:JAVADOC:70; WebSocket:JAVADOC:201; + * + * @test_Strategy: + */ + @Test + public void constructorTest2() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + + List> expected_decoders = new ArrayList<>(); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer") + .subprotocols(expected_subprotocols).extensions(extensions).decoders(expected_decoders).build(); + + List tmpe = sec.getExtensions(); + List tmpp = sec.getSubprotocols(); + List> tmpd = sec.getDecoders(); + + if (tmpe != null) { + log.append("getExtensions() return non-null List|"); + if (!tmpe.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmpe.size() + "|"); + int size_actual = tmpe.size(); + if (size_actual == extensions.size()) { + for (Extension ext : tmpe) { + if (extensions.contains(ext)) { + log.append("extension " + ext + " found is expected|"); + } else { + passed = false; + log.append("extension " + ext + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getExtensions() returned not exactly the same amount of extensions."); + log.append("Expecting two, returned " + size_actual); + } + } else { + log.append("getExtensions() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getExtensions() return null list|"); + } + + if (tmpp != null) { + log.append("getSubprotocols() return non-null List|"); + if (!tmpp.isEmpty()) { + log.append("getSubprotocols() return non-empty List with size " + tmpp.size() + "|"); + int size_actual = tmpp.size(); + if (size_actual == expected_subprotocols.size()) { + for (String subpro : tmpp) { + if (expected_subprotocols.contains(subpro)) { + log.append("sub protocol " + subpro + " found is expected|"); + } else { + passed = false; + log.append("sub protocol " + subpro + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getSubprotocols() returned not exactly the same size."); + log.append("Expecting seven, returned " + size_actual); + } + } else { + log.append("getSubprotocols() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getSubprotocols() return null list"); + } + + if (tmpd != null) { + log.append("getDecoders() return non-null List|"); + if (!tmpd.isEmpty()) { + int size = tmpd.size(); + log.append("getDecoders() return non-empty List with size " + tmpd.size() + "|"); + if (size == 2) { + for (Class decoder : tmpd) { + log.append("Decoder " + decoder + " found "); + if (expected_decoders.contains(decoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getDecoders() returned not exactly the same size."); + log.append("Expecting seven, returned " + size); + } + } else { + log.append("getDecoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getDecoders() return null list|"); + } + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: constructorTest3 + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:195; WebSocket:JAVADOC:197; WebSocket:JAVADOC:203; + * WebSocket:JAVADOC:204; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; + * WebSocket:JAVADOC:201; WebSocket:JAVADOC:202; + * + * @test_Strategy: + */ + @Test + public void constructorTest3() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + + List> expected_encoders = new ArrayList<>(); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); + + List> expected_decoders = new ArrayList<>(); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer") + .subprotocols(expected_subprotocols).extensions(extensions).decoders(expected_decoders) + .encoders(expected_encoders).build(); + + List tmpe = sec.getExtensions(); + List tmpp = sec.getSubprotocols(); + List> tmpd = sec.getDecoders(); + + if (tmpe != null) { + log.append("getExtensions() return non-null List|"); + if (!tmpe.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmpe.size() + "|"); + int size_actual = tmpe.size(); + if (size_actual == extensions.size()) { + for (Extension ext : tmpe) { + if (extensions.contains(ext)) { + log.append("extension " + ext + " found is expected|"); + } else { + passed = false; + log.append("extension " + ext + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getExtensions() returned not exactly the same amount of extensions."); + log.append("Expecting two, returned " + size_actual); + } + } else { + log.append("getExtensions() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getExtensions() return null list|"); + } + + if (tmpp != null) { + log.append("getSubprotocols() return non-null List|"); + if (!tmpp.isEmpty()) { + log.append("getSubprotocols() return non-empty List with size " + tmpp.size() + "|"); + int size_actual = tmpp.size(); + if (size_actual == expected_subprotocols.size()) { + for (String subpro : tmpp) { + if (expected_subprotocols.contains(subpro)) { + log.append("sub protocol " + subpro + " found is expected|"); + } else { + passed = false; + log.append("sub protocol " + subpro + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getSubprotocols() returned not exactly the same size."); + log.append("Expecting seven, returned " + size_actual); + } + } else { + log.append("getSubprotocols() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getSubprotocols() return null list"); + } + + if (tmpd != null) { + log.append("getDecoders() return non-null List|"); + if (!tmpd.isEmpty()) { + int size = tmpd.size(); + log.append("getDecoders() return non-empty List with size " + tmpd.size() + "|"); + if (size == 2) { + for (Class decoder : tmpd) { + log.append("Decoder " + decoder + " found "); + if (expected_decoders.contains(decoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getDecoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getDecoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getDecoders() return null list|"); + } + + List> tmpen = sec.getEncoders(); + if (tmpen != null) { + log.append("getEncoders() return non-null List"); + if (!tmpen.isEmpty()) { + int size = tmpen.size(); + log.append("getEncoders() return non-empty List with size " + size + "|"); + if (size == 2) { + for (Class encoder : tmpen) { + log.append("Encoder " + encoder + " found "); + if (expected_encoders.contains(encoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getEncoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getEncoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getEncoders() return null list"); + } + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: configuratorTest + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:199; WebSocket:JAVADOC:193; WebSocket:JAVADOC:206; + * WebSocket:JAVADOC:207; WebSocket:JAVADOC:69; + * + * @test_Strategy: + */ + @Test + public void configuratorTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + ServerEndpointConfig.Configurator config = new TCKConfigurator(); + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer") + .configurator(config).build(); + + ServerEndpointConfig.Configurator tmpc = sec.getConfigurator(); + + if (!tmpc.getClass().equals( + com.sun.ts.tests.websocket.api.jakarta.websocket.server.serverendpointconfig.TCKConfigurator.class)) { + log.append("getConfigurator() returned a different Configurator: " + tmpc.getClass().getName()); + passed = false; + } + + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: constructorTest4 + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:199; WebSocket:JAVADOC:193; WebSocket:JAVADOC:206; + * WebSocket:JAVADOC:207; WebSocket:JAVADOC:69; WebSocket:JAVADOC:70; + * WebSocket:JAVADOC:71; WebSocket:JAVADOC:195; WebSocket:JAVADOC:197; + * + * @test_Strategy: + */ + @Test + public void constructorTest4() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + ServerEndpointConfig.Configurator config = new TCKConfigurator(); + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer") + .configurator(config).build(); + List tmp = sec.getDecoders(); + if (tmp != null) { + TestUtil.logTrace("getDecoders() return non-null List"); + if (!tmp.isEmpty()) { + log.append("getDecoders() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = sec.getEncoders(); + if (tmp != null) { + TestUtil.logTrace("getEncoders() return non-null List"); + if (!tmp.isEmpty()) { + log.append("getEncoders() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = sec.getExtensions(); + if (tmp != null) { + TestUtil.logTrace("getExtensions() return non-null List"); + if (!tmp.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + tmp = sec.getSubprotocols(); + if (tmp != null) { + TestUtil.logTrace("getSubprotocols() return non-null List"); + if (!tmp.isEmpty()) { + log.append("getSubprotocols() return non-empty List with size " + tmp.size() + "|"); + passed = false; + } + } + + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: getEndpointClassTest + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:194; + * + * @test_Strategy: + */ + @Test + public void getEndpointClassTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer").build(); + + Class tmp = sec.getEndpointClass(); + + if (!tmp.equals( + com.sun.ts.tests.websocket.api.jakarta.websocket.server.serverendpointconfig.TCKEndpoint.class)) { + log.append("getEndpointClass() returned a different Class: " + tmp.getName()); + passed = false; + } + + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: getPathTest + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:196; + * + * @test_Strategy: + */ + @Test + public void getPathTest() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + String path = "/TCKTestServer"; + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, path).build(); + + String tmp = sec.getPath(); + + if (!path.equals(tmp)) { + log.append("getPath() returned a different path: " + tmp); + passed = false; + } + + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + /* + * @testName: constructorTest5 + * + * @assertion_ids: WebSocket:JAVADOC:200; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:199; WebSocket:JAVADOC:193; WebSocket:JAVADOC:206; + * WebSocket:JAVADOC:207; WebSocket:JAVADOC:69; WebSocket:JAVADOC:195; + * WebSocket:JAVADOC:197; WebSocket:JAVADOC:203; WebSocket:JAVADOC:204; + * WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; WebSocket:JAVADOC:201; + * WebSocket:JAVADOC:202; + * + * @test_Strategy: + */ + @Test + public void constructorTest5() throws Exception { + boolean passed = true; + StringBuffer log = new StringBuffer(); + + List expected_subprotocols = Arrays.asList("JSON", "XML", "XMPP", "Hessian", "Quake", "PUB/SUB", + "Query"); + + List> expected_encoders = new ArrayList<>(); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); + + List> expected_decoders = new ArrayList<>(); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); + + ServerEndpointConfig.Configurator config = new TCKConfigurator(); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(TCKEndpoint.class, "/TCKTestServer") + .subprotocols(expected_subprotocols).extensions(extensions).decoders(expected_decoders) + .encoders(expected_encoders).configurator(config).build(); + + List tmpe = sec.getExtensions(); + List tmpp = sec.getSubprotocols(); + List> tmpd = sec.getDecoders(); + + if (tmpe != null) { + log.append("getExtensions() return non-null List|"); + if (!tmpe.isEmpty()) { + log.append("getExtensions() return non-empty List with size " + tmpe.size() + "|"); + int size_actual = tmpe.size(); + if (size_actual == extensions.size()) { + for (Extension ext : tmpe) { + if (extensions.contains(ext)) { + log.append("extension " + ext + " found is expected|"); + } else { + passed = false; + log.append("extension " + ext + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getExtensions() returned not exactly the same amount of extensions."); + log.append("Expecting two, returned " + size_actual); + } + } else { + log.append("getExtensions() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getExtensions() return null list|"); + } + + if (tmpp != null) { + log.append("getSubprotocols() return non-null List|"); + if (!tmpp.isEmpty()) { + log.append("getSubprotocols() return non-empty List with size " + tmpp.size() + "|"); + int size_actual = tmpp.size(); + if (size_actual == expected_subprotocols.size()) { + for (String subpro : tmpp) { + if (expected_subprotocols.contains(subpro)) { + log.append("sub protocol " + subpro + " found is expected|"); + } else { + passed = false; + log.append("sub protocol " + subpro + " found is not expected|"); + } + } + } else { + passed = false; + log.append("getSubprotocols() returned not exactly the same size."); + log.append("Expecting seven, returned " + size_actual); + } + } else { + log.append("getSubprotocols() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getSubprotocols() return null list"); + } + + if (tmpd != null) { + log.append("getDecoders() return non-null List|"); + if (!tmpd.isEmpty()) { + int size = tmpd.size(); + log.append("getDecoders() return non-empty List with size " + tmpd.size() + "|"); + if (size == 2) { + for (Class decoder : tmpd) { + log.append("Decoder " + decoder + " found "); + if (expected_decoders.contains(decoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getDecoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getDecoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getDecoders() return null list|"); + } + + List> tmpen = sec.getEncoders(); + if (tmpen != null) { + log.append("getEncoders() return non-null List"); + if (!tmpen.isEmpty()) { + int size = tmpen.size(); + log.append("getEncoders() return non-empty List with size " + size + "|"); + if (size == 2) { + for (Class encoder : tmpen) { + log.append("Encoder " + encoder + " found "); + if (expected_encoders.contains(encoder)) { + log.append("is expected.|"); + } else { + passed = false; + log.append("is not expected.|"); + } + } + } else { + passed = false; + log.append("getEncoders() returned not exactly the same size."); + log.append("Expecting two, returned " + size); + } + } else { + log.append("getEncoders() return empty List|"); + passed = false; + } + } else { + passed = false; + log.append("getEncoders() return null list"); + } + } catch (Exception e) { + log.append(e.getMessage()); + passed = false; + } + + System.out.println(log.toString()); + + if (passed == false) { + throw new Exception("Test failed: " + log.toString()); + } + } + + public void cleanup() { + } +} + +class TCKConfigurator extends ServerEndpointConfig.Configurator { + + public static final TCKEndpoint testEndpoint = new TCKEndpoint(); + + @Override + public T getEndpointInstance(Class endpointClass) throws InstantiationException { + if (endpointClass.equals(TCKEndpoint.class)) { + return (T) testEndpoint; + } + throw new InstantiationException(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/websocketcontainer/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/websocketcontainer/WSClient.java deleted file mode 100644 index 4f7639fdc2..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/websocketcontainer/WSClient.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 - */ - -/* - * $Id:$ - */ -package com.sun.ts.tests.websocket.api.jakarta.websocket.websocketcontainer; - -import java.io.PrintWriter; -import java.util.List; -import java.util.Properties; -import java.util.Set; - -import com.sun.javatest.Status; -import com.sun.ts.lib.harness.ServiceEETest; -import com.sun.ts.lib.util.TestUtil; - -import jakarta.websocket.ContainerProvider; -import jakarta.websocket.Extension; -import jakarta.websocket.Extension.Parameter; -import jakarta.websocket.WebSocketContainer; - -public class WSClient extends ServiceEETest { - - public static void main(String[] args) { - WSClient theTests = new WSClient(); - Status s = theTests.run(args, new PrintWriter(System.out), - new PrintWriter(System.err)); - s.exit(); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ts_home; - */ - @SuppressWarnings("unused") - public void setup(String[] args, Properties p) throws Exception { - } - - /* Run test */ - /* - * @testName: getMaxSessionIdleTimeoutTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:167; - * - * @test_Strategy: Test method getMaxSessionIdleTimeout - */ - public void getMaxSessionIdleTimeoutTest() throws Exception { - WebSocketContainer client = ContainerProvider.getWebSocketContainer(); - - if (client.getDefaultMaxSessionIdleTimeout() != 0L) { - TestUtil.logTrace( - "Default timeout is: " + client.getDefaultMaxSessionIdleTimeout()); - } - } - - /* - * @testName: setMaxSessionIdleTimeoutTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:167; - * WebSocket:JAVADOC:172; - * - * @test_Strategy: Test method setMaxSessionIdleTimeout - */ - public void setMaxSessionIdleTimeoutTest() throws Exception { - long timeout = 987654321L; - WebSocketContainer client = ContainerProvider.getWebSocketContainer(); - client.setDefaultMaxSessionIdleTimeout(timeout); - - if (client.getDefaultMaxSessionIdleTimeout() != timeout) { - throw new Exception( - "Test failed. getMaxSessionIdleTimeout didn't return set value." - + "Expecting " + timeout + "; got " - + client.getDefaultMaxSessionIdleTimeout()); - } - } - - /* - * @testName: getMaxTextMessageBufferSizeTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:168; - * - * @test_Strategy: Test method getMaxTextMessageBufferSize - */ - public void getMaxTextMessageBufferSizeTest() throws Exception { - WebSocketContainer client = ContainerProvider.getWebSocketContainer(); - long default_msgsize = client.getDefaultMaxTextMessageBufferSize(); - System.out - .println("Default MaxTextMessageBufferSize is " + default_msgsize); - } - - /* - * @testName: setMaxTextMessageBufferSizeTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:168; - * WebSocket:JAVADOC:173; - * - * @test_Strategy: - */ - public void setMaxTextMessageBufferSizeTest() throws Exception { - int expected_msgsize = 987654321; - - WebSocketContainer client = ContainerProvider.getWebSocketContainer(); - long default_msgsize = client.getDefaultMaxTextMessageBufferSize(); - System.out - .println("Default MaxTextMessageBufferSize is " + default_msgsize); - - client.setDefaultMaxTextMessageBufferSize(expected_msgsize); - long actual_msgsize = client.getDefaultMaxTextMessageBufferSize(); - if (expected_msgsize != actual_msgsize) { - throw new Exception("DefaultMaxTextMessageBufferSize does not match. " - + "Expecting " + expected_msgsize + ", got " + actual_msgsize); - } - } - - /* - * @testName: getMaxBinaryMessageBufferSizeTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:166; - * - * @test_Strategy: - */ - public void getMaxBinaryMessageBufferSizeTest() throws Exception { - WebSocketContainer client = ContainerProvider.getWebSocketContainer(); - long default_msgsize = client.getDefaultMaxBinaryMessageBufferSize(); - System.out - .println("Default MaxTextMessageBufferSize is " + default_msgsize); - } - - /* - * @testName: setMaxBinaryMessageBufferSizeTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:166; - * WebSocket:JAVADOC:171; - * - * @test_Strategy: - */ - public void setMaxBinaryMessageBufferSizeTest() throws Exception { - int expected_msgsize = 987654321; - - WebSocketContainer client = ContainerProvider.getWebSocketContainer(); - long default_msgsize = client.getDefaultMaxBinaryMessageBufferSize(); - System.out - .println("Default MaxBinaryMessageBufferSize is " + default_msgsize); - - client.setDefaultMaxBinaryMessageBufferSize(expected_msgsize); - long actual_msgsize = client.getDefaultMaxBinaryMessageBufferSize(); - if (expected_msgsize != actual_msgsize) { - throw new Exception("DefaultMaxBinaryMessageBufferSize does not match. " - + "Expecting " + expected_msgsize + ", got " + actual_msgsize); - } - } - - /* - * @testName: getDefaultAsyncSendTimeoutTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:165; - * - * @test_Strategy: Test method getMaxSessionIdleTimeout - */ - public void getDefaultAsyncSendTimeoutTest() throws Exception { - WebSocketContainer client = ContainerProvider.getWebSocketContainer(); - - if (client.getDefaultAsyncSendTimeout() != 0L) { - TestUtil.logTrace( - "Default timeout is: " + client.getDefaultMaxSessionIdleTimeout()); - } - } - - /* - * @testName: setAsyncSendTimeoutTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:165; - * WebSocket:JAVADOC:170; - * - * @test_Strategy: - */ - public void setAsyncSendTimeoutTest() throws Exception { - long expected_timeout = 987654321L; - WebSocketContainer client = ContainerProvider.getWebSocketContainer(); - client.setAsyncSendTimeout(expected_timeout); - - long actual_timeout = client.getDefaultAsyncSendTimeout(); - if (actual_timeout != expected_timeout) { - throw new Exception( - "Test failed. getDefaultAsyncSendTimeout didn't return set value." - + "Expecting " + expected_timeout + "; got " + actual_timeout); - } - } - - /* - * @testName: getInstalledExtensionsTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:169; - * - * @test_Strategy: - */ - public void getInstalledExtensionsTest() throws Exception { - WebSocketContainer client = ContainerProvider.getWebSocketContainer(); - - Set extensions = client.getInstalledExtensions(); - if (extensions != null) { - if (!extensions.isEmpty()) { - for (Extension tmp : extensions) { - System.out.println("Installed Extension: " + tmp.getName()); - List params = tmp.getParameters(); - for (Parameter tmp1 : params) { - System.out.println("Parameter's name= " + tmp1.getName() - + "Parameter's value= " + tmp1.getValue()); - } - } - } else { - System.out.println("Installed Extension returned empty set"); - } - } else { - System.out.println("getInstalledExtensions() returned null"); - } - } - - public void cleanup() { - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/websocketcontainer/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/websocketcontainer/WSClientIT.java new file mode 100644 index 0000000000..9d71b562a4 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/api/jakarta/websocket/websocketcontainer/WSClientIT.java @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $Id:$ + */ +package com.sun.ts.tests.websocket.api.jakarta.websocket.websocketcontainer; + +import java.util.List; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import com.sun.ts.lib.util.TestUtil; + +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.Extension; +import jakarta.websocket.Extension.Parameter; +import jakarta.websocket.WebSocketContainer; + +public class WSClientIT { + + /* Run test */ + /* + * @testName: getMaxSessionIdleTimeoutTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:167; + * + * @test_Strategy: Test method getMaxSessionIdleTimeout + */ + @Test + public void getMaxSessionIdleTimeoutTest() throws Exception { + WebSocketContainer client = ContainerProvider.getWebSocketContainer(); + + if (client.getDefaultMaxSessionIdleTimeout() != 0L) { + TestUtil.logTrace("Default timeout is: " + client.getDefaultMaxSessionIdleTimeout()); + } + } + + /* + * @testName: setMaxSessionIdleTimeoutTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:167; + * WebSocket:JAVADOC:172; + * + * @test_Strategy: Test method setMaxSessionIdleTimeout + */ + @Test + public void setMaxSessionIdleTimeoutTest() throws Exception { + long timeout = 987654321L; + WebSocketContainer client = ContainerProvider.getWebSocketContainer(); + client.setDefaultMaxSessionIdleTimeout(timeout); + + if (client.getDefaultMaxSessionIdleTimeout() != timeout) { + throw new Exception("Test failed. getMaxSessionIdleTimeout didn't return set value." + "Expecting " + + timeout + "; got " + client.getDefaultMaxSessionIdleTimeout()); + } + } + + /* + * @testName: getMaxTextMessageBufferSizeTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:168; + * + * @test_Strategy: Test method getMaxTextMessageBufferSize + */ + @Test + public void getMaxTextMessageBufferSizeTest() throws Exception { + WebSocketContainer client = ContainerProvider.getWebSocketContainer(); + long default_msgsize = client.getDefaultMaxTextMessageBufferSize(); + System.out.println("Default MaxTextMessageBufferSize is " + default_msgsize); + } + + /* + * @testName: setMaxTextMessageBufferSizeTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:168; + * WebSocket:JAVADOC:173; + * + * @test_Strategy: + */ + @Test + public void setMaxTextMessageBufferSizeTest() throws Exception { + int expected_msgsize = 987654321; + + WebSocketContainer client = ContainerProvider.getWebSocketContainer(); + long default_msgsize = client.getDefaultMaxTextMessageBufferSize(); + System.out.println("Default MaxTextMessageBufferSize is " + default_msgsize); + + client.setDefaultMaxTextMessageBufferSize(expected_msgsize); + long actual_msgsize = client.getDefaultMaxTextMessageBufferSize(); + if (expected_msgsize != actual_msgsize) { + throw new Exception("DefaultMaxTextMessageBufferSize does not match. " + "Expecting " + expected_msgsize + + ", got " + actual_msgsize); + } + } + + /* + * @testName: getMaxBinaryMessageBufferSizeTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:166; + * + * @test_Strategy: + */ + @Test + public void getMaxBinaryMessageBufferSizeTest() throws Exception { + WebSocketContainer client = ContainerProvider.getWebSocketContainer(); + long default_msgsize = client.getDefaultMaxBinaryMessageBufferSize(); + System.out.println("Default MaxTextMessageBufferSize is " + default_msgsize); + } + + /* + * @testName: setMaxBinaryMessageBufferSizeTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:166; + * WebSocket:JAVADOC:171; + * + * @test_Strategy: + */ + @Test + public void setMaxBinaryMessageBufferSizeTest() throws Exception { + int expected_msgsize = 987654321; + + WebSocketContainer client = ContainerProvider.getWebSocketContainer(); + long default_msgsize = client.getDefaultMaxBinaryMessageBufferSize(); + System.out.println("Default MaxBinaryMessageBufferSize is " + default_msgsize); + + client.setDefaultMaxBinaryMessageBufferSize(expected_msgsize); + long actual_msgsize = client.getDefaultMaxBinaryMessageBufferSize(); + if (expected_msgsize != actual_msgsize) { + throw new Exception("DefaultMaxBinaryMessageBufferSize does not match. " + "Expecting " + expected_msgsize + + ", got " + actual_msgsize); + } + } + + /* + * @testName: getDefaultAsyncSendTimeoutTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:165; + * + * @test_Strategy: Test method getMaxSessionIdleTimeout + */ + @Test + public void getDefaultAsyncSendTimeoutTest() throws Exception { + WebSocketContainer client = ContainerProvider.getWebSocketContainer(); + + if (client.getDefaultAsyncSendTimeout() != 0L) { + TestUtil.logTrace("Default timeout is: " + client.getDefaultMaxSessionIdleTimeout()); + } + } + + /* + * @testName: setAsyncSendTimeoutTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:165; + * WebSocket:JAVADOC:170; + * + * @test_Strategy: + */ + @Test + public void setAsyncSendTimeoutTest() throws Exception { + long expected_timeout = 987654321L; + WebSocketContainer client = ContainerProvider.getWebSocketContainer(); + client.setAsyncSendTimeout(expected_timeout); + + long actual_timeout = client.getDefaultAsyncSendTimeout(); + if (actual_timeout != expected_timeout) { + throw new Exception("Test failed. getDefaultAsyncSendTimeout didn't return set value." + "Expecting " + + expected_timeout + "; got " + actual_timeout); + } + } + + /* + * @testName: getInstalledExtensionsTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:169; + * + * @test_Strategy: + */ + @Test + public void getInstalledExtensionsTest() throws Exception { + WebSocketContainer client = ContainerProvider.getWebSocketContainer(); + + Set extensions = client.getInstalledExtensions(); + if (extensions != null) { + if (!extensions.isEmpty()) { + for (Extension tmp : extensions) { + System.out.println("Installed Extension: " + tmp.getName()); + List params = tmp.getParameters(); + for (Parameter tmp1 : params) { + System.out.println( + "Parameter's name= " + tmp1.getName() + "Parameter's value= " + tmp1.getValue()); + } + } + } else { + System.out.println("Installed Extension returned empty set"); + } + } else { + System.out.println("getInstalledExtensions() returned null"); + } + } + + public void cleanup() { + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/TCKExtension.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/TCKExtension.java index 5c666557c2..6e6e353c6c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/TCKExtension.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/TCKExtension.java @@ -25,66 +25,62 @@ public class TCKExtension implements Extension { - private final String name; - - private final List parameters; - - public TCKExtension(String name) { - this(name, null); - } - - public TCKExtension(String name, List parameters) { - if (name == null || name.length() == 0) { - throw new IllegalArgumentException(); - } - - this.name = name; - if (parameters != null) { - this.parameters = Collections - .unmodifiableList(new ArrayList<>(parameters)); - } else { - this.parameters = Collections - .unmodifiableList(Collections. emptyList()); - } - } - - @Override - public String getName() { - return name; - } - - @Override - public List getParameters() { - return parameters; - } - - public static class TCKParameter implements Parameter { - - private final String name; - - private final String value; - - /** - * Create {@link Parameter} with name and value. - * - * @param name - * parameter name. - * @param value - * parameter value. - */ - public TCKParameter(String name, String value) { - this.name = name; - this.value = value; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getValue() { - return value; - } - } + private final String name; + + private final List parameters; + + public TCKExtension(String name) { + this(name, null); + } + + public TCKExtension(String name, List parameters) { + if (name == null || name.length() == 0) { + throw new IllegalArgumentException(); + } + + this.name = name; + if (parameters != null) { + this.parameters = Collections.unmodifiableList(new ArrayList<>(parameters)); + } else { + this.parameters = Collections.unmodifiableList(Collections.emptyList()); + } + } + + @Override + public String getName() { + return name; + } + + @Override + public List getParameters() { + return parameters; + } + + public static class TCKParameter implements Parameter { + + private final String name; + + private final String value; + + /** + * Create {@link Parameter} with name and value. + * + * @param name parameter name. + * @param value parameter value. + */ + public TCKParameter(String name, String value) { + this.name = name; + this.value = value; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getValue() { + return value; + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedByteBufferClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedByteBufferClientEndpoint.java index 6a7e0de0a0..24935e67d1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedByteBufferClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedByteBufferClientEndpoint.java @@ -21,11 +21,10 @@ /** * @since 1.11 */ -public class AnnotatedByteBufferClientEndpoint - extends AnnotatedClientEndpoint { +public class AnnotatedByteBufferClientEndpoint extends AnnotatedClientEndpoint { - public AnnotatedByteBufferClientEndpoint() { - super(new ByteBufferClientEndpoint()); - } + public AnnotatedByteBufferClientEndpoint() { + super(new ByteBufferClientEndpoint()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedClientEndpoint.java index a9c16420ba..1f0cf9a534 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedClientEndpoint.java @@ -43,41 +43,41 @@ */ public abstract class AnnotatedClientEndpoint { - protected ClientEndpoint clientEndpoint; + protected ClientEndpoint clientEndpoint; - public AnnotatedClientEndpoint(ClientEndpoint endpoint) { - this.clientEndpoint = endpoint; - } + public AnnotatedClientEndpoint(ClientEndpoint endpoint) { + this.clientEndpoint = endpoint; + } - // @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } + // @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } - // @OnMessage - public void onMessage(DATATYPE msg) { - clientEndpoint.onMessage(msg); - } + // @OnMessage + public void onMessage(DATATYPE msg) { + clientEndpoint.onMessage(msg); + } - // @OnClose - public void onClose(Session session, CloseReason closeReason) { - clientEndpoint.onClose(session, closeReason); - } + // @OnClose + public void onClose(Session session, CloseReason closeReason) { + clientEndpoint.onClose(session, closeReason); + } - // @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } + // @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } - public CountDownLatch getCountDownLatch() { - return ClientEndpoint.getCountDownLatch(); - } + public CountDownLatch getCountDownLatch() { + return ClientEndpoint.getCountDownLatch(); + } - public StringBuffer getMessageBuilder() { - return ClientEndpoint.getMessageBuilder(); - } + public StringBuffer getMessageBuilder() { + return ClientEndpoint.getMessageBuilder(); + } - public Throwable getLastError() { - return ClientEndpoint.getLastError(); - } + public Throwable getLastError() { + return ClientEndpoint.getLastError(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedStringClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedStringClientEndpoint.java index 9c21fd8a66..6fe37c1682 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedStringClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/AnnotatedStringClientEndpoint.java @@ -16,11 +16,10 @@ package com.sun.ts.tests.websocket.common.client; -public abstract class AnnotatedStringClientEndpoint - extends AnnotatedClientEndpoint { +public abstract class AnnotatedStringClientEndpoint extends AnnotatedClientEndpoint { - public AnnotatedStringClientEndpoint() { - super(new StringClientEndpoint()); - } + public AnnotatedStringClientEndpoint() { + super(new StringClientEndpoint()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ApacheRequestAdapter.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ApacheRequestAdapter.java index 6f31bd289a..a0c9881a89 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ApacheRequestAdapter.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ApacheRequestAdapter.java @@ -21,22 +21,19 @@ public class ApacheRequestAdapter extends HttpRequest { - public ApacheRequestAdapter(String protocol, String requestLine, String host, - int port) { - super( - "GET " + requestLine.replace(protocol + "://", "http://") + " HTTP/1.1", - host, port); - } + public ApacheRequestAdapter(String protocol, String requestLine, String host, int port) { + super("GET " + requestLine.replace(protocol + "://", "http://") + " HTTP/1.1", host, port); + } - /** - * getRequestPath returns the request path for this particular - * request. - * - * @return String request path - */ - @Override - public String getRequestPath() { - return super.getRequestPath(); - } + /** + * getRequestPath returns the request path for this particular + * request. + * + * @return String request path + */ + @Override + public String getRequestPath() { + return super.getRequestPath(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ApacheResponseAdapter.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ApacheResponseAdapter.java index 465df0cac2..54f0a4604d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ApacheResponseAdapter.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ApacheResponseAdapter.java @@ -26,56 +26,56 @@ public class ApacheResponseAdapter extends HttpResponse { - public ApacheResponseAdapter(String host, int port) { - super(host, port, port == 443, null, null); - this.caser = TextCaser.NONE; - } + public ApacheResponseAdapter(String host, int port) { + super(host, port, port == 443, null, null); + this.caser = TextCaser.NONE; + } - public ApacheResponseAdapter(String host, int port, TextCaser caser) { - this(host, port); - this.caser = caser; - } + public ApacheResponseAdapter(String host, int port, TextCaser caser) { + this(host, port); + this.caser = caser; + } - private TextCaser caser = null; + private TextCaser caser = null; - /** - * Simulates HTTP status code, 500 on error, 200 on ok - */ - @Override - public String getStatusCode() { - if (ClientEndpointData.getError() != null) - WebSocketTestCase.logMsg("Unexpected error on client endpoint:", - IOUtil.printStackTrace(ClientEndpointData.getError())); - return ClientEndpointData.getError() == null ? "200" : "500"; - } + /** + * Simulates HTTP status code, 500 on error, 200 on ok + */ + @Override + public String getStatusCode() { + if (ClientEndpointData.getError() != null) + WebSocketTestCase.logMsg("Unexpected error on client endpoint:", + IOUtil.printStackTrace(ClientEndpointData.getError())); + return ClientEndpointData.getError() == null ? "200" : "500"; + } - @Override - public String getResponseBodyAsString() throws IOException { - return caser.getCasedText(ClientEndpointData.getResponseAsString()); - } + @Override + public String getResponseBodyAsString() throws IOException { + return caser.getCasedText(ClientEndpointData.getResponseAsString()); + } - @Override - public String getResponseBodyAsRawString() throws IOException { - return getResponseBodyAsString(); - } + @Override + public String getResponseBodyAsRawString() throws IOException { + return getResponseBodyAsString(); + } - @Override - public String getReasonPhrase() { - return null; - } + @Override + public String getReasonPhrase() { + return null; + } - @Override - public Header[] getResponseHeaders() { - return new Header[0]; - } + @Override + public Header[] getResponseHeaders() { + return new Header[0]; + } - @Override - public Header getResponseHeader(String headerName) { - return null; - } + @Override + public Header getResponseHeader(String headerName) { + return null; + } - @Override - public String getResponseEncoding() { - return null; - } + @Override + public String getResponseEncoding() { + return null; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/BinaryAndTextClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/BinaryAndTextClientEndpoint.java index a14d630286..bf4ef35bac 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/BinaryAndTextClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/BinaryAndTextClientEndpoint.java @@ -30,15 +30,15 @@ * behaves without making any difference on type of message received. */ public class BinaryAndTextClientEndpoint extends ClientEndpoint { - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - session.addMessageHandler(new MessageHandler.Whole() { - @Override - public void onMessage(ByteBuffer message) { - String msg = IOUtil.byteBufferToString(message); - BinaryAndTextClientEndpoint.this.onMessage(msg); - } - }); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + session.addMessageHandler(new MessageHandler.Whole() { + @Override + public void onMessage(ByteBuffer message) { + String msg = IOUtil.byteBufferToString(message); + BinaryAndTextClientEndpoint.this.onMessage(msg); + } + }); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ByteBufferClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ByteBufferClientEndpoint.java index 66067b027b..da1b853a25 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ByteBufferClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ByteBufferClientEndpoint.java @@ -22,8 +22,8 @@ public class ByteBufferClientEndpoint extends ClientEndpoint { - @Override - protected void appendMessage(ByteBuffer message) { - getMessageBuilder().append(IOUtil.byteBufferToString(message)); - } + @Override + protected void appendMessage(ByteBuffer message) { + getMessageBuilder().append(IOUtil.byteBufferToString(message)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ClientEndpoint.java index c8c9eca7a7..8bcab4a0fd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/ClientEndpoint.java @@ -28,188 +28,182 @@ import jakarta.websocket.Session; import jakarta.websocket.WebSocketContainer; -public abstract class ClientEndpoint extends Endpoint - implements MessageHandler.Whole { - - /** - * This structure is static, because the original API was unable to set an - * instance of endpoint when connecting to server, the only available option - * as an argument of - * {@link WebSocketContainer#connectToServer(Class, ClientEndpointConfig, java.net.URI)} - * was Class. The instance of endpoint was created by websocket API, and no - * information could be injected into the instance. - */ - public static class ClientEndpointData { - protected static volatile StringBuffer sb = new StringBuffer(); - - protected static volatile Throwable websocketError = null; - - protected static EndpointCallback callback; - - protected static volatile CountDownLatch messageLatch; - - protected static volatile Object lastMessage = null; - - protected static final Object LOCK = new Object(); - - protected static volatile CountDownLatch onCloseLatch = null; - - public static Throwable getError() { - return websocketError; - } - - private static void setError(Throwable error) { - websocketError = error; - } - - public static String getResponseAsString() { - WebSocketTestCase.logMsg("Response:", sb.toString()); - return sb.toString(); - } - - public static void resetData() { - synchronized (LOCK) { - WebSocketCommonClient.logTrace("Reseting callback and message", ""); - sb = new StringBuffer(); - websocketError = null; - callback = null; - lastMessage = null; - messageLatch = null; - onCloseLatch = null; - } - } - - public static void newCountDown(int count) { - messageLatch = new CountDownLatch(count); - }; - - public static void awaitCountDown(int seconds) { - try { - messageLatch.await(seconds, TimeUnit.SECONDS); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - - public static void newOnCloseCountDown() { - if (onCloseLatch == null) - onCloseLatch = new CountDownLatch(1); - } - - public static long getCount() { - return messageLatch.getCount(); - } - - public static void awaitOnClose() { - try { - onCloseLatch.await(2000L, TimeUnit.SECONDS); - } catch (InterruptedException e) { - e.printStackTrace(); // If it does not wait, - // the test should still pass - } - } - - public static Object getOriginalMessage() { - return lastMessage; - } - - private static void setOriginalMessage(Object message) { - lastMessage = message; - } - - } - - /** - * Hopefully this approach might be changed when api allows for passing the - * instance instead of class. - */ - - @Override - public void onOpen(Session session, EndpointConfig config) { - onOpen(session, config, true); - } - - public void onOpen(Session session, EndpointConfig config, - boolean addMessageHandler) { - WebSocketCommonClient.logTrace("On open on session id", session.getId()); - String uri = session.getRequestURI() == null ? "NULL" - : session.getRequestURI().toASCIIString(); - WebSocketCommonClient.logTrace("RequestUri:", uri); - if (session.isOpen()) { - if (addMessageHandler) - session.addMessageHandler(this); - } else - WebSocketCommonClient.logTrace("Session is closed!!!!", ""); - synchronized (ClientEndpointData.LOCK) { - if (ClientEndpointData.callback != null && session.isOpen()) - ClientEndpointData.callback.onOpen(session, config); - } - } - - @Override - public void onError(Session session, Throwable t) { - ClientEndpointData.setError(t); - t.printStackTrace(); - synchronized (ClientEndpointData.LOCK) { - if (ClientEndpointData.callback != null) - ClientEndpointData.callback.onError(session, t); - } - } - - protected void appendMessage(T message) { - ClientEndpointData.sb.append(message.toString()); - } - - @Override - public void onMessage(T message) { - ClientEndpointData.setOriginalMessage(message); - appendMessage(message); - WebSocketCommonClient.logTrace("Received message so far", - ClientEndpointData.sb.toString()); - synchronized (ClientEndpointData.LOCK) { - if (ClientEndpointData.callback != null) - ClientEndpointData.callback.onMessage(message); - } - WebSocketTestCase.logTrace("CountDownLatch hit"); - if (ClientEndpointData.messageLatch.getCount() == 0) - throw new IllegalStateException("CountDownLatch.getCount == 0 already"); - ClientEndpointData.messageLatch.countDown(); - } - - @Override - public void onClose(Session session, CloseReason closeReason) { - synchronized (ClientEndpointData.LOCK) { - WebSocketTestCase.logTrace("On close on session id", session.getId(), - "reason", closeReason); - if (ClientEndpointData.lastMessage == null) - WebSocketTestCase - .logTrace("onClose has been called before a message was received"); - else - WebSocketTestCase.logTrace("onClose has been called"); - if (ClientEndpointData.callback != null) - ClientEndpointData.callback.onClose(session, closeReason); - // onCloseLatch == null when close has not been called by client - if (ClientEndpointData.onCloseLatch == null) - ClientEndpointData.newOnCloseCountDown(); - ClientEndpointData.onCloseLatch.countDown(); - } - } - - public static CountDownLatch getCountDownLatch() { - return ClientEndpointData.messageLatch; - } - - public static StringBuffer getMessageBuilder() { - return ClientEndpointData.sb; - } - - @SuppressWarnings({ "unchecked", "unused" }) - public T getLastMessage(Class messageType) { - return (T) ClientEndpointData.lastMessage; - } - - public static Throwable getLastError() { - return ClientEndpointData.websocketError; - } +public abstract class ClientEndpoint extends Endpoint implements MessageHandler.Whole { + + /** + * This structure is static, because the original API was unable to set an + * instance of endpoint when connecting to server, the only available option as + * an argument of + * {@link WebSocketContainer#connectToServer(Class, ClientEndpointConfig, java.net.URI)} + * was Class. The instance of endpoint was created by websocket API, and no + * information could be injected into the instance. + */ + public static class ClientEndpointData { + protected static volatile StringBuffer sb = new StringBuffer(); + + protected static volatile Throwable websocketError = null; + + protected static EndpointCallback callback; + + protected static volatile CountDownLatch messageLatch; + + protected static volatile Object lastMessage = null; + + protected static final Object LOCK = new Object(); + + protected static volatile CountDownLatch onCloseLatch = null; + + public static Throwable getError() { + return websocketError; + } + + private static void setError(Throwable error) { + websocketError = error; + } + + public static String getResponseAsString() { + WebSocketTestCase.logMsg("Response:", sb.toString()); + return sb.toString(); + } + + public static void resetData() { + synchronized (LOCK) { + WebSocketCommonClient.logTrace("Reseting callback and message", ""); + sb = new StringBuffer(); + websocketError = null; + callback = null; + lastMessage = null; + messageLatch = null; + onCloseLatch = null; + } + } + + public static void newCountDown(int count) { + messageLatch = new CountDownLatch(count); + }; + + public static void awaitCountDown(int seconds) { + try { + messageLatch.await(seconds, TimeUnit.SECONDS); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + public static void newOnCloseCountDown() { + if (onCloseLatch == null) + onCloseLatch = new CountDownLatch(1); + } + + public static long getCount() { + return messageLatch.getCount(); + } + + public static void awaitOnClose() { + try { + onCloseLatch.await(2000L, TimeUnit.SECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); // If it does not wait, + // the test should still pass + } + } + + public static Object getOriginalMessage() { + return lastMessage; + } + + private static void setOriginalMessage(Object message) { + lastMessage = message; + } + + } + + /** + * Hopefully this approach might be changed when api allows for passing the + * instance instead of class. + */ + + @Override + public void onOpen(Session session, EndpointConfig config) { + onOpen(session, config, true); + } + + public void onOpen(Session session, EndpointConfig config, boolean addMessageHandler) { + WebSocketCommonClient.logTrace("On open on session id", session.getId()); + String uri = session.getRequestURI() == null ? "NULL" : session.getRequestURI().toASCIIString(); + WebSocketCommonClient.logTrace("RequestUri:", uri); + if (session.isOpen()) { + if (addMessageHandler) + session.addMessageHandler(this); + } else + WebSocketCommonClient.logTrace("Session is closed!!!!", ""); + synchronized (ClientEndpointData.LOCK) { + if (ClientEndpointData.callback != null && session.isOpen()) + ClientEndpointData.callback.onOpen(session, config); + } + } + + @Override + public void onError(Session session, Throwable t) { + ClientEndpointData.setError(t); + t.printStackTrace(); + synchronized (ClientEndpointData.LOCK) { + if (ClientEndpointData.callback != null) + ClientEndpointData.callback.onError(session, t); + } + } + + protected void appendMessage(T message) { + ClientEndpointData.sb.append(message.toString()); + } + + @Override + public void onMessage(T message) { + ClientEndpointData.setOriginalMessage(message); + appendMessage(message); + WebSocketCommonClient.logTrace("Received message so far", ClientEndpointData.sb.toString()); + synchronized (ClientEndpointData.LOCK) { + if (ClientEndpointData.callback != null) + ClientEndpointData.callback.onMessage(message); + } + WebSocketTestCase.logTrace("CountDownLatch hit"); + if (ClientEndpointData.messageLatch.getCount() == 0) + throw new IllegalStateException("CountDownLatch.getCount == 0 already"); + ClientEndpointData.messageLatch.countDown(); + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + synchronized (ClientEndpointData.LOCK) { + WebSocketTestCase.logTrace("On close on session id", session.getId(), "reason", closeReason); + if (ClientEndpointData.lastMessage == null) + WebSocketTestCase.logTrace("onClose has been called before a message was received"); + else + WebSocketTestCase.logTrace("onClose has been called"); + if (ClientEndpointData.callback != null) + ClientEndpointData.callback.onClose(session, closeReason); + // onCloseLatch == null when close has not been called by client + if (ClientEndpointData.onCloseLatch == null) + ClientEndpointData.newOnCloseCountDown(); + ClientEndpointData.onCloseLatch.countDown(); + } + } + + public static CountDownLatch getCountDownLatch() { + return ClientEndpointData.messageLatch; + } + + public static StringBuffer getMessageBuilder() { + return ClientEndpointData.sb; + } + + @SuppressWarnings({ "unchecked", "unused" }) + public T getLastMessage(Class messageType) { + return (T) ClientEndpointData.lastMessage; + } + + public static Throwable getLastError() { + return ClientEndpointData.websocketError; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/EndpointCallback.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/EndpointCallback.java index ab17e6d072..a99f76ba75 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/EndpointCallback.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/EndpointCallback.java @@ -32,36 +32,35 @@ * interface with {@link MessageHandler} interface. *

* Depending on what {@link WebSocketCommonClient.Entity} is defined (partial, - * whole), {@link Whole} or {@link Partial} functionality is used - * with onMessage + * whole), {@link Whole} or {@link Partial} functionality is used with onMessage */ public class EndpointCallback { - @SuppressWarnings("unused") - public void onError(Session session, Throwable t) { - } + @SuppressWarnings("unused") + public void onError(Session session, Throwable t) { + } - @SuppressWarnings("unused") - public void onMessage(Object o) { - } + @SuppressWarnings("unused") + public void onMessage(Object o) { + } - @SuppressWarnings("unused") - public void onOpen(Session session, EndpointConfig config) { - } + @SuppressWarnings("unused") + public void onOpen(Session session, EndpointConfig config) { + } - @SuppressWarnings("unused") - public void onClose(Session session, CloseReason closeReason) { - } + @SuppressWarnings("unused") + public void onClose(Session session, CloseReason closeReason) { + } - public CountDownLatch getCountDownLatch() { - return ClientEndpoint.getCountDownLatch(); - } + public CountDownLatch getCountDownLatch() { + return ClientEndpoint.getCountDownLatch(); + } - public StringBuffer getMessageBuilder() { - return ClientEndpoint.getMessageBuilder(); - } + public StringBuffer getMessageBuilder() { + return ClientEndpoint.getMessageBuilder(); + } - public Throwable getLastError() { - return ClientEndpoint.getLastError(); - } + public Throwable getLastError() { + return ClientEndpoint.getLastError(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/SendMessageCallback.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/SendMessageCallback.java index 025b37b0a3..98f6e5812e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/SendMessageCallback.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/SendMessageCallback.java @@ -46,87 +46,83 @@ * server side */ public class SendMessageCallback extends EndpointCallback { - protected Entity entity; + protected Entity entity; - public SendMessageCallback(Entity entity) { - super(); - this.entity = entity; - } + public SendMessageCallback(Entity entity) { + super(); + this.entity = entity; + } - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - logMsg("Sending entity", entity); - RemoteEndpoint.Basic endpoint = session.getBasicRemote(); - try { - if (entity.isInstance(String.class)) - sendString(endpoint, entity, 0); - else if (entity.isInstance(ByteBuffer.class)) - sendBytes(endpoint, entity, 0); - else if (entity.isInstance(PongMessage.class)) - sendPingPong(endpoint, entity.getEntityAt(PongMessage.class, 0)); - else - sendObject(endpoint, entity.getEntityAt(Object.class, 0)); - } catch (Exception i) { - throw new RuntimeException(i); - } - } + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + logMsg("Sending entity", entity); + RemoteEndpoint.Basic endpoint = session.getBasicRemote(); + try { + if (entity.isInstance(String.class)) + sendString(endpoint, entity, 0); + else if (entity.isInstance(ByteBuffer.class)) + sendBytes(endpoint, entity, 0); + else if (entity.isInstance(PongMessage.class)) + sendPingPong(endpoint, entity.getEntityAt(PongMessage.class, 0)); + else + sendObject(endpoint, entity.getEntityAt(Object.class, 0)); + } catch (Exception i) { + throw new RuntimeException(i); + } + } - protected void sendString(RemoteEndpoint.Basic endpoint, Entity entity, - int index) throws IOException { - String message = entity.getEntityAt(String.class, index); - if (entity.length() - 1 > index) { - endpoint.sendText(message, false); - logTrace("RemoteEndpoint.Basic.sendText(", message, ", false)"); - sendString(endpoint, entity, index + 1); - } else if (index > 0) { - endpoint.sendText(message, true); - logTrace("RemoteEndpoint.Basic.sendText(", message, ", true)"); - } else { - endpoint.sendText(message); - logTrace("RemoteEndpoint.Basic.sendText(", message, ")"); - } - } + protected void sendString(RemoteEndpoint.Basic endpoint, Entity entity, int index) throws IOException { + String message = entity.getEntityAt(String.class, index); + if (entity.length() - 1 > index) { + endpoint.sendText(message, false); + logTrace("RemoteEndpoint.Basic.sendText(", message, ", false)"); + sendString(endpoint, entity, index + 1); + } else if (index > 0) { + endpoint.sendText(message, true); + logTrace("RemoteEndpoint.Basic.sendText(", message, ", true)"); + } else { + endpoint.sendText(message); + logTrace("RemoteEndpoint.Basic.sendText(", message, ")"); + } + } - protected void sendBytes(RemoteEndpoint.Basic endpoint, Entity entity, - int index) throws IOException { - ByteBuffer msg = entity.getEntityAt(ByteBuffer.class, index); - String bytes = new String(msg.array()); - if (entity.length() - 1 > index) { - endpoint.sendBinary(msg, false); - logTrace("RemoteEndpoint.Basic.sendBinary(", bytes, ", false)"); - sendBytes(endpoint, entity, index + 1); - } else if (index > 0) { - endpoint.sendBinary(msg, true); - logTrace("RemoteEndpoint.Basic.sendBinary(", bytes, ", true)"); - } else { - endpoint.sendBinary(msg); - logTrace("RemoteEndpoint.Basic.sendBinary(", bytes, ")"); - } - } + protected void sendBytes(RemoteEndpoint.Basic endpoint, Entity entity, int index) throws IOException { + ByteBuffer msg = entity.getEntityAt(ByteBuffer.class, index); + String bytes = new String(msg.array()); + if (entity.length() - 1 > index) { + endpoint.sendBinary(msg, false); + logTrace("RemoteEndpoint.Basic.sendBinary(", bytes, ", false)"); + sendBytes(endpoint, entity, index + 1); + } else if (index > 0) { + endpoint.sendBinary(msg, true); + logTrace("RemoteEndpoint.Basic.sendBinary(", bytes, ", true)"); + } else { + endpoint.sendBinary(msg); + logTrace("RemoteEndpoint.Basic.sendBinary(", bytes, ")"); + } + } - protected void sendPingPong(RemoteEndpoint.Basic endpoint, PongMessage pong) - throws Exception { - ByteBuffer buffer = pong.getApplicationData(); - String msg = IOUtil.byteBufferToString(buffer); - if (StringPingMessage.class.isInstance(pong)) { - endpoint.sendPing(buffer); - logTrace("RemoteEndpoint.Basic.sendPing(", msg, ")"); - } else { - endpoint.sendPong(buffer); - logTrace("RemoteEndpoint.Basic.sendPong(", msg, ")"); - } - } + protected void sendPingPong(RemoteEndpoint.Basic endpoint, PongMessage pong) throws Exception { + ByteBuffer buffer = pong.getApplicationData(); + String msg = IOUtil.byteBufferToString(buffer); + if (StringPingMessage.class.isInstance(pong)) { + endpoint.sendPing(buffer); + logTrace("RemoteEndpoint.Basic.sendPing(", msg, ")"); + } else { + endpoint.sendPong(buffer); + logTrace("RemoteEndpoint.Basic.sendPong(", msg, ")"); + } + } - protected void sendObject(RemoteEndpoint.Basic endpoint, Object message) - throws Exception { - String entity = null; - if (message.getClass().getName().equals("[B")) - entity = new String((byte[]) message); - else - entity = message.toString(); - logTrace("RemoteEndpoint.Basic.sendObject(", entity, ")"); - endpoint.sendObject(message); - } + protected void sendObject(RemoteEndpoint.Basic endpoint, Object message) throws Exception { + String entity = null; + if (message.getClass().getName().equals("[B")) + entity = new String((byte[]) message); + else + entity = message.toString(); + logTrace("RemoteEndpoint.Basic.sendObject(", entity, ")"); + endpoint.sendObject(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/TextCaser.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/TextCaser.java index d1348d5f29..4fc964dc08 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/TextCaser.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/TextCaser.java @@ -22,26 +22,26 @@ * in order and case insensitive, this class is used. */ public enum TextCaser { - UPPER, NONE, LOWER; + UPPER, NONE, LOWER; - /** - * Get the text upper cased, lower cased, or unchanged, depending on current - * TextCaser value - */ - public final String getCasedText(String text) { - String ret = null; - switch (this) { - case UPPER: - ret = text.toUpperCase(); - break; - case LOWER: - ret = text.toLowerCase(); - break; - case NONE: - ret = text; - break; - } - return ret; - } + /** + * Get the text upper cased, lower cased, or unchanged, depending on current + * TextCaser value + */ + public final String getCasedText(String text) { + String ret = null; + switch (this) { + case UPPER: + ret = text.toUpperCase(); + break; + case LOWER: + ret = text.toLowerCase(); + break; + case NONE: + ret = text; + break; + } + return ret; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/WebSocketCommonClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/WebSocketCommonClient.java index 7ca9b451d5..eba9283263 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/WebSocketCommonClient.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/WebSocketCommonClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -17,9 +17,12 @@ package com.sun.ts.tests.websocket.common.client; +import java.io.BufferedReader; import java.io.IOException; -import java.io.PrintWriter; +import java.io.InputStream; +import java.io.InputStreamReader; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Enumeration; import java.util.HashMap; @@ -27,9 +30,8 @@ import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.stream.Collectors; -import com.sun.javatest.Status; -import com.sun.ts.lib.harness.ServiceEETest; import com.sun.ts.lib.util.BASE64Encoder; import com.sun.ts.lib.util.TestUtil; import com.sun.ts.tests.common.webclient.TestFailureException; @@ -45,1085 +47,943 @@ /** * The common client that contains common methods */ -public abstract class WebSocketCommonClient extends ServiceEETest { - - private static final long serialVersionUID = 1L; - - /** - * The property that is set after invoke(), to let know the cleanup of - * previous test should be performed so that more invocations are possible - */ - boolean isTestCaseAfterInvocation; - - /** - * TS Webserver host property - */ - protected static final String SERVLETHOSTPROP = "webServerHost"; - - /** - * TS Webserver port property - */ - protected static final String SERVLETPORTPROP = "webServerPort"; - - /** - * TS home property - */ - protected static final String TSHOME = "ts_home"; - - /** - * Single invocation incremental test properties - */ - protected Hashtable TEST_PROPS; - - /** - * Context root of target tests - */ - protected String _contextRoot = null; - - /** - * Target webserver hostname - */ - protected String _hostname = null; - - /** - * Target webserver port - */ - protected int _port = 0; - - /** - * The protocol to be used for invoking a request, ws, wss, http, https, ... - */ - protected String requestProtocol = "ws"; - - /** - * location of _tsHome - */ - protected String _tsHome = null; - - /** - * Property from ts.jte - */ - protected int _ws_wait = 0; - - /** - * The test case of given specified websocket message type - */ - protected WebSocketTestCase testCase; - - /** - * disable logging stack trace of exception caused on invoke() for the tests - * that expects the exception to be thrown - */ - protected boolean logExceptionOnInvoke = true; - - /** - * Entity of type T, where T is the type of WebSocketTestCase, e.g. String by - * default. As websocket supports partial messages, this Entity is an array of - * objects; For whole message, only one Object in the array is used. When more - * objects are utilized, partial message is being sent. - */ - public class Entity { - private Object[] entities; - - public Entity(Object... partials) { - entities = partials; - } - - public Entity(Object entity) { - this(new Object[] { entity }); - } - - public boolean isInstance(Class clazz) { - return clazz.isInstance(entities[0]); - } - - public int length() { - return entities.length; - } - - @SuppressWarnings("unchecked") - public T getEntityAt(Class clazz, int index) { - if (ByteBuffer.class.isAssignableFrom(clazz)) - return (T) cloneByteBuffer(index); - return (T) entities[index]; - } - - @SuppressWarnings("unchecked") - public T getEntityAt(int index) { - if (ByteBuffer.class.isInstance(entities[index])) - return (T) cloneByteBuffer(index); - return (T) entities[index]; - } - - private ByteBuffer clone(ByteBuffer message) { - byte[] orig = message.array(); - byte[] array = new byte[orig.length]; - System.arraycopy(orig, 0, array, 0, orig.length); - return ByteBuffer.wrap(array); - } - - private ByteBuffer cloneByteBuffer(int index) { - ByteBuffer bb = (ByteBuffer) entities[index]; - return clone(bb); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(entities.length); - if (entities.length == 1) - sb.append(" part: "); - else - sb.append(" parts: "); - sb.append(objectsToStringWithDelimiter(", ", entities)); - return sb.toString(); - } - } - - protected Entity entity; - - /** - * the list of properties to be put into a property table - */ - protected enum Property { - BASIC_AUTH_PASSWD, BASIC_AUTH_USER, // - CONTENT, EXPECTED_HEADERS, // - IGNORE_STATUS_CODE, REQUEST, // - SEARCH_STRING, SEARCH_STRING_IGNORE_CASE, STATUS_CODE, // - UNEXPECTED_HEADERS, UNEXPECTED_RESPONSE_MATCH, // - UNORDERED_SEARCH_STRING; - } - - // //////////////////////////////////////////////////////////////////////// - public String getContextRoot() { - return _contextRoot; - } - - public void setContextRoot(String root) { - TestUtil.logTrace("[WebSocketCommonClient] Contextroot set at " + root); - _contextRoot = root; - } - - /** - * Set property values to a given key if none exists, or adds all property - * values to a given key when one exists, unless the property is a content - */ - protected void setProperty(Property key, String... values) { - for (String singleValue : values) - setProperty(key, singleValue); - } - - /** - * Set property value to a given key if none exists, or adds a property value - * to a given key when one exists, unless the property is a content. When - * content, only the last single content is sent as a part of request - */ - protected void setProperty(Property key, String value) { - switch (key) { - case CONTENT: - setEntity(value); - break; - default: - String oldValue = TEST_PROPS.get(key); - if (oldValue == null) { - TEST_PROPS.put(key, value); - } else { - int len = value.length() + oldValue.length() + 1; - StringBuilder combinedValue = new StringBuilder(len); - combinedValue.append(oldValue).append("|").append(value); - TEST_PROPS.put(key, combinedValue.toString()); - } - break; - } - } - - protected String buildRequest(String... path) { - StringBuilder sb = new StringBuilder(); - sb.append(getAbsoluteUrl()).append("/"); - for (String segment : path) - sb.append(segment); - return sb.toString(); - } - - protected String getAbsoluteUrl() { - StringBuilder sb = new StringBuilder(); - sb.append(requestProtocol).append("://").append(_hostname).append(":") - .append(_port).append("/").append(getContextRoot()); - return sb.toString(); - } - - /** - * Shortcut to invoke() when endpoint, content, and search is known - * - * @param endpoint - * the endpoint the request is built to go to. - * @param content - * the content to be set as setEntity(content.name()) - * @param search - * a response would be searched for search.name() - * @throws Exception - * when invocation fails - */ - protected > // - void invoke(String endpoint, Enum content, Enum search) throws Exception { - invoke(endpoint, content.name(), search.name()); - } - - /** - * Shortcut to invoke() when endpoint, content, and search is known - * - * @param endpoint - * the endpoint the request is built to go to. - * @param content - * the content to be set as setEntity(content.name()) - * @param search - * a String the response would be searched for - * @throws Exception - * when invocation fails - */ - protected// - void invoke(String endpoint, Enum content, String... search) throws Exception { - invoke(endpoint, content.name(), search); - } - - /** - * Shortcut to invoke() when endpoint, content, and search is known - * - * @param endpoint - * the endpoint the request is built to go to. - * @param content - * the content to be set as setEntity(content) - * @param search - * the content of a response to be searched, or "" when does not - * matter - * @throws Exception - * when invocation fails - */ - protected void // - invoke(String endpoint, Object content, String... search) throws Exception { - invoke(endpoint, content, search, true); - } - - /** - * Shortcut to invoke() when endpoint, content, and search is known - * - * @param endpoint - * the endpoint the request is built to go to. - * @param content - * the content to be set as setEntity(content) - * @param search - * the content of a response to be searched, or "" when does not - * matter - * @param cleanup - * see {@link #invoke(boolean)} - * @throws Exception - * when invocation fails - */ - protected void // - invoke(String endpoint, Object content, String[] search, boolean cleanup) - throws Exception { - setProperty(Property.REQUEST, buildRequest(endpoint)); - setEntity(content); - setProperty(Property.SEARCH_STRING, search); - invoke(cleanup); - } - - protected void // - invoke(String endpoint, Object content, String search, boolean cleanup) - throws Exception { - invoke(endpoint, content, new String[] { search }, cleanup); - } - - /** - * Shortcut to invokeAgain(cleanup) when endpoint, content, and search is - * known - * - * @param content - * the content to be set as setEntity(content) - * @param search - * the content of a response to be searched, or "" when does not - * matter - * @param cleanup - * see {@link #invokeAgain(boolean)} - * @throws Exception - * when invocation fails - */ - protected void // - invokeAgain(Object content, String search, boolean cleanup) throws Exception { - setEntity(content); - setProperty(Property.SEARCH_STRING, search); - invokeAgain(cleanup); - } - - /** - *
-   * Invokes a test based on the properties
-   * stored in TEST_PROPS.  Once the test has completed,
-   * the properties in TEST_PROPS will be cleared.
-   * 
- * - * @throws Exception - * If an error occurs during the test run - */ - protected void invoke() throws Exception { - invoke(true); - } - - /** - *
-   * Invokes a test based on the properties
-   * stored in TEST_PROPS.  Once the test has completed,
-   * the properties in TEST_PROPS will be cleared if cleanUp says so.
-   * 
- * - * @throws Exception - * If an error occurs during the test run - * @param cleanUp - * Defines whether the test has ended - * - */ - protected void invoke(boolean cleanUp) throws Exception { - invoke(cleanUp, false); - } - - /** - * Invoke additional request with new entity and hold open - * {@link jakarta.websocket.Session} to a server {@link Endpoint}, the response - * is caught by client {@link Endpoint} set by current - * {@link WebSocketTestCase} - *

- * - * @throws Exception - */ - protected void invokeAgain(boolean cleanUp) throws Exception { - invoke(cleanUp, true); - } - - /** - *

-   * Invokes a test based on the properties
-   * stored in TEST_PROPS. The current session is used. Once the test has completed,
-   * the properties in TEST_PROPS will be cleared if cleanUp says so.
-   * 
- * - * @throws Exception - * If an error occurs during the test run - * @param cleanUp - * Defines whether the test has ended - * @param again - * the request to server endpoint is performed on currently - * established session, when the session has not been closed after - * previous {@link #invoke(false)}; - */ - protected void invoke(boolean cleanUp, boolean again) throws Exception { - TestUtil.logTrace("[WebSocketCommonClient] invoke"); - TestUtil.logTrace("[WebSocketCommonClient] EXECUTING"); - setTestProperties(getTestCase()); - try { - executeTestCase(again); - testCase.validate(); - assertCountDownLatchCount(); - } catch (TestFailureException tfe) { - dealWithTestFailureException(tfe); - } finally { - isTestCaseAfterInvocation = cleanUp; - if (cleanUp) { - cleanup(); - } - } - } - - /** - * Executes test case for the first time, or once again on existing - * {@link WebSocketTestCase} and existing {@link Session} for a new - * {@link Entity} - * - * @param again - * @throws TestFailureException - */ - protected// - void executeTestCase(boolean again) throws TestFailureException, Exception { - if (again) { - testCase.newCountDown(); - SendMessageCallback callback = new SendMessageCallback(entity); - callback.onOpen(getSession(), null); - testCase.awaitCountDown(); - } else - testCase.execute(); - } - - private// - void dealWithTestFailureException(TestFailureException tfe) throws Exception { - Throwable t = tfe.getRootCause(); - if (t != null && logExceptionOnInvoke) { - TestUtil.logErr("Root cause of Failure: " + t.getMessage(), t); - } else - logExceptionOnInvoke = true; - fault(tfe, "[WebSocketCommonClient]", sTestCase, - "failed! Check output for cause of failure."); - } - - /** - *
-   * Sets the appropriate test properties based
-   * on the values stored in TEST_PROPS
-   * 
- */ - protected void setTestProperties(WebSocketTestCase testCase) { - TestUtil.logTrace("[WebSocketCommonClient] setTestProperties"); - - if (TEST_PROPS.get(Property.STATUS_CODE) == null) - setProperty(Property.STATUS_CODE, "200"); - setWebTestCaseProperties(testCase); - } - - protected void setWebTestCaseProperties(WebSocketTestCase testCase) { - Property key = null; - String value = null; - // process the remainder of the properties - for (Enumeration e = TEST_PROPS.keys(); e.hasMoreElements();) { - key = e.nextElement(); - value = TEST_PROPS.get(key); - switch (key) { - case BASIC_AUTH_USER: - break; - case BASIC_AUTH_PASSWD: - final String user = TEST_PROPS.get(Property.BASIC_AUTH_USER); - final String password = TEST_PROPS.get(Property.BASIC_AUTH_PASSWD); - Configurator configurator = new Configurator() { - @Override - public void beforeRequest(Map> headers) { - headers.putAll(basicAuthenticationAsHeaderMap(user, password)); - super.beforeRequest(headers); - } - }; - addClientConfigurator(configurator); - break; - case CONTENT: - setEntity(value); - break; - case EXPECTED_HEADERS: - testCase.addExpectedHeader(value); - TEST_PROPS.remove(Property.EXPECTED_HEADERS); - break; - case IGNORE_STATUS_CODE: - testCase.setExpectedStatusCode("-1"); - break; - case REQUEST: - break; - case SEARCH_STRING: - value = testCase.getTextCaser().getCasedText(value); - testCase.setResponseSearchString(value); - TEST_PROPS.remove(Property.SEARCH_STRING); - break; - case SEARCH_STRING_IGNORE_CASE: - testCase.setResponseSearchStringIgnoreCase(value); - TEST_PROPS.remove(Property.SEARCH_STRING_IGNORE_CASE); - break; - case STATUS_CODE: - if (value.contains("|")) - testCase.setStrategy( - CheckOneOfStatusesTokenizedValidator.class.getName()); - testCase.setExpectedStatusCode(value); - break; - case UNEXPECTED_HEADERS: - testCase.addUnexpectedHeader(value); - TEST_PROPS.remove(Property.UNEXPECTED_HEADERS); - break; - case UNEXPECTED_RESPONSE_MATCH: - testCase.setUnexpectedResponseSearchString(value); - TEST_PROPS.remove(Property.UNEXPECTED_RESPONSE_MATCH); - break; - case UNORDERED_SEARCH_STRING: - value = testCase.getTextCaser().getCasedText(value); - testCase.setUnorderedSearchString(value); - TEST_PROPS.remove(Property.UNORDERED_SEARCH_STRING); - break; - } - } - } - - protected WebSocketTestCase getTestCase() { - if (testCase == null || isTestCaseAfterInvocation) { - testCase = new WebSocketTestCase(this); - isTestCaseAfterInvocation = false; - } - return testCase; - } - - protected // - void setEndPointCase(Class> endpoint) { - getTestCase().setClientEndpoint(endpoint); - } - - protected Entity setEntity(Object... partials) { - this.entity = new Entity(partials); - return this.entity; - } - - // /////////////////////////// JavaTest methods /////////////////////////// - /** - * This pattern is used in all subclasses - */ - protected Status run(String[] args) { - Status s; - s = run(args, new PrintWriter(System.out), new PrintWriter(System.err)); - s.exit(); - return s; - } - - /** - * cleanup is called by the test harness to cleanup after text - * execution - * - * @exception Fault - * if an error occurs - */ - public void cleanup() throws Exception { - TEST_PROPS.clear(); - isTestCaseAfterInvocation = true; - try { - if (testCase != null && testCase.session != null) { - if (testCase.session.isOpen()) { - ClientEndpointData.newOnCloseCountDown(); - logTrace("[WebSocketCommonClient] session.close() on session id", - testCase.session.getId()); - testCase.session.close(); - ClientEndpointData.awaitOnClose(); - } - testCase.session = null; - } - synchronized (ClientEndpointData.LOCK) { - ClientEndpointData.callback = null; - } - } catch (IOException e) { - fault(e); - } - TestUtil.logMsg("[WebSocketCommonClient] Test cleanup OK"); - } - - /** - * setup is by the test harness to initialize the tests. - * - * @param args - * a String[] value - * @param p - * a Properties value - * @exception Fault - * if an error occurs - */ - public void setup(String[] args, Properties p) throws Exception { - TestUtil.logTrace("setup method WebSocketCommonClient"); - - String hostname = p.getProperty(SERVLETHOSTPROP); - String portnum = p.getProperty(SERVLETPORTPROP); - String tshome = p.getProperty(TSHOME); - String wswait = p.getProperty("ws_wait"); - - assertFalse(isNullOrEmpty(hostname), - "[WebSocketCommonClient] 'webServerHost' was not set in the build.properties."); - _hostname = hostname.trim(); - assertFalse(isNullOrEmpty(portnum), - "[WebSocketCommonClient] 'webServerPort' was not set in the build.properties."); - _port = Integer.parseInt(portnum.trim()); - assertFalse(isNullOrEmpty(tshome), - "[WebSocketCommonClient] 'tshome' was not set in the build.properties."); - _tsHome = tshome.trim(); - assertFalse(isNullOrEmpty(wswait), - "[WebSocketCommonClient] 'ws_wait' must be set in ts.jte"); - _ws_wait = Integer.parseInt(wswait.trim()); - assertTrue(_ws_wait > 0, - "[WebSocketCommonClient] 'ws_wait' (in seconds) ts.jte must be set greater than 0"); - - TestUtil.logMsg("[WebSocketCommonClient] Test setup OK"); - TEST_PROPS = new Hashtable<>(); - } - - // ///////////////////////////// Utility methods - // ////////////////////////////// - - protected void assertCountDownLatchCount() throws Exception { - long hits = testCase.getCountDownLatchRemainingHits(); - int count = testCase.getCountDownLatchTotalCount(); - WebSocketCommonClient.assertEqualsLong(0, hits, - "The countDownLatch has been hit only", count - hits, "was expected", - count, "times"); - logTrace("[WebSocketCommonClient] CountDownLatch has been hit", count, - "times as expected"); - } - - /** - * Asserts that a condition is true. - * - * @param condition - * tested condition - * @param message - * a space separated message[i].toString() compilation for - * i=<0,message.length) - * @throws Exception - * when conditionTrue is not met with message provided - */ - public static void // - assertTrue(boolean condition, Object... message) throws Exception { - if (!condition) - fault(message); - } - - /** - * Asserts that a condition is false. - * - * @param condition - * tested condition - * @param message - * a space separated message[i].toString() compilation for - * i=<0,message.length) - * @throws Exception - * when condition is not false with message provided - */ - public static void // - assertFalse(boolean condition, Object... message) throws Exception { - assertTrue(!condition, message); - } - - /** - * Asserts that two objects are equal. When instances of Comparable, such as - * String, compareTo is used. - * - * @param first - * first object - * @param second - * second object - * @param message - * a space separated message[i].toString() compilation for - * i=<0,message.length) - * @throws Exception - * when objects are not equal with message provided - */ - @SuppressWarnings("unchecked") - public static void // - assertEquals(T first, T second, Object... message) throws Exception { - if (first == null && second == null) - return; - assertFalse(first == null && second != null, message); - assertFalse(first != null && second == null, message); - if (first instanceof Comparable) - assertTrue(((Comparable) first).compareTo(second) == 0, message); - else - assertTrue(first.equals(second), message); - } - - public static void // - assertEqualsInt(int first, int second, Object... message) throws Exception { - assertTrue(first == second, message); - } - - public static void // - assertEqualsLong(long first, long second, Object... message) - throws Exception { - assertTrue(first == second, message); - } - - public static void // - assertEqualsBool(boolean first, boolean second, Object... message) - throws Exception { - assertTrue(first == second, message); - } - - /** - * Asserts that an object is null. - * - * @param object - * Assert that object is not null - * @param message - * a space separated message[i].toString() compilation for - * i=<0,message.length) - * @throws Exception - * when condition is not met with message provided - */ - public static void // - assertNull(Object object, Object... message) throws Exception { - assertTrue(object == null, message); - } - - /** - * Asserts that an object is not null. - * - * @param object - * Assert that object is not null - * @param message - * a space separated message[i].toString() compilation for - * i=<0,message.length) - * @throws Exception - * when condition is not met with message provided - */ - public static void // - assertNotNull(Object object, Object... message) throws Exception { - assertTrue(object != null, message); - } - - /** - * Throws Fault with space separated objects[1],object[2],...,object[n] - * message - * - * @param objects - * objects whose toString() results will be added to Fault message - * @throws Exception - * fault with space separated objects.toString values - */ - public static void fault(Object... objects) throws Exception { - throw new Exception(objectsToString(objects)); - } - - /** - * Throws Fault with space separated objects[1],object[2],...,object[n] - * message - * - * @param t - * Throwable to pass to Fault - * @param objects - * objects whose toString() results will be added to Fault message - * @throws Exception - * fault with space separated objects.toString values - */ - public static void fault(Throwable t, Object... objects) throws Exception { - throw new Exception(objectsToString(objects), t); - } - - /** - * Assert that given substring is a substring of given string - * - * @param string - * the string to search substring in - * @param substring - * the substring to be searched in a given string - * @param message - * space separated message values to be thrown - * @throws Exception - * throws - */ - public static void assertContains(String string, String substring, - Object... message) throws Exception { - assertTrue(string.contains(substring), message); - } - - /** - * Assert that given substring is a substring of given string, case - * insensitive - * - * @param string - * the string to search substring in - * @param substring - * the substring to be searched in a given string - * @param message - * space separated message values to be thrown - * @throws Exception - */ - public static void assertContainsIgnoreCase(String string, String substring, - Object... message) throws Exception { - assertTrue(string.toLowerCase().contains(substring.toLowerCase()), message); - } - - /** - * Assert that given substring is not a substring of given string - * - * @param string - * the string to search substring in - * @param substring - * the substring to be searched in a given string - * @param message - * space separated message values to be thrown - * @throws Exception - * throws - */ - public static void assertNotContains(String string, String substring, - Object... message) throws Exception { - assertFalse(string.contains(substring), message); - } - - /** - * Assert that given substring is not a substring of given string, case - * insensitive - * - * @param string - * the string to search substring in - * @param substring - * the substring to be searched in a given string - * @param message - * space separated message values to be thrown - * @throws Exception - */ - public static void assertNotContainsIgnoreCase(String string, - String substring, Object... message) throws Exception { - assertFalse(string.toLowerCase().contains(substring.toLowerCase()), - message); - } - - /** - * Assert that given subtext.toString() subject is a substring of given text - * - * @param text - * the text.toString() object to search subtext.toString() in - * @param subtext - * the subtext.toString() to be searched in a given text.toString() - * @param message - * space separated message values to be thrown - * @throws Exception - */ - public static void assertContains(T text, T subtext, Object... message) - throws Exception { - assertContains(text.toString(), subtext.toString(), message); - } - - /** - * Assert that given subtext.toString() subject is a substring of given text, - * case insensitive - * - * @param text - * the text.toString() object to search subtext.toString() in - * @param subtext - * the subtext.toString() to be searched in a given text.toString() - * @param message - * space separated message values to be thrown - * @throws Exception - */ - public static void assertContainsIgnoreCase(T text, T subtext, - Object... message) throws Exception { - assertContainsIgnoreCase(text.toString(), subtext.toString(), message); - } - - public static// - String assertProperty(Properties p, String propertyName) throws Exception { - String value = p.getProperty(propertyName); - logTrace(propertyName, value); - assertTrue(!isNullOrEmpty(value), propertyName, - "was not set in build.properties"); - return value; - } - - /** - * Searches an encapsulated exception cause in parent exception - */ - protected static T assertCause(Throwable parent, - Class wrapped, Object... msg) throws Exception { - T t = hasCause(parent, wrapped); - assertNotNull(t, msg); - return t; - } - - /** - * Check whether the string is either null or blank - */ - protected static boolean isNullOrEmpty(String val) { - return val == null || val.trim().equals(""); - } - - @SuppressWarnings("unchecked") - private static T // - hasCause(Throwable parent, Class cause) { - while (parent != null) { - if (cause.isInstance(parent)) - return (T) parent; - parent = parent.getCause(); - } - return null; - } - - public static String getCauseMessage(Throwable t) { - String msg = null; - while (t != null) { - msg = t.getMessage(); - t = t.getCause(); - } - return msg; - } - - public static void logMsg(Object... msg) { - TestUtil.logMsg(objectsToString(msg)); - } - - public static void logTrace(Object... msg) { - TestUtil.logTrace(objectsToString(msg)); - } - - /** - * @param objects - * to be put in a sentence - * @return objects in a single string , each object separated by " " - */ - protected static String objectsToString(Object... objects) { - return objectsToStringWithDelimiter(" ", objects); - } - - protected static String objectsToStringWithDelimiter(String delimiter, - Object... objects) { - StringBuilder sb = new StringBuilder(); - if (objects != null) - for (Object o : objects) { - if (o != null && o.getClass().isArray() - && o.toString().startsWith("[L")) - sb.append(objectsToStringWithDelimiter(delimiter, (Object[]) o)); - else - sb.append(o).append(delimiter); - } - return sb.toString().trim(); - } - - /** - * Creates basic authentication header for given username and password, to be - * simply recalled in client Configurator, for instance - * - *
-   * Configurator configurator = new Configurator() {
-   *   public void beforeRequest(Map<String, List<String>> headers) {
-   *     headers.putAll(basicAuthenticationAsHeaderMap(USER, PASSWORD));
-   *   };
-   * };
-   * setClientConfigurator(configurator);
-   * 
- * - *

- * Note that this is done by client framework automatically when - * - *
-   * setProperty(Property.BASIC_AUTH_USER, USER);
-   * setProperty(Property.BASIC_AUTH_PASSWD, PASSWORD);
-   * 
- * - * @param userName - * @param password - * @return a header map containing just Authorization header - */ - protected static// - Map> basicAuthenticationAsHeaderMap(String userName, - String password) { - Map> headers = new HashMap<>(); - String toEncode = new StringBuilder().append(userName).append(':') - .append(password).toString(); - String base64 = new BASE64Encoder().encode(toEncode.getBytes()); - headers.put("Authorization", Arrays.asList("Basic " + base64)); - return headers; - } - - // ---------------------Callbacks --------------------------------- - /** - *

- * Possible cast to VI specific container, e.g. tyrus ClientManager and set - * properties for debug purposes. - *

- *

- * For instance, to delay the connection timeout, use - * - *

-   * ClientManager cm = (ClientManager) clientContainer;
-   * cm.getProperties().put(ClientProperties.HANDSHAKE_TIMEOUT, 500000);
-   * 
- * - * @param clientContainer - * The container used for e.g. - * {@link WebSocketContainer#connectToServer(Class, java.net.URI)} - *

- */ - protected void // - setupWebSocketContainerBeforeConnect(WebSocketContainer clientContainer) { - } - - // ---------------------Setters --------------------------------- - /** - * Sets the protocol the request starts with Default "ws" - * - * @param protocol - */ - protected void setRequestProtocol(String protocol) { - this.requestProtocol = protocol; - } - - protected void setCountDownLatchCount(int countDownLatchCount) { - getTestCase().setCountDownLatchCount(countDownLatchCount); - } - - /** - * set ClientEndpoint class. This endpoint class can be overriden by client - * endpoint instance set by {@link #setClientEndpointInstance} - */ - protected void setClientEndpoint( - Class> endpoint) { - getTestCase().setClientEndpoint(endpoint); - } - - /** - * The ClientEndpoint instance. It holds precedence over ClientEndpoint class - * set by {@link #setClientEndpoint} - */ - protected void setClientEndpointInstance(ClientEndpoint endpointInstance) { - getTestCase().setClientEndpointInstance(endpointInstance); - } - - /** - * The annotated client endpoint alternative to ClientEndpoint instance. It - * has precedence over ClientEndpoint class set by {@link #setClientEndpoint} - */ - protected void setAnnotatedClientEndpoint( - AnnotatedClientEndpoint annotatedEndpoint) { - getTestCase().setAnnotatedClientEndpoint(annotatedEndpoint); - } - - /** - * Ensures given Configurator to be registered to any given or default - * ClientEndpointConfig - */ - protected void // - addClientConfigurator(Configurator configurator) { - getTestCase().addClientConfigurator(configurator); - } - - protected void // - setClientEndpointConfig(ClientEndpointConfig clientEndpointConfig) { - getTestCase().setClientEndpointConfig(clientEndpointConfig); - } - - /** - * This method sets the main {@link EndpointCallback} to be used by a test. If - * a callback is to be used in conjunction with default - * {@link SendMessageCallback}, use - * {@link #addClientCallback(EndpointCallback)} method. - *

- * Note that when no entity is sent to a server, no clientCallback is used. - */ - protected void setClientCallback(EndpointCallback callback) { - getTestCase().setCallback(callback); - } - - /** - * Add additional callback functionality to a main callback. The main callback - * could either be set by {@link #setClientCallback(EndpointCallback)} method - * or it is the default {@link SendMessageCallback} client callback. - *

- * Note that when no entity is sent to a server, no clientCallback is used. - */ - protected void addClientCallback(EndpointCallback callback) { - getTestCase().addClientCallback(callback); - } - - protected Session getSession() throws Exception { - Session session = getTestCase().getSession(); - assertNotNull(session, "Session is null! Has been closed?"); - return session; - } - - protected String getResponseAsString() { - return getTestCase().getResponseAsString(); - } - - protected T getLastResponse(Class type) { - return getTestCase().getLastResponse(type); - } - - protected void printClientCall(boolean printClientCall) { - getTestCase().printClientCall(printClientCall); - } - - protected void logExceptionOnInvocation(boolean log) { - logExceptionOnInvoke = log; - } +public abstract class WebSocketCommonClient { + + private static final long serialVersionUID = 1L; + + /** + * The property that is set after invoke(), to let know the cleanup of previous + * test should be performed so that more invocations are possible + */ + boolean isTestCaseAfterInvocation; + + /** + * Webserver host property + */ + protected static final String SERVLETHOSTPROP = "webServerHost"; + + /** + * Webserver port property + */ + protected static final String SERVLETPORTPROP = "webServerPort"; + /** + * ws_wait wait for the response. + */ + protected static final String WSWAIT = "ws_wait"; + + /** + * Single invocation incremental test properties + */ + protected Hashtable TEST_PROPS; + + /** + * Context root of target tests + */ + protected String _contextRoot = null; + + /** + * Target webserver hostname + */ + protected String _hostname = null; + + /** + * Target webserver port + */ + protected int _port = 0; + + /** + * The protocol to be used for invoking a request, ws, wss, http, https, ... + */ + protected String requestProtocol = "ws"; + + /** + * Property from ts.jte + */ + protected int _ws_wait = 0; + + /** + * The test case of given specified websocket message type + */ + protected WebSocketTestCase testCase; + + /** + * disable logging stack trace of exception caused on invoke() for the tests + * that expects the exception to be thrown + */ + protected boolean logExceptionOnInvoke = true; + + /** + * Entity of type T, where T is the type of WebSocketTestCase, e.g. String by + * default. As websocket supports partial messages, this Entity is an array of + * objects; For whole message, only one Object in the array is used. When more + * objects are utilized, partial message is being sent. + */ + public class Entity { + private Object[] entities; + + public Entity(Object... partials) { + entities = partials; + } + + public Entity(Object entity) { + this(new Object[] { entity }); + } + + public boolean isInstance(Class clazz) { + return clazz.isInstance(entities[0]); + } + + public int length() { + return entities.length; + } + + @SuppressWarnings("unchecked") + public T getEntityAt(Class clazz, int index) { + if (ByteBuffer.class.isAssignableFrom(clazz)) + return (T) cloneByteBuffer(index); + return (T) entities[index]; + } + + @SuppressWarnings("unchecked") + public T getEntityAt(int index) { + if (ByteBuffer.class.isInstance(entities[index])) + return (T) cloneByteBuffer(index); + return (T) entities[index]; + } + + private ByteBuffer clone(ByteBuffer message) { + byte[] orig = message.array(); + byte[] array = new byte[orig.length]; + System.arraycopy(orig, 0, array, 0, orig.length); + return ByteBuffer.wrap(array); + } + + private ByteBuffer cloneByteBuffer(int index) { + ByteBuffer bb = (ByteBuffer) entities[index]; + return clone(bb); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(entities.length); + if (entities.length == 1) + sb.append(" part: "); + else + sb.append(" parts: "); + sb.append(objectsToStringWithDelimiter(", ", entities)); + return sb.toString(); + } + } + + protected Entity entity; + + /** + * the list of properties to be put into a property table + */ + protected enum Property { + BASIC_AUTH_PASSWD, BASIC_AUTH_USER, // + CONTENT, EXPECTED_HEADERS, // + IGNORE_STATUS_CODE, REQUEST, // + SEARCH_STRING, SEARCH_STRING_IGNORE_CASE, STATUS_CODE, // + UNEXPECTED_HEADERS, UNEXPECTED_RESPONSE_MATCH, // + UNORDERED_SEARCH_STRING; + } + + // //////////////////////////////////////////////////////////////////////// + public String getContextRoot() { + return _contextRoot; + } + + public void setContextRoot(String root) { + TestUtil.logTrace("[WebSocketCommonClient] Contextroot set at " + root); + _contextRoot = root; + } + + /** + * Set property values to a given key if none exists, or adds all property + * values to a given key when one exists, unless the property is a content + */ + protected void setProperty(Property key, String... values) { + for (String singleValue : values) + setProperty(key, singleValue); + } + + /** + * Set property value to a given key if none exists, or adds a property value to + * a given key when one exists, unless the property is a content. When content, + * only the last single content is sent as a part of request + */ + protected void setProperty(Property key, String value) { + switch (key) { + case CONTENT: + setEntity(value); + break; + default: + String oldValue = TEST_PROPS.get(key); + if (oldValue == null) { + TEST_PROPS.put(key, value); + } else { + int len = value.length() + oldValue.length() + 1; + StringBuilder combinedValue = new StringBuilder(len); + combinedValue.append(oldValue).append("|").append(value); + TEST_PROPS.put(key, combinedValue.toString()); + } + break; + } + } + + protected String buildRequest(String... path) { + StringBuilder sb = new StringBuilder(); + sb.append(getAbsoluteUrl()).append("/"); + for (String segment : path) { + sb.append(segment); + } + return sb.toString(); + } + + protected String getAbsoluteUrl() { + StringBuilder sb = new StringBuilder(); + sb.append(requestProtocol).append("://").append(_hostname).append(":").append(_port).append("/") + .append(getContextRoot()); + return sb.toString(); + } + + /** + * Shortcut to invoke() when endpoint, content, and search is known + * + * @param endpoint the endpoint the request is built to go to. + * @param content the content to be set as setEntity(content.name()) + * @param search a response would be searched for search.name() + * @throws Exception when invocation fails + */ + protected > // + void invoke(String endpoint, Enum content, Enum search) throws Exception { + invoke(endpoint, content.name(), search.name()); + } + + /** + * Shortcut to invoke() when endpoint, content, and search is known + * + * @param endpoint the endpoint the request is built to go to. + * @param content the content to be set as setEntity(content.name()) + * @param search a String the response would be searched for + * @throws Exception when invocation fails + */ + protected// + void invoke(String endpoint, Enum content, String... search) throws Exception { + invoke(endpoint, content.name(), search); + } + + /** + * Shortcut to invoke() when endpoint, content, and search is known + * + * @param endpoint the endpoint the request is built to go to. + * @param content the content to be set as setEntity(content) + * @param search the content of a response to be searched, or "" when does not + * matter + * @throws Exception when invocation fails + */ + protected void // + invoke(String endpoint, Object content, String... search) throws Exception { + invoke(endpoint, content, search, true); + } + + /** + * Shortcut to invoke() when endpoint, content, and search is known + * + * @param endpoint the endpoint the request is built to go to. + * @param content the content to be set as setEntity(content) + * @param search the content of a response to be searched, or "" when does not + * matter + * @param cleanup see {@link #invoke(boolean)} + * @throws Exception when invocation fails + */ + protected void // + invoke(String endpoint, Object content, String[] search, boolean cleanup) throws Exception { + setProperty(Property.REQUEST, buildRequest(endpoint)); + setEntity(content); + setProperty(Property.SEARCH_STRING, search); + invoke(cleanup); + } + + protected void // + invoke(String endpoint, Object content, String search, boolean cleanup) throws Exception { + invoke(endpoint, content, new String[] { search }, cleanup); + } + + /** + * Shortcut to invokeAgain(cleanup) when endpoint, content, and search is known + * + * @param content the content to be set as setEntity(content) + * @param search the content of a response to be searched, or "" when does not + * matter + * @param cleanup see {@link #invokeAgain(boolean)} + * @throws Exception when invocation fails + */ + protected void // + invokeAgain(Object content, String search, boolean cleanup) throws Exception { + setEntity(content); + setProperty(Property.SEARCH_STRING, search); + invokeAgain(cleanup); + } + + /** + *
+	 * Invokes a test based on the properties
+	 * stored in TEST_PROPS.  Once the test has completed,
+	 * the properties in TEST_PROPS will be cleared.
+	 * 
+ * + * @throws Exception If an error occurs during the test run + */ + protected void invoke() throws Exception { + invoke(true); + } + + /** + *
+	 * Invokes a test based on the properties
+	 * stored in TEST_PROPS.  Once the test has completed,
+	 * the properties in TEST_PROPS will be cleared if cleanUp says so.
+	 * 
+ * + * @throws Exception If an error occurs during the test run + * @param cleanUp Defines whether the test has ended + * + */ + protected void invoke(boolean cleanUp) throws Exception { + invoke(cleanUp, false); + } + + /** + * Invoke additional request with new entity and hold open + * {@link jakarta.websocket.Session} to a server {@link Endpoint}, the response + * is caught by client {@link Endpoint} set by current {@link WebSocketTestCase} + *

+ * + * @throws Exception + */ + protected void invokeAgain(boolean cleanUp) throws Exception { + invoke(cleanUp, true); + } + + /** + *

+	 * Invokes a test based on the properties
+	 * stored in TEST_PROPS. The current session is used. Once the test has completed,
+	 * the properties in TEST_PROPS will be cleared if cleanUp says so.
+	 * 
+ * + * @throws Exception If an error occurs during the test run + * @param cleanUp Defines whether the test has ended + * @param again the request to server endpoint is performed on currently + * established session, when the session has not been closed + * after previous {@link #invoke(false)}; + */ + protected void invoke(boolean cleanUp, boolean again) throws Exception { + TestUtil.logTrace("[WebSocketCommonClient] invoke"); + TestUtil.logTrace("[WebSocketCommonClient] EXECUTING"); + setTestProperties(getTestCase()); + try { + executeTestCase(again); + testCase.validate(); + assertCountDownLatchCount(); + } catch (TestFailureException tfe) { + dealWithTestFailureException(tfe); + } finally { + isTestCaseAfterInvocation = cleanUp; + if (cleanUp) { + cleanup(); + } + } + } + + /** + * Executes test case for the first time, or once again on existing + * {@link WebSocketTestCase} and existing {@link Session} for a new + * {@link Entity} + * + * @param again + * @throws TestFailureException + */ + protected// + void executeTestCase(boolean again) throws TestFailureException, Exception { + if (again) { + testCase.newCountDown(); + SendMessageCallback callback = new SendMessageCallback(entity); + callback.onOpen(getSession(), null); + testCase.awaitCountDown(); + } else + testCase.execute(); + } + + private// + void dealWithTestFailureException(TestFailureException tfe) throws Exception { + Throwable t = tfe.getRootCause(); + if (t != null && logExceptionOnInvoke) { + TestUtil.logErr("Root cause of Failure: " + t.getMessage(), t); + } else + logExceptionOnInvoke = true; + new Exception( + tfe.getMessage() + "[WebSocketCommonClient] TestCase failed! Check output for cause of failure."); + } + + /** + *
+	 * Sets the appropriate test properties based
+	 * on the values stored in TEST_PROPS
+	 * 
+ */ + protected void setTestProperties(WebSocketTestCase testCase) { + TestUtil.logTrace("[WebSocketCommonClient] setTestProperties"); + + if (TEST_PROPS.get(Property.STATUS_CODE) == null) + setProperty(Property.STATUS_CODE, "200"); + setWebTestCaseProperties(testCase); + } + + protected void setWebTestCaseProperties(WebSocketTestCase testCase) { + Property key = null; + String value = null; + // process the remainder of the properties + for (Enumeration e = TEST_PROPS.keys(); e.hasMoreElements();) { + key = e.nextElement(); + value = TEST_PROPS.get(key); + switch (key) { + case BASIC_AUTH_USER: + break; + case BASIC_AUTH_PASSWD: + final String user = TEST_PROPS.get(Property.BASIC_AUTH_USER); + final String password = TEST_PROPS.get(Property.BASIC_AUTH_PASSWD); + Configurator configurator = new Configurator() { + @Override + public void beforeRequest(Map> headers) { + headers.putAll(basicAuthenticationAsHeaderMap(user, password)); + super.beforeRequest(headers); + } + }; + addClientConfigurator(configurator); + break; + case CONTENT: + setEntity(value); + break; + case EXPECTED_HEADERS: + testCase.addExpectedHeader(value); + TEST_PROPS.remove(Property.EXPECTED_HEADERS); + break; + case IGNORE_STATUS_CODE: + testCase.setExpectedStatusCode("-1"); + break; + case REQUEST: + break; + case SEARCH_STRING: + value = testCase.getTextCaser().getCasedText(value); + testCase.setResponseSearchString(value); + TEST_PROPS.remove(Property.SEARCH_STRING); + break; + case SEARCH_STRING_IGNORE_CASE: + testCase.setResponseSearchStringIgnoreCase(value); + TEST_PROPS.remove(Property.SEARCH_STRING_IGNORE_CASE); + break; + case STATUS_CODE: + if (value.contains("|")) + testCase.setStrategy(CheckOneOfStatusesTokenizedValidator.class.getName()); + testCase.setExpectedStatusCode(value); + break; + case UNEXPECTED_HEADERS: + testCase.addUnexpectedHeader(value); + TEST_PROPS.remove(Property.UNEXPECTED_HEADERS); + break; + case UNEXPECTED_RESPONSE_MATCH: + testCase.setUnexpectedResponseSearchString(value); + TEST_PROPS.remove(Property.UNEXPECTED_RESPONSE_MATCH); + break; + case UNORDERED_SEARCH_STRING: + value = testCase.getTextCaser().getCasedText(value); + testCase.setUnorderedSearchString(value); + TEST_PROPS.remove(Property.UNORDERED_SEARCH_STRING); + break; + } + } + } + + protected WebSocketTestCase getTestCase() { + if (testCase == null || isTestCaseAfterInvocation) { + testCase = new WebSocketTestCase(this); + isTestCaseAfterInvocation = false; + } + return testCase; + } + + protected // + void setEndPointCase(Class> endpoint) { + getTestCase().setClientEndpoint(endpoint); + } + + protected Entity setEntity(Object... partials) { + this.entity = new Entity(partials); + return this.entity; + } + + /** + * cleanup is called by the test harness to cleanup after text + * execution + * + * @exception Exception if an error occurs + */ + public void cleanup() throws Exception { + TEST_PROPS.clear(); + isTestCaseAfterInvocation = true; + if (testCase != null && testCase.session != null) { + if (testCase.session.isOpen()) { + ClientEndpointData.newOnCloseCountDown(); + logTrace("[WebSocketCommonClient] session.close() on session id", testCase.session.getId()); + testCase.session.close(); + ClientEndpointData.awaitOnClose(); + } + testCase.session = null; + } + synchronized (ClientEndpointData.LOCK) { + ClientEndpointData.callback = null; + } + TestUtil.logMsg("[WebSocketCommonClient] Test cleanup OK"); + } + + /** + * setup is by the test harness to initialize the tests. + * + * @param args a String[] value + * @param p a Properties value + * @exception Exception if an error occurs + */ + public void setup() throws Exception { + TestUtil.logTrace("setup method WebSocketCommonClient"); + String hostname = System.getProperty(SERVLETHOSTPROP); + String portnum = System.getProperty(SERVLETPORTPROP); + String wswait = System.getProperty(WSWAIT); + + assertFalse(isNullOrEmpty(hostname), "[WebSocketCommonClient] 'webServerHost' was not set in the properties."); + _hostname = hostname.trim(); + assertFalse(isNullOrEmpty(portnum), "[WebSocketCommonClient] 'webServerPort' was not set in the properties."); + _port = Integer.parseInt(portnum.trim()); + assertFalse(isNullOrEmpty(wswait), "[WebSocketCommonClient] 'ws_wait' must be set in the properties"); + _ws_wait = Integer.parseInt(wswait.trim()); + assertTrue(_ws_wait > 0, "[WebSocketCommonClient] 'ws_wait' (in seconds) must be set greater than 0"); + + TestUtil.logMsg("[WebSocketCommonClient] Test setup OK"); + TEST_PROPS = new Hashtable<>(); + } + + // ///////////////////////////// Utility methods + // ////////////////////////////// + + protected void assertCountDownLatchCount() throws Exception { + long hits = testCase.getCountDownLatchRemainingHits(); + int count = testCase.getCountDownLatchTotalCount(); + WebSocketCommonClient.assertEqualsLong(0, hits, "The countDownLatch has been hit only", count - hits, + "was expected", count, "times"); + logTrace("[WebSocketCommonClient] CountDownLatch has been hit", count, "times as expected"); + } + + /** + * Asserts that a condition is true. + * + * @param condition tested condition + * @param message a space separated message[i].toString() compilation for + * i=<0,message.length) + * @throws Exception when conditionTrue is not met with message provided + */ + public static void // + assertTrue(boolean condition, Object... message) throws Exception { + if (!condition) + new Exception(message.toString()); + } + + /** + * Asserts that a condition is false. + * + * @param condition tested condition + * @param message a space separated message[i].toString() compilation for + * i=<0,message.length) + * @throws Exception when condition is not false with message provided + */ + public static void // + assertFalse(boolean condition, Object... message) throws Exception { + assertTrue(!condition, message); + } + + /** + * Asserts that two objects are equal. When instances of Comparable, such as + * String, compareTo is used. + * + * @param first first object + * @param second second object + * @param message a space separated message[i].toString() compilation for + * i=<0,message.length) + * @throws Exception when objects are not equal with message provided + */ + @SuppressWarnings("unchecked") + public static void // + assertEquals(T first, T second, Object... message) throws Exception { + if (first == null && second == null) + return; + assertFalse(first == null && second != null, message); + assertFalse(first != null && second == null, message); + if (first instanceof Comparable) + assertTrue(((Comparable) first).compareTo(second) == 0, message); + else + assertTrue(first.equals(second), message); + } + + public static void // + assertEqualsInt(int first, int second, Object... message) throws Exception { + assertTrue(first == second, message); + } + + public static void // + assertEqualsLong(long first, long second, Object... message) throws Exception { + assertTrue(first == second, message); + } + + public static void // + assertEqualsBool(boolean first, boolean second, Object... message) throws Exception { + assertTrue(first == second, message); + } + + /** + * Asserts that an object is null. + * + * @param object Assert that object is not null + * @param message a space separated message[i].toString() compilation for + * i=<0,message.length) + * @throws Exception when condition is not met with message provided + */ + public static void // + assertNull(Object object, Object... message) throws Exception { + assertTrue(object == null, message); + } + + /** + * Asserts that an object is not null. + * + * @param object Assert that object is not null + * @param message a space separated message[i].toString() compilation for + * i=<0,message.length) + * @throws Exception when condition is not met with message provided + */ + public static void // + assertNotNull(Object object, Object... message) throws Exception { + assertTrue(object != null, message); + } + + /** + * Assert that given substring is a substring of given string + * + * @param string the string to search substring in + * @param substring the substring to be searched in a given string + * @param message space separated message values to be thrown + * @throws Exception throws + */ + public static void assertContains(String string, String substring, Object... message) throws Exception { + assertTrue(string.contains(substring), message); + } + + /** + * Assert that given substring is a substring of given string, case insensitive + * + * @param string the string to search substring in + * @param substring the substring to be searched in a given string + * @param message space separated message values to be thrown + * @throws Exception + */ + public static void assertContainsIgnoreCase(String string, String substring, Object... message) throws Exception { + assertTrue(string.toLowerCase().contains(substring.toLowerCase()), message); + } + + /** + * Assert that given substring is not a substring of given string + * + * @param string the string to search substring in + * @param substring the substring to be searched in a given string + * @param message space separated message values to be thrown + * @throws Exception throws + */ + public static void assertNotContains(String string, String substring, Object... message) throws Exception { + assertFalse(string.contains(substring), message); + } + + /** + * Assert that given substring is not a substring of given string, case + * insensitive + * + * @param string the string to search substring in + * @param substring the substring to be searched in a given string + * @param message space separated message values to be thrown + * @throws Exception + */ + public static void assertNotContainsIgnoreCase(String string, String substring, Object... message) + throws Exception { + assertFalse(string.toLowerCase().contains(substring.toLowerCase()), message); + } + + /** + * Assert that given subtext.toString() subject is a substring of given text + * + * @param text the text.toString() object to search subtext.toString() in + * @param subtext the subtext.toString() to be searched in a given + * text.toString() + * @param message space separated message values to be thrown + * @throws Exception + */ + public static void assertContains(T text, T subtext, Object... message) throws Exception { + assertContains(text.toString(), subtext.toString(), message); + } + + /** + * Assert that given subtext.toString() subject is a substring of given text, + * case insensitive + * + * @param text the text.toString() object to search subtext.toString() in + * @param subtext the subtext.toString() to be searched in a given + * text.toString() + * @param message space separated message values to be thrown + * @throws Exception + */ + public static void assertContainsIgnoreCase(T text, T subtext, Object... message) throws Exception { + assertContainsIgnoreCase(text.toString(), subtext.toString(), message); + } + + public static// + String assertProperty(Properties p, String propertyName) throws Exception { + String value = System.getProperty(propertyName); + logTrace(propertyName, value); + assertTrue(!isNullOrEmpty(value), propertyName, "was not set in build.properties"); + return value; + } + + /** + * Searches an encapsulated exception cause in parent exception + */ + protected static T assertCause(Throwable parent, Class wrapped, Object... msg) + throws Exception { + T t = hasCause(parent, wrapped); + assertNotNull(t, msg); + return t; + } + + /** + * Check whether the string is either null or blank + */ + protected static boolean isNullOrEmpty(String val) { + return val == null || val.trim().equals(""); + } + + @SuppressWarnings("unchecked") + private static T // + hasCause(Throwable parent, Class cause) { + while (parent != null) { + if (cause.isInstance(parent)) + return (T) parent; + parent = parent.getCause(); + } + return null; + } + + public static String getCauseMessage(Throwable t) { + String msg = null; + while (t != null) { + msg = t.getMessage(); + t = t.getCause(); + } + return msg; + } + + public static void logMsg(Object... msg) { + TestUtil.logMsg(objectsToString(msg)); + } + + public static void logTrace(Object... msg) { + TestUtil.logTrace(objectsToString(msg)); + } + + /** + * @param objects to be put in a sentence + * @return objects in a single string , each object separated by " " + */ + protected static String objectsToString(Object... objects) { + return objectsToStringWithDelimiter(" ", objects); + } + + protected static String objectsToStringWithDelimiter(String delimiter, Object... objects) { + StringBuilder sb = new StringBuilder(); + if (objects != null) + for (Object o : objects) { + if (o != null && o.getClass().isArray() && o.toString().startsWith("[L")) + sb.append(objectsToStringWithDelimiter(delimiter, (Object[]) o)); + else + sb.append(o).append(delimiter); + } + return sb.toString().trim(); + } + + /** + * Creates basic authentication header for given username and password, to be + * simply recalled in client Configurator, for instance + * + *
+	 * Configurator configurator = new Configurator() {
+	 * 	public void beforeRequest(Map<String, List<String>> headers) {
+	 * 		headers.putAll(basicAuthenticationAsHeaderMap(USER, PASSWORD));
+	 * 	};
+	 * };
+	 * setClientConfigurator(configurator);
+	 * 
+ * + *

+ * Note that this is done by client framework automatically when + * + *
+	 * setProperty(Property.BASIC_AUTH_USER, USER);
+	 * setProperty(Property.BASIC_AUTH_PASSWD, PASSWORD);
+	 * 
+ * + * @param userName + * @param password + * @return a header map containing just Authorization header + */ + protected static// + Map> basicAuthenticationAsHeaderMap(String userName, String password) { + Map> headers = new HashMap<>(); + String toEncode = new StringBuilder().append(userName).append(':').append(password).toString(); + String base64 = new BASE64Encoder().encode(toEncode.getBytes()); + headers.put("Authorization", Arrays.asList("Basic " + base64)); + return headers; + } + + // ---------------------Callbacks --------------------------------- + /** + *

+ * Possible cast to VI specific container, e.g. tyrus ClientManager and set + * properties for debug purposes. + *

+ *

+ * For instance, to delay the connection timeout, use + * + *

+	 * ClientManager cm = (ClientManager) clientContainer;
+	 * cm.getProperties().put(ClientProperties.HANDSHAKE_TIMEOUT, 500000);
+	 * 
+ * + * @param clientContainer The container used for e.g. + * {@link WebSocketContainer#connectToServer(Class, java.net.URI)} + *

+ */ + protected void // + setupWebSocketContainerBeforeConnect(WebSocketContainer clientContainer) { + } + + // ---------------------Setters --------------------------------- + /** + * Sets the protocol the request starts with Default "ws" + * + * @param protocol + */ + protected void setRequestProtocol(String protocol) { + this.requestProtocol = protocol; + } + + protected void setCountDownLatchCount(int countDownLatchCount) { + getTestCase().setCountDownLatchCount(countDownLatchCount); + } + + /** + * set ClientEndpoint class. This endpoint class can be overriden by client + * endpoint instance set by {@link #setClientEndpointInstance} + */ + protected void setClientEndpoint(Class> endpoint) { + getTestCase().setClientEndpoint(endpoint); + } + + /** + * The ClientEndpoint instance. It holds precedence over ClientEndpoint class + * set by {@link #setClientEndpoint} + */ + protected void setClientEndpointInstance(ClientEndpoint endpointInstance) { + getTestCase().setClientEndpointInstance(endpointInstance); + } + + /** + * The annotated client endpoint alternative to ClientEndpoint instance. It has + * precedence over ClientEndpoint class set by {@link #setClientEndpoint} + */ + protected void setAnnotatedClientEndpoint(AnnotatedClientEndpoint annotatedEndpoint) { + getTestCase().setAnnotatedClientEndpoint(annotatedEndpoint); + } + + /** + * Ensures given Configurator to be registered to any given or default + * ClientEndpointConfig + */ + protected void // + addClientConfigurator(Configurator configurator) { + getTestCase().addClientConfigurator(configurator); + } + + protected void // + setClientEndpointConfig(ClientEndpointConfig clientEndpointConfig) { + getTestCase().setClientEndpointConfig(clientEndpointConfig); + } + + /** + * This method sets the main {@link EndpointCallback} to be used by a test. If a + * callback is to be used in conjunction with default + * {@link SendMessageCallback}, use {@link #addClientCallback(EndpointCallback)} + * method. + *

+ * Note that when no entity is sent to a server, no clientCallback is used. + */ + protected void setClientCallback(EndpointCallback callback) { + getTestCase().setCallback(callback); + } + + /** + * Add additional callback functionality to a main callback. The main callback + * could either be set by {@link #setClientCallback(EndpointCallback)} method or + * it is the default {@link SendMessageCallback} client callback. + *

+ * Note that when no entity is sent to a server, no clientCallback is used. + */ + protected void addClientCallback(EndpointCallback callback) { + getTestCase().addClientCallback(callback); + } + + protected Session getSession() throws Exception { + Session session = getTestCase().getSession(); + assertNotNull(session, "Session is null! Has been closed?"); + return session; + } + + protected String getResponseAsString() { + return getTestCase().getResponseAsString(); + } + + protected T getLastResponse(Class type) { + return getTestCase().getLastResponse(type); + } + + protected void printClientCall(boolean printClientCall) { + getTestCase().printClientCall(printClientCall); + } + + protected void logExceptionOnInvocation(boolean log) { + logExceptionOnInvoke = log; + } + + public static String toString(InputStream inStream) throws IOException{ + try (BufferedReader bufReader = new BufferedReader(new InputStreamReader(inStream, StandardCharsets.UTF_8))) { + return bufReader.lines().collect(Collectors.joining(System.lineSeparator())); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/WebSocketTestCase.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/WebSocketTestCase.java index 74c50d3036..e90ff6d78e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/WebSocketTestCase.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/client/WebSocketTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -63,472 +63,449 @@ */ public class WebSocketTestCase extends WebTestCase { - /** - * Apache HTTP response mock - */ - protected HttpResponse _response; - - /** - * A reference to WebSocketCommonClient, holder of properties needed to build - * request - */ - protected WebSocketCommonClient client; - - /** - * A reference to ClientEndpoint, a websocket endpoint the messages are passed - * into it - */ - protected Class> endpoint = StringClientEndpoint.class; - - /** - * An Instance to ClientEndpoint, a websocket endpoint the messages are passed - * into it - */ - protected ClientEndpoint endpointInstance = null; - - /** - * An annotated endpoint, in this implementation merely a bridge to - * ClientEndpoint, to be sure the annotated methods are called and also to - * have all the EndpointCallbacks working there - */ - protected AnnotatedClientEndpoint annotatedEndpoint = null; - - /** - * A single master callback to be used in client end point - */ - protected volatile EndpointCallback clientCallback = null; - - /* - * Callbacks to be added to a given master callback or to a default - * SendMessageCallback master callback if no master callback is provided - */ - protected List slaveClientCallbacks = null; - - /** - * Upper case, lower case, or exact text matching? - */ - protected TextCaser textCaser = TextCaser.NONE; - - /** - * Strategy to use when validating the test case against the server's - * response. - */ - protected ValidationStrategy strategy = null; - - /** - * The WebSocket Session Object to be addressed from test - */ - protected volatile Session session; - - /** - * Count Down Latch Count - */ - protected int countDownLatchCount = 1; - - /** - * ClientEndpointConfig to be used - */ - protected ClientEndpointConfig clientEndpointConfig = null; - - protected List configurators = null; - - /** - * Flag to enable client call logging - */ - protected boolean printClientCall = false; - - // --------------------------------------------------------------------- - public WebSocketTestCase(WebSocketCommonClient client) { - super(); - this.client = client; - clientEndpointConfig = ClientEndpointConfig.Builder.create().build(); - strategy = ValidationFactory.getInstance(TOKENIZED_STRATEGY); - configurators = new LinkedList<>(); - slaveClientCallbacks = new LinkedList<>(); - ClientEndpointData.resetData(); - logTrace("A new test case has been created"); - } - - /** - * Executes the test case. - * - * @throws TestFailureException - * if the test fails for any reason. - * @throws IllegalStateException - * if no request was configured or if no Validator is available at - * runtime. - */ - @Override - public void execute() throws TestFailureException { - verifyValidationStrategy(); - verifySettings(); - addAllConfiguratorsToClientEndpointConfig(); - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - String path = client.TEST_PROPS.get(Property.REQUEST); - if (printClientCall) - logTrace("\n-----------\n", printClientCall(), "-----------\n"); - logMsg("Connecting to", path); - if (slaveClientCallbacks.size() != 0) - clientCallback = createMasterEndpointCallback(); - if (client.entity != null) { - if (clientCallback != null) - ClientEndpointData.callback = clientCallback; - else - ClientEndpointData.callback = new SendMessageCallback(client.entity); - } - client.setupWebSocketContainerBeforeConnect(clientContainer); - newCountDown(); - session = connectToServer(clientContainer, path); - awaitCountDown(); - } catch (Throwable t) { - String message = t.getMessage(); - - StringBuilder sb = new StringBuilder(); - sb.append("[FATAL] Unexpected failure during test execution.\n"); - // print client call code to report into JIRA when needed - if (client.logExceptionOnInvoke) - sb.append(printClientCall().toString()); - // Inherited message - sb.append((message == null ? t.toString() : message)); - - throw new TestFailureException(sb.toString(), t); - } - } - - /** - * Validate this test case instance - * - * @throws TestFailureException - */ - protected void validate() throws TestFailureException { - if (!strategy.validate(this)) { - throw new TestFailureException("Test FAILED!"); - } - } - - /** - * Logging method for internal purposes - */ - protected StringBuilder printClientCall() { - StringBuilder sb = new StringBuilder(); - if (client.entity != null && client.entity.isInstance(String.class)) { - sb.append("class ").append(endpoint.getSimpleName()); - sb.append(" extends Endpoint implements MessageHandler.Whole"); - sb.append(" {\n"); - sb.append( - " public void onOpen(Session session, EndpointConfig config) {\n"); - sb.append(" session.addMessageHandler(this);\n"); - sb.append( - " RemoteEndpoint.Basic endpoint = session.getBasicRemote();\n"); - sb.append(" try {\n"); - sb.append(" endpoint.sendText(\""); - sb.append(client.entity.getEntityAt(String.class, 0)); - sb.append("\");\n"); - sb.append(" } catch (IOException e) {\n"); - sb.append(" throw new RuntimeException(e);\n"); - sb.append(" }\n"); - sb.append(" }\n"); - sb.append(" public void onMessage(String message) {\n"); - sb.append(" System.out.println(message);\n"); - sb.append(" messageLatch.countDown()"); - sb.append(" }\n"); - sb.append("};\n"); - } - sb.append("CountDownLatch messageLatch;\n"); - sb.append("public void test() {\n"); - sb.append(" WebSocketContainer clientContainer = ContainerProvider"); - sb.append(".getWebSocketContainer();\n"); - sb.append(" messageLatch = new CountDownLatch("); - sb.append(countDownLatchCount).append(");\n"); - sb.append(" Session session = clientContainer.connectToServer("); - sb.append(endpoint.getSimpleName()).append(".class,\n"); - sb.append(" "); - sb.append("ClientEndpointConfig.Builder.create()"); - Configurator configurator = clientEndpointConfig.getConfigurator(); - if (configurator != null) - sb.append(".config(new ").append(configurator.getClass().getName()) - .append("())"); - sb.append(".build(),\n"); - sb.append(" "); - sb.append("new URI(\"").append(client.TEST_PROPS.get(Property.REQUEST)); - sb.append("\"));\n"); - sb.append(" messageLatch.await(").append(client._ws_wait); - sb.append(", TimeUnit.SECONDS);\n"); - sb.append("}\n"); - - return sb; - } - - protected Session connectToServer(WebSocketContainer clientContainer, - String path) throws Exception { - WebSocketCommonClient.assertTrue( - endpointInstance == null || annotatedEndpoint == null, - "Either a ClientEndpoint instance or Annotated endpoint can be used, not both"); - - if (annotatedEndpoint != null) - session = clientContainer.connectToServer(annotatedEndpoint, - new URI(path)); - else if (endpointInstance != null) - session = clientContainer.connectToServer(endpointInstance, - clientEndpointConfig, new URI(path)); - else - session = clientContainer.connectToServer(endpoint, clientEndpointConfig, - new URI(path)); - logTrace("Connection session id:", session.getId()); - return session; - } - - protected void addAllConfiguratorsToClientEndpointConfig() { - if (!configurators.isEmpty()) { - ClientEndpointConfig.Configurator masterConfigurator = createMasterConfigurator(); - ClientEndpointConfig.Builder builder = cloneConfigWithoutConfigurator(); - builder.configurator(masterConfigurator); - clientEndpointConfig = builder.build(); - } - } - - protected ClientEndpointConfig.Builder cloneConfigWithoutConfigurator() { - ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder - .create(); - builder.decoders(clientEndpointConfig.getDecoders()); - builder.encoders(clientEndpointConfig.getEncoders()); - builder.extensions(clientEndpointConfig.getExtensions()); - builder - .preferredSubprotocols(clientEndpointConfig.getPreferredSubprotocols()); - return builder; - } - - protected ClientEndpointConfig.Configurator createMasterConfigurator() { - ClientEndpointConfig.Configurator master = new ClientEndpointConfig.Configurator() { - final ClientEndpointConfig.Configurator original = clientEndpointConfig - .getConfigurator(); - - @Override - public void afterResponse(HandshakeResponse hr) { - if (configurators != null) - for (ClientEndpointConfig.Configurator configurator : configurators) - configurator.afterResponse(hr); - if (original != null) - original.afterResponse(hr); - } - - @Override - public void beforeRequest(Map> headers) { - if (configurators != null) - for (ClientEndpointConfig.Configurator configurator : configurators) - configurator.beforeRequest(headers); - if (original != null) - original.beforeRequest(headers); - - if (true) - printHeaders(headers); - } - - void printHeaders(Map> headers) { - for (Entry> set : headers.entrySet()) - logMsg(set.getKey(), ":", - WebSocketCommonClient.objectsToString(set.getValue().toArray())); - } - }; - return master; - } - - protected EndpointCallback createMasterEndpointCallback() { - EndpointCallback master = new EndpointCallback() { - EndpointCallback original = clientCallback == null - ? new SendMessageCallback(client.entity) - : clientCallback; - - @Override - public void onOpen(Session session, EndpointConfig config) { - original.onOpen(session, config); - for (EndpointCallback callback : slaveClientCallbacks) - callback.onOpen(session, config); - } - - @Override - public void onMessage(Object o) { - original.onMessage(o); - for (EndpointCallback callback : slaveClientCallbacks) - callback.onMessage(o); - } - - @Override - public void onError(Session session, Throwable t) { - original.onError(session, t); - for (EndpointCallback callback : slaveClientCallbacks) - callback.onError(session, t); - } - - @Override - public void onClose(Session session, CloseReason closeReason) { - original.onClose(session, closeReason); - for (EndpointCallback callback : slaveClientCallbacks) - callback.onClose(session, closeReason); - } - }; - return master; - } - - protected void verifyValidationStrategy() { - // If no strategy instance is available (strange, but has happened), - // fail. - try { - getStrategy(); - } catch (NullPointerException e) { - throw new IllegalStateException("[FATAL] No Validator available."); - } - } - - protected void verifySettings() throws TestFailureException { - if (client.getContextRoot() == null) - throw new TestFailureException("No resource url request set"); - } - - protected void awaitCountDown() { - logTrace("Setting CountDownLatch to", client._ws_wait, - "seconds, should be hit", countDownLatchCount, "times"); - ClientEndpointData.awaitCountDown(client._ws_wait); - } - - protected void newCountDown() { - ClientEndpointData.newCountDown(countDownLatchCount); - } - - // --------------------------------------------------------------------- - // Apache adaptor methods - - @Override - public HttpRequest getRequest() { - if (super.getRequest() == null) { - super.setRequest(new ApacheRequestAdapter(client.requestProtocol, - client.TEST_PROPS.get(Property.REQUEST), client._hostname, - client._port)); - } - return super.getRequest(); - } - - @Override - public HttpResponse getResponse() { - if (_response == null) { - _response = new ApacheResponseAdapter(client._hostname, client._port, - textCaser); - } - return _response; - } - - // ---------------------------------------------------------------------- - /** - * Sets the validation strategy for this test case instance. - * - * @param validator - * - the fully qualified class name of the response validator to use. - */ - @Override - public void setStrategy(String validator) { - ValidationStrategy strat = ValidationFactory.getInstance(validator); - if (strat != null) { - strategy = strat; - } else { - StringBuilder sb = new StringBuilder(); - sb.append("[WebTestCase][WARNING] An attempt was made to use a "); - sb.append("non-existing validator ("); - sb.append(validator); - sb.append("). Falling back to the TokenizedValidator"); - TestUtil.logMsg(sb.toString()); - } - } - - // --------------------------- Getters & setters -------------------------- - protected TextCaser getTextCaser() { - return textCaser; - } - - /** - * set ClientEndpoint class. This endpoint class can be overriden by client - * endpoint instance set by {@link #setClientEndpointInstance} - */ - protected void setClientEndpoint( - Class> endpoint) { - this.endpoint = endpoint; - } - - /** - * The ClientEndpoint instance. It holds precedence over ClientEndpoint class - * set by {@link #setClientEndpoint} - */ - protected void setClientEndpointInstance(ClientEndpoint endpointInstance) { - this.endpointInstance = endpointInstance; - } - - /** - * The annotated client endpoint alternative to ClientEndpoint instance. It - * has precedence over ClientEndpoint class set by {@link #setClientEndpoint} - */ - protected void setAnnotatedClientEndpoint( - AnnotatedClientEndpoint annotatedEndpoint) { - this.annotatedEndpoint = annotatedEndpoint; - } - - protected void setCountDownLatchCount(int countDownLatchCount) { - this.countDownLatchCount = countDownLatchCount; - } - - protected int getCountDownLatchTotalCount() { - return countDownLatchCount; - } - - protected long getCountDownLatchRemainingHits() { - long hits = ClientEndpointData.getCount(); - return hits; - } - - protected void setCallback(EndpointCallback callback) { - this.clientCallback = callback; - } - - protected void addClientCallback(EndpointCallback callback) { - this.slaveClientCallbacks.add(callback); - } - - protected Session getSession() { - return session; - } - - protected String getResponseAsString() { - return ClientEndpoint.getMessageBuilder().toString(); - } - - @SuppressWarnings({ "unchecked", "unused" }) - protected T getLastResponse(Class type) { - return (T) ClientEndpointData.lastMessage; - } - - protected void // - setClientEndpointConfig(ClientEndpointConfig clientEndpointConfig) { - this.clientEndpointConfig = clientEndpointConfig; - } - - protected void addClientConfigurator( - ClientEndpointConfig.Configurator config) { - this.configurators.add(config); - } - - protected void printClientCall(boolean printClientCall) { - this.printClientCall = printClientCall; - } - - static void logMsg(Object... msg) { - WebSocketCommonClient.logMsg("[WebSocketCommonClient]", msg); - } - - static void logTrace(Object... msg) { - WebSocketCommonClient.logTrace("[WebSocketCommonClient]", msg); - } - - protected ClientEndpointConfig getEndpointConfig() { - return clientEndpointConfig; - } + /** + * Apache HTTP response mock + */ + protected HttpResponse _response; + + /** + * A reference to WebSocketCommonClient, holder of properties needed to build + * request + */ + protected WebSocketCommonClient client; + + /** + * A reference to ClientEndpoint, a websocket endpoint the messages are passed + * into it + */ + protected Class> endpoint = StringClientEndpoint.class; + + /** + * An Instance to ClientEndpoint, a websocket endpoint the messages are passed + * into it + */ + protected ClientEndpoint endpointInstance = null; + + /** + * An annotated endpoint, in this implementation merely a bridge to + * ClientEndpoint, to be sure the annotated methods are called and also to have + * all the EndpointCallbacks working there + */ + protected AnnotatedClientEndpoint annotatedEndpoint = null; + + /** + * A single master callback to be used in client end point + */ + protected volatile EndpointCallback clientCallback = null; + + /* + * Callbacks to be added to a given master callback or to a default + * SendMessageCallback master callback if no master callback is provided + */ + protected List slaveClientCallbacks = null; + + /** + * Upper case, lower case, or exact text matching? + */ + protected TextCaser textCaser = TextCaser.NONE; + + /** + * Strategy to use when validating the test case against the server's response. + */ + protected ValidationStrategy strategy = null; + + /** + * The WebSocket Session Object to be addressed from test + */ + protected volatile Session session; + + /** + * Count Down Latch Count + */ + protected int countDownLatchCount = 1; + + /** + * ClientEndpointConfig to be used + */ + protected ClientEndpointConfig clientEndpointConfig = null; + + protected List configurators = null; + + /** + * Flag to enable client call logging + */ + protected boolean printClientCall = false; + + // --------------------------------------------------------------------- + public WebSocketTestCase(WebSocketCommonClient client) { + super(); + this.client = client; + clientEndpointConfig = ClientEndpointConfig.Builder.create().build(); + strategy = ValidationFactory.getInstance(TOKENIZED_STRATEGY); + configurators = new LinkedList<>(); + slaveClientCallbacks = new LinkedList<>(); + ClientEndpointData.resetData(); + logTrace("A new test case has been created"); + } + + /** + * Executes the test case. + * + * @throws TestFailureException if the test fails for any reason. + * @throws IllegalStateException if no request was configured or if no Validator + * is available at runtime. + */ + @Override + public void execute() throws TestFailureException { + verifyValidationStrategy(); + verifySettings(); + addAllConfiguratorsToClientEndpointConfig(); + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + String path = client.TEST_PROPS.get(Property.REQUEST); + if (printClientCall) + logTrace("\n-----------\n", printClientCall(), "-----------\n"); + logMsg("Connecting to", path); + if (slaveClientCallbacks.size() != 0) + clientCallback = createMasterEndpointCallback(); + if (client.entity != null) { + if (clientCallback != null) + ClientEndpointData.callback = clientCallback; + else + ClientEndpointData.callback = new SendMessageCallback(client.entity); + } + client.setupWebSocketContainerBeforeConnect(clientContainer); + newCountDown(); + session = connectToServer(clientContainer, path); + awaitCountDown(); + } catch (Throwable t) { + String message = t.getMessage(); + + StringBuilder sb = new StringBuilder(); + sb.append("[FATAL] Unexpected failure during test execution.\n"); + // print client call code to report into JIRA when needed + if (client.logExceptionOnInvoke) + sb.append(printClientCall().toString()); + // Inherited message + sb.append((message == null ? t.toString() : message)); + + throw new TestFailureException(sb.toString(), t); + } + } + + /** + * Validate this test case instance + * + * @throws TestFailureException + */ + protected void validate() throws TestFailureException { + if (!strategy.validate(this)) { + throw new TestFailureException("Test FAILED!"); + } + } + + /** + * Logging method for internal purposes + */ + protected StringBuilder printClientCall() { + StringBuilder sb = new StringBuilder(); + if (client.entity != null && client.entity.isInstance(String.class)) { + sb.append("class ").append(endpoint.getSimpleName()); + sb.append(" extends Endpoint implements MessageHandler.Whole"); + sb.append(" {\n"); + sb.append(" public void onOpen(Session session, EndpointConfig config) {\n"); + sb.append(" session.addMessageHandler(this);\n"); + sb.append(" RemoteEndpoint.Basic endpoint = session.getBasicRemote();\n"); + sb.append(" try {\n"); + sb.append(" endpoint.sendText(\""); + sb.append(client.entity.getEntityAt(String.class, 0)); + sb.append("\");\n"); + sb.append(" } catch (IOException e) {\n"); + sb.append(" throw new RuntimeException(e);\n"); + sb.append(" }\n"); + sb.append(" }\n"); + sb.append(" public void onMessage(String message) {\n"); + sb.append(" System.out.println(message);\n"); + sb.append(" messageLatch.countDown()"); + sb.append(" }\n"); + sb.append("};\n"); + } + sb.append("CountDownLatch messageLatch;\n"); + sb.append("public void test() {\n"); + sb.append(" WebSocketContainer clientContainer = ContainerProvider"); + sb.append(".getWebSocketContainer();\n"); + sb.append(" messageLatch = new CountDownLatch("); + sb.append(countDownLatchCount).append(");\n"); + sb.append(" Session session = clientContainer.connectToServer("); + sb.append(endpoint.getSimpleName()).append(".class,\n"); + sb.append(" "); + sb.append("ClientEndpointConfig.Builder.create()"); + Configurator configurator = clientEndpointConfig.getConfigurator(); + if (configurator != null) + sb.append(".config(new ").append(configurator.getClass().getName()).append("())"); + sb.append(".build(),\n"); + sb.append(" "); + sb.append("new URI(\"").append(client.TEST_PROPS.get(Property.REQUEST)); + sb.append("\"));\n"); + sb.append(" messageLatch.await(").append(client._ws_wait); + sb.append(", TimeUnit.SECONDS);\n"); + sb.append("}\n"); + + return sb; + } + + protected Session connectToServer(WebSocketContainer clientContainer, String path) throws Exception { + WebSocketCommonClient.assertTrue(endpointInstance == null || annotatedEndpoint == null, + "Either a ClientEndpoint instance or Annotated endpoint can be used, not both"); + + if (annotatedEndpoint != null) + session = clientContainer.connectToServer(annotatedEndpoint, new URI(path)); + else if (endpointInstance != null) + session = clientContainer.connectToServer(endpointInstance, clientEndpointConfig, new URI(path)); + else + session = clientContainer.connectToServer(endpoint, clientEndpointConfig, new URI(path)); + logTrace("Connection session id:", session.getId()); + return session; + } + + protected void addAllConfiguratorsToClientEndpointConfig() { + if (!configurators.isEmpty()) { + ClientEndpointConfig.Configurator masterConfigurator = createMasterConfigurator(); + ClientEndpointConfig.Builder builder = cloneConfigWithoutConfigurator(); + builder.configurator(masterConfigurator); + clientEndpointConfig = builder.build(); + } + } + + protected ClientEndpointConfig.Builder cloneConfigWithoutConfigurator() { + ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create(); + builder.decoders(clientEndpointConfig.getDecoders()); + builder.encoders(clientEndpointConfig.getEncoders()); + builder.extensions(clientEndpointConfig.getExtensions()); + builder.preferredSubprotocols(clientEndpointConfig.getPreferredSubprotocols()); + return builder; + } + + protected ClientEndpointConfig.Configurator createMasterConfigurator() { + ClientEndpointConfig.Configurator master = new ClientEndpointConfig.Configurator() { + final ClientEndpointConfig.Configurator original = clientEndpointConfig.getConfigurator(); + + @Override + public void afterResponse(HandshakeResponse hr) { + if (configurators != null) + for (ClientEndpointConfig.Configurator configurator : configurators) + configurator.afterResponse(hr); + if (original != null) + original.afterResponse(hr); + } + + @Override + public void beforeRequest(Map> headers) { + if (configurators != null) + for (ClientEndpointConfig.Configurator configurator : configurators) + configurator.beforeRequest(headers); + if (original != null) + original.beforeRequest(headers); + + if (true) + printHeaders(headers); + } + + void printHeaders(Map> headers) { + for (Entry> set : headers.entrySet()) + logMsg(set.getKey(), ":", WebSocketCommonClient.objectsToString(set.getValue().toArray())); + } + }; + return master; + } + + protected EndpointCallback createMasterEndpointCallback() { + EndpointCallback master = new EndpointCallback() { + EndpointCallback original = clientCallback == null ? new SendMessageCallback(client.entity) + : clientCallback; + + @Override + public void onOpen(Session session, EndpointConfig config) { + original.onOpen(session, config); + for (EndpointCallback callback : slaveClientCallbacks) + callback.onOpen(session, config); + } + + @Override + public void onMessage(Object o) { + original.onMessage(o); + for (EndpointCallback callback : slaveClientCallbacks) + callback.onMessage(o); + } + + @Override + public void onError(Session session, Throwable t) { + original.onError(session, t); + for (EndpointCallback callback : slaveClientCallbacks) + callback.onError(session, t); + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + original.onClose(session, closeReason); + for (EndpointCallback callback : slaveClientCallbacks) + callback.onClose(session, closeReason); + } + }; + return master; + } + + protected void verifyValidationStrategy() { + // If no strategy instance is available (strange, but has happened), + // fail. + try { + getStrategy(); + } catch (NullPointerException e) { + throw new IllegalStateException("[FATAL] No Validator available."); + } + } + + protected void verifySettings() throws TestFailureException { + if (client.getContextRoot() == null) + throw new TestFailureException("No resource url request set"); + } + + protected void awaitCountDown() { + logTrace("Setting CountDownLatch to", client._ws_wait, "seconds, should be hit", countDownLatchCount, "times"); + ClientEndpointData.awaitCountDown(client._ws_wait); + } + + protected void newCountDown() { + ClientEndpointData.newCountDown(countDownLatchCount); + } + + // --------------------------------------------------------------------- + // Apache adaptor methods + + @Override + public HttpRequest getRequest() { + if (super.getRequest() == null) { + super.setRequest(new ApacheRequestAdapter(client.requestProtocol, client.TEST_PROPS.get(Property.REQUEST), + client._hostname, client._port)); + } + return super.getRequest(); + } + + @Override + public HttpResponse getResponse() { + if (_response == null) { + _response = new ApacheResponseAdapter(client._hostname, client._port, textCaser); + } + return _response; + } + + // ---------------------------------------------------------------------- + /** + * Sets the validation strategy for this test case instance. + * + * @param validator - the fully qualified class name of the response validator + * to use. + */ + @Override + public void setStrategy(String validator) { + ValidationStrategy strat = ValidationFactory.getInstance(validator); + if (strat != null) { + strategy = strat; + } else { + StringBuilder sb = new StringBuilder(); + sb.append("[WebTestCase][WARNING] An attempt was made to use a "); + sb.append("non-existing validator ("); + sb.append(validator); + sb.append("). Falling back to the TokenizedValidator"); + TestUtil.logMsg(sb.toString()); + } + } + + // --------------------------- Getters & setters -------------------------- + protected TextCaser getTextCaser() { + return textCaser; + } + + /** + * set ClientEndpoint class. This endpoint class can be overriden by client + * endpoint instance set by {@link #setClientEndpointInstance} + */ + protected void setClientEndpoint(Class> endpoint) { + this.endpoint = endpoint; + } + + /** + * The ClientEndpoint instance. It holds precedence over ClientEndpoint class + * set by {@link #setClientEndpoint} + */ + protected void setClientEndpointInstance(ClientEndpoint endpointInstance) { + this.endpointInstance = endpointInstance; + } + + /** + * The annotated client endpoint alternative to ClientEndpoint instance. It has + * precedence over ClientEndpoint class set by {@link #setClientEndpoint} + */ + protected void setAnnotatedClientEndpoint(AnnotatedClientEndpoint annotatedEndpoint) { + this.annotatedEndpoint = annotatedEndpoint; + } + + protected void setCountDownLatchCount(int countDownLatchCount) { + this.countDownLatchCount = countDownLatchCount; + } + + protected int getCountDownLatchTotalCount() { + return countDownLatchCount; + } + + protected long getCountDownLatchRemainingHits() { + long hits = ClientEndpointData.getCount(); + return hits; + } + + protected void setCallback(EndpointCallback callback) { + this.clientCallback = callback; + } + + protected void addClientCallback(EndpointCallback callback) { + this.slaveClientCallbacks.add(callback); + } + + protected Session getSession() { + return session; + } + + protected String getResponseAsString() { + return ClientEndpoint.getMessageBuilder().toString(); + } + + @SuppressWarnings({ "unchecked", "unused" }) + protected T getLastResponse(Class type) { + return (T) ClientEndpointData.lastMessage; + } + + protected void // + setClientEndpointConfig(ClientEndpointConfig clientEndpointConfig) { + this.clientEndpointConfig = clientEndpointConfig; + } + + protected void addClientConfigurator(ClientEndpointConfig.Configurator config) { + this.configurators.add(config); + } + + protected void printClientCall(boolean printClientCall) { + this.printClientCall = printClientCall; + } + + static void logMsg(Object... msg) { + WebSocketCommonClient.logMsg("[WebSocketCommonClient]", msg); + } + + static void logTrace(Object... msg) { + WebSocketCommonClient.logTrace("[WebSocketCommonClient]", msg); + } + + protected ClientEndpointConfig getEndpointConfig() { + return clientEndpointConfig; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ClientConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ClientConfigurator.java index 37a6b4415f..7045e973c7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ClientConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ClientConfigurator.java @@ -31,77 +31,70 @@ public class ClientConfigurator extends Configurator { - private Map> requestMap = new TreeMap<>(); - - private Map> responseMap = new TreeMap<>(); - - private boolean hasBeenAfterResponse = false; - - private boolean hasBeenBeforeRequest = false; - - public boolean hasBeenBeforeRequest() { - return hasBeenBeforeRequest; - } - - public boolean hasBeenAfterResponse() { - return hasBeenAfterResponse; - } - - public void addToRequest(String key, String... values) { - requestMap.put(key, Arrays.asList(values)); - } - - public void addToResponse(String key, String... values) { - responseMap.put(key, Arrays.asList(values)); - } - - public void addToRequestAndResponse(String key, String... values) { - addToRequest(key, values); - addToResponse(key, values); - } - - @Override - public void beforeRequest(Map> headers) { - super.beforeRequest(headers); - for (Entry> set : requestMap.entrySet()) - headers.put(set.getKey(), set.getValue()); - hasBeenBeforeRequest = true; - } - - @Override - public void afterResponse(HandshakeResponse hr) { - super.afterResponse(hr); - Map> headers = hr.getHeaders(); - for (Entry> set : responseMap.entrySet()) { - String key = set.getKey(); - assertTrue(headers.containsKey(key), "key", key, - "was not found in HandshakeResponse headers"); - assertTrue(StringUtil.contains(headers.get(key), set.getValue(), false), - "value \"", StringUtil.collectionToString(set.getValue()), "\"", - "was not found for key", key, "only \"", - StringUtil.collectionToString(headers.get(key)), "\" has been found"); - WebSocketCommonClient.logTrace("found expected pair [", key, ",", - headers.get(key), "]"); - } - hasBeenAfterResponse = true; - } - - public void assertAfterResponseHasBeenCalled() { - assertTrue(hasBeenAfterResponse(), - "Configurator#afterResponse has not been called"); - WebSocketCommonClient - .logTrace("Configurator#afterResponse has been called as expected", ""); - } - - public void assertBeforeRequestHasBeenCalled() { - assertTrue(hasBeenBeforeRequest(), - "Configurator#beforeRequest has not been called"); - WebSocketCommonClient - .logTrace("Configurator#beforeRequest has been called as expected", ""); - } - - protected static void assertTrue(boolean t, String... msg) { - if (!t) - throw new RuntimeException(StringUtil.objectsToString((Object[]) msg)); - } + private Map> requestMap = new TreeMap<>(); + + private Map> responseMap = new TreeMap<>(); + + private boolean hasBeenAfterResponse = false; + + private boolean hasBeenBeforeRequest = false; + + public boolean hasBeenBeforeRequest() { + return hasBeenBeforeRequest; + } + + public boolean hasBeenAfterResponse() { + return hasBeenAfterResponse; + } + + public void addToRequest(String key, String... values) { + requestMap.put(key, Arrays.asList(values)); + } + + public void addToResponse(String key, String... values) { + responseMap.put(key, Arrays.asList(values)); + } + + public void addToRequestAndResponse(String key, String... values) { + addToRequest(key, values); + addToResponse(key, values); + } + + @Override + public void beforeRequest(Map> headers) { + super.beforeRequest(headers); + for (Entry> set : requestMap.entrySet()) + headers.put(set.getKey(), set.getValue()); + hasBeenBeforeRequest = true; + } + + @Override + public void afterResponse(HandshakeResponse hr) { + super.afterResponse(hr); + Map> headers = hr.getHeaders(); + for (Entry> set : responseMap.entrySet()) { + String key = set.getKey(); + assertTrue(headers.containsKey(key), "key", key, "was not found in HandshakeResponse headers"); + assertTrue(StringUtil.contains(headers.get(key), set.getValue(), false), "value \"", + StringUtil.collectionToString(set.getValue()), "\"", "was not found for key", key, "only \"", + StringUtil.collectionToString(headers.get(key)), "\" has been found"); + WebSocketCommonClient.logTrace("found expected pair [", key, ",", headers.get(key), "]"); + } + hasBeenAfterResponse = true; + } + + public void assertAfterResponseHasBeenCalled() { + assertTrue(hasBeenAfterResponse(), "Configurator#afterResponse has not been called"); + WebSocketCommonClient.logTrace("Configurator#afterResponse has been called as expected", ""); + } + + public void assertBeforeRequestHasBeenCalled() { + assertTrue(hasBeenBeforeRequest(), "Configurator#beforeRequest has not been called"); + WebSocketCommonClient.logTrace("Configurator#beforeRequest has been called as expected", ""); + } + + protected static void assertTrue(boolean t, String... msg) { + if (!t) + throw new RuntimeException(StringUtil.objectsToString((Object[]) msg)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ExtensionImpl.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ExtensionImpl.java index 90a9f3f3b7..e52724605d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ExtensionImpl.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ExtensionImpl.java @@ -32,137 +32,131 @@ */ public class ExtensionImpl implements Extension, Comparable { - protected List list = new ArrayList<>(); - - protected String name; - - protected boolean caseSensitive = false; - - public void caseSensitive(boolean caseSensitive) { - this.caseSensitive = caseSensitive; - } - - /** - * An Extension Implementation. For empty parameter list, use null - * - * @param name - * Extension name, see {@link Extension#getName()} - * @param params - * Extension Parameter list, see {@link Extension#getParameters()} - */ - public ExtensionImpl(String name, Parameter... params) { - super(); - this.name = name; - addParameters(params); - } - - public ExtensionImpl(Extension extension) { - this(extension.getName(), - extension.getParameters().toArray(new Parameter[0])); - } - - public void addParameters(Parameter... params) { - if (params != null) - for (Parameter param : params) - list.add(param); - } - - @Override - public String getName() { - return name; - } - - @Override - public List getParameters() { - return list; - } - - @Override - public int compareTo(Extension o) { - int cmp = caseSensitive ? name.compareTo(o.getName()) - : name.compareToIgnoreCase(o.getName()); - if (cmp != 0) - return cmp; - cmp = getParameters().size() - o.getParameters().size(); - if (cmp != 0) - return (int) Math.signum(cmp); - - List newThisList = getExtensionParameters(this); - List newOtherList = getExtensionParameters(o); - Collections.sort(newThisList); - Collections.sort(newOtherList); - Iterator i = newThisList.iterator(); - Iterator j = newOtherList.iterator(); - while (i.hasNext() && cmp == 0) { - ExtensionParameterImpl iItem = i.next(); - ExtensionParameterImpl jItem = j.next(); - cmp = iItem.compareTo(jItem); - } - return cmp; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Extension) - return compareTo((Extension) obj) == 0; - return false; - } - - @Override - public int hashCode() { - return toString().hashCode(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder().append(getClass().getSimpleName()) - .append("(name=\"").append(name).append("\", parameters=["); - for (Parameter p : getExtensionParameters(this)) - sb.append(p.toString()).append(","); - sb.append("])"); - return sb.toString(); - } - - /** - * Can pass VI of Extension to have tck impl of Extension.Parameter list - */ - public List getExtensionParameters( - Extension extension) { - List params = new ArrayList<>(); - for (Parameter item : extension.getParameters()) - params.add(new ExtensionParameterImpl(item, caseSensitive)); - Collections.sort(params); - return params; - } - - /** - * Transform list of VI Extensions to List of TCK impl of Extension - * - * @param extensions - * @return - */ - public static List transformToImpl( - List extensions) { - List list = new ArrayList<>(); - if (extensions != null) - for (Extension ex : extensions) - list.add(new ExtensionImpl(ex)); - // do not sort, the order of extensions is significant - // (rfc6455#section-9.1) - return list; - } - - /** - * For proper output, make sure the list contains ExtensionImpl items, see - * {@link #transformToImpl(List)}, otherwise the output depends on overridden - * {@linkplain #toString()} of given Extensions - */ - public static String toString(List list) { - StringBuilder sb = new StringBuilder().append("{"); - if (list != null) - for (Extension ex : list) - sb.append(ex.toString()).append(";"); - sb.append("}"); - return sb.toString(); - } + protected List list = new ArrayList<>(); + + protected String name; + + protected boolean caseSensitive = false; + + public void caseSensitive(boolean caseSensitive) { + this.caseSensitive = caseSensitive; + } + + /** + * An Extension Implementation. For empty parameter list, use null + * + * @param name Extension name, see {@link Extension#getName()} + * @param params Extension Parameter list, see {@link Extension#getParameters()} + */ + public ExtensionImpl(String name, Parameter... params) { + super(); + this.name = name; + addParameters(params); + } + + public ExtensionImpl(Extension extension) { + this(extension.getName(), extension.getParameters().toArray(new Parameter[0])); + } + + public void addParameters(Parameter... params) { + if (params != null) + for (Parameter param : params) + list.add(param); + } + + @Override + public String getName() { + return name; + } + + @Override + public List getParameters() { + return list; + } + + @Override + public int compareTo(Extension o) { + int cmp = caseSensitive ? name.compareTo(o.getName()) : name.compareToIgnoreCase(o.getName()); + if (cmp != 0) + return cmp; + cmp = getParameters().size() - o.getParameters().size(); + if (cmp != 0) + return (int) Math.signum(cmp); + + List newThisList = getExtensionParameters(this); + List newOtherList = getExtensionParameters(o); + Collections.sort(newThisList); + Collections.sort(newOtherList); + Iterator i = newThisList.iterator(); + Iterator j = newOtherList.iterator(); + while (i.hasNext() && cmp == 0) { + ExtensionParameterImpl iItem = i.next(); + ExtensionParameterImpl jItem = j.next(); + cmp = iItem.compareTo(jItem); + } + return cmp; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Extension) + return compareTo((Extension) obj) == 0; + return false; + } + + @Override + public int hashCode() { + return toString().hashCode(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder().append(getClass().getSimpleName()).append("(name=\"").append(name) + .append("\", parameters=["); + for (Parameter p : getExtensionParameters(this)) + sb.append(p.toString()).append(","); + sb.append("])"); + return sb.toString(); + } + + /** + * Can pass VI of Extension to have tck impl of Extension.Parameter list + */ + public List getExtensionParameters(Extension extension) { + List params = new ArrayList<>(); + for (Parameter item : extension.getParameters()) + params.add(new ExtensionParameterImpl(item, caseSensitive)); + Collections.sort(params); + return params; + } + + /** + * Transform list of VI Extensions to List of TCK impl of Extension + * + * @param extensions + * @return + */ + public static List transformToImpl(List extensions) { + List list = new ArrayList<>(); + if (extensions != null) + for (Extension ex : extensions) + list.add(new ExtensionImpl(ex)); + // do not sort, the order of extensions is significant + // (rfc6455#section-9.1) + return list; + } + + /** + * For proper output, make sure the list contains ExtensionImpl items, see + * {@link #transformToImpl(List)}, otherwise the output depends on overridden + * {@linkplain #toString()} of given Extensions + */ + public static String toString(List list) { + StringBuilder sb = new StringBuilder().append("{"); + if (list != null) + for (Extension ex : list) + sb.append(ex.toString()).append(";"); + sb.append("}"); + return sb.toString(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ExtensionParameterImpl.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ExtensionParameterImpl.java index a07f90cf40..f4df6cdb76 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ExtensionParameterImpl.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/ExtensionParameterImpl.java @@ -25,76 +25,70 @@ * RFC 2616 says : Field names are case-insensitive, the default is case * insensitive. */ -public class ExtensionParameterImpl - implements Parameter, Comparable { - - public ExtensionParameterImpl(String name, String value) { - super(); - this.name = name; - this.value = value; - } - - /** - * @param caseSensitive - * states whether compares case sensitively or not - */ - public ExtensionParameterImpl(String name, String value, - boolean caseSensitive) { - this(name, value); - } - - public ExtensionParameterImpl(Parameter param, boolean caseSensitive) { - this(param.getName(), param.getValue(), caseSensitive); - } - - protected String name; - - protected String value; - - protected boolean caseSensitive = false; - - public void caseSensitive(boolean caseSensitive) { - this.caseSensitive = caseSensitive; - } - - @Override - public String getName() { - return name; - } - - @Override - public String getValue() { - return value; - } - - @Override - public int compareTo(Parameter o) { - int cmp1 = caseSensitive ? name.compareTo(o.getName()) - : name.compareToIgnoreCase(o.getName()); - int cmp2 = caseSensitive ? value.compareTo(o.getValue()) - : value.compareToIgnoreCase(o.getValue()); - return cmp1 == 0 ? cmp2 : cmp1; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Parameter) - return compareTo((Parameter) obj) == 0; - else - return false; - } - - @Override - public int hashCode() { - return toString().hashCode(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder().append(getClass().getSimpleName()) - .append("(name=\"").append(name).append("\", value=\"").append(value) - .append("\")"); - return sb.toString(); - } +public class ExtensionParameterImpl implements Parameter, Comparable { + + public ExtensionParameterImpl(String name, String value) { + super(); + this.name = name; + this.value = value; + } + + /** + * @param caseSensitive states whether compares case sensitively or not + */ + public ExtensionParameterImpl(String name, String value, boolean caseSensitive) { + this(name, value); + } + + public ExtensionParameterImpl(Parameter param, boolean caseSensitive) { + this(param.getName(), param.getValue(), caseSensitive); + } + + protected String name; + + protected String value; + + protected boolean caseSensitive = false; + + public void caseSensitive(boolean caseSensitive) { + this.caseSensitive = caseSensitive; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getValue() { + return value; + } + + @Override + public int compareTo(Parameter o) { + int cmp1 = caseSensitive ? name.compareTo(o.getName()) : name.compareToIgnoreCase(o.getName()); + int cmp2 = caseSensitive ? value.compareTo(o.getValue()) : value.compareToIgnoreCase(o.getValue()); + return cmp1 == 0 ? cmp2 : cmp1; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Parameter) + return compareTo((Parameter) obj) == 0; + else + return false; + } + + @Override + public int hashCode() { + return toString().hashCode(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder().append(getClass().getSimpleName()).append("(name=\"").append(name) + .append("\", value=\"").append(value).append("\")"); + return sb.toString(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/StringPingMessage.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/StringPingMessage.java index 681629633a..b5fa6980a2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/StringPingMessage.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/StringPingMessage.java @@ -26,7 +26,7 @@ */ public class StringPingMessage extends StringPongMessage { - public StringPingMessage(String message) { - super(message); - } + public StringPingMessage(String message) { + super(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/StringPongMessage.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/StringPongMessage.java index 8bace46b9c..2df8813237 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/StringPongMessage.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/StringPongMessage.java @@ -23,17 +23,17 @@ public class StringPongMessage implements PongMessage { - protected String message; - - public StringPongMessage(String message) { - if (message.length() > 125) - throw new RuntimeException("StringPongMessage is too long"); - this.message = message; - } - - @Override - public ByteBuffer getApplicationData() { - return ByteBuffer.wrap(message.getBytes()); - } + protected String message; + + public StringPongMessage(String message) { + if (message.length() > 125) + throw new RuntimeException("StringPongMessage is too long"); + this.message = message; + } + + @Override + public ByteBuffer getApplicationData() { + return ByteBuffer.wrap(message.getBytes()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/WaitingSendHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/WaitingSendHandler.java index d5f14dfc95..cf8d5b2661 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/WaitingSendHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/impl/WaitingSendHandler.java @@ -30,31 +30,31 @@ * The main goal is to pass SendHandler object to a caller code */ public class WaitingSendHandler implements SendHandler { - private volatile CountDownLatch latch; - - private volatile SendResult result = null; - - public WaitingSendHandler() { - latch = new CountDownLatch(1); - } - - public SendResult waitForResult(long seconds) { - try { - latch.await(seconds, TimeUnit.SECONDS); - } catch (InterruptedException e) { - throw new RuntimeException("Wait has been interrupted", e); - } - if (latch != null && latch.getCount() != 0) - throw new IllegalStateException("onResult has not been called on time"); - if (result == null) - throw new IllegalStateException("SendResult is null"); - return result; - } - - @Override - public void onResult(SendResult result) { - this.result = result; - latch.countDown(); - } + private volatile CountDownLatch latch; + + private volatile SendResult result = null; + + public WaitingSendHandler() { + latch = new CountDownLatch(1); + } + + public SendResult waitForResult(long seconds) { + try { + latch.await(seconds, TimeUnit.SECONDS); + } catch (InterruptedException e) { + throw new RuntimeException("Wait has been interrupted", e); + } + if (latch != null && latch.getCount() != 0) + throw new IllegalStateException("onResult has not been called on time"); + if (result == null) + throw new IllegalStateException("SendResult is null"); + return result; + } + + @Override + public void onResult(SendResult result) { + this.result = result; + latch.countDown(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/io/StringInputStream.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/io/StringInputStream.java index 5e28867b73..2b31e3fa1b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/io/StringInputStream.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/io/StringInputStream.java @@ -20,7 +20,7 @@ public class StringInputStream extends ByteArrayInputStream { - public StringInputStream(String string) { - super(string.getBytes()); - } + public StringInputStream(String string) { + super(string.getBytes()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/io/StringReader.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/io/StringReader.java index 3b8b21c412..4c2ecaffad 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/io/StringReader.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/io/StringReader.java @@ -20,8 +20,8 @@ public class StringReader extends InputStreamReader { - public StringReader(String string) { - super(new StringInputStream(string)); - } + public StringReader(String string) { + super(new StringInputStream(string)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBean.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBean.java index e50d426e3f..d213759fcd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBean.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBean.java @@ -22,23 +22,23 @@ * mutable string. */ public class StringBean { - private String value; + private String value; - public String get() { - return value; - } + public String get() { + return value; + } - public void set(String value) { - this.value = value; - } + public void set(String value) { + this.value = value; + } - @Override - public String toString() { - return "StringBean. To get a value, use rather #get() method."; - } + @Override + public String toString() { + return "StringBean. To get a value, use rather #get() method."; + } - public StringBean(String value) { - super(); - this.value = value; - } + public StringBean(String value) { + super(); + this.value = value; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryDecoder.java index e12959add4..107e523fed 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryDecoder.java @@ -25,21 +25,21 @@ public class StringBeanBinaryDecoder implements Binary { - @Override - public void init(EndpointConfig config) { - } - - @Override - public StringBean decode(ByteBuffer arg0) throws DecodeException { - return new StringBean(new String(arg0.array())); - } - - @Override - public boolean willDecode(ByteBuffer arg0) { - return true; - } - - @Override - public void destroy() { - } + @Override + public void init(EndpointConfig config) { + } + + @Override + public StringBean decode(ByteBuffer arg0) throws DecodeException { + return new StringBean(new String(arg0.array())); + } + + @Override + public boolean willDecode(ByteBuffer arg0) { + return true; + } + + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryEncoder.java index 9da3a5f308..f15374486c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryEncoder.java @@ -25,16 +25,16 @@ public class StringBeanBinaryEncoder implements Binary { - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public ByteBuffer encode(StringBean bean) throws EncodeException { - return ByteBuffer.wrap(bean.get().getBytes()); - } + @Override + public ByteBuffer encode(StringBean bean) throws EncodeException { + return ByteBuffer.wrap(bean.get().getBytes()); + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryStreamDecoder.java index 14ddb80a4c..10a983f60e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryStreamDecoder.java @@ -28,18 +28,17 @@ public class StringBeanBinaryStreamDecoder implements BinaryStream { - @Override - public void init(EndpointConfig config) { - } - - @Override - public StringBean decode(InputStream arg0) - throws DecodeException, IOException { - String data = IOUtil.readFromStream(arg0); - return new StringBean(data); - } - - @Override - public void destroy() { - } + @Override + public void init(EndpointConfig config) { + } + + @Override + public StringBean decode(InputStream arg0) throws DecodeException, IOException { + String data = IOUtil.readFromStream(arg0); + return new StringBean(data); + } + + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryStreamEncoder.java index 677a5e5a2a..ac32c2cb8b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanBinaryStreamEncoder.java @@ -26,17 +26,16 @@ public class StringBeanBinaryStreamEncoder implements BinaryStream { - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public void encode(StringBean bean, OutputStream stream) - throws EncodeException, IOException { - stream.write(bean.get().getBytes()); - } + @Override + public void encode(StringBean bean, OutputStream stream) throws EncodeException, IOException { + stream.write(bean.get().getBytes()); + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanClientEndpoint.java index f3760e6946..71eca293ca 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanClientEndpoint.java @@ -19,8 +19,8 @@ import com.sun.ts.tests.websocket.common.client.ClientEndpoint; public class StringBeanClientEndpoint extends ClientEndpoint { - @Override - protected void appendMessage(StringBean message) { - getMessageBuilder().append(message.get()); - } + @Override + protected void appendMessage(StringBean message) { + getMessageBuilder().append(message.get()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextDecoder.java index bcd2c472fb..2323911a1e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextDecoder.java @@ -23,21 +23,21 @@ public class StringBeanTextDecoder implements Text { - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public StringBean decode(String s) throws DecodeException { - return new StringBean(s); - } + @Override + public StringBean decode(String s) throws DecodeException { + return new StringBean(s); + } - @Override - public boolean willDecode(String s) { - return true; - } + @Override + public boolean willDecode(String s) { + return true; + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextEncoder.java index 14bdfaf76a..d244ba8954 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextEncoder.java @@ -23,16 +23,16 @@ public class StringBeanTextEncoder implements Text { - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public String encode(StringBean bean) throws EncodeException { - return bean.get(); - } + @Override + public String encode(StringBean bean) throws EncodeException { + return bean.get(); + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextStreamDecoder.java index a0cb2a8969..fef9557184 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextStreamDecoder.java @@ -28,17 +28,17 @@ public class StringBeanTextStreamDecoder implements TextStream { - @Override - public void init(EndpointConfig config) { - } - - @Override - public StringBean decode(Reader r) throws DecodeException, IOException { - String text = IOUtil.readFromReader(r); - return new StringBean(text); - } - - @Override - public void destroy() { - } + @Override + public void init(EndpointConfig config) { + } + + @Override + public StringBean decode(Reader r) throws DecodeException, IOException { + String text = IOUtil.readFromReader(r); + return new StringBean(text); + } + + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextStreamEncoder.java index c530557a1d..5a4a29362e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/stringbean/StringBeanTextStreamEncoder.java @@ -26,17 +26,16 @@ public class StringBeanTextStreamEncoder implements TextStream { - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public void encode(StringBean bean, Writer writer) - throws EncodeException, IOException { - writer.append(bean.get()); - } + @Override + public void encode(StringBean bean, Writer writer) throws EncodeException, IOException { + writer.append(bean.get()); + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/BooleanDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/BooleanDecoder.java index 59b85cc73b..2d699039bd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/BooleanDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/BooleanDecoder.java @@ -26,21 +26,21 @@ public class BooleanDecoder implements Decoder.Text { - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public Boolean decode(String s) throws DecodeException { - return Boolean.valueOf(s); - } + @Override + public Boolean decode(String s) throws DecodeException { + return Boolean.valueOf(s); + } - @Override - public boolean willDecode(String s) { - return true; - } + @Override + public boolean willDecode(String s) { + return true; + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/BooleanEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/BooleanEncoder.java index 33644fad45..68d18307ec 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/BooleanEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/BooleanEncoder.java @@ -26,17 +26,17 @@ public class BooleanEncoder implements Encoder.Text { - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public String encode(Boolean b) throws EncodeException { + @Override + public String encode(Boolean b) throws EncodeException { - return b.toString(); - } + return b.toString(); + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/ByteDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/ByteDecoder.java index 6f089ca1b9..11b025d575 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/ByteDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/ByteDecoder.java @@ -26,21 +26,21 @@ public class ByteDecoder implements Decoder.Text { - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public Byte decode(String s) throws DecodeException { - return Byte.valueOf(s); - } + @Override + public Byte decode(String s) throws DecodeException { + return Byte.valueOf(s); + } - @Override - public boolean willDecode(String s) { - return true; - } + @Override + public boolean willDecode(String s) { + return true; + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/ErrorEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/ErrorEncoder.java index 35bc74338c..507ee4428c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/ErrorEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/ErrorEncoder.java @@ -26,16 +26,16 @@ public class ErrorEncoder implements Encoder.Text { - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public String encode(String data) throws EncodeException { - throw new EncodeException("Something went horribly wrong", data); - } + @Override + public String encode(String data) throws EncodeException { + throw new EncodeException("Something went horribly wrong", data); + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/IOUtil.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/IOUtil.java index 82a0c1f671..1e7db68e63 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/IOUtil.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/IOUtil.java @@ -30,48 +30,47 @@ */ public abstract class IOUtil { - public static final// - String readFromReader(Reader reader) throws IOException { - BufferedReader br = new BufferedReader(reader); - StringBuilder sb = new StringBuilder(); - String line = null; - while ((line = br.readLine()) != null) { - if (sb.length() != 0) - sb.append("\n"); - sb.append(line); - } - br.close(); - return sb.toString(); - } + public static final// + String readFromReader(Reader reader) throws IOException { + BufferedReader br = new BufferedReader(reader); + StringBuilder sb = new StringBuilder(); + String line = null; + while ((line = br.readLine()) != null) { + if (sb.length() != 0) + sb.append("\n"); + sb.append(line); + } + br.close(); + return sb.toString(); + } - public static final// - String printStackTrace(Throwable t) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - t.printStackTrace(pw); - String value = sw.toString(); - pw.close(); - return value; - } + public static final// + String printStackTrace(Throwable t) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + t.printStackTrace(pw); + String value = sw.toString(); + pw.close(); + return value; + } - public static final// - String readFromStream(InputStream stream) throws IOException { - InputStreamReader isr = new InputStreamReader(stream); - return readFromReader(isr); - } + public static final// + String readFromStream(InputStream stream) throws IOException { + InputStreamReader isr = new InputStreamReader(stream); + return readFromReader(isr); + } - public static final// - String byteBufferToString(ByteBuffer buffer) { - byte[] ret = new byte[buffer.remaining()]; + public static final// + String byteBufferToString(ByteBuffer buffer) { + byte[] ret = new byte[buffer.remaining()]; - if (buffer.hasArray()) { - byte[] array = buffer.array(); - System.arraycopy(array, buffer.arrayOffset() + buffer.position(), ret, 0, - ret.length); - } else { - buffer.asReadOnlyBuffer().get(ret); - } + if (buffer.hasArray()) { + byte[] array = buffer.array(); + System.arraycopy(array, buffer.arrayOffset() + buffer.position(), ret, 0, ret.length); + } else { + buffer.asReadOnlyBuffer().get(ret); + } - return new String(ret); - } + return new String(ret); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/MessageValidator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/MessageValidator.java index 2c6663d575..0c7ed4846d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/MessageValidator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/MessageValidator.java @@ -26,52 +26,48 @@ public class MessageValidator { - public static boolean checkSearchStrings(String expected, String actual) - throws IOException { + public static boolean checkSearchStrings(String expected, String actual) throws IOException { - List list = new ArrayList<>(); - StringTokenizer st = new StringTokenizer(expected, "|"); - while (st.hasMoreTokens()) { - list.add(st.nextToken()); - } + List list = new ArrayList<>(); + StringTokenizer st = new StringTokenizer(expected, "|"); + while (st.hasMoreTokens()) { + list.add(st.nextToken()); + } - boolean found = true; - if (list != null && actual != null) { + boolean found = true; + if (list != null && actual != null) { - String search = null; + String search = null; - for (int i = 0, n = list.size(), startIdx = 0, acLength = actual - .length(); i < n; i++) { + for (int i = 0, n = list.size(), startIdx = 0, acLength = actual.length(); i < n; i++) { - // set the startIdx to the same value as the actual message length - // and let the test fail (prevents index based runtime exceptions). - if (startIdx >= acLength) { - startIdx = acLength; - } + // set the startIdx to the same value as the actual message length + // and let the test fail (prevents index based runtime exceptions). + if (startIdx >= acLength) { + startIdx = acLength; + } - search = (String) list.get(i); - int searchIdx = actual.indexOf(search, startIdx); - System.out - .println("[MessageValidator] Scanning for " + "search string: '" - + search + "' starting at index " + "location: " + startIdx); - if (searchIdx < 0) { - found = false; - StringBuffer sb = new StringBuffer(1024); - sb.append("[MessageValidator] Unable to find the following "); - sb.append("search string"); - sb.append(search).append("' at index: "); - sb.append(startIdx); - System.err.println(sb.toString()); - break; - } + search = (String) list.get(i); + int searchIdx = actual.indexOf(search, startIdx); + System.out.println("[MessageValidator] Scanning for " + "search string: '" + search + + "' starting at index " + "location: " + startIdx); + if (searchIdx < 0) { + found = false; + StringBuffer sb = new StringBuffer(1024); + sb.append("[MessageValidator] Unable to find the following "); + sb.append("search string"); + sb.append(search).append("' at index: "); + sb.append(startIdx); + System.err.println(sb.toString()); + break; + } - System.out.println("[MessageValidator] Found search string: '" + search - + "' at index '" + searchIdx); - // the new searchIdx is the old index plus the lenght of the - // search string. - startIdx = searchIdx + search.length(); - } - } - return found; - } + System.out.println("[MessageValidator] Found search string: '" + search + "' at index '" + searchIdx); + // the new searchIdx is the old index plus the lenght of the + // search string. + startIdx = searchIdx + search.length(); + } + } + return found; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/SessionUtil.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/SessionUtil.java index 60dfa1b049..b4feb62b06 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/SessionUtil.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/SessionUtil.java @@ -21,21 +21,21 @@ public class SessionUtil { - private SessionUtil() { - } + private SessionUtil() { + } - public static void waitUntilClosed(Session session, long timeout, TimeUnit unit) { - long timeoutMillis = unit.toMillis(timeout); - while (session.isOpen() && timeoutMillis > 0) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - // Clear the interrupt flag - Thread.interrupted(); - // Exit the loop - break; - } - timeoutMillis -= 100; - } - } + public static void waitUntilClosed(Session session, long timeout, TimeUnit unit) { + long timeoutMillis = unit.toMillis(timeout); + while (session.isOpen() && timeoutMillis > 0) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // Clear the interrupt flag + Thread.interrupted(); + // Exit the loop + break; + } + timeoutMillis -= 100; + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/StringUtil.java b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/StringUtil.java index 5cf7618f19..4f5760c974 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/StringUtil.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/common/util/StringUtil.java @@ -25,186 +25,167 @@ public class StringUtil { - public static final String WEBSOCKET_SUBPROTOCOLS_0 = "MBWS.huawei.com"; - - public static final String WEBSOCKET_SUBPROTOCOLS_1 = "MBLWS.huawei.com"; - - public static final String WEBSOCKET_SUBPROTOCOLS_2 = "soap"; - - public static final String WEBSOCKET_SUBPROTOCOLS_3 = "wamp"; - - public static final String WEBSOCKET_SUBPROTOCOLS_4 = "v10.stomp"; - - public static final String WEBSOCKET_SUBPROTOCOLS_5 = "v11.stomp"; - - public static final String WEBSOCKET_SUBPROTOCOLS_6 = "v12.stomp"; - - public static final String WEBSOCKET_SUBPROTOCOLS_7 = "ocpp1.2"; - - public static final String WEBSOCKET_SUBPROTOCOLS_8 = "ocpp1.5"; - - public static final String WEBSOCKET_SUBPROTOCOLS_9 = "ocpp2.0"; - - /** - * Registered subprotocols From IANA WebSocket Protocol Registries - * http://www.iana.org/assignments/websocket/websocket.xml - */ - public static final String[] WEBSOCKET_SUBPROTOCOLS = { - WEBSOCKET_SUBPROTOCOLS_0, WEBSOCKET_SUBPROTOCOLS_1, - WEBSOCKET_SUBPROTOCOLS_2, WEBSOCKET_SUBPROTOCOLS_3, - WEBSOCKET_SUBPROTOCOLS_4, WEBSOCKET_SUBPROTOCOLS_5, - WEBSOCKET_SUBPROTOCOLS_6, WEBSOCKET_SUBPROTOCOLS_7, - WEBSOCKET_SUBPROTOCOLS_8, WEBSOCKET_SUBPROTOCOLS_9 }; - - /** - * @param objects - * to be put in a sentence - * @return objects in a single string , each object separated by " " - */ - public static String objectsToString(Object... objects) { - return objectsToStringWithDelimiter(" ", objects); - } - - public static String objectsToStringWithDelimiter(String delimiter, - Object... objects) { - StringBuilder sb = new StringBuilder(); - if (objects != null) - for (Object o : objects) { - if (o.getClass().isArray()) - sb.append(objectsToStringWithDelimiter(delimiter, (Object[]) o)); - else if (Collection.class.isInstance(o)) - sb.append( - collectionToStringWithDelimiter(delimiter, (Collection) o)); - else - sb.append(o).append(delimiter); - } - return sb.toString().trim(); - } - - /** - * @param objects - * to be put in a sentence - * @return objects in a single string , each object separated by delimiter - */ - public static String collectionToStringWithDelimiter(String delimiter, - Collection objects) { - return objects == null ? "" - : objectsToStringWithDelimiter(delimiter, objects.toArray()); - } - - /** - * @param objects - * to be put in a sentence - * @return objects in a single string , each object separated by " " - */ - public static String collectionToString(Collection objects) { - return collectionToStringWithDelimiter(" ", objects); - } - - /** - * Check that every single String in one List is contained in other List - * - * @param where - * The other list where String items are searched - * @param what - * List of String items that are searched in the other List - * @param caseSensitive - * define whether the occurrence of Strings is case sensitive - * @return true iff every single item in {@link where} List is in {@link what} - * List - */ - public static boolean // - contains(List where, List what, boolean caseSensitive) { - // do not use slow and memory consuming contains(List where, List - // what) - String whereInOne = objectsToStringWithDelimiter("", where); - if (!caseSensitive) - whereInOne = whereInOne.toLowerCase(); - for (String whatItem : what) { - boolean found = false; - if (caseSensitive) - found = whereInOne.contains(whatItem); - else - found = whereInOne.contains(whatItem.toLowerCase()); - if (!found) - return false; - } - return true; - } - - /** - * Check that every single T in one List is contained in other List - * - * @param where - * The other list where T items are searched - * @param what - * List of T items that are searched in the other List - * @param comparator - * see {@link Comparator} - * @return true iff every single item in {@link where} List is in {@link what} - * List - */ - public static boolean // - contains(List where, List what, Comparator comparator) { - where = new ArrayList<>(where); // new collection not to affect - what = new ArrayList<>(what); // the original by sorting - Collections.sort(what, comparator); - Collections.sort(where, comparator); - Iterator j = where.iterator(); - for (Iterator i = what.iterator(); i.hasNext();) { - T whatItem = i.next(); - T whereItem; - do { - if (!j.hasNext()) - return false; - whereItem = j.next(); - } while (comparator.compare(whatItem, whereItem) != 0); - } - return true; - } - - /** - * Check that every single T in one List is contained in other List - * - * @param where - * The other list where T items are searched - * @param what - * List of T items that are searched in the other List - * @return true iff every single item in {@link where} List is in {@link what} - * List - */ - public static > // - boolean contains(List where, List what) { - where = new ArrayList<>(where); // new collection not to affect - what = new ArrayList<>(what); // the original by sorting - Collections.sort(what); - Collections.sort(where); - return containsInOrder(where, what); - } - - /** - * Check that every single T in one List is contained in other List in given - * order - * - * @param where - * The other list where T items are searched - * @param what - * List of T items that are searched in the other List - * @return true iff every single item in {@link where} List is in {@link what} - * List - */ - public static > // - boolean containsInOrder(List where, List what) { - Iterator j = where.iterator(); - for (Iterator i = what.iterator(); i.hasNext();) { - T whatItem = i.next(); - T whereItem; - do { - if (!j.hasNext()) - return false; - whereItem = j.next(); - } while (whatItem.compareTo(whereItem) != 0); - } - return true; - } + public static final String WEBSOCKET_SUBPROTOCOLS_0 = "MBWS.huawei.com"; + + public static final String WEBSOCKET_SUBPROTOCOLS_1 = "MBLWS.huawei.com"; + + public static final String WEBSOCKET_SUBPROTOCOLS_2 = "soap"; + + public static final String WEBSOCKET_SUBPROTOCOLS_3 = "wamp"; + + public static final String WEBSOCKET_SUBPROTOCOLS_4 = "v10.stomp"; + + public static final String WEBSOCKET_SUBPROTOCOLS_5 = "v11.stomp"; + + public static final String WEBSOCKET_SUBPROTOCOLS_6 = "v12.stomp"; + + public static final String WEBSOCKET_SUBPROTOCOLS_7 = "ocpp1.2"; + + public static final String WEBSOCKET_SUBPROTOCOLS_8 = "ocpp1.5"; + + public static final String WEBSOCKET_SUBPROTOCOLS_9 = "ocpp2.0"; + + /** + * Registered subprotocols From IANA WebSocket Protocol Registries + * http://www.iana.org/assignments/websocket/websocket.xml + */ + public static final String[] WEBSOCKET_SUBPROTOCOLS = { WEBSOCKET_SUBPROTOCOLS_0, WEBSOCKET_SUBPROTOCOLS_1, + WEBSOCKET_SUBPROTOCOLS_2, WEBSOCKET_SUBPROTOCOLS_3, WEBSOCKET_SUBPROTOCOLS_4, WEBSOCKET_SUBPROTOCOLS_5, + WEBSOCKET_SUBPROTOCOLS_6, WEBSOCKET_SUBPROTOCOLS_7, WEBSOCKET_SUBPROTOCOLS_8, WEBSOCKET_SUBPROTOCOLS_9 }; + + /** + * @param objects to be put in a sentence + * @return objects in a single string , each object separated by " " + */ + public static String objectsToString(Object... objects) { + return objectsToStringWithDelimiter(" ", objects); + } + + public static String objectsToStringWithDelimiter(String delimiter, Object... objects) { + StringBuilder sb = new StringBuilder(); + if (objects != null) + for (Object o : objects) { + if (o.getClass().isArray()) + sb.append(objectsToStringWithDelimiter(delimiter, (Object[]) o)); + else if (Collection.class.isInstance(o)) + sb.append(collectionToStringWithDelimiter(delimiter, (Collection) o)); + else + sb.append(o).append(delimiter); + } + return sb.toString().trim(); + } + + /** + * @param objects to be put in a sentence + * @return objects in a single string , each object separated by delimiter + */ + public static String collectionToStringWithDelimiter(String delimiter, Collection objects) { + return objects == null ? "" : objectsToStringWithDelimiter(delimiter, objects.toArray()); + } + + /** + * @param objects to be put in a sentence + * @return objects in a single string , each object separated by " " + */ + public static String collectionToString(Collection objects) { + return collectionToStringWithDelimiter(" ", objects); + } + + /** + * Check that every single String in one List is contained in other List + * + * @param where The other list where String items are searched + * @param what List of String items that are searched in the other List + * @param caseSensitive define whether the occurrence of Strings is case + * sensitive + * @return true iff every single item in {@link where} List is in {@link what} + * List + */ + public static boolean // + contains(List where, List what, boolean caseSensitive) { + // do not use slow and memory consuming contains(List where, List + // what) + String whereInOne = objectsToStringWithDelimiter("", where); + if (!caseSensitive) + whereInOne = whereInOne.toLowerCase(); + for (String whatItem : what) { + boolean found = false; + if (caseSensitive) + found = whereInOne.contains(whatItem); + else + found = whereInOne.contains(whatItem.toLowerCase()); + if (!found) + return false; + } + return true; + } + + /** + * Check that every single T in one List is contained in other List + * + * @param where The other list where T items are searched + * @param what List of T items that are searched in the other List + * @param comparator see {@link Comparator} + * @return true iff every single item in {@link where} List is in {@link what} + * List + */ + public static boolean // + contains(List where, List what, Comparator comparator) { + where = new ArrayList<>(where); // new collection not to affect + what = new ArrayList<>(what); // the original by sorting + Collections.sort(what, comparator); + Collections.sort(where, comparator); + Iterator j = where.iterator(); + for (Iterator i = what.iterator(); i.hasNext();) { + T whatItem = i.next(); + T whereItem; + do { + if (!j.hasNext()) + return false; + whereItem = j.next(); + } while (comparator.compare(whatItem, whereItem) != 0); + } + return true; + } + + /** + * Check that every single T in one List is contained in other List + * + * @param where The other list where T items are searched + * @param what List of T items that are searched in the other List + * @return true iff every single item in {@link where} List is in {@link what} + * List + */ + public static > // + boolean contains(List where, List what) { + where = new ArrayList<>(where); // new collection not to affect + what = new ArrayList<>(what); // the original by sorting + Collections.sort(what); + Collections.sort(where); + return containsInOrder(where, what); + } + + /** + * Check that every single T in one List is contained in other List in given + * order + * + * @param where The other list where T items are searched + * @param what List of T items that are searched in the other List + * @return true iff every single item in {@link where} List is in {@link what} + * List + */ + public static > // + boolean containsInOrder(List where, List what) { + Iterator j = where.iterator(); + for (Iterator i = what.iterator(); i.hasNext();) { + T whatItem = i.next(); + T whereItem; + do { + if (!j.hasNext()) + return false; + whereItem = j.next(); + } while (whatItem.compareTo(whereItem) != 0); + } + return true; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/ClientConfiguratorHolderClientConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/ClientConfiguratorHolderClientConfigurator.java index cb2a5e2008..b4025ddc6e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/ClientConfiguratorHolderClientConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/ClientConfiguratorHolderClientConfigurator.java @@ -21,20 +21,19 @@ /** * The findbugs compliant ClientConfigurator accessible out of WebSocket impl */ -public class ClientConfiguratorHolderClientConfigurator - extends ClientConfigurator { - private static ClientConfigurator configurator; +public class ClientConfiguratorHolderClientConfigurator extends ClientConfigurator { + private static ClientConfigurator configurator; - public ClientConfiguratorHolderClientConfigurator() { - super(); - ClientConfiguratorHolderClientConfigurator.setConfigurator(this); - } + public ClientConfiguratorHolderClientConfigurator() { + super(); + ClientConfiguratorHolderClientConfigurator.setConfigurator(this); + } - static ClientConfigurator getConfigurator() { - return configurator; - } + static ClientConfigurator getConfigurator() { + return configurator; + } - private static void setConfigurator(ClientConfigurator configurator) { - ClientConfiguratorHolderClientConfigurator.configurator = configurator; - } + private static void setConfigurator(ClientConfigurator configurator) { + ClientConfiguratorHolderClientConfigurator.configurator = configurator; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/GetNegotiatedSubprotocolConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/GetNegotiatedSubprotocolConfigurator.java index 5de1a5b5e1..3d9bcbb5aa 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/GetNegotiatedSubprotocolConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/GetNegotiatedSubprotocolConfigurator.java @@ -22,43 +22,41 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class GetNegotiatedSubprotocolConfigurator extends Configurator { - private static List supported; + private static List supported; - private static List requested; + private static List requested; - private static String resulted; + private static String resulted; - @Override - public String getNegotiatedSubprotocol(List supported, - List requested) { - GetNegotiatedSubprotocolConfigurator.setRequested(requested); - GetNegotiatedSubprotocolConfigurator.setSupported(supported); - GetNegotiatedSubprotocolConfigurator - .setResulted(super.getNegotiatedSubprotocol(supported, requested)); - return GetNegotiatedSubprotocolConfigurator.getResulted(); - } + @Override + public String getNegotiatedSubprotocol(List supported, List requested) { + GetNegotiatedSubprotocolConfigurator.setRequested(requested); + GetNegotiatedSubprotocolConfigurator.setSupported(supported); + GetNegotiatedSubprotocolConfigurator.setResulted(super.getNegotiatedSubprotocol(supported, requested)); + return GetNegotiatedSubprotocolConfigurator.getResulted(); + } - static List getSupported() { - return supported; - } + static List getSupported() { + return supported; + } - static List getRequested() { - return requested; - } + static List getRequested() { + return requested; + } - static String getResulted() { - return resulted; - } + static String getResulted() { + return resulted; + } - private static void setSupported(List supported) { - GetNegotiatedSubprotocolConfigurator.supported = supported; - } + private static void setSupported(List supported) { + GetNegotiatedSubprotocolConfigurator.supported = supported; + } - private static void setRequested(List requested) { - GetNegotiatedSubprotocolConfigurator.requested = requested; - } + private static void setRequested(List requested) { + GetNegotiatedSubprotocolConfigurator.requested = requested; + } - private static void setResulted(String resulted) { - GetNegotiatedSubprotocolConfigurator.resulted = resulted; - } + private static void setResulted(String resulted) { + GetNegotiatedSubprotocolConfigurator.resulted = resulted; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/OPS.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/OPS.java index f4f7573cf9..4cb728a8b7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/OPS.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/OPS.java @@ -17,5 +17,5 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.clientendpoint; public enum OPS { - ECHO_MSG, THROW, NEGOTIATED; + ECHO_MSG, THROW, NEGOTIATED; } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCCloseClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCCloseClientEndpoint.java index 0c5d9dc5f8..e1963e49cd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCCloseClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCCloseClientEndpoint.java @@ -34,46 +34,46 @@ @ClientEndpoint public class WSCCloseClientEndpoint extends AnnotatedClientEndpoint { - boolean onCloseCalled = false; + boolean onCloseCalled = false; - CountDownLatch countDown = new CountDownLatch(1); + CountDownLatch countDown = new CountDownLatch(1); - public WSCCloseClientEndpoint() { - super(new StringClientEndpoint()); - } + public WSCCloseClientEndpoint() { + super(new StringClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - onCloseCalled = true; - countDown.countDown(); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + onCloseCalled = true; + countDown.countDown(); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - public void waitForClose(long seconds) { - try { - countDown.await(seconds, TimeUnit.SECONDS); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } + public void waitForClose(long seconds) { + try { + countDown.await(seconds, TimeUnit.SECONDS); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCConfiguratedClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCConfiguratedClientEndpoint.java index 916034ad65..afc2954b67 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCConfiguratedClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCConfiguratedClientEndpoint.java @@ -30,35 +30,34 @@ import jakarta.websocket.Session; @ClientEndpoint(configurator = ClientConfiguratorHolderClientConfigurator.class) -public class WSCConfiguratedClientEndpoint - extends AnnotatedClientEndpoint { - - public WSCConfiguratedClientEndpoint() { - super(new StringClientEndpoint()); - } - - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } +public class WSCConfiguratedClientEndpoint extends AnnotatedClientEndpoint { + + public WSCConfiguratedClientEndpoint() { + super(new StringClientEndpoint()); + } + + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCEchoServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCEchoServer.java index 81baaa2c9f..985468e955 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCEchoServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCEchoServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,17 +29,17 @@ @ServerEndpoint("/echo") public class WSCEchoServer { - @OnMessage - public String echo(String echo) { - return echo; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo) { + return echo; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCErrorClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCErrorClientEndpoint.java index 712432570d..5d405cfba2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCErrorClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCErrorClientEndpoint.java @@ -32,48 +32,48 @@ @ClientEndpoint public class WSCErrorClientEndpoint extends AnnotatedClientEndpoint { - private static final String EXCEPTION = "TCK test throwable"; + private static final String EXCEPTION = "TCK test throwable"; - boolean onErrorCalled = false; + boolean onErrorCalled = false; - public WSCErrorClientEndpoint() { - super(new StringClientEndpoint()); - } + public WSCErrorClientEndpoint() { + super(new StringClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - OPS op = OPS.valueOf(msg); - switch (op) { - case THROW: - throw new RuntimeException(EXCEPTION); - default: - break; - } - } + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + OPS op = OPS.valueOf(msg); + switch (op) { + case THROW: + throw new RuntimeException(EXCEPTION); + default: + break; + } + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String msg = WebSocketCommonClient.getCauseMessage(t); - if (EXCEPTION.equals(msg)) { - onErrorCalled = true; - getCountDownLatch().countDown(); - } else - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String msg = WebSocketCommonClient.getCauseMessage(t); + if (EXCEPTION.equals(msg)) { + onErrorCalled = true; + getCountDownLatch().countDown(); + } else + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCMatchedSubprotocolClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCMatchedSubprotocolClientEndpoint.java index 1524dfbb9f..8980cc26c5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCMatchedSubprotocolClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCMatchedSubprotocolClientEndpoint.java @@ -30,37 +30,35 @@ import jakarta.websocket.OnOpen; import jakarta.websocket.Session; -@ClientEndpoint(subprotocols = { StringUtil.WEBSOCKET_SUBPROTOCOLS_1, - StringUtil.WEBSOCKET_SUBPROTOCOLS_2 }) -public class WSCMatchedSubprotocolClientEndpoint - extends AnnotatedClientEndpoint { +@ClientEndpoint(subprotocols = { StringUtil.WEBSOCKET_SUBPROTOCOLS_1, StringUtil.WEBSOCKET_SUBPROTOCOLS_2 }) +public class WSCMatchedSubprotocolClientEndpoint extends AnnotatedClientEndpoint { - public WSCMatchedSubprotocolClientEndpoint() { - super(new StringClientEndpoint()); - } + public WSCMatchedSubprotocolClientEndpoint() { + super(new StringClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCSubprotocolServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCSubprotocolServer.java index 8486a44322..50545cd18c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCSubprotocolServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCSubprotocolServer.java @@ -27,33 +27,30 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/subprotocol", subprotocols = { - StringUtil.WEBSOCKET_SUBPROTOCOLS_0, - StringUtil.WEBSOCKET_SUBPROTOCOLS_1 }, configurator = GetNegotiatedSubprotocolConfigurator.class) +@ServerEndpoint(value = "/subprotocol", subprotocols = { StringUtil.WEBSOCKET_SUBPROTOCOLS_0, + StringUtil.WEBSOCKET_SUBPROTOCOLS_1 }, configurator = GetNegotiatedSubprotocolConfigurator.class) public class WSCSubprotocolServer { - @OnMessage - public String echo(String msg) { - OPS op = OPS.valueOf(msg); - switch (op) { - case ECHO_MSG: - break; - case NEGOTIATED: - msg = "{" + GetNegotiatedSubprotocolConfigurator.getResulted().trim() - + "}"; - break; - default: - throw new IllegalArgumentException( - "Operation" + msg + "has not been implemented"); - } - return msg; - } + @OnMessage + public String echo(String msg) { + OPS op = OPS.valueOf(msg); + switch (op) { + case ECHO_MSG: + break; + case NEGOTIATED: + msg = "{" + GetNegotiatedSubprotocolConfigurator.getResulted().trim() + "}"; + break; + default: + throw new IllegalArgumentException("Operation" + msg + "has not been implemented"); + } + return msg; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCUnmatchedSubprotocolClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCUnmatchedSubprotocolClientEndpoint.java index 2aeb6ebb96..7d116c3742 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCUnmatchedSubprotocolClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSCUnmatchedSubprotocolClientEndpoint.java @@ -30,37 +30,35 @@ import jakarta.websocket.OnOpen; import jakarta.websocket.Session; -@ClientEndpoint(subprotocols = { StringUtil.WEBSOCKET_SUBPROTOCOLS_3, - StringUtil.WEBSOCKET_SUBPROTOCOLS_4 }) -public class WSCUnmatchedSubprotocolClientEndpoint - extends AnnotatedClientEndpoint { +@ClientEndpoint(subprotocols = { StringUtil.WEBSOCKET_SUBPROTOCOLS_3, StringUtil.WEBSOCKET_SUBPROTOCOLS_4 }) +public class WSCUnmatchedSubprotocolClientEndpoint extends AnnotatedClientEndpoint { - public WSCUnmatchedSubprotocolClientEndpoint() { - super(new StringClientEndpoint()); - } + public WSCUnmatchedSubprotocolClientEndpoint() { + super(new StringClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSClient.java deleted file mode 100644 index f5bbe35d8d..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSClient.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.clientendpoint; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; -import com.sun.ts.tests.websocket.common.util.StringUtil; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = 5512614247407170347L; - - public WSClient() { - setContextRoot("wsc_ee_clientendpoint_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - /* - * @testName: subprotocolsMatchTest - * - * @assertion_ids: WebSocket:JAVADOC:4; - * - * @test_Strategy: ClientEndpoint.subprotocols - * - * when there is a subprotocol match, the server responds - */ - public void subprotocolsMatchTest() throws Exception { - WSCMatchedSubprotocolClientEndpoint endpoint = new WSCMatchedSubprotocolClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - invoke("subprotocol", OPS.NEGOTIATED, StringUtil.WEBSOCKET_SUBPROTOCOLS_1); - } - - /* - * @testName: subprotocolsNotMatchTest - * - * @assertion_ids: WebSocket:JAVADOC:4; - * - * @test_Strategy: ClientEndpoint.subprotocols when there is NOT a subprotocol - * match, the server responds as well - */ - public void subprotocolsNotMatchTest() throws Exception { - WSCUnmatchedSubprotocolClientEndpoint endpoint = new WSCUnmatchedSubprotocolClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - invoke("subprotocol", OPS.NEGOTIATED, "{}"); - } - - /* - * @testName: configuratorTest - * - * @assertion_ids: WebSocket:JAVADOC:1; WebSocket:JAVADOC:5; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:16; WebSocket:JAVADOC:17; - * - * @test_Strategy: ClientEndpoint.configurator - * ClientEndpointConfig.getConfigurator - * ClientEndpointConfig.Configurator.afterResponse - * ClientEndpointConfig.Configurator.beforeRequest - * ClientEndpointConfig.Configurator.ClientEndpointConfig.Configurator - */ - public void configuratorTest() throws Exception { - WSCConfiguratedClientEndpoint endpoint = new WSCConfiguratedClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - invoke("echo", OPS.ECHO_MSG, OPS.ECHO_MSG); - ClientConfigurator configurator = ClientConfiguratorHolderClientConfigurator - .getConfigurator(); - configurator.assertBeforeRequestHasBeenCalled(); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: onErrorWorksTest - * - * @assertion_ids: WebSocket:JAVADOC:1; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.2.4-1; - * - * @test_Strategy: check @OnError works on Client Endpoint - * - * The method level @OnOpen and @OnClose annotations allow the developers to - * decorate methods on their - * - * @ServerEndpoint annotated Java class to specify that they must be called by - * the implementation when the resulting endpoint receives a new connection - * from a peer or when a connection from a peer is closed, respectively. - * - * @OnMessage annotation allows the developer to indicate which methods the - * implementation must call when a message is received. - * - * @OnError annotation to mark one of its methods must be called by the - * implementation with information about the error whenever such an error - * occurs - */ - public void onErrorWorksTest() throws Exception { - WSCErrorClientEndpoint endpoint = new WSCErrorClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - invoke("echo", OPS.ECHO_MSG, OPS.ECHO_MSG); - assertFalse(endpoint.onErrorCalled, - "@OnError has been unexpectedly called"); - - setCountDownLatchCount(2); - setAnnotatedClientEndpoint(endpoint); - invoke("echo", OPS.THROW, OPS.THROW); - assertTrue(endpoint.onErrorCalled, - "@OnError has NOT been called after RuntimeException is thrown on @OnMessage"); - logMsg( - "@OnError has been called after RuntimeException is thrown on @OnMessage as expected"); - } - - /* - * @testName: onCloseWorksTest - * - * @assertion_ids: WebSocket:JAVADOC:1; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: check @OnClose works on Client Endpoint - * - * The method level @OnOpen and @OnClose annotations allow the developers to - * decorate methods on their - * - * @ServerEndpoint annotated Java class to specify that they must be called by - * the implementation when the resulting endpoint receives a new connection - * from a peer or when a connection from a peer is closed, respectively. - * - * @OnMessage annotation allows the developer to indicate which methods the - * implementation must call when a message is received. - */ - public void onCloseWorksTest() throws Exception { - WSCCloseClientEndpoint endpoint = new WSCCloseClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - invoke("echo", OPS.ECHO_MSG.name(), OPS.ECHO_MSG.name(), false); - assertFalse(endpoint.onCloseCalled, - "@OnClose has been unexpectedly called"); - cleanup(); - endpoint.waitForClose(_ws_wait); - assertTrue(endpoint.onCloseCalled, - "@OnClose has NOT been called after session.close()"); - logMsg("@OnClose has been called after session.close() as expected"); - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSClientIT.java new file mode 100644 index 0000000000..22a2aae0dd --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpoint/WSClientIT.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.clientendpoint; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.common.util.StringUtil; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = 5512614247407170347L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_clientendpoint_web.war"); + archive.addClasses(GetNegotiatedSubprotocolConfigurator.class, OPS.class, WSCEchoServer.class, + WSCSubprotocolServer.class); + + archive.addClasses(IOUtil.class, StringUtil.class); + + return archive; + } + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_clientendpoint_web"); + } + + /* Run test */ + /* + * @testName: subprotocolsMatchTest + * + * @assertion_ids: WebSocket:JAVADOC:4; + * + * @test_Strategy: ClientEndpoint.subprotocols + * + * when there is a subprotocol match, the server responds + */ + @Test + public void subprotocolsMatchTest() throws Exception { + WSCMatchedSubprotocolClientEndpoint endpoint = new WSCMatchedSubprotocolClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + invoke("subprotocol", OPS.NEGOTIATED, StringUtil.WEBSOCKET_SUBPROTOCOLS_1); + } + + /* + * @testName: subprotocolsNotMatchTest + * + * @assertion_ids: WebSocket:JAVADOC:4; + * + * @test_Strategy: ClientEndpoint.subprotocols when there is NOT a subprotocol + * match, the server responds as well + */ + @Test + public void subprotocolsNotMatchTest() throws Exception { + WSCUnmatchedSubprotocolClientEndpoint endpoint = new WSCUnmatchedSubprotocolClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + invoke("subprotocol", OPS.NEGOTIATED, "{}"); + } + + /* + * @testName: configuratorTest + * + * @assertion_ids: WebSocket:JAVADOC:1; WebSocket:JAVADOC:5; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:16; WebSocket:JAVADOC:17; + * + * @test_Strategy: ClientEndpoint.configurator + * ClientEndpointConfig.getConfigurator + * ClientEndpointConfig.Configurator.afterResponse + * ClientEndpointConfig.Configurator.beforeRequest + * ClientEndpointConfig.Configurator.ClientEndpointConfig.Configurator + */ + @Test + public void configuratorTest() throws Exception { + WSCConfiguratedClientEndpoint endpoint = new WSCConfiguratedClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + invoke("echo", OPS.ECHO_MSG, OPS.ECHO_MSG); + ClientConfigurator configurator = ClientConfiguratorHolderClientConfigurator.getConfigurator(); + configurator.assertBeforeRequestHasBeenCalled(); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: onErrorWorksTest + * + * @assertion_ids: WebSocket:JAVADOC:1; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.2.4-1; + * + * @test_Strategy: check @OnError works on Client Endpoint + * + * The method level @OnOpen and @OnClose annotations allow the developers to + * decorate methods on their + * + * @ServerEndpoint annotated Java class to specify that they must be called by + * the implementation when the resulting endpoint receives a new connection from + * a peer or when a connection from a peer is closed, respectively. + * + * @OnMessage annotation allows the developer to indicate which methods the + * implementation must call when a message is received. + * + * @OnError annotation to mark one of its methods must be called by the + * implementation with information about the error whenever such an error occurs + */ + @Test + public void onErrorWorksTest() throws Exception { + WSCErrorClientEndpoint endpoint = new WSCErrorClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + invoke("echo", OPS.ECHO_MSG, OPS.ECHO_MSG); + assertFalse(endpoint.onErrorCalled, "@OnError has been unexpectedly called"); + + setCountDownLatchCount(2); + setAnnotatedClientEndpoint(endpoint); + invoke("echo", OPS.THROW, OPS.THROW); + assertTrue(endpoint.onErrorCalled, + "@OnError has NOT been called after RuntimeException is thrown on @OnMessage"); + logMsg("@OnError has been called after RuntimeException is thrown on @OnMessage as expected"); + } + + /* + * @testName: onCloseWorksTest + * + * @assertion_ids: WebSocket:JAVADOC:1; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: check @OnClose works on Client Endpoint + * + * The method level @OnOpen and @OnClose annotations allow the developers to + * decorate methods on their + * + * @ServerEndpoint annotated Java class to specify that they must be called by + * the implementation when the resulting endpoint receives a new connection from + * a peer or when a connection from a peer is closed, respectively. + * + * @OnMessage annotation allows the developer to indicate which methods the + * implementation must call when a message is received. + */ + @Test + public void onCloseWorksTest() throws Exception { + WSCCloseClientEndpoint endpoint = new WSCCloseClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + invoke("echo", OPS.ECHO_MSG.name(), OPS.ECHO_MSG.name(), false); + assertFalse(endpoint.onCloseCalled, "@OnClose has been unexpectedly called"); + cleanup(); + endpoint.waitForClose(_ws_wait); + assertTrue(endpoint.onCloseCalled, "@OnClose has NOT been called after session.close()"); + logMsg("@OnClose has been called after session.close() as expected"); + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/WSClient.java deleted file mode 100644 index aa40fd1c3f..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/WSClient.java +++ /dev/null @@ -1,887 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates and others. - * 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 - */ - -/* - * $Id:$ - */ -package com.sun.ts.tests.websocket.ee.jakarta.websocket.clientendpointconfig; - -import java.io.IOException; -import java.io.PrintWriter; -import java.net.URI; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import com.sun.javatest.Status; -import com.sun.ts.tests.websocket.common.TCKExtension; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.util.MessageValidator; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.CloseReason; -import jakarta.websocket.ContainerProvider; -import jakarta.websocket.Decoder; -import jakarta.websocket.Encoder; -import jakarta.websocket.Endpoint; -import jakarta.websocket.EndpointConfig; -import jakarta.websocket.Extension; -import jakarta.websocket.HandshakeResponse; -import jakarta.websocket.MessageHandler; -import jakarta.websocket.Session; -import jakarta.websocket.WebSocketContainer; - -public class WSClient extends WebSocketCommonClient { - - private static final String CONTEXT_ROOT = "/ws_ee_clientendpointconfig_web"; - - private static StringBuffer receivedMessageString = new StringBuffer(); - - static volatile CountDownLatch messageLatch; - - public static void main(String[] args) { - WSClient theTests = new WSClient(); - Status s = theTests.run(args, new PrintWriter(System.out), - new PrintWriter(System.err)); - s.exit(); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; - */ - - /* Run test */ - /* - * @testName: constructortest - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; WebSocket:JAVADOC:28; - * WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; WebSocket:JAVADOC:123; - * WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; WebSocket:JAVADOC:136; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-3.2.1-1; - * WebSocket:SPEC:WSC-3.2.2-1; - * - * @test_Strategy: Test constructor - */ - public void constructortest() throws Exception { - boolean passed = true; - - try { - ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build(); - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - cec, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(5); - session.getBasicRemote().sendText("Dummy String Test"); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - - passed = MessageValidator.checkSearchStrings( - "Extension size=0|" - + "TCKTestServer received String:Dummy String Test|" - + "TCKTestServer: Extension size=0", - receivedMessageString.toString()); - if (receivedMessageString.indexOf("subProtocol=|") > -1) { - receivedMessageString - .append("Correct subProtocol received from client side"); - } else { - passed = false; - receivedMessageString - .append("Incorrect subProtocol received from client side"); - } - - if (receivedMessageString.indexOf("TCKTestServer: subProtocol==|") > -1) { - receivedMessageString - .append("========Correct subProtocol received from server side"); - } else { - passed = false; - receivedMessageString - .append("========Incorrect subProtocol received from server side"); - } - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - System.out.println(receivedMessageString); - - if (passed == false) { - throw new Exception( - "Test failed with incorrect values, " + receivedMessageString); - } - } - - /* - * @testName: preferredSubprotocolsTest - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:14; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; - * WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; - * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; - * WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void preferredSubprotocolsTest() throws Exception { - boolean passed = true; - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - try { - ClientEndpointConfig cec = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(expected_subprotocols).build(); - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - cec, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(5); - session.getBasicRemote().sendText("Dummy String Test"); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - - passed = MessageValidator.checkSearchStrings( - "Extension size=0|" - + "TCKTestServer received String:Dummy String Test|" - + "TCKTestServer: Extension size=0", - receivedMessageString.toString()); - if (receivedMessageString.indexOf("subProtocol=|") > -1) { - receivedMessageString - .append("Correct subProtocol received from client side"); - } else { - passed = false; - receivedMessageString - .append("Incorrect subProtocol received from client side"); - } - - if (receivedMessageString.indexOf("TCKTestServer: subProtocol==|") > -1) { - receivedMessageString - .append("========Correct subProtocol received from server side"); - } else { - passed = false; - receivedMessageString - .append("========Incorrect subProtocol received from server side"); - } - } catch (IOException ioex) { - passed = false; - ioex.printStackTrace(); - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - System.out.println(receivedMessageString); - - if (passed == false) { - throw new Exception( - "Test failed with incorrect values, " + receivedMessageString); - } - } - - /* - * @testName: extensionsTest - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:13; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; - * WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; - * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; - * WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void extensionsTest() throws Exception { - boolean passed = true; - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ClientEndpointConfig cec = ClientEndpointConfig.Builder.create() - .extensions(extensions).build(); - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - cec, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(5); - session.getBasicRemote().sendText("Dummy String Test"); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - - passed = MessageValidator.checkSearchStrings( - "TCKTestServer received String:Dummy String Test", - receivedMessageString.toString()); - - if (receivedMessageString.indexOf("Extension size=0") > -1 - || receivedMessageString.indexOf("Extension size=1") > -1 - || receivedMessageString.indexOf("Extension size=2") > -1) { - receivedMessageString - .append("Correct Extensions received from client side"); - } else { - passed = false; - receivedMessageString - .append("Incorrect Extensions received from client side"); - } - - if (receivedMessageString.indexOf("TCKTestServer: Extension size=0") > -1 - || receivedMessageString - .indexOf("TCKTestServer: Extension size=1") > -1 - || receivedMessageString - .indexOf("TCKTestServer: Extension size=2") > -1) { - receivedMessageString - .append("========Correct Extensions received from server side"); - } else { - passed = false; - receivedMessageString - .append("========Incorrect Extensions received from server side"); - } - - } catch (IOException ioex) { - passed = false; - ioex.printStackTrace(); - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - System.out.println(receivedMessageString); - - if (passed == false) { - throw new Exception( - "Test failed with incorrect values, " + receivedMessageString); - } - } - - /* - * @testName: constructorTest1 - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:13; WebSocket:JAVADOC:13; WebSocket:JAVADOC:70; - * WebSocket:JAVADOC:71; WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; - * WebSocket:JAVADOC:128; WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:121; WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; - * WebSocket:JAVADOC:135; WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void constructorTest1() throws Exception { - boolean passed = true; - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ClientEndpointConfig cec = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(expected_subprotocols).extensions(extensions) - .build(); - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - cec, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(5); - session.getBasicRemote().sendText("Dummy String Test"); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - - passed = MessageValidator.checkSearchStrings( - "TCKTestServer received String:Dummy String Test", - receivedMessageString.toString()); - - if (receivedMessageString.indexOf("subProtocol=|") > -1) { - receivedMessageString - .append("Correct subProtocol received from client side"); - } else { - passed = false; - receivedMessageString - .append("Incorrect subProtocol received from client side"); - } - - if (receivedMessageString.indexOf("TCKTestServer: subProtocol==|") > -1) { - receivedMessageString - .append("========Correct subProtocol received from server side"); - } else { - passed = false; - receivedMessageString - .append("========Incorrect subProtocol received from server side"); - } - - if (receivedMessageString.indexOf("Extension size=0") > -1 - || receivedMessageString.indexOf("Extension size=1") > -1 - || receivedMessageString.indexOf("Extension size=2") > -1) { - receivedMessageString - .append("Correct Extensions received from client side"); - } else { - passed = false; - receivedMessageString - .append("Incorrect Extensions received from client side"); - } - if (receivedMessageString.indexOf("TCKTestServer: Extension size=0") > -1 - || receivedMessageString - .indexOf("TCKTestServer: Extension size=1") > -1 - || receivedMessageString - .indexOf("TCKTestServer: Extension size=2") > -1) { - receivedMessageString - .append("========Correct Extensions received from server side"); - } else { - passed = false; - receivedMessageString - .append("========Incorrect Extensions received from server side"); - } - } catch (IOException ioex) { - passed = false; - ioex.printStackTrace(); - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - System.out.println(receivedMessageString); - - if (passed == false) { - throw new Exception( - "Test failed with incorrect values, " + receivedMessageString); - } - } - - /* - * @testName: encodersTest - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:12; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; - * WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; - * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; - * WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void encodersTest() throws Exception { - boolean passed = true; - - List> expected_encoders = new ArrayList<>(); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); - - try { - ClientEndpointConfig cec = ClientEndpointConfig.Builder.create() - .encoders(expected_encoders).build(); - - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - cec, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(5); - session.getBasicRemote().sendText("Dummy String Test"); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - - passed = MessageValidator.checkSearchStrings( - "EndpointConfig.getEncoders() returned encoders size=2|" - + "com.sun.ts.tests.websocket.common.util.ErrorEncoder|" - + "com.sun.ts.tests.websocket.common.util.BooleanEncoder|" - + "TCKTestServer received String:Dummy String Test", - receivedMessageString.toString()); - } catch (IOException ioex) { - passed = false; - ioex.printStackTrace(); - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - System.out.println(receivedMessageString); - - if (passed == false) { - throw new Exception( - "Test failed with incorrect values, " + receivedMessageString); - } - } - - /* - * @testName: decodersTest - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:11; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; - * WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; - * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; - * WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void decodersTest() throws Exception { - boolean passed = true; - - List> expected_decoders = new ArrayList<>(); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); - - try { - ClientEndpointConfig cec = ClientEndpointConfig.Builder.create() - .decoders(expected_decoders).build(); - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - cec, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(5); - session.getBasicRemote().sendText("Dummy String Test"); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - - passed = MessageValidator.checkSearchStrings( - "EndpointConfig.getDecoders() returned decoders size=|" - + "com.sun.ts.tests.websocket.common.util.ByteDecoder|" - + "com.sun.ts.tests.websocket.common.util.BooleanDecoder|" - + "TCKTestServer received String:Dummy String Test", - receivedMessageString.toString()); - } catch (IOException ioex) { - passed = false; - ioex.printStackTrace(); - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - System.out.println(receivedMessageString); - - if (passed == false) { - throw new Exception( - "Test failed with incorrect values, " + receivedMessageString); - } - } - - /* - * @testName: constructorTest2 - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:11; WebSocket:JAVADOC:13; WebSocket:JAVADOC:14; - * WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; WebSocket:JAVADOC:28; - * WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; WebSocket:JAVADOC:123; - * WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; WebSocket:JAVADOC:136; - * WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void constructorTest2() throws Exception { - boolean passed = true; - - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - - List> expected_decoders = new ArrayList<>(); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ClientEndpointConfig cec = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(expected_subprotocols).extensions(extensions) - .decoders(expected_decoders).build(); - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - cec, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(5); - session.getBasicRemote().sendText("Dummy String Test"); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - - passed = MessageValidator.checkSearchStrings( - "EndpointConfig.getDecoders() returned decoders size=|" - + "com.sun.ts.tests.websocket.common.util.ByteDecoder|" - + "com.sun.ts.tests.websocket.common.util.BooleanDecoder|" - + "TCKTestServer received String:Dummy String Test", - receivedMessageString.toString()); - - if (receivedMessageString.indexOf("Extension size=0") > -1 - || receivedMessageString.indexOf("Extension size=1") > -1 - || receivedMessageString.indexOf("Extension size=2") > -1) { - receivedMessageString - .append("Correct Extensions received from client side"); - } else { - passed = false; - receivedMessageString - .append("Incorrect Extensions received from client side"); - } - if (receivedMessageString.indexOf("TCKTestServer: Extension size=0") > -1 - || receivedMessageString - .indexOf("TCKTestServer: Extension size=1") > -1 - || receivedMessageString - .indexOf("TCKTestServer: Extension size=2") > -1) { - receivedMessageString - .append("========Correct Extensions received from server side"); - } else { - passed = false; - receivedMessageString - .append("========Incorrect Extensions received from server side"); - } - - if (receivedMessageString.indexOf("subProtocol=|") > -1) { - receivedMessageString - .append("Correct subProtocol received from client side"); - } else { - passed = false; - receivedMessageString - .append("Incorrect subProtocol received from client side"); - } - - if (receivedMessageString.indexOf("TCKTestServer: subProtocol==|") > -1) { - receivedMessageString - .append("========Correct subProtocol received from server side"); - } else { - passed = false; - receivedMessageString - .append("========Incorrect subProtocol received from server side"); - } - } catch (IOException ioex) { - passed = false; - ioex.printStackTrace(); - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - System.out.println(receivedMessageString); - - if (passed == false) { - throw new Exception( - "Test failed with incorrect values, " + receivedMessageString); - } - } - - /* - * @testName: constructorTest3 - * - * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; - * WebSocket:JAVADOC:11; WebSocket:JAVADOC:12; WebSocket:JAVADOC:13; - * WebSocket:JAVADOC:14; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; - * WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; - * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; - * WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void constructorTest3() throws Exception { - boolean passed = true; - - List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", - "WAMP", "v10.stomp", "v11.stomp", "v12.stomp"); - - List> expected_decoders = new ArrayList<>(); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); - expected_decoders - .add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); - - List> expected_encoders = new ArrayList<>(); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); - expected_encoders - .add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); - - final List extension1 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("permessage-compress", "foo")); - add(new TCKExtension.TCKParameter("prop", "val")); - } - }; - - final List extension2 = new ArrayList() { - - { - add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); - add(new TCKExtension.TCKParameter("prop1", "val1")); - add(new TCKExtension.TCKParameter("prop2", "val2")); - } - }; - - ArrayList extensions = new ArrayList<>(); - extensions.add(new TCKExtension("ext1", extension1)); - extensions.add(new TCKExtension("ext2", extension2)); - - try { - ClientEndpointConfig cec = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(expected_subprotocols).extensions(extensions) - .decoders(expected_decoders).encoders(expected_encoders).build(); - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - cec, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(5); - session.getBasicRemote().sendText("Dummy String Test"); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - - passed = MessageValidator.checkSearchStrings( - "EndpointConfig.getEncoders() returned encoders size=2|" - + "com.sun.ts.tests.websocket.common.util.ErrorEncoder|" - + "com.sun.ts.tests.websocket.common.util.BooleanEncoder|" - + "EndpointConfig.getDecoders() returned decoders size=|" - + "com.sun.ts.tests.websocket.common.util.ByteDecoder|" - + "com.sun.ts.tests.websocket.common.util.BooleanDecoder|" - + "TCKTestServer received String:Dummy String Test", - receivedMessageString.toString()); - - if (receivedMessageString.indexOf("Extension size=0") > -1 - || receivedMessageString.indexOf("Extension size=1") > -1 - || receivedMessageString.indexOf("Extension size=2") > -1) { - receivedMessageString - .append("Correct Extensions received from client side"); - } else { - passed = false; - receivedMessageString - .append("Incorrect Extensions received from client side"); - } - if (receivedMessageString.indexOf("TCKTestServer: Extension size=0") > -1 - || receivedMessageString - .indexOf("TCKTestServer: Extension size=1") > -1 - || receivedMessageString - .indexOf("TCKTestServer: Extension size=2") > -1) { - receivedMessageString - .append("========Correct Extensions received from server side"); - } else { - passed = false; - receivedMessageString - .append("========Incorrect Extensions received from server side"); - } - - if (receivedMessageString.indexOf("subProtocol=|") > -1) { - receivedMessageString - .append("Correct subProtocol received from client side"); - } else { - passed = false; - receivedMessageString - .append("Incorrect subProtocol received from client side"); - } - - if (receivedMessageString.indexOf("TCKTestServer: subProtocol==|") > -1) { - receivedMessageString - .append("========Correct subProtocol received from server side"); - } else { - passed = false; - receivedMessageString - .append("========Incorrect subProtocol received from server side"); - } - } catch (IOException ioex) { - passed = false; - ioex.printStackTrace(); - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - System.out.println(receivedMessageString); - - if (passed == false) { - throw new Exception( - "Test failed with incorrect values, " + receivedMessageString); - } - } - - @Override - public void cleanup() throws Exception { - super.cleanup(); - } - - public final static class TCKBasicEndpoint extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - String subprotocol = session.getNegotiatedSubprotocol(); - receivedMessageString.append("subProtocol=" + subprotocol + "|"); - - List extensions = session.getNegotiatedExtensions(); - - receivedMessageString.append("Extension size=" + extensions.size() + "|"); - for (Extension extension : extensions) { - receivedMessageString.append(extension.getName() + "|"); - } - - List> encoders = config.getEncoders(); - int size = encoders.size(); - receivedMessageString.append( - "EndpointConfig.getEncoders() returned encoders size=" + size + "|"); - for (Class encoder : encoders) { - receivedMessageString.append("Encoder " + encoder + " found "); - } - - List> decoders = config.getDecoders(); - size = decoders.size(); - receivedMessageString.append( - "EndpointConfig.getDecoders() returned decoders size=" + size + "|"); - for (Class decoder : decoders) { - receivedMessageString.append("Decoder " + decoder + " found "); - } - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - receivedMessageString - .append("========Basic String MessageHander received=" + message); - messageLatch.countDown(); - } - }); - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(ByteBuffer data) { - byte[] data1 = new byte[data.remaining()]; - data.get(data1); - receivedMessageString - .append("========Basic ByteBuffer MessageHander received=" - + new String(data1)); - messageLatch.countDown(); - } - }); - - } - - @Override - public void onClose(Session session, CloseReason closeReason) { - receivedMessageString.append("CloseCode=" + closeReason.getCloseCode()); - receivedMessageString - .append("ReasonPhrase=" + closeReason.getReasonPhrase()); - } - } - - class TCKConfigurator extends ClientEndpointConfig.Configurator { - - @Override - public void beforeRequest(Map> headers) { - } - - @Override - public void afterResponse(HandshakeResponse hr) { - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/WSClientIT.java new file mode 100644 index 0000000000..74fb6e707a --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/WSClientIT.java @@ -0,0 +1,808 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $Id:$ + */ +package com.sun.ts.tests.websocket.ee.jakarta.websocket.clientendpointconfig; + +import java.io.IOException; +import java.net.URI; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.TCKExtension; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.common.util.MessageValidator; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.CloseReason; +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.Decoder; +import jakarta.websocket.Encoder; +import jakarta.websocket.Endpoint; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.Extension; +import jakarta.websocket.HandshakeResponse; +import jakarta.websocket.MessageHandler; +import jakarta.websocket.Session; +import jakarta.websocket.WebSocketContainer; + +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_ee_clientendpointconfig_web.war"); + archive.addClasses(WSTestServer.class); + archive.addClasses(IOUtil.class); + archive.addAsWebInfResource(WSClientIT.class.getPackage(), "web.xml", "web.xml"); + + return archive; + } + + private static final String CONTEXT_ROOT = "/ws_ee_clientendpointconfig_web"; + + private static StringBuffer receivedMessageString = new StringBuffer(); + + static volatile CountDownLatch messageLatch; + + /* + * @class.setup_props: webServerHost; webServerPort; ws_wait; + */ + public WSClientIT() throws Exception { + super.setup(); + } + + /* Run test */ + /* + * @testName: constructortest + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; WebSocket:JAVADOC:28; + * WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; WebSocket:JAVADOC:123; + * WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; WebSocket:JAVADOC:136; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-3.2.1-1; + * WebSocket:SPEC:WSC-3.2.2-1; + * + * @test_Strategy: Test constructor + */ + @Test + public void constructortest() throws Exception { + boolean passed = true; + + try { + ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build(); + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, cec, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(5); + session.getBasicRemote().sendText("Dummy String Test"); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + + passed = MessageValidator.checkSearchStrings("Extension size=0|" + + "TCKTestServer received String:Dummy String Test|" + "TCKTestServer: Extension size=0", + receivedMessageString.toString()); + if (receivedMessageString.indexOf("subProtocol=|") > -1) { + receivedMessageString.append("Correct subProtocol received from client side"); + } else { + passed = false; + receivedMessageString.append("Incorrect subProtocol received from client side"); + } + + if (receivedMessageString.indexOf("TCKTestServer: subProtocol==|") > -1) { + receivedMessageString.append("========Correct subProtocol received from server side"); + } else { + passed = false; + receivedMessageString.append("========Incorrect subProtocol received from server side"); + } + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + System.out.println(receivedMessageString); + + if (passed == false) { + throw new Exception("Test failed with incorrect values, " + receivedMessageString); + } + } + + /* + * @testName: preferredSubprotocolsTest + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:14; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; + * WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; + * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; + * WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void preferredSubprotocolsTest() throws Exception { + boolean passed = true; + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + try { + ClientEndpointConfig cec = ClientEndpointConfig.Builder.create() + .preferredSubprotocols(expected_subprotocols).build(); + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, cec, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(5); + session.getBasicRemote().sendText("Dummy String Test"); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + + passed = MessageValidator.checkSearchStrings("Extension size=0|" + + "TCKTestServer received String:Dummy String Test|" + "TCKTestServer: Extension size=0", + receivedMessageString.toString()); + if (receivedMessageString.indexOf("subProtocol=|") > -1) { + receivedMessageString.append("Correct subProtocol received from client side"); + } else { + passed = false; + receivedMessageString.append("Incorrect subProtocol received from client side"); + } + + if (receivedMessageString.indexOf("TCKTestServer: subProtocol==|") > -1) { + receivedMessageString.append("========Correct subProtocol received from server side"); + } else { + passed = false; + receivedMessageString.append("========Incorrect subProtocol received from server side"); + } + } catch (IOException ioex) { + passed = false; + ioex.printStackTrace(); + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + System.out.println(receivedMessageString); + + if (passed == false) { + throw new Exception("Test failed with incorrect values, " + receivedMessageString); + } + } + + /* + * @testName: extensionsTest + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:13; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; + * WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; + * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; + * WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void extensionsTest() throws Exception { + boolean passed = true; + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().extensions(extensions).build(); + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, cec, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(5); + session.getBasicRemote().sendText("Dummy String Test"); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + + passed = MessageValidator.checkSearchStrings("TCKTestServer received String:Dummy String Test", + receivedMessageString.toString()); + + if (receivedMessageString.indexOf("Extension size=0") > -1 + || receivedMessageString.indexOf("Extension size=1") > -1 + || receivedMessageString.indexOf("Extension size=2") > -1) { + receivedMessageString.append("Correct Extensions received from client side"); + } else { + passed = false; + receivedMessageString.append("Incorrect Extensions received from client side"); + } + + if (receivedMessageString.indexOf("TCKTestServer: Extension size=0") > -1 + || receivedMessageString.indexOf("TCKTestServer: Extension size=1") > -1 + || receivedMessageString.indexOf("TCKTestServer: Extension size=2") > -1) { + receivedMessageString.append("========Correct Extensions received from server side"); + } else { + passed = false; + receivedMessageString.append("========Incorrect Extensions received from server side"); + } + + } catch (IOException ioex) { + passed = false; + ioex.printStackTrace(); + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + System.out.println(receivedMessageString); + + if (passed == false) { + throw new Exception("Test failed with incorrect values, " + receivedMessageString); + } + } + + /* + * @testName: constructorTest1 + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:13; WebSocket:JAVADOC:13; WebSocket:JAVADOC:70; + * WebSocket:JAVADOC:71; WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; + * WebSocket:JAVADOC:128; WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:121; WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; + * WebSocket:JAVADOC:135; WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void constructorTest1() throws Exception { + boolean passed = true; + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ClientEndpointConfig cec = ClientEndpointConfig.Builder.create() + .preferredSubprotocols(expected_subprotocols).extensions(extensions).build(); + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, cec, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(5); + session.getBasicRemote().sendText("Dummy String Test"); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + + passed = MessageValidator.checkSearchStrings("TCKTestServer received String:Dummy String Test", + receivedMessageString.toString()); + + if (receivedMessageString.indexOf("subProtocol=|") > -1) { + receivedMessageString.append("Correct subProtocol received from client side"); + } else { + passed = false; + receivedMessageString.append("Incorrect subProtocol received from client side"); + } + + if (receivedMessageString.indexOf("TCKTestServer: subProtocol==|") > -1) { + receivedMessageString.append("========Correct subProtocol received from server side"); + } else { + passed = false; + receivedMessageString.append("========Incorrect subProtocol received from server side"); + } + + if (receivedMessageString.indexOf("Extension size=0") > -1 + || receivedMessageString.indexOf("Extension size=1") > -1 + || receivedMessageString.indexOf("Extension size=2") > -1) { + receivedMessageString.append("Correct Extensions received from client side"); + } else { + passed = false; + receivedMessageString.append("Incorrect Extensions received from client side"); + } + if (receivedMessageString.indexOf("TCKTestServer: Extension size=0") > -1 + || receivedMessageString.indexOf("TCKTestServer: Extension size=1") > -1 + || receivedMessageString.indexOf("TCKTestServer: Extension size=2") > -1) { + receivedMessageString.append("========Correct Extensions received from server side"); + } else { + passed = false; + receivedMessageString.append("========Incorrect Extensions received from server side"); + } + } catch (IOException ioex) { + passed = false; + ioex.printStackTrace(); + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + System.out.println(receivedMessageString); + + if (passed == false) { + throw new Exception("Test failed with incorrect values, " + receivedMessageString); + } + } + + /* + * @testName: encodersTest + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:12; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; + * WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; + * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; + * WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void encodersTest() throws Exception { + boolean passed = true; + + List> expected_encoders = new ArrayList<>(); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); + + try { + ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().encoders(expected_encoders).build(); + + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, cec, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(5); + session.getBasicRemote().sendText("Dummy String Test"); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + + passed = MessageValidator.checkSearchStrings("EndpointConfig.getEncoders() returned encoders size=2|" + + "com.sun.ts.tests.websocket.common.util.ErrorEncoder|" + + "com.sun.ts.tests.websocket.common.util.BooleanEncoder|" + + "TCKTestServer received String:Dummy String Test", receivedMessageString.toString()); + } catch (IOException ioex) { + passed = false; + ioex.printStackTrace(); + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + System.out.println(receivedMessageString); + + if (passed == false) { + throw new Exception("Test failed with incorrect values, " + receivedMessageString); + } + } + + /* + * @testName: decodersTest + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:11; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; + * WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; + * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; + * WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void decodersTest() throws Exception { + boolean passed = true; + + List> expected_decoders = new ArrayList<>(); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); + + try { + ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().decoders(expected_decoders).build(); + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, cec, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(5); + session.getBasicRemote().sendText("Dummy String Test"); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + + passed = MessageValidator.checkSearchStrings("EndpointConfig.getDecoders() returned decoders size=|" + + "com.sun.ts.tests.websocket.common.util.ByteDecoder|" + + "com.sun.ts.tests.websocket.common.util.BooleanDecoder|" + + "TCKTestServer received String:Dummy String Test", receivedMessageString.toString()); + } catch (IOException ioex) { + passed = false; + ioex.printStackTrace(); + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + System.out.println(receivedMessageString); + + if (passed == false) { + throw new Exception("Test failed with incorrect values, " + receivedMessageString); + } + } + + /* + * @testName: constructorTest2 + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:11; WebSocket:JAVADOC:13; WebSocket:JAVADOC:14; + * WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; WebSocket:JAVADOC:28; + * WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; WebSocket:JAVADOC:123; + * WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; WebSocket:JAVADOC:136; + * WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void constructorTest2() throws Exception { + boolean passed = true; + + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + + List> expected_decoders = new ArrayList<>(); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ClientEndpointConfig cec = ClientEndpointConfig.Builder.create() + .preferredSubprotocols(expected_subprotocols).extensions(extensions).decoders(expected_decoders) + .build(); + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, cec, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(5); + session.getBasicRemote().sendText("Dummy String Test"); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + + passed = MessageValidator.checkSearchStrings("EndpointConfig.getDecoders() returned decoders size=|" + + "com.sun.ts.tests.websocket.common.util.ByteDecoder|" + + "com.sun.ts.tests.websocket.common.util.BooleanDecoder|" + + "TCKTestServer received String:Dummy String Test", receivedMessageString.toString()); + + if (receivedMessageString.indexOf("Extension size=0") > -1 + || receivedMessageString.indexOf("Extension size=1") > -1 + || receivedMessageString.indexOf("Extension size=2") > -1) { + receivedMessageString.append("Correct Extensions received from client side"); + } else { + passed = false; + receivedMessageString.append("Incorrect Extensions received from client side"); + } + if (receivedMessageString.indexOf("TCKTestServer: Extension size=0") > -1 + || receivedMessageString.indexOf("TCKTestServer: Extension size=1") > -1 + || receivedMessageString.indexOf("TCKTestServer: Extension size=2") > -1) { + receivedMessageString.append("========Correct Extensions received from server side"); + } else { + passed = false; + receivedMessageString.append("========Incorrect Extensions received from server side"); + } + + if (receivedMessageString.indexOf("subProtocol=|") > -1) { + receivedMessageString.append("Correct subProtocol received from client side"); + } else { + passed = false; + receivedMessageString.append("Incorrect subProtocol received from client side"); + } + + if (receivedMessageString.indexOf("TCKTestServer: subProtocol==|") > -1) { + receivedMessageString.append("========Correct subProtocol received from server side"); + } else { + passed = false; + receivedMessageString.append("========Incorrect subProtocol received from server side"); + } + } catch (IOException ioex) { + passed = false; + ioex.printStackTrace(); + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + System.out.println(receivedMessageString); + + if (passed == false) { + throw new Exception("Test failed with incorrect values, " + receivedMessageString); + } + } + + /* + * @testName: constructorTest3 + * + * @assertion_ids: WebSocket:JAVADOC:8; WebSocket:JAVADOC:10; + * WebSocket:JAVADOC:11; WebSocket:JAVADOC:12; WebSocket:JAVADOC:13; + * WebSocket:JAVADOC:14; WebSocket:JAVADOC:70; WebSocket:JAVADOC:71; + * WebSocket:JAVADOC:28; WebSocket:JAVADOC:159; WebSocket:JAVADOC:128; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; + * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:135; + * WebSocket:JAVADOC:136; WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void constructorTest3() throws Exception { + boolean passed = true; + + List expected_subprotocols = Arrays.asList("MBWS", "MBLWS", "soap", "WAMP", "v10.stomp", "v11.stomp", + "v12.stomp"); + + List> expected_decoders = new ArrayList<>(); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.ByteDecoder.class); + expected_decoders.add(com.sun.ts.tests.websocket.common.util.BooleanDecoder.class); + + List> expected_encoders = new ArrayList<>(); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.ErrorEncoder.class); + expected_encoders.add(com.sun.ts.tests.websocket.common.util.BooleanEncoder.class); + + final List extension1 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("permessage-compress", "foo")); + add(new TCKExtension.TCKParameter("prop", "val")); + } + }; + + final List extension2 = new ArrayList() { + + { + add(new TCKExtension.TCKParameter("permessage-compress", "deflate")); + add(new TCKExtension.TCKParameter("prop1", "val1")); + add(new TCKExtension.TCKParameter("prop2", "val2")); + } + }; + + ArrayList extensions = new ArrayList<>(); + extensions.add(new TCKExtension("ext1", extension1)); + extensions.add(new TCKExtension("ext2", extension2)); + + try { + ClientEndpointConfig cec = ClientEndpointConfig.Builder.create() + .preferredSubprotocols(expected_subprotocols).extensions(extensions).decoders(expected_decoders) + .encoders(expected_encoders).build(); + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, cec, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(5); + session.getBasicRemote().sendText("Dummy String Test"); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + + passed = MessageValidator.checkSearchStrings("EndpointConfig.getEncoders() returned encoders size=2|" + + "com.sun.ts.tests.websocket.common.util.ErrorEncoder|" + + "com.sun.ts.tests.websocket.common.util.BooleanEncoder|" + + "EndpointConfig.getDecoders() returned decoders size=|" + + "com.sun.ts.tests.websocket.common.util.ByteDecoder|" + + "com.sun.ts.tests.websocket.common.util.BooleanDecoder|" + + "TCKTestServer received String:Dummy String Test", receivedMessageString.toString()); + + if (receivedMessageString.indexOf("Extension size=0") > -1 + || receivedMessageString.indexOf("Extension size=1") > -1 + || receivedMessageString.indexOf("Extension size=2") > -1) { + receivedMessageString.append("Correct Extensions received from client side"); + } else { + passed = false; + receivedMessageString.append("Incorrect Extensions received from client side"); + } + if (receivedMessageString.indexOf("TCKTestServer: Extension size=0") > -1 + || receivedMessageString.indexOf("TCKTestServer: Extension size=1") > -1 + || receivedMessageString.indexOf("TCKTestServer: Extension size=2") > -1) { + receivedMessageString.append("========Correct Extensions received from server side"); + } else { + passed = false; + receivedMessageString.append("========Incorrect Extensions received from server side"); + } + + if (receivedMessageString.indexOf("subProtocol=|") > -1) { + receivedMessageString.append("Correct subProtocol received from client side"); + } else { + passed = false; + receivedMessageString.append("Incorrect subProtocol received from client side"); + } + + if (receivedMessageString.indexOf("TCKTestServer: subProtocol==|") > -1) { + receivedMessageString.append("========Correct subProtocol received from server side"); + } else { + passed = false; + receivedMessageString.append("========Incorrect subProtocol received from server side"); + } + } catch (IOException ioex) { + passed = false; + ioex.printStackTrace(); + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + System.out.println(receivedMessageString); + + if (passed == false) { + throw new Exception("Test failed with incorrect values, " + receivedMessageString); + } + } + + @Override + public void cleanup() throws Exception { + super.cleanup(); + } + + public final static class TCKBasicEndpoint extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + String subprotocol = session.getNegotiatedSubprotocol(); + receivedMessageString.append("subProtocol=" + subprotocol + "|"); + + List extensions = session.getNegotiatedExtensions(); + + receivedMessageString.append("Extension size=" + extensions.size() + "|"); + for (Extension extension : extensions) { + receivedMessageString.append(extension.getName() + "|"); + } + + List> encoders = config.getEncoders(); + int size = encoders.size(); + receivedMessageString.append("EndpointConfig.getEncoders() returned encoders size=" + size + "|"); + for (Class encoder : encoders) { + receivedMessageString.append("Encoder " + encoder + " found "); + } + + List> decoders = config.getDecoders(); + size = decoders.size(); + receivedMessageString.append("EndpointConfig.getDecoders() returned decoders size=" + size + "|"); + for (Class decoder : decoders) { + receivedMessageString.append("Decoder " + decoder + " found "); + } + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append("========Basic String MessageHander received=" + message); + messageLatch.countDown(); + } + }); + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(ByteBuffer data) { + byte[] data1 = new byte[data.remaining()]; + data.get(data1); + receivedMessageString + .append("========Basic ByteBuffer MessageHander received=" + new String(data1)); + messageLatch.countDown(); + } + }); + + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + receivedMessageString.append("CloseCode=" + closeReason.getCloseCode()); + receivedMessageString.append("ReasonPhrase=" + closeReason.getReasonPhrase()); + } + } + + class TCKConfigurator extends ClientEndpointConfig.Configurator { + + @Override + public void beforeRequest(Map> headers) { + } + + @Override + public void afterResponse(HandshakeResponse hr) { + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/WSTestServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/WSTestServer.java index ddad43f7ce..5cec6ed684 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/WSTestServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/WSTestServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -40,106 +40,93 @@ @ServerEndpoint(value = "/TCKTestServer") public class WSTestServer { - static EndpointConfig config; - - @OnOpen - public void init(Session session, EndpointConfig configs) throws IOException { - System.out.println("========TCKTestServer opened"); - config = configs; - session.getBasicRemote().sendText("========TCKTestServer opened"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from Server is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from Server is open=FALSE"); - } - } - - @OnMessage - public void respondString(String message, Session session) { - System.out.println("TCKTestServer got String message: " + message); - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String:" + message + "|"); - - String subprotocol = session.getNegotiatedSubprotocol(); - session.getBasicRemote() - .sendText("========TCKTestServer: subProtocol==" + subprotocol + "|"); - - List extensions = session.getNegotiatedExtensions(); - - session.getBasicRemote().sendText( - "========TCKTestServer: Extension size=" + extensions.size() + "|"); - for (Extension extension : extensions) { - session.getBasicRemote().sendText( - "========TCKTestServer: extensions " + extension.getName() + "|"); - } - - List> encoders = config.getEncoders(); - int size = encoders.size(); - session.getBasicRemote().sendText( - "========TCKTestServer: getEncoders() returned encoders size=" + size - + "|"); - for (Class encoder : encoders) { - session.getBasicRemote().sendText(encoder + "|"); - } - - List> decoders = config.getDecoders(); - size = decoders.size(); - session.getBasicRemote().sendText( - "========TCKTestServer: EndpointConfig.getDecoders() returned decoders size=" - + size + "|"); - for (Class decoder : decoders) { - session.getBasicRemote().sendText(decoder + "|"); - } - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @OnMessage - public void respondByte(ByteBuffer message, Session session) { - String message_string = IOUtil.byteBufferToString(message); - - System.out - .println("TCKTestServer got ByteBuffer message: " + message_string); - - ByteBuffer data = ByteBuffer - .wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); - ByteBuffer data1 = ByteBuffer - .wrap(("========TCKTestServer responds: Message in bytes").getBytes()); - - try { - session.getBasicRemote().sendBinary(data); - session.getBasicRemote().sendBinary(message); - session.getBasicRemote().sendBinary(data1); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @OnError - public void onError(Session session, Throwable t) { - System.out.println("TCKTestServer onError"); - try { - session.getBasicRemote().sendText("========TCKTestServer onError"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========onError: session from Server is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========onError: session from Server is open=FALSE"); - } - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } - - @OnClose - public void onClose() { - System.out.println("==From onClose=="); - } + static EndpointConfig config; + + @OnOpen + public void init(Session session, EndpointConfig configs) throws IOException { + System.out.println("========TCKTestServer opened"); + config = configs; + session.getBasicRemote().sendText("========TCKTestServer opened"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from Server is open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from Server is open=FALSE"); + } + } + + @OnMessage + public void respondString(String message, Session session) { + System.out.println("TCKTestServer got String message: " + message); + try { + session.getBasicRemote().sendText("========TCKTestServer received String:" + message + "|"); + + String subprotocol = session.getNegotiatedSubprotocol(); + session.getBasicRemote().sendText("========TCKTestServer: subProtocol==" + subprotocol + "|"); + + List extensions = session.getNegotiatedExtensions(); + + session.getBasicRemote().sendText("========TCKTestServer: Extension size=" + extensions.size() + "|"); + for (Extension extension : extensions) { + session.getBasicRemote().sendText("========TCKTestServer: extensions " + extension.getName() + "|"); + } + + List> encoders = config.getEncoders(); + int size = encoders.size(); + session.getBasicRemote() + .sendText("========TCKTestServer: getEncoders() returned encoders size=" + size + "|"); + for (Class encoder : encoders) { + session.getBasicRemote().sendText(encoder + "|"); + } + + List> decoders = config.getDecoders(); + size = decoders.size(); + session.getBasicRemote().sendText( + "========TCKTestServer: EndpointConfig.getDecoders() returned decoders size=" + size + "|"); + for (Class decoder : decoders) { + session.getBasicRemote().sendText(decoder + "|"); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @OnMessage + public void respondByte(ByteBuffer message, Session session) { + String message_string = IOUtil.byteBufferToString(message); + + System.out.println("TCKTestServer got ByteBuffer message: " + message_string); + + ByteBuffer data = ByteBuffer.wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); + ByteBuffer data1 = ByteBuffer.wrap(("========TCKTestServer responds: Message in bytes").getBytes()); + + try { + session.getBasicRemote().sendBinary(data); + session.getBasicRemote().sendBinary(message); + session.getBasicRemote().sendBinary(data1); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @OnError + public void onError(Session session, Throwable t) { + System.out.println("TCKTestServer onError"); + try { + session.getBasicRemote().sendText("========TCKTestServer onError"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========onError: session from Server is open=TRUE"); + } else { + session.getBasicRemote().sendText("========onError: session from Server is open=FALSE"); + } + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } + + @OnClose + public void onClose() { + System.out.println("==From onClose=="); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/OPS.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/OPS.java index db71542848..e2ad666adb 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/OPS.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/OPS.java @@ -17,5 +17,5 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.clientendpointonmessage; public enum OPS { - TEXT, TEXTPARTIAL, BINARY, BINARYPARTIAL, PONG + TEXT, TEXTPARTIAL, BINARY, BINARYPARTIAL, PONG } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryDecoderAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryDecoderAndSessionClientEndpoint.java index 712c9a08cc..bdf7be8910 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryDecoderAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryDecoderAndSessionClientEndpoint.java @@ -34,34 +34,33 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = { StringBeanBinaryDecoder.class }) -public class WSBinaryDecoderAndSessionClientEndpoint - extends AnnotatedClientEndpoint { +public class WSBinaryDecoderAndSessionClientEndpoint extends AnnotatedClientEndpoint { - public WSBinaryDecoderAndSessionClientEndpoint() { - super(new StringBeanClientEndpoint()); - } + public WSBinaryDecoderAndSessionClientEndpoint() { + super(new StringBeanClientEndpoint()); + } - @OnMessage - public void echo(StringBean bean, Session session) throws IOException { - super.onMessage(bean); - session.getBasicRemote().sendText(bean.get()); - } + @OnMessage + public void echo(StringBean bean, Session session) throws IOException { + super.onMessage(bean); + session.getBasicRemote().sendText(bean.get()); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryDecoderClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryDecoderClientEndpoint.java index a87da0c801..40b2bee624 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryDecoderClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryDecoderClientEndpoint.java @@ -32,35 +32,34 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = { StringBeanBinaryDecoder.class }) -public class WSBinaryDecoderClientEndpoint - extends AnnotatedClientEndpoint { +public class WSBinaryDecoderClientEndpoint extends AnnotatedClientEndpoint { - public WSBinaryDecoderClientEndpoint() { - super(new StringBeanClientEndpoint()); - } + public WSBinaryDecoderClientEndpoint() { + super(new StringBeanClientEndpoint()); + } - @OnMessage - public String echo(StringBean bean) { - super.onMessage(bean); - return bean.get(); - } + @OnMessage + public String echo(StringBean bean) { + super.onMessage(bean); + return bean.get(); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryStreamDecoderAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryStreamDecoderAndSessionClientEndpoint.java index 6b40cb6ad2..b1bd485993 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryStreamDecoderAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryStreamDecoderAndSessionClientEndpoint.java @@ -34,34 +34,33 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = { StringBeanBinaryStreamDecoder.class }) -public class WSBinaryStreamDecoderAndSessionClientEndpoint - extends AnnotatedClientEndpoint { +public class WSBinaryStreamDecoderAndSessionClientEndpoint extends AnnotatedClientEndpoint { - public WSBinaryStreamDecoderAndSessionClientEndpoint() { - super(new StringBeanClientEndpoint()); - } + public WSBinaryStreamDecoderAndSessionClientEndpoint() { + super(new StringBeanClientEndpoint()); + } - @OnMessage - public void echo(StringBean bean, Session s) throws IOException { - super.onMessage(bean); - s.getBasicRemote().sendText(bean.get()); - } + @OnMessage + public void echo(StringBean bean, Session s) throws IOException { + super.onMessage(bean); + s.getBasicRemote().sendText(bean.get()); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryStreamDecoderClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryStreamDecoderClientEndpoint.java index 54edc9fbba..c4161d1a67 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryStreamDecoderClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSBinaryStreamDecoderClientEndpoint.java @@ -32,34 +32,33 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = { StringBeanBinaryStreamDecoder.class }) -public class WSBinaryStreamDecoderClientEndpoint - extends AnnotatedClientEndpoint { +public class WSBinaryStreamDecoderClientEndpoint extends AnnotatedClientEndpoint { - public WSBinaryStreamDecoderClientEndpoint() { - super(new StringBeanClientEndpoint()); - } + public WSBinaryStreamDecoderClientEndpoint() { + super(new StringBeanClientEndpoint()); + } - @OnMessage - public String echo(StringBean bean) { - super.onMessage(bean); - return bean.get(); - } + @OnMessage + public String echo(StringBean bean) { + super.onMessage(bean); + return bean.get(); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayAndSessionClientEndpoint.java index c6ebf2f02b..db6c89e299 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayAndSessionClientEndpoint.java @@ -31,31 +31,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSByteArrayAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void bytesToString(byte[] array, Session s) throws IOException { - String msg = new String(array); - super.onMessage(msg); - s.getBasicRemote().sendText(msg); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSByteArrayAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void bytesToString(byte[] array, Session s) throws IOException { + String msg = new String(array); + super.onMessage(msg); + s.getBasicRemote().sendText(msg); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayClientEndpoint.java index 52aba2caaf..db2ffff864 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayClientEndpoint.java @@ -31,28 +31,28 @@ @ClientEndpoint public class WSByteArrayClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String bytesToString(byte[] array) { - String msg = new String(array); - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public String bytesToString(byte[] array) { + String msg = new String(array); + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayPartialAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayPartialAndSessionClientEndpoint.java index 83aca5eae6..085b3e0877 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayPartialAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayPartialAndSessionClientEndpoint.java @@ -31,37 +31,35 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSByteArrayPartialAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { +public class WSByteArrayPartialAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { - private StringBuffer sb = new StringBuffer(); + private StringBuffer sb = new StringBuffer(); - @OnMessage - public void bytesToString(byte[] array, Session s, boolean finito) - throws IOException { - sb.append(new String(array)).append("(").append(finito).append(")"); - if (finito) { - super.onMessage(sb.toString()); - s.getBasicRemote().sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); - sb = new StringBuffer(); - } - } + @OnMessage + public void bytesToString(byte[] array, Session s, boolean finito) throws IOException { + sb.append(new String(array)).append("(").append(finito).append(")"); + if (finito) { + super.onMessage(sb.toString()); + s.getBasicRemote().sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); + sb = new StringBuffer(); + } + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayPartialClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayPartialClientEndpoint.java index dde404be7d..dbe9c4cd30 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayPartialClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteArrayPartialClientEndpoint.java @@ -31,40 +31,38 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSByteArrayPartialClientEndpoint - extends AnnotatedStringClientEndpoint { +public class WSByteArrayPartialClientEndpoint extends AnnotatedStringClientEndpoint { - protected Session session; + protected Session session; - private StringBuffer sb = new StringBuffer(); + private StringBuffer sb = new StringBuffer(); - @OnMessage - public void bytesToString(byte[] array, boolean finito) throws IOException { - sb.append(new String(array)).append("(").append(finito).append(")"); - if (finito) { - super.onMessage(sb.toString()); - session.getBasicRemote() - .sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); - sb = new StringBuffer(); - } - } + @OnMessage + public void bytesToString(byte[] array, boolean finito) throws IOException { + sb.append(new String(array)).append("(").append(finito).append(")"); + if (finito) { + super.onMessage(sb.toString()); + session.getBasicRemote().sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); + sb = new StringBuffer(); + } + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferAndSessionClientEndpoint.java index f46065e941..27ee4c61ee 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferAndSessionClientEndpoint.java @@ -33,33 +33,32 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSByteBufferAndSessionClientEndpoint - extends AnnotatedClientEndpoint { - public WSByteBufferAndSessionClientEndpoint() { - super(new ByteBufferClientEndpoint()); - } +public class WSByteBufferAndSessionClientEndpoint extends AnnotatedClientEndpoint { + public WSByteBufferAndSessionClientEndpoint() { + super(new ByteBufferClientEndpoint()); + } - @OnMessage - public void echo(ByteBuffer b, Session s) throws IOException { - super.onMessage(b); - s.getBasicRemote().sendBinary(b); - } + @OnMessage + public void echo(ByteBuffer b, Session s) throws IOException { + super.onMessage(b); + s.getBasicRemote().sendBinary(b); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferClientEndpoint.java index 3dc2751af4..39c9e9ef09 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferClientEndpoint.java @@ -33,33 +33,32 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSByteBufferClientEndpoint - extends AnnotatedClientEndpoint { - public WSByteBufferClientEndpoint() { - super(new ByteBufferClientEndpoint()); - } +public class WSByteBufferClientEndpoint extends AnnotatedClientEndpoint { + public WSByteBufferClientEndpoint() { + super(new ByteBufferClientEndpoint()); + } - @OnMessage - public String echo(ByteBuffer b) { - super.onMessage(b); - return IOUtil.byteBufferToString(b); - } + @OnMessage + public String echo(ByteBuffer b) { + super.onMessage(b); + return IOUtil.byteBufferToString(b); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferPartialAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferPartialAndSessionClientEndpoint.java index 1cbdd20979..a1ef876a9b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferPartialAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferPartialAndSessionClientEndpoint.java @@ -33,38 +33,35 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSByteBufferPartialAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { +public class WSByteBufferPartialAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { - private StringBuilder sb = new StringBuilder(); + private StringBuilder sb = new StringBuilder(); - @OnMessage - public void echo(ByteBuffer buf, Session s, boolean finito) - throws IOException { - sb.append(IOUtil.byteBufferToString(buf)).append("(").append(finito) - .append(")"); - if (finito) { - super.onMessage(sb.toString()); - s.getBasicRemote().sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); - sb = new StringBuilder(); - } - } + @OnMessage + public void echo(ByteBuffer buf, Session s, boolean finito) throws IOException { + sb.append(IOUtil.byteBufferToString(buf)).append("(").append(finito).append(")"); + if (finito) { + super.onMessage(sb.toString()); + s.getBasicRemote().sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); + sb = new StringBuilder(); + } + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferPartialClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferPartialClientEndpoint.java index 91f845baa1..934aeaba70 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferPartialClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSByteBufferPartialClientEndpoint.java @@ -33,41 +33,38 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSByteBufferPartialClientEndpoint - extends AnnotatedStringClientEndpoint { - protected Session session; +public class WSByteBufferPartialClientEndpoint extends AnnotatedStringClientEndpoint { + protected Session session; - private StringBuilder sb = new StringBuilder(); + private StringBuilder sb = new StringBuilder(); - @OnMessage - public void echo(ByteBuffer buf, boolean finito) throws IOException { - sb.append(IOUtil.byteBufferToString(buf)).append("(").append(finito) - .append(")"); - if (finito) { - super.onMessage(sb.toString()); - session.getBasicRemote() - .sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); - sb = new StringBuilder(); - } - } + @OnMessage + public void echo(ByteBuffer buf, boolean finito) throws IOException { + sb.append(IOUtil.byteBufferToString(buf)).append("(").append(finito).append(")"); + if (finito) { + super.onMessage(sb.toString()); + session.getBasicRemote().sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); + sb = new StringBuilder(); + } + } - @OnError - @Override - public void onError(Session session, Throwable t) { - this.session = session; - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + this.session = session; + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSCServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSCServer.java index 41e34f0b27..38e066b996 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSCServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSCServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -33,119 +33,117 @@ @ServerEndpoint("/srv/{param}") public class WSCServer { - private enum State { - INIT, SECOND, FINAL - }; + private enum State { + INIT, SECOND, FINAL + }; - // endpoint instance is created once per connection - private State state = State.INIT; + // endpoint instance is created once per connection + private State state = State.INIT; - @OnOpen - public void onOpen(final Session session, - final @PathParam("param") String op) { - session.addMessageHandler(new MessageHandler.Whole() { - @Override - public void onMessage(ByteBuffer message) { - echo(op, IOUtil.byteBufferToString(message), session); - } - }); - } + @OnOpen + public void onOpen(final Session session, final @PathParam("param") String op) { + session.addMessageHandler(new MessageHandler.Whole() { + @Override + public void onMessage(ByteBuffer message) { + echo(op, IOUtil.byteBufferToString(message), session); + } + }); + } - @OnMessage - public void echo(@PathParam("param") String op, String echo, - Session session) { - switch (state) { - case INIT: - state = State.SECOND; - op(op, echo, session); - break; - case SECOND: - state = State.FINAL; - op(op, echo, session); - break; - case FINAL: - // do not send anything, otherwise it would not ever stop - try { - session.close(); - } catch (IOException e) { - onError(session, e); - } - break; - } - } + @OnMessage + public void echo(@PathParam("param") String op, String echo, Session session) { + switch (state) { + case INIT: + state = State.SECOND; + op(op, echo, session); + break; + case SECOND: + state = State.FINAL; + op(op, echo, session); + break; + case FINAL: + // do not send anything, otherwise it would not ever stop + try { + session.close(); + } catch (IOException e) { + onError(session, e); + } + break; + } + } - private void op(String param, String echo, Session session) { - if (param == null) - throw new RuntimeException("Path param is null"); - OPS op = OPS.valueOf(param); - switch (op) { - case TEXT: - try { - session.getBasicRemote().sendText(echo); - } catch (IOException e) { - onError(session, e); - } - break; - case TEXTPARTIAL: - String[] tokens = echo.split("_"); - for (int i = 0; i != tokens.length; i++) - try { - boolean isLast = i == tokens.length - 1; - if (isLast) - session.getBasicRemote().sendText(tokens[i], true); - else - session.getBasicRemote().sendText(tokens[i] + "_", false); - } catch (IOException e) { - onError(session, e); - } - break; - case BINARY: - try { - session.getBasicRemote().sendBinary(ByteBuffer.wrap(echo.getBytes())); - } catch (IOException e) { - onError(session, e); - } - break; - case BINARYPARTIAL: - tokens = echo.split("_"); - for (int i = 0; i != tokens.length; i++) - try { - boolean isLast = i == tokens.length - 1; - ByteBuffer buf; - if (isLast) { - buf = ByteBuffer.wrap(tokens[i].getBytes()); - session.getBasicRemote().sendBinary(buf, true); - } else { - buf = ByteBuffer.wrap((tokens[i] + "_").getBytes()); - session.getBasicRemote().sendBinary(buf, false); - } - } catch (IOException e) { - onError(session, e); - } - break; - case PONG: - try { - session.getBasicRemote().sendPong(ByteBuffer.wrap(echo.getBytes())); - } catch (IOException e) { - onError(session, e); - } - break; - default: - throw new IllegalStateException(op + " not implemented"); - } - } + private void op(String param, String echo, Session session) { + if (param == null) + throw new RuntimeException("Path param is null"); + OPS op = OPS.valueOf(param); + switch (op) { + case TEXT: + try { + session.getBasicRemote().sendText(echo); + } catch (IOException e) { + onError(session, e); + } + break; + case TEXTPARTIAL: + String[] tokens = echo.split("_"); + for (int i = 0; i != tokens.length; i++) + try { + boolean isLast = i == tokens.length - 1; + if (isLast) + session.getBasicRemote().sendText(tokens[i], true); + else + session.getBasicRemote().sendText(tokens[i] + "_", false); + } catch (IOException e) { + onError(session, e); + } + break; + case BINARY: + try { + session.getBasicRemote().sendBinary(ByteBuffer.wrap(echo.getBytes())); + } catch (IOException e) { + onError(session, e); + } + break; + case BINARYPARTIAL: + tokens = echo.split("_"); + for (int i = 0; i != tokens.length; i++) + try { + boolean isLast = i == tokens.length - 1; + ByteBuffer buf; + if (isLast) { + buf = ByteBuffer.wrap(tokens[i].getBytes()); + session.getBasicRemote().sendBinary(buf, true); + } else { + buf = ByteBuffer.wrap((tokens[i] + "_").getBytes()); + session.getBasicRemote().sendBinary(buf, false); + } + } catch (IOException e) { + onError(session, e); + } + break; + case PONG: + try { + session.getBasicRemote().sendPong(ByteBuffer.wrap(echo.getBytes())); + } catch (IOException e) { + onError(session, e); + } + break; + default: + throw new IllegalStateException(op + " not implemented"); + } + } - @OnError - public void onError(Session session, Throwable t) { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - try { - if (session.isOpen()) - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } + @OnError + public void onError(Session session, Throwable t) { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + try { + if (session.isOpen()) + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSClient.java deleted file mode 100644 index 66c1e44382..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSClient.java +++ /dev/null @@ -1,941 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.clientendpointonmessage; - -import java.nio.ByteBuffer; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicInteger; - -import com.sun.ts.tests.websocket.common.client.EndpointCallback; -import com.sun.ts.tests.websocket.common.client.SendMessageCallback; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -import jakarta.websocket.CloseReason; -import jakarta.websocket.Session; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = 7948609603037530363L; - - static final String ECHO = "Echo message to be sent to server endpoint"; - - public static void main(String[] args) { - new WSClient().run(args); - } - - @Override - public void setup(String[] args, Properties p) throws Exception { - setCountDownLatchCount(3); - setContextRoot("ws_ee_clientendpointonmessage_web"); - addClientCallback(new EndpointCallback() { - @Override - public void onClose(Session session, CloseReason closeReason) { - getCountDownLatch().countDown(); - super.onClose(session, closeReason); - } - }); - super.setup(args, p); - } - - /* Run test */ - - // TEXT ------------------------------------------ - - /* - * @testName: echoStringTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Echo String - */ - public void echoStringTest() throws Exception { - setAnnotatedClientEndpoint(new WSStringClientEndpoint()); - setProperty(Property.CONTENT, ECHO); - invoke(OPS.TEXT, ECHO); - } - - /* - * @testName: echoIntTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo int - */ - public void echoIntTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveIntClientEndpoint()); - int entity = Integer.MIN_VALUE; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoByteTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo byte - */ - public void echoByteTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveByteClientEndpoint()); - byte entity = 123; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoCharTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo char - */ - public void echoCharTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveCharClientEndpoint()); - char entity = 'E'; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoBooleanTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo boolean - */ - public void echoBooleanTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveBooleanClientEndpoint()); - boolean entity = true; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoShortTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo short - */ - public void echoShortTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveShortClientEndpoint()); - short entity = -32100; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoDoubleTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo double - */ - public void echoDoubleTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveDoubleClientEndpoint()); - double entity = -12345678.88; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoFloatTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo float - */ - public void echoFloatTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveFloatClientEndpoint()); - float entity = -12345678.88f; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoLongTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo long - */ - public void echoLongTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveLongClientEndpoint()); - long entity = Long.MIN_VALUE; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoFullIntTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo int - */ - public void echoFullIntTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullLongClientEndpoint()); - Integer entity = Integer.MIN_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullByteTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo byte - */ - public void echoFullByteTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullByteClientEndpoint()); - Byte entity = Byte.MIN_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullCharTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo char - */ - public void echoFullCharTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullCharClientEndpoint()); - Character entity = 'E'; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullBooleanTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo boolean - */ - public void echoFullBooleanTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullBooleanClientEndpoint()); - Boolean entity = true; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullShortTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo short - */ - public void echoFullShortTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullShortClientEndpoint()); - Short entity = Short.MAX_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullDoubleTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo double - */ - public void echoFullDoubleTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullDoubleClientEndpoint()); - Double entity = Double.MIN_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullFloatTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo float - */ - public void echoFullFloatTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullFloatClientEndpoint()); - Float entity = Float.MAX_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullLongTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo long - */ - public void echoFullLongTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullLongClientEndpoint()); - Long entity = Long.MAX_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoReaderTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: OnMessage(Reader) - */ - public void echoReaderTest() throws Exception { - setAnnotatedClientEndpoint(new WSReaderClientEndpoint()); - setProperty(Property.CONTENT, ECHO); - invoke(OPS.TEXT, ECHO); - } - - /* - * @testName: echoTextDecoderTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: OnMessage using TextDecoder - */ - public void echoTextDecoderTest() throws Exception { - setAnnotatedClientEndpoint(new WSTextDecoderClientEndpoint()); - setProperty(Property.CONTENT, ECHO); - invoke(OPS.TEXT, ECHO); - } - - /* - * @testName: echoTextStreamDecoderTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: OnMessage using TextStreamDecoder - */ - public void echoTextStreamDecoderTest() throws Exception { - setAnnotatedClientEndpoint(new WSTextStreamDecoderClientEndpoint()); - setProperty(Property.CONTENT, ECHO); - invoke(OPS.TEXT, ECHO); - } - - // -------------------------TEXT AND SESSION ------------------------------ - /* - * @testName: echoStringAndSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Echo String - */ - public void echoStringAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSStringAndSessionClientEndpoint()); - setProperty(Property.CONTENT, ECHO); - invoke(OPS.TEXT, ECHO); - } - - /* - * @testName: echoIntAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo int - */ - public void echoIntAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveIntAndSessionClientEndpoint()); - int entity = Integer.MIN_VALUE; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoByteAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo byte - */ - public void echoByteAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveByteAndSessionClientEndpoint()); - byte entity = 123; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoCharAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo char - */ - public void echoCharAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveCharAndSessionClientEndpoint()); - char entity = 'E'; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity) + "char"); - } - - /* - * @testName: echoBooleanAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo boolean - */ - public void echoBooleanAndSessionTest() throws Exception { - setAnnotatedClientEndpoint( - new WSPrimitiveBooleanAndSessionClientEndpoint()); - boolean entity = true; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoShortAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo short - */ - public void echoShortAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveShortAndSessionClientEndpoint()); - short entity = -32100; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoDoubleAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo double - */ - public void echoDoubleAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveDoubleAndSessionClientEndpoint()); - double entity = -12345678.88; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoFloatAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo float - */ - public void echoFloatAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveFloatAndSessionClientEndpoint()); - float entity = -12345678.88f; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoLongAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo long - */ - public void echoLongAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSPrimitiveLongAndSessionClientEndpoint()); - long entity = Long.MIN_VALUE; - setEntity(entity); - invoke(OPS.TEXT, String.valueOf(entity)); - } - - /* - * @testName: echoFullIntAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo int - */ - public void echoFullIntAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullLongAndSessionClientEndpoint()); - Integer entity = Integer.MIN_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullByteAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo byte - */ - public void echoFullByteAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullByteAndSessionClientEndpoint()); - Byte entity = Byte.MIN_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullCharAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo char - */ - public void echoFullCharAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullCharAndSessionClientEndpoint()); - Character entity = 'E'; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullBooleanAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo boolean - */ - public void echoFullBooleanAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullBooleanAndSessionClientEndpoint()); - Boolean entity = true; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullShortAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo short - */ - public void echoFullShortAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullShortAndSessionClientEndpoint()); - Short entity = Short.MAX_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullDoubleAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo double - */ - public void echoFullDoubleAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullDoubleAndSessionClientEndpoint()); - Double entity = Double.MIN_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullFloatAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo float - */ - public void echoFullFloatAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullFloatAndSessionClientEndpoint()); - Float entity = Float.MAX_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoFullLongAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo long - */ - public void echoFullLongAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSFullLongAndSessionClientEndpoint()); - Long entity = Long.MAX_VALUE; - setEntity(entity); - invoke(OPS.TEXT, entity.toString()); - } - - /* - * @testName: echoReaderAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: OnMessage(Reader) - */ - public void echoReaderAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSReaderAndSessionClientEndpoint()); - setProperty(Property.CONTENT, ECHO); - invoke(OPS.TEXT, ECHO); - } - - /* - * @testName: echoTextDecoderAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: OnMessage using TextDecoder - */ - public void echoTextDecoderAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSTextDecoderAndSessionClientEndpoint()); - setProperty(Property.CONTENT, ECHO); - invoke(OPS.TEXT, ECHO); - } - - /* - * @testName: echoTextStreamDecoderAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: OnMessage using TextStreamDecoder - */ - public void echoTextStreamDecoderAndSessionTest() throws Exception { - setAnnotatedClientEndpoint( - new WSTextStreamDecoderAndSessionClientEndpoint()); - setProperty(Property.CONTENT, ECHO); - invoke(OPS.TEXT, ECHO); - } - - // -----------------------PARTIAL--------------------------------- - - /* - * @testName: partialStringTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send partial message - */ - public void partialStringTest() throws Exception { - setAnnotatedClientEndpoint(new WSStringPartialClientEndpoint()); - String partial2 = "partialStringTest"; - String response = ECHO + "_(false)" + partial2 + "(true)"; - setEntity(ECHO + "_" + partial2); - invoke(OPS.TEXTPARTIAL, response); - } - - /* - * @testName: partialStringAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send string and string receive the combined string - */ - public void partialStringAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSStringPartialAndSessionClientEndpoint()); - String partial2 = "partialStringAndSessionTest"; - String response = ECHO + "_(false)" + partial2 + "(true)"; - setEntity(ECHO + "_" + partial2); - invoke(OPS.TEXTPARTIAL, response); - } - - // ----------------- BINARY ----------------------------------- - - /* - * @testName: echoByteBufferTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Echo ByteBuffer - */ - public void echoByteBufferTest() throws Exception { - setAnnotatedClientEndpoint(new WSByteBufferClientEndpoint()); - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - invoke(OPS.BINARY, ECHO); - } - - /* - * @testName: byteBufferToBytesTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Send ByteBuffer receive bytes - */ - public void byteBufferToBytesTest() throws Exception { - setAnnotatedClientEndpoint(new WSByteArrayClientEndpoint()); - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - invoke(OPS.BINARY, ECHO); - } - - /* - * @testName: byteBufferToInputStreamTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Send ByteBuffer receive InputStream - */ - public void byteBufferToInputStreamTest() throws Exception { - setAnnotatedClientEndpoint(new WSInputStreamClientEndpoint()); - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - invoke(OPS.BINARY, ECHO); - } - - /* - * @testName: byteBufferToBinaryDecoderTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Send ByteBuffer receive Object - */ - public void byteBufferToBinaryDecoderTest() throws Exception { - setAnnotatedClientEndpoint(new WSBinaryDecoderClientEndpoint()); - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - invoke(OPS.BINARY, ECHO); - } - - /* - * @testName: byteBufferToBinaryStreamDecoderTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Send ByteBuffer receive Object - */ - public void byteBufferToBinaryStreamDecoderTest() throws Exception { - setAnnotatedClientEndpoint(new WSBinaryStreamDecoderClientEndpoint()); - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - invoke(OPS.BINARY, ECHO); - } - - // ----------------- CONTROL ----------------------------------- - /* - * @testName: pongToPongTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: pong message - */ - public void pongToPongTest() throws Exception { - setAnnotatedClientEndpoint(new WSPongMessageClientEndpoint()); - setEntity(ECHO); - invoke(OPS.PONG, ECHO); - } - - /* - * @testName: pongToPongAndSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: pong message - */ - public void pongToPongAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSPongMessageAndSessionClientEndpoint()); - setEntity(ECHO); - invoke(OPS.PONG, ECHO); - } - - // ----------------- BINARY AND SESSION ----------------------------------- - /* - * @testName: echoByteBufferAndSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Echo ByteBuffer - */ - public void echoByteBufferAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSByteBufferAndSessionClientEndpoint()); - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - invoke(OPS.BINARY, ECHO); - } - - /* - * @testName: byteBufferToBytesAndSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Send ByteBuffer receive bytes - */ - public void byteBufferToBytesAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSByteArrayAndSessionClientEndpoint()); - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - invoke(OPS.BINARY, ECHO); - } - - /* - * @testName: byteBufferToInputStreamAndSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Send ByteBuffer receive InputStream - */ - public void byteBufferToInputStreamAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSInputStreamAndSessionClientEndpoint()); - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - invoke(OPS.BINARY, ECHO); - } - - /* - * @testName: byteBufferToBinaryDecoderAndSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Send ByteBuffer receive Object - */ - public void byteBufferToBinaryDecoderAndSessionTest() throws Exception { - setAnnotatedClientEndpoint(new WSBinaryDecoderAndSessionClientEndpoint()); - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - invoke(OPS.BINARY, ECHO); - } - - /* - * @testName: byteBufferToBinaryStreamDecoderAndSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Send ByteBuffer receive Object - */ - public void byteBufferToBinaryStreamDecoderAndSessionTest() throws Exception { - setAnnotatedClientEndpoint( - new WSBinaryStreamDecoderAndSessionClientEndpoint()); - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - invoke(OPS.BINARY, ECHO); - } - - // ----------------- PARTIAL BINARY ----------------------------------- - /* - * @testName: partialByteArrayTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send bytearray and bytearray receive the combined message - */ - public void partialByteArrayTest() throws Exception { - setAnnotatedClientEndpoint(new WSByteArrayPartialClientEndpoint()); - String partial2 = "partialByteArrayTest"; - String response = ECHO + "_(false)" + partial2 + "(true)"; - setEntity(ByteBuffer.wrap((ECHO + "_" + partial2).getBytes())); - invoke(OPS.BINARYPARTIAL, response); - } - - /* - * @testName: partialByteArrayAndSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send bytearray and bytearray receive the combined message - */ - public void partialByteArrayAndSessionTest() throws Exception { - setAnnotatedClientEndpoint( - new WSByteArrayPartialAndSessionClientEndpoint()); - String partial2 = "partialByteArrayAndSessionTest"; - String response = ECHO + "_(false)" + partial2 + "(true)"; - setEntity(ByteBuffer.wrap((ECHO + "_" + partial2).getBytes())); - invoke(OPS.BINARYPARTIAL, response); - } - - /* - * @testName: partialByteBufferTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message - */ - public void partialByteBufferTest() throws Exception { - setAnnotatedClientEndpoint(new WSByteBufferPartialClientEndpoint()); - String partial2 = "partialByteBufferTest"; - String response = ECHO + "_(false)" + partial2 + "(true)"; - setEntity(ByteBuffer.wrap((ECHO + "_" + partial2).getBytes())); - invoke(OPS.BINARYPARTIAL, response); - } - - /* - * @testName: partialByteBufferAndSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message - */ - public void partialByteBufferAndSessionTest() throws Exception { - setAnnotatedClientEndpoint( - new WSByteBufferPartialAndSessionClientEndpoint()); - String partial2 = "partialByteBufferAndSessionTest"; - String response = ECHO + "_(false)" + partial2 + "(true)"; - setEntity(ByteBuffer.wrap((ECHO + "_" + partial2).getBytes())); - invoke(OPS.BINARYPARTIAL, response); - } - - // --------------------------------- MAX LEN - /* - * @testName: maxLengthOKTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: the message is shorter than maxMessageLength - */ - public void maxLengthOKTest() throws Exception { - setAnnotatedClientEndpoint(new WSMaxLengthClientEndpoint()); - String entity = "12345"; - setEntity(entity); - invoke(OPS.TEXT, entity); - } - - /* - * @testName: maxLengthFailsTest - * - * @assertion_ids: WebSocket:JAVADOC:80; WebSocket:SPEC:WSC-4.7.1-1; - * - * @test_Strategy: the message is longer than maxMessageLength - */ - public void maxLengthFailsTest() throws Exception { - setCountDownLatchCount(1); - final AtomicInteger ai = new AtomicInteger(0); - setEntity("123456"); - EndpointCallback callback = new SendMessageCallback(entity) { - @Override - public void onClose(Session session, CloseReason closeReason) { - ai.set(closeReason.getCloseCode().getCode()); - getCountDownLatch().countDown(); - } - }; - setClientCallback(callback); - setAnnotatedClientEndpoint(new WSMaxLengthClientEndpoint()); - setProperty(Property.REQUEST, buildRequest(OPS.TEXT)); - invoke(false); - assertEqualsInt(1009, ai.get(), "Unexpected close reason found", ai.get()); - logMsg("Found expected close reason code", 1009); - } - - /* - * @testName: defaultMaxLengthTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Default -1; - */ - public void defaultMaxLengthTest() throws Exception { - setAnnotatedClientEndpoint(new WSDefaultMaxLengthClientEndpoint()); - setEntity("123456789"); - invoke(OPS.TEXT, "-1"); - } - - // //////////////////////////////////////////////////////////////////// - private String buildRequest(OPS op) { - return buildRequest("srv", "/", op.name()); - } - - private void invoke(OPS op, String search) throws Exception { - setProperty(Property.REQUEST, buildRequest(op)); - setProperty(Property.SEARCH_STRING, search, search); - invoke(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSClientIT.java new file mode 100644 index 0000000000..a03d306cd0 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSClientIT.java @@ -0,0 +1,1023 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.clientendpointonmessage; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.concurrent.atomic.AtomicInteger; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.EndpointCallback; +import com.sun.ts.tests.websocket.common.client.SendMessageCallback; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.StringPongMessage; +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamDecoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +import jakarta.websocket.CloseReason; +import jakarta.websocket.Session; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = 7948609603037530363L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_ee_clientendpointonmessage_web.war"); + archive.addClasses(OPS.class, WSCServer.class); + archive.addClasses(StringBean.class, StringBeanBinaryDecoder.class, StringBeanBinaryStreamDecoder.class, + StringBeanTextDecoder.class, StringBeanTextStreamDecoder.class); + archive.addClasses(IOUtil.class); + archive.addClasses(StringPongMessage.class); + return archive; + }; + + static final String ECHO = "Echo message to be sent to server endpoint"; + + public WSClientIT() throws Exception { + setup(); + } + + @Override + public void setup() throws Exception { + setCountDownLatchCount(3); + setContextRoot("ws_ee_clientendpointonmessage_web"); + addClientCallback(new EndpointCallback() { + @Override + public void onClose(Session session, CloseReason closeReason) { + getCountDownLatch().countDown(); + super.onClose(session, closeReason); + } + }); + super.setup(); + } + + /* Run test */ + + // TEXT ------------------------------------------ + + /* + * @testName: echoStringTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Echo String + */ + @Test + public void echoStringTest() throws Exception { + setAnnotatedClientEndpoint(new WSStringClientEndpoint()); + setProperty(Property.CONTENT, ECHO); + invoke(OPS.TEXT, ECHO); + } + + /* + * @testName: echoIntTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo int + */ + @Test + public void echoIntTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveIntClientEndpoint()); + int entity = Integer.MIN_VALUE; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoByteTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo byte + */ + @Test + public void echoByteTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveByteClientEndpoint()); + byte entity = 123; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoCharTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo char + */ + @Test + public void echoCharTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveCharClientEndpoint()); + char entity = 'E'; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoBooleanTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo boolean + */ + @Test + public void echoBooleanTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveBooleanClientEndpoint()); + boolean entity = true; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoShortTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo short + */ + @Test + public void echoShortTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveShortClientEndpoint()); + short entity = -32100; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoDoubleTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo double + */ + @Test + public void echoDoubleTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveDoubleClientEndpoint()); + double entity = -12345678.88; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoFloatTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo float + */ + @Test + public void echoFloatTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveFloatClientEndpoint()); + float entity = -12345678.88f; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoLongTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo long + */ + @Test + public void echoLongTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveLongClientEndpoint()); + long entity = Long.MIN_VALUE; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoFullIntTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo int + */ + @Test + public void echoFullIntTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullLongClientEndpoint()); + Integer entity = Integer.MIN_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullByteTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo byte + */ + @Test + public void echoFullByteTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullByteClientEndpoint()); + Byte entity = Byte.MIN_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullCharTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo char + */ + @Test + public void echoFullCharTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullCharClientEndpoint()); + Character entity = 'E'; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullBooleanTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo boolean + */ + @Test + public void echoFullBooleanTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullBooleanClientEndpoint()); + Boolean entity = true; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullShortTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo short + */ + @Test + public void echoFullShortTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullShortClientEndpoint()); + Short entity = Short.MAX_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullDoubleTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo double + */ + @Test + public void echoFullDoubleTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullDoubleClientEndpoint()); + Double entity = Double.MIN_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullFloatTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo float + */ + @Test + public void echoFullFloatTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullFloatClientEndpoint()); + Float entity = Float.MAX_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullLongTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo long + */ + @Test + public void echoFullLongTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullLongClientEndpoint()); + Long entity = Long.MAX_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoReaderTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: OnMessage(Reader) + */ + @Test + public void echoReaderTest() throws Exception { + setAnnotatedClientEndpoint(new WSReaderClientEndpoint()); + setProperty(Property.CONTENT, ECHO); + invoke(OPS.TEXT, ECHO); + } + + /* + * @testName: echoTextDecoderTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: OnMessage using TextDecoder + */ + @Test + public void echoTextDecoderTest() throws Exception { + setAnnotatedClientEndpoint(new WSTextDecoderClientEndpoint()); + setProperty(Property.CONTENT, ECHO); + invoke(OPS.TEXT, ECHO); + } + + /* + * @testName: echoTextStreamDecoderTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: OnMessage using TextStreamDecoder + */ + @Test + public void echoTextStreamDecoderTest() throws Exception { + setAnnotatedClientEndpoint(new WSTextStreamDecoderClientEndpoint()); + setProperty(Property.CONTENT, ECHO); + invoke(OPS.TEXT, ECHO); + } + + // -------------------------TEXT AND SESSION ------------------------------ + /* + * @testName: echoStringAndSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Echo String + */ + @Test + public void echoStringAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSStringAndSessionClientEndpoint()); + setProperty(Property.CONTENT, ECHO); + invoke(OPS.TEXT, ECHO); + } + + /* + * @testName: echoIntAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo int + */ + @Test + public void echoIntAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveIntAndSessionClientEndpoint()); + int entity = Integer.MIN_VALUE; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoByteAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo byte + */ + @Test + public void echoByteAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveByteAndSessionClientEndpoint()); + byte entity = 123; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoCharAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo char + */ + @Test + public void echoCharAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveCharAndSessionClientEndpoint()); + char entity = 'E'; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity) + "char"); + } + + /* + * @testName: echoBooleanAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo boolean + */ + @Test + public void echoBooleanAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveBooleanAndSessionClientEndpoint()); + boolean entity = true; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoShortAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo short + */ + @Test + public void echoShortAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveShortAndSessionClientEndpoint()); + short entity = -32100; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoDoubleAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo double + */ + @Test + public void echoDoubleAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveDoubleAndSessionClientEndpoint()); + double entity = -12345678.88; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoFloatAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo float + */ + @Test + public void echoFloatAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveFloatAndSessionClientEndpoint()); + float entity = -12345678.88f; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoLongAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo long + */ + @Test + public void echoLongAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSPrimitiveLongAndSessionClientEndpoint()); + long entity = Long.MIN_VALUE; + setEntity(entity); + invoke(OPS.TEXT, String.valueOf(entity)); + } + + /* + * @testName: echoFullIntAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo int + */ + @Test + public void echoFullIntAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullLongAndSessionClientEndpoint()); + Integer entity = Integer.MIN_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullByteAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo byte + */ + @Test + public void echoFullByteAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullByteAndSessionClientEndpoint()); + Byte entity = Byte.MIN_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullCharAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo char + */ + @Test + public void echoFullCharAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullCharAndSessionClientEndpoint()); + Character entity = 'E'; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullBooleanAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo boolean + */ + @Test + public void echoFullBooleanAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullBooleanAndSessionClientEndpoint()); + Boolean entity = true; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullShortAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo short + */ + @Test + public void echoFullShortAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullShortAndSessionClientEndpoint()); + Short entity = Short.MAX_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullDoubleAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo double + */ + @Test + public void echoFullDoubleAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullDoubleAndSessionClientEndpoint()); + Double entity = Double.MIN_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullFloatAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo float + */ + @Test + public void echoFullFloatAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullFloatAndSessionClientEndpoint()); + Float entity = Float.MAX_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoFullLongAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo long + */ + @Test + public void echoFullLongAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSFullLongAndSessionClientEndpoint()); + Long entity = Long.MAX_VALUE; + setEntity(entity); + invoke(OPS.TEXT, entity.toString()); + } + + /* + * @testName: echoReaderAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: OnMessage(Reader) + */ + @Test + public void echoReaderAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSReaderAndSessionClientEndpoint()); + setProperty(Property.CONTENT, ECHO); + invoke(OPS.TEXT, ECHO); + } + + /* + * @testName: echoTextDecoderAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: OnMessage using TextDecoder + */ + @Test + public void echoTextDecoderAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSTextDecoderAndSessionClientEndpoint()); + setProperty(Property.CONTENT, ECHO); + invoke(OPS.TEXT, ECHO); + } + + /* + * @testName: echoTextStreamDecoderAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: OnMessage using TextStreamDecoder + */ + @Test + public void echoTextStreamDecoderAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSTextStreamDecoderAndSessionClientEndpoint()); + setProperty(Property.CONTENT, ECHO); + invoke(OPS.TEXT, ECHO); + } + + // -----------------------PARTIAL--------------------------------- + + /* + * @testName: partialStringTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send partial message + */ + @Test + public void partialStringTest() throws Exception { + setAnnotatedClientEndpoint(new WSStringPartialClientEndpoint()); + String partial2 = "partialStringTest"; + String response = ECHO + "_(false)" + partial2 + "(true)"; + setEntity(ECHO + "_" + partial2); + invoke(OPS.TEXTPARTIAL, response); + } + + /* + * @testName: partialStringAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send string and string receive the combined string + */ + @Test + public void partialStringAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSStringPartialAndSessionClientEndpoint()); + String partial2 = "partialStringAndSessionTest"; + String response = ECHO + "_(false)" + partial2 + "(true)"; + setEntity(ECHO + "_" + partial2); + invoke(OPS.TEXTPARTIAL, response); + } + + // ----------------- BINARY ----------------------------------- + + /* + * @testName: echoByteBufferTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Echo ByteBuffer + */ + @Test + public void echoByteBufferTest() throws Exception { + setAnnotatedClientEndpoint(new WSByteBufferClientEndpoint()); + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + invoke(OPS.BINARY, ECHO); + } + + /* + * @testName: byteBufferToBytesTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Send ByteBuffer receive bytes + */ + @Test + public void byteBufferToBytesTest() throws Exception { + setAnnotatedClientEndpoint(new WSByteArrayClientEndpoint()); + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + invoke(OPS.BINARY, ECHO); + } + + /* + * @testName: byteBufferToInputStreamTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Send ByteBuffer receive InputStream + */ + @Test + public void byteBufferToInputStreamTest() throws Exception { + setAnnotatedClientEndpoint(new WSInputStreamClientEndpoint()); + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + invoke(OPS.BINARY, ECHO); + } + + /* + * @testName: byteBufferToBinaryDecoderTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Send ByteBuffer receive Object + */ + @Test + public void byteBufferToBinaryDecoderTest() throws Exception { + setAnnotatedClientEndpoint(new WSBinaryDecoderClientEndpoint()); + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + invoke(OPS.BINARY, ECHO); + } + + /* + * @testName: byteBufferToBinaryStreamDecoderTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Send ByteBuffer receive Object + */ + @Test + public void byteBufferToBinaryStreamDecoderTest() throws Exception { + setAnnotatedClientEndpoint(new WSBinaryStreamDecoderClientEndpoint()); + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + invoke(OPS.BINARY, ECHO); + } + + // ----------------- CONTROL ----------------------------------- + /* + * @testName: pongToPongTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: pong message + */ + @Test + public void pongToPongTest() throws Exception { + setAnnotatedClientEndpoint(new WSPongMessageClientEndpoint()); + setEntity(ECHO); + invoke(OPS.PONG, ECHO); + } + + /* + * @testName: pongToPongAndSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: pong message + */ + @Test + public void pongToPongAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSPongMessageAndSessionClientEndpoint()); + setEntity(ECHO); + invoke(OPS.PONG, ECHO); + } + + // ----------------- BINARY AND SESSION ----------------------------------- + /* + * @testName: echoByteBufferAndSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Echo ByteBuffer + */ + @Test + public void echoByteBufferAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSByteBufferAndSessionClientEndpoint()); + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + invoke(OPS.BINARY, ECHO); + } + + /* + * @testName: byteBufferToBytesAndSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Send ByteBuffer receive bytes + */ + @Test + public void byteBufferToBytesAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSByteArrayAndSessionClientEndpoint()); + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + invoke(OPS.BINARY, ECHO); + } + + /* + * @testName: byteBufferToInputStreamAndSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Send ByteBuffer receive InputStream + */ + @Test + public void byteBufferToInputStreamAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSInputStreamAndSessionClientEndpoint()); + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + invoke(OPS.BINARY, ECHO); + } + + /* + * @testName: byteBufferToBinaryDecoderAndSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Send ByteBuffer receive Object + */ + @Test + public void byteBufferToBinaryDecoderAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSBinaryDecoderAndSessionClientEndpoint()); + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + invoke(OPS.BINARY, ECHO); + } + + /* + * @testName: byteBufferToBinaryStreamDecoderAndSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Send ByteBuffer receive Object + */ + @Test + public void byteBufferToBinaryStreamDecoderAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSBinaryStreamDecoderAndSessionClientEndpoint()); + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + invoke(OPS.BINARY, ECHO); + } + + // ----------------- PARTIAL BINARY ----------------------------------- + /* + * @testName: partialByteArrayTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send bytearray and bytearray receive the combined message + */ + @Test + public void partialByteArrayTest() throws Exception { + setAnnotatedClientEndpoint(new WSByteArrayPartialClientEndpoint()); + String partial2 = "partialByteArrayTest"; + String response = ECHO + "_(false)" + partial2 + "(true)"; + setEntity(ByteBuffer.wrap((ECHO + "_" + partial2).getBytes())); + invoke(OPS.BINARYPARTIAL, response); + } + + /* + * @testName: partialByteArrayAndSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send bytearray and bytearray receive the combined message + */ + @Test + public void partialByteArrayAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSByteArrayPartialAndSessionClientEndpoint()); + String partial2 = "partialByteArrayAndSessionTest"; + String response = ECHO + "_(false)" + partial2 + "(true)"; + setEntity(ByteBuffer.wrap((ECHO + "_" + partial2).getBytes())); + invoke(OPS.BINARYPARTIAL, response); + } + + /* + * @testName: partialByteBufferTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message + */ + @Test + public void partialByteBufferTest() throws Exception { + setAnnotatedClientEndpoint(new WSByteBufferPartialClientEndpoint()); + String partial2 = "partialByteBufferTest"; + String response = ECHO + "_(false)" + partial2 + "(true)"; + setEntity(ByteBuffer.wrap((ECHO + "_" + partial2).getBytes())); + invoke(OPS.BINARYPARTIAL, response); + } + + /* + * @testName: partialByteBufferAndSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message + */ + @Test + public void partialByteBufferAndSessionTest() throws Exception { + setAnnotatedClientEndpoint(new WSByteBufferPartialAndSessionClientEndpoint()); + String partial2 = "partialByteBufferAndSessionTest"; + String response = ECHO + "_(false)" + partial2 + "(true)"; + setEntity(ByteBuffer.wrap((ECHO + "_" + partial2).getBytes())); + invoke(OPS.BINARYPARTIAL, response); + } + + // --------------------------------- MAX LEN + /* + * @testName: maxLengthOKTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: the message is shorter than maxMessageLength + */ + @Test + public void maxLengthOKTest() throws Exception { + setAnnotatedClientEndpoint(new WSMaxLengthClientEndpoint()); + String entity = "12345"; + setEntity(entity); + invoke(OPS.TEXT, entity); + } + + /* + * @testName: maxLengthFailsTest + * + * @assertion_ids: WebSocket:JAVADOC:80; WebSocket:SPEC:WSC-4.7.1-1; + * + * @test_Strategy: the message is longer than maxMessageLength + */ + @Test + public void maxLengthFailsTest() throws Exception { + setCountDownLatchCount(1); + final AtomicInteger ai = new AtomicInteger(0); + setEntity("123456"); + EndpointCallback callback = new SendMessageCallback(entity) { + @Override + public void onClose(Session session, CloseReason closeReason) { + ai.set(closeReason.getCloseCode().getCode()); + getCountDownLatch().countDown(); + } + }; + setClientCallback(callback); + setAnnotatedClientEndpoint(new WSMaxLengthClientEndpoint()); + setProperty(Property.REQUEST, buildRequest(OPS.TEXT)); + invoke(false); + assertEqualsInt(1009, ai.get(), "Unexpected close reason found", ai.get()); + logMsg("Found expected close reason code", 1009); + } + + /* + * @testName: defaultMaxLengthTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Default -1; + */ + @Test + public void defaultMaxLengthTest() throws Exception { + setAnnotatedClientEndpoint(new WSDefaultMaxLengthClientEndpoint()); + setEntity("123456789"); + invoke(OPS.TEXT, "-1"); + } + + // //////////////////////////////////////////////////////////////////// + private String buildRequest(OPS op) { + return buildRequest("srv", "/", op.name()); + } + + private void invoke(OPS op, String search) throws Exception { + setProperty(Property.REQUEST, buildRequest(op)); + setProperty(Property.SEARCH_STRING, search, search); + invoke(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSDefaultMaxLengthClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSDefaultMaxLengthClientEndpoint.java index 7e4f34baef..0d21c20b8d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSDefaultMaxLengthClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSDefaultMaxLengthClientEndpoint.java @@ -33,43 +33,42 @@ import jakarta.websocket.Session; @ClientEndpoint() -public class WSDefaultMaxLengthClientEndpoint - extends AnnotatedClientEndpoint { +public class WSDefaultMaxLengthClientEndpoint extends AnnotatedClientEndpoint { - public WSDefaultMaxLengthClientEndpoint() { - super(new StringClientEndpoint()); - } + public WSDefaultMaxLengthClientEndpoint() { + super(new StringClientEndpoint()); + } - @SuppressWarnings("unused") - @OnMessage - public String echo(String echo) { - try { - Method m = getClass().getMethod("echo", String.class); - OnMessage onm = m.getAnnotation(OnMessage.class); - long size = onm.maxMessageSize(); - String msg = String.valueOf(size); - super.onMessage(msg); - return msg; - } catch (Exception e) { - return IOUtil.printStackTrace(e); - } - } + @SuppressWarnings("unused") + @OnMessage + public String echo(String echo) { + try { + Method m = getClass().getMethod("echo", String.class); + OnMessage onm = m.getAnnotation(OnMessage.class); + long size = onm.maxMessageSize(); + String msg = String.valueOf(size); + super.onMessage(msg); + return msg; + } catch (Exception e) { + return IOUtil.printStackTrace(e); + } + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullBooleanAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullBooleanAndSessionClientEndpoint.java index 254e5b2c80..c5ce06cabd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullBooleanAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullBooleanAndSessionClientEndpoint.java @@ -32,30 +32,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSFullBooleanAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(Boolean b, Session s) throws IOException, EncodeException { - super.onMessage(b.toString()); - s.getBasicRemote().sendObject(b); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSFullBooleanAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(Boolean b, Session s) throws IOException, EncodeException { + super.onMessage(b.toString()); + s.getBasicRemote().sendObject(b); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullBooleanClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullBooleanClientEndpoint.java index e51ec0d584..a3ae4b3b4b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullBooleanClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullBooleanClientEndpoint.java @@ -31,28 +31,28 @@ @ClientEndpoint public class WSFullBooleanClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(Boolean b) { - String msg = b.toString(); - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public String echo(Boolean b) { + String msg = b.toString(); + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullByteAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullByteAndSessionClientEndpoint.java index 07a8577c8d..dd08c894ae 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullByteAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullByteAndSessionClientEndpoint.java @@ -32,30 +32,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSFullByteAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(Byte b, Session s) throws IOException, EncodeException { - super.onMessage(b.toString()); - s.getBasicRemote().sendObject(b); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSFullByteAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(Byte b, Session s) throws IOException, EncodeException { + super.onMessage(b.toString()); + s.getBasicRemote().sendObject(b); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullByteClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullByteClientEndpoint.java index ff944a4a08..4d87bf3d5f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullByteClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullByteClientEndpoint.java @@ -31,28 +31,28 @@ @ClientEndpoint public class WSFullByteClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(Byte b) { - String msg = b.toString(); - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public String echo(Byte b) { + String msg = b.toString(); + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullCharAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullCharAndSessionClientEndpoint.java index 6d97d19a77..459bf4fdbc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullCharAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullCharAndSessionClientEndpoint.java @@ -32,30 +32,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSFullCharAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(Session s, Character c) throws IOException, EncodeException { - super.onMessage(c.toString()); - s.getBasicRemote().sendObject(c); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSFullCharAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(Session s, Character c) throws IOException, EncodeException { + super.onMessage(c.toString()); + s.getBasicRemote().sendObject(c); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullCharClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullCharClientEndpoint.java index a795a82d26..a3a593e0a1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullCharClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullCharClientEndpoint.java @@ -31,28 +31,28 @@ @ClientEndpoint public class WSFullCharClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(Character c) { - String msg = c.toString(); - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public String echo(Character c) { + String msg = c.toString(); + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullDoubleAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullDoubleAndSessionClientEndpoint.java index 50cc304a75..ea9c56260f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullDoubleAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullDoubleAndSessionClientEndpoint.java @@ -32,31 +32,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSFullDoubleAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(Session s, Double d) throws IOException, EncodeException { - String msg = d.toString(); - super.onMessage(msg); - s.getBasicRemote().sendObject(d); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSFullDoubleAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(Session s, Double d) throws IOException, EncodeException { + String msg = d.toString(); + super.onMessage(msg); + s.getBasicRemote().sendObject(d); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullDoubleClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullDoubleClientEndpoint.java index 9341bb9132..198a3b800b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullDoubleClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullDoubleClientEndpoint.java @@ -30,28 +30,28 @@ @ClientEndpoint public class WSFullDoubleClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(Double d) { - String msg = d.toString(); - super.onMessage(msg); - return msg; - } + @OnMessage + public String echo(Double d) { + String msg = d.toString(); + super.onMessage(msg); + return msg; + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullFloatAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullFloatAndSessionClientEndpoint.java index 3694fb7879..378f5a2a1a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullFloatAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullFloatAndSessionClientEndpoint.java @@ -32,29 +32,28 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSFullFloatAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - @OnMessage - public void echo(Float f, Session s) throws IOException, EncodeException { - super.onMessage(f.toString()); - s.getBasicRemote().sendObject(f); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSFullFloatAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + @OnMessage + public void echo(Float f, Session s) throws IOException, EncodeException { + super.onMessage(f.toString()); + s.getBasicRemote().sendObject(f); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullFloatClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullFloatClientEndpoint.java index 046bb98d14..8d82db0b56 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullFloatClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullFloatClientEndpoint.java @@ -30,28 +30,28 @@ @ClientEndpoint public class WSFullFloatClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(Float f) { - String msg = f.toString(); - super.onMessage(msg); - return msg; - } + @OnMessage + public String echo(Float f) { + String msg = f.toString(); + super.onMessage(msg); + return msg; + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullIntAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullIntAndSessionClientEndpoint.java index a3eb56ca68..01bd0cace6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullIntAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullIntAndSessionClientEndpoint.java @@ -32,29 +32,28 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSFullIntAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - @OnMessage - public void echo(Integer i, Session s) throws IOException, EncodeException { - super.onMessage(i.toString()); - s.getBasicRemote().sendObject(i); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSFullIntAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + @OnMessage + public void echo(Integer i, Session s) throws IOException, EncodeException { + super.onMessage(i.toString()); + s.getBasicRemote().sendObject(i); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullIntClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullIntClientEndpoint.java index f2152b4b5d..7956fea6fd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullIntClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullIntClientEndpoint.java @@ -30,28 +30,28 @@ @ClientEndpoint public class WSFullIntClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(Integer i) { - String msg = i.toString(); - super.onMessage(msg); - return msg; - } + @OnMessage + public String echo(Integer i) { + String msg = i.toString(); + super.onMessage(msg); + return msg; + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullLongAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullLongAndSessionClientEndpoint.java index c8ef592c78..372e9b5f00 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullLongAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullLongAndSessionClientEndpoint.java @@ -32,30 +32,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSFullLongAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(Long l, Session s) throws IOException, EncodeException { - super.onMessage(l.toString()); - s.getBasicRemote().sendObject(l); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSFullLongAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(Long l, Session s) throws IOException, EncodeException { + super.onMessage(l.toString()); + s.getBasicRemote().sendObject(l); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullLongClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullLongClientEndpoint.java index 2f0a7c2a35..a926dc30c6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullLongClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullLongClientEndpoint.java @@ -31,28 +31,28 @@ @ClientEndpoint public class WSFullLongClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(Long l) { - String msg = l.toString(); - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public String echo(Long l) { + String msg = l.toString(); + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullShortAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullShortAndSessionClientEndpoint.java index 4a84e9e150..f41bd42ff0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullShortAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullShortAndSessionClientEndpoint.java @@ -32,32 +32,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSFullShortAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(Short s, Session session) - throws IOException, EncodeException { - String msg = s.toString(); - super.onMessage(msg); - session.getBasicRemote().sendObject(s); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSFullShortAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(Short s, Session session) throws IOException, EncodeException { + String msg = s.toString(); + super.onMessage(msg); + session.getBasicRemote().sendObject(s); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullShortClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullShortClientEndpoint.java index da90ead6f1..b123e1b900 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullShortClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSFullShortClientEndpoint.java @@ -31,28 +31,28 @@ @ClientEndpoint public class WSFullShortClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(Short s) { - String msg = s.toString(); - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public String echo(Short s) { + String msg = s.toString(); + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSInputStreamAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSInputStreamAndSessionClientEndpoint.java index 6e7a193d8d..bfee082414 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSInputStreamAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSInputStreamAndSessionClientEndpoint.java @@ -33,31 +33,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSInputStreamAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(InputStream stream, Session s) throws IOException { - String message = IOUtil.readFromStream(stream); - super.onMessage(message); - s.getBasicRemote().sendText(message); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSInputStreamAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(InputStream stream, Session s) throws IOException { + String message = IOUtil.readFromStream(stream); + super.onMessage(message); + s.getBasicRemote().sendText(message); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSInputStreamClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSInputStreamClientEndpoint.java index 5cd54ce173..5d03251121 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSInputStreamClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSInputStreamClientEndpoint.java @@ -35,28 +35,28 @@ @ClientEndpoint public class WSInputStreamClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(InputStream stream) throws IOException { - String message = IOUtil.readFromStream(stream); - super.onMessage(message); - return message; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public String echo(InputStream stream) throws IOException { + String message = IOUtil.readFromStream(stream); + super.onMessage(message); + return message; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSMaxLengthClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSMaxLengthClientEndpoint.java index a904f31f11..56d42b7c23 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSMaxLengthClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSMaxLengthClientEndpoint.java @@ -31,30 +31,30 @@ @ClientEndpoint public class WSMaxLengthClientEndpoint extends AnnotatedStringClientEndpoint { - public static final String MSG = "maxMessageSize casts an exception as expected:"; - - @OnMessage(maxMessageSize = 5L) - public String echo(String echo) { - super.onMessage(echo); - return echo; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - String message = WebSocketCommonClient.getCauseMessage(t); - WebSocketCommonClient.logMsg(MSG, message); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + public static final String MSG = "maxMessageSize casts an exception as expected:"; + + @OnMessage(maxMessageSize = 5L) + public String echo(String echo) { + super.onMessage(echo); + return echo; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + String message = WebSocketCommonClient.getCauseMessage(t); + WebSocketCommonClient.logMsg(MSG, message); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPongMessageAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPongMessageAndSessionClientEndpoint.java index 353f7d572f..a0ebc79842 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPongMessageAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPongMessageAndSessionClientEndpoint.java @@ -33,31 +33,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPongMessageAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(PongMessage msg, Session s) throws IOException { - String data = IOUtil.byteBufferToString(msg.getApplicationData()); - super.onMessage(data); - s.getBasicRemote().sendText(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPongMessageAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(PongMessage msg, Session s) throws IOException { + String data = IOUtil.byteBufferToString(msg.getApplicationData()); + super.onMessage(data); + s.getBasicRemote().sendText(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPongMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPongMessageClientEndpoint.java index 0ad85ba4d5..c7b135898f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPongMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPongMessageClientEndpoint.java @@ -33,28 +33,28 @@ @ClientEndpoint public class WSPongMessageClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(PongMessage msg) { - String data = IOUtil.byteBufferToString(msg.getApplicationData()); - super.onMessage(data); - return data; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public String echo(PongMessage msg) { + String data = IOUtil.byteBufferToString(msg.getApplicationData()); + super.onMessage(data); + return data; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveBooleanAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveBooleanAndSessionClientEndpoint.java index 5a961bd085..f84ccdb56a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveBooleanAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveBooleanAndSessionClientEndpoint.java @@ -31,30 +31,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveBooleanAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - @OnMessage - public void echo(boolean b, Session s) throws IOException { - String msg = String.valueOf(b); - super.onMessage(msg); - s.getBasicRemote().sendText(msg); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveBooleanAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + @OnMessage + public void echo(boolean b, Session s) throws IOException { + String msg = String.valueOf(b); + super.onMessage(msg); + s.getBasicRemote().sendText(msg); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveBooleanClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveBooleanClientEndpoint.java index 066443f31f..457827bddc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveBooleanClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveBooleanClientEndpoint.java @@ -29,30 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveBooleanClientEndpoint - extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(boolean b) { - String msg = String.valueOf(b); - super.onMessage(msg); - return msg; - } +public class WSPrimitiveBooleanClientEndpoint extends AnnotatedStringClientEndpoint { + @OnMessage + public String echo(boolean b) { + String msg = String.valueOf(b); + super.onMessage(msg); + return msg; + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveByteAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveByteAndSessionClientEndpoint.java index c61f716680..165d9c2e3c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveByteAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveByteAndSessionClientEndpoint.java @@ -31,30 +31,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveByteAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - @OnMessage - public void echo(byte b, Session s) throws IOException { - String msg = String.valueOf(b); - super.onMessage(msg); - s.getBasicRemote().sendText(msg); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveByteAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + @OnMessage + public void echo(byte b, Session s) throws IOException { + String msg = String.valueOf(b); + super.onMessage(msg); + s.getBasicRemote().sendText(msg); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveByteClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveByteClientEndpoint.java index 2be4439fa3..781f549baf 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveByteClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveByteClientEndpoint.java @@ -29,30 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveByteClientEndpoint - extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(byte b) { - String msg = String.valueOf(b); - super.onMessage(msg); - return msg; - } +public class WSPrimitiveByteClientEndpoint extends AnnotatedStringClientEndpoint { + @OnMessage + public String echo(byte b) { + String msg = String.valueOf(b); + super.onMessage(msg); + return msg; + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveCharAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveCharAndSessionClientEndpoint.java index efe85f5c02..2d7393bd4b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveCharAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveCharAndSessionClientEndpoint.java @@ -31,31 +31,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveCharAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(char c, Session s) throws IOException { - String msg = String.valueOf(c) + "char"; - super.onMessage(msg); - s.getBasicRemote().sendText(msg); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveCharAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(char c, Session s) throws IOException { + String msg = String.valueOf(c) + "char"; + super.onMessage(msg); + s.getBasicRemote().sendText(msg); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveCharClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveCharClientEndpoint.java index ab37e440bd..c3b20ec955 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveCharClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveCharClientEndpoint.java @@ -29,31 +29,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveCharClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public String echo(char c) { - String msg = String.valueOf(c) + "char"; - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveCharClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public String echo(char c) { + String msg = String.valueOf(c) + "char"; + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveDoubleAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveDoubleAndSessionClientEndpoint.java index aa8a7d064d..3f643a77f4 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveDoubleAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveDoubleAndSessionClientEndpoint.java @@ -31,31 +31,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveDoubleAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(double d, Session s) throws IOException { - String msg = String.valueOf(d); - super.onMessage(msg); - s.getBasicRemote().sendText(msg); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveDoubleAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(double d, Session s) throws IOException { + String msg = String.valueOf(d); + super.onMessage(msg); + s.getBasicRemote().sendText(msg); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveDoubleClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveDoubleClientEndpoint.java index 7f3d7a1b2d..4870e7aee9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveDoubleClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveDoubleClientEndpoint.java @@ -29,31 +29,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveDoubleClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public String echo(double d) { - String msg = String.valueOf(d); - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveDoubleClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public String echo(double d) { + String msg = String.valueOf(d); + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveFloatAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveFloatAndSessionClientEndpoint.java index 6b5dbe8007..39a9cc8322 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveFloatAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveFloatAndSessionClientEndpoint.java @@ -31,31 +31,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveFloatAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(float f, Session s) throws IOException { - String msg = String.valueOf(f); - super.onMessage(msg); - s.getBasicRemote().sendText(msg); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveFloatAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(float f, Session s) throws IOException { + String msg = String.valueOf(f); + super.onMessage(msg); + s.getBasicRemote().sendText(msg); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveFloatClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveFloatClientEndpoint.java index e646b3825d..2605daa61a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveFloatClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveFloatClientEndpoint.java @@ -29,31 +29,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveFloatClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public String echo(float f) { - String msg = String.valueOf(f); - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveFloatClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public String echo(float f) { + String msg = String.valueOf(f); + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveIntAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveIntAndSessionClientEndpoint.java index 56497b0510..52eb24f731 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveIntAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveIntAndSessionClientEndpoint.java @@ -31,31 +31,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveIntAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echoInt(int i, Session s) throws IOException { - String msg = String.valueOf(i); - super.onMessage(msg); - s.getBasicRemote().sendText(msg); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveIntAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echoInt(int i, Session s) throws IOException { + String msg = String.valueOf(i); + super.onMessage(msg); + s.getBasicRemote().sendText(msg); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveIntClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveIntClientEndpoint.java index 05d23183ac..962b09e753 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveIntClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveIntClientEndpoint.java @@ -29,31 +29,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveIntClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public String echoInt(int i) { - String msg = String.valueOf(i); - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveIntClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public String echoInt(int i) { + String msg = String.valueOf(i); + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveLongAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveLongAndSessionClientEndpoint.java index b71654b613..e42a5b3632 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveLongAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveLongAndSessionClientEndpoint.java @@ -31,31 +31,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveLongAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(Session s, long l) throws IOException { - String msg = String.valueOf(l); - super.onMessage(msg); - s.getBasicRemote().sendText(msg); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveLongAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(Session s, long l) throws IOException { + String msg = String.valueOf(l); + super.onMessage(msg); + s.getBasicRemote().sendText(msg); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveLongClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveLongClientEndpoint.java index 992dca324c..3b6c7ecd59 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveLongClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveLongClientEndpoint.java @@ -29,31 +29,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveLongClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public String echo(long l) { - String msg = String.valueOf(l); - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveLongClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public String echo(long l) { + String msg = String.valueOf(l); + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveShortAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveShortAndSessionClientEndpoint.java index a9fd42fae4..20c05fa272 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveShortAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveShortAndSessionClientEndpoint.java @@ -31,30 +31,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveShortAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - @OnMessage - public void echo(short s, Session session) throws IOException { - String msg = String.valueOf(s); - super.onMessage(msg); - session.getBasicRemote().sendText(msg); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSPrimitiveShortAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + @OnMessage + public void echo(short s, Session session) throws IOException { + String msg = String.valueOf(s); + super.onMessage(msg); + session.getBasicRemote().sendText(msg); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveShortClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveShortClientEndpoint.java index c8e2fdb593..97105a9b4e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveShortClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSPrimitiveShortClientEndpoint.java @@ -29,30 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSPrimitiveShortClientEndpoint - extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(short s) { - String msg = String.valueOf(s); - super.onMessage(msg); - return msg; - } +public class WSPrimitiveShortClientEndpoint extends AnnotatedStringClientEndpoint { + @OnMessage + public String echo(short s) { + String msg = String.valueOf(s); + super.onMessage(msg); + return msg; + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSReaderAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSReaderAndSessionClientEndpoint.java index ba34ec9dd8..2739e9b1b4 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSReaderAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSReaderAndSessionClientEndpoint.java @@ -32,31 +32,30 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSReaderAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void reader(java.io.Reader r, Session s) throws IOException { - String msg = IOUtil.readFromReader(r); - super.onMessage(msg); - s.getBasicRemote().sendText(msg); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSReaderAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void reader(java.io.Reader r, Session s) throws IOException { + String msg = IOUtil.readFromReader(r); + super.onMessage(msg); + s.getBasicRemote().sendText(msg); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSReaderClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSReaderClientEndpoint.java index f0ff0aa2a5..dedec25b04 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSReaderClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSReaderClientEndpoint.java @@ -34,28 +34,28 @@ @ClientEndpoint public class WSReaderClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String reader(java.io.Reader r) throws IOException { - String msg = IOUtil.readFromReader(r); - super.onMessage(msg); - return msg; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public String reader(java.io.Reader r) throws IOException { + String msg = IOUtil.readFromReader(r); + super.onMessage(msg); + return msg; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringAndSessionClientEndpoint.java index f101b619e2..462b6b545b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringAndSessionClientEndpoint.java @@ -31,30 +31,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSStringAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public void echo(String echo, Session s) throws IOException { - super.onMessage(echo); - s.getBasicRemote().sendText(echo); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSStringAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public void echo(String echo, Session s) throws IOException { + super.onMessage(echo); + s.getBasicRemote().sendText(echo); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringClientEndpoint.java index 3e9ca5e938..600619c4de 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringClientEndpoint.java @@ -31,27 +31,27 @@ @ClientEndpoint public class WSStringClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public String echo(String echo) { - super.onMessage(echo); - return echo; - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public String echo(String echo) { + super.onMessage(echo); + return echo; + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringPartialAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringPartialAndSessionClientEndpoint.java index e179d233cd..01ccbc10e2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringPartialAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringPartialAndSessionClientEndpoint.java @@ -31,37 +31,35 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSStringPartialAndSessionClientEndpoint - extends AnnotatedStringClientEndpoint { +public class WSStringPartialAndSessionClientEndpoint extends AnnotatedStringClientEndpoint { - private StringBuilder sb = new StringBuilder(); + private StringBuilder sb = new StringBuilder(); - @OnMessage - public void partial(String msg, boolean finito, Session s) - throws IOException { - sb.append(msg).append("(").append(finito).append(")"); - if (finito) { - s.getBasicRemote().sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); - super.onMessage(sb.toString()); - sb = new StringBuilder(); - } - } + @OnMessage + public void partial(String msg, boolean finito, Session s) throws IOException { + sb.append(msg).append("(").append(finito).append(")"); + if (finito) { + s.getBasicRemote().sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); + super.onMessage(sb.toString()); + sb = new StringBuilder(); + } + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringPartialClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringPartialClientEndpoint.java index 62aea925bd..aaac2f4faa 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringPartialClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSStringPartialClientEndpoint.java @@ -31,43 +31,41 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSStringPartialClientEndpoint - extends AnnotatedStringClientEndpoint { +public class WSStringPartialClientEndpoint extends AnnotatedStringClientEndpoint { - protected Session session; + protected Session session; - /** - * Buffer the messages until they are all received - */ - private StringBuilder sb = new StringBuilder(); + /** + * Buffer the messages until they are all received + */ + private StringBuilder sb = new StringBuilder(); - @OnMessage - public void partial(String msg, boolean finito) throws IOException { - sb.append(msg).append("(").append(finito).append(")"); - if (finito) { - session.getBasicRemote() - .sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); - super.onMessage(sb.toString()); - sb = new StringBuilder(); - } - } + @OnMessage + public void partial(String msg, boolean finito) throws IOException { + sb.append(msg).append("(").append(finito).append(")"); + if (finito) { + session.getBasicRemote().sendText(sb.toString().replaceAll("[(][a-z]*[)]", "")); + super.onMessage(sb.toString()); + sb = new StringBuilder(); + } + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextDecoderAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextDecoderAndSessionClientEndpoint.java index fd8af01786..c5313747cf 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextDecoderAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextDecoderAndSessionClientEndpoint.java @@ -34,34 +34,33 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = { StringBeanTextDecoder.class }) -public class WSTextDecoderAndSessionClientEndpoint - extends AnnotatedClientEndpoint { +public class WSTextDecoderAndSessionClientEndpoint extends AnnotatedClientEndpoint { - public WSTextDecoderAndSessionClientEndpoint() { - super(new StringBeanClientEndpoint()); - } + public WSTextDecoderAndSessionClientEndpoint() { + super(new StringBeanClientEndpoint()); + } - @OnMessage - public void echo(StringBean bean, Session s) throws IOException { - super.onMessage(bean); - s.getBasicRemote().sendText(bean.get()); - } + @OnMessage + public void echo(StringBean bean, Session s) throws IOException { + super.onMessage(bean); + s.getBasicRemote().sendText(bean.get()); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextDecoderClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextDecoderClientEndpoint.java index 0d2c9a149d..43d1a922ca 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextDecoderClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextDecoderClientEndpoint.java @@ -32,34 +32,33 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = { StringBeanTextDecoder.class }) -public class WSTextDecoderClientEndpoint - extends AnnotatedClientEndpoint { +public class WSTextDecoderClientEndpoint extends AnnotatedClientEndpoint { - public WSTextDecoderClientEndpoint() { - super(new StringBeanClientEndpoint()); - } + public WSTextDecoderClientEndpoint() { + super(new StringBeanClientEndpoint()); + } - @OnMessage - public String echo(StringBean bean) { - super.onMessage(bean); - return bean.get(); - } + @OnMessage + public String echo(StringBean bean) { + super.onMessage(bean); + return bean.get(); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextStreamDecoderAndSessionClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextStreamDecoderAndSessionClientEndpoint.java index 9add6b5a0f..884857da0a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextStreamDecoderAndSessionClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextStreamDecoderAndSessionClientEndpoint.java @@ -34,34 +34,33 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = { StringBeanTextStreamDecoder.class }) -public class WSTextStreamDecoderAndSessionClientEndpoint - extends AnnotatedClientEndpoint { +public class WSTextStreamDecoderAndSessionClientEndpoint extends AnnotatedClientEndpoint { - public WSTextStreamDecoderAndSessionClientEndpoint() { - super(new StringBeanClientEndpoint()); - } + public WSTextStreamDecoderAndSessionClientEndpoint() { + super(new StringBeanClientEndpoint()); + } - @OnMessage - public void echo(Session s, StringBean bean) throws IOException { - super.onMessage(bean); - s.getBasicRemote().sendText(bean.get()); - } + @OnMessage + public void echo(Session s, StringBean bean) throws IOException { + super.onMessage(bean); + s.getBasicRemote().sendText(bean.get()); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextStreamDecoderClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextStreamDecoderClientEndpoint.java index 7373b374b6..dc3c6a6151 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextStreamDecoderClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointonmessage/WSTextStreamDecoderClientEndpoint.java @@ -31,30 +31,29 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = { StringBeanTextStreamDecoder.class }) -public class WSTextStreamDecoderClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public String echo(StringBean bean) { - super.onMessage(bean.get()); - return bean.get(); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSTextStreamDecoderClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public String echo(StringBean bean) { + super.onMessage(bean.get()); + return bean.get(); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCBinaryEncoderClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCBinaryEncoderClientEndpoint.java index 7929f88b10..84923bba9c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCBinaryEncoderClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCBinaryEncoderClientEndpoint.java @@ -31,30 +31,29 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = { StringBeanBinaryEncoder.class }) -public class WSCBinaryEncoderClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public StringBean echo(String data) { - super.onMessage(data); - return new StringBean(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSCBinaryEncoderClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public StringBean echo(String data) { + super.onMessage(data); + return new StringBean(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCBinaryStreamEncoderClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCBinaryStreamEncoderClientEndpoint.java index 15b40c0e91..d62439d492 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCBinaryStreamEncoderClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCBinaryStreamEncoderClientEndpoint.java @@ -31,30 +31,29 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = { StringBeanBinaryStreamEncoder.class }) -public class WSCBinaryStreamEncoderClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public StringBean echo(String data) { - super.onMessage(data); - return new StringBean(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSCBinaryStreamEncoderClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public StringBean echo(String data) { + super.onMessage(data); + return new StringBean(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCByteArrayClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCByteArrayClientEndpoint.java index 5cec7723e2..ba6b8f691c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCByteArrayClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCByteArrayClientEndpoint.java @@ -31,27 +31,27 @@ @ClientEndpoint public class WSCByteArrayClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public byte[] bytesToString(String data) { - super.onMessage(data); - return data.getBytes(); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public byte[] bytesToString(String data) { + super.onMessage(data); + return data.getBytes(); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCByteBufferClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCByteBufferClientEndpoint.java index a2521858bb..9e4bc187a7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCByteBufferClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCByteBufferClientEndpoint.java @@ -32,27 +32,27 @@ @ClientEndpoint public class WSCByteBufferClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public ByteBuffer echo(String data) { - super.onMessage(data); - return ByteBuffer.wrap(data.getBytes()); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public ByteBuffer echo(String data) { + super.onMessage(data); + return ByteBuffer.wrap(data.getBytes()); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullBooleanClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullBooleanClientEndpoint.java index 49a9ddb3ba..2245aa08e9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullBooleanClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullBooleanClientEndpoint.java @@ -29,30 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSCFullBooleanClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public Boolean echo(String data) { - super.onMessage(data); - return Boolean.valueOf(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSCFullBooleanClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public Boolean echo(String data) { + super.onMessage(data); + return Boolean.valueOf(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullByteClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullByteClientEndpoint.java index 09e464df2b..f9a507b554 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullByteClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullByteClientEndpoint.java @@ -31,27 +31,27 @@ @ClientEndpoint public class WSCFullByteClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public Byte echo(String data) { - super.onMessage(data); - return Byte.valueOf(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public Byte echo(String data) { + super.onMessage(data); + return Byte.valueOf(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullCharClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullCharClientEndpoint.java index b90b272926..f5a1a28e2c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullCharClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullCharClientEndpoint.java @@ -31,27 +31,27 @@ @ClientEndpoint public class WSCFullCharClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public Character echo(String data) { - super.onMessage(data); - return Character.valueOf(data.charAt(0)); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public Character echo(String data) { + super.onMessage(data); + return Character.valueOf(data.charAt(0)); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullDoubleClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullDoubleClientEndpoint.java index 1054e2b003..bf27243d3e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullDoubleClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullDoubleClientEndpoint.java @@ -30,27 +30,27 @@ @ClientEndpoint public class WSCFullDoubleClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public Double echo(String data) { - super.onMessage(data); - return Double.valueOf(data); - } + @OnMessage + public Double echo(String data) { + super.onMessage(data); + return Double.valueOf(data); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullFloatClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullFloatClientEndpoint.java index bf9cd23141..c54050a49d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullFloatClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullFloatClientEndpoint.java @@ -30,27 +30,27 @@ @ClientEndpoint public class WSCFullFloatClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public Float echo(String data) { - super.onMessage(data); - return Float.valueOf(data); - } + @OnMessage + public Float echo(String data) { + super.onMessage(data); + return Float.valueOf(data); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullIntClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullIntClientEndpoint.java index a90ccbc496..39d7a5b3fd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullIntClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullIntClientEndpoint.java @@ -30,27 +30,27 @@ @ClientEndpoint public class WSCFullIntClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public Integer echo(String data) { - super.onMessage(data); - return Integer.valueOf(data); - } + @OnMessage + public Integer echo(String data) { + super.onMessage(data); + return Integer.valueOf(data); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullLongClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullLongClientEndpoint.java index a95bfba43f..2da9698d7a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullLongClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullLongClientEndpoint.java @@ -31,27 +31,27 @@ @ClientEndpoint public class WSCFullLongClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public Long echo(String data) { - super.onMessage(data); - return Long.valueOf(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public Long echo(String data) { + super.onMessage(data); + return Long.valueOf(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullShortClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullShortClientEndpoint.java index 8ce618e4b4..8f8f69acae 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullShortClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCFullShortClientEndpoint.java @@ -31,27 +31,27 @@ @ClientEndpoint public class WSCFullShortClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public Short echo(String data) { - super.onMessage(data); - return Short.valueOf(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnMessage + public Short echo(String data) { + super.onMessage(data); + return Short.valueOf(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveBooleanClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveBooleanClientEndpoint.java index c09c022ef3..03ef0d9281 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveBooleanClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveBooleanClientEndpoint.java @@ -29,29 +29,28 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSCPrimitiveBooleanClientEndpoint - extends AnnotatedStringClientEndpoint { - @OnMessage - public boolean echo(String data) { - super.onMessage(data); - return Boolean.parseBoolean(data); - } +public class WSCPrimitiveBooleanClientEndpoint extends AnnotatedStringClientEndpoint { + @OnMessage + public boolean echo(String data) { + super.onMessage(data); + return Boolean.parseBoolean(data); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveByteClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveByteClientEndpoint.java index 2bb4a09951..cf586de155 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveByteClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveByteClientEndpoint.java @@ -29,29 +29,28 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSCPrimitiveByteClientEndpoint - extends AnnotatedStringClientEndpoint { - @OnMessage - public byte echo(String data) { - super.onMessage(data); - return Byte.parseByte(data); - } +public class WSCPrimitiveByteClientEndpoint extends AnnotatedStringClientEndpoint { + @OnMessage + public byte echo(String data) { + super.onMessage(data); + return Byte.parseByte(data); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveCharClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveCharClientEndpoint.java index 97ef0aa92e..9e68a6ea22 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveCharClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveCharClientEndpoint.java @@ -29,30 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSCPrimitiveCharClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public char echo(String data) { - super.onMessage(data); - return Character.valueOf(data.charAt(0)).charValue(); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSCPrimitiveCharClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public char echo(String data) { + super.onMessage(data); + return Character.valueOf(data.charAt(0)).charValue(); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveDoubleClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveDoubleClientEndpoint.java index bda44b19eb..670f4ffd9c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveDoubleClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveDoubleClientEndpoint.java @@ -29,30 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSCPrimitiveDoubleClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public double echo(String data) { - super.onMessage(data); - return Double.parseDouble(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSCPrimitiveDoubleClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public double echo(String data) { + super.onMessage(data); + return Double.parseDouble(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveFloatClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveFloatClientEndpoint.java index 83d5480cc7..c2ceb5d774 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveFloatClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveFloatClientEndpoint.java @@ -29,30 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSCPrimitiveFloatClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public float echo(String data) { - super.onMessage(data); - return Float.parseFloat(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSCPrimitiveFloatClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public float echo(String data) { + super.onMessage(data); + return Float.parseFloat(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveIntClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveIntClientEndpoint.java index 43099b3f1b..56a33cb116 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveIntClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveIntClientEndpoint.java @@ -29,30 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSCPrimitiveIntClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public int echoInt(String data) { - super.onMessage(data); - return Integer.valueOf(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSCPrimitiveIntClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public int echoInt(String data) { + super.onMessage(data); + return Integer.valueOf(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveLongClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveLongClientEndpoint.java index 468ae396f4..16c70f12c4 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveLongClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveLongClientEndpoint.java @@ -29,30 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSCPrimitiveLongClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public long echo(String data) { - super.onMessage(data); - return Long.parseLong(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSCPrimitiveLongClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public long echo(String data) { + super.onMessage(data); + return Long.parseLong(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveShortClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveShortClientEndpoint.java index 39d43705de..1a2653ed2a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveShortClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCPrimitiveShortClientEndpoint.java @@ -29,29 +29,28 @@ import jakarta.websocket.Session; @ClientEndpoint -public class WSCPrimitiveShortClientEndpoint - extends AnnotatedStringClientEndpoint { - @OnMessage - public short echo(String data) { - super.onMessage(data); - return Short.parseShort(data); - } +public class WSCPrimitiveShortClientEndpoint extends AnnotatedStringClientEndpoint { + @OnMessage + public short echo(String data) { + super.onMessage(data); + return Short.parseShort(data); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCServer.java index 676cf1b951..d79a3e7598 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -32,64 +32,64 @@ @ServerEndpoint("/srv") public class WSCServer { - private enum State { - INIT, SECOND, FINAL - }; + private enum State { + INIT, SECOND, FINAL + }; - // endpoint instance is created once per connection - private State state = State.INIT; + // endpoint instance is created once per connection + private State state = State.INIT; - @OnOpen - public void onOpen(final Session session) { - session.addMessageHandler(new MessageHandler.Whole() { - @Override - public void onMessage(ByteBuffer message) { - echo(IOUtil.byteBufferToString(message), session); - } - }); - } + @OnOpen + public void onOpen(final Session session) { + session.addMessageHandler(new MessageHandler.Whole() { + @Override + public void onMessage(ByteBuffer message) { + echo(IOUtil.byteBufferToString(message), session); + } + }); + } - @OnMessage - public void echo(String echo, Session session) { - switch (state) { - case INIT: - state = State.SECOND; - op(echo, session); - break; - case SECOND: - state = State.FINAL; - op(echo, session); - break; - case FINAL: - // do not send anything, otherwise it would not ever stop - try { - session.close(); - } catch (IOException e) { - onError(session, e); - } - break; - } - } + @OnMessage + public void echo(String echo, Session session) { + switch (state) { + case INIT: + state = State.SECOND; + op(echo, session); + break; + case SECOND: + state = State.FINAL; + op(echo, session); + break; + case FINAL: + // do not send anything, otherwise it would not ever stop + try { + session.close(); + } catch (IOException e) { + onError(session, e); + } + break; + } + } - private void op(String echo, Session session) { - try { - session.getBasicRemote().sendText(echo); - } catch (IOException e) { - onError(session, e); - } - } + private void op(String echo, Session session) { + try { + session.getBasicRemote().sendText(echo); + } catch (IOException e) { + onError(session, e); + } + } - @OnError - public void onError(Session session, Throwable t) { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - try { - if (session.isOpen()) - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } + @OnError + public void onError(Session session, Throwable t) { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + try { + if (session.isOpen()) + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCTextEncoderClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCTextEncoderClientEndpoint.java index 9be9b3a65a..0e9fceaed8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCTextEncoderClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCTextEncoderClientEndpoint.java @@ -31,30 +31,29 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = { StringBeanTextEncoder.class }) -public class WSCTextEncoderClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public StringBean echo(String data) { - super.onMessage(data); - return new StringBean(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSCTextEncoderClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public StringBean echo(String data) { + super.onMessage(data); + return new StringBean(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCTextStreamEncoderClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCTextStreamEncoderClientEndpoint.java index 68e114c3a8..d03f879799 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCTextStreamEncoderClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSCTextStreamEncoderClientEndpoint.java @@ -31,30 +31,29 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = { StringBeanTextStreamEncoder.class }) -public class WSCTextStreamEncoderClientEndpoint - extends AnnotatedStringClientEndpoint { - - @OnMessage - public StringBean echo(String data) { - super.onMessage(data); - return new StringBean(data); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } +public class WSCTextStreamEncoderClientEndpoint extends AnnotatedStringClientEndpoint { + + @OnMessage + public StringBean echo(String data) { + super.onMessage(data); + return new StringBean(data); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSClient.java deleted file mode 100644 index e7eefde317..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSClient.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.clientendpointreturntype; - -import com.sun.ts.tests.websocket.common.client.AnnotatedClientEndpoint; -import com.sun.ts.tests.websocket.common.client.ByteBufferClientEndpoint; -import com.sun.ts.tests.websocket.common.client.EndpointCallback; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -import jakarta.websocket.CloseReason; -import jakarta.websocket.Session; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 3375865828117749296L; - - public WSClient() { - setContextRoot("wsc_ee_clientendpointreturntype_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - // TEXT ------------------------------------------ - - /* - * @testName: dataTypesTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: test primitive and boxed datatypes - */ - public void dataTypesTest() throws Exception { - invokeSequence("true", new WSCPrimitiveBooleanClientEndpoint(), - new WSCFullBooleanClientEndpoint()); - invokeSequence("123", new WSCPrimitiveByteClientEndpoint(), - new WSCFullByteClientEndpoint()); - invokeSequence(String.valueOf(Short.MAX_VALUE), - new WSCPrimitiveShortClientEndpoint(), - new WSCFullShortClientEndpoint()); - invokeSequence(String.valueOf(Short.MIN_VALUE), - new WSCPrimitiveIntClientEndpoint(), new WSCFullIntClientEndpoint()); - invokeSequence(String.valueOf(Short.MIN_VALUE), - new WSCPrimitiveLongClientEndpoint(), new WSCFullLongClientEndpoint()); - invokeSequence(String.valueOf(123.456f), - new WSCPrimitiveFloatClientEndpoint(), - new WSCFullFloatClientEndpoint()); - invokeSequence(String.valueOf(789.012), - new WSCPrimitiveDoubleClientEndpoint(), - new WSCFullDoubleClientEndpoint()); - invokeSequence(String.valueOf('A'), new WSCPrimitiveCharClientEndpoint(), - new WSCFullCharClientEndpoint()); - } - - /* - * @testName: textEncoderTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test text encoder - */ - public void textEncoderTest() throws Exception { - invokeSequence("textEncoderTest", new WSCTextEncoderClientEndpoint()); - } - - /* - * @testName: textStreamEncoderTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test text stream encoder - */ - public void textStreamEncoderTest() throws Exception { - invokeSequence("textStreamEncoderTest", - new WSCTextStreamEncoderClientEndpoint()); - } - - // -----------------Binary -------------------------------- - - /* - * @testName: binaryEncoderTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test binary encoder - */ - public void binaryEncoderTest() throws Exception { - setClientEndpoint(ByteBufferClientEndpoint.class); - invokeSequence("binaryEncoderTest", new WSCBinaryEncoderClientEndpoint()); - } - - /* - * @testName: binaryStreamEncoderTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test binary stream encoder - */ - public void binaryStreamEncoderTest() throws Exception { - setClientEndpoint(ByteBufferClientEndpoint.class); - invokeSequence("binaryStreamEncoderTest", - new WSCBinaryStreamEncoderClientEndpoint()); - } - - /* - * @testName: byteArrayTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test byte array - */ - public void byteArrayTest() throws Exception { - setClientEndpoint(ByteBufferClientEndpoint.class); - invokeSequence("byteArrayTest", new WSCByteArrayClientEndpoint()); - } - - /* - * @testName: byteBufferTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test byte array - */ - public void byteBufferTest() throws Exception { - setClientEndpoint(ByteBufferClientEndpoint.class); - invokeSequence("byteBufferTest", new WSCByteBufferClientEndpoint()); - } - - // Private ----------------------------------------- - private void invokeSequence(String search, - AnnotatedClientEndpoint... endpoints) throws Exception { - for (AnnotatedClientEndpoint endpoint : endpoints) { - setCountDownLatchCount(3); - setAnnotatedClientEndpoint(endpoint); - addClientCallback(new EndpointCallback() { - @Override - public void onClose(Session session, CloseReason closeReason) { - getCountDownLatch().countDown(); - super.onClose(session, closeReason); - } - }); - invoke("srv", search, search); - } - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSClientIT.java new file mode 100644 index 0000000000..7e29d06e44 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointreturntype/WSClientIT.java @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.clientendpointreturntype; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.AnnotatedClientEndpoint; +import com.sun.ts.tests.websocket.common.client.ByteBufferClientEndpoint; +import com.sun.ts.tests.websocket.common.client.EndpointCallback; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamEncoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +import jakarta.websocket.CloseReason; +import jakarta.websocket.Session; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 3375865828117749296L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_clientendpointreturntype_web.war"); + archive.addClasses(WSCServer.class); + archive.addClasses(StringBean.class, StringBeanBinaryEncoder.class, StringBeanBinaryStreamEncoder.class, + StringBeanTextEncoder.class, StringBeanTextStreamEncoder.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_clientendpointreturntype_web"); + } + + /* Run test */ + + // TEXT ------------------------------------------ + + /* + * @testName: dataTypesTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: test primitive and boxed datatypes + */ + @Test + public void dataTypesTest() throws Exception { + invokeSequence("true", new WSCPrimitiveBooleanClientEndpoint(), new WSCFullBooleanClientEndpoint()); + invokeSequence("123", new WSCPrimitiveByteClientEndpoint(), new WSCFullByteClientEndpoint()); + invokeSequence(String.valueOf(Short.MAX_VALUE), new WSCPrimitiveShortClientEndpoint(), + new WSCFullShortClientEndpoint()); + invokeSequence(String.valueOf(Short.MIN_VALUE), new WSCPrimitiveIntClientEndpoint(), + new WSCFullIntClientEndpoint()); + invokeSequence(String.valueOf(Short.MIN_VALUE), new WSCPrimitiveLongClientEndpoint(), + new WSCFullLongClientEndpoint()); + invokeSequence(String.valueOf(123.456f), new WSCPrimitiveFloatClientEndpoint(), + new WSCFullFloatClientEndpoint()); + invokeSequence(String.valueOf(789.012), new WSCPrimitiveDoubleClientEndpoint(), + new WSCFullDoubleClientEndpoint()); + invokeSequence(String.valueOf('A'), new WSCPrimitiveCharClientEndpoint(), new WSCFullCharClientEndpoint()); + } + + /* + * @testName: textEncoderTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test text encoder + */ + @Test + public void textEncoderTest() throws Exception { + invokeSequence("textEncoderTest", new WSCTextEncoderClientEndpoint()); + } + + /* + * @testName: textStreamEncoderTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test text stream encoder + */ + @Test + public void textStreamEncoderTest() throws Exception { + invokeSequence("textStreamEncoderTest", new WSCTextStreamEncoderClientEndpoint()); + } + + // -----------------Binary -------------------------------- + + /* + * @testName: binaryEncoderTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test binary encoder + */ + @Test + public void binaryEncoderTest() throws Exception { + setClientEndpoint(ByteBufferClientEndpoint.class); + invokeSequence("binaryEncoderTest", new WSCBinaryEncoderClientEndpoint()); + } + + /* + * @testName: binaryStreamEncoderTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test binary stream encoder + */ + @Test + public void binaryStreamEncoderTest() throws Exception { + setClientEndpoint(ByteBufferClientEndpoint.class); + invokeSequence("binaryStreamEncoderTest", new WSCBinaryStreamEncoderClientEndpoint()); + } + + /* + * @testName: byteArrayTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test byte array + */ + @Test + public void byteArrayTest() throws Exception { + setClientEndpoint(ByteBufferClientEndpoint.class); + invokeSequence("byteArrayTest", new WSCByteArrayClientEndpoint()); + } + + /* + * @testName: byteBufferTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test byte array + */ + @Test + public void byteBufferTest() throws Exception { + setClientEndpoint(ByteBufferClientEndpoint.class); + invokeSequence("byteBufferTest", new WSCByteBufferClientEndpoint()); + } + + // Private ----------------------------------------- + private void invokeSequence(String search, AnnotatedClientEndpoint... endpoints) throws Exception { + for (AnnotatedClientEndpoint endpoint : endpoints) { + setCountDownLatchCount(3); + setAnnotatedClientEndpoint(endpoint); + addClientCallback(new EndpointCallback() { + @Override + public void onClose(Session session, CloseReason closeReason) { + getCountDownLatch().countDown(); + super.onClose(session, closeReason); + } + }); + invoke("srv", search, search); + } + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/CoderClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/CoderClient.java new file mode 100644 index 0000000000..e1ca028c31 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/CoderClient.java @@ -0,0 +1,946 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.coder; + +import java.nio.ByteBuffer; + +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.client.ByteBufferClientEndpoint; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.stringbean.StringBean; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class CoderClient extends WebSocketCommonClient { + private static final long serialVersionUID = -6699156272937435550L; + + protected static final String ECHO = "Echo message"; + + + /* Run test */ + /* + * @testName: textEncoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:61; WebSocket:JAVADOC:190; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text encoder init and destroy were called The websocket + * implementation creates a new instance of the encoder per endpoint instance + * per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode ServerEndpoint.encoders + */ + @Test + public void textEncoderInitDestroyTest() throws Exception { + invokeClear(); + invokeEcho("textencoder"); + invokeGetInit(InitDestroyTextEncoder.class); + invokeGetDestroy(InitDestroyTextEncoder.class); + } + + /* + * @testName: textStreamEncoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:63; WebSocket:JAVADOC:190; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text stream encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode ServerEndpoint.encoders + */ + @Test + public void textStreamEncoderInitDestroyTest() throws Exception { + invokeClear(); + invokeEcho("textstreamencoder"); + invokeGetInit(InitDestroyTextStreamEncoder.class); + invokeGetDestroy(InitDestroyTextStreamEncoder.class); + } + + /* + * @testName: binaryEncoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:56; WebSocket:JAVADOC:190; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode ServerEndpoint.encoders + */ + @Test + public void binaryEncoderInitDestroyTest() throws Exception { + invokeClear(); + invokeBinaryEncoderEcho("binaryencoder"); + invokeGetInit(InitDestroyBinaryEncoder.class); + invokeGetDestroy(InitDestroyBinaryEncoder.class); + } + + /* + * @testName: binaryStreamEncoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:58; WebSocket:JAVADOC:190; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary stream encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode ServerEndpoint.encoders + */ + @Test + public void binaryStreamEncoderInitDestroyTest() throws Exception { + invokeClear(); + invokeBinaryEncoderEcho("binarystreamencoder"); + invokeGetInit(InitDestroyBinaryStreamEncoder.class); + invokeGetDestroy(InitDestroyBinaryStreamEncoder.class); + } + + // ---------------------------------------------------------------------- + + /* + * @testName: textDecoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; WebSocket:JAVADOC:189; + * WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text decoder init and destroy were called The websocket + * implementation creates a new instance of the encoder per endpoint instance + * per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode, willdecode ServerEndpoint.decoders + */ + @Test + public void textDecoderInitDestroyTest() throws Exception { + invokeClear(); + invokeEcho("textdecoder"); + invokeGetInit(InitDestroyTextDecoder.class); + invokeGetDestroy(InitDestroyTextDecoder.class); + } + + /* + * @testName: textStreamDecoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:46; WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text stream decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode ServerEndpoint.decoders + */ + @Test + public void textStreamDecoderInitDestroyTest() throws Exception { + invokeClear(); + invokeEcho("textstreamdecoder"); + invokeGetInit(InitDestroyTextStreamDecoder.class); + invokeGetDestroy(InitDestroyTextStreamDecoder.class); + } + + /* + * @testName: binaryDecoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; WebSocket:JAVADOC:189; + * WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode, willDecode ServerEndpoint.decoders + */ + @Test + public void binaryDecoderInitDestroyTest() throws Exception { + invokeClear(); + invokeBinaryDecoderEcho("binarydecoder"); + invokeGetInit(InitDestroyBinaryDecoder.class); + invokeGetDestroy(InitDestroyBinaryDecoder.class); + } + + /* + * @testName: binaryStreamDecoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:40; WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary stream decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode ServerEndpoint.decoders + */ + @Test + public void binaryStreamDecoderInitDestroyTest() throws Exception { + invokeClear(); + invokeBinaryDecoderEcho("binarystreamdecoder"); + invokeGetInit(InitDestroyBinaryStreamDecoder.class); + invokeGetDestroy(InitDestroyBinaryStreamDecoder.class); + } + + // ---------------------------------------------------------------------- + + /* + * @testName: textEncoderEncodeTest + * + * @assertion_ids: WebSocket:JAVADOC:61; WebSocket:JAVADOC:190; + * WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text encoder encode was called + * + * ServerEndpoint.encoders + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Test + public void textEncoderEncodeTest() throws Exception { + invokeClear(); + invokeEcho("textencoder"); + invokeGetCode(InitDestroyTextEncoder.class); + } + + /* + * @testName: textStreamEncoderEncodeTest + * + * @assertion_ids: WebSocket:JAVADOC:63; WebSocket:JAVADOC:190; + * WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text stream encode was called + * + * ServerEndpoint.encoders + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + public void textStreamEncoderEncodeTest() throws Exception { + invokeClear(); + invokeEcho("textstreamencoder"); + invokeGetCode(InitDestroyTextStreamEncoder.class); + } + + /* + * @testName: binaryEncoderEncodeTest + * + * @assertion_ids: WebSocket:JAVADOC:56; WebSocket:JAVADOC:190; + * WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary encoder encode was called + * + * ServerEndpoint.encoders + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Test + public void binaryEncoderEncodeTest() throws Exception { + invokeClear(); + invokeBinaryEncoderEcho("binaryencoder"); + invokeGetCode(InitDestroyBinaryEncoder.class); + } + + /* + * @testName: binaryStreamEncoderEncodeTest + * + * @assertion_ids: WebSocket:JAVADOC:58; WebSocket:JAVADOC:190; + * WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary stream encoder encode was called + * + * ServerEndpoint.encoders + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Test + public void binaryStreamEncoderEncodeTest() throws Exception { + invokeClear(); + invokeBinaryEncoderEcho("binarystreamencoder"); + invokeGetCode(InitDestroyBinaryStreamEncoder.class); + } + + // ----------------------------------------------------------------------- + + /* + * @testName: textDecoderDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; + * WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; + * WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test text decoder decode and willDecode were called + * + * ServerEndpoint.decoders + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Test + public void textDecoderDecodeTest() throws Exception { + invokeClear(); + invokeEcho("textdecoder"); + invokeGetCode(InitDestroyTextDecoder.class); + invokeGetWillCode(InitDestroyTextDecoder.class); + } + + /* + * @testName: textStreamDecoderDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:46; WebSocket:JAVADOC:189; + * WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text stream decoder decode was called + * ServerEndpoint.decoders + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Test + public void textStreamDecoderDecodeTest() throws Exception { + invokeClear(); + invokeEcho("textstreamdecoder"); + invokeGetCode(InitDestroyTextStreamDecoder.class); + } + + /* + * @testName: binaryDecoderDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; + * WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; + * WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test binary decoder decode and willDecode were called + * + * ServerEndpoint.decoders + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Test + public void binaryDecoderDecodeTest() throws Exception { + invokeClear(); + invokeBinaryDecoderEcho("binarydecoder"); + invokeGetCode(InitDestroyBinaryDecoder.class); + invokeGetWillCode(InitDestroyBinaryDecoder.class); + } + + /* + * @testName: binaryStreamDecoderDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:40; WebSocket:JAVADOC:189; + * WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary stream decoder decode was called + * + * ServerEndpoint.decoders + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Test + public void binaryStreamDecoderDecodeTest() throws Exception { + invokeClear(); + invokeBinaryDecoderEcho("binarystreamdecoder"); + invokeGetCode(InitDestroyBinaryStreamDecoder.class); + } + + /* + * @testName: binaryDecoderWillDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; + * WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; + * WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test binary decoder with willDecode returning false will not + * be used + * + * ServerEndpoint.decoders + */ + @Test + public void binaryDecoderWillDecodeTest() throws Exception { + invokeClear(); + invokeBinaryDecoderEcho("binarywilldecode"); + invokeGetWillCode(WillDecodeFirstBinaryDecoder.class, WillDecodeSecondBinaryDecoder.class); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, WillDecodeFirstBinaryDecoder.class.getName()); + invokeGetCode(WillDecodeSecondBinaryDecoder.class); + } + + /* + * @testName: textDecoderWillDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; + * WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; + * WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test text decoder with willDecode returning false will not be + * used + * + * ServerEndpoint.decoders + */ + @Test + public void textDecoderWillDecodeTest() throws Exception { + invokeClear(); + invokeEcho("textwilldecode"); + invokeGetWillCode(WillDecodeFirstTextDecoder.class, WillDecodeSecondTextDecoder.class); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, WillDecodeFirstTextDecoder.class.getName()); + invokeGetCode(WillDecodeSecondTextDecoder.class); + } + + // ==================================================================== + /* + * @testName: textEncoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:61; WebSocket:JAVADOC:3; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text encoder init and destroy were called The websocket + * implementation creates a new instance of the encoder per endpoint instance + * per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode ClientEndpoint.encoders + */ + @Test + public void textEncoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithTextEncoder()); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertInit(InitDestroyTextEncoder.class); + assertDestroy(InitDestroyTextEncoder.class); + } + + /* + * @testName: textStreamEncoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:63; WebSocket:JAVADOC:3; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text stream encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode ClientEndpoint.encoders + */ + @Test + public void textStreamEncoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithTextStreamEncoder()); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertInit(InitDestroyTextStreamEncoder.class); + assertDestroy(InitDestroyTextStreamEncoder.class); + } + + /* + * @testName: binaryEncoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:56; WebSocket:JAVADOC:3; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode ClientEndpoint.encoders + */ + @Test + public void binaryEncoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithBinaryEncoder()); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertInit(InitDestroyBinaryEncoder.class); + assertDestroy(InitDestroyBinaryEncoder.class); + } + + /* + * @testName: binaryStreamEncoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:58; WebSocket:JAVADOC:3; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary stream encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode ClientEndpoint.encoders + */ + @Test + public void binaryStreamEncoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithBinaryStreamEncoder()); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertInit(InitDestroyBinaryStreamEncoder.class); + assertDestroy(InitDestroyBinaryStreamEncoder.class); + } + + // --------------------------------------------------------------------- + + /* + * @testName: textDecoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; WebSocket:JAVADOC:2; + * WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text decoder init and destroy were called The websocket + * implementation creates a new instance of the encoder per endpoint instance + * per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode, willdecode ClientEndpoint.decoders + */ + @Test + public void textDecoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithTextDecoder()); + invoke("simpleecho", ECHO, ECHO); + assertInit(InitDestroyTextDecoder.class); + assertDestroy(InitDestroyTextDecoder.class); + } + + /* + * @testName: textStreamDecoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:46; WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text stream decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode ClientEndpoint.decoders + */ + @Test + public void textStreamDecoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithTextStreamDecoder()); + invoke("simpleecho", ECHO, ECHO); + assertInit(InitDestroyTextStreamDecoder.class); + assertDestroy(InitDestroyTextStreamDecoder.class); + } + + /* + * @testName: binaryDecoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; WebSocket:JAVADOC:2; + * WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode, willDecode ClientEndpoint.decoders + */ + @Test + public void binaryDecoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithBinaryDecoder()); + invoke("simplebin", ECHO, ECHO); + assertInit(InitDestroyBinaryDecoder.class); + assertDestroy(InitDestroyBinaryDecoder.class); + } + + /* + * @testName: binaryStreamDecoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:40; WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary stream decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode ClientEndpoint.decoders + */ + @Test + public void binaryStreamDecoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithBinaryStreamDecoder()); + invoke("simplebin", ECHO, ECHO); + assertInit(InitDestroyBinaryStreamDecoder.class); + assertDestroy(InitDestroyBinaryStreamDecoder.class); + } + + // ---------------------------------------------------------------------- + + /* + * @testName: textEncoderEncodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:61; WebSocket:JAVADOC:3; + * WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text encoder encode was called ClientEndpoint.encoders + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Test + public void textEncoderEncodeOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithTextEncoder()); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertCode(InitDestroyTextEncoder.class); + } + + /* + * @testName: textStreamEncoderEncodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:63; WebSocket:JAVADOC:3; + * WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text stream encode was called ClientEndpoint.encoders + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Test + public void textStreamEncoderEncodeOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithTextStreamEncoder()); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertCode(InitDestroyTextStreamEncoder.class); + } + + /* + * @testName: binaryEncoderEncodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:56; WebSocket:JAVADOC:3; + * WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary encoder encode was called ClientEndpoint.encoders + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Test + public void binaryEncoderEncodeOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithBinaryEncoder()); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertCode(InitDestroyBinaryEncoder.class); + } + + /* + * @testName: binaryStreamEncoderEncodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:58; WebSocket:JAVADOC:3; + * WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary stream encoder encode was called + * ClientEndpoint.encoders + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Test + public void binaryStreamEncoderEncodeOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithBinaryStreamEncoder()); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertCode(InitDestroyBinaryStreamEncoder.class); + } + + // ---------------------------------------------------------------------- + + /* + * @testName: textDecoderDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; + * WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test text decoder decode and willDecode were called + * ClientEndpoint.decoders + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Test + public void textDecoderDecodeOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithTextDecoder()); + invoke("simpleecho", ECHO, ECHO); + assertCode(InitDestroyTextDecoder.class); + assertWillCode(InitDestroyTextDecoder.class); + } + + /* + * @testName: textStreamDecoderDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:46; WebSocket:JAVADOC:2; + * WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text stream decoder decode was called + * ClientEndpoint.decoders + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Test + public void textStreamDecoderDecodeOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithTextStreamDecoder()); + invoke("simpleecho", ECHO, ECHO); + assertCode(InitDestroyTextStreamDecoder.class); + } + + /* + * @testName: binaryDecoderDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; + * WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test binary decoder decode and willDecode were called + * ClientEndpoint.decoders + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Test + public void binaryDecoderDecodeOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithBinaryDecoder()); + invoke("simplebin", ECHO, ECHO); + assertCode(InitDestroyBinaryDecoder.class); + assertWillCode(InitDestroyBinaryDecoder.class); + } + + /* + * @testName: binaryStreamDecoderDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:40; WebSocket:JAVADOC:2; + * WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary stream decoder decode was called + * ClientEndpoint.decoders + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Test + public void binaryStreamDecoderDecodeOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithBinaryStreamDecoder()); + invoke("simplebin", ECHO, ECHO); + assertCode(InitDestroyBinaryStreamDecoder.class); + } + + /* + * @testName: binaryDecoderWillDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; + * WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test binary decoder with willDecode returning false will not + * be used ClientEndpoint.decoders + */ + @Test + public void binaryDecoderWillDecodeOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithBinaryDecoders()); + invoke("simplebin", ECHO, ECHO); + assertWillCode(WillDecodeFirstBinaryDecoder.class); + assertWillCode(WillDecodeSecondBinaryDecoder.class); + assertNotCode(WillDecodeFirstBinaryDecoder.class); + assertCode(WillDecodeSecondBinaryDecoder.class); + } + + /* + * @testName: textDecoderWillDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; + * WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test text decoder with willDecode returning false will not be + * used ClientEndpoint.decoders + */ + @Test + public void textDecoderWillDecodeOnClientTest() throws Exception { + clientClear(); + setAnnotatedClientEndpoint(new WSCEndpointWithTextDecoders()); + invoke("simpleecho", ECHO, ECHO); + assertWillCode(WillDecodeFirstTextDecoder.class); + assertWillCode(WillDecodeSecondTextDecoder.class); + assertNotCode(WillDecodeFirstTextDecoder.class); + assertCode(WillDecodeSecondTextDecoder.class); + } + + // ////////////////////////////////////////////////////////////////// + private void invokeClear() throws Exception { + invokeLogger("clearall", "clearall"); + } + + private void invokeEcho(String endpoint) throws Exception { + invoke(endpoint, ECHO, ECHO); + } + + private void invokeBinaryEncoderEcho(String endpoint) throws Exception { + setClientEndpoint(ByteBufferClientEndpoint.class); + invokeEcho(endpoint); + } + + private void invokeBinaryDecoderEcho(String endpoint) throws Exception { + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + setProperty(Property.REQUEST, buildRequest(endpoint)); + setProperty(Property.SEARCH_STRING, ECHO); + invoke(); + } + + private void invokeGetInit(Class searchClazz) throws Exception { + invokeLogger("getinit", searchClazz.getName()); + } + + private void invokeGetDestroy(Class searchClazz) throws Exception { + // Sleep current tread to give server time to call destroy() should not + // be needed, just for sake + TestUtil.sleepMsec(500); + invokeLogger("getdestroy", searchClazz.getName()); + } + + private void invokeGetCode(Class... searchClasses) throws Exception { + for (Class searchClazz : searchClasses) + invokeLogger("getcode", searchClazz.getName()); + } + + private void invokeGetWillCode(Class... searchClasses) throws Exception { + for (Class searchClazz : searchClasses) + invokeLogger("getwillcode", searchClazz.getName()); + } + + private void invokeLogger(String method, String search) throws Exception { + invoke("logger", method, search); + } + + // //////////////////////////// Client ////////////////////////////////// + protected void clientClear() { + WSCLoggerServer.operation("clearall"); + } + + protected void assertInit(Class searchClazz) throws Exception { + String log = WSCLoggerServer.operation("getinit"); + assertContains(log, searchClazz.getName(), searchClazz.getName(), + "has not been found in a list of classes calling the init() method, only [", log, "] has been found"); + logMsg("init() has been called on", searchClazz, "as expected"); + } + + protected void assertDestroy(Class searchClazz) throws Exception { + System.gc(); + // Sleep current tread to give server time to call destroy() should not + // be needed, just for sake + TestUtil.sleepMsec(500); + String log = WSCLoggerServer.operation("getdestroy"); + assertContains(log, searchClazz.getName(), searchClazz.getName(), + "has not been found in a list of classes calling the destroy() method, only [", log, + "] has been found"); + logMsg("destroy() has been called on", searchClazz, "as expected"); + } + + protected void assertCode(Class searchClass) throws Exception { + String log = WSCLoggerServer.operation("getcode"); + assertContains(log, searchClass.getName(), searchClass.getName(), + "has not been found in a list of classes calling the code() method, only [", log, "] has been found"); + logMsg("code() has been called on", searchClass, "as expected"); + } + + protected void assertWillCode(Class searchClass) throws Exception { + String log = WSCLoggerServer.operation("getwillcode"); + assertContains(log, searchClass.getName(), searchClass.getName(), + "has not been found in a list of classes calling the willCode() method, only [", log, + "] has been found"); + logMsg("willCode() has been called on", searchClass, "as expected"); + } + + protected void assertNotCode(Class searchClass) throws Exception { + String log = WSCLoggerServer.operation("getcode"); + assertNotContains(log, searchClass.getName(), searchClass.getName(), + "has unexpectedly been found in a list of classes calling the code() method"); + logMsg("code() has not been called on", searchClass, "as expected"); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryDecoder.java index 60738d2fe1..f73b8e4f8c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryDecoder.java @@ -26,25 +26,25 @@ import jakarta.websocket.EndpointConfig; public class InitDestroyBinaryDecoder extends StringBeanBinaryDecoder { - @Override - public void init(EndpointConfig config) { - Logger.onInit(getClass()); - } - - @Override - public void destroy() { - Logger.onDestroy(getClass()); - } - - @Override - public StringBean decode(ByteBuffer arg0) throws DecodeException { - Logger.onCode(getClass()); - return super.decode(arg0); - }; - - @Override - public boolean willDecode(ByteBuffer arg0) { - Logger.onWillCode(getClass()); - return super.willDecode(arg0); - } + @Override + public void init(EndpointConfig config) { + Logger.onInit(getClass()); + } + + @Override + public void destroy() { + Logger.onDestroy(getClass()); + } + + @Override + public StringBean decode(ByteBuffer arg0) throws DecodeException { + Logger.onCode(getClass()); + return super.decode(arg0); + }; + + @Override + public boolean willDecode(ByteBuffer arg0) { + Logger.onWillCode(getClass()); + return super.willDecode(arg0); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryEncoder.java index 0fabebcf25..4ac02cca0c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryEncoder.java @@ -26,19 +26,19 @@ import jakarta.websocket.EndpointConfig; public class InitDestroyBinaryEncoder extends StringBeanBinaryEncoder { - @Override - public void init(EndpointConfig config) { - Logger.onInit(getClass()); - } + @Override + public void init(EndpointConfig config) { + Logger.onInit(getClass()); + } - @Override - public void destroy() { - Logger.onDestroy(getClass()); - } + @Override + public void destroy() { + Logger.onDestroy(getClass()); + } - @Override - public ByteBuffer encode(StringBean bean) throws EncodeException { - Logger.onCode(getClass()); - return super.encode(bean); - } + @Override + public ByteBuffer encode(StringBean bean) throws EncodeException { + Logger.onCode(getClass()); + return super.encode(bean); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryStreamDecoder.java index 7bfb391c46..c44116c8aa 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryStreamDecoder.java @@ -26,22 +26,20 @@ import jakarta.websocket.DecodeException; import jakarta.websocket.EndpointConfig; -public class InitDestroyBinaryStreamDecoder - extends StringBeanBinaryStreamDecoder { - @Override - public void init(EndpointConfig config) { - Logger.onInit(getClass()); - } +public class InitDestroyBinaryStreamDecoder extends StringBeanBinaryStreamDecoder { + @Override + public void init(EndpointConfig config) { + Logger.onInit(getClass()); + } - @Override - public void destroy() { - Logger.onDestroy(getClass()); - } + @Override + public void destroy() { + Logger.onDestroy(getClass()); + } - @Override - public StringBean decode(InputStream arg0) - throws DecodeException, IOException { - Logger.onCode(getClass()); - return super.decode(arg0); - }; + @Override + public StringBean decode(InputStream arg0) throws DecodeException, IOException { + Logger.onCode(getClass()); + return super.decode(arg0); + }; } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryStreamEncoder.java index cbbf985319..cbb3fd7ab3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyBinaryStreamEncoder.java @@ -26,22 +26,20 @@ import jakarta.websocket.EncodeException; import jakarta.websocket.EndpointConfig; -public class InitDestroyBinaryStreamEncoder - extends StringBeanBinaryStreamEncoder { - @Override - public void init(EndpointConfig config) { - Logger.onInit(getClass()); - } +public class InitDestroyBinaryStreamEncoder extends StringBeanBinaryStreamEncoder { + @Override + public void init(EndpointConfig config) { + Logger.onInit(getClass()); + } - @Override - public void destroy() { - Logger.onDestroy(getClass()); - } + @Override + public void destroy() { + Logger.onDestroy(getClass()); + } - @Override - public void encode(StringBean bean, OutputStream stream) - throws EncodeException, IOException { - Logger.onCode(getClass()); - super.encode(bean, stream); - } + @Override + public void encode(StringBean bean, OutputStream stream) throws EncodeException, IOException { + Logger.onCode(getClass()); + super.encode(bean, stream); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextDecoder.java index a657483f1f..a2ca51c003 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextDecoder.java @@ -24,25 +24,25 @@ import jakarta.websocket.EndpointConfig; public class InitDestroyTextDecoder extends StringBeanTextDecoder { - @Override - public void init(EndpointConfig config) { - Logger.onInit(getClass()); - } + @Override + public void init(EndpointConfig config) { + Logger.onInit(getClass()); + } - @Override - public void destroy() { - Logger.onDestroy(getClass()); - } + @Override + public void destroy() { + Logger.onDestroy(getClass()); + } - @Override - public StringBean decode(String s) throws DecodeException { - Logger.onCode(getClass()); - return super.decode(s); - }; + @Override + public StringBean decode(String s) throws DecodeException { + Logger.onCode(getClass()); + return super.decode(s); + }; - @Override - public boolean willDecode(String s) { - Logger.onWillCode(getClass()); - return super.willDecode(s); - } + @Override + public boolean willDecode(String s) { + Logger.onWillCode(getClass()); + return super.willDecode(s); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextEncoder.java index ef2f0848b7..5d4fef4ee8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextEncoder.java @@ -24,19 +24,19 @@ import jakarta.websocket.EndpointConfig; public class InitDestroyTextEncoder extends StringBeanTextEncoder { - @Override - public void init(EndpointConfig config) { - Logger.onInit(getClass()); - } + @Override + public void init(EndpointConfig config) { + Logger.onInit(getClass()); + } - @Override - public void destroy() { - Logger.onDestroy(getClass()); - } + @Override + public void destroy() { + Logger.onDestroy(getClass()); + } - @Override - public String encode(StringBean bean) throws EncodeException { - Logger.onCode(getClass()); - return super.encode(bean); - } + @Override + public String encode(StringBean bean) throws EncodeException { + Logger.onCode(getClass()); + return super.encode(bean); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextStreamDecoder.java index 62eb82b0f6..957bdbf210 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextStreamDecoder.java @@ -27,19 +27,19 @@ import jakarta.websocket.EndpointConfig; public class InitDestroyTextStreamDecoder extends StringBeanTextStreamDecoder { - @Override - public void init(EndpointConfig config) { - Logger.onInit(getClass()); - } + @Override + public void init(EndpointConfig config) { + Logger.onInit(getClass()); + } - @Override - public void destroy() { - Logger.onDestroy(getClass()); - } + @Override + public void destroy() { + Logger.onDestroy(getClass()); + } - @Override - public StringBean decode(Reader r) throws DecodeException, IOException { - Logger.onCode(getClass()); - return super.decode(r); - }; + @Override + public StringBean decode(Reader r) throws DecodeException, IOException { + Logger.onCode(getClass()); + return super.decode(r); + }; } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextStreamEncoder.java index 9ae3f78a0a..33ce17ed85 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/InitDestroyTextStreamEncoder.java @@ -27,20 +27,19 @@ import jakarta.websocket.EndpointConfig; public class InitDestroyTextStreamEncoder extends StringBeanTextStreamEncoder { - @Override - public void init(EndpointConfig config) { - Logger.onInit(getClass()); - } + @Override + public void init(EndpointConfig config) { + Logger.onInit(getClass()); + } - @Override - public void destroy() { - Logger.onDestroy(getClass()); - } + @Override + public void destroy() { + Logger.onDestroy(getClass()); + } - @Override - public void encode(StringBean bean, Writer writer) - throws EncodeException, IOException { - Logger.onCode(getClass()); - super.encode(bean, writer); - } + @Override + public void encode(StringBean bean, Writer writer) throws EncodeException, IOException { + Logger.onCode(getClass()); + super.encode(bean, writer); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/Logger.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/Logger.java index 3da379e680..dd97aea879 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/Logger.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/Logger.java @@ -17,64 +17,64 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.coder; public class Logger { - private static final StringBuilder destroyLog = new StringBuilder(); + private static final StringBuilder destroyLog = new StringBuilder(); - private static final StringBuilder initLog = new StringBuilder(); + private static final StringBuilder initLog = new StringBuilder(); - private static final StringBuilder codeLog = new StringBuilder(); + private static final StringBuilder codeLog = new StringBuilder(); - private static final StringBuilder willCodeLog = new StringBuilder(); + private static final StringBuilder willCodeLog = new StringBuilder(); - public static void onDestroy(Class clazz) { - destroyLog.append(clazz.getName()).append(" "); - } + public static void onDestroy(Class clazz) { + destroyLog.append(clazz.getName()).append(" "); + } - public static void onInit(Class clazz) { - initLog.append(clazz.getName()).append(" "); - } + public static void onInit(Class clazz) { + initLog.append(clazz.getName()).append(" "); + } - public static void clearDestroyLog() { - int len = destroyLog.length(); - destroyLog.delete(0, len); - } + public static void clearDestroyLog() { + int len = destroyLog.length(); + destroyLog.delete(0, len); + } - public static void clearInitLog() { - int len = initLog.length(); - initLog.delete(0, len); - } + public static void clearInitLog() { + int len = initLog.length(); + initLog.delete(0, len); + } - public static String getInitLog() { - return initLog.toString(); - } + public static String getInitLog() { + return initLog.toString(); + } - public static String getDestroyLog() { - return initLog.toString(); - } + public static String getDestroyLog() { + return initLog.toString(); + } - public static void clearCodeLog() { - int len = codeLog.length(); - codeLog.delete(0, len); - } + public static void clearCodeLog() { + int len = codeLog.length(); + codeLog.delete(0, len); + } - public static void clearWillCodeLog() { - int len = willCodeLog.length(); - willCodeLog.delete(0, len); - } + public static void clearWillCodeLog() { + int len = willCodeLog.length(); + willCodeLog.delete(0, len); + } - public static void onCode(Class clazz) { - codeLog.append(clazz.getName()).append(" "); - } + public static void onCode(Class clazz) { + codeLog.append(clazz.getName()).append(" "); + } - public static void onWillCode(Class clazz) { - willCodeLog.append(clazz.getName()).append(" "); - } + public static void onWillCode(Class clazz) { + willCodeLog.append(clazz.getName()).append(" "); + } - public static String getCodeLog() { - return codeLog.toString(); - } + public static String getCodeLog() { + return codeLog.toString(); + } - public static String getWillCodeLog() { - return willCodeLog.toString(); - } + public static String getWillCodeLog() { + return willCodeLog.toString(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryDecoder.java index e318acd7a8..2acb8ca3ca 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryDecoder.java @@ -31,35 +31,34 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = InitDestroyBinaryDecoder.class) -public class WSCEndpointWithBinaryDecoder - extends AnnotatedClientEndpoint { +public class WSCEndpointWithBinaryDecoder extends AnnotatedClientEndpoint { - public WSCEndpointWithBinaryDecoder() { - super(new StringBeanClientEndpoint()); - } + public WSCEndpointWithBinaryDecoder() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryDecoders.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryDecoders.java index 86981c2ab7..d04b83c566 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryDecoders.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryDecoders.java @@ -30,37 +30,35 @@ import jakarta.websocket.OnOpen; import jakarta.websocket.Session; -@ClientEndpoint(decoders = { WillDecodeFirstBinaryDecoder.class, - WillDecodeSecondBinaryDecoder.class }) -public class WSCEndpointWithBinaryDecoders - extends AnnotatedClientEndpoint { +@ClientEndpoint(decoders = { WillDecodeFirstBinaryDecoder.class, WillDecodeSecondBinaryDecoder.class }) +public class WSCEndpointWithBinaryDecoders extends AnnotatedClientEndpoint { - public WSCEndpointWithBinaryDecoders() { - super(new StringBeanClientEndpoint()); - } + public WSCEndpointWithBinaryDecoders() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryEncoder.java index c0d76f10c7..9d2f27f5f2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryEncoder.java @@ -30,35 +30,34 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = InitDestroyBinaryEncoder.class) -public class WSCEndpointWithBinaryEncoder - extends AnnotatedClientEndpoint { - - public WSCEndpointWithBinaryEncoder() { - super(new StringClientEndpoint()); - } - - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } +public class WSCEndpointWithBinaryEncoder extends AnnotatedClientEndpoint { + + public WSCEndpointWithBinaryEncoder() { + super(new StringClientEndpoint()); + } + + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryStreamDecoder.java index 156fb90ce4..95ac48d513 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryStreamDecoder.java @@ -31,35 +31,34 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = InitDestroyBinaryStreamDecoder.class) -public class WSCEndpointWithBinaryStreamDecoder - extends AnnotatedClientEndpoint { +public class WSCEndpointWithBinaryStreamDecoder extends AnnotatedClientEndpoint { - public WSCEndpointWithBinaryStreamDecoder() { - super(new StringBeanClientEndpoint()); - } + public WSCEndpointWithBinaryStreamDecoder() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryStreamEncoder.java index f3398e7b30..4144a3480d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithBinaryStreamEncoder.java @@ -30,35 +30,34 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = InitDestroyBinaryStreamEncoder.class) -public class WSCEndpointWithBinaryStreamEncoder - extends AnnotatedClientEndpoint { - - public WSCEndpointWithBinaryStreamEncoder() { - super(new StringClientEndpoint()); - } - - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } +public class WSCEndpointWithBinaryStreamEncoder extends AnnotatedClientEndpoint { + + public WSCEndpointWithBinaryStreamEncoder() { + super(new StringClientEndpoint()); + } + + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextDecoder.java index a64cb78c34..1d51b52a5a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextDecoder.java @@ -31,35 +31,34 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = InitDestroyTextDecoder.class) -public class WSCEndpointWithTextDecoder - extends AnnotatedClientEndpoint { +public class WSCEndpointWithTextDecoder extends AnnotatedClientEndpoint { - public WSCEndpointWithTextDecoder() { - super(new StringBeanClientEndpoint()); - } + public WSCEndpointWithTextDecoder() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextDecoders.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextDecoders.java index 1b9bc35bf8..e69580c8be 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextDecoders.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextDecoders.java @@ -30,37 +30,35 @@ import jakarta.websocket.OnOpen; import jakarta.websocket.Session; -@ClientEndpoint(decoders = { WillDecodeFirstTextDecoder.class, - WillDecodeSecondTextDecoder.class }) -public class WSCEndpointWithTextDecoders - extends AnnotatedClientEndpoint { +@ClientEndpoint(decoders = { WillDecodeFirstTextDecoder.class, WillDecodeSecondTextDecoder.class }) +public class WSCEndpointWithTextDecoders extends AnnotatedClientEndpoint { - public WSCEndpointWithTextDecoders() { - super(new StringBeanClientEndpoint()); - } + public WSCEndpointWithTextDecoders() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextEncoder.java index ed741466a2..f947f79b5a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextEncoder.java @@ -30,35 +30,34 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = InitDestroyTextEncoder.class) -public class WSCEndpointWithTextEncoder - extends AnnotatedClientEndpoint { - - public WSCEndpointWithTextEncoder() { - super(new StringClientEndpoint()); - } - - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } +public class WSCEndpointWithTextEncoder extends AnnotatedClientEndpoint { + + public WSCEndpointWithTextEncoder() { + super(new StringClientEndpoint()); + } + + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextStreamDecoder.java index c92e25a99c..a5261af4e9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextStreamDecoder.java @@ -31,35 +31,34 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = InitDestroyTextStreamDecoder.class) -public class WSCEndpointWithTextStreamDecoder - extends AnnotatedClientEndpoint { +public class WSCEndpointWithTextStreamDecoder extends AnnotatedClientEndpoint { - public WSCEndpointWithTextStreamDecoder() { - super(new StringBeanClientEndpoint()); - } + public WSCEndpointWithTextStreamDecoder() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextStreamEncoder.java index d44ad1693c..bd70ba0a40 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCEndpointWithTextStreamEncoder.java @@ -30,35 +30,34 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = InitDestroyTextStreamEncoder.class) -public class WSCEndpointWithTextStreamEncoder - extends AnnotatedClientEndpoint { - - public WSCEndpointWithTextStreamEncoder() { - super(new StringClientEndpoint()); - } - - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } +public class WSCEndpointWithTextStreamEncoder extends AnnotatedClientEndpoint { + + public WSCEndpointWithTextStreamEncoder() { + super(new StringClientEndpoint()); + } + + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryDecoderServer.java index 042db9e977..08af207cee 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryDecoderServer.java @@ -27,21 +27,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarydecoder", decoders = { - InitDestroyBinaryDecoder.class }) +@ServerEndpoint(value = "/binarydecoder", decoders = { InitDestroyBinaryDecoder.class }) public class WSCIDBinaryDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryEncoderServer.java index 3df901a35a..88f2097285 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryEncoderServer.java @@ -27,21 +27,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binaryencoder", encoders = { - InitDestroyBinaryEncoder.class }) +@ServerEndpoint(value = "/binaryencoder", encoders = { InitDestroyBinaryEncoder.class }) public class WSCIDBinaryEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryStreamDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryStreamDecoderServer.java index c32ca6c33c..0a603fbed9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryStreamDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryStreamDecoderServer.java @@ -27,21 +27,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarystreamdecoder", decoders = { - InitDestroyBinaryStreamDecoder.class }) +@ServerEndpoint(value = "/binarystreamdecoder", decoders = { InitDestroyBinaryStreamDecoder.class }) public class WSCIDBinaryStreamDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryStreamEncoderServer.java index a161d0aad3..f2682e729b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDBinaryStreamEncoderServer.java @@ -27,21 +27,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarystreamencoder", encoders = { - InitDestroyBinaryStreamEncoder.class }) +@ServerEndpoint(value = "/binarystreamencoder", encoders = { InitDestroyBinaryStreamEncoder.class }) public class WSCIDBinaryStreamEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextDecoderServer.java index 1769b1ac0f..1b0b771d9a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextDecoderServer.java @@ -27,21 +27,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textdecoder", decoders = { - InitDestroyTextDecoder.class }) +@ServerEndpoint(value = "/textdecoder", decoders = { InitDestroyTextDecoder.class }) public class WSCIDTextDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextStreamDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextStreamDecoderServer.java index 2b94cd49c3..8af8da6906 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextStreamDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextStreamDecoderServer.java @@ -27,21 +27,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstreamdecoder", decoders = { - InitDestroyTextStreamDecoder.class }) +@ServerEndpoint(value = "/textstreamdecoder", decoders = { InitDestroyTextStreamDecoder.class }) public class WSCIDTextStreamDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextStreamEncoderServer.java index 7f5e87d8c7..4712d85b3d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCIDTextStreamEncoderServer.java @@ -27,21 +27,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstreamencoder", encoders = { - InitDestroyTextStreamEncoder.class }) +@ServerEndpoint(value = "/textstreamencoder", encoders = { InitDestroyTextStreamEncoder.class }) public class WSCIDTextStreamEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCLoggerServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCLoggerServer.java index 9068d8b925..fff9966fe7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCLoggerServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCLoggerServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -27,42 +27,43 @@ import jakarta.websocket.server.ServerEndpoint; @ServerEndpoint("/logger") + public class WSCLoggerServer { - @OnMessage - public String echo(String operation) { - return operation(operation); - } + @OnMessage + public String echo(String operation) { + return operation(operation); + } - public static String operation(String operation) { - String ret = operation; - if (operation.equals("clearinit")) - Logger.clearInitLog(); - else if (operation.equals("cleardestroy")) - Logger.clearDestroyLog(); - else if (operation.equals("getinit")) - ret = Logger.getInitLog(); - else if (operation.equals("getdestroy")) - ret = Logger.getDestroyLog(); - else if (operation.equals("getcode")) - ret = Logger.getCodeLog(); - else if (operation.equals("getwillcode")) - ret = Logger.getWillCodeLog(); - else if (operation.equals("clearall")) { - Logger.clearInitLog(); - Logger.clearDestroyLog(); - Logger.clearCodeLog(); - Logger.clearWillCodeLog(); - } - return ret; - } + public static String operation(String operation) { + String ret = operation; + if (operation.equals("clearinit")) + Logger.clearInitLog(); + else if (operation.equals("cleardestroy")) + Logger.clearDestroyLog(); + else if (operation.equals("getinit")) + ret = Logger.getInitLog(); + else if (operation.equals("getdestroy")) + ret = Logger.getDestroyLog(); + else if (operation.equals("getcode")) + ret = Logger.getCodeLog(); + else if (operation.equals("getwillcode")) + ret = Logger.getWillCodeLog(); + else if (operation.equals("clearall")) { + Logger.clearInitLog(); + Logger.clearDestroyLog(); + Logger.clearCodeLog(); + Logger.clearWillCodeLog(); + } + return ret; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCSimpleBinaryEchoServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCSimpleBinaryEchoServer.java index b1f76f2511..586dc81fc7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCSimpleBinaryEchoServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCSimpleBinaryEchoServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/simplebin") public class WSCSimpleBinaryEchoServer { - @OnMessage - public ByteBuffer echo(String echo) { - return ByteBuffer.wrap(echo.getBytes()); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public ByteBuffer echo(String echo) { + return ByteBuffer.wrap(echo.getBytes()); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCSimpleEchoServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCSimpleEchoServer.java index 0455b75541..b4e819b0d1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCSimpleEchoServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSCSimpleEchoServer.java @@ -32,36 +32,36 @@ @ServerEndpoint("/simpleecho") public class WSCSimpleEchoServer { - @OnOpen - public void onOpen(final Session session) { - session.addMessageHandler(new MessageHandler.Whole() { - @Override - public void onMessage(ByteBuffer message) { - String ret = echo(IOUtil.byteBufferToString(message)); - try { - session.getBasicRemote().sendText(ret); - } catch (IOException e) { - try { - onError(session, e); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } - }); - } + @OnOpen + public void onOpen(final Session session) { + session.addMessageHandler(new MessageHandler.Whole() { + @Override + public void onMessage(ByteBuffer message) { + String ret = echo(IOUtil.byteBufferToString(message)); + try { + session.getBasicRemote().sendText(ret); + } catch (IOException e) { + try { + onError(session, e); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } + }); + } - @OnMessage - public String echo(String echo) { - return echo; - } + @OnMessage + public String echo(String echo) { + return echo; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSClient.java deleted file mode 100644 index c7067ade66..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSClient.java +++ /dev/null @@ -1,925 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.coder; - -import java.nio.ByteBuffer; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.common.client.ByteBufferClientEndpoint; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.stringbean.StringBean; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = -6699156272937435550L; - - protected static final String ECHO = "Echo message"; - - public WSClient() { - setContextRoot("wsc_ee_coder_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - /* - * @testName: textEncoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:61; WebSocket:JAVADOC:190; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode ServerEndpoint.encoders - */ - public void textEncoderInitDestroyTest() throws Exception { - invokeClear(); - invokeEcho("textencoder"); - invokeGetInit(InitDestroyTextEncoder.class); - invokeGetDestroy(InitDestroyTextEncoder.class); - } - - /* - * @testName: textStreamEncoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:63; WebSocket:JAVADOC:190; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text stream encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode ServerEndpoint.encoders - */ - public void textStreamEncoderInitDestroyTest() throws Exception { - invokeClear(); - invokeEcho("textstreamencoder"); - invokeGetInit(InitDestroyTextStreamEncoder.class); - invokeGetDestroy(InitDestroyTextStreamEncoder.class); - } - - /* - * @testName: binaryEncoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:56; WebSocket:JAVADOC:190; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode ServerEndpoint.encoders - */ - public void binaryEncoderInitDestroyTest() throws Exception { - invokeClear(); - invokeBinaryEncoderEcho("binaryencoder"); - invokeGetInit(InitDestroyBinaryEncoder.class); - invokeGetDestroy(InitDestroyBinaryEncoder.class); - } - - /* - * @testName: binaryStreamEncoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:58; WebSocket:JAVADOC:190; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary stream encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode ServerEndpoint.encoders - */ - public void binaryStreamEncoderInitDestroyTest() throws Exception { - invokeClear(); - invokeBinaryEncoderEcho("binarystreamencoder"); - invokeGetInit(InitDestroyBinaryStreamEncoder.class); - invokeGetDestroy(InitDestroyBinaryStreamEncoder.class); - } - - // ---------------------------------------------------------------------- - - /* - * @testName: textDecoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; WebSocket:JAVADOC:189; - * WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode, willdecode ServerEndpoint.decoders - */ - public void textDecoderInitDestroyTest() throws Exception { - invokeClear(); - invokeEcho("textdecoder"); - invokeGetInit(InitDestroyTextDecoder.class); - invokeGetDestroy(InitDestroyTextDecoder.class); - } - - /* - * @testName: textStreamDecoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:46; WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text stream decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode ServerEndpoint.decoders - */ - public void textStreamDecoderInitDestroyTest() throws Exception { - invokeClear(); - invokeEcho("textstreamdecoder"); - invokeGetInit(InitDestroyTextStreamDecoder.class); - invokeGetDestroy(InitDestroyTextStreamDecoder.class); - } - - /* - * @testName: binaryDecoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; WebSocket:JAVADOC:189; - * WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode, willDecode ServerEndpoint.decoders - */ - public void binaryDecoderInitDestroyTest() throws Exception { - invokeClear(); - invokeBinaryDecoderEcho("binarydecoder"); - invokeGetInit(InitDestroyBinaryDecoder.class); - invokeGetDestroy(InitDestroyBinaryDecoder.class); - } - - /* - * @testName: binaryStreamDecoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:40; WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary stream decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode ServerEndpoint.decoders - */ - public void binaryStreamDecoderInitDestroyTest() throws Exception { - invokeClear(); - invokeBinaryDecoderEcho("binarystreamdecoder"); - invokeGetInit(InitDestroyBinaryStreamDecoder.class); - invokeGetDestroy(InitDestroyBinaryStreamDecoder.class); - } - - // ---------------------------------------------------------------------- - - /* - * @testName: textEncoderEncodeTest - * - * @assertion_ids: WebSocket:JAVADOC:61; WebSocket:JAVADOC:190; - * WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text encoder encode was called - * - * ServerEndpoint.encoders - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - public void textEncoderEncodeTest() throws Exception { - invokeClear(); - invokeEcho("textencoder"); - invokeGetCode(InitDestroyTextEncoder.class); - } - - /* - * @testName: textStreamEncoderEncodeTest - * - * @assertion_ids: WebSocket:JAVADOC:63; WebSocket:JAVADOC:190; - * WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text stream encode was called - * - * ServerEndpoint.encoders - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - public void textStreamEncoderEncodeTest() throws Exception { - invokeClear(); - invokeEcho("textstreamencoder"); - invokeGetCode(InitDestroyTextStreamEncoder.class); - } - - /* - * @testName: binaryEncoderEncodeTest - * - * @assertion_ids: WebSocket:JAVADOC:56; WebSocket:JAVADOC:190; - * WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary encoder encode was called - * - * ServerEndpoint.encoders - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - public void binaryEncoderEncodeTest() throws Exception { - invokeClear(); - invokeBinaryEncoderEcho("binaryencoder"); - invokeGetCode(InitDestroyBinaryEncoder.class); - } - - /* - * @testName: binaryStreamEncoderEncodeTest - * - * @assertion_ids: WebSocket:JAVADOC:58; WebSocket:JAVADOC:190; - * WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary stream encoder encode was called - * - * ServerEndpoint.encoders - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - public void binaryStreamEncoderEncodeTest() throws Exception { - invokeClear(); - invokeBinaryEncoderEcho("binarystreamencoder"); - invokeGetCode(InitDestroyBinaryStreamEncoder.class); - } - - // ----------------------------------------------------------------------- - - /* - * @testName: textDecoderDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; - * WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; - * WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test text decoder decode and willDecode were called - * - * ServerEndpoint.decoders - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - public void textDecoderDecodeTest() throws Exception { - invokeClear(); - invokeEcho("textdecoder"); - invokeGetCode(InitDestroyTextDecoder.class); - invokeGetWillCode(InitDestroyTextDecoder.class); - } - - /* - * @testName: textStreamDecoderDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:46; WebSocket:JAVADOC:189; - * WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text stream decoder decode was called - * ServerEndpoint.decoders - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - public void textStreamDecoderDecodeTest() throws Exception { - invokeClear(); - invokeEcho("textstreamdecoder"); - invokeGetCode(InitDestroyTextStreamDecoder.class); - } - - /* - * @testName: binaryDecoderDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; - * WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; - * WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test binary decoder decode and willDecode were called - * - * ServerEndpoint.decoders - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - public void binaryDecoderDecodeTest() throws Exception { - invokeClear(); - invokeBinaryDecoderEcho("binarydecoder"); - invokeGetCode(InitDestroyBinaryDecoder.class); - invokeGetWillCode(InitDestroyBinaryDecoder.class); - } - - /* - * @testName: binaryStreamDecoderDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:40; WebSocket:JAVADOC:189; - * WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary stream decoder decode was called - * - * ServerEndpoint.decoders - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - public void binaryStreamDecoderDecodeTest() throws Exception { - invokeClear(); - invokeBinaryDecoderEcho("binarystreamdecoder"); - invokeGetCode(InitDestroyBinaryStreamDecoder.class); - } - - /* - * @testName: binaryDecoderWillDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; - * WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; - * WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test binary decoder with willDecode returning false will - * not be used - * - * ServerEndpoint.decoders - */ - public void binaryDecoderWillDecodeTest() throws Exception { - invokeClear(); - invokeBinaryDecoderEcho("binarywilldecode"); - invokeGetWillCode(WillDecodeFirstBinaryDecoder.class, - WillDecodeSecondBinaryDecoder.class); - setProperty(Property.UNEXPECTED_RESPONSE_MATCH, - WillDecodeFirstBinaryDecoder.class.getName()); - invokeGetCode(WillDecodeSecondBinaryDecoder.class); - } - - /* - * @testName: textDecoderWillDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; - * WebSocket:JAVADOC:189; WebSocket:SPEC:WSC-4.1.3-1; - * WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test text decoder with willDecode returning false will not - * be used - * - * ServerEndpoint.decoders - */ - public void textDecoderWillDecodeTest() throws Exception { - invokeClear(); - invokeEcho("textwilldecode"); - invokeGetWillCode(WillDecodeFirstTextDecoder.class, - WillDecodeSecondTextDecoder.class); - setProperty(Property.UNEXPECTED_RESPONSE_MATCH, - WillDecodeFirstTextDecoder.class.getName()); - invokeGetCode(WillDecodeSecondTextDecoder.class); - } - - // ==================================================================== - /* - * @testName: textEncoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:61; WebSocket:JAVADOC:3; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode ClientEndpoint.encoders - */ - public void textEncoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithTextEncoder()); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertInit(InitDestroyTextEncoder.class); - assertDestroy(InitDestroyTextEncoder.class); - } - - /* - * @testName: textStreamEncoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:63; WebSocket:JAVADOC:3; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text stream encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode ClientEndpoint.encoders - */ - public void textStreamEncoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithTextStreamEncoder()); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertInit(InitDestroyTextStreamEncoder.class); - assertDestroy(InitDestroyTextStreamEncoder.class); - } - - /* - * @testName: binaryEncoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:56; WebSocket:JAVADOC:3; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode ClientEndpoint.encoders - */ - public void binaryEncoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithBinaryEncoder()); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertInit(InitDestroyBinaryEncoder.class); - assertDestroy(InitDestroyBinaryEncoder.class); - } - - /* - * @testName: binaryStreamEncoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:58; WebSocket:JAVADOC:3; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary stream encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode ClientEndpoint.encoders - */ - public void binaryStreamEncoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithBinaryStreamEncoder()); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertInit(InitDestroyBinaryStreamEncoder.class); - assertDestroy(InitDestroyBinaryStreamEncoder.class); - } - - // --------------------------------------------------------------------- - - /* - * @testName: textDecoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; WebSocket:JAVADOC:2; - * WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode, willdecode ClientEndpoint.decoders - */ - public void textDecoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithTextDecoder()); - invoke("simpleecho", ECHO, ECHO); - assertInit(InitDestroyTextDecoder.class); - assertDestroy(InitDestroyTextDecoder.class); - } - - /* - * @testName: textStreamDecoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:46; WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text stream decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode ClientEndpoint.decoders - */ - public void textStreamDecoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithTextStreamDecoder()); - invoke("simpleecho", ECHO, ECHO); - assertInit(InitDestroyTextStreamDecoder.class); - assertDestroy(InitDestroyTextStreamDecoder.class); - } - - /* - * @testName: binaryDecoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; WebSocket:JAVADOC:2; - * WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode, willDecode ClientEndpoint.decoders - */ - public void binaryDecoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithBinaryDecoder()); - invoke("simplebin", ECHO, ECHO); - assertInit(InitDestroyBinaryDecoder.class); - assertDestroy(InitDestroyBinaryDecoder.class); - } - - /* - * @testName: binaryStreamDecoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:40; WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary stream decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode ClientEndpoint.decoders - */ - public void binaryStreamDecoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithBinaryStreamDecoder()); - invoke("simplebin", ECHO, ECHO); - assertInit(InitDestroyBinaryStreamDecoder.class); - assertDestroy(InitDestroyBinaryStreamDecoder.class); - } - - // ---------------------------------------------------------------------- - - /* - * @testName: textEncoderEncodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:61; WebSocket:JAVADOC:3; - * WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text encoder encode was called ClientEndpoint.encoders - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - public void textEncoderEncodeOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithTextEncoder()); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertCode(InitDestroyTextEncoder.class); - } - - /* - * @testName: textStreamEncoderEncodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:63; WebSocket:JAVADOC:3; - * WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text stream encode was called ClientEndpoint.encoders - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - public void textStreamEncoderEncodeOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithTextStreamEncoder()); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertCode(InitDestroyTextStreamEncoder.class); - } - - /* - * @testName: binaryEncoderEncodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:56; WebSocket:JAVADOC:3; - * WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary encoder encode was called - * ClientEndpoint.encoders - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - public void binaryEncoderEncodeOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithBinaryEncoder()); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertCode(InitDestroyBinaryEncoder.class); - } - - /* - * @testName: binaryStreamEncoderEncodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:58; WebSocket:JAVADOC:3; - * WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary stream encoder encode was called - * ClientEndpoint.encoders - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - public void binaryStreamEncoderEncodeOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithBinaryStreamEncoder()); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertCode(InitDestroyBinaryStreamEncoder.class); - } - - // ---------------------------------------------------------------------- - - /* - * @testName: textDecoderDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; - * WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; - * WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test text decoder decode and willDecode were called - * ClientEndpoint.decoders - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - public void textDecoderDecodeOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithTextDecoder()); - invoke("simpleecho", ECHO, ECHO); - assertCode(InitDestroyTextDecoder.class); - assertWillCode(InitDestroyTextDecoder.class); - } - - /* - * @testName: textStreamDecoderDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:46; WebSocket:JAVADOC:2; - * WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text stream decoder decode was called - * ClientEndpoint.decoders - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - public void textStreamDecoderDecodeOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithTextStreamDecoder()); - invoke("simpleecho", ECHO, ECHO); - assertCode(InitDestroyTextStreamDecoder.class); - } - - /* - * @testName: binaryDecoderDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; - * WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; - * WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test binary decoder decode and willDecode were called - * ClientEndpoint.decoders - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - public void binaryDecoderDecodeOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithBinaryDecoder()); - invoke("simplebin", ECHO, ECHO); - assertCode(InitDestroyBinaryDecoder.class); - assertWillCode(InitDestroyBinaryDecoder.class); - } - - /* - * @testName: binaryStreamDecoderDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:40; WebSocket:JAVADOC:2; - * WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary stream decoder decode was called - * ClientEndpoint.decoders - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - public void binaryStreamDecoderDecodeOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithBinaryStreamDecoder()); - invoke("simplebin", ECHO, ECHO); - assertCode(InitDestroyBinaryStreamDecoder.class); - } - - /* - * @testName: binaryDecoderWillDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; - * WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; - * WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test binary decoder with willDecode returning false will - * not be used ClientEndpoint.decoders - */ - public void binaryDecoderWillDecodeOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithBinaryDecoders()); - invoke("simplebin", ECHO, ECHO); - assertWillCode(WillDecodeFirstBinaryDecoder.class); - assertWillCode(WillDecodeSecondBinaryDecoder.class); - assertNotCode(WillDecodeFirstBinaryDecoder.class); - assertCode(WillDecodeSecondBinaryDecoder.class); - } - - /* - * @testName: textDecoderWillDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; - * WebSocket:JAVADOC:2; WebSocket:SPEC:WSC-4.1.3-1; - * WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test text decoder with willDecode returning false will not - * be used ClientEndpoint.decoders - */ - public void textDecoderWillDecodeOnClientTest() throws Exception { - clientClear(); - setAnnotatedClientEndpoint(new WSCEndpointWithTextDecoders()); - invoke("simpleecho", ECHO, ECHO); - assertWillCode(WillDecodeFirstTextDecoder.class); - assertWillCode(WillDecodeSecondTextDecoder.class); - assertNotCode(WillDecodeFirstTextDecoder.class); - assertCode(WillDecodeSecondTextDecoder.class); - } - - // ////////////////////////////////////////////////////////////////// - private void invokeClear() throws Exception { - invokeLogger("clearall", "clearall"); - } - - private void invokeEcho(String endpoint) throws Exception { - invoke(endpoint, ECHO, ECHO); - } - - private void invokeBinaryEncoderEcho(String endpoint) throws Exception { - setClientEndpoint(ByteBufferClientEndpoint.class); - invokeEcho(endpoint); - } - - private void invokeBinaryDecoderEcho(String endpoint) throws Exception { - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - setProperty(Property.REQUEST, buildRequest(endpoint)); - setProperty(Property.SEARCH_STRING, ECHO); - invoke(); - } - - private void invokeGetInit(Class searchClazz) throws Exception { - invokeLogger("getinit", searchClazz.getName()); - } - - private void invokeGetDestroy(Class searchClazz) throws Exception { - // Sleep current tread to give server time to call destroy() should not - // be needed, just for sake - TestUtil.sleepMsec(500); - invokeLogger("getdestroy", searchClazz.getName()); - } - - private void invokeGetCode(Class... searchClasses) throws Exception { - for (Class searchClazz : searchClasses) - invokeLogger("getcode", searchClazz.getName()); - } - - private void invokeGetWillCode(Class... searchClasses) throws Exception { - for (Class searchClazz : searchClasses) - invokeLogger("getwillcode", searchClazz.getName()); - } - - private void invokeLogger(String method, String search) throws Exception { - invoke("logger", method, search); - } - - // //////////////////////////// Client ////////////////////////////////// - protected void clientClear() { - WSCLoggerServer.operation("clearall"); - } - - protected void assertInit(Class searchClazz) throws Exception { - String log = WSCLoggerServer.operation("getinit"); - assertContains(log, searchClazz.getName(), searchClazz.getName(), - "has not been found in a list of classes calling the init() method, only [", - log, "] has been found"); - logMsg("init() has been called on", searchClazz, "as expected"); - } - - protected void assertDestroy(Class searchClazz) throws Exception { - System.gc(); - // Sleep current tread to give server time to call destroy() should not - // be needed, just for sake - TestUtil.sleepMsec(500); - String log = WSCLoggerServer.operation("getdestroy"); - assertContains(log, searchClazz.getName(), searchClazz.getName(), - "has not been found in a list of classes calling the destroy() method, only [", - log, "] has been found"); - logMsg("destroy() has been called on", searchClazz, "as expected"); - } - - protected void assertCode(Class searchClass) throws Exception { - String log = WSCLoggerServer.operation("getcode"); - assertContains(log, searchClass.getName(), searchClass.getName(), - "has not been found in a list of classes calling the code() method, only [", - log, "] has been found"); - logMsg("code() has been called on", searchClass, "as expected"); - } - - protected void assertWillCode(Class searchClass) throws Exception { - String log = WSCLoggerServer.operation("getwillcode"); - assertContains(log, searchClass.getName(), searchClass.getName(), - "has not been found in a list of classes calling the willCode() method, only [", - log, "] has been found"); - logMsg("willCode() has been called on", searchClass, "as expected"); - } - - protected void assertNotCode(Class searchClass) throws Exception { - String log = WSCLoggerServer.operation("getcode"); - assertNotContains(log, searchClass.getName(), searchClass.getName(), - "has unexpectedly been found in a list of classes calling the code() method"); - logMsg("code() has not been called on", searchClass, "as expected"); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSClientIT.java new file mode 100644 index 0000000000..615fa3e86a --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSClientIT.java @@ -0,0 +1,41 @@ +package com.sun.ts.tests.websocket.ee.jakarta.websocket.coder; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; + +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamEncoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +public class WSClientIT extends CoderClient { + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_coder_web.war"); + archive.addClasses(StringBean.class, StringBeanBinaryDecoder.class, StringBeanBinaryEncoder.class, + StringBeanBinaryStreamEncoder.class, StringBeanBinaryStreamDecoder.class, StringBeanTextEncoder.class, + StringBeanTextDecoder.class, StringBeanTextStreamEncoder.class, StringBeanTextStreamDecoder.class); + archive.addClasses(IOUtil.class); + archive.addPackages(true, Filters.exclude(CoderClient.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.coder"); + return archive; + }; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_coder_web"); + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSIDTextEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSIDTextEncoderServer.java index e4241fc87c..b3f78d6ccd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSIDTextEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSIDTextEncoderServer.java @@ -27,21 +27,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textencoder", encoders = { - InitDestroyTextEncoder.class }) +@ServerEndpoint(value = "/textencoder", encoders = { InitDestroyTextEncoder.class }) public class WSIDTextEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSWillDecodeBinaryDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSWillDecodeBinaryDecoderServer.java index c7d3eace55..f0e7d5a6e6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSWillDecodeBinaryDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSWillDecodeBinaryDecoderServer.java @@ -27,21 +27,21 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarywilldecode", decoders = { - WillDecodeFirstBinaryDecoder.class, WillDecodeSecondBinaryDecoder.class }) +@ServerEndpoint(value = "/binarywilldecode", decoders = { WillDecodeFirstBinaryDecoder.class, + WillDecodeSecondBinaryDecoder.class }) public class WSWillDecodeBinaryDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSWillDecodeTextDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSWillDecodeTextDecoderServer.java index 687c5dfec8..45f85efcc3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSWillDecodeTextDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WSWillDecodeTextDecoderServer.java @@ -27,21 +27,21 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textwilldecode", decoders = { - WillDecodeFirstTextDecoder.class, WillDecodeSecondTextDecoder.class }) +@ServerEndpoint(value = "/textwilldecode", decoders = { WillDecodeFirstTextDecoder.class, + WillDecodeSecondTextDecoder.class }) public class WSWillDecodeTextDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeFirstBinaryDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeFirstBinaryDecoder.java index 02118d7146..1b981ffd16 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeFirstBinaryDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeFirstBinaryDecoder.java @@ -25,15 +25,15 @@ import jakarta.websocket.DecodeException; public class WillDecodeFirstBinaryDecoder extends StringBeanBinaryDecoder { - @Override - public StringBean decode(ByteBuffer arg0) throws DecodeException { - Logger.onCode(getClass()); - return super.decode(arg0); - }; + @Override + public StringBean decode(ByteBuffer arg0) throws DecodeException { + Logger.onCode(getClass()); + return super.decode(arg0); + }; - @Override - public boolean willDecode(ByteBuffer arg0) { - Logger.onWillCode(getClass()); - return false; - } + @Override + public boolean willDecode(ByteBuffer arg0) { + Logger.onWillCode(getClass()); + return false; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeFirstTextDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeFirstTextDecoder.java index cf4a6c2c72..6b3420a04d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeFirstTextDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeFirstTextDecoder.java @@ -24,15 +24,15 @@ public class WillDecodeFirstTextDecoder extends StringBeanTextDecoder { - @Override - public StringBean decode(String s) throws DecodeException { - Logger.onCode(getClass()); - return super.decode(s); - }; + @Override + public StringBean decode(String s) throws DecodeException { + Logger.onCode(getClass()); + return super.decode(s); + }; - @Override - public boolean willDecode(String s) { - Logger.onWillCode(getClass()); - return false; - } + @Override + public boolean willDecode(String s) { + Logger.onWillCode(getClass()); + return false; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeSecondBinaryDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeSecondBinaryDecoder.java index 36c1f86100..a7100e4d72 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeSecondBinaryDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeSecondBinaryDecoder.java @@ -25,15 +25,15 @@ import jakarta.websocket.DecodeException; public class WillDecodeSecondBinaryDecoder extends StringBeanBinaryDecoder { - @Override - public StringBean decode(ByteBuffer arg0) throws DecodeException { - Logger.onCode(getClass()); - return super.decode(arg0); - }; + @Override + public StringBean decode(ByteBuffer arg0) throws DecodeException { + Logger.onCode(getClass()); + return super.decode(arg0); + }; - @Override - public boolean willDecode(ByteBuffer arg0) { - Logger.onWillCode(getClass()); - return true; - } + @Override + public boolean willDecode(ByteBuffer arg0) { + Logger.onWillCode(getClass()); + return true; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeSecondTextDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeSecondTextDecoder.java index 2b790601e4..5f0f309f43 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeSecondTextDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/coder/WillDecodeSecondTextDecoder.java @@ -24,15 +24,15 @@ public class WillDecodeSecondTextDecoder extends StringBeanTextDecoder { - @Override - public StringBean decode(String s) throws DecodeException { - Logger.onCode(getClass()); - return super.decode(s); - }; + @Override + public StringBean decode(String s) throws DecodeException { + Logger.onCode(getClass()); + return super.decode(s); + }; - @Override - public boolean willDecode(String s) { - Logger.onWillCode(getClass()); - return true; - } + @Override + public boolean willDecode(String s) { + Logger.onWillCode(getClass()); + return true; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/LibrariedQuestionaire.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/LibrariedQuestionaire.java index 2c209c75ab..c6f10995ef 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/LibrariedQuestionaire.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/LibrariedQuestionaire.java @@ -24,36 +24,34 @@ import jakarta.websocket.WebSocketContainer; public class LibrariedQuestionaire { - public String getContainerProviderName() { - WebSocketContainer origContainer = ContainerProvider - .getWebSocketContainer(); - TCKContainerProvider.setOriginalContainer(origContainer); - - String name = null; - - name = AccessController.doPrivileged(new PrivilegedAction() { - @Override - public String run() { - String name = null; - ClassLoader origCl = Thread.currentThread().getContextClassLoader(); - try { - TCKClassLoader myCl = new TCKClassLoader(origCl); - Thread.currentThread().setContextClassLoader(myCl); - - WebSocketContainer container = ContainerProvider - .getWebSocketContainer(); - - if (TCKWebSocketContainer.class.isInstance(container)) - name = TCKWebSocketContainer.class.getName(); - else - name = container.getClass().getName(); - } finally { - Thread.currentThread().setContextClassLoader(origCl); - } - return name; - } - }); - return name; - } + public String getContainerProviderName() { + WebSocketContainer origContainer = ContainerProvider.getWebSocketContainer(); + TCKContainerProvider.setOriginalContainer(origContainer); + + String name = null; + + name = AccessController.doPrivileged(new PrivilegedAction() { + @Override + public String run() { + String name = null; + ClassLoader origCl = Thread.currentThread().getContextClassLoader(); + try { + TCKClassLoader myCl = new TCKClassLoader(origCl); + Thread.currentThread().setContextClassLoader(myCl); + + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + + if (TCKWebSocketContainer.class.isInstance(container)) + name = TCKWebSocketContainer.class.getName(); + else + name = container.getClass().getName(); + } finally { + Thread.currentThread().setContextClassLoader(origCl); + } + return name; + } + }); + return name; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/TCKClassLoader.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/TCKClassLoader.java index d64dcfbef8..e33cec59d6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/TCKClassLoader.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/TCKClassLoader.java @@ -27,57 +27,56 @@ public class TCKClassLoader extends ClassLoader { - private ClassLoader orig; + private ClassLoader orig; - public TCKClassLoader(ClassLoader orig) { - this.orig = orig; - } + public TCKClassLoader(ClassLoader orig) { + this.orig = orig; + } - @Override - public Enumeration getResources(String name) throws IOException { - Enumeration en = orig.getResources(name); - return filter(en); - } + @Override + public Enumeration getResources(String name) throws IOException { + Enumeration en = orig.getResources(name); + return filter(en); + } - @Override - public Class loadClass(String name) throws ClassNotFoundException { - return orig.loadClass(name); - } + @Override + public Class loadClass(String name) throws ClassNotFoundException { + return orig.loadClass(name); + } - @Override - public boolean equals(Object obj) { - return orig.equals(obj); - } + @Override + public boolean equals(Object obj) { + return orig.equals(obj); + } - @Override - public void clearAssertionStatus() { - orig.clearAssertionStatus(); - } + @Override + public void clearAssertionStatus() { + orig.clearAssertionStatus(); + } - @Override - public URL getResource(String name) { - return orig.getResource(name); - } + @Override + public URL getResource(String name) { + return orig.getResource(name); + } - @Override - public InputStream getResourceAsStream(String name) { - return orig.getResourceAsStream(name); - } + @Override + public InputStream getResourceAsStream(String name) { + return orig.getResourceAsStream(name); + } - @Override - public int hashCode() { - return orig.hashCode(); - } + @Override + public int hashCode() { + return orig.hashCode(); + } - private static Enumeration filter(Enumeration orig) { - List list = new LinkedList<>(); - while (orig.hasMoreElements()) { - URL url = orig.nextElement(); - String file = url.getFile(); - if (file.contains("lib.jar") && file - .contains("META-INF/services/jakarta.websocket.ContainerProvider")) - list.add(url); - } - return Collections.enumeration(list); - } + private static Enumeration filter(Enumeration orig) { + List list = new LinkedList<>(); + while (orig.hasMoreElements()) { + URL url = orig.nextElement(); + String file = url.getFile(); + if (file.contains("lib.jar") && file.contains("META-INF/services/jakarta.websocket.ContainerProvider")) + list.add(url); + } + return Collections.enumeration(list); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/TCKContainerProvider.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/TCKContainerProvider.java index d7e2ce9f25..53336b2154 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/TCKContainerProvider.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/TCKContainerProvider.java @@ -24,55 +24,52 @@ import jakarta.websocket.ContainerProvider; import jakarta.websocket.WebSocketContainer; -public class TCKContainerProvider extends ContainerProvider - implements InvocationHandler { +public class TCKContainerProvider extends ContainerProvider implements InvocationHandler { - private static WebSocketContainer provider; + private static WebSocketContainer provider; - public static void setOriginalContainer(WebSocketContainer provider) { - TCKContainerProvider.provider = provider; - } + public static void setOriginalContainer(WebSocketContainer provider) { + TCKContainerProvider.provider = provider; + } - @Override - protected WebSocketContainer getContainer() { - Object o = Proxy.newProxyInstance(getClass().getClassLoader(), - new Class[] { TCKWebSocketContainer.class }, this); - return (WebSocketContainer) o; - } + @Override + protected WebSocketContainer getContainer() { + Object o = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { TCKWebSocketContainer.class }, + this); + return (WebSocketContainer) o; + } - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - Method m = find(ContainerProvider.class.getMethods(), method); - if (m != null) { - Object ret = m.invoke(provider, args); - return ret; - } - return null; - } + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + Method m = find(ContainerProvider.class.getMethods(), method); + if (m != null) { + Object ret = m.invoke(provider, args); + return ret; + } + return null; + } - private static final Method find(Method[] array, Method object) { - for (Method i : array) - if (equals(object, i)) - return i; - return null; - } + private static final Method find(Method[] array, Method object) { + for (Method i : array) + if (equals(object, i)) + return i; + return null; + } - private static final boolean equals(Method obj, Method other) { - if (!obj.getName().equals(other.getName())) - return false; - if (!obj.getReturnType().equals(other.getReturnType())) - return false; - return parameterEquals(obj.getParameterTypes(), other.getParameterTypes()); - } + private static final boolean equals(Method obj, Method other) { + if (!obj.getName().equals(other.getName())) + return false; + if (!obj.getReturnType().equals(other.getReturnType())) + return false; + return parameterEquals(obj.getParameterTypes(), other.getParameterTypes()); + } - private static final boolean parameterEquals(Class[] params1, - Class[] params2) { - if (params1.length != params2.length) - return false; - for (int i = 0; i < params1.length; i++) - if (params1[i] != params2[i]) - return false; - return true; - } + private static final boolean parameterEquals(Class[] params1, Class[] params2) { + if (params1.length != params2.length) + return false; + for (int i = 0; i < params1.length; i++) + if (params1[i] != params2[i]) + return false; + return true; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/WSCServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/WSCServer.java index 10a58d72dd..46baa0598f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/WSCServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/WSCServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -28,17 +28,18 @@ @ServerEndpoint("/srv") public class WSCServer { - @SuppressWarnings("unused") - @OnMessage - public String onMessage(String data) { - LibrariedQuestionaire lq = new LibrariedQuestionaire(); - return lq.getContainerProviderName(); - } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String onMessage(String data) { + LibrariedQuestionaire lq = new LibrariedQuestionaire(); + return lq.getContainerProviderName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/WSClient.java deleted file mode 100644 index 32fdf491fb..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/WSClient.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.containerprovider.metainf; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = 8387217970724424176L; - - public WSClient() { - setContextRoot("wsc_ee_containerprovider_metainf_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - /* - * @testName: getWebSocketContainerOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:27; - * - * @test_Strategy: Check the TCKContainerProvider is used, as order by - * META-INF/services/jakarta.websocket.ContainerProvider file - * - * ContainerProvider.ContainerProvider() - */ - public void getWebSocketContainerOnServerTest() throws Exception { - invoke("srv", "anything", TCKWebSocketContainer.class.getName()); - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/WSClientIT.java new file mode 100644 index 0000000000..c545df9c02 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/metainf/WSClientIT.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.containerprovider.metainf; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = 8387217970724424176L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_containerprovider_metainf_web.war"); + archive.addClasses(WSCServer.class); + archive.addPackages(true, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.containerprovider.metainf"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_containerprovider_metainf_web"); + } + + /* Run test */ + /* + * @testName: getWebSocketContainerOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:27; + * + * @test_Strategy: Check the TCKContainerProvider is used, as order by + * META-INF/services/jakarta.websocket.ContainerProvider file + * + * ContainerProvider.ContainerProvider() + */ + public void getWebSocketContainerOnServerTest() throws Exception { + invoke("srv", "anything", TCKWebSocketContainer.class.getName()); + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/vi/WSCServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/vi/WSCServer.java index ff4f39112b..f7b2c57af9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/vi/WSCServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/vi/WSCServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,17 +30,18 @@ @ServerEndpoint("/srv") public class WSCServer { - @SuppressWarnings("unused") - @OnMessage - public boolean onMessage(String data) { - WebSocketContainer container = ContainerProvider.getWebSocketContainer(); - return container != null; - } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public boolean onMessage(String data) { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + return container != null; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/vi/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/vi/WSClient.java deleted file mode 100644 index 5fb9c1ede7..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/vi/WSClient.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.containerprovider.vi; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -import jakarta.websocket.ContainerProvider; -import jakarta.websocket.WebSocketContainer; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = 4245245442874605867L; - - public WSClient() { - setContextRoot("wsc_ee_containerprovider_vi_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - /* - * @testName: getWebSocketContainerOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:28; - * - * @test_Strategy: ContainerProvider.getWebSocketContainer - */ - public void getWebSocketContainerOnClientTest() throws Exception { - WebSocketContainer container = ContainerProvider.getWebSocketContainer(); - assertNotNull(container, "ContainerProvider#getWebSocketContainer is null"); - logMsg( - "ContainerProvider#getWebSocketContainer obtained WebSocketContainer as expected"); - } - - /* - * @testName: getWebSocketContainerOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:28; - * - * @test_Strategy: ContainerProvider.getWebSocketContainer - */ - public void getWebSocketContainerOnServerTest() throws Exception { - invoke("srv", "anything", "true"); - logMsg( - "ContainerProvider#getWebSocketContainer obtained WebSocketContainer as expected"); - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/vi/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/vi/WSClientIT.java new file mode 100644 index 0000000000..8c7ece14ee --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/containerprovider/vi/WSClientIT.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.containerprovider.vi; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.WebSocketContainer; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_containerprovider_vi_web.war"); + archive.addClasses(WSCServer.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + private static final long serialVersionUID = 4245245442874605867L; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_containerprovider_vi_web"); + } + + /* Run test */ + /* + * @testName: getWebSocketContainerOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:28; + * + * @test_Strategy: ContainerProvider.getWebSocketContainer + */ + @Test + public void getWebSocketContainerOnClientTest() throws Exception { + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + assertNotNull(container, "ContainerProvider#getWebSocketContainer is null"); + logMsg("ContainerProvider#getWebSocketContainer obtained WebSocketContainer as expected"); + } + + /* + * @testName: getWebSocketContainerOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:28; + * + * @test_Strategy: ContainerProvider.getWebSocketContainer + */ + @Test + public void getWebSocketContainerOnServerTest() throws Exception { + invoke("srv", "anything", "true"); + logMsg("ContainerProvider#getWebSocketContainer obtained WebSocketContainer as expected"); + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/OPS.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/OPS.java index cbc0892fbb..8b7e026ebf 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/OPS.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/OPS.java @@ -17,5 +17,5 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.endpoint.client; public enum OPS { - ECHO_MSG, THROW; + ECHO_MSG, THROW; } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCCloseClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCCloseClientEndpoint.java index 8531717df0..a6cd147530 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCCloseClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCCloseClientEndpoint.java @@ -27,38 +27,38 @@ import jakarta.websocket.Session; public class WSCCloseClientEndpoint extends StringClientEndpoint { - boolean onCloseCalled = false; + boolean onCloseCalled = false; - private CountDownLatch countDown = new CountDownLatch(1); + private CountDownLatch countDown = new CountDownLatch(1); - @Override - public void onMessage(String msg) { - super.onMessage(msg); - } + @Override + public void onMessage(String msg) { + super.onMessage(msg); + } - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - onCloseCalled = true; - countDown.countDown(); - } + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + onCloseCalled = true; + countDown.countDown(); + } - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - public void waitForClose(long seconds) { - try { - countDown.await(seconds, TimeUnit.SECONDS); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } + public void waitForClose(long seconds) { + try { + countDown.await(seconds, TimeUnit.SECONDS); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCEchoServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCEchoServer.java index 17d8880059..b6ad15da42 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCEchoServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCEchoServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -28,18 +28,17 @@ @ServerEndpoint("/echo") public class WSCEchoServer { - - @OnMessage - public String echo(String echo) { - return echo; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo) { + return echo; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCErrorClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCErrorClientEndpoint.java index bcd321aa83..f9ccaeade3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCErrorClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSCErrorClientEndpoint.java @@ -26,41 +26,41 @@ import jakarta.websocket.Session; public class WSCErrorClientEndpoint extends StringClientEndpoint { - private static final String EXCEPTION = "TCK test throwable"; + private static final String EXCEPTION = "TCK test throwable"; - boolean onErrorCalled = false; + boolean onErrorCalled = false; - @Override - public void onMessage(String msg) { - super.onMessage(msg); - OPS op = OPS.valueOf(msg); - switch (op) { - case THROW: - throw new RuntimeException(EXCEPTION); - default: - break; - } - } + @Override + public void onMessage(String msg) { + super.onMessage(msg); + OPS op = OPS.valueOf(msg); + switch (op) { + case THROW: + throw new RuntimeException(EXCEPTION); + default: + break; + } + } - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - public void onError(Session session, Throwable t) { - String msg = WebSocketCommonClient.getCauseMessage(t); - if (EXCEPTION.equals(msg)) { - onErrorCalled = true; - getCountDownLatch().countDown(); - } else - super.onError(session, t); - } + @Override + public void onError(Session session, Throwable t) { + String msg = WebSocketCommonClient.getCauseMessage(t); + if (EXCEPTION.equals(msg)) { + onErrorCalled = true; + getCountDownLatch().countDown(); + } else + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSClient.java deleted file mode 100644 index 0479e35510..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSClient.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.endpoint.client; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = 5511697770152558944L; - - public WSClient() { - setContextRoot("wsc_ee_endpoint_client_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - /* - * @testName: onErrorWorksTest - * - * @assertion_ids: WebSocket:JAVADOC:68;WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:66; - * - * @test_Strategy: check @OnError works on Endpoint on Client Side - * jakarta.websocket.Endpoint.onOpen Endpoint.Endpoint - */ - public void onErrorWorksTest() throws Exception { - WSCErrorClientEndpoint endpoint = new WSCErrorClientEndpoint(); - setClientEndpointInstance(endpoint); - invoke("echo", OPS.ECHO_MSG, OPS.ECHO_MSG); - assertFalse(endpoint.onErrorCalled, - "@OnError has been unexpectedly called"); - - setCountDownLatchCount(2); - setClientEndpointInstance(endpoint); - invoke("echo", OPS.THROW, OPS.THROW); - assertTrue(endpoint.onErrorCalled, - "@OnError has NOT been called after RuntimeException is thrown on @OnMessage"); - logMsg( - "@OnError has been called after RuntimeException is thrown on @OnMessage as expected"); - } - - /* - * @testName: onCloseWorksTest - * - * @assertion_ids: WebSocket:JAVADOC:67;WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:66; - * - * @test_Strategy: check @OnClose works on Endpoint on Client side - * jakarta.websocket.Endpoint.onOpen Endpoint.Endpoint - */ - public void onCloseWorksTest() throws Exception { - WSCCloseClientEndpoint endpoint = new WSCCloseClientEndpoint(); - setClientEndpointInstance(endpoint); - invoke("echo", OPS.ECHO_MSG.name(), OPS.ECHO_MSG.name(), false); - assertFalse(endpoint.onCloseCalled, - "@OnClose has been unexpectedly called"); - cleanup(); - endpoint.waitForClose(_ws_wait); - assertTrue(endpoint.onCloseCalled, - "@OnClose has NOT been called after session.close()"); - logMsg("@OnClose has been called after session.close() as expected"); - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSClientIT.java new file mode 100644 index 0000000000..87f61718b9 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/client/WSClientIT.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.endpoint.client; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = 5511697770152558944L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_endpoint_client_web.war"); + archive.addClasses(OPS.class, WSCEchoServer.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_endpoint_client_web"); + } + + /* Run test */ + + /* + * @testName: onErrorWorksTest + * + * @assertion_ids: WebSocket:JAVADOC:68;WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:66; + * + * @test_Strategy: check @OnError works on Endpoint on Client Side + * jakarta.websocket.Endpoint.onOpen Endpoint.Endpoint + */ + @Test + public void onErrorWorksTest() throws Exception { + WSCErrorClientEndpoint endpoint = new WSCErrorClientEndpoint(); + setClientEndpointInstance(endpoint); + invoke("echo", OPS.ECHO_MSG, OPS.ECHO_MSG); + assertFalse(endpoint.onErrorCalled, "@OnError has been unexpectedly called"); + + setCountDownLatchCount(2); + setClientEndpointInstance(endpoint); + invoke("echo", OPS.THROW, OPS.THROW); + assertTrue(endpoint.onErrorCalled, + "@OnError has NOT been called after RuntimeException is thrown on @OnMessage"); + logMsg("@OnError has been called after RuntimeException is thrown on @OnMessage as expected"); + } + + /* + * @testName: onCloseWorksTest + * + * @assertion_ids: WebSocket:JAVADOC:67;WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:66; + * + * @test_Strategy: check @OnClose works on Endpoint on Client side + * jakarta.websocket.Endpoint.onOpen Endpoint.Endpoint + */ + @Test + public void onCloseWorksTest() throws Exception { + WSCCloseClientEndpoint endpoint = new WSCCloseClientEndpoint(); + setClientEndpointInstance(endpoint); + invoke("echo", OPS.ECHO_MSG.name(), OPS.ECHO_MSG.name(), false); + assertFalse(endpoint.onCloseCalled, "@OnClose has been unexpectedly called"); + cleanup(); + endpoint.waitForClose(_ws_wait); + assertTrue(endpoint.onCloseCalled, "@OnClose has NOT been called after session.close()"); + logMsg("@OnClose has been called after session.close() as expected"); + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/AppConfig.java index 52857ff332..bfe743b724 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/AppConfig.java @@ -26,25 +26,24 @@ public class AppConfig implements ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - ServerEndpointConfig closeConfig = ServerEndpointConfig.Builder - .create(WSCCloseServerEndpoint.class, "/close").build(); - - ServerEndpointConfig errorConfig = ServerEndpointConfig.Builder - .create(WSCErrorServerEndpoint.class, "/error").build(); - - Set set = new HashSet<>(); - set.add(closeConfig); - set.add(errorConfig); - return set; - } - - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(WSCMsgServer.class); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + ServerEndpointConfig closeConfig = ServerEndpointConfig.Builder.create(WSCCloseServerEndpoint.class, "/close") + .build(); + + ServerEndpointConfig errorConfig = ServerEndpointConfig.Builder.create(WSCErrorServerEndpoint.class, "/error") + .build(); + + Set set = new HashSet<>(); + set.add(closeConfig); + set.add(errorConfig); + return set; + } + + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(WSCMsgServer.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCCloseServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCCloseServerEndpoint.java index fb976fe280..d76df15b86 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCCloseServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCCloseServerEndpoint.java @@ -26,42 +26,41 @@ import jakarta.websocket.EndpointConfig; import jakarta.websocket.Session; -public class WSCCloseServerEndpoint extends Endpoint - implements jakarta.websocket.MessageHandler.Whole { - private Session session; +public class WSCCloseServerEndpoint extends Endpoint implements jakarta.websocket.MessageHandler.Whole { + private Session session; - static final String CLOSE = "@OnClose"; + static final String CLOSE = "@OnClose"; - @Override - public void onMessage(String msg) { - try { - session.getBasicRemote().sendText(msg); - } catch (IOException e) { - onError(session, e); - } - } + @Override + public void onMessage(String msg) { + try { + session.getBasicRemote().sendText(msg); + } catch (IOException e) { + onError(session, e); + } + } - @Override - public void onOpen(Session session, EndpointConfig config) { - session.addMessageHandler(this); - this.session = session; - } + @Override + public void onOpen(Session session, EndpointConfig config) { + session.addMessageHandler(this); + this.session = session; + } - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - WSCMsgServer.setLastMessage(CLOSE); - } + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + WSCMsgServer.setLastMessage(CLOSE); + } - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCErrorServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCErrorServerEndpoint.java index 250785ec58..dd577277cf 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCErrorServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCErrorServerEndpoint.java @@ -28,53 +28,52 @@ import jakarta.websocket.OnClose; import jakarta.websocket.Session; -public class WSCErrorServerEndpoint extends Endpoint - implements MessageHandler.Whole { - static final String EXCEPTION = "TCK test throwable"; +public class WSCErrorServerEndpoint extends Endpoint implements MessageHandler.Whole { + static final String EXCEPTION = "TCK test throwable"; - private Session session; + private Session session; - @Override - public void onMessage(String msg) { - session.getAsyncRemote().sendText(msg); - throw new RuntimeException(EXCEPTION); - } + @Override + public void onMessage(String msg) { + session.getAsyncRemote().sendText(msg); + throw new RuntimeException(EXCEPTION); + } - @Override - public void onOpen(Session session, EndpointConfig config) { - session.addMessageHandler(this); - this.session = session; - } + @Override + public void onOpen(Session session, EndpointConfig config) { + session.addMessageHandler(this); + this.session = session; + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - public void onError(Session session, Throwable t) { - String msg = getCauseMessage(t); - if (EXCEPTION.equals(msg)) { - WSCMsgServer.setLastMessage(EXCEPTION); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } - } + @Override + public void onError(Session session, Throwable t) { + String msg = getCauseMessage(t); + if (EXCEPTION.equals(msg)) { + WSCMsgServer.setLastMessage(EXCEPTION); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } + } - private static String getCauseMessage(Throwable t) { - String msg = null; - while (t != null) { - msg = t.getMessage(); - t = t.getCause(); - } - return msg; - } + private static String getCauseMessage(Throwable t) { + String msg = null; + while (t != null) { + msg = t.getMessage(); + t = t.getCause(); + } + return msg; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCMsgServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCMsgServer.java index b07e1a7f8e..11b7ce67b6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCMsgServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSCMsgServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -28,34 +28,35 @@ @ServerEndpoint(value = "/msg") public class WSCMsgServer { - static final String EMPTY = "empty"; - - static final String MESSAGES[] = { "reset", "lastmsg" }; - - static String message = EMPTY; - - @OnMessage - public String onMessage(String msg) { - if (MESSAGES[0].equals(msg)) { - setLastMessage(EMPTY); - } - msg = getLastMessage(); - return msg; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } - - private static String getLastMessage() { - return message; - } - - public static void setLastMessage(String lastMessage) { - WSCMsgServer.message = lastMessage; - } + + static final String EMPTY = "empty"; + + static final String MESSAGES[] = { "reset", "lastmsg" }; + + static String message = EMPTY; + + @OnMessage + public String onMessage(String msg) { + if (MESSAGES[0].equals(msg)) { + setLastMessage(EMPTY); + } + msg = getLastMessage(); + return msg; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } + + private static String getLastMessage() { + return message; + } + + public static void setLastMessage(String lastMessage) { + WSCMsgServer.message = lastMessage; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSClient.java deleted file mode 100644 index 78da7f65a0..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSClient.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.endpoint.server; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = -712294674123256741L; - - public WSClient() { - setContextRoot("wsc_ee_endpoint_server_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - /* - * @testName: onErrorWorksTest - * - * @assertion_ids: WebSocket:JAVADOC:68;WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:66; - * - * @test_Strategy: check @OnError works on Endpoint on Server Side - * jakarta.websocket.Endpoint.onOpen Endpoint.Endpoint - */ - public void onErrorWorksTest() throws Exception { - invoke("msg", WSCMsgServer.MESSAGES[0], WSCMsgServer.EMPTY); - invoke("error", "anything", "anything"); - invokeUntilFound("msg", WSCMsgServer.MESSAGES[1], - WSCErrorServerEndpoint.EXCEPTION); - logMsg( - "@OnError has been called after RuntimeException is thrown on @OnMessage as expected"); - } - - /* - * @testName: onCloseWorksTest - * - * @assertion_ids: WebSocket:JAVADOC:67;WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:66; - * - * @test_Strategy: check @OnClose works on Endpoint on Server side - * jakarta.websocket.Endpoint.onOpen Endpoint.Endpoint - */ - public void onCloseWorksTest() throws Exception { - invoke("msg", WSCMsgServer.MESSAGES[0], WSCMsgServer.EMPTY); - invoke("close", "anything", "anything"); - invokeUntilFound("msg", WSCMsgServer.MESSAGES[1], - WSCCloseServerEndpoint.CLOSE); - logMsg("@OnClose has been called after session.close() as expected"); - } - - // ////////////////////////////////////////////////////////////////////// - private void invokeUntilFound(String endpoint, String content, String search) - throws Exception { - int sleep = 100; - long maxWait = _ws_wait * (1000 / sleep); - long count = 0; - boolean found = false; - String response = null; - while (!found && count < maxWait) { - invoke(endpoint, content, "", false); - response = getLastResponse(String.class); - if (response.equals(search)) - found = true; - cleanup(); - if (!found) - TestUtil.sleepMsec(sleep); - count++; - } - if (!found) { - fault(search, "has not been found in response, last response was", - response); - } - } - - @Override - protected com.sun.javatest.Status run(String[] args) { - if (args.length == 0) { - args = new String[] { "-p", "install/websocket/bin/ts.jte", "-t", - "onCloseWorksTest", "-vehicle", "servlet" }; - } - return super.run(args); - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSClientIT.java new file mode 100644 index 0000000000..8b1e11c682 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/endpoint/server/WSClientIT.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.endpoint.server; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = -712294674123256741L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_endpoint_server_web.war"); + archive.addPackages(true, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.endpoint.server"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_endpoint_server_web"); + } + + /* Run test */ + + /* + * @testName: onErrorWorksTest + * + * @assertion_ids: WebSocket:JAVADOC:68;WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:66; + * + * @test_Strategy: check @OnError works on Endpoint on Server Side + * jakarta.websocket.Endpoint.onOpen Endpoint.Endpoint + */ + @Test + public void onErrorWorksTest() throws Exception { + invoke("msg", WSCMsgServer.MESSAGES[0], WSCMsgServer.EMPTY); + invoke("error", "anything", "anything"); + invokeUntilFound("msg", WSCMsgServer.MESSAGES[1], WSCErrorServerEndpoint.EXCEPTION); + logMsg("@OnError has been called after RuntimeException is thrown on @OnMessage as expected"); + } + + /* + * @testName: onCloseWorksTest + * + * @assertion_ids: WebSocket:JAVADOC:67;WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:66; + * + * @test_Strategy: check @OnClose works on Endpoint on Server side + * jakarta.websocket.Endpoint.onOpen Endpoint.Endpoint + */ + @Test + public void onCloseWorksTest() throws Exception { + invoke("msg", WSCMsgServer.MESSAGES[0], WSCMsgServer.EMPTY); + invoke("close", "anything", "anything"); + invokeUntilFound("msg", WSCMsgServer.MESSAGES[1], WSCCloseServerEndpoint.CLOSE); + logMsg("@OnClose has been called after session.close() as expected"); + } + + // ////////////////////////////////////////////////////////////////////// + private void invokeUntilFound(String endpoint, String content, String search) throws Exception { + int sleep = 100; + long maxWait = _ws_wait * (1000 / sleep); + long count = 0; + boolean found = false; + String response = null; + while (!found && count < maxWait) { + invoke(endpoint, content, "", false); + response = getLastResponse(String.class); + if (response.equals(search)) + found = true; + cleanup(); + if (!found) + TestUtil.sleepMsec(sleep); + count++; + } + if (!found) { + new Exception(search + " has not been found in response, last response was " + response); + } + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/EchoConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/EchoConfigurator.java index 07be16d5a8..d467e943d7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/EchoConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/EchoConfigurator.java @@ -27,19 +27,18 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class EchoConfigurator extends Configurator { - static final String KEY = "ReadOnlyKey"; + static final String KEY = "ReadOnlyKey"; - static final String[] VALUES = { "ReadOnlyValue1", "ReadOnlyValue2" }; + static final String[] VALUES = { "ReadOnlyValue1", "ReadOnlyValue2" }; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - Map> map = request.getHeaders(); - try { - map.put(KEY, Arrays.asList(VALUES)); - } catch (Exception e) { - // possible, but not mandatory - } - response.getHeaders().putAll(map); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + Map> map = request.getHeaders(); + try { + map.put(KEY, Arrays.asList(VALUES)); + } catch (Exception e) { + // possible, but not mandatory + } + response.getHeaders().putAll(map); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/SetHeadersConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/SetHeadersConfigurator.java index 4fcd0faae0..bcec6943b6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/SetHeadersConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/SetHeadersConfigurator.java @@ -27,16 +27,15 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class SetHeadersConfigurator extends Configurator { - static final String KEY = "aFirstKey"; + static final String KEY = "aFirstKey"; - static final String[] HEADERS = { "header1", "header2", "header3", "header4", - "header5", "header6", "header7", "header8" }; + static final String[] HEADERS = { "header1", "header2", "header3", "header4", "header5", "header6", "header7", + "header8" }; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - Map> map = request.getHeaders(); - response.getHeaders().putAll(map); - response.getHeaders().put(KEY, Arrays.asList(HEADERS)); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + Map> map = request.getHeaders(); + response.getHeaders().putAll(map); + response.getHeaders().put(KEY, Arrays.asList(HEADERS)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCClient.java deleted file mode 100644 index 77b9b1b2e5..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCClient.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.handshakeresponse; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; - -import jakarta.websocket.ClientEndpointConfig; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSCClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 2315071335485201973L; - - public WSCClient() { - setContextRoot("wsc_ee_jakarta_websocket_handshakeresponse_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - static final String KEY = "aFirstKey"; - - static final String[] HEADERS = { "header1", "header2", "header3", "header4", - "header5", "header6", "header7", "header8" }; - - /* Run test */ - - /* - * @testName: headerToHeaderTest - * - * @assertion_ids: WebSocket:JAVADOC:77; WebSocket:JAVADOC:174; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:16; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeResponse.getHeaders HandshakeRequest.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ClientEndpointConfig.Configurator.beforeRequest - * ServerEndpointConfig.Configurator.modifyHandshake - * - * This test sets headers to request on client, on server it reads them, and - * put them to response, and headers are checked on client - */ - public void headerToHeaderTest() throws Exception { - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToRequestAndResponse(KEY, HEADERS); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - invoke("echo", "anything", "anything"); - configurator.assertBeforeRequestHasBeenCalled(); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: addHeadersOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:77; WebSocket:JAVADOC:174; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:16; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeResponse.getHeaders HandshakeRequest.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ClientEndpointConfig.Configurator.beforeRequest - * ServerEndpointConfig.Configurator.modifyHandshake - * - * This test puts new values to header map on server and it is checked on a - * client - */ - public void addHeadersOnServerTest() throws Exception { - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse(SetHeadersConfigurator.KEY, - SetHeadersConfigurator.HEADERS); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - invoke("setheaders", "anything", "anything"); - configurator.assertBeforeRequestHasBeenCalled(); - configurator.assertAfterResponseHasBeenCalled(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCClientIT.java new file mode 100644 index 0000000000..35a140fe48 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCClientIT.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.handshakeresponse; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +import jakarta.websocket.ClientEndpointConfig; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 2315071335485201973L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_jakarta_websocket_handshakeresponse_web.war"); + archive.addPackages(true, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.handshakeresponse"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_jakarta_websocket_handshakeresponse_web"); + } + + static final String KEY = "aFirstKey"; + + static final String[] HEADERS = { "header1", "header2", "header3", "header4", "header5", "header6", "header7", + "header8" }; + + /* Run test */ + + /* + * @testName: headerToHeaderTest + * + * @assertion_ids: WebSocket:JAVADOC:77; WebSocket:JAVADOC:174; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:16; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeResponse.getHeaders HandshakeRequest.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ClientEndpointConfig.Configurator.beforeRequest + * ServerEndpointConfig.Configurator.modifyHandshake + * + * This test sets headers to request on client, on server it reads them, and put + * them to response, and headers are checked on client + */ + @Test + public void headerToHeaderTest() throws Exception { + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToRequestAndResponse(KEY, HEADERS); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + invoke("echo", "anything", "anything"); + configurator.assertBeforeRequestHasBeenCalled(); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: addHeadersOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:77; WebSocket:JAVADOC:174; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:16; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeResponse.getHeaders HandshakeRequest.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ClientEndpointConfig.Configurator.beforeRequest + * ServerEndpointConfig.Configurator.modifyHandshake + * + * This test puts new values to header map on server and it is checked on a + * client + */ + @Test + public void addHeadersOnServerTest() throws Exception { + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse(SetHeadersConfigurator.KEY, SetHeadersConfigurator.HEADERS); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + invoke("setheaders", "anything", "anything"); + configurator.assertBeforeRequestHasBeenCalled(); + configurator.assertAfterResponseHasBeenCalled(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCEchoServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCEchoServer.java index 9a8f692eab..12d18b335a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCEchoServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCEchoServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/echo", configurator = EchoConfigurator.class) public class WSCEchoServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCSetHeadersServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCSetHeadersServer.java index dd608304d3..95e91aaee7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCSetHeadersServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/handshakeresponse/WSCSetHeadersServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/setheaders", configurator = SetHeadersConfigurator.class) public class WSCSetHeadersServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/AppConfig.java index d2d81c7e79..5645cc1435 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/AppConfig.java @@ -30,29 +30,28 @@ public class AppConfig implements ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - set.add(new BinaryDecoderEndpointConfig()); - set.add(new BinaryEncoderEndpointConfig()); - set.add(new BinaryStreamDecoderEndpointConfig()); - set.add(new BinaryStreamEncoderEndpointConfig()); - set.add(new TextDecoderEndpointConfig()); - set.add(new TextEncoderEndpointConfig()); - set.add(new TextStreamDecoderEndpointConfig()); - set.add(new TextStreamEncoderEndpointConfig()); - set.add(new WillDecodeBinaryDecoderEndpointConfig()); - set.add(new WillDecodeTextDecoderEndpointConfig()); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + set.add(new BinaryDecoderEndpointConfig()); + set.add(new BinaryEncoderEndpointConfig()); + set.add(new BinaryStreamDecoderEndpointConfig()); + set.add(new BinaryStreamEncoderEndpointConfig()); + set.add(new TextDecoderEndpointConfig()); + set.add(new TextEncoderEndpointConfig()); + set.add(new TextStreamDecoderEndpointConfig()); + set.add(new TextStreamEncoderEndpointConfig()); + set.add(new WillDecodeBinaryDecoderEndpointConfig()); + set.add(new WillDecodeTextDecoderEndpointConfig()); + return set; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(WSCLoggerServer.class); - set.add(WSCSimpleBinaryEchoServer.class); - set.add(WSCSimpleEchoServer.class); - return set; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(WSCLoggerServer.class); + set.add(WSCSimpleBinaryEchoServer.class); + set.add(WSCSimpleEchoServer.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryDecoderEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryDecoderEndpointConfig.java index 17980358ad..3d2ea62aff 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryDecoderEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryDecoderEndpointConfig.java @@ -31,48 +31,48 @@ public class BinaryDecoderEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSCBinaryDecoderServer.class; - } + @Override + public Class getEndpointClass() { + return WSCBinaryDecoderServer.class; + } - @Override - public String getPath() { - return "/binarydecoder"; - } + @Override + public String getPath() { + return "/binarydecoder"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - Class clz = InitDestroyBinaryDecoder.class; - List> list = new LinkedList<>(); - list.add(clz); - return list; - } + @Override + public List> getDecoders() { + Class clz = InitDestroyBinaryDecoder.class; + List> list = new LinkedList<>(); + list.add(clz); + return list; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryEncoderEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryEncoderEndpointConfig.java index e8dc82ff41..5e8169bcfc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryEncoderEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryEncoderEndpointConfig.java @@ -31,48 +31,48 @@ public class BinaryEncoderEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSCBinaryEncoderServer.class; - } + @Override + public Class getEndpointClass() { + return WSCBinaryEncoderServer.class; + } - @Override - public String getPath() { - return "/binaryencoder"; - } + @Override + public String getPath() { + return "/binaryencoder"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - Class clz = InitDestroyBinaryEncoder.class; - List> list = new LinkedList<>(); - list.add(clz); - return list; - } + @Override + public List> getEncoders() { + Class clz = InitDestroyBinaryEncoder.class; + List> list = new LinkedList<>(); + list.add(clz); + return list; + } - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + @Override + public List> getDecoders() { + return Collections.emptyList(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryStreamDecoderEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryStreamDecoderEndpointConfig.java index e0620c8ddb..8ca213392a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryStreamDecoderEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryStreamDecoderEndpointConfig.java @@ -31,48 +31,48 @@ public class BinaryStreamDecoderEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSCBinaryStreamDecoderServer.class; - } + @Override + public Class getEndpointClass() { + return WSCBinaryStreamDecoderServer.class; + } - @Override - public String getPath() { - return "/binarystreamdecoder"; - } + @Override + public String getPath() { + return "/binarystreamdecoder"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - Class clz = InitDestroyBinaryStreamDecoder.class; - List> list = new LinkedList<>(); - list.add(clz); - return list; - } + @Override + public List> getDecoders() { + Class clz = InitDestroyBinaryStreamDecoder.class; + List> list = new LinkedList<>(); + list.add(clz); + return list; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryStreamEncoderEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryStreamEncoderEndpointConfig.java index f9addf3e31..c5bed5e1ca 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryStreamEncoderEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/BinaryStreamEncoderEndpointConfig.java @@ -31,48 +31,48 @@ public class BinaryStreamEncoderEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSCBinaryStreamEncoderServer.class; - } + @Override + public Class getEndpointClass() { + return WSCBinaryStreamEncoderServer.class; + } - @Override - public String getPath() { - return "/binarystreamencoder"; - } + @Override + public String getPath() { + return "/binarystreamencoder"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - Class clz = InitDestroyBinaryStreamEncoder.class; - List> list = new LinkedList<>(); - list.add(clz); - return list; - } + @Override + public List> getEncoders() { + Class clz = InitDestroyBinaryStreamEncoder.class; + List> list = new LinkedList<>(); + list.add(clz); + return list; + } - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + @Override + public List> getDecoders() { + return Collections.emptyList(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextDecoderEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextDecoderEndpointConfig.java index 0fdc41edf9..2470a1f9ec 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextDecoderEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextDecoderEndpointConfig.java @@ -31,48 +31,48 @@ public class TextDecoderEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSCTextDecoderServer.class; - } + @Override + public Class getEndpointClass() { + return WSCTextDecoderServer.class; + } - @Override - public String getPath() { - return "/textdecoder"; - } + @Override + public String getPath() { + return "/textdecoder"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - Class clz = InitDestroyTextDecoder.class; - List> list = new LinkedList<>(); - list.add(clz); - return list; - } + @Override + public List> getDecoders() { + Class clz = InitDestroyTextDecoder.class; + List> list = new LinkedList<>(); + list.add(clz); + return list; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextEncoderEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextEncoderEndpointConfig.java index 3fa76e5b01..e2e2a7c926 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextEncoderEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextEncoderEndpointConfig.java @@ -31,48 +31,48 @@ public class TextEncoderEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSCTextEncoderServer.class; - } + @Override + public Class getEndpointClass() { + return WSCTextEncoderServer.class; + } - @Override - public String getPath() { - return "/textencoder"; - } + @Override + public String getPath() { + return "/textencoder"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - Class clz = InitDestroyTextEncoder.class; - List> list = new LinkedList<>(); - list.add(clz); - return list; - } + @Override + public List> getEncoders() { + Class clz = InitDestroyTextEncoder.class; + List> list = new LinkedList<>(); + list.add(clz); + return list; + } - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + @Override + public List> getDecoders() { + return Collections.emptyList(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextStreamDecoderEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextStreamDecoderEndpointConfig.java index a66afe4c0e..431e374477 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextStreamDecoderEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextStreamDecoderEndpointConfig.java @@ -31,48 +31,48 @@ public class TextStreamDecoderEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSCTextStreamDecoderServer.class; - } + @Override + public Class getEndpointClass() { + return WSCTextStreamDecoderServer.class; + } - @Override - public String getPath() { - return "/textstreamdecoder"; - } + @Override + public String getPath() { + return "/textstreamdecoder"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - Class clz = InitDestroyTextStreamDecoder.class; - List> list = new LinkedList<>(); - list.add(clz); - return list; - } + @Override + public List> getDecoders() { + Class clz = InitDestroyTextStreamDecoder.class; + List> list = new LinkedList<>(); + list.add(clz); + return list; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextStreamEncoderEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextStreamEncoderEndpointConfig.java index 344346cc71..4ff6a36303 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextStreamEncoderEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/TextStreamEncoderEndpointConfig.java @@ -31,48 +31,48 @@ public class TextStreamEncoderEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSCTextStreamEncoderServer.class; - } + @Override + public Class getEndpointClass() { + return WSCTextStreamEncoderServer.class; + } - @Override - public String getPath() { - return "/textstreamencoder"; - } + @Override + public String getPath() { + return "/textstreamencoder"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - Class clz = InitDestroyTextStreamEncoder.class; - List> list = new LinkedList<>(); - list.add(clz); - return list; - } + @Override + public List> getEncoders() { + Class clz = InitDestroyTextStreamEncoder.class; + List> list = new LinkedList<>(); + list.add(clz); + return list; + } - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + @Override + public List> getDecoders() { + return Collections.emptyList(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCBinaryDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCBinaryDecoderServer.java index cccee1a447..4d49f0eca2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCBinaryDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCBinaryDecoderServer.java @@ -27,36 +27,35 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class WSCBinaryDecoderServer extends Endpoint - implements MessageHandler.Whole { - - private Session session; - - @Override - public void onMessage(StringBean bean) { - try { - session.getBasicRemote().sendText(bean.get()); - } catch (IOException e) { - onError(session, e); - } - } - - @Override - public void onError(Session session, Throwable t) { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - this.session.addMessageHandler(this); - } +public class WSCBinaryDecoderServer extends Endpoint implements MessageHandler.Whole { + + private Session session; + + @Override + public void onMessage(StringBean bean) { + try { + session.getBasicRemote().sendText(bean.get()); + } catch (IOException e) { + onError(session, e); + } + } + + @Override + public void onError(Session session, Throwable t) { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + this.session.addMessageHandler(this); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCBinaryEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCBinaryEncoderServer.java index e213c8cdc5..eaebe84536 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCBinaryEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCBinaryEncoderServer.java @@ -27,35 +27,34 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class WSCBinaryEncoderServer extends Endpoint - implements MessageHandler.Whole { - - private Session session; - - @Override - public void onMessage(String bean) { - try { - session.getBasicRemote().sendObject(new StringBean(bean)); - } catch (Exception e) { - onError(session, e); - } - } - - @Override - public void onError(Session session, Throwable t) { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - this.session.addMessageHandler(this); - } +public class WSCBinaryEncoderServer extends Endpoint implements MessageHandler.Whole { + + private Session session; + + @Override + public void onMessage(String bean) { + try { + session.getBasicRemote().sendObject(new StringBean(bean)); + } catch (Exception e) { + onError(session, e); + } + } + + @Override + public void onError(Session session, Throwable t) { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + this.session.addMessageHandler(this); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCWillDecodeTextDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCWillDecodeTextDecoderServer.java index bd4179db00..070080b175 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCWillDecodeTextDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSCWillDecodeTextDecoderServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 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 @@ -17,5 +17,4 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.programaticcoder; public class WSCWillDecodeTextDecoderServer extends WSCBinaryDecoderServer { - } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSProgramaticClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSProgramaticClient.java deleted file mode 100644 index 57897d6a44..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSProgramaticClient.java +++ /dev/null @@ -1,815 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.programaticcoder; - -import java.util.LinkedList; -import java.util.List; - -import com.sun.ts.tests.websocket.common.stringbean.StringBean; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanClientEndpoint; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyBinaryDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyBinaryEncoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyBinaryStreamDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyBinaryStreamEncoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyTextDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyTextEncoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyTextStreamDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyTextStreamEncoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.WSClient; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.WillDecodeFirstBinaryDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.WillDecodeFirstTextDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.WillDecodeSecondBinaryDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.WillDecodeSecondTextDecoder; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.Decoder; -import jakarta.websocket.Encoder; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSProgramaticClient extends WSClient { - - private static final long serialVersionUID = 5189314464250884426L; - - public WSProgramaticClient() { - setContextRoot("wsc_ee_programaticcoder_web"); - } - - public static void main(String[] args) { - new WSProgramaticClient().run(args); - } - - /* Run test */ - /* - * @testName: textEncoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:61; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode - */ - @Override - public void textEncoderInitDestroyTest() throws Exception { - super.textEncoderInitDestroyTest(); - } - - /* - * @testName: textStreamEncoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:63; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text stream encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode - */ - @Override - public void textStreamEncoderInitDestroyTest() throws Exception { - super.textStreamEncoderInitDestroyTest(); - } - - /* - * @testName: binaryEncoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:56; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode - */ - @Override - public void binaryEncoderInitDestroyTest() throws Exception { - super.binaryEncoderInitDestroyTest(); - } - - /* - * @testName: binaryStreamEncoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:58; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary stream encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode - */ - @Override - public void binaryStreamEncoderInitDestroyTest() throws Exception { - super.binaryStreamEncoderInitDestroyTest(); - } - - // ---------------------------------------------------------------------- - - /* - * @testName: textDecoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode, willdecode - */ - @Override - public void textDecoderInitDestroyTest() throws Exception { - super.textDecoderInitDestroyTest(); - } - - /* - * @testName: textStreamDecoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:46; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text stream decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode - */ - @Override - public void textStreamDecoderInitDestroyTest() throws Exception { - super.textStreamDecoderInitDestroyTest(); - } - - /* - * @testName: binaryDecoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode, willDecode - */ - @Override - public void binaryDecoderInitDestroyTest() throws Exception { - super.binaryDecoderInitDestroyTest(); - } - - /* - * @testName: binaryStreamDecoderInitDestroyTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:40; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary stream decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode - */ - @Override - public void binaryStreamDecoderInitDestroyTest() throws Exception { - super.binaryStreamDecoderInitDestroyTest(); - } - - // ---------------------------------------------------------------------- - - /* - * @testName: textEncoderEncodeTest - * - * @assertion_ids: WebSocket:JAVADOC:61; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text encoder encode was called - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - @Override - public void textEncoderEncodeTest() throws Exception { - super.textEncoderEncodeTest(); - } - - /* - * @testName: textStreamEncoderEncodeTest - * - * @assertion_ids: WebSocket:JAVADOC:63; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text stream encode was called - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - @Override - public void textStreamEncoderEncodeTest() throws Exception { - super.textStreamEncoderEncodeTest(); - } - - /* - * @testName: binaryEncoderEncodeTest - * - * @assertion_ids: WebSocket:JAVADOC:56; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary encoder encode was called - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - @Override - public void binaryEncoderEncodeTest() throws Exception { - super.binaryEncoderEncodeTest(); - } - - /* - * @testName: binaryStreamEncoderEncodeTest - * - * @assertion_ids: WebSocket:JAVADOC:58; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary stream encoder encode was called - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - @Override - public void binaryStreamEncoderEncodeTest() throws Exception { - super.binaryStreamEncoderEncodeTest(); - } - - // ----------------------------------------------------------------------- - - /* - * @testName: textDecoderDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; - * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test text decoder decode and willDecode were called - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - @Override - public void textDecoderDecodeTest() throws Exception { - super.textDecoderDecodeTest(); - } - - /* - * @testName: textStreamDecoderDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:46; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text stream decoder decode was called - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - @Override - public void textStreamDecoderDecodeTest() throws Exception { - super.textStreamDecoderDecodeTest(); - } - - /* - * @testName: binaryDecoderDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; - * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test binary decoder decode and willDecode were called - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - @Override - public void binaryDecoderDecodeTest() throws Exception { - super.binaryDecoderDecodeTest(); - } - - /* - * @testName: binaryStreamDecoderDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:40; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary stream decoder decode was called - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - @Override - public void binaryStreamDecoderDecodeTest() throws Exception { - super.binaryStreamDecoderDecodeTest(); - } - - /* - * @testName: binaryDecoderWillDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; - * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test binary decoder with willDecode returning false will - * not be used - */ - @Override - public void binaryDecoderWillDecodeTest() throws Exception { - super.binaryDecoderWillDecodeTest(); - } - - /* - * @testName: textDecoderWillDecodeTest - * - * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; - * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test text decoder with willDecode returning false will not - * be used - */ - @Override - public void textDecoderWillDecodeTest() throws Exception { - super.textDecoderWillDecodeTest(); - } - - // ===================================================================== - - /* - * @testName: textEncoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:61; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode - */ - @Override - public void textEncoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setEncoder(InitDestroyTextEncoder.class); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertInit(InitDestroyTextEncoder.class); - assertDestroy(InitDestroyTextEncoder.class); - } - - /* - * @testName: textStreamEncoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:63; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text stream encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode - */ - @Override - public void textStreamEncoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setEncoder(InitDestroyTextStreamEncoder.class); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertInit(InitDestroyTextStreamEncoder.class); - assertDestroy(InitDestroyTextStreamEncoder.class); - } - - /* - * @testName: binaryEncoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:56; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode - */ - @Override - public void binaryEncoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setEncoder(InitDestroyBinaryEncoder.class); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertInit(InitDestroyBinaryEncoder.class); - assertDestroy(InitDestroyBinaryEncoder.class); - } - - /* - * @testName: binaryStreamEncoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; - * WebSocket:JAVADOC:58; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary stream encoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - * - * encode - */ - @Override - public void binaryStreamEncoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setEncoder(InitDestroyBinaryStreamEncoder.class); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertInit(InitDestroyBinaryStreamEncoder.class); - assertDestroy(InitDestroyBinaryStreamEncoder.class); - } - - // --------------------------------------------------------------------- - - /* - * @testName: textDecoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode, willdecode - */ - @Override - public void textDecoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setClientEndpointInstance(new StringBeanClientEndpoint()); - setDecoder(InitDestroyTextDecoder.class); - invoke("simpleecho", ECHO, ECHO); - assertInit(InitDestroyTextDecoder.class); - assertDestroy(InitDestroyTextDecoder.class); - } - - /* - * @testName: textStreamDecoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:46; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text stream decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode - */ - @Override - public void textStreamDecoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setClientEndpointInstance(new StringBeanClientEndpoint()); - setDecoder(InitDestroyTextStreamDecoder.class); - invoke("simpleecho", ECHO, ECHO); - assertInit(InitDestroyTextStreamDecoder.class); - assertDestroy(InitDestroyTextStreamDecoder.class); - } - - /* - * @testName: binaryDecoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode, willDecode - */ - @Override - public void binaryDecoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setClientEndpointInstance(new StringBeanClientEndpoint()); - setDecoder(InitDestroyBinaryDecoder.class); - invoke("simplebin", ECHO, ECHO); - assertInit(InitDestroyBinaryDecoder.class); - assertDestroy(InitDestroyBinaryDecoder.class); - } - - /* - * @testName: binaryStreamDecoderInitDestroyOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; - * WebSocket:JAVADOC:40; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary stream decoder init and destroy were called The - * websocket implementation creates a new instance of the encoder per endpoint - * instance per connection. - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - * - * decode - */ - @Override - public void binaryStreamDecoderInitDestroyOnClientTest() throws Exception { - clientClear(); - setClientEndpointInstance(new StringBeanClientEndpoint()); - setDecoder(InitDestroyBinaryStreamDecoder.class); - invoke("simplebin", ECHO, ECHO); - assertInit(InitDestroyBinaryStreamDecoder.class); - assertDestroy(InitDestroyBinaryStreamDecoder.class); - } - - // ---------------------------------------------------------------------- - - /* - * @testName: textEncoderEncodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:61; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text encoder encode was called - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - @Override - public void textEncoderEncodeOnClientTest() throws Exception { - clientClear(); - setEncoder(InitDestroyTextEncoder.class); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertCode(InitDestroyTextEncoder.class); - } - - /* - * @testName: textStreamEncoderEncodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:63; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test text stream encode was called - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - @Override - public void textStreamEncoderEncodeOnClientTest() throws Exception { - clientClear(); - setEncoder(InitDestroyTextStreamEncoder.class); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertCode(InitDestroyTextStreamEncoder.class); - } - - /* - * @testName: binaryEncoderEncodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:56; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary encoder encode was called - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - @Override - public void binaryEncoderEncodeOnClientTest() throws Exception { - clientClear(); - setEncoder(InitDestroyBinaryEncoder.class); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertCode(InitDestroyBinaryEncoder.class); - } - - /* - * @testName: binaryStreamEncoderEncodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:58; WebSocket:SPEC:WSC-4.1.2-1; - * - * @test_Strategy: test binary stream encoder encode was called - * - * The implementation must attempt to encode application objects of matching - * parametrized type as the encoder when they are attempted to be sent - */ - @Override - public void binaryStreamEncoderEncodeOnClientTest() throws Exception { - clientClear(); - setEncoder(InitDestroyBinaryStreamEncoder.class); - invoke("simpleecho", new StringBean(ECHO), ECHO); - assertCode(InitDestroyBinaryStreamEncoder.class); - } - - // ---------------------------------------------------------------------- - - /* - * @testName: textDecoderDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; - * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test text decoder decode and willDecode were called - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - @Override - public void textDecoderDecodeOnClientTest() throws Exception { - clientClear(); - setDecoder(InitDestroyTextDecoder.class); - setClientEndpointInstance(new StringBeanClientEndpoint()); - invoke("simpleecho", ECHO, ECHO); - assertCode(InitDestroyTextDecoder.class); - assertWillCode(InitDestroyTextDecoder.class); - } - - /* - * @testName: textStreamDecoderDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:46; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test text stream decoder decode was called - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - @Override - public void textStreamDecoderDecodeOnClientTest() throws Exception { - clientClear(); - setDecoder(InitDestroyTextStreamDecoder.class); - setClientEndpointInstance(new StringBeanClientEndpoint()); - invoke("simpleecho", ECHO, ECHO); - assertCode(InitDestroyTextStreamDecoder.class); - } - - /* - * @testName: binaryDecoderDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; - * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test binary decoder decode and willDecode were called - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - @Override - public void binaryDecoderDecodeOnClientTest() throws Exception { - clientClear(); - setDecoder(InitDestroyBinaryDecoder.class); - setClientEndpointInstance(new StringBeanClientEndpoint()); - invoke("simplebin", ECHO, ECHO); - assertCode(InitDestroyBinaryDecoder.class); - assertWillCode(InitDestroyBinaryDecoder.class); - } - - /* - * @testName: binaryStreamDecoderDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:40; WebSocket:SPEC:WSC-4.1.3-1; - * - * @test_Strategy: test binary stream decoder decode was called - * - * The implementation must attempt to decode websocket messages using the - * decoder in the list appropriate to the native websocket message type and - * pass the message in decoded object form to the websocket endpoint - */ - @Override - public void binaryStreamDecoderDecodeOnClientTest() throws Exception { - clientClear(); - setDecoder(InitDestroyBinaryStreamDecoder.class); - setClientEndpointInstance(new StringBeanClientEndpoint()); - invoke("simplebin", ECHO, ECHO); - assertCode(InitDestroyBinaryStreamDecoder.class); - } - - /* - * @testName: binaryDecoderWillDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; - * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test binary decoder with willDecode returning false will - * not be used - */ - @Override - public void binaryDecoderWillDecodeOnClientTest() throws Exception { - clientClear(); - setClientEndpointInstance(new StringBeanClientEndpoint()); - setDecoder(WillDecodeFirstBinaryDecoder.class, - WillDecodeSecondBinaryDecoder.class); - invoke("simplebin", ECHO, ECHO); - assertWillCode(WillDecodeFirstBinaryDecoder.class); - assertWillCode(WillDecodeSecondBinaryDecoder.class); - assertNotCode(WillDecodeFirstBinaryDecoder.class); - assertCode(WillDecodeSecondBinaryDecoder.class); - } - - /* - * @testName: textDecoderWillDecodeOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; - * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; - * - * @test_Strategy: test text decoder with willDecode returning false will not - * be used - */ - @Override - public void textDecoderWillDecodeOnClientTest() throws Exception { - clientClear(); - setClientEndpointInstance(new StringBeanClientEndpoint()); - setDecoder(WillDecodeFirstTextDecoder.class, - WillDecodeSecondTextDecoder.class); - invoke("simpleecho", ECHO, ECHO); - assertWillCode(WillDecodeFirstTextDecoder.class); - assertWillCode(WillDecodeSecondTextDecoder.class); - assertNotCode(WillDecodeFirstTextDecoder.class); - assertCode(WillDecodeSecondTextDecoder.class); - } - - ///////////////////////////////////////////////////////////////////////// - - @SafeVarargs - private final void setEncoder(Class... encoders) { - List> list = new LinkedList<>(); - for (Class encoder : encoders) - list.add(encoder); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .encoders(list).build(); - setClientEndpointConfig(config); - } - - @SafeVarargs - private final void setDecoder(Class... decoders) { - List> list = new LinkedList<>(); - for (Class decoder : decoders) - list.add(decoder); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .decoders(list).build(); - setClientEndpointConfig(config); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSProgramaticClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSProgramaticClientIT.java new file mode 100644 index 0000000000..a2c6122034 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WSProgramaticClientIT.java @@ -0,0 +1,867 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.programaticcoder; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanClientEndpoint; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.CoderClient; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyBinaryDecoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyBinaryEncoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyBinaryStreamDecoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyBinaryStreamEncoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyTextDecoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyTextEncoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyTextStreamDecoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.InitDestroyTextStreamEncoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.WSClientIT; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.WillDecodeFirstBinaryDecoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.WillDecodeFirstTextDecoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.WillDecodeSecondBinaryDecoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.coder.WillDecodeSecondTextDecoder; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.Decoder; +import jakarta.websocket.Encoder; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +//@ExtendWith(ArquillianExtension.class) +public class WSProgramaticClientIT extends CoderClient { + + private static final long serialVersionUID = 5189314464250884426L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_programaticcoder_web.war"); + archive.addPackages(true, Filters.exclude(WSProgramaticClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.programaticcoder"); + archive.addPackages(true, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.coder"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + + public WSProgramaticClientIT() throws Exception { + setup(); + setContextRoot("wsc_ee_programaticcoder_web"); + } + + /* Run test */ + /* + * @testName: textEncoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:61; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text encoder init and destroy were called The websocket + * implementation creates a new instance of the encoder per endpoint instance + * per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode + */ + @Override + @Test + public void textEncoderInitDestroyTest() throws Exception { + super.textEncoderInitDestroyTest(); + } + + /* + * @testName: textStreamEncoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:63; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text stream encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode + */ + @Override + @Test + public void textStreamEncoderInitDestroyTest() throws Exception { + super.textStreamEncoderInitDestroyTest(); + } + + /* + * @testName: binaryEncoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:56; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode + */ + @Override + @Test + public void binaryEncoderInitDestroyTest() throws Exception { + super.binaryEncoderInitDestroyTest(); + } + + /* + * @testName: binaryStreamEncoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:58; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary stream encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode + */ + @Override + @Test + public void binaryStreamEncoderInitDestroyTest() throws Exception { + super.binaryStreamEncoderInitDestroyTest(); + } + + // ---------------------------------------------------------------------- + + /* + * @testName: textDecoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text decoder init and destroy were called The websocket + * implementation creates a new instance of the encoder per endpoint instance + * per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode, willdecode + */ + @Override + @Test + public void textDecoderInitDestroyTest() throws Exception { + super.textDecoderInitDestroyTest(); + } + + /* + * @testName: textStreamDecoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:46; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text stream decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode + */ + @Override + @Test + public void textStreamDecoderInitDestroyTest() throws Exception { + super.textStreamDecoderInitDestroyTest(); + } + + /* + * @testName: binaryDecoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode, willDecode + */ + @Override + @Test + public void binaryDecoderInitDestroyTest() throws Exception { + super.binaryDecoderInitDestroyTest(); + } + + /* + * @testName: binaryStreamDecoderInitDestroyTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:40; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary stream decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode + */ + @Override + @Test + public void binaryStreamDecoderInitDestroyTest() throws Exception { + super.binaryStreamDecoderInitDestroyTest(); + } + + // ---------------------------------------------------------------------- + + /* + * @testName: textEncoderEncodeTest + * + * @assertion_ids: WebSocket:JAVADOC:61; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text encoder encode was called + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Override + @Test + public void textEncoderEncodeTest() throws Exception { + super.textEncoderEncodeTest(); + } + + /* + * @testName: textStreamEncoderEncodeTest + * + * @assertion_ids: WebSocket:JAVADOC:63; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text stream encode was called + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Override + @Test + public void textStreamEncoderEncodeTest() throws Exception { + super.textStreamEncoderEncodeTest(); + } + + /* + * @testName: binaryEncoderEncodeTest + * + * @assertion_ids: WebSocket:JAVADOC:56; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary encoder encode was called + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Override + @Test + public void binaryEncoderEncodeTest() throws Exception { + super.binaryEncoderEncodeTest(); + } + + /* + * @testName: binaryStreamEncoderEncodeTest + * + * @assertion_ids: WebSocket:JAVADOC:58; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary stream encoder encode was called + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Override + @Test + public void binaryStreamEncoderEncodeTest() throws Exception { + super.binaryStreamEncoderEncodeTest(); + } + + // ----------------------------------------------------------------------- + + /* + * @testName: textDecoderDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; + * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test text decoder decode and willDecode were called + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Override + @Test + public void textDecoderDecodeTest() throws Exception { + super.textDecoderDecodeTest(); + } + + /* + * @testName: textStreamDecoderDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:46; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text stream decoder decode was called + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Override + @Test + public void textStreamDecoderDecodeTest() throws Exception { + super.textStreamDecoderDecodeTest(); + } + + /* + * @testName: binaryDecoderDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; + * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test binary decoder decode and willDecode were called + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Override + @Test + public void binaryDecoderDecodeTest() throws Exception { + super.binaryDecoderDecodeTest(); + } + + /* + * @testName: binaryStreamDecoderDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:40; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary stream decoder decode was called + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Override + @Test + public void binaryStreamDecoderDecodeTest() throws Exception { + super.binaryStreamDecoderDecodeTest(); + } + + /* + * @testName: binaryDecoderWillDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; + * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test binary decoder with willDecode returning false will not + * be used + */ + @Override + @Test + public void binaryDecoderWillDecodeTest() throws Exception { + super.binaryDecoderWillDecodeTest(); + } + + /* + * @testName: textDecoderWillDecodeTest + * + * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; + * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test text decoder with willDecode returning false will not be + * used + */ + @Override + @Test + public void textDecoderWillDecodeTest() throws Exception { + super.textDecoderWillDecodeTest(); + } + + // ===================================================================== + + /* + * @testName: textEncoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:61; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text encoder init and destroy were called The websocket + * implementation creates a new instance of the encoder per endpoint instance + * per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode + */ + @Override + @Test + public void textEncoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setEncoder(InitDestroyTextEncoder.class); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertInit(InitDestroyTextEncoder.class); + assertDestroy(InitDestroyTextEncoder.class); + } + + /* + * @testName: textStreamEncoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:63; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text stream encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode + */ + @Override + @Test + public void textStreamEncoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setEncoder(InitDestroyTextStreamEncoder.class); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertInit(InitDestroyTextStreamEncoder.class); + assertDestroy(InitDestroyTextStreamEncoder.class); + } + + /* + * @testName: binaryEncoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:56; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode + */ + @Override + @Test + public void binaryEncoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setEncoder(InitDestroyBinaryEncoder.class); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertInit(InitDestroyBinaryEncoder.class); + assertDestroy(InitDestroyBinaryEncoder.class); + } + + /* + * @testName: binaryStreamEncoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:54; WebSocket:JAVADOC:55; + * WebSocket:JAVADOC:58; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary stream encoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + * + * encode + */ + @Override + @Test + public void binaryStreamEncoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setEncoder(InitDestroyBinaryStreamEncoder.class); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertInit(InitDestroyBinaryStreamEncoder.class); + assertDestroy(InitDestroyBinaryStreamEncoder.class); + } + + // --------------------------------------------------------------------- + + /* + * @testName: textDecoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text decoder init and destroy were called The websocket + * implementation creates a new instance of the encoder per endpoint instance + * per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode, willdecode + */ + @Override + @Test + public void textDecoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setClientEndpointInstance(new StringBeanClientEndpoint()); + setDecoder(InitDestroyTextDecoder.class); + invoke("simpleecho", ECHO, ECHO); + assertInit(InitDestroyTextDecoder.class); + assertDestroy(InitDestroyTextDecoder.class); + } + + /* + * @testName: textStreamDecoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:46; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text stream decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode + */ + @Override + @Test + public void textStreamDecoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setClientEndpointInstance(new StringBeanClientEndpoint()); + setDecoder(InitDestroyTextStreamDecoder.class); + invoke("simpleecho", ECHO, ECHO); + assertInit(InitDestroyTextStreamDecoder.class); + assertDestroy(InitDestroyTextStreamDecoder.class); + } + + /* + * @testName: binaryDecoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode, willDecode + */ + @Override + @Test + public void binaryDecoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setClientEndpointInstance(new StringBeanClientEndpoint()); + setDecoder(InitDestroyBinaryDecoder.class); + invoke("simplebin", ECHO, ECHO); + assertInit(InitDestroyBinaryDecoder.class); + assertDestroy(InitDestroyBinaryDecoder.class); + } + + /* + * @testName: binaryStreamDecoderInitDestroyOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:35; WebSocket:JAVADOC:36; + * WebSocket:JAVADOC:40; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary stream decoder init and destroy were called The + * websocket implementation creates a new instance of the encoder per endpoint + * instance per connection. + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + * + * decode + */ + @Override + @Test + public void binaryStreamDecoderInitDestroyOnClientTest() throws Exception { + clientClear(); + setClientEndpointInstance(new StringBeanClientEndpoint()); + setDecoder(InitDestroyBinaryStreamDecoder.class); + invoke("simplebin", ECHO, ECHO); + assertInit(InitDestroyBinaryStreamDecoder.class); + assertDestroy(InitDestroyBinaryStreamDecoder.class); + } + + // ---------------------------------------------------------------------- + + /* + * @testName: textEncoderEncodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:61; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text encoder encode was called + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Override + @Test + public void textEncoderEncodeOnClientTest() throws Exception { + clientClear(); + setEncoder(InitDestroyTextEncoder.class); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertCode(InitDestroyTextEncoder.class); + } + + /* + * @testName: textStreamEncoderEncodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:63; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test text stream encode was called + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Override + @Test + public void textStreamEncoderEncodeOnClientTest() throws Exception { + clientClear(); + setEncoder(InitDestroyTextStreamEncoder.class); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertCode(InitDestroyTextStreamEncoder.class); + } + + /* + * @testName: binaryEncoderEncodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:56; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary encoder encode was called + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Override + @Test + public void binaryEncoderEncodeOnClientTest() throws Exception { + clientClear(); + setEncoder(InitDestroyBinaryEncoder.class); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertCode(InitDestroyBinaryEncoder.class); + } + + /* + * @testName: binaryStreamEncoderEncodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:58; WebSocket:SPEC:WSC-4.1.2-1; + * + * @test_Strategy: test binary stream encoder encode was called + * + * The implementation must attempt to encode application objects of matching + * parametrized type as the encoder when they are attempted to be sent + */ + @Override + @Test + public void binaryStreamEncoderEncodeOnClientTest() throws Exception { + clientClear(); + setEncoder(InitDestroyBinaryStreamEncoder.class); + invoke("simpleecho", new StringBean(ECHO), ECHO); + assertCode(InitDestroyBinaryStreamEncoder.class); + } + + // ---------------------------------------------------------------------- + + /* + * @testName: textDecoderDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; + * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test text decoder decode and willDecode were called + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Override + @Test + public void textDecoderDecodeOnClientTest() throws Exception { + clientClear(); + setDecoder(InitDestroyTextDecoder.class); + setClientEndpointInstance(new StringBeanClientEndpoint()); + invoke("simpleecho", ECHO, ECHO); + assertCode(InitDestroyTextDecoder.class); + assertWillCode(InitDestroyTextDecoder.class); + } + + /* + * @testName: textStreamDecoderDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:46; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test text stream decoder decode was called + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Override + @Test + public void textStreamDecoderDecodeOnClientTest() throws Exception { + clientClear(); + setDecoder(InitDestroyTextStreamDecoder.class); + setClientEndpointInstance(new StringBeanClientEndpoint()); + invoke("simpleecho", ECHO, ECHO); + assertCode(InitDestroyTextStreamDecoder.class); + } + + /* + * @testName: binaryDecoderDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; + * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test binary decoder decode and willDecode were called + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Override + @Test + public void binaryDecoderDecodeOnClientTest() throws Exception { + clientClear(); + setDecoder(InitDestroyBinaryDecoder.class); + setClientEndpointInstance(new StringBeanClientEndpoint()); + invoke("simplebin", ECHO, ECHO); + assertCode(InitDestroyBinaryDecoder.class); + assertWillCode(InitDestroyBinaryDecoder.class); + } + + /* + * @testName: binaryStreamDecoderDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:40; WebSocket:SPEC:WSC-4.1.3-1; + * + * @test_Strategy: test binary stream decoder decode was called + * + * The implementation must attempt to decode websocket messages using the + * decoder in the list appropriate to the native websocket message type and pass + * the message in decoded object form to the websocket endpoint + */ + @Override + @Test + public void binaryStreamDecoderDecodeOnClientTest() throws Exception { + clientClear(); + setDecoder(InitDestroyBinaryStreamDecoder.class); + setClientEndpointInstance(new StringBeanClientEndpoint()); + invoke("simplebin", ECHO, ECHO); + assertCode(InitDestroyBinaryStreamDecoder.class); + } + + /* + * @testName: binaryDecoderWillDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:37; WebSocket:JAVADOC:39; + * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test binary decoder with willDecode returning false will not + * be used + */ + @Override + @Test + public void binaryDecoderWillDecodeOnClientTest() throws Exception { + clientClear(); + setClientEndpointInstance(new StringBeanClientEndpoint()); + setDecoder(WillDecodeFirstBinaryDecoder.class, WillDecodeSecondBinaryDecoder.class); + invoke("simplebin", ECHO, ECHO); + assertWillCode(WillDecodeFirstBinaryDecoder.class); + assertWillCode(WillDecodeSecondBinaryDecoder.class); + assertNotCode(WillDecodeFirstBinaryDecoder.class); + assertCode(WillDecodeSecondBinaryDecoder.class); + } + + /* + * @testName: textDecoderWillDecodeOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:43; WebSocket:JAVADOC:45; + * WebSocket:SPEC:WSC-4.1.3-1; WebSocket:SPEC:WSC-4.1.3-2; + * + * @test_Strategy: test text decoder with willDecode returning false will not be + * used + */ + @Override + @Test + public void textDecoderWillDecodeOnClientTest() throws Exception { + clientClear(); + setClientEndpointInstance(new StringBeanClientEndpoint()); + setDecoder(WillDecodeFirstTextDecoder.class, WillDecodeSecondTextDecoder.class); + invoke("simpleecho", ECHO, ECHO); + assertWillCode(WillDecodeFirstTextDecoder.class); + assertWillCode(WillDecodeSecondTextDecoder.class); + assertNotCode(WillDecodeFirstTextDecoder.class); + assertCode(WillDecodeSecondTextDecoder.class); + } + + ///////////////////////////////////////////////////////////////////////// + + @SafeVarargs + private final void setEncoder(Class... encoders) { + List> list = new LinkedList<>(); + for (Class encoder : encoders) + list.add(encoder); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().encoders(list).build(); + setClientEndpointConfig(config); + } + + @SafeVarargs + private final void setDecoder(Class... decoders) { + List> list = new LinkedList<>(); + for (Class decoder : decoders) + list.add(decoder); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().decoders(list).build(); + setClientEndpointConfig(config); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WillDecodeBinaryDecoderEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WillDecodeBinaryDecoderEndpointConfig.java index 138da39cd4..d8ddf3392f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WillDecodeBinaryDecoderEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WillDecodeBinaryDecoderEndpointConfig.java @@ -30,51 +30,50 @@ import jakarta.websocket.Extension; import jakarta.websocket.server.ServerEndpointConfig; -public class WillDecodeBinaryDecoderEndpointConfig - implements ServerEndpointConfig { +public class WillDecodeBinaryDecoderEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSCBinaryDecoderServer.class; - } + @Override + public Class getEndpointClass() { + return WSCBinaryDecoderServer.class; + } - @Override - public String getPath() { - return "/binarywilldecode"; - } + @Override + public String getPath() { + return "/binarywilldecode"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - List> list = new LinkedList<>(); - list.add(WillDecodeFirstBinaryDecoder.class); - list.add(WillDecodeSecondBinaryDecoder.class); - return list; - } + @Override + public List> getDecoders() { + List> list = new LinkedList<>(); + list.add(WillDecodeFirstBinaryDecoder.class); + list.add(WillDecodeSecondBinaryDecoder.class); + return list; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WillDecodeTextDecoderEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WillDecodeTextDecoderEndpointConfig.java index d222c109ed..f6043fa907 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WillDecodeTextDecoderEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/programaticcoder/WillDecodeTextDecoderEndpointConfig.java @@ -30,51 +30,50 @@ import jakarta.websocket.Extension; import jakarta.websocket.server.ServerEndpointConfig; -public class WillDecodeTextDecoderEndpointConfig - implements ServerEndpointConfig { +public class WillDecodeTextDecoderEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSCWillDecodeTextDecoderServer.class; - } + @Override + public Class getEndpointClass() { + return WSCWillDecodeTextDecoderServer.class; + } - @Override - public String getPath() { - return "/textwilldecode"; - } + @Override + public String getPath() { + return "/textwilldecode"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - List> list = new LinkedList<>(); - list.add(WillDecodeFirstTextDecoder.class); - list.add(WillDecodeSecondTextDecoder.class); - return list; - } + @Override + public List> getDecoders() { + List> list = new LinkedList<>(); + list.add(WillDecodeFirstTextDecoder.class); + list.add(WillDecodeSecondTextDecoder.class); + return list; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/PongMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/PongMessageClientEndpoint.java index d29fff0d9c..63b1e88121 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/PongMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/PongMessageClientEndpoint.java @@ -26,15 +26,15 @@ import jakarta.websocket.Session; public class PongMessageClientEndpoint extends BinaryAndTextClientEndpoint { - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - session.addMessageHandler(new MessageHandler.Whole() { - @Override - public void onMessage(PongMessage message) { - String msg = IOUtil.byteBufferToString(message.getApplicationData()); - PongMessageClientEndpoint.this.onMessage(msg); - } - }); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + session.addMessageHandler(new MessageHandler.Whole() { + @Override + public void onMessage(PongMessage message) { + String msg = IOUtil.byteBufferToString(message.getApplicationData()); + PongMessageClientEndpoint.this.onMessage(msg); + } + }); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/AsyncEndpointCallback.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/AsyncEndpointCallback.java index b7b06e1122..2428f3ebfe 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/AsyncEndpointCallback.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/AsyncEndpointCallback.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -17,7 +17,6 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.async; -import com.sun.ts.lib.harness.EETest.Fault; import com.sun.ts.tests.websocket.common.client.EndpointCallback; import jakarta.websocket.EndpointConfig; @@ -25,16 +24,16 @@ import jakarta.websocket.Session; public abstract class AsyncEndpointCallback extends EndpointCallback { - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - Async asyncRemote = session.getAsyncRemote(); - try { - doAsync(asyncRemote); - } catch (Exception f) { - throw new RuntimeException(f); - } - } + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + Async asyncRemote = session.getAsyncRemote(); + try { + doAsync(asyncRemote); + } catch (Exception f) { + throw new RuntimeException(f); + } + } - abstract void doAsync(Async async) throws Exception; + abstract void doAsync(Async async) throws Exception; } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/OPS.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/OPS.java index 0330b27f8c..85bf4a9251 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/OPS.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/OPS.java @@ -17,15 +17,16 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.async; public enum OPS { - POKE, TIMEOUT, // - SENDBINARY, SENDBINARYTHROWS, SENDBINARYEXECUTIONEXCEPTION, // - SENDBINARYHANDLER, SENDBINARYHANDLERTHROWSONDATA, SENDBINARYHANDLERTHROWSONHANDLER, // - SENDOBJECT, SENDOBJECTTHROWS, SENDOBJECTEXECUTIONEXCEPTION, // - SENDOBJECTHANDLER, SENDOBJECTHANDLERTHROWSONDATA, SENDOBJECTHANDLERTHROWSONHANDLER, SENDOBJECTHANDLEREXECUTIONEXCEPTION, // - SENDOBJECT_BYTE, SENDOBJECT_SHORT, SENDOBJECT_INT, SENDOBJECT_LONG, // - SENDOBJECT_FLOAT, SENDOBJECT_DOUBLE, SENDOBJECT_BOOL, SENDOBJECT_CHAR, // - SENDTEXT, SENDTEXTTHROWS, // - SENDTEXTHANDLER, SENDTEXTHANDLERTHROWSONDATA, SENDTEXTHANDLERTHROWSONHANDLER, // - BATCHING_ALLOWED, SEND_PING, SEND_PONG, SEND_PING_THROWS, SEND_PONG_THROWS, // - IDLE /* let ping make no idle timeout */, PING_4_TIMES, PONG_4_TIMES + POKE, TIMEOUT, // + SENDBINARY, SENDBINARYTHROWS, SENDBINARYEXECUTIONEXCEPTION, // + SENDBINARYHANDLER, SENDBINARYHANDLERTHROWSONDATA, SENDBINARYHANDLERTHROWSONHANDLER, // + SENDOBJECT, SENDOBJECTTHROWS, SENDOBJECTEXECUTIONEXCEPTION, // + SENDOBJECTHANDLER, SENDOBJECTHANDLERTHROWSONDATA, SENDOBJECTHANDLERTHROWSONHANDLER, + SENDOBJECTHANDLEREXECUTIONEXCEPTION, // + SENDOBJECT_BYTE, SENDOBJECT_SHORT, SENDOBJECT_INT, SENDOBJECT_LONG, // + SENDOBJECT_FLOAT, SENDOBJECT_DOUBLE, SENDOBJECT_BOOL, SENDOBJECT_CHAR, // + SENDTEXT, SENDTEXTTHROWS, // + SENDTEXTHANDLER, SENDTEXTHANDLERTHROWSONDATA, SENDTEXTHANDLERTHROWSONHANDLER, // + BATCHING_ALLOWED, SEND_PING, SEND_PONG, SEND_PING_THROWS, SEND_PONG_THROWS, // + IDLE /* let ping make no idle timeout */, PING_4_TIMES, PONG_4_TIMES } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/PokingEndpointCallback.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/PokingEndpointCallback.java index 8d8422f0dc..e17da24ac9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/PokingEndpointCallback.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/PokingEndpointCallback.java @@ -27,102 +27,101 @@ public class PokingEndpointCallback extends SendMessageCallback { - public PokingEndpointCallback(Entity entity) { - super(entity); - } + public PokingEndpointCallback(Entity entity) { + super(entity); + } - private Session session; + private Session session; - int pokeCnt = 0; + int pokeCnt = 0; - int pokeMax = 1; + int pokeMax = 1; - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - this.session = session; - } + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + this.session = session; + } - public void onMessage(String msg, Session session) throws IOException { - if (msg.equals(WSCServerSideServer.RESPONSE[0]) - || (msg.equals(WSCServerSideServer.RESPONSE[1]))) - return; - if (msg.startsWith("-100")) - msg = OPS.SENDOBJECT_BYTE.name(); - else if (msg.startsWith("-101")) - msg = OPS.SENDOBJECT_SHORT.name(); - else if (msg.startsWith("-102")) - msg = OPS.SENDOBJECT_INT.name(); - else if (msg.startsWith("-103")) - msg = OPS.SENDOBJECT_LONG.name(); - else if (msg.startsWith("-104")) - msg = OPS.SENDOBJECT_FLOAT.name(); - else if (msg.startsWith("-105")) - msg = OPS.SENDOBJECT_DOUBLE.name(); - else if (msg.startsWith(String.valueOf((char) 106))) - msg = OPS.SENDOBJECT_CHAR.name(); - else if (msg.startsWith("false")) - msg = OPS.SENDOBJECT_BOOL.name(); - OPS ops = OPS.valueOf(msg); - switch (ops) { - case SENDBINARY: - case SENDBINARYHANDLER: - case SENDOBJECT: - case SENDOBJECT_BOOL: - case SENDOBJECT_BYTE: - case SENDOBJECT_CHAR: - case SENDOBJECT_DOUBLE: - case SENDOBJECT_FLOAT: - case SENDOBJECT_INT: - case SENDOBJECT_LONG: - case SENDOBJECT_SHORT: - case SENDOBJECTHANDLER: - case SENDTEXT: - case SENDTEXTHANDLER: - case BATCHING_ALLOWED: - case SEND_PONG: - if (pokeCnt++ <= pokeMax) - session.getBasicRemote().sendText(OPS.POKE.name()); - break; - case SENDBINARYTHROWS: - case SENDBINARYEXECUTIONEXCEPTION: - // - case SENDBINARYHANDLERTHROWSONDATA: - case SENDBINARYHANDLERTHROWSONHANDLER: - // - case SENDOBJECTHANDLEREXECUTIONEXCEPTION: - case SENDOBJECTHANDLERTHROWSONDATA: - case SENDOBJECTHANDLERTHROWSONHANDLER: - // - case SENDOBJECTEXECUTIONEXCEPTION: - case SENDOBJECTTHROWS: - // - case SENDTEXTTHROWS: - // - case SENDTEXTHANDLERTHROWSONDATA: - case SENDTEXTHANDLERTHROWSONHANDLER: - // - case POKE: - case TIMEOUT: - // - case SEND_PING: - case SEND_PING_THROWS: - case SEND_PONG_THROWS: - break; - default: - break; - } - } + public void onMessage(String msg, Session session) throws IOException { + if (msg.equals(WSCServerSideServer.RESPONSE[0]) || (msg.equals(WSCServerSideServer.RESPONSE[1]))) + return; + if (msg.startsWith("-100")) + msg = OPS.SENDOBJECT_BYTE.name(); + else if (msg.startsWith("-101")) + msg = OPS.SENDOBJECT_SHORT.name(); + else if (msg.startsWith("-102")) + msg = OPS.SENDOBJECT_INT.name(); + else if (msg.startsWith("-103")) + msg = OPS.SENDOBJECT_LONG.name(); + else if (msg.startsWith("-104")) + msg = OPS.SENDOBJECT_FLOAT.name(); + else if (msg.startsWith("-105")) + msg = OPS.SENDOBJECT_DOUBLE.name(); + else if (msg.startsWith(String.valueOf((char) 106))) + msg = OPS.SENDOBJECT_CHAR.name(); + else if (msg.startsWith("false")) + msg = OPS.SENDOBJECT_BOOL.name(); + OPS ops = OPS.valueOf(msg); + switch (ops) { + case SENDBINARY: + case SENDBINARYHANDLER: + case SENDOBJECT: + case SENDOBJECT_BOOL: + case SENDOBJECT_BYTE: + case SENDOBJECT_CHAR: + case SENDOBJECT_DOUBLE: + case SENDOBJECT_FLOAT: + case SENDOBJECT_INT: + case SENDOBJECT_LONG: + case SENDOBJECT_SHORT: + case SENDOBJECTHANDLER: + case SENDTEXT: + case SENDTEXTHANDLER: + case BATCHING_ALLOWED: + case SEND_PONG: + if (pokeCnt++ <= pokeMax) + session.getBasicRemote().sendText(OPS.POKE.name()); + break; + case SENDBINARYTHROWS: + case SENDBINARYEXECUTIONEXCEPTION: + // + case SENDBINARYHANDLERTHROWSONDATA: + case SENDBINARYHANDLERTHROWSONHANDLER: + // + case SENDOBJECTHANDLEREXECUTIONEXCEPTION: + case SENDOBJECTHANDLERTHROWSONDATA: + case SENDOBJECTHANDLERTHROWSONHANDLER: + // + case SENDOBJECTEXECUTIONEXCEPTION: + case SENDOBJECTTHROWS: + // + case SENDTEXTTHROWS: + // + case SENDTEXTHANDLERTHROWSONDATA: + case SENDTEXTHANDLERTHROWSONHANDLER: + // + case POKE: + case TIMEOUT: + // + case SEND_PING: + case SEND_PING_THROWS: + case SEND_PONG_THROWS: + break; + default: + break; + } + } - @Override - public void onMessage(Object o) { - super.onMessage(o); - try { - String msg = o.toString(); - onMessage(msg, session); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } + @Override + public void onMessage(Object o) { + super.onMessage(o); + try { + String msg = o.toString(); + onMessage(msg, session); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingBinaryCoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingBinaryCoder.java index 0e13e9d5b5..5259b96756 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingBinaryCoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingBinaryCoder.java @@ -24,19 +24,19 @@ import jakarta.websocket.EndpointConfig; public class ThrowingBinaryCoder implements Encoder.Binary { - public static final String ERROR = "TCK intended Exception on transmition"; + public static final String ERROR = "TCK intended Exception on transmition"; - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } - @Override - public ByteBuffer encode(ByteBuffer object) throws EncodeException { - throw new EncodeException(object, ERROR); - } + @Override + public ByteBuffer encode(ByteBuffer object) throws EncodeException { + throw new EncodeException(object, ERROR); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingStringBean.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingStringBean.java index 08e13fd83a..1e622bfe13 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingStringBean.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingStringBean.java @@ -17,18 +17,18 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.async; public class ThrowingStringBean { - public static final String ERROR = "TCK Exception thrown to check ExecutionException"; + public static final String ERROR = "TCK Exception thrown to check ExecutionException"; - public String get() { - throw new IllegalStateException(ERROR); - } + public String get() { + throw new IllegalStateException(ERROR); + } - @SuppressWarnings("unused") - public void set(String bean) { - } + @SuppressWarnings("unused") + public void set(String bean) { + } - @Override - public String toString() { - return super.toString() + " to get a value, use get()"; - } + @Override + public String toString() { + return super.toString() + " to get a value, use get()"; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingStringBeanEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingStringBeanEncoder.java index e83507df52..36587dfeea 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingStringBeanEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingStringBeanEncoder.java @@ -23,17 +23,17 @@ public class ThrowingStringBeanEncoder implements Text { - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } - @Override - public String encode(ThrowingStringBean object) throws EncodeException { - return object.get(); - } + @Override + public String encode(ThrowingStringBean object) throws EncodeException { + return object.get(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingTextCoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingTextCoder.java index c616c9f8fa..52054e230f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingTextCoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/ThrowingTextCoder.java @@ -22,19 +22,19 @@ import jakarta.websocket.EndpointConfig; public class ThrowingTextCoder implements Encoder.Text { - public static final String ERROR = "TCK intended Exception on transmition"; + public static final String ERROR = "TCK intended Exception on transmition"; - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } - @Override - public String encode(String object) throws EncodeException { - throw new EncodeException(object, ERROR); - } + @Override + public String encode(String object) throws EncodeException { + throw new EncodeException(object, ERROR); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCOtherSideServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCOtherSideServer.java index 4577e75c49..8a1e2c9411 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCOtherSideServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCOtherSideServer.java @@ -31,28 +31,28 @@ @ServerEndpoint("/client") public class WSCOtherSideServer { - @OnMessage - public String onMessage(PongMessage pong) { - return IOUtil.byteBufferToString(pong.getApplicationData()); - } - - @OnMessage - public String onMessage(String msg) { - return msg; - } - - @OnMessage - public String onMessage(ByteBuffer buffer) { - String msg = IOUtil.byteBufferToString(buffer); - return onMessage(msg); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String onMessage(PongMessage pong) { + return IOUtil.byteBufferToString(pong.getApplicationData()); + } + + @OnMessage + public String onMessage(String msg) { + return msg; + } + + @OnMessage + public String onMessage(ByteBuffer buffer) { + String msg = IOUtil.byteBufferToString(buffer); + return onMessage(msg); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCServerSideServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCServerSideServer.java index 2dea98f908..d49bca606d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCServerSideServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCServerSideServer.java @@ -36,444 +36,436 @@ @ServerEndpoint(value = "/server", encoders = { StringBeanTextEncoder.class }) public class WSCServerSideServer { - static final String[] RESPONSE = { "OK", "FAIL" }; - - static final long SECONDS = 10; - - @OnMessage - public String onMessage(PongMessage pong) { - return IOUtil.byteBufferToString(pong.getApplicationData()); - } - - @OnMessage - public String onMessage(String msg, Session session) { - Async asyncRemote = session.getAsyncRemote(); - OPS op = OPS.valueOf(msg.toUpperCase()); - switch (op) { - case POKE: - // returns msg; - break; - case TIMEOUT: - msg = timeout(asyncRemote); - break; - case SENDBINARY: - msg = sendBinary(asyncRemote); - break; - case SENDBINARYTHROWS: - msg = sendBinaryThrows(asyncRemote); - break; - case SENDBINARYHANDLER: - msg = sendBinaryWithHandler(asyncRemote); - break; - case SENDBINARYHANDLERTHROWSONDATA: - msg = sendBinaryWithHandlerThrowsOnData(asyncRemote); - break; - case SENDBINARYHANDLERTHROWSONHANDLER: - msg = sendBinaryWithHandlerThrowsOnHandler(asyncRemote); - break; - case SENDOBJECT: - msg = sendObject(asyncRemote); - break; - case SENDOBJECT_BOOL: - msg = sendObject(asyncRemote, boolean.class); - break; - case SENDOBJECT_BYTE: - msg = sendObject(asyncRemote, byte.class); - break; - case SENDOBJECT_CHAR: - msg = sendObject(asyncRemote, char.class); - break; - case SENDOBJECT_DOUBLE: - msg = sendObject(asyncRemote, double.class); - break; - case SENDOBJECT_FLOAT: - msg = sendObject(asyncRemote, float.class); - break; - case SENDOBJECT_INT: - msg = sendObject(asyncRemote, int.class); - break; - case SENDOBJECT_LONG: - msg = sendObject(asyncRemote, long.class); - break; - case SENDOBJECT_SHORT: - msg = sendObject(asyncRemote, short.class); - break; - case SENDOBJECTTHROWS: - msg = sendObjectThrows(asyncRemote); - break; - case SENDOBJECTHANDLER: - msg = sendObjectWithHandler(asyncRemote); - break; - case SENDOBJECTHANDLERTHROWSONDATA: - msg = sendObjectWithHandlerThrowsOnData(asyncRemote); - break; - case SENDOBJECTHANDLERTHROWSONHANDLER: - msg = sendObjectWithHandlerThrowsOnHandler(asyncRemote); - break; - case SENDTEXT: - msg = sendText(asyncRemote); - break; - case SENDTEXTTHROWS: - msg = sendTextThrows(asyncRemote); - break; - case SENDTEXTHANDLER: - msg = sendTextWithHandler(asyncRemote); - break; - case SENDTEXTHANDLERTHROWSONDATA: - msg = sendTextWithHandlerThrowsOnData(asyncRemote); - break; - case SENDTEXTHANDLERTHROWSONHANDLER: - msg = sendTextWithHandlerThrowsOnHandler(asyncRemote); - break; - case BATCHING_ALLOWED: - msg = batchingAllowed(asyncRemote); - break; - case SEND_PING: - msg = sendPing(asyncRemote); - break; - case SEND_PING_THROWS: - msg = sendPingThrows(asyncRemote); - break; - case SEND_PONG: - msg = sendPong(asyncRemote); - break; - case SEND_PONG_THROWS: - msg = sendBinaryThrows(asyncRemote); - break; - case IDLE: - session.setMaxIdleTimeout(1500L); - break; - case PING_4_TIMES: - msg = sendPing4times(asyncRemote); - break; - case PONG_4_TIMES: - msg = sendPong4times(asyncRemote); - break; - default: - throw new IllegalArgumentException("Method " + msg + " not implemented"); - } - return msg; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - - /** - * The setSendTimeout() method is not possible to be tested in terms of - * functionality, as there is unfortunately no way guarantee that the timeout - * would be reached regardless the websocket implementation - */ - protected static String timeout(Async asyncRemote) { - boolean set = true; - int timeout = 1; - asyncRemote.setSendTimeout(timeout); - set &= (timeout == asyncRemote.getSendTimeout()); - timeout = 5; - asyncRemote.setSendTimeout(timeout); - set &= (timeout == asyncRemote.getSendTimeout()); - return set ? RESPONSE[0] : RESPONSE[1]; - } - - /** - * Again, since the asynchronous thread sends message in virtually no time, - * one does not have any force to hold that send operation in its thread, to - * check the send operation is really unblocking and asynchronous - * - * @param asyncRemote - * @return - */ - protected static String sendBinary(Async asyncRemote) { - Future future = asyncRemote - .sendBinary(ByteBuffer.wrap(OPS.SENDBINARY.name().getBytes())); - try { - Void v = future.get(); - return v == null ? RESPONSE[0] : RESPONSE[1]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } - - protected static String sendBinaryThrows(Async asyncRemote) { - try { - asyncRemote.sendBinary((ByteBuffer) null); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } - } - - protected static String sendBinaryWithHandler(Async asyncRemote) { - WaitingSendHandler handler = new WaitingSendHandler(); - asyncRemote.sendBinary( - ByteBuffer.wrap(OPS.SENDBINARYHANDLER.name().getBytes()), handler); - SendResult result = handler.waitForResult(SECONDS); - return result.isOK() ? RESPONSE[0] : RESPONSE[1]; - } - - protected static String sendBinaryWithHandlerThrowsOnData(Async asyncRemote) { - try { - asyncRemote.sendBinary((ByteBuffer) null, new WaitingSendHandler()); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } - } - - protected static String sendBinaryWithHandlerThrowsOnHandler( - Async asyncRemote) { - try { - asyncRemote.sendBinary( - ByteBuffer.wrap(OPS.SENDBINARYHANDLERTHROWSONDATA.name().getBytes()), - (WaitingSendHandler) null); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } - } - - protected static String sendObject(Async asyncRemote) { - Future future = asyncRemote - .sendObject(new StringBean(OPS.SENDOBJECT.name())); - try { - Void v = future.get(); - return v == null ? RESPONSE[0] : RESPONSE[1]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } - - protected static String sendObject(Async asyncRemote, Class type) { - try { - Future future = null; - if (type == byte.class) { - byte b = -100; - future = asyncRemote.sendObject(b); - } else if (type == short.class) { - short s = -101; - future = asyncRemote.sendObject(s); - } else if (type == int.class) { - int i = -102; - future = asyncRemote.sendObject(i); - } else if (type == long.class) { - long l = -103L; - future = asyncRemote.sendObject(l); - } else if (type == float.class) { - float f = -104f; - future = asyncRemote.sendObject(f); - } else if (type == double.class) { - double d = -105d; - future = asyncRemote.sendObject(d); - } else if (type == boolean.class) { - boolean b = false; - future = asyncRemote.sendObject(b); - } else if (type == char.class) { - char c = 106; - future = asyncRemote.sendObject(c); - } - @SuppressWarnings("null") // v being null is a bug so we want the NPE in this case - Void v = future.get(); - return v == null ? RESPONSE[0] : RESPONSE[1]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } - - protected static String sendObjectThrows(Async asyncRemote) { - try { - asyncRemote.sendObject((StringBean) null); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } - } - - protected static String sendObjectWithHandler(Async asyncRemote) { - WaitingSendHandler handler = new WaitingSendHandler(); - asyncRemote.sendObject(new StringBean(OPS.SENDOBJECTHANDLER.name()), - handler); - SendResult result = handler.waitForResult(SECONDS); - return result.isOK() ? RESPONSE[0] : RESPONSE[1]; - } - - protected static String sendObjectWithHandlerThrowsOnData(Async asyncRemote) { - try { - asyncRemote.sendObject((Object) null, new WaitingSendHandler()); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } - } - - protected static String sendObjectWithHandlerThrowsOnHandler( - Async asyncRemote) { - try { - OPS op = OPS.SENDOBJECTHANDLERTHROWSONHANDLER; - asyncRemote.sendObject(op, (WaitingSendHandler) null); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } - } - - protected static String sendText(Async asyncRemote) { - Future future = asyncRemote.sendText(OPS.SENDTEXT.name()); - try { - Void v = future.get(); - return v == null ? RESPONSE[0] : RESPONSE[1]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } - - protected static String sendTextThrows(Async asyncRemote) { - try { - asyncRemote.sendText((String) null); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } - } - - protected static String sendTextWithHandler(Async asyncRemote) { - WaitingSendHandler handler = new WaitingSendHandler(); - asyncRemote.sendText(OPS.SENDTEXTHANDLER.name(), handler); - SendResult result = handler.waitForResult(SECONDS); - return result.isOK() ? RESPONSE[0] : RESPONSE[1]; - } - - protected static String sendTextWithHandlerThrowsOnData(Async asyncRemote) { - try { - asyncRemote.sendText((String) null, new WaitingSendHandler()); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } - } - - protected static String sendTextWithHandlerThrowsOnHandler( - Async asyncRemote) { - try { - asyncRemote.sendText(OPS.SENDOBJECTHANDLERTHROWSONHANDLER.name(), - (WaitingSendHandler) null); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } - } - - protected static String batchingAllowed(Async asyncRemote) { - try { - boolean allowed = asyncRemote.getBatchingAllowed(); - asyncRemote.setBatchingAllowed(!allowed); - // now getBatching can be true, or false if not supported - // really there is nothing to test, except that the exception is - // not thrown - asyncRemote.sendText(OPS.BATCHING_ALLOWED.name()); - asyncRemote.flushBatch(); - // If batching is supported then it will currently be enabled. - // Reset it so subsequent messages are not batched causing the - // test to fail. - asyncRemote.setBatchingAllowed(allowed); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } - - protected static String sendPing(Async asyncRemote) { - try { - asyncRemote.sendPing(ByteBuffer.wrap(OPS.SEND_PING.name().getBytes())); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } - - protected static String sendPingThrows(Async asyncRemote) { - try { - asyncRemote.sendPing(ByteBuffer.wrap(generateMessage(126).getBytes())); - return RESPONSE[1]; - } catch (IllegalArgumentException iae) { - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } - - protected static String generateMessage(int length) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i != length; i++) - sb.append(i % 10); - return sb.toString(); - } - - protected static String sendPong(Async asyncRemote) { - try { - asyncRemote.sendPong(ByteBuffer.wrap(OPS.SEND_PONG.name().getBytes())); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } - - protected static String sendPongThrows(Async asyncRemote) { - try { - asyncRemote.sendPong(ByteBuffer.wrap(generateMessage(126).getBytes())); - return RESPONSE[1]; - } catch (IllegalArgumentException iae) { - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } - - protected static String sendPing4times(Async asyncRemote) { - try { - byte[] bytes = OPS.POKE.name().getBytes(); - asyncRemote.sendPing(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - asyncRemote.sendPing(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - asyncRemote.sendPing(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - asyncRemote.sendPing(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } - - protected static String sendPong4times(Async asyncRemote) { - try { - byte[] bytes = OPS.POKE.name().getBytes(); - asyncRemote.sendPong(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - asyncRemote.sendPong(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - asyncRemote.sendPong(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - asyncRemote.sendPong(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + + static final String[] RESPONSE = { "OK", "FAIL" }; + + static final long SECONDS = 10; + + @OnMessage + public String onMessage(PongMessage pong) { + return IOUtil.byteBufferToString(pong.getApplicationData()); + } + + @OnMessage + public String onMessage(String msg, Session session) { + Async asyncRemote = session.getAsyncRemote(); + OPS op = OPS.valueOf(msg.toUpperCase()); + switch (op) { + case POKE: + // returns msg; + break; + case TIMEOUT: + msg = timeout(asyncRemote); + break; + case SENDBINARY: + msg = sendBinary(asyncRemote); + break; + case SENDBINARYTHROWS: + msg = sendBinaryThrows(asyncRemote); + break; + case SENDBINARYHANDLER: + msg = sendBinaryWithHandler(asyncRemote); + break; + case SENDBINARYHANDLERTHROWSONDATA: + msg = sendBinaryWithHandlerThrowsOnData(asyncRemote); + break; + case SENDBINARYHANDLERTHROWSONHANDLER: + msg = sendBinaryWithHandlerThrowsOnHandler(asyncRemote); + break; + case SENDOBJECT: + msg = sendObject(asyncRemote); + break; + case SENDOBJECT_BOOL: + msg = sendObject(asyncRemote, boolean.class); + break; + case SENDOBJECT_BYTE: + msg = sendObject(asyncRemote, byte.class); + break; + case SENDOBJECT_CHAR: + msg = sendObject(asyncRemote, char.class); + break; + case SENDOBJECT_DOUBLE: + msg = sendObject(asyncRemote, double.class); + break; + case SENDOBJECT_FLOAT: + msg = sendObject(asyncRemote, float.class); + break; + case SENDOBJECT_INT: + msg = sendObject(asyncRemote, int.class); + break; + case SENDOBJECT_LONG: + msg = sendObject(asyncRemote, long.class); + break; + case SENDOBJECT_SHORT: + msg = sendObject(asyncRemote, short.class); + break; + case SENDOBJECTTHROWS: + msg = sendObjectThrows(asyncRemote); + break; + case SENDOBJECTHANDLER: + msg = sendObjectWithHandler(asyncRemote); + break; + case SENDOBJECTHANDLERTHROWSONDATA: + msg = sendObjectWithHandlerThrowsOnData(asyncRemote); + break; + case SENDOBJECTHANDLERTHROWSONHANDLER: + msg = sendObjectWithHandlerThrowsOnHandler(asyncRemote); + break; + case SENDTEXT: + msg = sendText(asyncRemote); + break; + case SENDTEXTTHROWS: + msg = sendTextThrows(asyncRemote); + break; + case SENDTEXTHANDLER: + msg = sendTextWithHandler(asyncRemote); + break; + case SENDTEXTHANDLERTHROWSONDATA: + msg = sendTextWithHandlerThrowsOnData(asyncRemote); + break; + case SENDTEXTHANDLERTHROWSONHANDLER: + msg = sendTextWithHandlerThrowsOnHandler(asyncRemote); + break; + case BATCHING_ALLOWED: + msg = batchingAllowed(asyncRemote); + break; + case SEND_PING: + msg = sendPing(asyncRemote); + break; + case SEND_PING_THROWS: + msg = sendPingThrows(asyncRemote); + break; + case SEND_PONG: + msg = sendPong(asyncRemote); + break; + case SEND_PONG_THROWS: + msg = sendBinaryThrows(asyncRemote); + break; + case IDLE: + session.setMaxIdleTimeout(1500L); + break; + case PING_4_TIMES: + msg = sendPing4times(asyncRemote); + break; + case PONG_4_TIMES: + msg = sendPong4times(asyncRemote); + break; + default: + throw new IllegalArgumentException("Method " + msg + " not implemented"); + } + return msg; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + + /** + * The setSendTimeout() method is not possible to be tested in terms of + * functionality, as there is unfortunately no way guarantee that the timeout + * would be reached regardless the websocket implementation + */ + protected static String timeout(Async asyncRemote) { + boolean set = true; + int timeout = 1; + asyncRemote.setSendTimeout(timeout); + set &= (timeout == asyncRemote.getSendTimeout()); + timeout = 5; + asyncRemote.setSendTimeout(timeout); + set &= (timeout == asyncRemote.getSendTimeout()); + return set ? RESPONSE[0] : RESPONSE[1]; + } + + /** + * Again, since the asynchronous thread sends message in virtually no time, one + * does not have any force to hold that send operation in its thread, to check + * the send operation is really unblocking and asynchronous + * + * @param asyncRemote + * @return + */ + protected static String sendBinary(Async asyncRemote) { + Future future = asyncRemote.sendBinary(ByteBuffer.wrap(OPS.SENDBINARY.name().getBytes())); + try { + Void v = future.get(); + return v == null ? RESPONSE[0] : RESPONSE[1]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } + + protected static String sendBinaryThrows(Async asyncRemote) { + try { + asyncRemote.sendBinary((ByteBuffer) null); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } + } + + protected static String sendBinaryWithHandler(Async asyncRemote) { + WaitingSendHandler handler = new WaitingSendHandler(); + asyncRemote.sendBinary(ByteBuffer.wrap(OPS.SENDBINARYHANDLER.name().getBytes()), handler); + SendResult result = handler.waitForResult(SECONDS); + return result.isOK() ? RESPONSE[0] : RESPONSE[1]; + } + + protected static String sendBinaryWithHandlerThrowsOnData(Async asyncRemote) { + try { + asyncRemote.sendBinary((ByteBuffer) null, new WaitingSendHandler()); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } + } + + protected static String sendBinaryWithHandlerThrowsOnHandler(Async asyncRemote) { + try { + asyncRemote.sendBinary(ByteBuffer.wrap(OPS.SENDBINARYHANDLERTHROWSONDATA.name().getBytes()), + (WaitingSendHandler) null); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } + } + + protected static String sendObject(Async asyncRemote) { + Future future = asyncRemote.sendObject(new StringBean(OPS.SENDOBJECT.name())); + try { + Void v = future.get(); + return v == null ? RESPONSE[0] : RESPONSE[1]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } + + protected static String sendObject(Async asyncRemote, Class type) { + try { + Future future = null; + if (type == byte.class) { + byte b = -100; + future = asyncRemote.sendObject(b); + } else if (type == short.class) { + short s = -101; + future = asyncRemote.sendObject(s); + } else if (type == int.class) { + int i = -102; + future = asyncRemote.sendObject(i); + } else if (type == long.class) { + long l = -103L; + future = asyncRemote.sendObject(l); + } else if (type == float.class) { + float f = -104f; + future = asyncRemote.sendObject(f); + } else if (type == double.class) { + double d = -105d; + future = asyncRemote.sendObject(d); + } else if (type == boolean.class) { + boolean b = false; + future = asyncRemote.sendObject(b); + } else if (type == char.class) { + char c = 106; + future = asyncRemote.sendObject(c); + } + @SuppressWarnings("null") // v being null is a bug so we want the NPE in this case + Void v = future.get(); + return v == null ? RESPONSE[0] : RESPONSE[1]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } + + protected static String sendObjectThrows(Async asyncRemote) { + try { + asyncRemote.sendObject((StringBean) null); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } + } + + protected static String sendObjectWithHandler(Async asyncRemote) { + WaitingSendHandler handler = new WaitingSendHandler(); + asyncRemote.sendObject(new StringBean(OPS.SENDOBJECTHANDLER.name()), handler); + SendResult result = handler.waitForResult(SECONDS); + return result.isOK() ? RESPONSE[0] : RESPONSE[1]; + } + + protected static String sendObjectWithHandlerThrowsOnData(Async asyncRemote) { + try { + asyncRemote.sendObject((Object) null, new WaitingSendHandler()); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } + } + + protected static String sendObjectWithHandlerThrowsOnHandler(Async asyncRemote) { + try { + OPS op = OPS.SENDOBJECTHANDLERTHROWSONHANDLER; + asyncRemote.sendObject(op, (WaitingSendHandler) null); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } + } + + protected static String sendText(Async asyncRemote) { + Future future = asyncRemote.sendText(OPS.SENDTEXT.name()); + try { + Void v = future.get(); + return v == null ? RESPONSE[0] : RESPONSE[1]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } + + protected static String sendTextThrows(Async asyncRemote) { + try { + asyncRemote.sendText((String) null); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } + } + + protected static String sendTextWithHandler(Async asyncRemote) { + WaitingSendHandler handler = new WaitingSendHandler(); + asyncRemote.sendText(OPS.SENDTEXTHANDLER.name(), handler); + SendResult result = handler.waitForResult(SECONDS); + return result.isOK() ? RESPONSE[0] : RESPONSE[1]; + } + + protected static String sendTextWithHandlerThrowsOnData(Async asyncRemote) { + try { + asyncRemote.sendText((String) null, new WaitingSendHandler()); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } + } + + protected static String sendTextWithHandlerThrowsOnHandler(Async asyncRemote) { + try { + asyncRemote.sendText(OPS.SENDOBJECTHANDLERTHROWSONHANDLER.name(), (WaitingSendHandler) null); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } + } + + protected static String batchingAllowed(Async asyncRemote) { + try { + boolean allowed = asyncRemote.getBatchingAllowed(); + asyncRemote.setBatchingAllowed(!allowed); + // now getBatching can be true, or false if not supported + // really there is nothing to test, except that the exception is + // not thrown + asyncRemote.sendText(OPS.BATCHING_ALLOWED.name()); + asyncRemote.flushBatch(); + // If batching is supported then it will currently be enabled. + // Reset it so subsequent messages are not batched causing the + // test to fail. + asyncRemote.setBatchingAllowed(allowed); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } + + protected static String sendPing(Async asyncRemote) { + try { + asyncRemote.sendPing(ByteBuffer.wrap(OPS.SEND_PING.name().getBytes())); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } + + protected static String sendPingThrows(Async asyncRemote) { + try { + asyncRemote.sendPing(ByteBuffer.wrap(generateMessage(126).getBytes())); + return RESPONSE[1]; + } catch (IllegalArgumentException iae) { + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } + + protected static String generateMessage(int length) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i != length; i++) + sb.append(i % 10); + return sb.toString(); + } + + protected static String sendPong(Async asyncRemote) { + try { + asyncRemote.sendPong(ByteBuffer.wrap(OPS.SEND_PONG.name().getBytes())); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } + + protected static String sendPongThrows(Async asyncRemote) { + try { + asyncRemote.sendPong(ByteBuffer.wrap(generateMessage(126).getBytes())); + return RESPONSE[1]; + } catch (IllegalArgumentException iae) { + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } + + protected static String sendPing4times(Async asyncRemote) { + try { + byte[] bytes = OPS.POKE.name().getBytes(); + asyncRemote.sendPing(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + asyncRemote.sendPing(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + asyncRemote.sendPing(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + asyncRemote.sendPing(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } + + protected static String sendPong4times(Async asyncRemote) { + try { + byte[] bytes = OPS.POKE.name().getBytes(); + asyncRemote.sendPong(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + asyncRemote.sendPong(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + asyncRemote.sendPong(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + asyncRemote.sendPong(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCThrowingServerSideServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCThrowingServerSideServer.java index 8a37a4937b..3faa6c9b9c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCThrowingServerSideServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSCThrowingServerSideServer.java @@ -34,71 +34,68 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/throwing", encoders = { ThrowingBinaryCoder.class, - ThrowingTextCoder.class, StringBeanTextEncoder.class, - ThrowingStringBeanEncoder.class }) +@ServerEndpoint(value = "/throwing", encoders = { ThrowingBinaryCoder.class, ThrowingTextCoder.class, + StringBeanTextEncoder.class, ThrowingStringBeanEncoder.class }) public class WSCThrowingServerSideServer { - static final String[] RESPONSE = { "OK", "FAIL" }; + static final String[] RESPONSE = { "OK", "FAIL" }; - @OnMessage - public StringBean onMessage(String msg, Session session) { - Async asyncRemote = session.getAsyncRemote(); - OPS op = OPS.valueOf(msg.toUpperCase()); - switch (op) { - case SENDBINARYEXECUTIONEXCEPTION: - msg = sendBinaryHasExecutionException(asyncRemote); - break; - case SENDOBJECTEXECUTIONEXCEPTION: - msg = sendObjectHasExecutionException(asyncRemote); - break; - case SENDOBJECTHANDLEREXECUTIONEXCEPTION: - msg = sendObjectWithSendHandlerHasExecutionException(asyncRemote); - break; - default: - throw new IllegalArgumentException("Method " + msg + " not implemented"); - } - return new StringBean(msg); - } + @OnMessage + public StringBean onMessage(String msg, Session session) { + Async asyncRemote = session.getAsyncRemote(); + OPS op = OPS.valueOf(msg.toUpperCase()); + switch (op) { + case SENDBINARYEXECUTIONEXCEPTION: + msg = sendBinaryHasExecutionException(asyncRemote); + break; + case SENDOBJECTEXECUTIONEXCEPTION: + msg = sendObjectHasExecutionException(asyncRemote); + break; + case SENDOBJECTHANDLEREXECUTIONEXCEPTION: + msg = sendObjectWithSendHandlerHasExecutionException(asyncRemote); + break; + default: + throw new IllegalArgumentException("Method " + msg + " not implemented"); + } + return new StringBean(msg); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } - public static String sendBinaryHasExecutionException(Async asyncRemote) { - Future future = asyncRemote.sendBinary( - ByteBuffer.wrap(OPS.SENDBINARYEXECUTIONEXCEPTION.name().getBytes())); - try { - future.get(); - return RESPONSE[1]; - } catch (ExecutionException e) { - return RESPONSE[0]; - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } + public static String sendBinaryHasExecutionException(Async asyncRemote) { + Future future = asyncRemote + .sendBinary(ByteBuffer.wrap(OPS.SENDBINARYEXECUTIONEXCEPTION.name().getBytes())); + try { + future.get(); + return RESPONSE[1]; + } catch (ExecutionException e) { + return RESPONSE[0]; + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } - public static String sendObjectHasExecutionException(Async asyncRemote) { - Future future = asyncRemote.sendObject(new ThrowingStringBean()); - try { - future.get(); - return RESPONSE[1]; - } catch (ExecutionException e) { - return RESPONSE[0]; - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } + public static String sendObjectHasExecutionException(Async asyncRemote) { + Future future = asyncRemote.sendObject(new ThrowingStringBean()); + try { + future.get(); + return RESPONSE[1]; + } catch (ExecutionException e) { + return RESPONSE[0]; + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } - public static String sendObjectWithSendHandlerHasExecutionException( - Async asyncRemote) { - WaitingSendHandler handler = new WaitingSendHandler(); - asyncRemote.sendObject(new ThrowingStringBean(), handler); - SendResult result = handler.waitForResult(WSCServerSideServer.SECONDS); - return !result.isOK() && result.getException() != null ? RESPONSE[0] - : RESPONSE[1]; - } + public static String sendObjectWithSendHandlerHasExecutionException(Async asyncRemote) { + WaitingSendHandler handler = new WaitingSendHandler(); + asyncRemote.sendObject(new ThrowingStringBean(), handler); + SendResult result = handler.waitForResult(WSCServerSideServer.SECONDS); + return !result.isOK() && result.getException() != null ? RESPONSE[0] : RESPONSE[1]; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSClient.java deleted file mode 100644 index 6e00fd0dba..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSClient.java +++ /dev/null @@ -1,1239 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.async; - -import java.util.LinkedList; -import java.util.List; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.common.client.BinaryAndTextClientEndpoint; -import com.sun.ts.tests.websocket.common.client.ClientEndpoint; -import com.sun.ts.tests.websocket.common.client.EndpointCallback; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.StringPingMessage; -import com.sun.ts.tests.websocket.common.impl.StringPongMessage; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextEncoder; -import com.sun.ts.tests.websocket.common.util.StringUtil; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.PongMessageClientEndpoint; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.Encoder; -import jakarta.websocket.RemoteEndpoint.Async; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 7620798773325933328L; - - static final String[] RESPONSE = WSCServerSideServer.RESPONSE; - - static final String ECHO = "echo"; - - public WSClient() { - setContextRoot("wsc_ee_jakarta_websocket_remoteendpoint_async_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - /* - * @testName: sendTimeoutOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:100; WebSocket:JAVADOC:93; - * WebSocket:JAVADOC:127; - * - * @test_Strategy: setSendTimeOut and getSendTimeout - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendTimeoutOnServerTest() throws Exception { - invoke("server", OPS.TIMEOUT.name(), RESPONSE[0]); - } - - /* - * @testName: sendTimeoutOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:100; WebSocket:JAVADOC:93; - * WebSocket:JAVADOC:127; - * - * @test_Strategy: setSendTimeOut and getSendTimeout - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendTimeoutOnClientTest() throws Exception { - EndpointCallback callback = new AsyncEndpointCallback() { - @Override - void doAsync(Async asyncRemote) throws Exception { - String ret = WSCServerSideServer.timeout(asyncRemote); - assertEquals(RESPONSE[0], ret, - "getSendTimeout did not return what was set by setSendTimeout"); - logMsg("getSendTimeout and setSendTimeout work as expected"); - asyncRemote.sendText(WSClient.this.entity.getEntityAt(String.class, 0)); - } - }; - setClientCallback(callback); - invoke("client", ECHO, ECHO); - } - - /* - * @testName: sendBinaryOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:94; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendBinaryOnServerTest() throws Exception { - sendOnServer(OPS.SENDBINARY); - } - - /* - * @testName: sendBinaryOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:94; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendBinaryOnClientTest() throws Exception { - sendOnClient(OPS.SENDBINARY); - } - - /* - * TODO use when ensured priority of user defined encoder/decoder - * - * @assertion_ids: WebSocket:JAVADOC:94; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * - * public void sendBinaryHasExecutionExceptionOnServerTest() throws Exception { - * setClientEndpoint(BinaryAndTextClientEndpoint.class); invoke("throwing", - * OPS.SENDBINARYEXECUTIONEXCEPTION.name(), RESPONSE[0]); } - */ - - /* - * @testName: sendBinaryThrowsIAEOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:94; - * - * @test_Strategy: Throws: IllegalArgumentException - if the data is null. - */ - public void sendBinaryThrowsIAEOnServerTest() throws Exception { - invoke("server", OPS.SENDBINARYTHROWS.name(), RESPONSE[0]); - } - - /* - * @testName: sendBinaryThrowsIAEOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:94; - * - * @test_Strategy: Throws: IllegalArgumentException - if the data is null. - */ - public void sendBinaryThrowsIAEOnClientTest() throws Exception { - sendOnClientThrows(OPS.SENDBINARYTHROWS); - } - - /* - * @testName: sendBinaryWithHandlerOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:95; WebSocket:JAVADOC:116; - * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.SendHandler.onResult( SendResult ) - * jakarta.websocket.SendResult.SendResult() - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendBinaryWithHandlerOnServerTest() throws Exception { - sendOnServer(OPS.SENDBINARYHANDLER); - } - - /* - * @testName: sendBinaryWithHandlerOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:95; WebSocket:JAVADOC:116; - * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.SendHandler.onResult( SendResult ) - * jakarta.websocket.SendResult.SendResult() - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendBinaryWithHandlerOnClientTest() throws Exception { - sendOnClient(OPS.SENDBINARYHANDLER); - } - - /* - * @testName: sendBinaryWithHandlerThrowsIAEOnServerWhenNullDataTest - * - * @assertion_ids: WebSocket:JAVADOC:95; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendBinaryWithHandlerThrowsIAEOnServerWhenNullDataTest() - throws Exception { - invoke("server", OPS.SENDBINARYHANDLERTHROWSONDATA.name(), RESPONSE[0]); - } - - /* - * @testName: sendBinaryWithHandlerThrowsIAEOnServerWhenNullHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:95; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendBinaryWithHandlerThrowsIAEOnServerWhenNullHandlerTest() - throws Exception { - invoke("server", OPS.SENDBINARYHANDLERTHROWSONHANDLER.name(), RESPONSE[0]); - } - - /* - * @testName: sendBinaryWithHandlerThrowsIAEOnClientWhenNullDataTest - * - * @assertion_ids: WebSocket:JAVADOC:95; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendBinaryWithHandlerThrowsIAEOnClientWhenNullDataTest() - throws Exception { - sendOnClientThrows(OPS.SENDBINARYHANDLERTHROWSONDATA); - } - - /* - * @testName: sendBinaryWithHandlerThrowsIAEOnClientWhenNullHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:95; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendBinaryWithHandlerThrowsIAEOnClientWhenNullHandlerTest() - throws Exception { - sendOnClientThrows(OPS.SENDBINARYHANDLERTHROWSONHANDLER); - } - - /* - * @testName: sendObjectOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT); - } - - /* - * @testName: sendObjectOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT); - } - - /* - * @testName: sendObjectBooleanOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectBooleanOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_BOOL, false); - } - - /* - * @testName: sendObjectBooleanOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectBooleanOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_BOOL, String.valueOf(false)); - } - - /* - * @testName: sendObjectByteOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectByteOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_BYTE, -100); - } - - /* - * @testName: sendObjectByteOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectByteOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_BYTE, "-100"); - } - - /* - * @testName: sendObjectCharOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents - */ - public void sendObjectCharOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_CHAR, String.valueOf((char) 106)); - } - - /* - * @testName: sendObjectCharOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectCharOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_CHAR, String.valueOf((char) 106)); - } - - /* - * @testName: sendObjectDoubleOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectDoubleOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_DOUBLE, -105d); - } - - /* - * @testName: sendObjectDoubleOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectDoubleOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_DOUBLE, "-105"); - } - - /* - * @testName: sendObjectFloatOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectFloatOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_FLOAT, -104f); - } - - /* - * @testName: sendObjectFloatOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectFloatOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_FLOAT, "-104"); - } - - /* - * @testName: sendObjectIntOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectIntOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_INT, -102); - } - - /* - * @testName: sendObjectIntOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectIntOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_INT, "-102"); - } - - /* - * @testName: sendObjectLongOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectLongOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_LONG, -103L); - } - - /* - * @testName: sendObjectLongOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectLongOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_LONG, "-103"); - } - - /* - * @testName: sendObjectShortOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectShortOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_SHORT, -101); - } - - /* - * @testName: sendObjectShortOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; - * - * @test_Strategy: Containers will by default be able to encode java primitive - * types and their object equivalents jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectShortOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_SHORT, "-101"); - } - - /* - * @testName: sendObjectThrowsIAEOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; - * - * @test_Strategy: Throws: IllegalArgumentException - if the data is null. - */ - public void sendObjectThrowsIAEOnServerTest() throws Exception { - invoke("server", OPS.SENDOBJECTTHROWS.name(), RESPONSE[0]); - } - - /* - * @testName: sendObjectThrowsIAEOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; - * - * @test_Strategy: Throws: IllegalArgumentException - if the data is null. - */ - public void sendObjectThrowsIAEOnClientTest() throws Exception { - sendOnClientThrows(OPS.SENDOBJECTTHROWS); - } - - /* - * @testName: sendObjectHasExecutionExceptionOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; - * - * @test_Strategy: Errors in transmission are wrapped in the - * ExecutionException thrown when querying the Future object. - */ - public void sendObjectHasExecutionExceptionOnServerTest() throws Exception { - setClientEndpoint(BinaryAndTextClientEndpoint.class); - invoke("throwing", OPS.SENDOBJECTEXECUTIONEXCEPTION.name(), RESPONSE[0]); - } - - /* - * @testName: sendObjectHasExecutionExceptionOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; - * - * @test_Strategy: Errors in transmission are wrapped in the - * ExecutionException thrown when querying the Future object. - */ - public void sendObjectHasExecutionExceptionOnClientTest() throws Exception { - sendOnClientHasExecutionException(OPS.SENDOBJECTEXECUTIONEXCEPTION); - } - - /* - * @testName: sendObjectWithHandlerOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:116; - * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.SendHandler.onResult( SendResult ) - * jakarta.websocket.SendHandler.SendHandler() - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectWithHandlerOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECTHANDLER); - } - - /* - * @testName: sendObjectWithHandlerOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:116; - * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.SendHandler.onResult( SendResult ) - * jakarta.websocket.SendHandler.SendHandler() - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendObjectWithHandlerOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECTHANDLER); - } - - /* - * @testName: sendObjectWithHandlerThrowsIAEOnServerWhenDataIsNullTest - * - * @assertion_ids: WebSocket:JAVADOC:97; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendObjectWithHandlerThrowsIAEOnServerWhenDataIsNullTest() - throws Exception { - invoke("server", OPS.SENDOBJECTHANDLERTHROWSONDATA.name(), RESPONSE[0]); - } - - /* - * @testName: sendObjectWithHandlerThrowsIAEOnServerWhenHandlerIsNullTest - * - * @assertion_ids: WebSocket:JAVADOC:97; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendObjectWithHandlerThrowsIAEOnServerWhenHandlerIsNullTest() - throws Exception { - invoke("server", OPS.SENDOBJECTHANDLERTHROWSONHANDLER.name(), RESPONSE[0]); - } - - /* - * @testName: sendObjectWithHandlerThrowsIAEOnClientWhenDataIsNullTest - * - * @assertion_ids: WebSocket:JAVADOC:97; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendObjectWithHandlerThrowsIAEOnClientWhenDataIsNullTest() - throws Exception { - sendOnClientThrows(OPS.SENDOBJECTHANDLERTHROWSONDATA); - } - - /* - * @testName: sendObjectWithHandlerThrowsIAEOnClientWhenHandlerIsNullTest - * - * @assertion_ids: WebSocket:JAVADOC:97; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendObjectWithHandlerThrowsIAEOnClientWhenHandlerIsNullTest() - throws Exception { - sendOnClientThrows(OPS.SENDOBJECTHANDLERTHROWSONHANDLER); - } - - /* - * @testName: sendObjectWithHandlerHasExceptionOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:116; - * WebSocket:JAVADOC:117; WebSocket:JAVADOC:118; WebSocket:JAVADOC:119; - * - * @test_Strategy: Check SendHandler#getException && SendHandler#isOk - * SendResult.SendResult( Throwable ) - */ - public void sendObjectWithHandlerHasExceptionOnServerTest() throws Exception { - setClientEndpoint(BinaryAndTextClientEndpoint.class); - invoke("throwing", OPS.SENDOBJECTHANDLEREXECUTIONEXCEPTION.name(), - RESPONSE[0]); - } - - /* - * @testName: sendObjectWithHandlerHasExecutionExceptionOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:116; - * WebSocket:JAVADOC:117; WebSocket:JAVADOC:118; WebSocket:JAVADOC:119; - * - * @test_Strategy: Check SendHandler#getException && SendHandler#isOk - * SendResult.SendResult( Throwable ) - */ - public void sendObjectWithHandlerHasExecutionExceptionOnClientTest() - throws Exception { - sendOnClientHasExecutionException(OPS.SENDOBJECTHANDLEREXECUTIONEXCEPTION); - } - - /* - * @testName: sendTextOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:99; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendTextOnServerTest() throws Exception { - sendOnServer(OPS.SENDTEXT); - } - - /* - * @testName: sendTextOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:99; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendTextOnClientTest() throws Exception { - sendOnClient(OPS.SENDTEXT); - } - - /* - * @testName: sendTextThrowsIAEOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:99; - * - * @test_Strategy: Throws: IllegalArgumentException - if the data is null. - */ - public void sendTextThrowsIAEOnServerTest() throws Exception { - invoke("server", OPS.SENDTEXTTHROWS.name(), RESPONSE[0]); - } - - /* - * @testName: sendTextThrowsIAEOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:99; - * - * @test_Strategy: Throws: IllegalArgumentException - if the data is null. - */ - public void sendTextThrowsIAEOnClientTest() throws Exception { - sendOnClientThrows(OPS.SENDTEXTTHROWS); - } - - /* - * @testName: sendTextWithHandlerOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:98; WebSocket:JAVADOC:116; - * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.SendHandler.onResult( SendResult ) - * jakarta.websocket.SendHandler.SendHandler() - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendTextWithHandlerOnServerTest() throws Exception { - sendOnServer(OPS.SENDTEXTHANDLER); - } - - /* - * @testName: sendTextWithHandlerOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:98; WebSocket:JAVADOC:116; - * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; - * - * @test_Strategy: Initiates the asynchronous transmission of a binary - * message. The Future's get() method returns null upon successful completion. - * jakarta.websocket.SendHandler.onResult( SendResult ) - * jakarta.websocket.SendHandler.SendHandler() - * jakarta.websocket.Session.getAsyncRemote - */ - public void sendTextWithHandlerOnClientTest() throws Exception { - sendOnClient(OPS.SENDTEXTHANDLER); - } - - /* - * @testName: sendTextWithHandlerThrowsIAEOnServerWhenDataIsNullTest - * - * @assertion_ids: WebSocket:JAVADOC:98; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendTextWithHandlerThrowsIAEOnServerWhenDataIsNullTest() - throws Exception { - invoke("server", OPS.SENDTEXTHANDLERTHROWSONDATA.name(), RESPONSE[0]); - } - - /* - * @testName: sendTextWithHandlerThrowsIAEOnServerWhenHandlerIsNullTest - * - * @assertion_ids: WebSocket:JAVADOC:98; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendTextWithHandlerThrowsIAEOnServerWhenHandlerIsNullTest() - throws Exception { - invoke("server", OPS.SENDTEXTHANDLERTHROWSONHANDLER.name(), RESPONSE[0]); - } - - /* - * @testName: sendTextWithHandlerThrowsIAEOnClientWhenDataIsNullTest - * - * @assertion_ids: WebSocket:JAVADOC:98; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendTextWithHandlerThrowsIAEOnClientWhenDataIsNullTest() - throws Exception { - sendOnClientThrows(OPS.SENDTEXTHANDLERTHROWSONDATA); - } - - /* - * @testName: sendTextWithHandlerThrowsIAEOnClientWhenHandlerIsNullTest - * - * @assertion_ids: WebSocket:JAVADOC:98; - * - * @test_Strategy: Throws: IllegalArgumentException - if either the data or - * the handler are null. - */ - public void sendTextWithHandlerThrowsIAEOnClientWhenHandlerIsNullTest() - throws Exception { - sendOnClientThrows(OPS.SENDTEXTHANDLERTHROWSONHANDLER); - } - - // ------------------------------------------------------------------------ - /* - * @testName: batchingAllowedOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:84;WebSocket:JAVADOC:91; - * - * @test_Strategy: calls setBatchingAllowed(!getBatchingAllowed()) and checks - * no exception is thrown - */ - public void batchingAllowedOnServerTest() throws Exception { - sendOnServer(OPS.BATCHING_ALLOWED); - } - - /* - * @testName: batchingAllowedOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:84;WebSocket:JAVADOC:91; - * - * @test_Strategy: calls setBatchingAllowed(!getBatchingAllowed()) and checks - * no exception is thrown - */ - public void batchingAllowedOnClientTest() throws Exception { - sendOnClient(OPS.BATCHING_ALLOWED); - } - - /* - * @testName: sendPingOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:85; WebSocket:SPEC:WSC-2.2.5-1; - * WebSocket:SPEC:WSC-2.2.5-2; - * - * @test_Strategy: Send a Ping message containing the given application data - * to the remote endpoint. The corresponding Pong message may be picked up - * using the MessageHandler.Pong handler - */ - public void sendPingOnServerTest() throws Exception { - setCountDownLatchCount(2); - setProperty(Property.CONTENT, OPS.SEND_PING.name()); - setProperty(Property.REQUEST, buildRequest("server")); - // first server sends ping, websocket impl responses with pong - // then server sends ok and the pong is caught back on server - // and pong data are send back to client - setProperty(Property.UNORDERED_SEARCH_STRING, - search(RESPONSE[0], OPS.SEND_PING)); - invoke(); - } - - /* - * @testName: sendPingOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:85; - * - * @test_Strategy: Send a Ping message containing the given application data - * to the remote endpoint. The corresponding Pong message may be picked up - * using the MessageHandler.Pong handler - */ - public void sendPingOnClientTest() throws Exception { - setClientEndpoint(PongMessageClientEndpoint.class); - sendOnClient(OPS.SEND_PING); - } - - /* - * @testName: sendPingDelaysTimoutOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:85; WebSocket:SPEC:WSC-2.2.5-1; - * WebSocket:SPEC:WSC-2.2.5-2; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - * - * if a websocket implementation receives a ping message from a peer, it must - * respond as soon as possible to that peer with a pong message containing the - * same application data. - * - * if the implementation receives a pong message addressed to this endpoint, - * it must call that MessageHandler or that annotated message - */ - public void sendPingDelaysTimoutOnServerTest() throws Exception { - StringPingMessage ping = new StringPingMessage(OPS.POKE.name()); - setClientEndpoint(PongMessageClientEndpoint.class); - invoke("server", OPS.IDLE.name(), OPS.IDLE.name(), false); - - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - - invokeAgain(OPS.POKE.name(), OPS.POKE.name(), true); - } - - /* - * @testName: sendPingDelaysTimoutOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:85; WebSocket:SPEC:WSC-2.2.5-1; - * WebSocket:SPEC:WSC-2.2.5-2; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - * - * if a websocket implementation receives a ping message from a peer, it must - * respond as soon as possible to that peer with a pong message containing the - * same application data. - * - * if the implementation receives a pong message addressed to this endpoint, - * it must call that MessageHandler or that annotated message - */ - public void sendPingDelaysTimoutOnClientTest() throws Exception { - setClientEndpoint(PongMessageClientEndpoint.class); - invoke("server", OPS.POKE.name(), OPS.POKE.name(), false); - getSession().setMaxIdleTimeout(1500L); - - setCountDownLatchCount(5); - setProperty(Property.CONTENT, OPS.PING_4_TIMES.name()); - setProperty(Property.SEARCH_STRING, OPS.POKE.name(), OPS.POKE.name(), - OPS.POKE.name(), OPS.POKE.name()); - setProperty(Property.SEARCH_STRING_IGNORE_CASE); - setProperty(Property.SEARCH_STRING_IGNORE_CASE, RESPONSE[0]); - invokeAgain(true); - } - - /* - * @testName: sendPingThrowsOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:87; - * - * @test_Strategy: throws IllegalArgumentException - if the applicationData - * exceeds the maximum allowed payload of 125 bytes - */ - public void sendPingThrowsOnServerTest() throws Exception { - invoke("server", OPS.SEND_PING_THROWS, RESPONSE[0]); - } - - /* - * @testName: sendPingThrowsOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:87; - * - * @test_Strategy: throws IllegalArgumentException - if the applicationData - * exceeds the maximum allowed payload of 125 bytes - */ - public void sendPingThrowsOnClientTest() throws Exception { - sendOnClientThrows(OPS.SEND_PING_THROWS); - } - - /* - * @testName: sendPongOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:88; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - */ - public void sendPongOnServerTest() throws Exception { - sendOnServer(OPS.SEND_PONG, OPS.SEND_PONG.name(), - PongMessageClientEndpoint.class); - } - - /* - * @testName: sendPongOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:88; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - */ - public void sendPongOnClientTest() throws Exception { - sendOnClient(OPS.SEND_PONG); - } - - /* - * @testName: sendPongDelaysTimoutOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:88; WebSocket:SPEC:WSC-2.2.5-2; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - * - * if the implementation receives a pong message addressed to this endpoint, - * it must call that MessageHandler or that annotated message - */ - public void sendPongDelaysTimoutOnServerTest() throws Exception { - StringPongMessage ping = new StringPongMessage(OPS.POKE.name()); - setClientEndpoint(PongMessageClientEndpoint.class); - invoke("server", OPS.IDLE.name(), OPS.IDLE.name(), false); - - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - - invokeAgain(OPS.POKE.name(), OPS.POKE.name(), true); - } - - /* - * @testName: sendPongDelaysTimoutOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:88; WebSocket:SPEC:WSC-2.2.5-2; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - * - * if the implementation receives a pong message addressed to this endpoint, - * it must call that MessageHandler or that annotated message - */ - public void sendPongDelaysTimoutOnClientTest() throws Exception { - setClientEndpoint(PongMessageClientEndpoint.class); - invoke("server", OPS.POKE.name(), OPS.POKE.name(), false); - getSession().setMaxIdleTimeout(1500L); - - setCountDownLatchCount(5); - setProperty(Property.CONTENT, OPS.PONG_4_TIMES.name()); - setProperty(Property.SEARCH_STRING, OPS.POKE.name(), OPS.POKE.name(), - OPS.POKE.name(), OPS.POKE.name()); - setProperty(Property.SEARCH_STRING_IGNORE_CASE); - setProperty(Property.SEARCH_STRING_IGNORE_CASE, RESPONSE[0]); - invokeAgain(true); - } - - /* - * @testName: sendPongThrowsOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:90; - * - * @test_Strategy: throws IllegalArgumentException - if the applicationData - * exceeds the maximum allowed payload of 125 bytes - */ - public void sendPongThrowsOnServerTest() throws Exception { - invoke("server", OPS.SEND_PONG_THROWS, RESPONSE[0]); - } - - /* - * @testName: sendPongThrowsOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:90; - * - * @test_Strategy: throws IllegalArgumentException - if the applicationData - * exceeds the maximum allowed payload of 125 bytes - */ - public void sendPongThrowsOnClientTest() throws Exception { - sendOnClientThrows(OPS.SEND_PONG_THROWS); - } - - // ///////////////////////////////////////////////////////////////////////// - private String search(Object... ops) { - return StringUtil.objectsToStringWithDelimiter("|", (Object[]) ops); - } - - private void sendOnServer(OPS ops) throws Exception { - sendOnServer(ops, ops); - } - - private void sendOnServer(OPS ops, Object search) throws Exception { - sendOnServer(ops, search, BinaryAndTextClientEndpoint.class); - } - - private void sendOnServer(OPS ops, Object search, - Class> endpoint) throws Exception { - setCountDownLatchCount(3); - setProperty(Property.CONTENT, ops.name()); - setProperty(Property.REQUEST, buildRequest("server")); - setProperty(Property.UNORDERED_SEARCH_STRING, - search(search, OPS.POKE, RESPONSE[0])); - PokingEndpointCallback callback = new PokingEndpointCallback(entity); - setClientCallback(callback); - setClientEndpoint(endpoint); - invoke(); - } - - private void sendOnClient(final OPS op) throws Exception { - sendOnClient(op, op.name()); - } - - private void sendOnClient(final OPS op, String search) throws Exception { - EndpointCallback callback = new AsyncEndpointCallback() { - @Override - void doAsync(Async asyncRemote) throws Exception { - String ret = null; - String method = null; - switch (op) { - case SENDBINARY: - ret = WSCServerSideServer.sendBinary(asyncRemote); - method = "sendBinary(ByteBuffer)"; - break; - case SENDBINARYHANDLER: - ret = WSCServerSideServer.sendBinaryWithHandler(asyncRemote); - method = "sendBinary(ByteBuffer, SendHandler)"; - break; - case SENDOBJECT: - ret = WSCServerSideServer.sendObject(asyncRemote); - method = "sendObject(Object)"; - break; - case SENDOBJECTHANDLER: - ret = WSCServerSideServer.sendObjectWithHandler(asyncRemote); - method = "sendObject(Object, SendHandler)"; - break; - case SENDOBJECT_BOOL: - ret = WSCServerSideServer.sendObject(asyncRemote, boolean.class); - method = "sendObject(boolean)"; - break; - case SENDOBJECT_BYTE: - ret = WSCServerSideServer.sendObject(asyncRemote, byte.class); - method = "sendObject(byte)"; - break; - case SENDOBJECT_CHAR: - ret = WSCServerSideServer.sendObject(asyncRemote, char.class); - method = "sendObject(char)"; - break; - case SENDOBJECT_DOUBLE: - ret = WSCServerSideServer.sendObject(asyncRemote, double.class); - method = "sendObject(double)"; - break; - case SENDOBJECT_FLOAT: - ret = WSCServerSideServer.sendObject(asyncRemote, float.class); - method = "sendObject(float)"; - break; - case SENDOBJECT_INT: - ret = WSCServerSideServer.sendObject(asyncRemote, int.class); - method = "sendObject(int)"; - break; - case SENDOBJECT_LONG: - ret = WSCServerSideServer.sendObject(asyncRemote, long.class); - method = "sendObject(long)"; - break; - case SENDOBJECT_SHORT: - ret = WSCServerSideServer.sendObject(asyncRemote, short.class); - method = "sendObject(short)"; - break; - case SENDTEXT: - ret = WSCServerSideServer.sendText(asyncRemote); - method = "sendText(String)"; - break; - case SENDTEXTHANDLER: - ret = WSCServerSideServer.sendTextWithHandler(asyncRemote); - method = "sendText(String, SendHandler)"; - break; - case BATCHING_ALLOWED: - ret = WSCServerSideServer.batchingAllowed(asyncRemote); - method = "setBatchingAllowed(!getBatchingAllowed)"; - break; - case SEND_PING: - ret = WSCServerSideServer.sendPing(asyncRemote); - method = "sendPing(ByteBuffer)"; - break; - case SEND_PONG: - ret = WSCServerSideServer.sendPong(asyncRemote); - method = "sendPong(ByteBuffer)"; - break; - default: - fault("Method", op, "not implemented"); - } - assertEquals(RESPONSE[0], ret, method, "did not endup as expected"); - logMsg(method, "works as expected"); - } - }; - setClientCallback(callback); - - // Add StringBean encoder just for sendObject methods - List> list = new LinkedList<>(); - list.add(StringBeanTextEncoder.class); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .encoders(list).build(); - setClientEndpointConfig(config); - - invoke("client", "anything", search); - } - - private void sendOnClientHasExecutionException(final OPS op) throws Exception { - EndpointCallback callback = new AsyncEndpointCallback() { - @Override - void doAsync(Async asyncRemote) throws Exception { - String ret = null; - String method = null; - switch (op) { - case SENDOBJECTEXECUTIONEXCEPTION: - ret = WSCThrowingServerSideServer - .sendObjectHasExecutionException(asyncRemote); - method = "sendObject(Object)"; - break; - case SENDOBJECTHANDLEREXECUTIONEXCEPTION: - ret = WSCThrowingServerSideServer - .sendObjectWithSendHandlerHasExecutionException(asyncRemote); - method = "sendObject(Object, SendHandler)"; - break; - default: - fault("Method", op, "not implemented"); - } - assertEquals(RESPONSE[0], ret, method, - "did not endup with ExecutionException"); - logMsg(method, "end up with ExecutionException as expected"); - asyncRemote.sendText(entity.getEntityAt(String.class, 0)); - } - }; - setClientCallback(callback); - - // Add StringBean encoder just for sendObject methods - List> list = new LinkedList<>(); - list.add(ThrowingStringBeanEncoder.class); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .encoders(list).build(); - setClientEndpointConfig(config); - - invoke("client", ECHO, ECHO); - } - - private void sendOnClientThrows(final OPS op) throws Exception { - EndpointCallback callback = new AsyncEndpointCallback() { - @Override - void doAsync(Async asyncRemote) throws Exception { - String ret = null; - String method = null; - switch (op) { - case SENDBINARYTHROWS: - ret = WSCServerSideServer.sendBinaryThrows(asyncRemote); - method = "sendBinary(ByteBuffer)"; - break; - case SENDBINARYHANDLERTHROWSONDATA: - ret = WSCServerSideServer - .sendBinaryWithHandlerThrowsOnData(asyncRemote); - method = "sendBinary(ByteBuffer, SendHandler)"; - break; - case SENDBINARYHANDLERTHROWSONHANDLER: - ret = WSCServerSideServer - .sendBinaryWithHandlerThrowsOnHandler(asyncRemote); - method = "sendBinary(ByteBuffer, SendHandler)"; - break; - case SENDOBJECTTHROWS: - ret = WSCServerSideServer.sendObjectThrows(asyncRemote); - method = "sendObject(Object)"; - break; - case SENDOBJECTHANDLERTHROWSONDATA: - ret = WSCServerSideServer - .sendObjectWithHandlerThrowsOnData(asyncRemote); - method = "sendObject(Object, SendHandler)"; - break; - case SENDOBJECTHANDLERTHROWSONHANDLER: - ret = WSCServerSideServer - .sendObjectWithHandlerThrowsOnHandler(asyncRemote); - method = "sendObject(object, SendHandler)"; - break; - case SENDTEXTTHROWS: - ret = WSCServerSideServer.sendTextThrows(asyncRemote); - method = "sendText(String)"; - break; - case SENDTEXTHANDLERTHROWSONDATA: - ret = WSCServerSideServer - .sendTextWithHandlerThrowsOnData(asyncRemote); - method = "sendText(String, SendHandler)"; - break; - case SENDTEXTHANDLERTHROWSONHANDLER: - ret = WSCServerSideServer - .sendTextWithHandlerThrowsOnHandler(asyncRemote); - method = "sendText(String, SendHandler)"; - break; - case SEND_PING_THROWS: - ret = WSCServerSideServer.sendPingThrows(asyncRemote); - method = "sendPing()"; - break; - case SEND_PONG_THROWS: - ret = WSCServerSideServer.sendPongThrows(asyncRemote); - method = "sendPong()"; - break; - default: - fault("Method", op, "not implemented"); - } - assertEquals(RESPONSE[0], ret, method, - "does not throw IllegalArgumentException as expected"); - logMsg(method, "throws IllegalArgumentException as expected"); - asyncRemote.sendText(entity.getEntityAt(String.class, 0)); - } - }; - setClientCallback(callback); - invoke("client", ECHO, ECHO); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSClientIT.java new file mode 100644 index 0000000000..1e66cece31 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/async/WSClientIT.java @@ -0,0 +1,1292 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.async; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.client.BinaryAndTextClientEndpoint; +import com.sun.ts.tests.websocket.common.client.ClientEndpoint; +import com.sun.ts.tests.websocket.common.client.EndpointCallback; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.StringPingMessage; +import com.sun.ts.tests.websocket.common.impl.StringPongMessage; +import com.sun.ts.tests.websocket.common.impl.WaitingSendHandler; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextEncoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.common.util.StringUtil; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.PongMessageClientEndpoint; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.Encoder; +import jakarta.websocket.RemoteEndpoint.Async; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 7620798773325933328L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_ee_jakarta_websocket_remoteendpoint_async_web.war"); + archive.addPackages(true, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.async"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(WaitingSendHandler.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + static final String[] RESPONSE = WSCServerSideServer.RESPONSE; + + static final String ECHO = "echo"; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_jakarta_websocket_remoteendpoint_async_web"); + } + + /* Run test */ + + /* + * @testName: sendTimeoutOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:100; WebSocket:JAVADOC:93; + * WebSocket:JAVADOC:127; + * + * @test_Strategy: setSendTimeOut and getSendTimeout + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendTimeoutOnServerTest() throws Exception { + invoke("server", OPS.TIMEOUT.name(), RESPONSE[0]); + } + + /* + * @testName: sendTimeoutOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:100; WebSocket:JAVADOC:93; + * WebSocket:JAVADOC:127; + * + * @test_Strategy: setSendTimeOut and getSendTimeout + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendTimeoutOnClientTest() throws Exception { + EndpointCallback callback = new AsyncEndpointCallback() { + @Override + void doAsync(Async asyncRemote) throws Exception { + String ret = WSCServerSideServer.timeout(asyncRemote); + assertEquals(RESPONSE[0], ret, "getSendTimeout did not return what was set by setSendTimeout"); + logMsg("getSendTimeout and setSendTimeout work as expected"); + asyncRemote.sendText(WSClientIT.this.entity.getEntityAt(String.class, 0)); + } + }; + setClientCallback(callback); + invoke("client", ECHO, ECHO); + } + + /* + * @testName: sendBinaryOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:94; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendBinaryOnServerTest() throws Exception { + sendOnServer(OPS.SENDBINARY); + } + + /* + * @testName: sendBinaryOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:94; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendBinaryOnClientTest() throws Exception { + sendOnClient(OPS.SENDBINARY); + } + + /* + * TODO use when ensured priority of user defined encoder/decoder + * + * @assertion_ids: WebSocket:JAVADOC:94; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * + * public void sendBinaryHasExecutionExceptionOnServerTest() throws Exception { + * setClientEndpoint(BinaryAndTextClientEndpoint.class); invoke("throwing", + * OPS.SENDBINARYEXECUTIONEXCEPTION.name(), RESPONSE[0]); } + */ + + /* + * @testName: sendBinaryThrowsIAEOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:94; + * + * @test_Strategy: Throws: IllegalArgumentException - if the data is null. + */ + @Test + public void sendBinaryThrowsIAEOnServerTest() throws Exception { + invoke("server", OPS.SENDBINARYTHROWS.name(), RESPONSE[0]); + } + + /* + * @testName: sendBinaryThrowsIAEOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:94; + * + * @test_Strategy: Throws: IllegalArgumentException - if the data is null. + */ + @Test + public void sendBinaryThrowsIAEOnClientTest() throws Exception { + sendOnClientThrows(OPS.SENDBINARYTHROWS); + } + + /* + * @testName: sendBinaryWithHandlerOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:95; WebSocket:JAVADOC:116; + * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.SendHandler.onResult( SendResult ) + * jakarta.websocket.SendResult.SendResult() + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendBinaryWithHandlerOnServerTest() throws Exception { + sendOnServer(OPS.SENDBINARYHANDLER); + } + + /* + * @testName: sendBinaryWithHandlerOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:95; WebSocket:JAVADOC:116; + * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.SendHandler.onResult( SendResult ) + * jakarta.websocket.SendResult.SendResult() + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendBinaryWithHandlerOnClientTest() throws Exception { + sendOnClient(OPS.SENDBINARYHANDLER); + } + + /* + * @testName: sendBinaryWithHandlerThrowsIAEOnServerWhenNullDataTest + * + * @assertion_ids: WebSocket:JAVADOC:95; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendBinaryWithHandlerThrowsIAEOnServerWhenNullDataTest() throws Exception { + invoke("server", OPS.SENDBINARYHANDLERTHROWSONDATA.name(), RESPONSE[0]); + } + + /* + * @testName: sendBinaryWithHandlerThrowsIAEOnServerWhenNullHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:95; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendBinaryWithHandlerThrowsIAEOnServerWhenNullHandlerTest() throws Exception { + invoke("server", OPS.SENDBINARYHANDLERTHROWSONHANDLER.name(), RESPONSE[0]); + } + + /* + * @testName: sendBinaryWithHandlerThrowsIAEOnClientWhenNullDataTest + * + * @assertion_ids: WebSocket:JAVADOC:95; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendBinaryWithHandlerThrowsIAEOnClientWhenNullDataTest() throws Exception { + sendOnClientThrows(OPS.SENDBINARYHANDLERTHROWSONDATA); + } + + /* + * @testName: sendBinaryWithHandlerThrowsIAEOnClientWhenNullHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:95; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendBinaryWithHandlerThrowsIAEOnClientWhenNullHandlerTest() throws Exception { + sendOnClientThrows(OPS.SENDBINARYHANDLERTHROWSONHANDLER); + } + + /* + * @testName: sendObjectOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT); + } + + /* + * @testName: sendObjectOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT); + } + + /* + * @testName: sendObjectBooleanOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectBooleanOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_BOOL, false); + } + + /* + * @testName: sendObjectBooleanOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectBooleanOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_BOOL, String.valueOf(false)); + } + + /* + * @testName: sendObjectByteOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectByteOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_BYTE, -100); + } + + /* + * @testName: sendObjectByteOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectByteOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_BYTE, "-100"); + } + + /* + * @testName: sendObjectCharOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents + */ + @Test + public void sendObjectCharOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_CHAR, String.valueOf((char) 106)); + } + + /* + * @testName: sendObjectCharOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectCharOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_CHAR, String.valueOf((char) 106)); + } + + /* + * @testName: sendObjectDoubleOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectDoubleOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_DOUBLE, -105d); + } + + /* + * @testName: sendObjectDoubleOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectDoubleOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_DOUBLE, "-105"); + } + + /* + * @testName: sendObjectFloatOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectFloatOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_FLOAT, -104f); + } + + /* + * @testName: sendObjectFloatOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectFloatOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_FLOAT, "-104"); + } + + /* + * @testName: sendObjectIntOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectIntOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_INT, -102); + } + + /* + * @testName: sendObjectIntOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectIntOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_INT, "-102"); + } + + /* + * @testName: sendObjectLongOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectLongOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_LONG, -103L); + } + + /* + * @testName: sendObjectLongOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectLongOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_LONG, "-103"); + } + + /* + * @testName: sendObjectShortOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectShortOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_SHORT, -101); + } + + /* + * @testName: sendObjectShortOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:127; + * + * @test_Strategy: Containers will by default be able to encode java primitive + * types and their object equivalents jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectShortOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_SHORT, "-101"); + } + + /* + * @testName: sendObjectThrowsIAEOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; + * + * @test_Strategy: Throws: IllegalArgumentException - if the data is null. + */ + @Test + public void sendObjectThrowsIAEOnServerTest() throws Exception { + invoke("server", OPS.SENDOBJECTTHROWS.name(), RESPONSE[0]); + } + + /* + * @testName: sendObjectThrowsIAEOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; + * + * @test_Strategy: Throws: IllegalArgumentException - if the data is null. + */ + @Test + public void sendObjectThrowsIAEOnClientTest() throws Exception { + sendOnClientThrows(OPS.SENDOBJECTTHROWS); + } + + /* + * @testName: sendObjectHasExecutionExceptionOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; + * + * @test_Strategy: Errors in transmission are wrapped in the ExecutionException + * thrown when querying the Future object. + */ + @Test + public void sendObjectHasExecutionExceptionOnServerTest() throws Exception { + setClientEndpoint(BinaryAndTextClientEndpoint.class); + invoke("throwing", OPS.SENDOBJECTEXECUTIONEXCEPTION.name(), RESPONSE[0]); + } + + /* + * @testName: sendObjectHasExecutionExceptionOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; + * + * @test_Strategy: Errors in transmission are wrapped in the ExecutionException + * thrown when querying the Future object. + */ + @Test + public void sendObjectHasExecutionExceptionOnClientTest() throws Exception { + sendOnClientHasExecutionException(OPS.SENDOBJECTEXECUTIONEXCEPTION); + } + + /* + * @testName: sendObjectWithHandlerOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:116; + * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.SendHandler.onResult( SendResult ) + * jakarta.websocket.SendHandler.SendHandler() + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectWithHandlerOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECTHANDLER); + } + + /* + * @testName: sendObjectWithHandlerOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:116; + * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.SendHandler.onResult( SendResult ) + * jakarta.websocket.SendHandler.SendHandler() + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendObjectWithHandlerOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECTHANDLER); + } + + /* + * @testName: sendObjectWithHandlerThrowsIAEOnServerWhenDataIsNullTest + * + * @assertion_ids: WebSocket:JAVADOC:97; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendObjectWithHandlerThrowsIAEOnServerWhenDataIsNullTest() throws Exception { + invoke("server", OPS.SENDOBJECTHANDLERTHROWSONDATA.name(), RESPONSE[0]); + } + + /* + * @testName: sendObjectWithHandlerThrowsIAEOnServerWhenHandlerIsNullTest + * + * @assertion_ids: WebSocket:JAVADOC:97; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendObjectWithHandlerThrowsIAEOnServerWhenHandlerIsNullTest() throws Exception { + invoke("server", OPS.SENDOBJECTHANDLERTHROWSONHANDLER.name(), RESPONSE[0]); + } + + /* + * @testName: sendObjectWithHandlerThrowsIAEOnClientWhenDataIsNullTest + * + * @assertion_ids: WebSocket:JAVADOC:97; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendObjectWithHandlerThrowsIAEOnClientWhenDataIsNullTest() throws Exception { + sendOnClientThrows(OPS.SENDOBJECTHANDLERTHROWSONDATA); + } + + /* + * @testName: sendObjectWithHandlerThrowsIAEOnClientWhenHandlerIsNullTest + * + * @assertion_ids: WebSocket:JAVADOC:97; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendObjectWithHandlerThrowsIAEOnClientWhenHandlerIsNullTest() throws Exception { + sendOnClientThrows(OPS.SENDOBJECTHANDLERTHROWSONHANDLER); + } + + /* + * @testName: sendObjectWithHandlerHasExceptionOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:116; + * WebSocket:JAVADOC:117; WebSocket:JAVADOC:118; WebSocket:JAVADOC:119; + * + * @test_Strategy: Check SendHandler#getException && SendHandler#isOk + * SendResult.SendResult( Throwable ) + */ + @Test + public void sendObjectWithHandlerHasExceptionOnServerTest() throws Exception { + setClientEndpoint(BinaryAndTextClientEndpoint.class); + invoke("throwing", OPS.SENDOBJECTHANDLEREXECUTIONEXCEPTION.name(), RESPONSE[0]); + } + + /* + * @testName: sendObjectWithHandlerHasExecutionExceptionOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:116; + * WebSocket:JAVADOC:117; WebSocket:JAVADOC:118; WebSocket:JAVADOC:119; + * + * @test_Strategy: Check SendHandler#getException && SendHandler#isOk + * SendResult.SendResult( Throwable ) + */ + @Test + public void sendObjectWithHandlerHasExecutionExceptionOnClientTest() throws Exception { + sendOnClientHasExecutionException(OPS.SENDOBJECTHANDLEREXECUTIONEXCEPTION); + } + + /* + * @testName: sendTextOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:99; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendTextOnServerTest() throws Exception { + sendOnServer(OPS.SENDTEXT); + } + + /* + * @testName: sendTextOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:99; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendTextOnClientTest() throws Exception { + sendOnClient(OPS.SENDTEXT); + } + + /* + * @testName: sendTextThrowsIAEOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:99; + * + * @test_Strategy: Throws: IllegalArgumentException - if the data is null. + */ + @Test + public void sendTextThrowsIAEOnServerTest() throws Exception { + invoke("server", OPS.SENDTEXTTHROWS.name(), RESPONSE[0]); + } + + /* + * @testName: sendTextThrowsIAEOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:99; + * + * @test_Strategy: Throws: IllegalArgumentException - if the data is null. + */ + @Test + public void sendTextThrowsIAEOnClientTest() throws Exception { + sendOnClientThrows(OPS.SENDTEXTTHROWS); + } + + /* + * @testName: sendTextWithHandlerOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:98; WebSocket:JAVADOC:116; + * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.SendHandler.onResult( SendResult ) + * jakarta.websocket.SendHandler.SendHandler() + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendTextWithHandlerOnServerTest() throws Exception { + sendOnServer(OPS.SENDTEXTHANDLER); + } + + /* + * @testName: sendTextWithHandlerOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:98; WebSocket:JAVADOC:116; + * WebSocket:JAVADOC:120; WebSocket:JAVADOC:127; + * + * @test_Strategy: Initiates the asynchronous transmission of a binary message. + * The Future's get() method returns null upon successful completion. + * jakarta.websocket.SendHandler.onResult( SendResult ) + * jakarta.websocket.SendHandler.SendHandler() + * jakarta.websocket.Session.getAsyncRemote + */ + @Test + public void sendTextWithHandlerOnClientTest() throws Exception { + sendOnClient(OPS.SENDTEXTHANDLER); + } + + /* + * @testName: sendTextWithHandlerThrowsIAEOnServerWhenDataIsNullTest + * + * @assertion_ids: WebSocket:JAVADOC:98; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendTextWithHandlerThrowsIAEOnServerWhenDataIsNullTest() throws Exception { + invoke("server", OPS.SENDTEXTHANDLERTHROWSONDATA.name(), RESPONSE[0]); + } + + /* + * @testName: sendTextWithHandlerThrowsIAEOnServerWhenHandlerIsNullTest + * + * @assertion_ids: WebSocket:JAVADOC:98; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendTextWithHandlerThrowsIAEOnServerWhenHandlerIsNullTest() throws Exception { + invoke("server", OPS.SENDTEXTHANDLERTHROWSONHANDLER.name(), RESPONSE[0]); + } + + /* + * @testName: sendTextWithHandlerThrowsIAEOnClientWhenDataIsNullTest + * + * @assertion_ids: WebSocket:JAVADOC:98; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendTextWithHandlerThrowsIAEOnClientWhenDataIsNullTest() throws Exception { + sendOnClientThrows(OPS.SENDTEXTHANDLERTHROWSONDATA); + } + + /* + * @testName: sendTextWithHandlerThrowsIAEOnClientWhenHandlerIsNullTest + * + * @assertion_ids: WebSocket:JAVADOC:98; + * + * @test_Strategy: Throws: IllegalArgumentException - if either the data or the + * handler are null. + */ + @Test + public void sendTextWithHandlerThrowsIAEOnClientWhenHandlerIsNullTest() throws Exception { + sendOnClientThrows(OPS.SENDTEXTHANDLERTHROWSONHANDLER); + } + + // ------------------------------------------------------------------------ + /* + * @testName: batchingAllowedOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:84;WebSocket:JAVADOC:91; + * + * @test_Strategy: calls setBatchingAllowed(!getBatchingAllowed()) and checks no + * exception is thrown + */ + @Test + public void batchingAllowedOnServerTest() throws Exception { + sendOnServer(OPS.BATCHING_ALLOWED); + } + + /* + * @testName: batchingAllowedOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:84;WebSocket:JAVADOC:91; + * + * @test_Strategy: calls setBatchingAllowed(!getBatchingAllowed()) and checks no + * exception is thrown + */ + @Test + public void batchingAllowedOnClientTest() throws Exception { + sendOnClient(OPS.BATCHING_ALLOWED); + } + + /* + * @testName: sendPingOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:85; WebSocket:SPEC:WSC-2.2.5-1; + * WebSocket:SPEC:WSC-2.2.5-2; + * + * @test_Strategy: Send a Ping message containing the given application data to + * the remote endpoint. The corresponding Pong message may be picked up using + * the MessageHandler.Pong handler + */ + @Test + public void sendPingOnServerTest() throws Exception { + setCountDownLatchCount(2); + setProperty(Property.CONTENT, OPS.SEND_PING.name()); + setProperty(Property.REQUEST, buildRequest("server")); + // first server sends ping, websocket impl responses with pong + // then server sends ok and the pong is caught back on server + // and pong data are send back to client + setProperty(Property.UNORDERED_SEARCH_STRING, search(RESPONSE[0], OPS.SEND_PING)); + invoke(); + } + + /* + * @testName: sendPingOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:85; + * + * @test_Strategy: Send a Ping message containing the given application data to + * the remote endpoint. The corresponding Pong message may be picked up using + * the MessageHandler.Pong handler + */ + @Test + public void sendPingOnClientTest() throws Exception { + setClientEndpoint(PongMessageClientEndpoint.class); + sendOnClient(OPS.SEND_PING); + } + + /* + * @testName: sendPingDelaysTimoutOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:85; WebSocket:SPEC:WSC-2.2.5-1; + * WebSocket:SPEC:WSC-2.2.5-2; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + * + * if a websocket implementation receives a ping message from a peer, it must + * respond as soon as possible to that peer with a pong message containing the + * same application data. + * + * if the implementation receives a pong message addressed to this endpoint, it + * must call that MessageHandler or that annotated message + */ + @Test + public void sendPingDelaysTimoutOnServerTest() throws Exception { + StringPingMessage ping = new StringPingMessage(OPS.POKE.name()); + setClientEndpoint(PongMessageClientEndpoint.class); + invoke("server", OPS.IDLE.name(), OPS.IDLE.name(), false); + + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + + invokeAgain(OPS.POKE.name(), OPS.POKE.name(), true); + } + + /* + * @testName: sendPingDelaysTimoutOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:85; WebSocket:SPEC:WSC-2.2.5-1; + * WebSocket:SPEC:WSC-2.2.5-2; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + * + * if a websocket implementation receives a ping message from a peer, it must + * respond as soon as possible to that peer with a pong message containing the + * same application data. + * + * if the implementation receives a pong message addressed to this endpoint, it + * must call that MessageHandler or that annotated message + */ + @Test + public void sendPingDelaysTimoutOnClientTest() throws Exception { + setClientEndpoint(PongMessageClientEndpoint.class); + invoke("server", OPS.POKE.name(), OPS.POKE.name(), false); + getSession().setMaxIdleTimeout(1500L); + + setCountDownLatchCount(5); + setProperty(Property.CONTENT, OPS.PING_4_TIMES.name()); + setProperty(Property.SEARCH_STRING, OPS.POKE.name(), OPS.POKE.name(), OPS.POKE.name(), OPS.POKE.name()); + setProperty(Property.SEARCH_STRING_IGNORE_CASE); + setProperty(Property.SEARCH_STRING_IGNORE_CASE, RESPONSE[0]); + invokeAgain(true); + } + + /* + * @testName: sendPingThrowsOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:87; + * + * @test_Strategy: throws IllegalArgumentException - if the applicationData + * exceeds the maximum allowed payload of 125 bytes + */ + @Test + public void sendPingThrowsOnServerTest() throws Exception { + invoke("server", OPS.SEND_PING_THROWS, RESPONSE[0]); + } + + /* + * @testName: sendPingThrowsOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:87; + * + * @test_Strategy: throws IllegalArgumentException - if the applicationData + * exceeds the maximum allowed payload of 125 bytes + */ + @Test + public void sendPingThrowsOnClientTest() throws Exception { + sendOnClientThrows(OPS.SEND_PING_THROWS); + } + + /* + * @testName: sendPongOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:88; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + */ + @Test + public void sendPongOnServerTest() throws Exception { + sendOnServer(OPS.SEND_PONG, OPS.SEND_PONG.name(), PongMessageClientEndpoint.class); + } + + /* + * @testName: sendPongOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:88; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + */ + @Test + public void sendPongOnClientTest() throws Exception { + sendOnClient(OPS.SEND_PONG); + } + + /* + * @testName: sendPongDelaysTimoutOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:88; WebSocket:SPEC:WSC-2.2.5-2; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + * + * if the implementation receives a pong message addressed to this endpoint, it + * must call that MessageHandler or that annotated message + */ + @Test + public void sendPongDelaysTimoutOnServerTest() throws Exception { + StringPongMessage ping = new StringPongMessage(OPS.POKE.name()); + setClientEndpoint(PongMessageClientEndpoint.class); + invoke("server", OPS.IDLE.name(), OPS.IDLE.name(), false); + + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + + invokeAgain(OPS.POKE.name(), OPS.POKE.name(), true); + } + + /* + * @testName: sendPongDelaysTimoutOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:88; WebSocket:SPEC:WSC-2.2.5-2; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + * + * if the implementation receives a pong message addressed to this endpoint, it + * must call that MessageHandler or that annotated message + */ + @Test + public void sendPongDelaysTimoutOnClientTest() throws Exception { + setClientEndpoint(PongMessageClientEndpoint.class); + invoke("server", OPS.POKE.name(), OPS.POKE.name(), false); + getSession().setMaxIdleTimeout(1500L); + + setCountDownLatchCount(5); + setProperty(Property.CONTENT, OPS.PONG_4_TIMES.name()); + setProperty(Property.SEARCH_STRING, OPS.POKE.name(), OPS.POKE.name(), OPS.POKE.name(), OPS.POKE.name()); + setProperty(Property.SEARCH_STRING_IGNORE_CASE); + setProperty(Property.SEARCH_STRING_IGNORE_CASE, RESPONSE[0]); + invokeAgain(true); + } + + /* + * @testName: sendPongThrowsOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:90; + * + * @test_Strategy: throws IllegalArgumentException - if the applicationData + * exceeds the maximum allowed payload of 125 bytes + */ + @Test + public void sendPongThrowsOnServerTest() throws Exception { + invoke("server", OPS.SEND_PONG_THROWS, RESPONSE[0]); + } + + /* + * @testName: sendPongThrowsOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:90; + * + * @test_Strategy: throws IllegalArgumentException - if the applicationData + * exceeds the maximum allowed payload of 125 bytes + */ + @Test + public void sendPongThrowsOnClientTest() throws Exception { + sendOnClientThrows(OPS.SEND_PONG_THROWS); + } + + // ///////////////////////////////////////////////////////////////////////// + private String search(Object... ops) { + return StringUtil.objectsToStringWithDelimiter("|", (Object[]) ops); + } + + private void sendOnServer(OPS ops) throws Exception { + sendOnServer(ops, ops); + } + + private void sendOnServer(OPS ops, Object search) throws Exception { + sendOnServer(ops, search, BinaryAndTextClientEndpoint.class); + } + + private void sendOnServer(OPS ops, Object search, Class> endpoint) throws Exception { + setCountDownLatchCount(3); + setProperty(Property.CONTENT, ops.name()); + setProperty(Property.REQUEST, buildRequest("server")); + setProperty(Property.UNORDERED_SEARCH_STRING, search(search, OPS.POKE, RESPONSE[0])); + PokingEndpointCallback callback = new PokingEndpointCallback(entity); + setClientCallback(callback); + setClientEndpoint(endpoint); + invoke(); + } + + private void sendOnClient(final OPS op) throws Exception { + sendOnClient(op, op.name()); + } + + private void sendOnClient(final OPS op, String search) throws Exception { + EndpointCallback callback = new AsyncEndpointCallback() { + @Override + void doAsync(Async asyncRemote) throws Exception { + String ret = null; + String method = null; + switch (op) { + case SENDBINARY: + ret = WSCServerSideServer.sendBinary(asyncRemote); + method = "sendBinary(ByteBuffer)"; + break; + case SENDBINARYHANDLER: + ret = WSCServerSideServer.sendBinaryWithHandler(asyncRemote); + method = "sendBinary(ByteBuffer, SendHandler)"; + break; + case SENDOBJECT: + ret = WSCServerSideServer.sendObject(asyncRemote); + method = "sendObject(Object)"; + break; + case SENDOBJECTHANDLER: + ret = WSCServerSideServer.sendObjectWithHandler(asyncRemote); + method = "sendObject(Object, SendHandler)"; + break; + case SENDOBJECT_BOOL: + ret = WSCServerSideServer.sendObject(asyncRemote, boolean.class); + method = "sendObject(boolean)"; + break; + case SENDOBJECT_BYTE: + ret = WSCServerSideServer.sendObject(asyncRemote, byte.class); + method = "sendObject(byte)"; + break; + case SENDOBJECT_CHAR: + ret = WSCServerSideServer.sendObject(asyncRemote, char.class); + method = "sendObject(char)"; + break; + case SENDOBJECT_DOUBLE: + ret = WSCServerSideServer.sendObject(asyncRemote, double.class); + method = "sendObject(double)"; + break; + case SENDOBJECT_FLOAT: + ret = WSCServerSideServer.sendObject(asyncRemote, float.class); + method = "sendObject(float)"; + break; + case SENDOBJECT_INT: + ret = WSCServerSideServer.sendObject(asyncRemote, int.class); + method = "sendObject(int)"; + break; + case SENDOBJECT_LONG: + ret = WSCServerSideServer.sendObject(asyncRemote, long.class); + method = "sendObject(long)"; + break; + case SENDOBJECT_SHORT: + ret = WSCServerSideServer.sendObject(asyncRemote, short.class); + method = "sendObject(short)"; + break; + case SENDTEXT: + ret = WSCServerSideServer.sendText(asyncRemote); + method = "sendText(String)"; + break; + case SENDTEXTHANDLER: + ret = WSCServerSideServer.sendTextWithHandler(asyncRemote); + method = "sendText(String, SendHandler)"; + break; + case BATCHING_ALLOWED: + ret = WSCServerSideServer.batchingAllowed(asyncRemote); + method = "setBatchingAllowed(!getBatchingAllowed)"; + break; + case SEND_PING: + ret = WSCServerSideServer.sendPing(asyncRemote); + method = "sendPing(ByteBuffer)"; + break; + case SEND_PONG: + ret = WSCServerSideServer.sendPong(asyncRemote); + method = "sendPong(ByteBuffer)"; + break; + default: + new Exception("Method " + op + " not implemented"); + } + assertEquals(RESPONSE[0], ret, method, "did not endup as expected"); + logMsg(method, "works as expected"); + } + }; + setClientCallback(callback); + + // Add StringBean encoder just for sendObject methods + List> list = new LinkedList<>(); + list.add(StringBeanTextEncoder.class); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().encoders(list).build(); + setClientEndpointConfig(config); + + invoke("client", "anything", search); + } + + private void sendOnClientHasExecutionException(final OPS op) throws Exception { + EndpointCallback callback = new AsyncEndpointCallback() { + @Override + void doAsync(Async asyncRemote) throws Exception { + String ret = null; + String method = null; + switch (op) { + case SENDOBJECTEXECUTIONEXCEPTION: + ret = WSCThrowingServerSideServer.sendObjectHasExecutionException(asyncRemote); + method = "sendObject(Object)"; + break; + case SENDOBJECTHANDLEREXECUTIONEXCEPTION: + ret = WSCThrowingServerSideServer.sendObjectWithSendHandlerHasExecutionException(asyncRemote); + method = "sendObject(Object, SendHandler)"; + break; + default: + new Exception("Method " + op + " not implemented"); + } + assertEquals(RESPONSE[0], ret, method, "did not endup with ExecutionException"); + logMsg(method, "end up with ExecutionException as expected"); + asyncRemote.sendText(entity.getEntityAt(String.class, 0)); + } + }; + setClientCallback(callback); + + // Add StringBean encoder just for sendObject methods + List> list = new LinkedList<>(); + list.add(ThrowingStringBeanEncoder.class); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().encoders(list).build(); + setClientEndpointConfig(config); + + invoke("client", ECHO, ECHO); + } + + private void sendOnClientThrows(final OPS op) throws Exception { + EndpointCallback callback = new AsyncEndpointCallback() { + @Override + void doAsync(Async asyncRemote) throws Exception { + String ret = null; + String method = null; + switch (op) { + case SENDBINARYTHROWS: + ret = WSCServerSideServer.sendBinaryThrows(asyncRemote); + method = "sendBinary(ByteBuffer)"; + break; + case SENDBINARYHANDLERTHROWSONDATA: + ret = WSCServerSideServer.sendBinaryWithHandlerThrowsOnData(asyncRemote); + method = "sendBinary(ByteBuffer, SendHandler)"; + break; + case SENDBINARYHANDLERTHROWSONHANDLER: + ret = WSCServerSideServer.sendBinaryWithHandlerThrowsOnHandler(asyncRemote); + method = "sendBinary(ByteBuffer, SendHandler)"; + break; + case SENDOBJECTTHROWS: + ret = WSCServerSideServer.sendObjectThrows(asyncRemote); + method = "sendObject(Object)"; + break; + case SENDOBJECTHANDLERTHROWSONDATA: + ret = WSCServerSideServer.sendObjectWithHandlerThrowsOnData(asyncRemote); + method = "sendObject(Object, SendHandler)"; + break; + case SENDOBJECTHANDLERTHROWSONHANDLER: + ret = WSCServerSideServer.sendObjectWithHandlerThrowsOnHandler(asyncRemote); + method = "sendObject(object, SendHandler)"; + break; + case SENDTEXTTHROWS: + ret = WSCServerSideServer.sendTextThrows(asyncRemote); + method = "sendText(String)"; + break; + case SENDTEXTHANDLERTHROWSONDATA: + ret = WSCServerSideServer.sendTextWithHandlerThrowsOnData(asyncRemote); + method = "sendText(String, SendHandler)"; + break; + case SENDTEXTHANDLERTHROWSONHANDLER: + ret = WSCServerSideServer.sendTextWithHandlerThrowsOnHandler(asyncRemote); + method = "sendText(String, SendHandler)"; + break; + case SEND_PING_THROWS: + ret = WSCServerSideServer.sendPingThrows(asyncRemote); + method = "sendPing()"; + break; + case SEND_PONG_THROWS: + ret = WSCServerSideServer.sendPongThrows(asyncRemote); + method = "sendPong()"; + break; + default: + new Exception("Method " + op + " not implemented"); + } + assertEquals(RESPONSE[0], ret, method, "does not throw IllegalArgumentException as expected"); + logMsg(method, "throws IllegalArgumentException as expected"); + asyncRemote.sendText(entity.getEntityAt(String.class, 0)); + } + }; + setClientCallback(callback); + invoke("client", ECHO, ECHO); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/BasicEndpointCallback.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/BasicEndpointCallback.java index 5f7a09759d..3d6559cae3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/BasicEndpointCallback.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/BasicEndpointCallback.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -17,7 +17,6 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.basic; -import com.sun.ts.lib.harness.EETest.Fault; import com.sun.ts.tests.websocket.common.client.EndpointCallback; import jakarta.websocket.EndpointConfig; @@ -25,16 +24,16 @@ import jakarta.websocket.Session; public abstract class BasicEndpointCallback extends EndpointCallback { - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - Basic basicRemote = session.getBasicRemote(); - try { - doBasic(basicRemote); - } catch (Exception f) { - throw new RuntimeException(f); - } - } + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + Basic basicRemote = session.getBasicRemote(); + try { + doBasic(basicRemote); + } catch (Exception f) { + throw new RuntimeException(f); + } + } - abstract void doBasic(Basic basicRemote) throws Exception; + abstract void doBasic(Basic basicRemote) throws Exception; } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/HolderForThrowingEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/HolderForThrowingEncoder.java index a79a773713..a1931cc310 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/HolderForThrowingEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/HolderForThrowingEncoder.java @@ -17,19 +17,19 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.basic; public class HolderForThrowingEncoder { - public String getWrapped() { - return wrapped; - } + public String getWrapped() { + return wrapped; + } - public void setWrapped(String wrapped) { - this.wrapped = wrapped; - } + public void setWrapped(String wrapped) { + this.wrapped = wrapped; + } - public HolderForThrowingEncoder(String wrapped) { - super(); - this.wrapped = wrapped; - } + public HolderForThrowingEncoder(String wrapped) { + super(); + this.wrapped = wrapped; + } - private String wrapped; + private String wrapped; } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/OPS.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/OPS.java index bf4de45a3c..98546022e0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/OPS.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/OPS.java @@ -17,13 +17,13 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.basic; public enum OPS { - POKE, SENDSTREAM, // - SENDWRITER, // - SENDBINARY, SENDBINARYPART1, SENDBINARYPART2, SENDBINARYPART3, SENDBINARYTHROWS, // - SENDOBJECT, SENDOBJECTTHROWS, SENDOBJECTTHROWSENCODEEEXCEPTION, // - SENDOBJECT_BYTE, SENDOBJECT_SHORT, SENDOBJECT_INT, SENDOBJECT_LONG, // - SENDOBJECT_FLOAT, SENDOBJECT_DOUBLE, SENDOBJECT_BOOL, SENDOBJECT_CHAR, // - SENDTEXT, SENDTEXTPART1, SENDTEXTPART2, SENDTEXTPART3, SENDTEXTTHROWS, // - BATCHING_ALLOWED, SEND_PING, SEND_PONG, SEND_PING_THROWS, SEND_PONG_THROWS, // - IDLE /* let ping make no idle timeout */, PING_4_TIMES, PONG_4_TIMES + POKE, SENDSTREAM, // + SENDWRITER, // + SENDBINARY, SENDBINARYPART1, SENDBINARYPART2, SENDBINARYPART3, SENDBINARYTHROWS, // + SENDOBJECT, SENDOBJECTTHROWS, SENDOBJECTTHROWSENCODEEEXCEPTION, // + SENDOBJECT_BYTE, SENDOBJECT_SHORT, SENDOBJECT_INT, SENDOBJECT_LONG, // + SENDOBJECT_FLOAT, SENDOBJECT_DOUBLE, SENDOBJECT_BOOL, SENDOBJECT_CHAR, // + SENDTEXT, SENDTEXTPART1, SENDTEXTPART2, SENDTEXTPART3, SENDTEXTTHROWS, // + BATCHING_ALLOWED, SEND_PING, SEND_PONG, SEND_PING_THROWS, SEND_PONG_THROWS, // + IDLE /* let ping make no idle timeout */, PING_4_TIMES, PONG_4_TIMES } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/PokingEndpointCallback.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/PokingEndpointCallback.java index fdc3fbf1b5..b4b56729b4 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/PokingEndpointCallback.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/PokingEndpointCallback.java @@ -27,101 +27,100 @@ public class PokingEndpointCallback extends SendMessageCallback { - public PokingEndpointCallback(Entity entity) { - super(entity); - } + public PokingEndpointCallback(Entity entity) { + super(entity); + } - private Session session; + private Session session; - int pokeCnt = 0; + int pokeCnt = 0; - int pokeMax = 1; + int pokeMax = 1; - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - this.session = session; - } + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + this.session = session; + } - public void onMessage(String msg, Session session) throws IOException { - if (msg.equals(WSCServerSideServer.RESPONSE[0]) - || (msg.equals(WSCServerSideServer.RESPONSE[1]))) - return; - if (msg.startsWith("-100")) - msg = OPS.SENDOBJECT_BYTE.name(); - else if (msg.startsWith("-101")) - msg = OPS.SENDOBJECT_SHORT.name(); - else if (msg.startsWith("-102")) - msg = OPS.SENDOBJECT_INT.name(); - else if (msg.startsWith("-103")) - msg = OPS.SENDOBJECT_LONG.name(); - else if (msg.startsWith("-104")) - msg = OPS.SENDOBJECT_FLOAT.name(); - else if (msg.startsWith("-105")) - msg = OPS.SENDOBJECT_DOUBLE.name(); - else if (msg.startsWith(String.valueOf((char) 106))) - msg = OPS.SENDOBJECT_CHAR.name(); - else if (msg.startsWith("false")) - msg = OPS.SENDOBJECT_BOOL.name(); - else if (msg.startsWith(OPS.SENDBINARYPART1.name())) - msg = OPS.SENDBINARYPART1.name(); // when received partials at once - else if (msg.startsWith(OPS.SENDTEXTPART1.name())) - msg = OPS.SENDTEXTPART1.name(); // when received partials at once - OPS ops = OPS.valueOf(msg); - switch (ops) { - case SENDBINARY: - case SENDOBJECT: - case SENDOBJECT_BOOL: - case SENDOBJECT_BYTE: - case SENDOBJECT_CHAR: - case SENDOBJECT_DOUBLE: - case SENDOBJECT_FLOAT: - case SENDOBJECT_INT: - case SENDOBJECT_LONG: - case SENDOBJECT_SHORT: - case SENDBINARYPART1: - case SENDTEXT: - case SENDTEXTPART1: - case SENDSTREAM: - case SENDWRITER: - case BATCHING_ALLOWED: - case SEND_PONG: - if (pokeCnt++ <= pokeMax) - session.getBasicRemote().sendText(OPS.POKE.name()); - break; - case SENDBINARYPART2: - case SENDBINARYPART3: - // - case SENDBINARYTHROWS: - // - case SENDOBJECTTHROWS: - case SENDOBJECTTHROWSENCODEEEXCEPTION: - // - case SENDTEXTPART2: - case SENDTEXTPART3: - // - case SENDTEXTTHROWS: - // - case POKE: - // - case SEND_PING: - case SEND_PING_THROWS: - case SEND_PONG_THROWS: - break; - default: - break; - } - } + public void onMessage(String msg, Session session) throws IOException { + if (msg.equals(WSCServerSideServer.RESPONSE[0]) || (msg.equals(WSCServerSideServer.RESPONSE[1]))) + return; + if (msg.startsWith("-100")) + msg = OPS.SENDOBJECT_BYTE.name(); + else if (msg.startsWith("-101")) + msg = OPS.SENDOBJECT_SHORT.name(); + else if (msg.startsWith("-102")) + msg = OPS.SENDOBJECT_INT.name(); + else if (msg.startsWith("-103")) + msg = OPS.SENDOBJECT_LONG.name(); + else if (msg.startsWith("-104")) + msg = OPS.SENDOBJECT_FLOAT.name(); + else if (msg.startsWith("-105")) + msg = OPS.SENDOBJECT_DOUBLE.name(); + else if (msg.startsWith(String.valueOf((char) 106))) + msg = OPS.SENDOBJECT_CHAR.name(); + else if (msg.startsWith("false")) + msg = OPS.SENDOBJECT_BOOL.name(); + else if (msg.startsWith(OPS.SENDBINARYPART1.name())) + msg = OPS.SENDBINARYPART1.name(); // when received partials at once + else if (msg.startsWith(OPS.SENDTEXTPART1.name())) + msg = OPS.SENDTEXTPART1.name(); // when received partials at once + OPS ops = OPS.valueOf(msg); + switch (ops) { + case SENDBINARY: + case SENDOBJECT: + case SENDOBJECT_BOOL: + case SENDOBJECT_BYTE: + case SENDOBJECT_CHAR: + case SENDOBJECT_DOUBLE: + case SENDOBJECT_FLOAT: + case SENDOBJECT_INT: + case SENDOBJECT_LONG: + case SENDOBJECT_SHORT: + case SENDBINARYPART1: + case SENDTEXT: + case SENDTEXTPART1: + case SENDSTREAM: + case SENDWRITER: + case BATCHING_ALLOWED: + case SEND_PONG: + if (pokeCnt++ <= pokeMax) + session.getBasicRemote().sendText(OPS.POKE.name()); + break; + case SENDBINARYPART2: + case SENDBINARYPART3: + // + case SENDBINARYTHROWS: + // + case SENDOBJECTTHROWS: + case SENDOBJECTTHROWSENCODEEEXCEPTION: + // + case SENDTEXTPART2: + case SENDTEXTPART3: + // + case SENDTEXTTHROWS: + // + case POKE: + // + case SEND_PING: + case SEND_PING_THROWS: + case SEND_PONG_THROWS: + break; + default: + break; + } + } - @Override - public void onMessage(Object o) { - super.onMessage(o); - try { - String msg = o.toString(); - onMessage(msg, session); - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - } + @Override + public void onMessage(Object o) { + super.onMessage(o); + try { + String msg = o.toString(); + onMessage(msg, session); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/ThrowingEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/ThrowingEncoder.java index 64b62d4f6e..59afd944cf 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/ThrowingEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/ThrowingEncoder.java @@ -22,19 +22,19 @@ import jakarta.websocket.EndpointConfig; public class ThrowingEncoder implements Encoder.Text { - static final String ERR_MSG = "Meant TCK EncodeException"; + static final String ERR_MSG = "Meant TCK EncodeException"; - @Override - public void init(EndpointConfig config) { - } + @Override + public void init(EndpointConfig config) { + } - @Override - public void destroy() { - } + @Override + public void destroy() { + } - @Override - public String encode(HolderForThrowingEncoder object) throws EncodeException { - throw new EncodeException(object, ERR_MSG); - } + @Override + public String encode(HolderForThrowingEncoder object) throws EncodeException { + throw new EncodeException(object, ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSCOtherSideServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSCOtherSideServer.java index 87519454b5..73e9ce3c8d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSCOtherSideServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSCOtherSideServer.java @@ -31,28 +31,28 @@ @ServerEndpoint("/client") public class WSCOtherSideServer { - @OnMessage - public String onMessage(PongMessage pong) { - return IOUtil.byteBufferToString(pong.getApplicationData()); - } - - @OnMessage - public String onMessage(String msg) { - return msg; - } - - @OnMessage - public String onMessage(ByteBuffer buffer) { - String msg = IOUtil.byteBufferToString(buffer); - return onMessage(msg); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String onMessage(PongMessage pong) { + return IOUtil.byteBufferToString(pong.getApplicationData()); + } + + @OnMessage + public String onMessage(String msg) { + return msg; + } + + @OnMessage + public String onMessage(ByteBuffer buffer) { + String msg = IOUtil.byteBufferToString(buffer); + return onMessage(msg); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSCServerSideServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSCServerSideServer.java index a90b81239b..d18ec97a06 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSCServerSideServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSCServerSideServer.java @@ -34,397 +34,393 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/server", encoders = { StringBeanTextEncoder.class, - ThrowingEncoder.class }) +@ServerEndpoint(value = "/server", encoders = { StringBeanTextEncoder.class, ThrowingEncoder.class }) public class WSCServerSideServer { - static final String[] RESPONSE = { "OK", "FAIL" }; - @OnMessage - public String onMessage(PongMessage pong) { - return IOUtil.byteBufferToString(pong.getApplicationData()); - } + static final String[] RESPONSE = { "OK", "FAIL" }; - @OnMessage - public String onMessage(String msg, Session session) { - Basic basicRemote = session.getBasicRemote(); - OPS op = OPS.valueOf(msg.toUpperCase()); - switch (op) { - case POKE: - // returns msg; - break; - case SENDBINARY: - msg = sendBinary(basicRemote); - break; - case SENDBINARYPART1: - msg = sendBinaryPartial(basicRemote); - break; - case SENDBINARYTHROWS: - msg = sendBinaryThrows(basicRemote); - break; - case SENDOBJECT: - msg = sendObject(basicRemote); - break; - case SENDOBJECTTHROWS: - msg = sendObjectThrows(basicRemote); - break; - case SENDOBJECTTHROWSENCODEEEXCEPTION: - msg = sendObjectThrowsEncodeException(basicRemote); - break; - case SENDOBJECT_BOOL: - msg = sendObject(basicRemote, boolean.class); - break; - case SENDOBJECT_BYTE: - msg = sendObject(basicRemote, byte.class); - break; - case SENDOBJECT_CHAR: - msg = sendObject(basicRemote, char.class); - break; - case SENDOBJECT_DOUBLE: - msg = sendObject(basicRemote, double.class); - break; - case SENDOBJECT_FLOAT: - msg = sendObject(basicRemote, float.class); - break; - case SENDOBJECT_INT: - msg = sendObject(basicRemote, int.class); - break; - case SENDOBJECT_LONG: - msg = sendObject(basicRemote, long.class); - break; - case SENDOBJECT_SHORT: - msg = sendObject(basicRemote, short.class); - break; - case SENDTEXT: - msg = sendText(basicRemote); - break; - case SENDTEXTPART1: - msg = sendTextPartial(basicRemote); - break; - case SENDTEXTTHROWS: - msg = sendTextThrows(basicRemote); - break; - case SENDSTREAM: - msg = getSendStream(basicRemote); - break; - case SENDWRITER: - msg = getSendWriter(basicRemote); - break; - case BATCHING_ALLOWED: - msg = batchingAllowed(basicRemote); - break; - case SEND_PING: - msg = sendPing(basicRemote); - break; - case SEND_PING_THROWS: - msg = sendPingThrows(basicRemote); - break; - case SEND_PONG: - msg = sendPong(basicRemote); - break; - case SEND_PONG_THROWS: - msg = sendBinaryThrows(basicRemote); - break; - case IDLE: - session.setMaxIdleTimeout(1500L); - break; - case PING_4_TIMES: - msg = sendPing4times(basicRemote); - break; - case PONG_4_TIMES: - msg = sendPong4times(basicRemote); - break; - default: - throw new IllegalArgumentException("Method " + msg + " not implemented"); - } - return msg; - } + @OnMessage + public String onMessage(PongMessage pong) { + return IOUtil.byteBufferToString(pong.getApplicationData()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String onMessage(String msg, Session session) { + Basic basicRemote = session.getBasicRemote(); + OPS op = OPS.valueOf(msg.toUpperCase()); + switch (op) { + case POKE: + // returns msg; + break; + case SENDBINARY: + msg = sendBinary(basicRemote); + break; + case SENDBINARYPART1: + msg = sendBinaryPartial(basicRemote); + break; + case SENDBINARYTHROWS: + msg = sendBinaryThrows(basicRemote); + break; + case SENDOBJECT: + msg = sendObject(basicRemote); + break; + case SENDOBJECTTHROWS: + msg = sendObjectThrows(basicRemote); + break; + case SENDOBJECTTHROWSENCODEEEXCEPTION: + msg = sendObjectThrowsEncodeException(basicRemote); + break; + case SENDOBJECT_BOOL: + msg = sendObject(basicRemote, boolean.class); + break; + case SENDOBJECT_BYTE: + msg = sendObject(basicRemote, byte.class); + break; + case SENDOBJECT_CHAR: + msg = sendObject(basicRemote, char.class); + break; + case SENDOBJECT_DOUBLE: + msg = sendObject(basicRemote, double.class); + break; + case SENDOBJECT_FLOAT: + msg = sendObject(basicRemote, float.class); + break; + case SENDOBJECT_INT: + msg = sendObject(basicRemote, int.class); + break; + case SENDOBJECT_LONG: + msg = sendObject(basicRemote, long.class); + break; + case SENDOBJECT_SHORT: + msg = sendObject(basicRemote, short.class); + break; + case SENDTEXT: + msg = sendText(basicRemote); + break; + case SENDTEXTPART1: + msg = sendTextPartial(basicRemote); + break; + case SENDTEXTTHROWS: + msg = sendTextThrows(basicRemote); + break; + case SENDSTREAM: + msg = getSendStream(basicRemote); + break; + case SENDWRITER: + msg = getSendWriter(basicRemote); + break; + case BATCHING_ALLOWED: + msg = batchingAllowed(basicRemote); + break; + case SEND_PING: + msg = sendPing(basicRemote); + break; + case SEND_PING_THROWS: + msg = sendPingThrows(basicRemote); + break; + case SEND_PONG: + msg = sendPong(basicRemote); + break; + case SEND_PONG_THROWS: + msg = sendBinaryThrows(basicRemote); + break; + case IDLE: + session.setMaxIdleTimeout(1500L); + break; + case PING_4_TIMES: + msg = sendPing4times(basicRemote); + break; + case PONG_4_TIMES: + msg = sendPong4times(basicRemote); + break; + default: + throw new IllegalArgumentException("Method " + msg + " not implemented"); + } + return msg; + } - /** - * Again, since the asynchronous thread sends message in virtually no time, - * one does not have any force to hold that send operation in its thread, to - * check the send operation is really unblocking and asynchronous - * - * @param asyncRemote - * @return - */ - protected static String sendBinary(Basic basicRemote) { - try { - basicRemote.sendBinary(ByteBuffer.wrap(OPS.SENDBINARY.name().getBytes())); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } - protected static String sendBinaryPartial(Basic basicRemote) { - try { - basicRemote.sendBinary( - ByteBuffer.wrap(OPS.SENDBINARYPART1.name().getBytes()), false); - basicRemote.sendBinary( - ByteBuffer.wrap(OPS.SENDBINARYPART2.name().getBytes()), false); - basicRemote.sendBinary( - ByteBuffer.wrap(OPS.SENDBINARYPART3.name().getBytes()), true); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + /** + * Again, since the asynchronous thread sends message in virtually no time, one + * does not have any force to hold that send operation in its thread, to check + * the send operation is really unblocking and asynchronous + * + * @param asyncRemote + * @return + */ + protected static String sendBinary(Basic basicRemote) { + try { + basicRemote.sendBinary(ByteBuffer.wrap(OPS.SENDBINARY.name().getBytes())); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String sendBinaryThrows(Basic basicRemote) { - try { - basicRemote.sendBinary((ByteBuffer) null); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String sendBinaryPartial(Basic basicRemote) { + try { + basicRemote.sendBinary(ByteBuffer.wrap(OPS.SENDBINARYPART1.name().getBytes()), false); + basicRemote.sendBinary(ByteBuffer.wrap(OPS.SENDBINARYPART2.name().getBytes()), false); + basicRemote.sendBinary(ByteBuffer.wrap(OPS.SENDBINARYPART3.name().getBytes()), true); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String sendObject(Basic basicRemote) { - try { - basicRemote.sendObject(new StringBean(OPS.SENDOBJECT.name())); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String sendBinaryThrows(Basic basicRemote) { + try { + basicRemote.sendBinary((ByteBuffer) null); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String sendObject(Basic basicRemote, Class type) { - try { - if (type == byte.class) { - byte b = -100; - basicRemote.sendObject(b); - } else if (type == short.class) { - short s = -101; - basicRemote.sendObject(s); - } else if (type == int.class) { - int i = -102; - basicRemote.sendObject(i); - } else if (type == long.class) { - long l = -103L; - basicRemote.sendObject(l); - } else if (type == float.class) { - float f = -104f; - basicRemote.sendObject(f); - } else if (type == double.class) { - double d = -105d; - basicRemote.sendObject(d); - } else if (type == boolean.class) { - boolean b = false; - basicRemote.sendObject(b); - } else if (type == char.class) { - char c = 106; - basicRemote.sendObject(c); - } - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } + protected static String sendObject(Basic basicRemote) { + try { + basicRemote.sendObject(new StringBean(OPS.SENDOBJECT.name())); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - } + protected static String sendObject(Basic basicRemote, Class type) { + try { + if (type == byte.class) { + byte b = -100; + basicRemote.sendObject(b); + } else if (type == short.class) { + short s = -101; + basicRemote.sendObject(s); + } else if (type == int.class) { + int i = -102; + basicRemote.sendObject(i); + } else if (type == long.class) { + long l = -103L; + basicRemote.sendObject(l); + } else if (type == float.class) { + float f = -104f; + basicRemote.sendObject(f); + } else if (type == double.class) { + double d = -105d; + basicRemote.sendObject(d); + } else if (type == boolean.class) { + boolean b = false; + basicRemote.sendObject(b); + } else if (type == char.class) { + char c = 106; + basicRemote.sendObject(c); + } + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } - protected static String sendObjectThrows(Basic basicRemote) { - try { - basicRemote.sendObject((StringBean) null); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + } - protected static String sendObjectThrowsEncodeException(Basic basicRemote) { - try { - basicRemote.sendObject(new HolderForThrowingEncoder( - OPS.SENDOBJECTTHROWSENCODEEEXCEPTION.name())); - return RESPONSE[1]; - } catch (EncodeException e) { - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String sendObjectThrows(Basic basicRemote) { + try { + basicRemote.sendObject((StringBean) null); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String sendText(Basic basicRemote) { - try { - basicRemote.sendText(OPS.SENDTEXT.name()); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String sendObjectThrowsEncodeException(Basic basicRemote) { + try { + basicRemote.sendObject(new HolderForThrowingEncoder(OPS.SENDOBJECTTHROWSENCODEEEXCEPTION.name())); + return RESPONSE[1]; + } catch (EncodeException e) { + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String sendTextPartial(Basic basicRemote) { - try { - basicRemote.sendText(OPS.SENDTEXTPART1.name(), false); - basicRemote.sendText(OPS.SENDTEXTPART2.name(), false); - basicRemote.sendText(OPS.SENDTEXTPART3.name(), true); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String sendText(Basic basicRemote) { + try { + basicRemote.sendText(OPS.SENDTEXT.name()); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String sendTextThrows(Basic basicRemote) { - try { - basicRemote.sendText((String) null); - return RESPONSE[1]; - } catch (IllegalArgumentException e) { - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String sendTextPartial(Basic basicRemote) { + try { + basicRemote.sendText(OPS.SENDTEXTPART1.name(), false); + basicRemote.sendText(OPS.SENDTEXTPART2.name(), false); + basicRemote.sendText(OPS.SENDTEXTPART3.name(), true); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String getSendStream(Basic basicRemote) { - try { - OutputStream stream = basicRemote.getSendStream(); - stream.write(OPS.SENDSTREAM.name().getBytes()); - stream.close(); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String sendTextThrows(Basic basicRemote) { + try { + basicRemote.sendText((String) null); + return RESPONSE[1]; + } catch (IllegalArgumentException e) { + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String getSendWriter(Basic basicRemote) { - try { - Writer writer = basicRemote.getSendWriter(); - writer.append(OPS.SENDWRITER.name()); - writer.close(); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String getSendStream(Basic basicRemote) { + try { + OutputStream stream = basicRemote.getSendStream(); + stream.write(OPS.SENDSTREAM.name().getBytes()); + stream.close(); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String batchingAllowed(Basic basicRemote) { - try { - boolean allowed = basicRemote.getBatchingAllowed(); - basicRemote.setBatchingAllowed(!allowed); - // now getBatching can be true, or false if not supported - // really there is nothing to test, except that the exception is - // not thrown - basicRemote.sendText(OPS.BATCHING_ALLOWED.name()); - basicRemote.flushBatch(); - // If batching is supported then it will currently be enabled. - // Reset it so subsequent messages are not batched causing the - // test to fail. - basicRemote.setBatchingAllowed(allowed); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String getSendWriter(Basic basicRemote) { + try { + Writer writer = basicRemote.getSendWriter(); + writer.append(OPS.SENDWRITER.name()); + writer.close(); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String sendPing(Basic basicRemote) { - try { - basicRemote.sendPing(ByteBuffer.wrap(OPS.SEND_PING.name().getBytes())); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String batchingAllowed(Basic basicRemote) { + try { + boolean allowed = basicRemote.getBatchingAllowed(); + basicRemote.setBatchingAllowed(!allowed); + // now getBatching can be true, or false if not supported + // really there is nothing to test, except that the exception is + // not thrown + basicRemote.sendText(OPS.BATCHING_ALLOWED.name()); + basicRemote.flushBatch(); + // If batching is supported then it will currently be enabled. + // Reset it so subsequent messages are not batched causing the + // test to fail. + basicRemote.setBatchingAllowed(allowed); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String sendPingThrows(Basic basicRemote) { - try { - basicRemote.sendPing(ByteBuffer.wrap(generateMessage(126).getBytes())); - return RESPONSE[1]; - } catch (IllegalArgumentException iae) { - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String sendPing(Basic basicRemote) { + try { + basicRemote.sendPing(ByteBuffer.wrap(OPS.SEND_PING.name().getBytes())); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String generateMessage(int length) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i != length; i++) - sb.append(i % 10); - return sb.toString(); - } + protected static String sendPingThrows(Basic basicRemote) { + try { + basicRemote.sendPing(ByteBuffer.wrap(generateMessage(126).getBytes())); + return RESPONSE[1]; + } catch (IllegalArgumentException iae) { + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String sendPong(Basic basicRemote) { - try { - basicRemote.sendPong(ByteBuffer.wrap(OPS.SEND_PONG.name().getBytes())); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String generateMessage(int length) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i != length; i++) + sb.append(i % 10); + return sb.toString(); + } - protected static String sendPongThrows(Basic basicRemote) { - try { - basicRemote.sendPong(ByteBuffer.wrap(generateMessage(126).getBytes())); - return RESPONSE[1]; - } catch (IllegalArgumentException iae) { - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String sendPong(Basic basicRemote) { + try { + basicRemote.sendPong(ByteBuffer.wrap(OPS.SEND_PONG.name().getBytes())); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String sendPing4times(Basic basicRemote) { - try { - byte[] bytes = OPS.POKE.name().getBytes(); - basicRemote.sendPing(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - basicRemote.sendPing(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - basicRemote.sendPing(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - basicRemote.sendPing(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String sendPongThrows(Basic basicRemote) { + try { + basicRemote.sendPong(ByteBuffer.wrap(generateMessage(126).getBytes())); + return RESPONSE[1]; + } catch (IllegalArgumentException iae) { + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } - protected static String sendPong4times(Basic basicRemote) { - try { - byte[] bytes = OPS.POKE.name().getBytes(); - basicRemote.sendPong(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - basicRemote.sendPong(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - basicRemote.sendPong(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - basicRemote.sendPong(ByteBuffer.wrap(bytes)); - Thread.sleep(500L); - return RESPONSE[0]; - } catch (Exception e) { - e.printStackTrace(); - return IOUtil.printStackTrace(e); - } - } + protected static String sendPing4times(Basic basicRemote) { + try { + byte[] bytes = OPS.POKE.name().getBytes(); + basicRemote.sendPing(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + basicRemote.sendPing(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + basicRemote.sendPing(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + basicRemote.sendPing(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } + + protected static String sendPong4times(Basic basicRemote) { + try { + byte[] bytes = OPS.POKE.name().getBytes(); + basicRemote.sendPong(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + basicRemote.sendPong(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + basicRemote.sendPong(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + basicRemote.sendPong(ByteBuffer.wrap(bytes)); + Thread.sleep(500L); + return RESPONSE[0]; + } catch (Exception e) { + e.printStackTrace(); + return IOUtil.printStackTrace(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSClient.java deleted file mode 100644 index 6e13e16c63..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSClient.java +++ /dev/null @@ -1,980 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.basic; - -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.common.client.BinaryAndTextClientEndpoint; -import com.sun.ts.tests.websocket.common.client.ClientEndpoint; -import com.sun.ts.tests.websocket.common.client.EndpointCallback; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.StringPingMessage; -import com.sun.ts.tests.websocket.common.impl.StringPongMessage; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextEncoder; -import com.sun.ts.tests.websocket.common.util.StringUtil; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.PongMessageClientEndpoint; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.Encoder; -import jakarta.websocket.RemoteEndpoint.Basic; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = -8530759310254161854L; - - static final String[] RESPONSE = WSCServerSideServer.RESPONSE; - - static final String ECHO = "echo"; - - public WSClient() { - setContextRoot("wsc_ee_jakarta_websocket_remoteendpoint_basic_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - /* - * @testName: sendBinaryOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:105; - * - * @test_Strategy: Send a binary message, returning when all of the message - * has been transmitted. - */ - public void sendBinaryOnServerTest() throws Exception { - sendOnServer(OPS.SENDBINARY); - } - - /* - * @testName: sendBinaryOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:107; - * - * @test_Strategy: Send a binary message, returning when all of the message - * has been transmitted. - */ - public void sendBinaryOnClientTest() throws Exception { - sendOnClient(OPS.SENDBINARY); - } - - /* - * @testName: sendBinaryPartialOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:107; - * - * @test_Strategy: Send a binary message, returning when all of the message - * has been transmitted. - */ - public void sendBinaryPartialOnServerTest() throws Exception { - sendOnServer(OPS.SENDBINARYPART1, OPS.SENDBINARYPART1.name() - + OPS.SENDBINARYPART2.name() + OPS.SENDBINARYPART3.name()); - } - - /* - * @testName: sendBinaryPartialOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:105; - * - * @test_Strategy: Send a binary message, returning when all of the message - * has been transmitted. - */ - public void sendBinaryPartialOnClientTest() throws Exception { - sendOnClient(OPS.SENDBINARYPART1, OPS.SENDBINARYPART1.name() - + OPS.SENDBINARYPART2.name() + OPS.SENDBINARYPART3.name()); - } - - /* - * @testName: sendBinaryThrowsIAEOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:105; - * - * @test_Strategy: Throws: IllegalArgumentException - if the data is null. - */ - public void sendBinaryThrowsIAEOnServerTest() throws Exception { - invoke("server", OPS.SENDBINARYTHROWS.name(), RESPONSE[0]); - } - - /* - * @testName: sendBinaryThrowsIAEOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:105; - * - * @test_Strategy: Throws: IllegalArgumentException - if the data is null. - */ - public void sendBinaryThrowsIAEOnClientTest() throws Exception { - sendOnClientThrows(OPS.SENDBINARYTHROWS); - } - - /* - * @testName: sendObjectOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT); - } - - /* - * @testName: sendObjectOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT); - } - - /* - * @testName: sendObjectBooleanOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectBooleanOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_BOOL, false); - } - - /* - * @testName: sendObjectBooleanOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectBooleanOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_BOOL, String.valueOf(false)); - } - - /* - * @testName: sendObjectByteOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectByteOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_BYTE, -100); - } - - /* - * @testName: sendObjectByteOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectByteOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_BYTE, "-100"); - } - - /* - * @testName: sendObjectCharOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectCharOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_CHAR, String.valueOf((char) 106)); - } - - /* - * @testName: sendObjectCharOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectCharOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_CHAR, String.valueOf((char) 106)); - } - - /* - * @testName: sendObjectDoubleOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectDoubleOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_DOUBLE, -105d); - } - - /* - * @testName: sendObjectDoubleOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectDoubleOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_DOUBLE, "-105"); - } - - /* - * @testName: sendObjectFloatOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectFloatOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_FLOAT, -104f); - } - - /* - * @testName: sendObjectFloatOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectFloatOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_FLOAT, "-104"); - } - - /* - * @testName: sendObjectIntOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectIntOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_INT, -102); - } - - /* - * @testName: sendObjectIntOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectIntOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_INT, "-102"); - } - - /* - * @testName: sendObjectLongOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectLongOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_LONG, -103L); - } - - /* - * @testName: sendObjectLongOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectLongOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_LONG, "-103"); - } - - /* - * @testName: sendObjectShortOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectShortOnServerTest() throws Exception { - sendOnServer(OPS.SENDOBJECT_SHORT, -101); - } - - /* - * @testName: sendObjectShortOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Sends a custom developer object, blocking until it has been - * transmitted. - */ - public void sendObjectShortOnClientTest() throws Exception { - sendOnClient(OPS.SENDOBJECT_SHORT, "-101"); - } - - /* - * @testName: sendObjectThrowsIAEOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Throws: IllegalArgumentException - if the data is null. - */ - public void sendObjectThrowsIAEOnServerTest() throws Exception { - invoke("server", OPS.SENDOBJECTTHROWS.name(), RESPONSE[0]); - } - - /* - * @testName: sendObjectThrowsIAEOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; - * - * @test_Strategy: Throws: IllegalArgumentException - if the data is null. - */ - public void sendObjectThrowsIAEOnClientTest() throws Exception { - sendOnClientThrows(OPS.SENDOBJECTTHROWS); - } - - /* - * @testName: sendObjectThrowsEncodeExceptionOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:111; - * - * @test_Strategy: Throws: EncodeException - if there was a problem encoding - * the message object into the form of a native websocket message - */ - public void sendObjectThrowsEncodeExceptionOnServerTest() throws Exception { - invoke("server", OPS.SENDOBJECTTHROWSENCODEEEXCEPTION.name(), RESPONSE[0]); - } - - /* - * @testName: sendObjectThrowsEncodeExceptionOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:111; - * - * @test_Strategy: Throws: EncodeException - if there was a problem encoding - * the message object into the form of a native websocket message - */ - public void sendObjectThrowsEncodeExceptionOnClientTest() throws Exception { - sendOnClientThrowsException(OPS.SENDOBJECTTHROWSENCODEEEXCEPTION, - "EncodeException"); - } - - /* - * @testName: sendTextOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:112; - * - * @test_Strategy: Send a text message, blocking until all of the message has - * been transmitted. - */ - public void sendTextOnServerTest() throws Exception { - sendOnServer(OPS.SENDTEXT); - } - - /* - * @testName: sendTextOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:114; - * - * @test_Strategy: Send a text message, blocking until all of the message has - * been transmitted. - */ - public void sendTextOnClientTest() throws Exception { - sendOnClient(OPS.SENDTEXT); - } - - /* - * @testName: sendTextPartialOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:114; - * - * @test_Strategy: Send a text message, blocking until all of the message has - * been transmitted. - */ - public void sendTextPartialOnServerTest() throws Exception { - sendOnServer(OPS.SENDTEXTPART1, OPS.SENDTEXTPART1.name() - + OPS.SENDTEXTPART2.name() + OPS.SENDTEXTPART3.name()); - } - - /* - * @testName: sendTextPartialOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:112; - * - * @test_Strategy: Send a text message, blocking until all of the message has - * been transmitted. - */ - public void sendTextPartialOnClientTest() throws Exception { - sendOnClient(OPS.SENDTEXTPART1, OPS.SENDTEXTPART1.name() - + OPS.SENDTEXTPART2.name() + OPS.SENDTEXTPART3.name()); - } - - /* - * @testName: sendTextThrowsIAEOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:112; - * - * @test_Strategy: Throws: IllegalArgumentException - if the text is null. - */ - public void sendTextThrowsIAEOnServerTest() throws Exception { - invoke("server", OPS.SENDTEXTTHROWS.name(), RESPONSE[0]); - } - - /* - * @testName: sendTextThrowsIAEOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:112; - * - * @test_Strategy: Throws: IllegalArgumentException - if the text is null. - */ - public void sendTextThrowsIAEOnClientTest() throws Exception { - sendOnClientThrows(OPS.SENDTEXTTHROWS); - } - - /* - * @testName: getSendStreamOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:101; - * - * @test_Strategy: Opens an output stream on which a binary message may be - * sent. The developer must close the output stream in order to indicate that - * the complete message has been placed into the output stream. - */ - public void getSendStreamOnServerTest() throws Exception { - sendOnServer(OPS.SENDSTREAM); - } - - /* - * @testName: getSendStreamOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:101; - * - * @test_Strategy: Opens an output stream on which a binary message may be - * sent. The developer must close the output stream in order to indicate that - * the complete message has been placed into the output stream. - */ - public void getSendStreamOnClientTest() throws Exception { - sendOnClient(OPS.SENDSTREAM); - } - - /* - * @testName: getSendWriterOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:103; - * - * @test_Strategy: Opens an output stream on which a binary message may be - * sent. The developer must close the writer in order to indicate that the - * complete message has been placed into the character stream. - */ - public void getSendWriterOnServerTest() throws Exception { - sendOnServer(OPS.SENDWRITER); - } - - /* - * @testName: getSendWriterOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:103; - * - * @test_Strategy: Opens an output stream on which a binary message may be - * sent. The developer must close the writer in order to indicate that the - * complete message has been placed into the character stream. - */ - public void getSendWriterOnClientTest() throws Exception { - sendOnClient(OPS.SENDWRITER); - } - - /* - * @testName: batchingAllowedOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:84;WebSocket:JAVADOC:91; - * - * @test_Strategy: calls setBatchingAllowed(!getBatchingAllowed()) and checks - * no exception is thrown - */ - public void batchingAllowedOnServerTest() throws Exception { - sendOnServer(OPS.BATCHING_ALLOWED); - } - - /* - * @testName: batchingAllowedOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:84;WebSocket:JAVADOC:91; - * - * @test_Strategy: calls setBatchingAllowed(!getBatchingAllowed()) and checks - * no exception is thrown - */ - public void batchingAllowedOnClientTest() throws Exception { - sendOnClient(OPS.BATCHING_ALLOWED); - } - - /* - * @testName: sendPingOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:85; - * - * @test_Strategy: Send a Ping message containing the given application data - * to the remote endpoint. The corresponding Pong message may be picked up - * using the MessageHandler.Pong handler - */ - public void sendPingOnServerTest() throws Exception { - setCountDownLatchCount(2); - setProperty(Property.CONTENT, OPS.SEND_PING.name()); - setProperty(Property.REQUEST, buildRequest("server")); - // first server sends ping, websocket impl responses with pong - // then server sends ok and the pong is caught back on server - // and pong data are send back to client - setProperty(Property.UNORDERED_SEARCH_STRING, - search(RESPONSE[0], OPS.SEND_PING)); - invoke(); - } - - /* - * @testName: sendPingOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:85; - * - * @test_Strategy: Send a Ping message containing the given application data - * to the remote endpoint. The corresponding Pong message may be picked up - * using the MessageHandler.Pong handler - */ - public void sendPingOnClientTest() throws Exception { - setClientEndpoint(PongMessageClientEndpoint.class); - sendOnClient(OPS.SEND_PING); - } - - /* - * @testName: sendPingDelaysTimoutOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:85; WebSocket:SPEC:WSC-2.2.5-1; - * WebSocket:SPEC:WSC-2.2.5-2; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - * - * if a websocket implementation receives a ping message from a peer, it must - * respond as soon as possible to that peer with a pong message containing the - * same application data. - * - * if the implementation receives a pong message addressed to this endpoint, - * it must call that MessageHandler or that annotated message - */ - public void sendPingDelaysTimoutOnServerTest() throws Exception { - StringPingMessage ping = new StringPingMessage(OPS.POKE.name()); - setClientEndpoint(PongMessageClientEndpoint.class); - invoke("server", OPS.IDLE.name(), OPS.IDLE.name(), false); - - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - - invokeAgain(OPS.POKE.name(), OPS.POKE.name(), true); - } - - /* - * @testName: sendPingDelaysTimoutOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:85; WebSocket:SPEC:WSC-2.2.5-1; - * WebSocket:SPEC:WSC-2.2.5-2; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - * - * if a websocket implementation receives a ping message from a peer, it must - * respond as soon as possible to that peer with a pong message containing the - * same application data. - * - * if the implementation receives a pong message addressed to this endpoint, - * it must call that MessageHandler or that annotated message - */ - public void sendPingDelaysTimoutOnClientTest() throws Exception { - setClientEndpoint(PongMessageClientEndpoint.class); - invoke("server", OPS.POKE.name(), OPS.POKE.name(), false); - getSession().setMaxIdleTimeout(1500L); - - setCountDownLatchCount(5); - setProperty(Property.CONTENT, OPS.PING_4_TIMES.name()); - setProperty(Property.SEARCH_STRING, OPS.POKE.name(), OPS.POKE.name(), - OPS.POKE.name(), OPS.POKE.name()); - setProperty(Property.SEARCH_STRING_IGNORE_CASE); - setProperty(Property.SEARCH_STRING_IGNORE_CASE, RESPONSE[0]); - invokeAgain(true); - } - - /* - * @testName: sendPingThrowsOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:87; - * - * @test_Strategy: throws IllegalArgumentException - if the applicationData - * exceeds the maximum allowed payload of 125 bytes - */ - public void sendPingThrowsOnServerTest() throws Exception { - invoke("server", OPS.SEND_PING_THROWS, RESPONSE[0]); - } - - /* - * @testName: sendPingThrowsOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:87; - * - * @test_Strategy: throws IllegalArgumentException - if the applicationData - * exceeds the maximum allowed payload of 125 bytes - */ - public void sendPingThrowsOnClientTest() throws Exception { - sendOnClientThrows(OPS.SEND_PING_THROWS); - } - - /* - * @testName: sendPongOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:88; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - */ - public void sendPongOnServerTest() throws Exception { - sendOnServer(OPS.SEND_PONG, OPS.SEND_PONG.name(), - PongMessageClientEndpoint.class); - } - - /* - * @testName: sendPongOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:88; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - */ - public void sendPongOnClientTest() throws Exception { - sendOnClient(OPS.SEND_PONG); - } - - /* - * @testName: sendPongDelaysTimoutOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:88; WebSocket:SPEC:WSC-2.2.5-2; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - * - * if the implementation receives a pong message addressed to this endpoint, - * it must call that MessageHandler or that annotated message - */ - public void sendPongDelaysTimoutOnServerTest() throws Exception { - StringPongMessage ping = new StringPongMessage(OPS.POKE.name()); - setClientEndpoint(PongMessageClientEndpoint.class); - invoke("server", OPS.IDLE.name(), OPS.IDLE.name(), false); - - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - invokeAgain(ping, OPS.POKE.name(), false); - TestUtil.sleepMsec(500); - - invokeAgain(OPS.POKE.name(), OPS.POKE.name(), true); - } - - /* - * @testName: sendPongDelaysTimoutOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:88; WebSocket:SPEC:WSC-2.2.5-2; - * - * @test_Strategy: Allows the developer to send an unsolicited Pong message - * containing the given application data in order to serve as a unidirectional - * heartbeat for the session. - * - * if the implementation receives a pong message addressed to this endpoint, - * it must call that MessageHandler or that annotated message - */ - public void sendPongDelaysTimoutOnClientTest() throws Exception { - setClientEndpoint(PongMessageClientEndpoint.class); - invoke("server", OPS.POKE.name(), OPS.POKE.name(), false); - getSession().setMaxIdleTimeout(1500L); - - setCountDownLatchCount(5); - setProperty(Property.CONTENT, OPS.PONG_4_TIMES.name()); - setProperty(Property.SEARCH_STRING, OPS.POKE.name(), OPS.POKE.name(), - OPS.POKE.name(), OPS.POKE.name()); - setProperty(Property.SEARCH_STRING_IGNORE_CASE); - setProperty(Property.SEARCH_STRING_IGNORE_CASE, RESPONSE[0]); - invokeAgain(true); - } - - /* - * @testName: sendPongThrowsOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:90; - * - * @test_Strategy: throws IllegalArgumentException - if the applicationData - * exceeds the maximum allowed payload of 125 bytes - */ - public void sendPongThrowsOnServerTest() throws Exception { - invoke("server", OPS.SEND_PONG_THROWS, RESPONSE[0]); - } - - /* - * @testName: sendPongThrowsOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:90; - * - * @test_Strategy: throws IllegalArgumentException - if the applicationData - * exceeds the maximum allowed payload of 125 bytes - */ - public void sendPongThrowsOnClientTest() throws Exception { - sendOnClientThrows(OPS.SEND_PONG_THROWS); - } - - // ///////////////////////////////////////////////////////////////////////// - private String search(Object... ops) { - return StringUtil.objectsToStringWithDelimiter("|", (Object[]) ops); - } - - private void sendOnServer(OPS ops) throws Exception { - sendOnServer(ops, ops); - } - - private void sendOnServer(OPS ops, Object search) throws Exception { - sendOnServer(ops, search, BinaryAndTextClientEndpoint.class); - } - - private void sendOnServer(OPS ops, Object search, - Class> endpoint) throws Exception { - setCountDownLatchCount(3); - setProperty(Property.CONTENT, ops.name()); - setProperty(Property.REQUEST, buildRequest("server")); - setProperty(Property.UNORDERED_SEARCH_STRING, - search(search, OPS.POKE, RESPONSE[0])); - PokingEndpointCallback callback = new PokingEndpointCallback(entity); - setClientCallback(callback); - setClientEndpoint(endpoint); - invoke(); - } - - private void sendOnClient(final OPS op) throws Exception { - sendOnClient(op, op.name()); - } - - private void sendOnClient(final OPS op, String search) throws Exception { - EndpointCallback callback = new BasicEndpointCallback() { - @Override - void doBasic(Basic basicRemote) throws Exception { - String ret = null; - String method = null; - switch (op) { - case SENDBINARY: - ret = WSCServerSideServer.sendBinary(basicRemote); - method = "sendBinary(ByteBuffer)"; - break; - case SENDBINARYPART1: - ret = WSCServerSideServer.sendBinaryPartial(basicRemote); - method = "sendBinary(ByteBuffer, boolean)"; - break; - case SENDOBJECT: - ret = WSCServerSideServer.sendObject(basicRemote); - method = "sendObject(Object)"; - break; - case SENDOBJECT_BOOL: - ret = WSCServerSideServer.sendObject(basicRemote, boolean.class); - method = "sendObject(boolean)"; - break; - case SENDOBJECT_BYTE: - ret = WSCServerSideServer.sendObject(basicRemote, byte.class); - method = "sendObject(byte)"; - break; - case SENDOBJECT_CHAR: - ret = WSCServerSideServer.sendObject(basicRemote, char.class); - method = "sendObject(char)"; - break; - case SENDOBJECT_DOUBLE: - ret = WSCServerSideServer.sendObject(basicRemote, double.class); - method = "sendObject(double)"; - break; - case SENDOBJECT_FLOAT: - ret = WSCServerSideServer.sendObject(basicRemote, float.class); - method = "sendObject(float)"; - break; - case SENDOBJECT_INT: - ret = WSCServerSideServer.sendObject(basicRemote, int.class); - method = "sendObject(int)"; - break; - case SENDOBJECT_LONG: - ret = WSCServerSideServer.sendObject(basicRemote, long.class); - method = "sendObject(long)"; - break; - case SENDOBJECT_SHORT: - ret = WSCServerSideServer.sendObject(basicRemote, short.class); - method = "sendObject(short)"; - break; - case SENDTEXT: - ret = WSCServerSideServer.sendText(basicRemote); - method = "sendText(String)"; - break; - case SENDTEXTPART1: - ret = WSCServerSideServer.sendTextPartial(basicRemote); - method = "sendText(String, boolean)"; - break; - case SENDSTREAM: - ret = WSCServerSideServer.getSendStream(basicRemote); - method = "getSendStream()"; - break; - case SENDWRITER: - ret = WSCServerSideServer.getSendWriter(basicRemote); - method = "getSendWriter()"; - break; - case BATCHING_ALLOWED: - ret = WSCServerSideServer.batchingAllowed(basicRemote); - method = "setBatchingAllowed(!getBatchingAllowed)"; - break; - case SEND_PING: - ret = WSCServerSideServer.sendPing(basicRemote); - method = "sendPing(ByteBuffer)"; - break; - case SEND_PONG: - ret = WSCServerSideServer.sendPong(basicRemote); - method = "sendPong(ByteBuffer)"; - break; - default: - fault("Method", op, "not implemented"); - } - assertEquals(RESPONSE[0], ret, method, "did not endup as expected"); - logMsg(method, "works as expected"); - } - }; - setClientCallback(callback); - - // Add StringBean encoder just for sendObject methods - List> list = new LinkedList<>(); - list.add(StringBeanTextEncoder.class); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .encoders(list).build(); - setClientEndpointConfig(config); - - invoke("client", "anything", search); - } - - private void sendOnClientThrows(final OPS op) throws Exception { - EndpointCallback callback = new BasicEndpointCallback() { - @Override - void doBasic(Basic basicRemote) throws Exception { - String ret = null; - String method = null; - switch (op) { - case SENDBINARYTHROWS: - ret = WSCServerSideServer.sendBinaryThrows(basicRemote); - method = "sendBinary(ByteBuffer)"; - break; - case SENDOBJECTTHROWS: - ret = WSCServerSideServer.sendObjectThrows(basicRemote); - method = "sendObject(Object)"; - break; - case SENDTEXTTHROWS: - ret = WSCServerSideServer.sendTextThrows(basicRemote); - method = "sendText(String)"; - break; - case SEND_PING_THROWS: - ret = WSCServerSideServer.sendPingThrows(basicRemote); - method = "sendPing()"; - break; - case SEND_PONG_THROWS: - ret = WSCServerSideServer.sendPongThrows(basicRemote); - method = "sendPong()"; - break; - default: - fault("Method", op, "not implemented"); - } - assertEquals(RESPONSE[0], ret, method, - "does not throw IllegalArgumentException as expected"); - logMsg(method, "throws IllegalArgumentException as expected"); - try { - basicRemote.sendText(entity.getEntityAt(String.class, 0)); - } catch (IOException e) { - fault(e); - } - } - }; - setClientCallback(callback); - invoke("client", ECHO, ECHO); - } - - private void sendOnClientThrowsException(final OPS op, final String exception) - throws Exception { - EndpointCallback callback = new BasicEndpointCallback() { - @Override - void doBasic(Basic basicRemote) throws Exception { - String ret = null; - String method = null; - switch (op) { - case SENDOBJECTTHROWSENCODEEEXCEPTION: - ret = WSCServerSideServer - .sendObjectThrowsEncodeException(basicRemote); - method = "sendObject(Object)"; - break; - default: - fault("Method", op, "not implemented"); - } - assertEquals(RESPONSE[0], ret, method, "does not throw", exception, - "as expected"); - logMsg(method, "throws", exception, "as expected"); - try { - basicRemote.sendText(entity.getEntityAt(String.class, 0)); - } catch (IOException e) { - fault(e); - } - } - }; - // Add ThrowingEncoder encoder just for sendObject methods - List> list = new LinkedList<>(); - list.add(ThrowingEncoder.class); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .encoders(list).build(); - setClientEndpointConfig(config); - setClientCallback(callback); - invoke("client", ECHO, ECHO); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSClientIT.java new file mode 100644 index 0000000000..876d4483a9 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/basic/WSClientIT.java @@ -0,0 +1,1037 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.basic; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.client.BinaryAndTextClientEndpoint; +import com.sun.ts.tests.websocket.common.client.ClientEndpoint; +import com.sun.ts.tests.websocket.common.client.EndpointCallback; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.StringPingMessage; +import com.sun.ts.tests.websocket.common.impl.StringPongMessage; +import com.sun.ts.tests.websocket.common.impl.WaitingSendHandler; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextEncoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.common.util.StringUtil; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.PongMessageClientEndpoint; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.Encoder; +import jakarta.websocket.RemoteEndpoint.Basic; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = -8530759310254161854L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_ee_jakarta_websocket_remoteendpoint_basic_web.war"); + archive.addPackages(true, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.basic"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(WaitingSendHandler.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + static final String[] RESPONSE = WSCServerSideServer.RESPONSE; + + static final String ECHO = "echo"; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_jakarta_websocket_remoteendpoint_basic_web"); + } + + /* Run test */ + + /* + * @testName: sendBinaryOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:105; + * + * @test_Strategy: Send a binary message, returning when all of the message has + * been transmitted. + */ + @Test + public void sendBinaryOnServerTest() throws Exception { + sendOnServer(OPS.SENDBINARY); + } + + /* + * @testName: sendBinaryOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:107; + * + * @test_Strategy: Send a binary message, returning when all of the message has + * been transmitted. + */ + @Test + public void sendBinaryOnClientTest() throws Exception { + sendOnClient(OPS.SENDBINARY); + } + + /* + * @testName: sendBinaryPartialOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:107; + * + * @test_Strategy: Send a binary message, returning when all of the message has + * been transmitted. + */ + @Test + public void sendBinaryPartialOnServerTest() throws Exception { + sendOnServer(OPS.SENDBINARYPART1, + OPS.SENDBINARYPART1.name() + OPS.SENDBINARYPART2.name() + OPS.SENDBINARYPART3.name()); + } + + /* + * @testName: sendBinaryPartialOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:105; + * + * @test_Strategy: Send a binary message, returning when all of the message has + * been transmitted. + */ + @Test + public void sendBinaryPartialOnClientTest() throws Exception { + sendOnClient(OPS.SENDBINARYPART1, + OPS.SENDBINARYPART1.name() + OPS.SENDBINARYPART2.name() + OPS.SENDBINARYPART3.name()); + } + + /* + * @testName: sendBinaryThrowsIAEOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:105; + * + * @test_Strategy: Throws: IllegalArgumentException - if the data is null. + */ + @Test + public void sendBinaryThrowsIAEOnServerTest() throws Exception { + invoke("server", OPS.SENDBINARYTHROWS.name(), RESPONSE[0]); + } + + /* + * @testName: sendBinaryThrowsIAEOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:105; + * + * @test_Strategy: Throws: IllegalArgumentException - if the data is null. + */ + @Test + public void sendBinaryThrowsIAEOnClientTest() throws Exception { + sendOnClientThrows(OPS.SENDBINARYTHROWS); + } + + /* + * @testName: sendObjectOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT); + } + + /* + * @testName: sendObjectOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT); + } + + /* + * @testName: sendObjectBooleanOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectBooleanOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_BOOL, false); + } + + /* + * @testName: sendObjectBooleanOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectBooleanOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_BOOL, String.valueOf(false)); + } + + /* + * @testName: sendObjectByteOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectByteOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_BYTE, -100); + } + + /* + * @testName: sendObjectByteOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectByteOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_BYTE, "-100"); + } + + /* + * @testName: sendObjectCharOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectCharOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_CHAR, String.valueOf((char) 106)); + } + + /* + * @testName: sendObjectCharOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectCharOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_CHAR, String.valueOf((char) 106)); + } + + /* + * @testName: sendObjectDoubleOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectDoubleOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_DOUBLE, -105d); + } + + /* + * @testName: sendObjectDoubleOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectDoubleOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_DOUBLE, "-105"); + } + + /* + * @testName: sendObjectFloatOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectFloatOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_FLOAT, -104f); + } + + /* + * @testName: sendObjectFloatOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectFloatOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_FLOAT, "-104"); + } + + /* + * @testName: sendObjectIntOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectIntOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_INT, -102); + } + + /* + * @testName: sendObjectIntOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectIntOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_INT, "-102"); + } + + /* + * @testName: sendObjectLongOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectLongOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_LONG, -103L); + } + + /* + * @testName: sendObjectLongOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectLongOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_LONG, "-103"); + } + + /* + * @testName: sendObjectShortOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectShortOnServerTest() throws Exception { + sendOnServer(OPS.SENDOBJECT_SHORT, -101); + } + + /* + * @testName: sendObjectShortOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Sends a custom developer object, blocking until it has been + * transmitted. + */ + @Test + public void sendObjectShortOnClientTest() throws Exception { + sendOnClient(OPS.SENDOBJECT_SHORT, "-101"); + } + + /* + * @testName: sendObjectThrowsIAEOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Throws: IllegalArgumentException - if the data is null. + */ + @Test + public void sendObjectThrowsIAEOnServerTest() throws Exception { + invoke("server", OPS.SENDOBJECTTHROWS.name(), RESPONSE[0]); + } + + /* + * @testName: sendObjectThrowsIAEOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; + * + * @test_Strategy: Throws: IllegalArgumentException - if the data is null. + */ + @Test + public void sendObjectThrowsIAEOnClientTest() throws Exception { + sendOnClientThrows(OPS.SENDOBJECTTHROWS); + } + + /* + * @testName: sendObjectThrowsEncodeExceptionOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:111; + * + * @test_Strategy: Throws: EncodeException - if there was a problem encoding the + * message object into the form of a native websocket message + */ + @Test + public void sendObjectThrowsEncodeExceptionOnServerTest() throws Exception { + invoke("server", OPS.SENDOBJECTTHROWSENCODEEEXCEPTION.name(), RESPONSE[0]); + } + + /* + * @testName: sendObjectThrowsEncodeExceptionOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:111; + * + * @test_Strategy: Throws: EncodeException - if there was a problem encoding the + * message object into the form of a native websocket message + */ + @Test + public void sendObjectThrowsEncodeExceptionOnClientTest() throws Exception { + sendOnClientThrowsException(OPS.SENDOBJECTTHROWSENCODEEEXCEPTION, "EncodeException"); + } + + /* + * @testName: sendTextOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:112; + * + * @test_Strategy: Send a text message, blocking until all of the message has + * been transmitted. + */ + @Test + public void sendTextOnServerTest() throws Exception { + sendOnServer(OPS.SENDTEXT); + } + + /* + * @testName: sendTextOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:114; + * + * @test_Strategy: Send a text message, blocking until all of the message has + * been transmitted. + */ + @Test + public void sendTextOnClientTest() throws Exception { + sendOnClient(OPS.SENDTEXT); + } + + /* + * @testName: sendTextPartialOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:114; + * + * @test_Strategy: Send a text message, blocking until all of the message has + * been transmitted. + */ + @Test + public void sendTextPartialOnServerTest() throws Exception { + sendOnServer(OPS.SENDTEXTPART1, OPS.SENDTEXTPART1.name() + OPS.SENDTEXTPART2.name() + OPS.SENDTEXTPART3.name()); + } + + /* + * @testName: sendTextPartialOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:112; + * + * @test_Strategy: Send a text message, blocking until all of the message has + * been transmitted. + */ + @Test + public void sendTextPartialOnClientTest() throws Exception { + sendOnClient(OPS.SENDTEXTPART1, OPS.SENDTEXTPART1.name() + OPS.SENDTEXTPART2.name() + OPS.SENDTEXTPART3.name()); + } + + /* + * @testName: sendTextThrowsIAEOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:112; + * + * @test_Strategy: Throws: IllegalArgumentException - if the text is null. + */ + @Test + public void sendTextThrowsIAEOnServerTest() throws Exception { + invoke("server", OPS.SENDTEXTTHROWS.name(), RESPONSE[0]); + } + + /* + * @testName: sendTextThrowsIAEOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:112; + * + * @test_Strategy: Throws: IllegalArgumentException - if the text is null. + */ + @Test + public void sendTextThrowsIAEOnClientTest() throws Exception { + sendOnClientThrows(OPS.SENDTEXTTHROWS); + } + + /* + * @testName: getSendStreamOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:101; + * + * @test_Strategy: Opens an output stream on which a binary message may be sent. + * The developer must close the output stream in order to indicate that the + * complete message has been placed into the output stream. + */ + @Test + public void getSendStreamOnServerTest() throws Exception { + sendOnServer(OPS.SENDSTREAM); + } + + /* + * @testName: getSendStreamOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:101; + * + * @test_Strategy: Opens an output stream on which a binary message may be sent. + * The developer must close the output stream in order to indicate that the + * complete message has been placed into the output stream. + */ + @Test + public void getSendStreamOnClientTest() throws Exception { + sendOnClient(OPS.SENDSTREAM); + } + + /* + * @testName: getSendWriterOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:103; + * + * @test_Strategy: Opens an output stream on which a binary message may be sent. + * The developer must close the writer in order to indicate that the complete + * message has been placed into the character stream. + */ + @Test + public void getSendWriterOnServerTest() throws Exception { + sendOnServer(OPS.SENDWRITER); + } + + /* + * @testName: getSendWriterOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:103; + * + * @test_Strategy: Opens an output stream on which a binary message may be sent. + * The developer must close the writer in order to indicate that the complete + * message has been placed into the character stream. + */ + @Test + public void getSendWriterOnClientTest() throws Exception { + sendOnClient(OPS.SENDWRITER); + } + + /* + * @testName: batchingAllowedOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:84;WebSocket:JAVADOC:91; + * + * @test_Strategy: calls setBatchingAllowed(!getBatchingAllowed()) and checks no + * exception is thrown + */ + @Test + public void batchingAllowedOnServerTest() throws Exception { + sendOnServer(OPS.BATCHING_ALLOWED); + } + + /* + * @testName: batchingAllowedOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:84;WebSocket:JAVADOC:91; + * + * @test_Strategy: calls setBatchingAllowed(!getBatchingAllowed()) and checks no + * exception is thrown + */ + @Test + public void batchingAllowedOnClientTest() throws Exception { + sendOnClient(OPS.BATCHING_ALLOWED); + } + + /* + * @testName: sendPingOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:85; + * + * @test_Strategy: Send a Ping message containing the given application data to + * the remote endpoint. The corresponding Pong message may be picked up using + * the MessageHandler.Pong handler + */ + @Test + public void sendPingOnServerTest() throws Exception { + setCountDownLatchCount(2); + setProperty(Property.CONTENT, OPS.SEND_PING.name()); + setProperty(Property.REQUEST, buildRequest("server")); + // first server sends ping, websocket impl responses with pong + // then server sends ok and the pong is caught back on server + // and pong data are send back to client + setProperty(Property.UNORDERED_SEARCH_STRING, search(RESPONSE[0], OPS.SEND_PING)); + invoke(); + } + + /* + * @testName: sendPingOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:85; + * + * @test_Strategy: Send a Ping message containing the given application data to + * the remote endpoint. The corresponding Pong message may be picked up using + * the MessageHandler.Pong handler + */ + @Test + public void sendPingOnClientTest() throws Exception { + setClientEndpoint(PongMessageClientEndpoint.class); + sendOnClient(OPS.SEND_PING); + } + + /* + * @testName: sendPingDelaysTimoutOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:85; WebSocket:SPEC:WSC-2.2.5-1; + * WebSocket:SPEC:WSC-2.2.5-2; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + * + * if a websocket implementation receives a ping message from a peer, it must + * respond as soon as possible to that peer with a pong message containing the + * same application data. + * + * if the implementation receives a pong message addressed to this endpoint, it + * must call that MessageHandler or that annotated message + */ + @Test + public void sendPingDelaysTimoutOnServerTest() throws Exception { + StringPingMessage ping = new StringPingMessage(OPS.POKE.name()); + setClientEndpoint(PongMessageClientEndpoint.class); + invoke("server", OPS.IDLE.name(), OPS.IDLE.name(), false); + + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + + invokeAgain(OPS.POKE.name(), OPS.POKE.name(), true); + } + + /* + * @testName: sendPingDelaysTimoutOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:85; WebSocket:SPEC:WSC-2.2.5-1; + * WebSocket:SPEC:WSC-2.2.5-2; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + * + * if a websocket implementation receives a ping message from a peer, it must + * respond as soon as possible to that peer with a pong message containing the + * same application data. + * + * if the implementation receives a pong message addressed to this endpoint, it + * must call that MessageHandler or that annotated message + */ + @Test + public void sendPingDelaysTimoutOnClientTest() throws Exception { + setClientEndpoint(PongMessageClientEndpoint.class); + invoke("server", OPS.POKE.name(), OPS.POKE.name(), false); + getSession().setMaxIdleTimeout(1500L); + + setCountDownLatchCount(5); + setProperty(Property.CONTENT, OPS.PING_4_TIMES.name()); + setProperty(Property.SEARCH_STRING, OPS.POKE.name(), OPS.POKE.name(), OPS.POKE.name(), OPS.POKE.name()); + setProperty(Property.SEARCH_STRING_IGNORE_CASE); + setProperty(Property.SEARCH_STRING_IGNORE_CASE, RESPONSE[0]); + invokeAgain(true); + } + + /* + * @testName: sendPingThrowsOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:87; + * + * @test_Strategy: throws IllegalArgumentException - if the applicationData + * exceeds the maximum allowed payload of 125 bytes + */ + @Test + public void sendPingThrowsOnServerTest() throws Exception { + invoke("server", OPS.SEND_PING_THROWS, RESPONSE[0]); + } + + /* + * @testName: sendPingThrowsOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:87; + * + * @test_Strategy: throws IllegalArgumentException - if the applicationData + * exceeds the maximum allowed payload of 125 bytes + */ + @Test + public void sendPingThrowsOnClientTest() throws Exception { + sendOnClientThrows(OPS.SEND_PING_THROWS); + } + + /* + * @testName: sendPongOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:88; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + */ + @Test + public void sendPongOnServerTest() throws Exception { + sendOnServer(OPS.SEND_PONG, OPS.SEND_PONG.name(), PongMessageClientEndpoint.class); + } + + /* + * @testName: sendPongOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:88; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + */ + @Test + public void sendPongOnClientTest() throws Exception { + sendOnClient(OPS.SEND_PONG); + } + + /* + * @testName: sendPongDelaysTimoutOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:88; WebSocket:SPEC:WSC-2.2.5-2; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + * + * if the implementation receives a pong message addressed to this endpoint, it + * must call that MessageHandler or that annotated message + */ + @Test + public void sendPongDelaysTimoutOnServerTest() throws Exception { + StringPongMessage ping = new StringPongMessage(OPS.POKE.name()); + setClientEndpoint(PongMessageClientEndpoint.class); + invoke("server", OPS.IDLE.name(), OPS.IDLE.name(), false); + + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + invokeAgain(ping, OPS.POKE.name(), false); + TestUtil.sleepMsec(500); + + invokeAgain(OPS.POKE.name(), OPS.POKE.name(), true); + } + + /* + * @testName: sendPongDelaysTimoutOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:88; WebSocket:SPEC:WSC-2.2.5-2; + * + * @test_Strategy: Allows the developer to send an unsolicited Pong message + * containing the given application data in order to serve as a unidirectional + * heartbeat for the session. + * + * if the implementation receives a pong message addressed to this endpoint, it + * must call that MessageHandler or that annotated message + */ + @Test + public void sendPongDelaysTimoutOnClientTest() throws Exception { + setClientEndpoint(PongMessageClientEndpoint.class); + invoke("server", OPS.POKE.name(), OPS.POKE.name(), false); + getSession().setMaxIdleTimeout(1500L); + + setCountDownLatchCount(5); + setProperty(Property.CONTENT, OPS.PONG_4_TIMES.name()); + setProperty(Property.SEARCH_STRING, OPS.POKE.name(), OPS.POKE.name(), OPS.POKE.name(), OPS.POKE.name()); + setProperty(Property.SEARCH_STRING_IGNORE_CASE); + setProperty(Property.SEARCH_STRING_IGNORE_CASE, RESPONSE[0]); + invokeAgain(true); + } + + /* + * @testName: sendPongThrowsOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:90; + * + * @test_Strategy: throws IllegalArgumentException - if the applicationData + * exceeds the maximum allowed payload of 125 bytes + */ + @Test + public void sendPongThrowsOnServerTest() throws Exception { + invoke("server", OPS.SEND_PONG_THROWS, RESPONSE[0]); + } + + /* + * @testName: sendPongThrowsOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:90; + * + * @test_Strategy: throws IllegalArgumentException - if the applicationData + * exceeds the maximum allowed payload of 125 bytes + */ + @Test + public void sendPongThrowsOnClientTest() throws Exception { + sendOnClientThrows(OPS.SEND_PONG_THROWS); + } + + // ///////////////////////////////////////////////////////////////////////// + private String search(Object... ops) { + return StringUtil.objectsToStringWithDelimiter("|", (Object[]) ops); + } + + private void sendOnServer(OPS ops) throws Exception { + sendOnServer(ops, ops); + } + + private void sendOnServer(OPS ops, Object search) throws Exception { + sendOnServer(ops, search, BinaryAndTextClientEndpoint.class); + } + + private void sendOnServer(OPS ops, Object search, Class> endpoint) throws Exception { + setCountDownLatchCount(3); + setProperty(Property.CONTENT, ops.name()); + setProperty(Property.REQUEST, buildRequest("server")); + setProperty(Property.UNORDERED_SEARCH_STRING, search(search, OPS.POKE, RESPONSE[0])); + PokingEndpointCallback callback = new PokingEndpointCallback(entity); + setClientCallback(callback); + setClientEndpoint(endpoint); + invoke(); + } + + private void sendOnClient(final OPS op) throws Exception { + sendOnClient(op, op.name()); + } + + private void sendOnClient(final OPS op, String search) throws Exception { + EndpointCallback callback = new BasicEndpointCallback() { + @Override + void doBasic(Basic basicRemote) throws Exception { + String ret = null; + String method = null; + switch (op) { + case SENDBINARY: + ret = WSCServerSideServer.sendBinary(basicRemote); + method = "sendBinary(ByteBuffer)"; + break; + case SENDBINARYPART1: + ret = WSCServerSideServer.sendBinaryPartial(basicRemote); + method = "sendBinary(ByteBuffer, boolean)"; + break; + case SENDOBJECT: + ret = WSCServerSideServer.sendObject(basicRemote); + method = "sendObject(Object)"; + break; + case SENDOBJECT_BOOL: + ret = WSCServerSideServer.sendObject(basicRemote, boolean.class); + method = "sendObject(boolean)"; + break; + case SENDOBJECT_BYTE: + ret = WSCServerSideServer.sendObject(basicRemote, byte.class); + method = "sendObject(byte)"; + break; + case SENDOBJECT_CHAR: + ret = WSCServerSideServer.sendObject(basicRemote, char.class); + method = "sendObject(char)"; + break; + case SENDOBJECT_DOUBLE: + ret = WSCServerSideServer.sendObject(basicRemote, double.class); + method = "sendObject(double)"; + break; + case SENDOBJECT_FLOAT: + ret = WSCServerSideServer.sendObject(basicRemote, float.class); + method = "sendObject(float)"; + break; + case SENDOBJECT_INT: + ret = WSCServerSideServer.sendObject(basicRemote, int.class); + method = "sendObject(int)"; + break; + case SENDOBJECT_LONG: + ret = WSCServerSideServer.sendObject(basicRemote, long.class); + method = "sendObject(long)"; + break; + case SENDOBJECT_SHORT: + ret = WSCServerSideServer.sendObject(basicRemote, short.class); + method = "sendObject(short)"; + break; + case SENDTEXT: + ret = WSCServerSideServer.sendText(basicRemote); + method = "sendText(String)"; + break; + case SENDTEXTPART1: + ret = WSCServerSideServer.sendTextPartial(basicRemote); + method = "sendText(String, boolean)"; + break; + case SENDSTREAM: + ret = WSCServerSideServer.getSendStream(basicRemote); + method = "getSendStream()"; + break; + case SENDWRITER: + ret = WSCServerSideServer.getSendWriter(basicRemote); + method = "getSendWriter()"; + break; + case BATCHING_ALLOWED: + ret = WSCServerSideServer.batchingAllowed(basicRemote); + method = "setBatchingAllowed(!getBatchingAllowed)"; + break; + case SEND_PING: + ret = WSCServerSideServer.sendPing(basicRemote); + method = "sendPing(ByteBuffer)"; + break; + case SEND_PONG: + ret = WSCServerSideServer.sendPong(basicRemote); + method = "sendPong(ByteBuffer)"; + break; + default: + new Exception("Method " + op + " not implemented"); + } + assertEquals(RESPONSE[0], ret, method, "did not endup as expected"); + logMsg(method, "works as expected"); + } + }; + setClientCallback(callback); + + // Add StringBean encoder just for sendObject methods + List> list = new LinkedList<>(); + list.add(StringBeanTextEncoder.class); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().encoders(list).build(); + setClientEndpointConfig(config); + + invoke("client", "anything", search); + } + + private void sendOnClientThrows(final OPS op) throws Exception { + EndpointCallback callback = new BasicEndpointCallback() { + @Override + void doBasic(Basic basicRemote) throws Exception { + String ret = null; + String method = null; + switch (op) { + case SENDBINARYTHROWS: + ret = WSCServerSideServer.sendBinaryThrows(basicRemote); + method = "sendBinary(ByteBuffer)"; + break; + case SENDOBJECTTHROWS: + ret = WSCServerSideServer.sendObjectThrows(basicRemote); + method = "sendObject(Object)"; + break; + case SENDTEXTTHROWS: + ret = WSCServerSideServer.sendTextThrows(basicRemote); + method = "sendText(String)"; + break; + case SEND_PING_THROWS: + ret = WSCServerSideServer.sendPingThrows(basicRemote); + method = "sendPing()"; + break; + case SEND_PONG_THROWS: + ret = WSCServerSideServer.sendPongThrows(basicRemote); + method = "sendPong()"; + break; + default: + new Exception("Method " + op + " not implemented"); + } + assertEquals(RESPONSE[0], ret, method, "does not throw IllegalArgumentException as expected"); + logMsg(method, "throws IllegalArgumentException as expected"); + try { + basicRemote.sendText(entity.getEntityAt(String.class, 0)); + } catch (IOException e) { + new Exception(e); + } + } + }; + setClientCallback(callback); + invoke("client", ECHO, ECHO); + } + + private void sendOnClientThrowsException(final OPS op, final String exception) throws Exception { + EndpointCallback callback = new BasicEndpointCallback() { + @Override + void doBasic(Basic basicRemote) throws Exception { + String ret = null; + String method = null; + switch (op) { + case SENDOBJECTTHROWSENCODEEEXCEPTION: + ret = WSCServerSideServer.sendObjectThrowsEncodeException(basicRemote); + method = "sendObject(Object)"; + break; + default: + new Exception("Method " + op + " not implemented"); + } + assertEquals(RESPONSE[0], ret, method, "does not throw", exception, "as expected"); + logMsg(method, "throws", exception, "as expected"); + try { + basicRemote.sendText(entity.getEntityAt(String.class, 0)); + } catch (IOException e) { + new Exception(e); + } + } + }; + // Add ThrowingEncoder encoder just for sendObject methods + List> list = new LinkedList<>(); + list.add(ThrowingEncoder.class); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().encoders(list).build(); + setClientEndpointConfig(config); + setClientCallback(callback); + invoke("client", ECHO, ECHO); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderBool.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderBool.java index 97858dff6c..912d799d1f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderBool.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderBool.java @@ -23,8 +23,8 @@ public class BinaryCoderBool extends CoderSuperClassBinary { - @Override - public Boolean decode(ByteBuffer bytes) throws DecodeException { - return BOOL; - } + @Override + public Boolean decode(ByteBuffer bytes) throws DecodeException { + return BOOL; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderByte.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderByte.java index 0b9f98fcf7..7b9f90b3f4 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderByte.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderByte.java @@ -23,8 +23,8 @@ public class BinaryCoderByte extends CoderSuperClassBinary { - @Override - public Byte decode(ByteBuffer bytes) throws DecodeException { - return NUMERIC; - } + @Override + public Byte decode(ByteBuffer bytes) throws DecodeException { + return NUMERIC; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderChar.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderChar.java index 726e6cfdc4..a327208833 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderChar.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderChar.java @@ -23,8 +23,8 @@ public class BinaryCoderChar extends CoderSuperClassBinary { - @Override - public Character decode(ByteBuffer bytes) throws DecodeException { - return CHAR; - } + @Override + public Character decode(ByteBuffer bytes) throws DecodeException { + return CHAR; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderDouble.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderDouble.java index 0365d80d4f..bcfa4a080b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderDouble.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderDouble.java @@ -23,8 +23,8 @@ public class BinaryCoderDouble extends CoderSuperClassBinary { - @Override - public Double decode(ByteBuffer bytes) throws DecodeException { - return NUMERIC.doubleValue(); - } + @Override + public Double decode(ByteBuffer bytes) throws DecodeException { + return NUMERIC.doubleValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderFloat.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderFloat.java index d7acf2a065..1c1ce0c451 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderFloat.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderFloat.java @@ -23,8 +23,8 @@ public class BinaryCoderFloat extends CoderSuperClassBinary { - @Override - public Float decode(ByteBuffer bytes) throws DecodeException { - return NUMERIC.floatValue(); - } + @Override + public Float decode(ByteBuffer bytes) throws DecodeException { + return NUMERIC.floatValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderInt.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderInt.java index 4d81d9b263..fe545c2fd7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderInt.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderInt.java @@ -23,8 +23,8 @@ public class BinaryCoderInt extends CoderSuperClassBinary { - @Override - public Long decode(ByteBuffer bytes) throws DecodeException { - return NUMERIC.longValue(); - } + @Override + public Long decode(ByteBuffer bytes) throws DecodeException { + return NUMERIC.longValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderLong.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderLong.java index d2864b8f9a..fbb64c1a6b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderLong.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderLong.java @@ -23,8 +23,8 @@ public class BinaryCoderLong extends CoderSuperClassBinary { - @Override - public Integer decode(ByteBuffer bytes) throws DecodeException { - return NUMERIC.intValue(); - } + @Override + public Integer decode(ByteBuffer bytes) throws DecodeException { + return NUMERIC.intValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderShort.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderShort.java index 4494c0da9c..c0e55a9f3b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderShort.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryCoderShort.java @@ -23,8 +23,8 @@ public class BinaryCoderShort extends CoderSuperClassBinary { - @Override - public Short decode(ByteBuffer bytes) throws DecodeException { - return NUMERIC.shortValue(); - } + @Override + public Short decode(ByteBuffer bytes) throws DecodeException { + return NUMERIC.shortValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderBool.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderBool.java index a376139f5f..773552e939 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderBool.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderBool.java @@ -22,11 +22,10 @@ import jakarta.websocket.DecodeException; -public class BinaryStreamCoderBool - extends CoderSuperClassBinaryStream { +public class BinaryStreamCoderBool extends CoderSuperClassBinaryStream { - @Override - public Boolean decode(InputStream is) throws DecodeException, IOException { - return BOOL; - } + @Override + public Boolean decode(InputStream is) throws DecodeException, IOException { + return BOOL; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderByte.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderByte.java index 9516b6e593..181bcfc1c1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderByte.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderByte.java @@ -24,8 +24,8 @@ public class BinaryStreamCoderByte extends CoderSuperClassBinaryStream { - @Override - public Byte decode(InputStream is) throws DecodeException, IOException { - return NUMERIC; - } + @Override + public Byte decode(InputStream is) throws DecodeException, IOException { + return NUMERIC; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderChar.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderChar.java index 3d36521208..fb87005c76 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderChar.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderChar.java @@ -22,11 +22,10 @@ import jakarta.websocket.DecodeException; -public class BinaryStreamCoderChar - extends CoderSuperClassBinaryStream { +public class BinaryStreamCoderChar extends CoderSuperClassBinaryStream { - @Override - public Character decode(InputStream is) throws DecodeException, IOException { - return CHAR; - } + @Override + public Character decode(InputStream is) throws DecodeException, IOException { + return CHAR; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderDouble.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderDouble.java index 846b23a5c2..d6ba7f9fb7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderDouble.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderDouble.java @@ -22,11 +22,10 @@ import jakarta.websocket.DecodeException; -public class BinaryStreamCoderDouble - extends CoderSuperClassBinaryStream { +public class BinaryStreamCoderDouble extends CoderSuperClassBinaryStream { - @Override - public Double decode(InputStream is) throws DecodeException, IOException { - return NUMERIC.doubleValue(); - } + @Override + public Double decode(InputStream is) throws DecodeException, IOException { + return NUMERIC.doubleValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderFloat.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderFloat.java index ff760084b9..c495d244bc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderFloat.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderFloat.java @@ -24,8 +24,8 @@ public class BinaryStreamCoderFloat extends CoderSuperClassBinaryStream { - @Override - public Float decode(InputStream is) throws DecodeException, IOException { - return NUMERIC.floatValue(); - } + @Override + public Float decode(InputStream is) throws DecodeException, IOException { + return NUMERIC.floatValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderInt.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderInt.java index 55a3875ae5..f740695b9b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderInt.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderInt.java @@ -24,8 +24,8 @@ public class BinaryStreamCoderInt extends CoderSuperClassBinaryStream { - @Override - public Integer decode(InputStream is) throws DecodeException, IOException { - return NUMERIC.intValue(); - } + @Override + public Integer decode(InputStream is) throws DecodeException, IOException { + return NUMERIC.intValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderLong.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderLong.java index 6880b9ce08..c307e79773 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderLong.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderLong.java @@ -24,8 +24,8 @@ public class BinaryStreamCoderLong extends CoderSuperClassBinaryStream { - @Override - public Long decode(InputStream is) throws DecodeException, IOException { - return NUMERIC.longValue(); - } + @Override + public Long decode(InputStream is) throws DecodeException, IOException { + return NUMERIC.longValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderShort.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderShort.java index 09bcc707c4..28980024dd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderShort.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/BinaryStreamCoderShort.java @@ -24,8 +24,8 @@ public class BinaryStreamCoderShort extends CoderSuperClassBinaryStream { - @Override - public Short decode(InputStream is) throws DecodeException, IOException { - return NUMERIC.shortValue(); - } + @Override + public Short decode(InputStream is) throws DecodeException, IOException { + return NUMERIC.shortValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClass.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClass.java index 64573dd5d8..96168c62bf 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClass.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClass.java @@ -20,19 +20,19 @@ import jakarta.websocket.EndpointConfig; public abstract class CoderSuperClass { - public static final String COMMON_CODED_STRING = "Anything that should have been coded has been coded into this"; + public static final String COMMON_CODED_STRING = "Anything that should have been coded has been coded into this"; - public static final Byte NUMERIC = 100; + public static final Byte NUMERIC = 100; - public static final char CHAR = '0'; + public static final char CHAR = '0'; - public static final boolean BOOL = false; + public static final boolean BOOL = false; - @SuppressWarnings("unused") - public void init(EndpointConfig config) { - } + @SuppressWarnings("unused") + public void init(EndpointConfig config) { + } - public void destroy() { - } + public void destroy() { + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassBinary.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassBinary.java index 43887f4d2c..36ca0b8719 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassBinary.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassBinary.java @@ -23,17 +23,16 @@ import jakarta.websocket.EncodeException; import jakarta.websocket.Encoder; -public abstract class CoderSuperClassBinary extends CoderSuperClass - implements Encoder.Binary, Decoder.Binary { +public abstract class CoderSuperClassBinary extends CoderSuperClass implements Encoder.Binary, Decoder.Binary { - @Override - public boolean willDecode(ByteBuffer bytes) { - return true; - } + @Override + public boolean willDecode(ByteBuffer bytes) { + return true; + } - @Override - public ByteBuffer encode(T object) throws EncodeException { - return ByteBuffer.wrap(COMMON_CODED_STRING.getBytes()); - } + @Override + public ByteBuffer encode(T object) throws EncodeException { + return ByteBuffer.wrap(COMMON_CODED_STRING.getBytes()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassBinaryStream.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassBinaryStream.java index 5b510a77c3..a1f00c9501 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassBinaryStream.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassBinaryStream.java @@ -25,13 +25,12 @@ import jakarta.websocket.Encoder; public abstract class CoderSuperClassBinaryStream extends CoderSuperClass - implements Encoder.BinaryStream, Decoder.BinaryStream { + implements Encoder.BinaryStream, Decoder.BinaryStream { - @Override - public void encode(T object, OutputStream os) - throws EncodeException, IOException { - os.write(COMMON_CODED_STRING.getBytes()); - os.close(); - } + @Override + public void encode(T object, OutputStream os) throws EncodeException, IOException { + os.write(COMMON_CODED_STRING.getBytes()); + os.close(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassText.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassText.java index 91936c0833..9fdf628509 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassText.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassText.java @@ -21,17 +21,16 @@ import jakarta.websocket.EncodeException; import jakarta.websocket.Encoder; -public abstract class CoderSuperClassText extends CoderSuperClass - implements Encoder.Text, Decoder.Text { +public abstract class CoderSuperClassText extends CoderSuperClass implements Encoder.Text, Decoder.Text { - @Override - public boolean willDecode(String bytes) { - return true; - } + @Override + public boolean willDecode(String bytes) { + return true; + } - @Override - public String encode(T object) throws EncodeException { - return COMMON_CODED_STRING; - } + @Override + public String encode(T object) throws EncodeException { + return COMMON_CODED_STRING; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassTextStream.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassTextStream.java index 953969c203..55956a4247 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassTextStream.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/CoderSuperClassTextStream.java @@ -25,16 +25,16 @@ import jakarta.websocket.Encoder; public abstract class CoderSuperClassTextStream extends CoderSuperClass - implements Encoder.TextStream, Decoder.TextStream { + implements Encoder.TextStream, Decoder.TextStream { - @Override - public void encode(T object, Writer writer) throws EncodeException { - try { - writer.write(COMMON_CODED_STRING); - writer.close(); - } catch (IOException e) { - throw new EncodeException(object, COMMON_CODED_STRING, e); - } - } + @Override + public void encode(T object, Writer writer) throws EncodeException { + try { + writer.write(COMMON_CODED_STRING); + writer.close(); + } catch (IOException e) { + throw new EncodeException(object, COMMON_CODED_STRING, e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/OPS.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/OPS.java index 3247a7103d..2319976ada 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/OPS.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/OPS.java @@ -17,14 +17,12 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder; public enum OPS { - CHAR, BOOL, BYTE, SHORT, INT, LONG, FLOAT, DOUBLE; + CHAR, BOOL, BYTE, SHORT, INT, LONG, FLOAT, DOUBLE; - public static Object[] getClientEntities() { - return new Object[] { CoderSuperClass.BOOL, CoderSuperClass.CHAR, - CoderSuperClass.NUMERIC.byteValue(), - CoderSuperClass.NUMERIC.shortValue(), - CoderSuperClass.NUMERIC.intValue(), CoderSuperClass.NUMERIC.longValue(), - CoderSuperClass.NUMERIC.floatValue(), - CoderSuperClass.NUMERIC.doubleValue() }; - } + public static Object[] getClientEntities() { + return new Object[] { CoderSuperClass.BOOL, CoderSuperClass.CHAR, CoderSuperClass.NUMERIC.byteValue(), + CoderSuperClass.NUMERIC.shortValue(), CoderSuperClass.NUMERIC.intValue(), + CoderSuperClass.NUMERIC.longValue(), CoderSuperClass.NUMERIC.floatValue(), + CoderSuperClass.NUMERIC.doubleValue() }; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderBool.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderBool.java index c44a708c27..8ddbb37a21 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderBool.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderBool.java @@ -21,8 +21,8 @@ public class TextCoderBool extends CoderSuperClassText { - @Override - public Boolean decode(String s) throws DecodeException { - return BOOL; - } + @Override + public Boolean decode(String s) throws DecodeException { + return BOOL; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderByte.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderByte.java index 991d62edcb..38b5658b85 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderByte.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderByte.java @@ -21,8 +21,8 @@ public class TextCoderByte extends CoderSuperClassText { - @Override - public Byte decode(String s) throws DecodeException { - return NUMERIC; - } + @Override + public Byte decode(String s) throws DecodeException { + return NUMERIC; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderChar.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderChar.java index d24e38f1bd..fbb62742cc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderChar.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderChar.java @@ -21,8 +21,8 @@ public class TextCoderChar extends CoderSuperClassText { - @Override - public Character decode(String s) throws DecodeException { - return CHAR; - } + @Override + public Character decode(String s) throws DecodeException { + return CHAR; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderDouble.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderDouble.java index bd33219b7e..4ada97e711 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderDouble.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderDouble.java @@ -21,8 +21,8 @@ public class TextCoderDouble extends CoderSuperClassText { - @Override - public Double decode(String s) throws DecodeException { - return NUMERIC.doubleValue(); - } + @Override + public Double decode(String s) throws DecodeException { + return NUMERIC.doubleValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderFloat.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderFloat.java index ef1bfea931..cbb80331fa 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderFloat.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderFloat.java @@ -21,8 +21,8 @@ public class TextCoderFloat extends CoderSuperClassText { - @Override - public Float decode(String s) throws DecodeException { - return NUMERIC.floatValue(); - } + @Override + public Float decode(String s) throws DecodeException { + return NUMERIC.floatValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderInt.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderInt.java index a7f985949e..0b75322151 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderInt.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderInt.java @@ -21,8 +21,8 @@ public class TextCoderInt extends CoderSuperClassText { - @Override - public Integer decode(String s) throws DecodeException { - return NUMERIC.intValue(); - } + @Override + public Integer decode(String s) throws DecodeException { + return NUMERIC.intValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderLong.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderLong.java index 6ba778ccfd..578cadd2d7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderLong.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderLong.java @@ -21,8 +21,8 @@ public class TextCoderLong extends CoderSuperClassText { - @Override - public Long decode(String s) throws DecodeException { - return NUMERIC.longValue(); - } + @Override + public Long decode(String s) throws DecodeException { + return NUMERIC.longValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderShort.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderShort.java index 45c49785f4..d75fff3ca7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderShort.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextCoderShort.java @@ -21,8 +21,8 @@ public class TextCoderShort extends CoderSuperClassText { - @Override - public Short decode(String s) throws DecodeException { - return NUMERIC.shortValue(); - } + @Override + public Short decode(String s) throws DecodeException { + return NUMERIC.shortValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderBool.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderBool.java index 5b887bb3dd..b4d7b87661 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderBool.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderBool.java @@ -24,8 +24,8 @@ public class TextStreamCoderBool extends CoderSuperClassTextStream { - @Override - public Boolean decode(Reader reader) throws DecodeException, IOException { - return BOOL; - } + @Override + public Boolean decode(Reader reader) throws DecodeException, IOException { + return BOOL; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderByte.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderByte.java index e7678a3343..0f875e7467 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderByte.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderByte.java @@ -24,8 +24,8 @@ public class TextStreamCoderByte extends CoderSuperClassTextStream { - @Override - public Byte decode(Reader reader) throws DecodeException, IOException { - return NUMERIC; - } + @Override + public Byte decode(Reader reader) throws DecodeException, IOException { + return NUMERIC; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderChar.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderChar.java index fdd554a307..4ad121911a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderChar.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderChar.java @@ -24,8 +24,8 @@ public class TextStreamCoderChar extends CoderSuperClassTextStream { - @Override - public Character decode(Reader reader) throws DecodeException, IOException { - return CHAR; - } + @Override + public Character decode(Reader reader) throws DecodeException, IOException { + return CHAR; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderDouble.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderDouble.java index 5fd5ff54f7..d24469d138 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderDouble.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderDouble.java @@ -24,8 +24,8 @@ public class TextStreamCoderDouble extends CoderSuperClassTextStream { - @Override - public Double decode(Reader reader) throws DecodeException, IOException { - return NUMERIC.doubleValue(); - } + @Override + public Double decode(Reader reader) throws DecodeException, IOException { + return NUMERIC.doubleValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderFloat.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderFloat.java index ac3de6f2ad..6ff19e2e9f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderFloat.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderFloat.java @@ -24,8 +24,8 @@ public class TextStreamCoderFloat extends CoderSuperClassTextStream { - @Override - public Float decode(Reader reader) throws DecodeException, IOException { - return NUMERIC.floatValue(); - } + @Override + public Float decode(Reader reader) throws DecodeException, IOException { + return NUMERIC.floatValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderInt.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderInt.java index c326b0de0b..1fd67e5a83 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderInt.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderInt.java @@ -24,8 +24,8 @@ public class TextStreamCoderInt extends CoderSuperClassTextStream { - @Override - public Integer decode(Reader reader) throws DecodeException, IOException { - return NUMERIC.intValue(); - } + @Override + public Integer decode(Reader reader) throws DecodeException, IOException { + return NUMERIC.intValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderLong.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderLong.java index d07f5e1c7e..df46131f05 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderLong.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderLong.java @@ -24,8 +24,8 @@ public class TextStreamCoderLong extends CoderSuperClassTextStream { - @Override - public Long decode(Reader reader) throws DecodeException, IOException { - return NUMERIC.longValue(); - } + @Override + public Long decode(Reader reader) throws DecodeException, IOException { + return NUMERIC.longValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderShort.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderShort.java index e9ce68eeda..cffebbc18f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderShort.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/TextStreamCoderShort.java @@ -24,8 +24,8 @@ public class TextStreamCoderShort extends CoderSuperClassTextStream { - @Override - public Short decode(Reader reader) throws DecodeException, IOException { - return NUMERIC.shortValue(); - } + @Override + public Short decode(Reader reader) throws DecodeException, IOException { + return NUMERIC.shortValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCBinaryClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCBinaryClientEndpoint.java index b7c29475cb..4214512278 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCBinaryClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCBinaryClientEndpoint.java @@ -28,33 +28,33 @@ import jakarta.websocket.OnOpen; import jakarta.websocket.Session; -@ClientEndpoint(encoders = { BinaryCoderBool.class, BinaryCoderByte.class, - BinaryCoderChar.class, BinaryCoderDouble.class, BinaryCoderInt.class, - BinaryCoderLong.class, BinaryCoderFloat.class, BinaryCoderShort.class }) +@ClientEndpoint(encoders = { BinaryCoderBool.class, BinaryCoderByte.class, BinaryCoderChar.class, + BinaryCoderDouble.class, BinaryCoderInt.class, BinaryCoderLong.class, BinaryCoderFloat.class, + BinaryCoderShort.class }) public class WSCBinaryClientEndpoint extends AnnotatedStringClientEndpoint { - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } - - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } + + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCBinaryStreamClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCBinaryStreamClientEndpoint.java index ce1d4a817d..9dc6dbb666 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCBinaryStreamClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCBinaryStreamClientEndpoint.java @@ -28,36 +28,33 @@ import jakarta.websocket.OnOpen; import jakarta.websocket.Session; -@ClientEndpoint(encoders = { BinaryStreamCoderBool.class, - BinaryStreamCoderByte.class, BinaryStreamCoderChar.class, - BinaryStreamCoderDouble.class, BinaryStreamCoderInt.class, - BinaryStreamCoderLong.class, BinaryStreamCoderFloat.class, - BinaryStreamCoderShort.class }) -public class WSCBinaryStreamClientEndpoint - extends AnnotatedStringClientEndpoint { - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } - - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } +@ClientEndpoint(encoders = { BinaryStreamCoderBool.class, BinaryStreamCoderByte.class, BinaryStreamCoderChar.class, + BinaryStreamCoderDouble.class, BinaryStreamCoderInt.class, BinaryStreamCoderLong.class, + BinaryStreamCoderFloat.class, BinaryStreamCoderShort.class }) +public class WSCBinaryStreamClientEndpoint extends AnnotatedStringClientEndpoint { + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } + + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCEchoServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCEchoServer.java index a7f455dd6f..68b213c71d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCEchoServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCEchoServer.java @@ -32,33 +32,33 @@ @ServerEndpoint("/echo") public class WSCEchoServer implements MessageHandler.Whole { - Session session; + Session session; - @OnOpen - public void onOpen(Session session) { - session.addMessageHandler(this); - this.session = session; - } + @OnOpen + public void onOpen(Session session) { + session.addMessageHandler(this); + this.session = session; + } - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } - @Override - public void onMessage(ByteBuffer message) { - try { - session.getBasicRemote().sendText(IOUtil.byteBufferToString(message)); - } catch (IOException e) { - throw new RuntimeException(e); // call @OnError - } - } + @Override + public void onMessage(ByteBuffer message) { + try { + session.getBasicRemote().sendText(IOUtil.byteBufferToString(message)); + } catch (IOException e) { + throw new RuntimeException(e); // call @OnError + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCSuperEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCSuperEndpoint.java index c1ff261a56..f44f90f6a5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCSuperEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCSuperEndpoint.java @@ -17,12 +17,11 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder; public interface WSCSuperEndpoint { - public static final String ENCODED_STRING = "Anything. What ever. Does not matter."; + public static final String ENCODED_STRING = "Anything. What ever. Does not matter."; - public static final Byte NUMERIC = (byte) (CoderSuperClass.NUMERIC.byteValue() - + 100); + public static final Byte NUMERIC = (byte) (CoderSuperClass.NUMERIC.byteValue() + 100); - public static final char CHAR = '1'; + public static final char CHAR = '1'; - public static final boolean BOOL = !CoderSuperClass.BOOL; + public static final boolean BOOL = !CoderSuperClass.BOOL; } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCTextClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCTextClientEndpoint.java index 0da9690cf5..57dc9db3e5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCTextClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCTextClientEndpoint.java @@ -28,33 +28,32 @@ import jakarta.websocket.OnOpen; import jakarta.websocket.Session; -@ClientEndpoint(encoders = { TextCoderBool.class, TextCoderByte.class, - TextCoderChar.class, TextCoderDouble.class, TextCoderInt.class, - TextCoderLong.class, TextCoderFloat.class, TextCoderShort.class }) +@ClientEndpoint(encoders = { TextCoderBool.class, TextCoderByte.class, TextCoderChar.class, TextCoderDouble.class, + TextCoderInt.class, TextCoderLong.class, TextCoderFloat.class, TextCoderShort.class }) public class WSCTextClientEndpoint extends AnnotatedStringClientEndpoint { - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } - - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } + + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCTextStreamClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCTextStreamClientEndpoint.java index 9cbdd0a107..45b1713b06 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCTextStreamClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/WSCTextStreamClientEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -28,35 +28,33 @@ import jakarta.websocket.OnOpen; import jakarta.websocket.Session; -@ClientEndpoint(encoders = { TextStreamCoderBool.class, - TextStreamCoderByte.class, TextStreamCoderChar.class, - TextStreamCoderDouble.class, TextStreamCoderInt.class, - TextStreamCoderLong.class, TextStreamCoderFloat.class, - TextStreamCoderShort.class }) +@ClientEndpoint(encoders = { TextStreamCoderBool.class, TextStreamCoderByte.class, TextStreamCoderChar.class, + TextStreamCoderDouble.class, TextStreamCoderInt.class, TextStreamCoderLong.class, TextStreamCoderFloat.class, + TextStreamCoderShort.class }) public class WSCTextStreamClientEndpoint extends AnnotatedStringClientEndpoint { - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } - - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } + + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/AsyncEndpointCallback.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/AsyncEndpointCallback.java index 68b7adb90b..0dfa0de284 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/AsyncEndpointCallback.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/AsyncEndpointCallback.java @@ -27,22 +27,22 @@ import jakarta.websocket.Session; public class AsyncEndpointCallback extends EndpointCallback { - protected Entity entity; + protected Entity entity; - public AsyncEndpointCallback(Entity entity) { - super(); - this.entity = entity; - } + public AsyncEndpointCallback(Entity entity) { + super(); + this.entity = entity; + } - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - RemoteEndpoint.Async endpoint = session.getAsyncRemote(); - try { - Future future = endpoint.sendObject(entity.getEntityAt(0)); - future.get(); - } catch (Exception i) { - throw new RuntimeException(i); - } - } + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + RemoteEndpoint.Async endpoint = session.getAsyncRemote(); + try { + Future future = endpoint.sendObject(entity.getEntityAt(0)); + future.get(); + } catch (Exception i) { + throw new RuntimeException(i); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCBinaryServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCBinaryServer.java index 586286aed2..a5fc364705 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCBinaryServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCBinaryServer.java @@ -35,22 +35,21 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binary", encoders = { BinaryCoderBool.class, - BinaryCoderByte.class, BinaryCoderChar.class, BinaryCoderDouble.class, - BinaryCoderInt.class, BinaryCoderLong.class, BinaryCoderFloat.class, - BinaryCoderShort.class }) +@ServerEndpoint(value = "/binary", encoders = { BinaryCoderBool.class, BinaryCoderByte.class, BinaryCoderChar.class, + BinaryCoderDouble.class, BinaryCoderInt.class, BinaryCoderLong.class, BinaryCoderFloat.class, + BinaryCoderShort.class }) public class WSCBinaryServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) throws IOException, - EncodeException, InterruptedException, ExecutionException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) + throws IOException, EncodeException, InterruptedException, ExecutionException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCBinaryStreamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCBinaryStreamServer.java index 142f45b36b..f9c81c24d8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCBinaryStreamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCBinaryStreamServer.java @@ -35,23 +35,21 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarystream", encoders = { - BinaryStreamCoderBool.class, BinaryStreamCoderByte.class, - BinaryStreamCoderChar.class, BinaryStreamCoderDouble.class, - BinaryStreamCoderInt.class, BinaryStreamCoderLong.class, - BinaryStreamCoderFloat.class, BinaryStreamCoderShort.class }) +@ServerEndpoint(value = "/binarystream", encoders = { BinaryStreamCoderBool.class, BinaryStreamCoderByte.class, + BinaryStreamCoderChar.class, BinaryStreamCoderDouble.class, BinaryStreamCoderInt.class, + BinaryStreamCoderLong.class, BinaryStreamCoderFloat.class, BinaryStreamCoderShort.class }) public class WSCBinaryStreamServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) throws IOException, - EncodeException, InterruptedException, ExecutionException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) + throws IOException, EncodeException, InterruptedException, ExecutionException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCCommonServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCCommonServer.java index 6f4f16e327..8f5ea9237c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCCommonServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCCommonServer.java @@ -29,43 +29,43 @@ import jakarta.websocket.Session; public abstract class WSCCommonServer implements WSCSuperEndpoint { - public void onMessage(String msg, Session session) throws IOException, - EncodeException, InterruptedException, ExecutionException { - OPS op = OPS.valueOf(msg); - Future future = null; - switch (op) { - case BOOL: - future = session.getAsyncRemote().sendObject(BOOL); - break; - case BYTE: - future = session.getAsyncRemote().sendObject(NUMERIC.byteValue()); - break; - case CHAR: - future = session.getAsyncRemote().sendObject(CHAR); - break; - case DOUBLE: - future = session.getAsyncRemote().sendObject(NUMERIC.doubleValue()); - break; - case FLOAT: - future = session.getAsyncRemote().sendObject(NUMERIC.floatValue()); - break; - case INT: - future = session.getAsyncRemote().sendObject(NUMERIC.intValue()); - break; - case LONG: - future = session.getAsyncRemote().sendObject(NUMERIC.longValue()); - break; - case SHORT: - future = session.getAsyncRemote().sendObject(NUMERIC.shortValue()); - break; - } - future.get(); - } + public void onMessage(String msg, Session session) + throws IOException, EncodeException, InterruptedException, ExecutionException { + OPS op = OPS.valueOf(msg); + Future future = null; + switch (op) { + case BOOL: + future = session.getAsyncRemote().sendObject(BOOL); + break; + case BYTE: + future = session.getAsyncRemote().sendObject(NUMERIC.byteValue()); + break; + case CHAR: + future = session.getAsyncRemote().sendObject(CHAR); + break; + case DOUBLE: + future = session.getAsyncRemote().sendObject(NUMERIC.doubleValue()); + break; + case FLOAT: + future = session.getAsyncRemote().sendObject(NUMERIC.floatValue()); + break; + case INT: + future = session.getAsyncRemote().sendObject(NUMERIC.intValue()); + break; + case LONG: + future = session.getAsyncRemote().sendObject(NUMERIC.longValue()); + break; + case SHORT: + future = session.getAsyncRemote().sendObject(NUMERIC.shortValue()); + break; + } + future.get(); + } - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCTextServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCTextServer.java index 471bc4ac94..199c05765e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCTextServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCTextServer.java @@ -35,22 +35,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/text", encoders = { TextCoderBool.class, - TextCoderByte.class, TextCoderChar.class, TextCoderDouble.class, - TextCoderInt.class, TextCoderLong.class, TextCoderFloat.class, - TextCoderShort.class }) +@ServerEndpoint(value = "/text", encoders = { TextCoderBool.class, TextCoderByte.class, TextCoderChar.class, + TextCoderDouble.class, TextCoderInt.class, TextCoderLong.class, TextCoderFloat.class, TextCoderShort.class }) public class WSCTextServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) throws IOException, - EncodeException, InterruptedException, ExecutionException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) + throws IOException, EncodeException, InterruptedException, ExecutionException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCTextStreamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCTextStreamServer.java index 9e4085e075..a6f781580a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCTextStreamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSCTextStreamServer.java @@ -35,23 +35,21 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstream", encoders = { TextStreamCoderBool.class, - TextStreamCoderByte.class, TextStreamCoderChar.class, - TextStreamCoderDouble.class, TextStreamCoderInt.class, - TextStreamCoderLong.class, TextStreamCoderFloat.class, - TextStreamCoderShort.class }) +@ServerEndpoint(value = "/textstream", encoders = { TextStreamCoderBool.class, TextStreamCoderByte.class, + TextStreamCoderChar.class, TextStreamCoderDouble.class, TextStreamCoderInt.class, TextStreamCoderLong.class, + TextStreamCoderFloat.class, TextStreamCoderShort.class }) public class WSCTextStreamServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) throws IOException, - EncodeException, InterruptedException, ExecutionException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) + throws IOException, EncodeException, InterruptedException, ExecutionException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSClient.java deleted file mode 100644 index 78d2c11fb7..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSClient.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.async; - -import com.sun.ts.tests.websocket.common.client.BinaryAndTextClientEndpoint; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.CoderSuperClass; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.OPS; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryClientEndpoint; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryStreamClientEndpoint; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextClientEndpoint; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextStreamClientEndpoint; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = -948555257662550131L; - - public WSClient() { - setContextRoot("wsc_ee_jakarta_websocket_remoteendpoint_usercoder_async_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - /* - * @testName: sendObjectPrimitivesTextEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:61; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Text.encode - */ - public void sendObjectPrimitivesTextEncoderOnServerTest() throws Exception { - for (OPS op : OPS.values()) - invoke("text", op, CoderSuperClass.COMMON_CODED_STRING); - } - - /* - * @testName: sendObjectPrimitivesTextEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:61; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Text.encode - */ - public void sendObjectPrimitivesTextEncoderOnClientTest() throws Exception { - WSCTextClientEndpoint client = new WSCTextClientEndpoint(); - - for (Object clientEntity : OPS.getClientEntities()) { - setAnnotatedClientEndpoint(client); - setEntity(clientEntity); - setClientCallback(new AsyncEndpointCallback(entity)); - invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesTextStreamEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:63; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.TextStream.encode - */ - public void sendObjectPrimitivesTextStreamEncoderOnServerTest() throws Exception { - for (OPS op : OPS.values()) - invoke("textstream", op, CoderSuperClass.COMMON_CODED_STRING); - } - - /* - * @testName: sendObjectPrimitivesTextStreamEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:63; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.TextStream.encode - */ - public void sendObjectPrimitivesTextStreamEncoderOnClientTest() throws Exception { - WSCTextStreamClientEndpoint client = new WSCTextStreamClientEndpoint(); - - for (Object clientEntity : OPS.getClientEntities()) { - setAnnotatedClientEndpoint(client); - setEntity(clientEntity); - setClientCallback(new AsyncEndpointCallback(entity)); - invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:56; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Binary.encode - */ - public void sendObjectPrimitivesBinaryEncoderOnServerTest() throws Exception { - for (OPS op : OPS.values()) { - setClientEndpoint(BinaryAndTextClientEndpoint.class); - invoke("binary", op, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:56; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Binary.encode - */ - public void sendObjectPrimitivesBinaryEncoderOnClientTest() throws Exception { - WSCBinaryClientEndpoint client = new WSCBinaryClientEndpoint(); - - for (Object clientEntity : OPS.getClientEntities()) { - setAnnotatedClientEndpoint(client); - setEntity(clientEntity); - setClientCallback(new AsyncEndpointCallback(entity)); - invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryStreamEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:58; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.BinaryStream.encode - */ - public void sendObjectPrimitivesBinaryStreamEncoderOnServerTest() - throws Exception { - for (OPS op : OPS.values()) { - setClientEndpoint(BinaryAndTextClientEndpoint.class); - invoke("binarystream", op, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryStreamEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:58; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.BinaryStream.encode - */ - public void sendObjectPrimitivesBinaryStreamEncoderOnClientTest() - throws Exception { - WSCBinaryStreamClientEndpoint client = new WSCBinaryStreamClientEndpoint(); - - for (Object clientEntity : OPS.getClientEntities()) { - setAnnotatedClientEndpoint(client); - setEntity(clientEntity); - setClientCallback(new AsyncEndpointCallback(entity)); - invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSClientIT.java new file mode 100644 index 0000000000..e90e91c238 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/async/WSClientIT.java @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.async; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.BinaryAndTextClientEndpoint; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.CoderSuperClass; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.OPS; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryClientEndpoint; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryStreamClientEndpoint; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextClientEndpoint; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextStreamClientEndpoint; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = -948555257662550131L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_ee_jakarta_websocket_remoteendpoint_usercoder_async_web.war"); + archive.addPackages(false, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.async"); + archive.addPackages(false, "com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_jakarta_websocket_remoteendpoint_usercoder_async_web"); + } + + /* Run test */ + + /* + * @testName: sendObjectPrimitivesTextEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:61; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Text.encode + */ + @Test + public void sendObjectPrimitivesTextEncoderOnServerTest() throws Exception { + for (OPS op : OPS.values()) + invoke("text", op, CoderSuperClass.COMMON_CODED_STRING); + } + + /* + * @testName: sendObjectPrimitivesTextEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:61; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Text.encode + */ + @Test + public void sendObjectPrimitivesTextEncoderOnClientTest() throws Exception { + WSCTextClientEndpoint client = new WSCTextClientEndpoint(); + + for (Object clientEntity : OPS.getClientEntities()) { + setAnnotatedClientEndpoint(client); + setEntity(clientEntity); + setClientCallback(new AsyncEndpointCallback(entity)); + invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesTextStreamEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:63; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.TextStream.encode + */ + @Test + public void sendObjectPrimitivesTextStreamEncoderOnServerTest() throws Exception { + for (OPS op : OPS.values()) + invoke("textstream", op, CoderSuperClass.COMMON_CODED_STRING); + } + + /* + * @testName: sendObjectPrimitivesTextStreamEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:63; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.TextStream.encode + */ + @Test + public void sendObjectPrimitivesTextStreamEncoderOnClientTest() throws Exception { + WSCTextStreamClientEndpoint client = new WSCTextStreamClientEndpoint(); + + for (Object clientEntity : OPS.getClientEntities()) { + setAnnotatedClientEndpoint(client); + setEntity(clientEntity); + setClientCallback(new AsyncEndpointCallback(entity)); + invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:56; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Binary.encode + */ + @Test + public void sendObjectPrimitivesBinaryEncoderOnServerTest() throws Exception { + for (OPS op : OPS.values()) { + setClientEndpoint(BinaryAndTextClientEndpoint.class); + invoke("binary", op, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:56; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Binary.encode + */ + @Test + public void sendObjectPrimitivesBinaryEncoderOnClientTest() throws Exception { + WSCBinaryClientEndpoint client = new WSCBinaryClientEndpoint(); + + for (Object clientEntity : OPS.getClientEntities()) { + setAnnotatedClientEndpoint(client); + setEntity(clientEntity); + setClientCallback(new AsyncEndpointCallback(entity)); + invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryStreamEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:58; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.BinaryStream.encode + */ + @Test + public void sendObjectPrimitivesBinaryStreamEncoderOnServerTest() throws Exception { + for (OPS op : OPS.values()) { + setClientEndpoint(BinaryAndTextClientEndpoint.class); + invoke("binarystream", op, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryStreamEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:96; WebSocket:JAVADOC:58; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.BinaryStream.encode + */ + @Test + public void sendObjectPrimitivesBinaryStreamEncoderOnClientTest() throws Exception { + WSCBinaryStreamClientEndpoint client = new WSCBinaryStreamClientEndpoint(); + + for (Object clientEntity : OPS.getClientEntities()) { + setAnnotatedClientEndpoint(client); + setEntity(clientEntity); + setClientCallback(new AsyncEndpointCallback(entity)); + invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/AsyncEndpointCallback.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/AsyncEndpointCallback.java index e3bd9ce3ce..4718c77d63 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/AsyncEndpointCallback.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/AsyncEndpointCallback.java @@ -27,26 +27,26 @@ import jakarta.websocket.Session; public class AsyncEndpointCallback extends EndpointCallback { - protected Entity entity; + protected Entity entity; - public AsyncEndpointCallback(Entity entity) { - super(); - this.entity = entity; - } + public AsyncEndpointCallback(Entity entity) { + super(); + this.entity = entity; + } - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - RemoteEndpoint.Async endpoint = session.getAsyncRemote(); - SendResult result = null; - try { - WaitingSendHandler handler = new WaitingSendHandler(); - endpoint.sendObject(entity.getEntityAt(0), handler); - result = handler.waitForResult(4); - } catch (Exception i) { - throw new RuntimeException(i); - } - if (!result.isOK() || result.getException() != null) - throw new RuntimeException(result.getException()); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + RemoteEndpoint.Async endpoint = session.getAsyncRemote(); + SendResult result = null; + try { + WaitingSendHandler handler = new WaitingSendHandler(); + endpoint.sendObject(entity.getEntityAt(0), handler); + result = handler.waitForResult(4); + } catch (Exception i) { + throw new RuntimeException(i); + } + if (!result.isOK() || result.getException() != null) + throw new RuntimeException(result.getException()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCBinaryServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCBinaryServer.java index 383d84d0cb..e4ad0eb0f3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCBinaryServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCBinaryServer.java @@ -34,22 +34,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binary", encoders = { BinaryCoderBool.class, - BinaryCoderByte.class, BinaryCoderChar.class, BinaryCoderDouble.class, - BinaryCoderInt.class, BinaryCoderLong.class, BinaryCoderFloat.class, - BinaryCoderShort.class }) +@ServerEndpoint(value = "/binary", encoders = { BinaryCoderBool.class, BinaryCoderByte.class, BinaryCoderChar.class, + BinaryCoderDouble.class, BinaryCoderInt.class, BinaryCoderLong.class, BinaryCoderFloat.class, + BinaryCoderShort.class }) public class WSCBinaryServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) - throws IOException, EncodeException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) throws IOException, EncodeException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCBinaryStreamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCBinaryStreamServer.java index e6a4b74a99..725e80f790 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCBinaryStreamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCBinaryStreamServer.java @@ -34,23 +34,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarystream", encoders = { - BinaryStreamCoderBool.class, BinaryStreamCoderByte.class, - BinaryStreamCoderChar.class, BinaryStreamCoderDouble.class, - BinaryStreamCoderInt.class, BinaryStreamCoderLong.class, - BinaryStreamCoderFloat.class, BinaryStreamCoderShort.class }) +@ServerEndpoint(value = "/binarystream", encoders = { BinaryStreamCoderBool.class, BinaryStreamCoderByte.class, + BinaryStreamCoderChar.class, BinaryStreamCoderDouble.class, BinaryStreamCoderInt.class, + BinaryStreamCoderLong.class, BinaryStreamCoderFloat.class, BinaryStreamCoderShort.class }) public class WSCBinaryStreamServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) - throws IOException, EncodeException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) throws IOException, EncodeException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCCommonServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCCommonServer.java index 46c32f30d3..db309ca606 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCCommonServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCCommonServer.java @@ -29,45 +29,44 @@ import jakarta.websocket.Session; public abstract class WSCCommonServer implements WSCSuperEndpoint { - public void onMessage(String msg, Session session) - throws IOException, EncodeException { - OPS op = OPS.valueOf(msg); - WaitingSendHandler handler = new WaitingSendHandler(); - switch (op) { - case BOOL: - session.getAsyncRemote().sendObject(BOOL, handler); - break; - case BYTE: - session.getAsyncRemote().sendObject(NUMERIC.byteValue(), handler); - break; - case CHAR: - session.getAsyncRemote().sendObject(CHAR, handler); - break; - case DOUBLE: - session.getAsyncRemote().sendObject(NUMERIC.doubleValue(), handler); - break; - case FLOAT: - session.getAsyncRemote().sendObject(NUMERIC.floatValue(), handler); - break; - case INT: - session.getAsyncRemote().sendObject(NUMERIC.intValue(), handler); - break; - case LONG: - session.getAsyncRemote().sendObject(NUMERIC.longValue(), handler); - break; - case SHORT: - session.getAsyncRemote().sendObject(NUMERIC.shortValue(), handler); - break; - } - SendResult result = handler.waitForResult(4); - if (!result.isOK() || result.getException() != null) - throw new RuntimeException(result.getException()); - } + public void onMessage(String msg, Session session) throws IOException, EncodeException { + OPS op = OPS.valueOf(msg); + WaitingSendHandler handler = new WaitingSendHandler(); + switch (op) { + case BOOL: + session.getAsyncRemote().sendObject(BOOL, handler); + break; + case BYTE: + session.getAsyncRemote().sendObject(NUMERIC.byteValue(), handler); + break; + case CHAR: + session.getAsyncRemote().sendObject(CHAR, handler); + break; + case DOUBLE: + session.getAsyncRemote().sendObject(NUMERIC.doubleValue(), handler); + break; + case FLOAT: + session.getAsyncRemote().sendObject(NUMERIC.floatValue(), handler); + break; + case INT: + session.getAsyncRemote().sendObject(NUMERIC.intValue(), handler); + break; + case LONG: + session.getAsyncRemote().sendObject(NUMERIC.longValue(), handler); + break; + case SHORT: + session.getAsyncRemote().sendObject(NUMERIC.shortValue(), handler); + break; + } + SendResult result = handler.waitForResult(4); + if (!result.isOK() || result.getException() != null) + throw new RuntimeException(result.getException()); + } - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCTextServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCTextServer.java index bee445f03a..98e3233a26 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCTextServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCTextServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -34,22 +34,19 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/text", encoders = { TextCoderBool.class, - TextCoderByte.class, TextCoderChar.class, TextCoderDouble.class, - TextCoderInt.class, TextCoderLong.class, TextCoderFloat.class, - TextCoderShort.class }) +@ServerEndpoint(value = "/text", encoders = { TextCoderBool.class, TextCoderByte.class, TextCoderChar.class, + TextCoderDouble.class, TextCoderInt.class, TextCoderLong.class, TextCoderFloat.class, TextCoderShort.class }) public class WSCTextServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) - throws IOException, EncodeException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) throws IOException, EncodeException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCTextStreamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCTextStreamServer.java index 38a57d4c54..512d2a10a1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCTextStreamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSCTextStreamServer.java @@ -34,23 +34,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstream", encoders = { TextStreamCoderBool.class, - TextStreamCoderByte.class, TextStreamCoderChar.class, - TextStreamCoderDouble.class, TextStreamCoderInt.class, - TextStreamCoderLong.class, TextStreamCoderFloat.class, - TextStreamCoderShort.class }) +@ServerEndpoint(value = "/textstream", encoders = { TextStreamCoderBool.class, TextStreamCoderByte.class, + TextStreamCoderChar.class, TextStreamCoderDouble.class, TextStreamCoderInt.class, TextStreamCoderLong.class, + TextStreamCoderFloat.class, TextStreamCoderShort.class }) public class WSCTextStreamServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) - throws IOException, EncodeException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) throws IOException, EncodeException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSClient.java deleted file mode 100644 index b20d79b7e1..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSClient.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.asyncwithhandler; - -import com.sun.ts.tests.websocket.common.client.BinaryAndTextClientEndpoint; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.CoderSuperClass; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.OPS; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryClientEndpoint; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryStreamClientEndpoint; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextClientEndpoint; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextStreamClientEndpoint; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = -1237079492944813869L; - - public WSClient() { - setContextRoot( - "wsc_ee_jakarta_websocket_remoteendpoint_usercoder_asynchandler_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - /* - * @testName: sendObjectPrimitivesTextEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:61; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Text.encode - */ - public void sendObjectPrimitivesTextEncoderOnServerTest() throws Exception { - for (OPS op : OPS.values()) - invoke("text", op, CoderSuperClass.COMMON_CODED_STRING); - } - - /* - * @testName: sendObjectPrimitivesTextEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:61; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Text.encode - */ - public void sendObjectPrimitivesTextEncoderOnClientTest() throws Exception { - WSCTextClientEndpoint client = new WSCTextClientEndpoint(); - - for (Object clientEntity : OPS.getClientEntities()) { - setAnnotatedClientEndpoint(client); - setEntity(clientEntity); - setClientCallback(new AsyncEndpointCallback(entity)); - invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesTextStreamEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:63; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.TextStream.encode - */ - public void sendObjectPrimitivesTextStreamEncoderOnServerTest() throws Exception { - for (OPS op : OPS.values()) - invoke("textstream", op, CoderSuperClass.COMMON_CODED_STRING); - } - - /* - * @testName: sendObjectPrimitivesTextStreamEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:63; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.TextStream.encode - */ - public void sendObjectPrimitivesTextStreamEncoderOnClientTest() throws Exception { - WSCTextStreamClientEndpoint client = new WSCTextStreamClientEndpoint(); - - for (Object clientEntity : OPS.getClientEntities()) { - setAnnotatedClientEndpoint(client); - setEntity(clientEntity); - setClientCallback(new AsyncEndpointCallback(entity)); - invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:56; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Binary.encode - */ - public void sendObjectPrimitivesBinaryEncoderOnServerTest() throws Exception { - for (OPS op : OPS.values()) { - setClientEndpoint(BinaryAndTextClientEndpoint.class); - invoke("binary", op, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:56; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Binary.encode - */ - public void sendObjectPrimitivesBinaryEncoderOnClientTest() throws Exception { - WSCBinaryClientEndpoint client = new WSCBinaryClientEndpoint(); - - for (Object clientEntity : OPS.getClientEntities()) { - setAnnotatedClientEndpoint(client); - setEntity(clientEntity); - setClientCallback(new AsyncEndpointCallback(entity)); - invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryStreamEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:58; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.BinaryStream.encode - */ - public void sendObjectPrimitivesBinaryStreamEncoderOnServerTest() - throws Exception { - for (OPS op : OPS.values()) { - setClientEndpoint(BinaryAndTextClientEndpoint.class); - invoke("binarystream", op, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryStreamEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:58; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.BinaryStream.encode - */ - public void sendObjectPrimitivesBinaryStreamEncoderOnClientTest() - throws Exception { - WSCBinaryStreamClientEndpoint client = new WSCBinaryStreamClientEndpoint(); - - for (Object clientEntity : OPS.getClientEntities()) { - setAnnotatedClientEndpoint(client); - setEntity(clientEntity); - setClientCallback(new AsyncEndpointCallback(entity)); - invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSClientIT.java new file mode 100644 index 0000000000..3e6e6cd7fe --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/asyncwithhandler/WSClientIT.java @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.asyncwithhandler; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.BinaryAndTextClientEndpoint; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.WaitingSendHandler; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.CoderSuperClass; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.OPS; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryClientEndpoint; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryStreamClientEndpoint; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextClientEndpoint; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextStreamClientEndpoint; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = -1237079492944813869L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_ee_jakarta_websocket_remoteendpoint_usercoder_asynchandler_web.war"); + archive.addPackages(false, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.asyncwithhandler"); + archive.addPackages(false, "com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(WaitingSendHandler.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_jakarta_websocket_remoteendpoint_usercoder_asynchandler_web"); + } + + /* Run test */ + + /* + * @testName: sendObjectPrimitivesTextEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:61; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Text.encode + */ + @Test + public void sendObjectPrimitivesTextEncoderOnServerTest() throws Exception { + for (OPS op : OPS.values()) + invoke("text", op, CoderSuperClass.COMMON_CODED_STRING); + } + + /* + * @testName: sendObjectPrimitivesTextEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:61; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Text.encode + */ + @Test + public void sendObjectPrimitivesTextEncoderOnClientTest() throws Exception { + WSCTextClientEndpoint client = new WSCTextClientEndpoint(); + + for (Object clientEntity : OPS.getClientEntities()) { + setAnnotatedClientEndpoint(client); + setEntity(clientEntity); + setClientCallback(new AsyncEndpointCallback(entity)); + invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesTextStreamEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:63; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.TextStream.encode + */ + @Test + public void sendObjectPrimitivesTextStreamEncoderOnServerTest() throws Exception { + for (OPS op : OPS.values()) + invoke("textstream", op, CoderSuperClass.COMMON_CODED_STRING); + } + + /* + * @testName: sendObjectPrimitivesTextStreamEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:63; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.TextStream.encode + */ + @Test + public void sendObjectPrimitivesTextStreamEncoderOnClientTest() throws Exception { + WSCTextStreamClientEndpoint client = new WSCTextStreamClientEndpoint(); + + for (Object clientEntity : OPS.getClientEntities()) { + setAnnotatedClientEndpoint(client); + setEntity(clientEntity); + setClientCallback(new AsyncEndpointCallback(entity)); + invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:56; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Binary.encode + */ + @Test + public void sendObjectPrimitivesBinaryEncoderOnServerTest() throws Exception { + for (OPS op : OPS.values()) { + setClientEndpoint(BinaryAndTextClientEndpoint.class); + invoke("binary", op, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:56; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Binary.encode + */ + @Test + public void sendObjectPrimitivesBinaryEncoderOnClientTest() throws Exception { + WSCBinaryClientEndpoint client = new WSCBinaryClientEndpoint(); + + for (Object clientEntity : OPS.getClientEntities()) { + setAnnotatedClientEndpoint(client); + setEntity(clientEntity); + setClientCallback(new AsyncEndpointCallback(entity)); + invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryStreamEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:58; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.BinaryStream.encode + */ + @Test + public void sendObjectPrimitivesBinaryStreamEncoderOnServerTest() throws Exception { + for (OPS op : OPS.values()) { + setClientEndpoint(BinaryAndTextClientEndpoint.class); + invoke("binarystream", op, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryStreamEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:97; WebSocket:JAVADOC:58; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.BinaryStream.encode + */ + @Test + public void sendObjectPrimitivesBinaryStreamEncoderOnClientTest() throws Exception { + WSCBinaryStreamClientEndpoint client = new WSCBinaryStreamClientEndpoint(); + + for (Object clientEntity : OPS.getClientEntities()) { + setAnnotatedClientEndpoint(client); + setEntity(clientEntity); + setClientCallback(new AsyncEndpointCallback(entity)); + invoke("echo", clientEntity, CoderSuperClass.COMMON_CODED_STRING); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCBinaryServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCBinaryServer.java index d5f8d6556d..5bde8b2055 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCBinaryServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCBinaryServer.java @@ -34,22 +34,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binary", encoders = { BinaryCoderBool.class, - BinaryCoderByte.class, BinaryCoderChar.class, BinaryCoderDouble.class, - BinaryCoderInt.class, BinaryCoderLong.class, BinaryCoderFloat.class, - BinaryCoderShort.class }) +@ServerEndpoint(value = "/binary", encoders = { BinaryCoderBool.class, BinaryCoderByte.class, BinaryCoderChar.class, + BinaryCoderDouble.class, BinaryCoderInt.class, BinaryCoderLong.class, BinaryCoderFloat.class, + BinaryCoderShort.class }) public class WSCBinaryServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) - throws IOException, EncodeException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) throws IOException, EncodeException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCBinaryStreamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCBinaryStreamServer.java index 07eaea0ea9..c1b511daab 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCBinaryStreamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCBinaryStreamServer.java @@ -34,23 +34,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarystream", encoders = { - BinaryStreamCoderBool.class, BinaryStreamCoderByte.class, - BinaryStreamCoderChar.class, BinaryStreamCoderDouble.class, - BinaryStreamCoderInt.class, BinaryStreamCoderLong.class, - BinaryStreamCoderFloat.class, BinaryStreamCoderShort.class }) +@ServerEndpoint(value = "/binarystream", encoders = { BinaryStreamCoderBool.class, BinaryStreamCoderByte.class, + BinaryStreamCoderChar.class, BinaryStreamCoderDouble.class, BinaryStreamCoderInt.class, + BinaryStreamCoderLong.class, BinaryStreamCoderFloat.class, BinaryStreamCoderShort.class }) public class WSCBinaryStreamServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) - throws IOException, EncodeException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) throws IOException, EncodeException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCCommonServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCCommonServer.java index d92672760b..e5b66f0c54 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCCommonServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCCommonServer.java @@ -27,41 +27,40 @@ import jakarta.websocket.Session; public abstract class WSCCommonServer implements WSCSuperEndpoint { - public void onMessage(String msg, Session session) - throws IOException, EncodeException { - OPS op = OPS.valueOf(msg); - switch (op) { - case BOOL: - session.getBasicRemote().sendObject(BOOL); - break; - case BYTE: - session.getBasicRemote().sendObject(NUMERIC.byteValue()); - break; - case CHAR: - session.getBasicRemote().sendObject(CHAR); - break; - case DOUBLE: - session.getBasicRemote().sendObject(NUMERIC.doubleValue()); - break; - case FLOAT: - session.getBasicRemote().sendObject(NUMERIC.floatValue()); - break; - case INT: - session.getBasicRemote().sendObject(NUMERIC.intValue()); - break; - case LONG: - session.getBasicRemote().sendObject(NUMERIC.longValue()); - break; - case SHORT: - session.getBasicRemote().sendObject(NUMERIC.shortValue()); - break; - } - } + public void onMessage(String msg, Session session) throws IOException, EncodeException { + OPS op = OPS.valueOf(msg); + switch (op) { + case BOOL: + session.getBasicRemote().sendObject(BOOL); + break; + case BYTE: + session.getBasicRemote().sendObject(NUMERIC.byteValue()); + break; + case CHAR: + session.getBasicRemote().sendObject(CHAR); + break; + case DOUBLE: + session.getBasicRemote().sendObject(NUMERIC.doubleValue()); + break; + case FLOAT: + session.getBasicRemote().sendObject(NUMERIC.floatValue()); + break; + case INT: + session.getBasicRemote().sendObject(NUMERIC.intValue()); + break; + case LONG: + session.getBasicRemote().sendObject(NUMERIC.longValue()); + break; + case SHORT: + session.getBasicRemote().sendObject(NUMERIC.shortValue()); + break; + } + } - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCTextServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCTextServer.java index 93c7a5cacb..d6f78ec8cd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCTextServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCTextServer.java @@ -34,22 +34,19 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/text", encoders = { TextCoderBool.class, - TextCoderByte.class, TextCoderChar.class, TextCoderDouble.class, - TextCoderInt.class, TextCoderLong.class, TextCoderFloat.class, - TextCoderShort.class }) +@ServerEndpoint(value = "/text", encoders = { TextCoderBool.class, TextCoderByte.class, TextCoderChar.class, + TextCoderDouble.class, TextCoderInt.class, TextCoderLong.class, TextCoderFloat.class, TextCoderShort.class }) public class WSCTextServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) - throws IOException, EncodeException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) throws IOException, EncodeException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCTextStreamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCTextStreamServer.java index d54e8f5022..3d1511547e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCTextStreamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSCTextStreamServer.java @@ -34,23 +34,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstream", encoders = { TextStreamCoderBool.class, - TextStreamCoderByte.class, TextStreamCoderChar.class, - TextStreamCoderDouble.class, TextStreamCoderInt.class, - TextStreamCoderLong.class, TextStreamCoderFloat.class, - TextStreamCoderShort.class }) +@ServerEndpoint(value = "/textstream", encoders = { TextStreamCoderBool.class, TextStreamCoderByte.class, + TextStreamCoderChar.class, TextStreamCoderDouble.class, TextStreamCoderInt.class, TextStreamCoderLong.class, + TextStreamCoderFloat.class, TextStreamCoderShort.class }) public class WSCTextStreamServer extends WSCCommonServer { - @Override - @OnMessage - public void onMessage(String msg, Session session) - throws IOException, EncodeException { - super.onMessage(msg, session); - } + @Override + @OnMessage + public void onMessage(String msg, Session session) throws IOException, EncodeException { + super.onMessage(msg, session); + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSClient.java deleted file mode 100644 index 1102ab4d8d..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSClient.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.basic; - -import com.sun.ts.tests.websocket.common.client.BinaryAndTextClientEndpoint; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.CoderSuperClass; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.OPS; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryClientEndpoint; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryStreamClientEndpoint; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCSuperEndpoint; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextClientEndpoint; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextStreamClientEndpoint; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = 7637718042723179933L; - - public WSClient() { - setContextRoot("wsc_ee_jakarta_websocket_remoteendpoint_usercoder_basic_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - /* - * @testName: sendObjectBooleanTextEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Text.encode - */ - public void sendObjectBooleanTextEncoderOnServerTest() throws Exception { - invoke("text", OPS.BOOL, CoderSuperClass.COMMON_CODED_STRING); - } - - /* - * @testName: sendObjectCharTextEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Text.encode - */ - public void sendObjectCharTextEncoderOnServerTest() throws Exception { - invoke("text", OPS.CHAR, CoderSuperClass.COMMON_CODED_STRING); - } - - /* - * @testName: sendObjectNumberTextEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Text.encode - */ - public void sendObjectNumberTextEncoderOnServerTest() throws Exception { - invoke("text", OPS.BYTE, CoderSuperClass.COMMON_CODED_STRING); - invoke("text", OPS.SHORT, CoderSuperClass.COMMON_CODED_STRING); - invoke("text", OPS.INT, CoderSuperClass.COMMON_CODED_STRING); - invoke("text", OPS.LONG, CoderSuperClass.COMMON_CODED_STRING); - invoke("text", OPS.FLOAT, CoderSuperClass.COMMON_CODED_STRING); - invoke("text", OPS.DOUBLE, CoderSuperClass.COMMON_CODED_STRING); - } - - /* - * @testName: sendObjectBooleanTextEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Text.encode - */ - public void sendObjectBooleanTextEncoderOnClientTest() throws Exception { - WSCTextClientEndpoint client = new WSCTextClientEndpoint(); - setAnnotatedClientEndpoint(client); - invoke("echo", Boolean.valueOf(WSCSuperEndpoint.BOOL), - CoderSuperClass.COMMON_CODED_STRING); - } - - /* - * @testName: sendObjectCharTextEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Text.encode - */ - public void sendObjectCharTextEncoderOnClientTest() throws Exception { - WSCTextClientEndpoint client = new WSCTextClientEndpoint(); - setAnnotatedClientEndpoint(client); - invoke("echo", Character.valueOf(WSCSuperEndpoint.CHAR), - CoderSuperClass.COMMON_CODED_STRING); - } - - /* - * @testName: sendObjectNumberTextEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Text.encode - */ - public void sendObjectNumberTextEncoderOnClientTest() throws Exception { - WSCTextClientEndpoint client = new WSCTextClientEndpoint(); - setAnnotatedClientEndpoint(client); - invoke("echo", WSCSuperEndpoint.NUMERIC, - CoderSuperClass.COMMON_CODED_STRING); - - setAnnotatedClientEndpoint(client); - invoke("echo", Short.valueOf(WSCSuperEndpoint.NUMERIC.shortValue()), - CoderSuperClass.COMMON_CODED_STRING); - - setAnnotatedClientEndpoint(client); - invoke("echo", WSCSuperEndpoint.NUMERIC.intValue(), - CoderSuperClass.COMMON_CODED_STRING); - - setAnnotatedClientEndpoint(client); - invoke("echo", WSCSuperEndpoint.NUMERIC.longValue(), - CoderSuperClass.COMMON_CODED_STRING); - - setAnnotatedClientEndpoint(client); - invoke("echo", WSCSuperEndpoint.NUMERIC.doubleValue(), - CoderSuperClass.COMMON_CODED_STRING); - - setAnnotatedClientEndpoint(client); - invoke("echo", WSCSuperEndpoint.NUMERIC.floatValue(), - CoderSuperClass.COMMON_CODED_STRING); - } - - // ---------------------------------------------------------------------- - /* - * @testName: sendObjectPrimitivesTextStreamEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:63; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.TextStream.encode - */ - public void sendObjectPrimitivesTextStreamEncoderOnServerTest() throws Exception { - for (OPS op : OPS.values()) - invoke("textstream", op, CoderSuperClass.COMMON_CODED_STRING); - } - - /* - * @testName: sendObjectPrimitivesTextStreamEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:63; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.TextStream.encode - */ - public void sendObjectPrimitivesTextStreamEncoderOnClientTest() throws Exception { - WSCTextStreamClientEndpoint client = new WSCTextStreamClientEndpoint(); - - for (Object entity : OPS.getClientEntities()) { - setAnnotatedClientEndpoint(client); - invoke("echo", entity, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:56; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Binary.encode - */ - public void sendObjectPrimitivesBinaryEncoderOnServerTest() throws Exception { - for (OPS op : OPS.values()) { - setClientEndpoint(BinaryAndTextClientEndpoint.class); - invoke("binary", op, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:56; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.Binary.encode - */ - public void sendObjectPrimitivesBinaryEncoderOnClientTest() throws Exception { - WSCBinaryClientEndpoint client = new WSCBinaryClientEndpoint(); - - for (Object entity : OPS.getClientEntities()) { - setAnnotatedClientEndpoint(client); - invoke("echo", entity, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryStreamEncoderOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:58; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.BinaryStream.encode - */ - public void sendObjectPrimitivesBinaryStreamEncoderOnServerTest() - throws Exception { - for (OPS op : OPS.values()) { - setClientEndpoint(BinaryAndTextClientEndpoint.class); - invoke("binarystream", op, CoderSuperClass.COMMON_CODED_STRING); - } - } - - /* - * @testName: sendObjectPrimitivesBinaryStreamEncoderOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:58; - * - * @test_Strategy: A developer-provided encoder for a Java primitive type - * overrides the container default encoder. Encoder.BinaryStream.encode - */ - public void sendObjectPrimitivesBinaryStreamEncoderOnClientTest() - throws Exception { - WSCBinaryStreamClientEndpoint client = new WSCBinaryStreamClientEndpoint(); - - for (Object entity : OPS.getClientEntities()) { - setAnnotatedClientEndpoint(client); - invoke("echo", entity, CoderSuperClass.COMMON_CODED_STRING); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSClientIT.java new file mode 100644 index 0000000000..c03e9c2de6 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/remoteendpoint/usercoder/basic/WSClientIT.java @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.basic; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.BinaryAndTextClientEndpoint; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.WaitingSendHandler; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.CoderSuperClass; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.OPS; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryClientEndpoint; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCBinaryStreamClientEndpoint; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCSuperEndpoint; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextClientEndpoint; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.WSCTextStreamClientEndpoint; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = 7637718042723179933L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_ee_jakarta_websocket_remoteendpoint_usercoder_basic_web.war"); + archive.addPackages(false, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder.basic"); + archive.addPackages(false, "com.sun.ts.tests.websocket.ee.jakarta.websocket.remoteendpoint.usercoder"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(WaitingSendHandler.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_jakarta_websocket_remoteendpoint_usercoder_basic_web"); + } + + /* Run test */ + + /* + * @testName: sendObjectBooleanTextEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Text.encode + */ + @Test + public void sendObjectBooleanTextEncoderOnServerTest() throws Exception { + invoke("text", OPS.BOOL, CoderSuperClass.COMMON_CODED_STRING); + } + + /* + * @testName: sendObjectCharTextEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Text.encode + */ + @Test + public void sendObjectCharTextEncoderOnServerTest() throws Exception { + invoke("text", OPS.CHAR, CoderSuperClass.COMMON_CODED_STRING); + } + + /* + * @testName: sendObjectNumberTextEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Text.encode + */ + @Test + public void sendObjectNumberTextEncoderOnServerTest() throws Exception { + invoke("text", OPS.BYTE, CoderSuperClass.COMMON_CODED_STRING); + invoke("text", OPS.SHORT, CoderSuperClass.COMMON_CODED_STRING); + invoke("text", OPS.INT, CoderSuperClass.COMMON_CODED_STRING); + invoke("text", OPS.LONG, CoderSuperClass.COMMON_CODED_STRING); + invoke("text", OPS.FLOAT, CoderSuperClass.COMMON_CODED_STRING); + invoke("text", OPS.DOUBLE, CoderSuperClass.COMMON_CODED_STRING); + } + + /* + * @testName: sendObjectBooleanTextEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Text.encode + */ + @Test + public void sendObjectBooleanTextEncoderOnClientTest() throws Exception { + WSCTextClientEndpoint client = new WSCTextClientEndpoint(); + setAnnotatedClientEndpoint(client); + invoke("echo", Boolean.valueOf(WSCSuperEndpoint.BOOL), CoderSuperClass.COMMON_CODED_STRING); + } + + /* + * @testName: sendObjectCharTextEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Text.encode + */ + @Test + public void sendObjectCharTextEncoderOnClientTest() throws Exception { + WSCTextClientEndpoint client = new WSCTextClientEndpoint(); + setAnnotatedClientEndpoint(client); + invoke("echo", Character.valueOf(WSCSuperEndpoint.CHAR), CoderSuperClass.COMMON_CODED_STRING); + } + + /* + * @testName: sendObjectNumberTextEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:61; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Text.encode + */ + @Test + public void sendObjectNumberTextEncoderOnClientTest() throws Exception { + WSCTextClientEndpoint client = new WSCTextClientEndpoint(); + setAnnotatedClientEndpoint(client); + invoke("echo", WSCSuperEndpoint.NUMERIC, CoderSuperClass.COMMON_CODED_STRING); + + setAnnotatedClientEndpoint(client); + invoke("echo", Short.valueOf(WSCSuperEndpoint.NUMERIC.shortValue()), CoderSuperClass.COMMON_CODED_STRING); + + setAnnotatedClientEndpoint(client); + invoke("echo", WSCSuperEndpoint.NUMERIC.intValue(), CoderSuperClass.COMMON_CODED_STRING); + + setAnnotatedClientEndpoint(client); + invoke("echo", WSCSuperEndpoint.NUMERIC.longValue(), CoderSuperClass.COMMON_CODED_STRING); + + setAnnotatedClientEndpoint(client); + invoke("echo", WSCSuperEndpoint.NUMERIC.doubleValue(), CoderSuperClass.COMMON_CODED_STRING); + + setAnnotatedClientEndpoint(client); + invoke("echo", WSCSuperEndpoint.NUMERIC.floatValue(), CoderSuperClass.COMMON_CODED_STRING); + } + + // ---------------------------------------------------------------------- + /* + * @testName: sendObjectPrimitivesTextStreamEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:63; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.TextStream.encode + */ + @Test + public void sendObjectPrimitivesTextStreamEncoderOnServerTest() throws Exception { + for (OPS op : OPS.values()) + invoke("textstream", op, CoderSuperClass.COMMON_CODED_STRING); + } + + /* + * @testName: sendObjectPrimitivesTextStreamEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:63; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.TextStream.encode + */ + @Test + public void sendObjectPrimitivesTextStreamEncoderOnClientTest() throws Exception { + WSCTextStreamClientEndpoint client = new WSCTextStreamClientEndpoint(); + + for (Object entity : OPS.getClientEntities()) { + setAnnotatedClientEndpoint(client); + invoke("echo", entity, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:56; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Binary.encode + */ + @Test + public void sendObjectPrimitivesBinaryEncoderOnServerTest() throws Exception { + for (OPS op : OPS.values()) { + setClientEndpoint(BinaryAndTextClientEndpoint.class); + invoke("binary", op, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:56; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.Binary.encode + */ + @Test + public void sendObjectPrimitivesBinaryEncoderOnClientTest() throws Exception { + WSCBinaryClientEndpoint client = new WSCBinaryClientEndpoint(); + + for (Object entity : OPS.getClientEntities()) { + setAnnotatedClientEndpoint(client); + invoke("echo", entity, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryStreamEncoderOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:58; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.BinaryStream.encode + */ + @Test + public void sendObjectPrimitivesBinaryStreamEncoderOnServerTest() throws Exception { + for (OPS op : OPS.values()) { + setClientEndpoint(BinaryAndTextClientEndpoint.class); + invoke("binarystream", op, CoderSuperClass.COMMON_CODED_STRING); + } + } + + /* + * @testName: sendObjectPrimitivesBinaryStreamEncoderOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:109; WebSocket:JAVADOC:58; + * + * @test_Strategy: A developer-provided encoder for a Java primitive type + * overrides the container default encoder. Encoder.BinaryStream.encode + */ + @Test + public void sendObjectPrimitivesBinaryStreamEncoderOnClientTest() throws Exception { + WSCBinaryStreamClientEndpoint client = new WSCBinaryStreamClientEndpoint(); + + for (Object entity : OPS.getClientEntities()) { + setAnnotatedClientEndpoint(client); + invoke("echo", entity, CoderSuperClass.COMMON_CODED_STRING); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/CaseInsensitiveHeaderNamesConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/CaseInsensitiveHeaderNamesConfigurator.java index dd723dc6a0..2ae0db6893 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/CaseInsensitiveHeaderNamesConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/CaseInsensitiveHeaderNamesConfigurator.java @@ -28,30 +28,28 @@ public class CaseInsensitiveHeaderNamesConfigurator extends Configurator { - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - Map> headers = request.getHeaders(); - boolean isCaseSensitive = true; - isCaseSensitive &= headers.containsKey(REQUEST_KEY); - isCaseSensitive &= headers.containsKey(REQUEST_KEY.toLowerCase()); - isCaseSensitive &= headers.containsKey(REQUEST_KEY.toUpperCase()); - response.getHeaders().put(RESPONSE_KEY, - Arrays.asList(String.valueOf(isCaseSensitive))); - super.modifyHandshake(sec, request, response); - } - - /* - * Request sets this key with REQUEST_VALUES and case sensitivity is checked - * afterwards in modifyHandshake() - */ - static final String REQUEST_KEY = "caseInsensitiveKey"; - - /* - * The value of this key is set to be checked on a client and the value should - * reflect boolean value of being case sensitive or not - */ - static final String RESPONSE_KEY = "isCaseSensitive"; - - static final String[] REQUEST_VALUES = { "RequestValue1", "RequestValue2" }; + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + Map> headers = request.getHeaders(); + boolean isCaseSensitive = true; + isCaseSensitive &= headers.containsKey(REQUEST_KEY); + isCaseSensitive &= headers.containsKey(REQUEST_KEY.toLowerCase()); + isCaseSensitive &= headers.containsKey(REQUEST_KEY.toUpperCase()); + response.getHeaders().put(RESPONSE_KEY, Arrays.asList(String.valueOf(isCaseSensitive))); + super.modifyHandshake(sec, request, response); + } + + /* + * Request sets this key with REQUEST_VALUES and case sensitivity is checked + * afterwards in modifyHandshake() + */ + static final String REQUEST_KEY = "caseInsensitiveKey"; + + /* + * The value of this key is set to be checked on a client and the value should + * reflect boolean value of being case sensitive or not + */ + static final String RESPONSE_KEY = "isCaseSensitive"; + + static final String[] REQUEST_VALUES = { "RequestValue1", "RequestValue2" }; } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetQueryStringConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetQueryStringConfigurator.java index 2140720855..dd0ec6c617 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetQueryStringConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetQueryStringConfigurator.java @@ -25,13 +25,12 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class GetQueryStringConfigurator extends Configurator { - static final String KEY = "GetQueryStringConfigurator"; + static final String KEY = "GetQueryStringConfigurator"; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - String query = request.getQueryString(); - query = query == null ? "NULL" : query; - response.getHeaders().put(KEY, Arrays.asList(query)); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + String query = request.getQueryString(); + query = query == null ? "NULL" : query; + response.getHeaders().put(KEY, Arrays.asList(query)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetRequestUriConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetRequestUriConfigurator.java index df4f264316..f36049b0a9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetRequestUriConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetRequestUriConfigurator.java @@ -26,13 +26,12 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class GetRequestUriConfigurator extends Configurator { - static final String KEY = "GetRequestUriConfigurator"; + static final String KEY = "GetRequestUriConfigurator"; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - URI uri = request.getRequestURI(); - String sUri = uri == null ? "NULL" : uri.toASCIIString(); - response.getHeaders().put(KEY, Arrays.asList(sUri)); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + URI uri = request.getRequestURI(); + String sUri = uri == null ? "NULL" : uri.toASCIIString(); + response.getHeaders().put(KEY, Arrays.asList(sUri)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetUserPrincipalNotAuthenticatedConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetUserPrincipalNotAuthenticatedConfigurator.java index 9377763627..6c4e366cef 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetUserPrincipalNotAuthenticatedConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/GetUserPrincipalNotAuthenticatedConfigurator.java @@ -26,13 +26,12 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class GetUserPrincipalNotAuthenticatedConfigurator extends Configurator { - static final String KEY = "GetUserPrincipalNotAuthenticatedConfigurator"; + static final String KEY = "GetUserPrincipalNotAuthenticatedConfigurator"; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - Principal principal = request.getUserPrincipal(); - String value = String.valueOf(principal == null); - response.getHeaders().put(KEY, Arrays.asList(value)); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + Principal principal = request.getUserPrincipal(); + String value = String.valueOf(principal == null); + response.getHeaders().put(KEY, Arrays.asList(value)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/IsUserInRoleNotAuthenticatedConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/IsUserInRoleNotAuthenticatedConfigurator.java index 4cf90f4464..e817ba775a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/IsUserInRoleNotAuthenticatedConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/IsUserInRoleNotAuthenticatedConfigurator.java @@ -25,14 +25,13 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class IsUserInRoleNotAuthenticatedConfigurator extends Configurator { - static final String KEY = "IsUserInRoleNotAuthenticatedConfigurator"; + static final String KEY = "IsUserInRoleNotAuthenticatedConfigurator"; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - boolean isInRole = request.isUserInRole("j2ee"); - isInRole |= request.isUserInRole("DIRECTOR"); - String value = String.valueOf(isInRole); - response.getHeaders().put(KEY, Arrays.asList(value)); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + boolean isInRole = request.isUserInRole("j2ee"); + isInRole |= request.isUserInRole("DIRECTOR"); + String value = String.valueOf(isInRole); + response.getHeaders().put(KEY, Arrays.asList(value)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/PathParamConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/PathParamConfigurator.java index b33df4577d..c80a9e123f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/PathParamConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/PathParamConfigurator.java @@ -27,10 +27,9 @@ public class PathParamConfigurator extends Configurator { - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - Map> map = request.getParameterMap(); - response.getHeaders().putAll(map); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + Map> map = request.getParameterMap(); + response.getHeaders().putAll(map); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/ReadonlyGetHeadersConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/ReadonlyGetHeadersConfigurator.java index 4dc97378b1..385eac9eaa 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/ReadonlyGetHeadersConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/ReadonlyGetHeadersConfigurator.java @@ -27,20 +27,19 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class ReadonlyGetHeadersConfigurator extends Configurator { - static final String KEY = "GetQueryStringConfigurator"; + static final String KEY = "GetQueryStringConfigurator"; - static final String[] VALUES = { "ReadOnlyValue1", "ReadOnlyValue2" }; + static final String[] VALUES = { "ReadOnlyValue1", "ReadOnlyValue2" }; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - Map> map = request.getHeaders(); - try { - map.put(KEY, Arrays.asList(VALUES)); - } catch (Exception e) { - // possible, but not mandatory - } - map = request.getHeaders(); - response.getHeaders().putAll(map); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + Map> map = request.getHeaders(); + try { + map.put(KEY, Arrays.asList(VALUES)); + } catch (Exception e) { + // possible, but not mandatory + } + map = request.getHeaders(); + response.getHeaders().putAll(map); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/ReadonlyGetParamsConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/ReadonlyGetParamsConfigurator.java index 98a16fe08e..ce36b5f026 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/ReadonlyGetParamsConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/ReadonlyGetParamsConfigurator.java @@ -27,20 +27,19 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class ReadonlyGetParamsConfigurator extends Configurator { - static final String KEY = "ReadOnlyKey"; + static final String KEY = "ReadOnlyKey"; - static final String[] VALUES = { "ReadOnlyValue1", "ReadOnlyValue2" }; + static final String[] VALUES = { "ReadOnlyValue1", "ReadOnlyValue2" }; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - Map> map = request.getParameterMap(); - try { - map.put(KEY, Arrays.asList(VALUES)); - } catch (Exception e) { - // possible, but not mandatory - } - map = request.getParameterMap(); - response.getHeaders().putAll(map); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + Map> map = request.getParameterMap(); + try { + map.put(KEY, Arrays.asList(VALUES)); + } catch (Exception e) { + // possible, but not mandatory + } + map = request.getParameterMap(); + response.getHeaders().putAll(map); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCCaseInsensitiveHeaderNamesServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCCaseInsensitiveHeaderNamesServer.java index 6cc6b0a9f0..c8734ef9bc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCCaseInsensitiveHeaderNamesServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCCaseInsensitiveHeaderNamesServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/caseinsensitiveheadernames", configurator = CaseInsensitiveHeaderNamesConfigurator.class) public class WSCCaseInsensitiveHeaderNamesServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCClient.java deleted file mode 100644 index 4a3d56cd54..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCClient.java +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.handshakerequest; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; -import com.sun.ts.tests.websocket.common.util.StringUtil; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.HandshakeResponse; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSCClient extends WebSocketCommonClient { - private static final long serialVersionUID = 6725664656725817177L; - - public WSCClient() { - setContextRoot("wsc_ee_jakarta_websocket_handshakerequest_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - static final String KEY = "aFirstKey"; - - static final String[] HEADERS = { "header1", "header2", "header3", "header4", - "header5", "header6", "header7", "header8" }; - - /* Run test */ - - /* - * @testName: getHeadersIsReadonlyTest - * - * @assertion_ids: WebSocket:JAVADOC:174; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeRequest.getHeaders HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake - * - * Return the read only Map of Http Headers that came with the handshake - * request. - */ - public void getHeadersIsReadonlyTest() throws Exception { - ClientConfigurator configurator = new ClientConfigurator() { - @Override - public void afterResponse(HandshakeResponse hr) { - super.afterResponse(hr); - boolean contains = hr.getHeaders() - .containsKey(ReadonlyGetHeadersConfigurator.KEY); - assertTrue(!contains, - "HandshakeRequest.getHeaders is not readonly, it contains [", - ReadonlyGetHeadersConfigurator.KEY, ",", - StringUtil.collectionToString( - hr.getHeaders().get(ReadonlyGetHeadersConfigurator.KEY)), - "]"); - logMsg("HandshakeRequest.getHeaders is readonly as expected"); - } - }; - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - invoke("readonlygetheaders", "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: getHeadersHasCaseInsensitiveNamesTest - * - * @assertion_ids: WebSocket:JAVADOC:174; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:16; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeRequest.getHeaders HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ClientEndpointConfig.Configurator.beforeRequest - * ServerEndpointConfig.Configurator.modifyHandshake - * - * The header names are case insensitive. - */ - public void getHeadersHasCaseInsensitiveNamesTest() throws Exception { - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToRequest( - CaseInsensitiveHeaderNamesConfigurator.REQUEST_KEY, - CaseInsensitiveHeaderNamesConfigurator.REQUEST_VALUES); - configurator.addToResponse( - CaseInsensitiveHeaderNamesConfigurator.RESPONSE_KEY, - String.valueOf(true)); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - invoke("caseinsensitiveheadernames", "anything", "anything"); - configurator.assertBeforeRequestHasBeenCalled(); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: getParameterMapIsUnmodifiableTest - * - * @assertion_ids: WebSocket:JAVADOC:176; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeRequest.getParameterMap - * HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake - * - * Returns: the unmodifiable map of the request parameters. - */ - public void getParameterMapIsUnmodifiableTest() throws Exception { - ClientConfigurator configurator = new ClientConfigurator() { - @Override - public void afterResponse(HandshakeResponse hr) { - super.afterResponse(hr); - boolean contains = hr.getHeaders() - .containsKey(ReadonlyGetParamsConfigurator.KEY); - assertTrue(!contains, - "HandshakeRequest.getParameterMap is not readonly, it contains [", - ReadonlyGetParamsConfigurator.KEY, ",", - StringUtil.collectionToString( - hr.getHeaders().get(ReadonlyGetParamsConfigurator.KEY)), - "]"); - logMsg("HandshakeRequest.getParameterMap is readonly as expected"); - } - }; - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - invoke("readonlygetparams", "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: getParameterMapOneParamTest - * - * @assertion_ids: WebSocket:JAVADOC:176; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeRequest.getParameterMap - * HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake - * - * Returns: the unmodifiable map of the request parameters. - */ - public void getParameterMapOneParamTest() throws Exception { - String param = "firstParam"; - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse("first", param); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - setProperty(Property.SEARCH_STRING, param); - invoke("getoneparam/" + param, "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: getParameterMapOneParamOneQueryParamTest - * - * @assertion_ids: WebSocket:JAVADOC:176; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeRequest.getParameterMap - * HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake - * - * Returns: the unmodifiable map of the request parameters. - */ - public void getParameterMapOneParamOneQueryParamTest() throws Exception { - String param = "firstParam"; - String queryParam = "secondParam"; - String query = "?second=" + queryParam + "&second=" + param; - ClientConfigurator configurator = new ClientConfigurator(); - // configurator.addToResponse("first", param); - configurator.addToResponse("second", queryParam, param); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - setProperty(Property.SEARCH_STRING, param); - invoke("getoneparam/" + param + query, "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: getParameterMapTwoParamsTest - * - * @assertion_ids: WebSocket:JAVADOC:176; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeRequest.getParameterMap - * HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake - * - * Returns: the unmodifiable map of the request parameters. - */ - public void getParameterMapTwoParamsTest() throws Exception { - String[] params = { String.valueOf(123L), String.valueOf(123.456d) }; - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse("first", params[0]); - configurator.addToResponse("second", params[1]); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - setProperty(Property.SEARCH_STRING, params[0]); - setProperty(Property.SEARCH_STRING, params[1]); - invoke("gettwoparams/" + params[0] + "/" + params[1], "anything", - "anything"); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: getQueryStringTest - * - * @assertion_ids: WebSocket:JAVADOC:177; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeRequest.getQueryString - * HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake - * - * Return the query string associated with the request. - */ - public void getQueryStringTest() throws Exception { - String query = "abc=123&def=456"; - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse(GetQueryStringConfigurator.KEY, query); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - invoke("getquerystring?" + query, "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: getRequestUriTest - * - * @assertion_ids: WebSocket:JAVADOC:178; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeRequest.getRequestUri HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake - * - * Returns: the request uri of the handshake request. - */ - public void getRequestUriTest() throws Exception { - String uri = "getrequesturi"; - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse(GetRequestUriConfigurator.KEY, uri); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - invoke(uri, "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: getUserPrincipalNotAuthenticatedTest - * - * @assertion_ids: WebSocket:JAVADOC:179; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeRequest.getUserPrincipal - * HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake - * - * Return the authenticated user or null if no user is authenticated for this - * handshake. - */ - public void getUserPrincipalNotAuthenticatedTest() throws Exception { - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse(GetUserPrincipalNotAuthenticatedConfigurator.KEY, - String.valueOf(true)); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - invoke("getuserprincipal", "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: isUserInRoleNotAuthenticatedTest - * - * @assertion_ids: WebSocket:JAVADOC:180; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; - * - * @test_Strategy: HandshakeRequest.isUserInRole HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake - * - * If the user has not been authenticated, the method returns false. - */ - public void isUserInRoleNotAuthenticatedTest() throws Exception { - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse(IsUserInRoleNotAuthenticatedConfigurator.KEY, - String.valueOf(false)); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - invoke("isuserinrole", "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCClientIT.java new file mode 100644 index 0000000000..3c97daa545 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCClientIT.java @@ -0,0 +1,326 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.handshakerequest; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.common.util.StringUtil; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.HandshakeResponse; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = 6725664656725817177L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_jakarta_websocket_handshakerequest_web.war"); + archive.addPackages(true, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.server.handshakerequest"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_jakarta_websocket_handshakerequest_web"); + } + + static final String KEY = "aFirstKey"; + + static final String[] HEADERS = { "header1", "header2", "header3", "header4", "header5", "header6", "header7", + "header8" }; + + /* Run test */ + + /* + * @testName: getHeadersIsReadonlyTest + * + * @assertion_ids: WebSocket:JAVADOC:174; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeRequest.getHeaders HandshakeResponse.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake + * + * Return the read only Map of Http Headers that came with the handshake + * request. + */ + @Test + public void getHeadersIsReadonlyTest() throws Exception { + ClientConfigurator configurator = new ClientConfigurator() { + @Override + public void afterResponse(HandshakeResponse hr) { + super.afterResponse(hr); + boolean contains = hr.getHeaders().containsKey(ReadonlyGetHeadersConfigurator.KEY); + assertTrue(!contains, "HandshakeRequest.getHeaders is not readonly, it contains [", + ReadonlyGetHeadersConfigurator.KEY, ",", + StringUtil.collectionToString(hr.getHeaders().get(ReadonlyGetHeadersConfigurator.KEY)), "]"); + logMsg("HandshakeRequest.getHeaders is readonly as expected"); + } + }; + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + invoke("readonlygetheaders", "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: getHeadersHasCaseInsensitiveNamesTest + * + * @assertion_ids: WebSocket:JAVADOC:174; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:16; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeRequest.getHeaders HandshakeResponse.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ClientEndpointConfig.Configurator.beforeRequest + * ServerEndpointConfig.Configurator.modifyHandshake + * + * The header names are case insensitive. + */ + @Test + public void getHeadersHasCaseInsensitiveNamesTest() throws Exception { + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToRequest(CaseInsensitiveHeaderNamesConfigurator.REQUEST_KEY, + CaseInsensitiveHeaderNamesConfigurator.REQUEST_VALUES); + configurator.addToResponse(CaseInsensitiveHeaderNamesConfigurator.RESPONSE_KEY, String.valueOf(true)); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + invoke("caseinsensitiveheadernames", "anything", "anything"); + configurator.assertBeforeRequestHasBeenCalled(); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: getParameterMapIsUnmodifiableTest + * + * @assertion_ids: WebSocket:JAVADOC:176; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeRequest.getParameterMap HandshakeResponse.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake + * + * Returns: the unmodifiable map of the request parameters. + */ + @Test + public void getParameterMapIsUnmodifiableTest() throws Exception { + ClientConfigurator configurator = new ClientConfigurator() { + @Override + public void afterResponse(HandshakeResponse hr) { + super.afterResponse(hr); + boolean contains = hr.getHeaders().containsKey(ReadonlyGetParamsConfigurator.KEY); + assertTrue(!contains, "HandshakeRequest.getParameterMap is not readonly, it contains [", + ReadonlyGetParamsConfigurator.KEY, ",", + StringUtil.collectionToString(hr.getHeaders().get(ReadonlyGetParamsConfigurator.KEY)), "]"); + logMsg("HandshakeRequest.getParameterMap is readonly as expected"); + } + }; + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + invoke("readonlygetparams", "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: getParameterMapOneParamTest + * + * @assertion_ids: WebSocket:JAVADOC:176; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeRequest.getParameterMap HandshakeResponse.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake + * + * Returns: the unmodifiable map of the request parameters. + */ + @Test + public void getParameterMapOneParamTest() throws Exception { + String param = "firstParam"; + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse("first", param); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + setProperty(Property.SEARCH_STRING, param); + invoke("getoneparam/" + param, "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: getParameterMapOneParamOneQueryParamTest + * + * @assertion_ids: WebSocket:JAVADOC:176; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeRequest.getParameterMap HandshakeResponse.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake + * + * Returns: the unmodifiable map of the request parameters. + */ + @Test + public void getParameterMapOneParamOneQueryParamTest() throws Exception { + String param = "firstParam"; + String queryParam = "secondParam"; + String query = "?second=" + queryParam + "&second=" + param; + ClientConfigurator configurator = new ClientConfigurator(); + // configurator.addToResponse("first", param); + configurator.addToResponse("second", queryParam, param); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + setProperty(Property.SEARCH_STRING, param); + invoke("getoneparam/" + param + query, "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: getParameterMapTwoParamsTest + * + * @assertion_ids: WebSocket:JAVADOC:176; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeRequest.getParameterMap HandshakeResponse.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake + * + * Returns: the unmodifiable map of the request parameters. + */ + @Test + public void getParameterMapTwoParamsTest() throws Exception { + String[] params = { String.valueOf(123L), String.valueOf(123.456d) }; + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse("first", params[0]); + configurator.addToResponse("second", params[1]); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + setProperty(Property.SEARCH_STRING, params[0]); + setProperty(Property.SEARCH_STRING, params[1]); + invoke("gettwoparams/" + params[0] + "/" + params[1], "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: getQueryStringTest + * + * @assertion_ids: WebSocket:JAVADOC:177; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeRequest.getQueryString HandshakeResponse.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake + * + * Return the query string associated with the request. + */ + @Test + public void getQueryStringTest() throws Exception { + String query = "abc=123&def=456"; + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse(GetQueryStringConfigurator.KEY, query); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + invoke("getquerystring?" + query, "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: getRequestUriTest + * + * @assertion_ids: WebSocket:JAVADOC:178; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeRequest.getRequestUri HandshakeResponse.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake + * + * Returns: the request uri of the handshake request. + */ + @Test + public void getRequestUriTest() throws Exception { + String uri = "getrequesturi"; + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse(GetRequestUriConfigurator.KEY, uri); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + invoke(uri, "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: getUserPrincipalNotAuthenticatedTest + * + * @assertion_ids: WebSocket:JAVADOC:179; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeRequest.getUserPrincipal + * HandshakeResponse.getHeaders ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake + * + * Return the authenticated user or null if no user is authenticated for this + * handshake. + */ + @Test + public void getUserPrincipalNotAuthenticatedTest() throws Exception { + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse(GetUserPrincipalNotAuthenticatedConfigurator.KEY, String.valueOf(true)); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + invoke("getuserprincipal", "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: isUserInRoleNotAuthenticatedTest + * + * @assertion_ids: WebSocket:JAVADOC:180; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; + * + * @test_Strategy: HandshakeRequest.isUserInRole HandshakeResponse.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake + * + * If the user has not been authenticated, the method returns false. + */ + @Test + public void isUserInRoleNotAuthenticatedTest() throws Exception { + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse(IsUserInRoleNotAuthenticatedConfigurator.KEY, String.valueOf(false)); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + invoke("isuserinrole", "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetOneParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetOneParamServer.java index c464c0fe4f..dcf801eb9b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetOneParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetOneParamServer.java @@ -29,16 +29,16 @@ @ServerEndpoint(value = "/getoneparam/{first}", configurator = PathParamConfigurator.class) public class WSCGetOneParamServer { - @OnMessage - public String onMessage(@PathParam("first") String param, String msg) { - return param + msg; - } + @OnMessage + public String onMessage(@PathParam("first") String param, String msg) { + return param + msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetQueryStringServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetQueryStringServer.java index 5098f53e31..8774b3a73e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetQueryStringServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetQueryStringServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/getquerystring", configurator = GetQueryStringConfigurator.class) public class WSCGetQueryStringServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetTwoParamsServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetTwoParamsServer.java index 71038dd809..c15e38a544 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetTwoParamsServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetTwoParamsServer.java @@ -29,17 +29,17 @@ @ServerEndpoint(value = "/gettwoparams/{first}/{second}", configurator = PathParamConfigurator.class) public class WSCGetTwoParamsServer { - @OnMessage - public String onMessage(@PathParam("first") long lng, - @PathParam("second") double dbl, String msg) { - return String.valueOf(lng) + ";" + String.valueOf(dbl) + ";" + msg; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + + @OnMessage + public String onMessage(@PathParam("first") long lng, @PathParam("second") double dbl, String msg) { + return String.valueOf(lng) + ";" + String.valueOf(dbl) + ";" + msg; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetUserPrincipalServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetUserPrincipalServer.java index c2809f37de..0ef2089ef3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetUserPrincipalServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCGetUserPrincipalServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/getuserprincipal", configurator = GetUserPrincipalNotAuthenticatedConfigurator.class) public class WSCGetUserPrincipalServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCIsUserInRoleServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCIsUserInRoleServer.java index fc5b162550..9b6cb0a2d9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCIsUserInRoleServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCIsUserInRoleServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/isuserinrole", configurator = IsUserInRoleNotAuthenticatedConfigurator.class) public class WSCIsUserInRoleServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCReadOnlyGetHeadersServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCReadOnlyGetHeadersServer.java index 223d9d069d..b32b1ae53d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCReadOnlyGetHeadersServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCReadOnlyGetHeadersServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/readonlygetheaders", configurator = ReadonlyGetHeadersConfigurator.class) public class WSCReadOnlyGetHeadersServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCReadOnlyGetParameterMapServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCReadOnlyGetParameterMapServer.java index b9739ebdb5..a06234d480 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCReadOnlyGetParameterMapServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCReadOnlyGetParameterMapServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/readonlygetparams", configurator = ReadonlyGetParamsConfigurator.class) public class WSCReadOnlyGetParameterMapServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCRequestUriServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCRequestUriServer.java index 422a826588..edc2f53702 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCRequestUriServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/handshakerequest/WSCRequestUriServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/getrequesturi", configurator = GetRequestUriConfigurator.class) public class WSCRequestUriServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/OPS.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/OPS.java index a3f924aae9..b26b568e4c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/OPS.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/OPS.java @@ -17,5 +17,5 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.server.pathparam; public enum OPS { - OPEN, MESSAGE, IOEXCEPTION, RUNTIMEEXCEPTION + OPEN, MESSAGE, IOEXCEPTION, RUNTIMEEXCEPTION } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS0StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS0StringPathParamServer.java index b1a3b8f479..5a0dc4f00d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS0StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS0StringPathParamServer.java @@ -31,53 +31,51 @@ @ServerEndpoint(value = "/nonused/{nonusedparam}") public class WS0StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String p1; + private String p1; - @OnOpen - public void onOpen(@PathParam("param1") String p1) { - this.p1 = p1; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1) { + this.p1 = p1; + } - @OnMessage - public String param(@PathParam("param1") String p1, String content) - throws IOException { - OPS o = OPS.valueOf(content); - switch (o) { - case OPEN: - content = getPathParam(this.p1); - break; - case MESSAGE: - content = getPathParam(p1); - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, String content) throws IOException { + OPS o = OPS.valueOf(content); + switch (o) { + case OPEN: + content = getPathParam(this.p1); + break; + case MESSAGE: + content = getPathParam(p1); + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, Session session, - Throwable t) throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote().sendText(getPathParam(p1)); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, Session session, Throwable t) throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(getPathParam(p1)); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1) { - WSOnClosePathParamServer.set(0, getPathParam(p1)); - } + @OnClose + public void onClose(@PathParam("param1") String p1) { + WSOnClosePathParamServer.set(0, getPathParam(p1)); + } - private static String getPathParam(String p) { - return p == null ? "null" : p; - } + private static String getPathParam(String p) { + return p == null ? "null" : p; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS10StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS10StringPathParamServer.java index 1f6d6109cd..3c7c4d68ac 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS10StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS10StringPathParamServer.java @@ -31,88 +31,77 @@ @ServerEndpoint(value = "/param/{param1}/{param2}/{param3}/{param4}/{param5}/{param6}/{param7}/{param8}/{param9}/{param10}") public class WS10StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[10]; + private String[] p = new String[10]; - @OnOpen - public void onOpen(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9, - @PathParam("param10") String p10) { - p[0] = p1; - p[1] = p2; - p[2] = p3; - p[3] = p4; - p[4] = p5; - p[5] = p6; - p[6] = p7; - p[7] = p8; - p[8] = p9; - p[9] = p10; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9, + @PathParam("param10") String p10) { + p[0] = p1; + p[1] = p2; + p[2] = p3; + p[3] = p4; + p[4] = p5; + p[5] = p6; + p[6] = p7; + p[7] = p8; + p[8] = p9; + p[9] = p10; + } - @OnMessage - public String param(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9, - @PathParam("param10") String p10, String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + p[7] + p[8] - + p[9]; - break; - case MESSAGE: - content = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10; - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9, + @PathParam("param10") String p10, String content) throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + p[7] + p[8] + p[9]; + break; + case MESSAGE: + content = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10; + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9, - @PathParam("param10") String p10, Session session, Throwable t) - throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote() - .sendText(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9, + @PathParam("param10") String p10, Session session, Throwable t) throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9, - @PathParam("param10") String p10) { - WSOnClosePathParamServer.set(0, p1); - WSOnClosePathParamServer.set(1, p2); - WSOnClosePathParamServer.set(2, p3); - WSOnClosePathParamServer.set(3, p4); - WSOnClosePathParamServer.set(4, p5); - WSOnClosePathParamServer.set(5, p6); - WSOnClosePathParamServer.set(6, p7); - WSOnClosePathParamServer.set(7, p8); - WSOnClosePathParamServer.set(8, p9); - WSOnClosePathParamServer.set(9, p10); - } + @OnClose + public void onClose(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9, + @PathParam("param10") String p10) { + WSOnClosePathParamServer.set(0, p1); + WSOnClosePathParamServer.set(1, p2); + WSOnClosePathParamServer.set(2, p3); + WSOnClosePathParamServer.set(3, p4); + WSOnClosePathParamServer.set(4, p5); + WSOnClosePathParamServer.set(5, p6); + WSOnClosePathParamServer.set(6, p7); + WSOnClosePathParamServer.set(7, p8); + WSOnClosePathParamServer.set(8, p9); + WSOnClosePathParamServer.set(9, p10); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS11StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS11StringPathParamServer.java index cc59c9fd0c..5df47c1ebb 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS11StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS11StringPathParamServer.java @@ -31,91 +31,80 @@ @ServerEndpoint(value = "/param/{param1}/{param2}/{param3}/{param4}/{param5}/{param6}/{param7}/{param8}/{param9}/{param10}/{param11}") public class WS11StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[11]; + private String[] p = new String[11]; - @OnOpen - public void onOpen(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9, - @PathParam("param10") String p10, @PathParam("param11") String p11) { - p[0] = p1; - p[1] = p2; - p[2] = p3; - p[3] = p4; - p[4] = p5; - p[5] = p6; - p[6] = p7; - p[7] = p8; - p[8] = p9; - p[9] = p10; - p[10] = p11; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9, + @PathParam("param10") String p10, @PathParam("param11") String p11) { + p[0] = p1; + p[1] = p2; + p[2] = p3; + p[3] = p4; + p[4] = p5; + p[5] = p6; + p[6] = p7; + p[7] = p8; + p[8] = p9; + p[9] = p10; + p[10] = p11; + } - @OnMessage - public String param(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9, - @PathParam("param10") String p10, @PathParam("param11") String p11, - String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + p[7] + p[8] - + p[9] + p[10]; - break; - case MESSAGE: - content = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11; - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9, + @PathParam("param10") String p10, @PathParam("param11") String p11, String content) throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + p[7] + p[8] + p[9] + p[10]; + break; + case MESSAGE: + content = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11; + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9, - @PathParam("param10") String p10, @PathParam("param11") String p11, - Session session, Throwable t) throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote() - .sendText(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9, + @PathParam("param10") String p10, @PathParam("param11") String p11, Session session, Throwable t) + throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9, - @PathParam("param10") String p10, @PathParam("param11") String p11) { - WSOnClosePathParamServer.set(0, p1); - WSOnClosePathParamServer.set(1, p2); - WSOnClosePathParamServer.set(2, p3); - WSOnClosePathParamServer.set(3, p4); - WSOnClosePathParamServer.set(4, p5); - WSOnClosePathParamServer.set(5, p6); - WSOnClosePathParamServer.set(6, p7); - WSOnClosePathParamServer.set(7, p8); - WSOnClosePathParamServer.set(8, p9); - WSOnClosePathParamServer.set(9, p10); - WSOnClosePathParamServer.set(10, p11); - } + @OnClose + public void onClose(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9, + @PathParam("param10") String p10, @PathParam("param11") String p11) { + WSOnClosePathParamServer.set(0, p1); + WSOnClosePathParamServer.set(1, p2); + WSOnClosePathParamServer.set(2, p3); + WSOnClosePathParamServer.set(3, p4); + WSOnClosePathParamServer.set(4, p5); + WSOnClosePathParamServer.set(5, p6); + WSOnClosePathParamServer.set(6, p7); + WSOnClosePathParamServer.set(7, p8); + WSOnClosePathParamServer.set(8, p9); + WSOnClosePathParamServer.set(9, p10); + WSOnClosePathParamServer.set(10, p11); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS1StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS1StringPathParamServer.java index 4c88a57e73..1755f34723 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS1StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS1StringPathParamServer.java @@ -31,49 +31,47 @@ @ServerEndpoint(value = "/param/{param1}") public class WS1StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String p; + private String p; - @OnOpen - public void onOpen(@PathParam("param1") String p1) { - p = p1; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1) { + p = p1; + } - @OnMessage - public String param(@PathParam("param1") String p1, String content) - throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p; - break; - case MESSAGE: - content = p1; - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, String content) throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p; + break; + case MESSAGE: + content = p1; + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, Session session, - Throwable t) throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote().sendText(p1); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, Session session, Throwable t) throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1) { - WSOnClosePathParamServer.set(0, p1); - } + @OnClose + public void onClose(@PathParam("param1") String p1) { + WSOnClosePathParamServer.set(0, p1); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2DifferentPathParamsServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2DifferentPathParamsServer.java index 7db91e7198..4de0cffb37 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2DifferentPathParamsServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2DifferentPathParamsServer.java @@ -31,55 +31,51 @@ @ServerEndpoint(value = "/different/{param1}/{param2}") public class WS2DifferentPathParamsServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[2]; + private String[] p = new String[2]; - @OnOpen - public void onOpen(@PathParam("param1") boolean p1, - @PathParam("param2") char p2) { - p[0] = String.valueOf(p1); - p[1] = String.valueOf(p2); - } + @OnOpen + public void onOpen(@PathParam("param1") boolean p1, @PathParam("param2") char p2) { + p[0] = String.valueOf(p1); + p[1] = String.valueOf(p2); + } - @OnMessage - public String param(@PathParam("param1") boolean p1, - @PathParam("param2") char p2, String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1]; - break; - case MESSAGE: - content = String.valueOf(p1) + String.valueOf(p2); - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") boolean p1, @PathParam("param2") char p2, String content) + throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1]; + break; + case MESSAGE: + content = String.valueOf(p1) + String.valueOf(p2); + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") boolean p1, - @PathParam("param2") char p2, Session session, Throwable t) - throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote() - .sendText(String.valueOf(p1) + String.valueOf(p2)); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") boolean p1, @PathParam("param2") char p2, Session session, Throwable t) + throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(String.valueOf(p1) + String.valueOf(p2)); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") boolean p1, - @PathParam("param2") char p2) { - WSOnClosePathParamServer.set(0, String.valueOf(p1)); - WSOnClosePathParamServer.set(1, String.valueOf(p2)); - } + @OnClose + public void onClose(@PathParam("param1") boolean p1, @PathParam("param2") char p2) { + WSOnClosePathParamServer.set(0, String.valueOf(p1)); + WSOnClosePathParamServer.set(1, String.valueOf(p2)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2FullDifferentPathParamsServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2FullDifferentPathParamsServer.java index 7f4f2f708f..1bb78be42b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2FullDifferentPathParamsServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2FullDifferentPathParamsServer.java @@ -31,54 +31,51 @@ @ServerEndpoint(value = "/full/{param1}/{param2}") public class WS2FullDifferentPathParamsServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[2]; + private String[] p = new String[2]; - @OnOpen - public void onOpen(@PathParam("param1") Double p1, - @PathParam("param2") Float p2) { - p[0] = p1.toString(); - p[1] = p2.toString(); - } + @OnOpen + public void onOpen(@PathParam("param1") Double p1, @PathParam("param2") Float p2) { + p[0] = p1.toString(); + p[1] = p2.toString(); + } - @OnMessage - public String param(@PathParam("param1") Double p1, - @PathParam("param2") Float p2, String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1]; - break; - case MESSAGE: - content = p1.toString() + p2.toString(); - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") Double p1, @PathParam("param2") Float p2, String content) + throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1]; + break; + case MESSAGE: + content = p1.toString() + p2.toString(); + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") Double p1, - @PathParam("param2") Float p2, Session session, Throwable t) - throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote().sendText(p1.toString() + p2.toString()); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") Double p1, @PathParam("param2") Float p2, Session session, Throwable t) + throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1.toString() + p2.toString()); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") Double p1, - @PathParam("param2") Float p2) { - WSOnClosePathParamServer.set(0, p1.toString()); - WSOnClosePathParamServer.set(1, p2.toString()); - } + @OnClose + public void onClose(@PathParam("param1") Double p1, @PathParam("param2") Float p2) { + WSOnClosePathParamServer.set(0, p1.toString()); + WSOnClosePathParamServer.set(1, p2.toString()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2StringPathParamServer.java index 4d5c4130c2..9037af0cec 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS2StringPathParamServer.java @@ -31,54 +31,51 @@ @ServerEndpoint(value = "/param/{param1}/{param2}") public class WS2StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[2]; + private String[] p = new String[2]; - @OnOpen - public void onOpen(@PathParam("param1") String p1, - @PathParam("param2") String p2) { - p[0] = p1; - p[1] = p2; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1, @PathParam("param2") String p2) { + p[0] = p1; + p[1] = p2; + } - @OnMessage - public String param(@PathParam("param1") String p1, - @PathParam("param2") String p2, String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1]; - break; - case MESSAGE: - content = p1 + p2; - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, @PathParam("param2") String p2, String content) + throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1]; + break; + case MESSAGE: + content = p1 + p2; + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, - @PathParam("param2") String p2, Session session, Throwable t) - throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote().sendText(p1 + p2); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, @PathParam("param2") String p2, Session session, Throwable t) + throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1 + p2); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1, - @PathParam("param2") String p2) { - WSOnClosePathParamServer.set(0, p1); - WSOnClosePathParamServer.set(1, p2); - } + @OnClose + public void onClose(@PathParam("param1") String p1, @PathParam("param2") String p2) { + WSOnClosePathParamServer.set(0, p1); + WSOnClosePathParamServer.set(1, p2); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS3StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS3StringPathParamServer.java index 767fadfb19..229b9cd4b7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS3StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS3StringPathParamServer.java @@ -31,57 +31,54 @@ @ServerEndpoint(value = "/param/{param1}/{param2}/{param3}") public class WS3StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[3]; + private String[] p = new String[3]; - @OnOpen - public void onOpen(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3) { - p[0] = p1; - p[1] = p2; - p[2] = p3; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3) { + p[0] = p1; + p[1] = p2; + p[2] = p3; + } - @OnMessage - public String param(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1] + p[2]; - break; - case MESSAGE: - content = p1 + p2 + p3; - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + String content) throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1] + p[2]; + break; + case MESSAGE: + content = p1 + p2 + p3; + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - Session session, Throwable t) throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote().sendText(p1 + p2 + p3); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + Session session, Throwable t) throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1 + p2 + p3); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3) { - WSOnClosePathParamServer.set(0, p1); - WSOnClosePathParamServer.set(1, p2); - WSOnClosePathParamServer.set(2, p3); - } + @OnClose + public void onClose(@PathParam("param1") String p1, @PathParam("param2") String p2, + @PathParam("param3") String p3) { + WSOnClosePathParamServer.set(0, p1); + WSOnClosePathParamServer.set(1, p2); + WSOnClosePathParamServer.set(2, p3); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS4StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS4StringPathParamServer.java index c35f299b8c..902266f73c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS4StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS4StringPathParamServer.java @@ -31,62 +31,57 @@ @ServerEndpoint(value = "/param/{param1}/{param2}/{param3}/{param4}") public class WS4StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[4]; + private String[] p = new String[4]; - @OnOpen - public void onOpen(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4) { - p[0] = p1; - p[1] = p2; - p[2] = p3; - p[3] = p4; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4) { + p[0] = p1; + p[1] = p2; + p[2] = p3; + p[3] = p4; + } - @OnMessage - public String param(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1] + p[2] + p[3]; - break; - case MESSAGE: - content = p1 + p2 + p3 + p4; - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, String content) throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1] + p[2] + p[3]; + break; + case MESSAGE: + content = p1 + p2 + p3 + p4; + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, Session session, Throwable t) - throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote().sendText(p1 + p2 + p3 + p4); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, Session session, Throwable t) throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1 + p2 + p3 + p4); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4) { - WSOnClosePathParamServer.set(0, p1); - WSOnClosePathParamServer.set(1, p2); - WSOnClosePathParamServer.set(2, p3); - WSOnClosePathParamServer.set(3, p4); - } + @OnClose + public void onClose(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4) { + WSOnClosePathParamServer.set(0, p1); + WSOnClosePathParamServer.set(1, p2); + WSOnClosePathParamServer.set(2, p3); + WSOnClosePathParamServer.set(3, p4); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS5StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS5StringPathParamServer.java index 5ced80e945..3f834b6439 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS5StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS5StringPathParamServer.java @@ -31,65 +31,60 @@ @ServerEndpoint(value = "/param/{param1}/{param2}/{param3}/{param4}/{param5}") public class WS5StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[5]; + private String[] p = new String[5]; - @OnOpen - public void onOpen(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5) { - p[0] = p1; - p[1] = p2; - p[2] = p3; - p[3] = p4; - p[4] = p5; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5) { + p[0] = p1; + p[1] = p2; + p[2] = p3; + p[3] = p4; + p[4] = p5; + } - @OnMessage - public String param(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1] + p[2] + p[3] + p[4]; - break; - case MESSAGE: - content = p1 + p2 + p3 + p4 + p5; - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, String content) throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1] + p[2] + p[3] + p[4]; + break; + case MESSAGE: + content = p1 + p2 + p3 + p4 + p5; + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - Session session, Throwable t) throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote().sendText(p1 + p2 + p3 + p4 + p5); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, Session session, Throwable t) + throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1 + p2 + p3 + p4 + p5); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5) { - WSOnClosePathParamServer.set(0, p1); - WSOnClosePathParamServer.set(1, p2); - WSOnClosePathParamServer.set(2, p3); - WSOnClosePathParamServer.set(3, p4); - WSOnClosePathParamServer.set(4, p5); - } + @OnClose + public void onClose(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5) { + WSOnClosePathParamServer.set(0, p1); + WSOnClosePathParamServer.set(1, p2); + WSOnClosePathParamServer.set(2, p3); + WSOnClosePathParamServer.set(3, p4); + WSOnClosePathParamServer.set(4, p5); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS6StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS6StringPathParamServer.java index e5e32b5bbe..bc0e8183c7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS6StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS6StringPathParamServer.java @@ -31,70 +31,63 @@ @ServerEndpoint(value = "/param/{param1}/{param2}/{param3}/{param4}/{param5}/{param6}") public class WS6StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[6]; + private String[] p = new String[6]; - @OnOpen - public void onOpen(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6) { - p[0] = p1; - p[1] = p2; - p[2] = p3; - p[3] = p4; - p[4] = p5; - p[5] = p6; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6) { + p[0] = p1; + p[1] = p2; + p[2] = p3; + p[3] = p4; + p[4] = p5; + p[5] = p6; + } - @OnMessage - public String param(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5]; - break; - case MESSAGE: - content = p1 + p2 + p3 + p4 + p5 + p6; - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + String content) throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5]; + break; + case MESSAGE: + content = p1 + p2 + p3 + p4 + p5 + p6; + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, Session session, Throwable t) - throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote().sendText(p1 + p2 + p3 + p4 + p5 + p6); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + Session session, Throwable t) throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1 + p2 + p3 + p4 + p5 + p6); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6) { - WSOnClosePathParamServer.set(0, p1); - WSOnClosePathParamServer.set(1, p2); - WSOnClosePathParamServer.set(2, p3); - WSOnClosePathParamServer.set(3, p4); - WSOnClosePathParamServer.set(4, p5); - WSOnClosePathParamServer.set(5, p6); - } + @OnClose + public void onClose(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6) { + WSOnClosePathParamServer.set(0, p1); + WSOnClosePathParamServer.set(1, p2); + WSOnClosePathParamServer.set(2, p3); + WSOnClosePathParamServer.set(3, p4); + WSOnClosePathParamServer.set(4, p5); + WSOnClosePathParamServer.set(5, p6); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS7StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS7StringPathParamServer.java index 7c60804593..650f35f87e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS7StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS7StringPathParamServer.java @@ -31,73 +31,67 @@ @ServerEndpoint(value = "/param/{param1}/{param2}/{param3}/{param4}/{param5}/{param6}/{param7}") public class WS7StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[7]; + private String[] p = new String[7]; - @OnOpen - public void onOpen(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7) { - p[0] = p1; - p[1] = p2; - p[2] = p3; - p[3] = p4; - p[4] = p5; - p[5] = p6; - p[6] = p7; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7) { + p[0] = p1; + p[1] = p2; + p[2] = p3; + p[3] = p4; + p[4] = p5; + p[5] = p6; + p[6] = p7; + } - @OnMessage - public String param(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6]; - break; - case MESSAGE: - content = p1 + p2 + p3 + p4 + p5 + p6 + p7; - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, String content) throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6]; + break; + case MESSAGE: + content = p1 + p2 + p3 + p4 + p5 + p6 + p7; + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - Session session, Throwable t) throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote().sendText(p1 + p2 + p3 + p4 + p5 + p6 + p7); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, Session session, Throwable t) throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1 + p2 + p3 + p4 + p5 + p6 + p7); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7) { - WSOnClosePathParamServer.set(0, p1); - WSOnClosePathParamServer.set(1, p2); - WSOnClosePathParamServer.set(2, p3); - WSOnClosePathParamServer.set(3, p4); - WSOnClosePathParamServer.set(4, p5); - WSOnClosePathParamServer.set(5, p6); - WSOnClosePathParamServer.set(6, p7); - } + @OnClose + public void onClose(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7) { + WSOnClosePathParamServer.set(0, p1); + WSOnClosePathParamServer.set(1, p2); + WSOnClosePathParamServer.set(2, p3); + WSOnClosePathParamServer.set(3, p4); + WSOnClosePathParamServer.set(4, p5); + WSOnClosePathParamServer.set(5, p6); + WSOnClosePathParamServer.set(6, p7); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS8StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS8StringPathParamServer.java index 03577c7ec6..06588b8c6f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS8StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS8StringPathParamServer.java @@ -31,78 +31,70 @@ @ServerEndpoint(value = "/param/{param1}/{param2}/{param3}/{param4}/{param5}/{param6}/{param7}/{param8}") public class WS8StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[8]; + private String[] p = new String[8]; - @OnOpen - public void onOpen(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8) { - p[0] = p1; - p[1] = p2; - p[2] = p3; - p[3] = p4; - p[4] = p5; - p[5] = p6; - p[6] = p7; - p[7] = p8; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8) { + p[0] = p1; + p[1] = p2; + p[2] = p3; + p[3] = p4; + p[4] = p5; + p[5] = p6; + p[6] = p7; + p[7] = p8; + } - @OnMessage - public String param(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + p[7]; - break; - case MESSAGE: - content = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8; - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, String content) throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + p[7]; + break; + case MESSAGE: + content = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8; + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, Session session, Throwable t) - throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote().sendText(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, Session session, Throwable t) + throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8) { - WSOnClosePathParamServer.set(0, p1); - WSOnClosePathParamServer.set(1, p2); - WSOnClosePathParamServer.set(2, p3); - WSOnClosePathParamServer.set(3, p4); - WSOnClosePathParamServer.set(4, p5); - WSOnClosePathParamServer.set(5, p6); - WSOnClosePathParamServer.set(6, p7); - WSOnClosePathParamServer.set(7, p8); - } + @OnClose + public void onClose(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8) { + WSOnClosePathParamServer.set(0, p1); + WSOnClosePathParamServer.set(1, p2); + WSOnClosePathParamServer.set(2, p3); + WSOnClosePathParamServer.set(3, p4); + WSOnClosePathParamServer.set(4, p5); + WSOnClosePathParamServer.set(5, p6); + WSOnClosePathParamServer.set(6, p7); + WSOnClosePathParamServer.set(7, p8); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS9StringPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS9StringPathParamServer.java index 802915cbbb..bc6245a232 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS9StringPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WS9StringPathParamServer.java @@ -31,82 +31,73 @@ @ServerEndpoint(value = "/param/{param1}/{param2}/{param3}/{param4}/{param5}/{param6}/{param7}/{param8}/{param9}") public class WS9StringPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; + private final static String ERR = "TCK INTENDED ERROR"; - private String[] p = new String[9]; + private String[] p = new String[9]; - @OnOpen - public void onOpen(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9) { - p[0] = p1; - p[1] = p2; - p[2] = p3; - p[3] = p4; - p[4] = p5; - p[5] = p6; - p[6] = p7; - p[7] = p8; - p[8] = p9; - } + @OnOpen + public void onOpen(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9) { + p[0] = p1; + p[1] = p2; + p[2] = p3; + p[3] = p4; + p[4] = p5; + p[5] = p6; + p[6] = p7; + p[7] = p8; + p[8] = p9; + } - @OnMessage - public String param(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9, - String content) throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + p[7] + p[8]; - break; - case MESSAGE: - content = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9; - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnMessage + public String param(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9, + String content) throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p[0] + p[1] + p[2] + p[3] + p[4] + p[5] + p[6] + p[7] + p[8]; + break; + case MESSAGE: + content = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9; + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnError - public void onError(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9, - Session session, Throwable t) throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote() - .sendText(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnError + public void onError(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9, + Session session, Throwable t) throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } - @OnClose - public void onClose(@PathParam("param1") String p1, - @PathParam("param2") String p2, @PathParam("param3") String p3, - @PathParam("param4") String p4, @PathParam("param5") String p5, - @PathParam("param6") String p6, @PathParam("param7") String p7, - @PathParam("param8") String p8, @PathParam("param9") String p9) { - WSOnClosePathParamServer.set(0, p1); - WSOnClosePathParamServer.set(1, p2); - WSOnClosePathParamServer.set(2, p3); - WSOnClosePathParamServer.set(3, p4); - WSOnClosePathParamServer.set(4, p5); - WSOnClosePathParamServer.set(5, p6); - WSOnClosePathParamServer.set(6, p7); - WSOnClosePathParamServer.set(7, p8); - WSOnClosePathParamServer.set(8, p9); - } + @OnClose + public void onClose(@PathParam("param1") String p1, @PathParam("param2") String p2, @PathParam("param3") String p3, + @PathParam("param4") String p4, @PathParam("param5") String p5, @PathParam("param6") String p6, + @PathParam("param7") String p7, @PathParam("param8") String p8, @PathParam("param9") String p9) { + WSOnClosePathParamServer.set(0, p1); + WSOnClosePathParamServer.set(1, p2); + WSOnClosePathParamServer.set(2, p3); + WSOnClosePathParamServer.set(3, p4); + WSOnClosePathParamServer.set(4, p5); + WSOnClosePathParamServer.set(5, p6); + WSOnClosePathParamServer.set(6, p7); + WSOnClosePathParamServer.set(7, p8); + WSOnClosePathParamServer.set(8, p9); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSClient.java deleted file mode 100644 index a8b03f7de5..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSClient.java +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.pathparam; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = -6963654147324631018L; - - public WSClient() { - setContextRoot("ws_ee_jakarta_websocket_server_pathparam_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - // -----------------------------On Message - - /* - * @testName: multipleStringParamsOnMessageTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-4; - * - * @test_Strategy: test sending more path params - */ - public void multipleStringParamsOnMessageTest() throws Exception { - multipleStringParams(OPS.MESSAGE); - } - - /* - * @testName: noStringParamsOnMessageTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: test sending zero path params If the name does not match a - * path variable in the URI-template, the value of the method parameter this - * annotation annotates is null. - */ - public void noStringParamsOnMessageTest() throws Exception { - noStringParams(OPS.MESSAGE); - } - - /* - * @testName: directStringParamOnMessageTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-4; - * - * @test_Strategy: test sending zero path params - */ - public void directStringParamOnMessageTest() throws Exception { - directStringParam(OPS.MESSAGE); - } - - /* - * @testName: primitiveBooleanAndCharParamsOnMessageTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-5; - * - * @test_Strategy: test sending boolean and char to primitives - */ - public void primitiveBooleanAndCharParamsOnMessageTest() throws Exception { - primitiveBooleanAndCharParams(OPS.MESSAGE); - } - - /* - * @testName: fullDoubleAndFloatParamsOnMessageTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-5; - * - * @test_Strategy: test sending double and float to Full classes - */ - public void fullDoubleAndFloatParamsOnMessageTest() throws Exception { - fullDoubleAndFloatParams(OPS.MESSAGE); - } - - // -----------------------------On Open - - /* - * @testName: multipleStringParamsOnOpenTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-4; - * - * @test_Strategy: test sending more path params - */ - public void multipleStringParamsOnOpenTest() throws Exception { - multipleStringParams(OPS.OPEN); - } - - /* - * @testName: noStringParamsOnOpenTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: test sending zero path params If the name does not match a - * path variable in the URI-template, the value of the method parameter this - * annotation annotates is null. - */ - public void noStringParamsOnOpenTest() throws Exception { - noStringParams(OPS.OPEN); - } - - /* - * @testName: directStringParamOnOpenTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-4; - * - * @test_Strategy: test sending zero path params - */ - public void directStringParamOnOpenTest() throws Exception { - directStringParam(OPS.OPEN); - } - - /* - * @testName: primitiveBooleanAndCharParamsOnOpenTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-5; - * - * @test_Strategy: test sending boolean and char to primitives - */ - public void primitiveBooleanAndCharParamsOnOpenTest() throws Exception { - primitiveBooleanAndCharParams(OPS.OPEN); - } - - /* - * @testName: fullDoubleAndFloatParamsOnOpenTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-5; - * - * @test_Strategy: test sending double and float to Full classes - */ - public void fullDoubleAndFloatParamsOnOpenTest() throws Exception { - fullDoubleAndFloatParams(OPS.OPEN); - } - - // -----------------------------On IOException - - /* - * @testName: multipleStringParamsOnIOETest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-4; - * - * @test_Strategy: test sending more path params - */ - public void multipleStringParamsOnIOETest() throws Exception { - multipleStringParams(OPS.IOEXCEPTION); - } - - /* - * @testName: noStringParamsOnIOETest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: test sending zero path params If the name does not match a - * path variable in the URI-template, the value of the method parameter this - * annotation annotates is null. - */ - public void noStringParamsOnIOETest() throws Exception { - noStringParams(OPS.IOEXCEPTION); - } - - /* - * @testName: directStringParamOnIOETest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-4; - * - * @test_Strategy: test sending zero path params - */ - public void directStringParamOnIOETest() throws Exception { - directStringParam(OPS.IOEXCEPTION); - } - - /* - * @testName: primitiveBooleanAndCharParamsOnIOETest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-5; - * - * @test_Strategy: test sending boolean and char to primitives - */ - public void primitiveBooleanAndCharParamsOnIOETest() throws Exception { - primitiveBooleanAndCharParams(OPS.IOEXCEPTION); - } - - /* - * @testName: fullDoubleAndFloatParamsOnIOTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-5; - * - * @test_Strategy: test sending double and float to Full classes - */ - public void fullDoubleAndFloatParamsOnIOTest() throws Exception { - fullDoubleAndFloatParams(OPS.IOEXCEPTION); - } - - // -----------------------------On RuntimeException - - /* - * @testName: multipleStringParamsOnRETest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-4; - * - * @test_Strategy: test sending more path params - */ - public void multipleStringParamsOnRETest() throws Exception { - multipleStringParams(OPS.RUNTIMEEXCEPTION); - } - - /* - * @testName: noStringParamsOnRETest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: test sending zero path params If the name does not match a - * path variable in the URI-template, the value of the method parameter this - * annotation annotates is null. - */ - public void noStringParamsOnRETest() throws Exception { - noStringParams(OPS.RUNTIMEEXCEPTION); - } - - /* - * @testName: directStringParamOnRETest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-4; - * - * @test_Strategy: test sending zero path params - */ - public void directStringParamOnRETest() throws Exception { - directStringParam(OPS.RUNTIMEEXCEPTION); - } - - /* - * @testName: primitiveBooleanAndCharParamsOnRETest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-5; - * - * @test_Strategy: test sending boolean and char to primitives - */ - public void primitiveBooleanAndCharParamsOnRETest() throws Exception { - primitiveBooleanAndCharParams(OPS.RUNTIMEEXCEPTION); - } - - /* - * @testName: fullDoubleAndFloatParamsOnRETest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-5; - * - * @test_Strategy: test sending double and float to Full classes - */ - public void fullDoubleAndFloatParamsOnRETest() throws Exception { - fullDoubleAndFloatParams(OPS.RUNTIMEEXCEPTION); - } - - // -----------------------------On Close - - /* - * @testName: multipleStringParamsOnCloseTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-4; - * - * @test_Strategy: test sending more path params - */ - public void multipleStringParamsOnCloseTest() throws Exception { - String param = "param"; - StringBuilder sb = new StringBuilder(); - for (int i = 1; i != 12; i++) { - invoke("onclose", "-1", WSOnClosePathParamServer.RESET); - sb.append("/").append(param).append(i); - setProperty(Property.REQUEST, buildRequest(param, sb.toString())); - setProperty(Property.SEARCH_STRING, sb.toString().replace("/", "")); - setProperty(Property.CONTENT, OPS.MESSAGE.name()); - invoke(); - TestUtil.sleepMsec(200); - for (int j = 0; j != i; j++) - invoke("onclose", String.valueOf(j), param + String.valueOf(j + 1)); - } - } - - /* - * @testName: noStringParamsOnCloseTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: test sending zero path params If the name does not match a - * path variable in the URI-template, the value of the method parameter this - * annotation annotates is null. - */ - public void noStringParamsOnCloseTest() throws Exception { - invoke("onclose", "-1", WSOnClosePathParamServer.RESET); - String search = noStringParams(OPS.MESSAGE); - TestUtil.sleepMsec(200); - invoke("onclose", "0", search); - } - - /* - * @testName: directStringParamOnCloseTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-4; - * - * @test_Strategy: test sending zero path params - */ - public void directStringParamOnCloseTest() throws Exception { - invoke("onclose", "-1", WSOnClosePathParamServer.RESET); - String search = directStringParam(OPS.MESSAGE); - TestUtil.sleepMsec(200); - invoke("onclose", "0", search); - } - - /* - * @testName: primitiveBooleanAndCharParamsOnCloseTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-5; - * - * @test_Strategy: test sending boolean and char to primitives - */ - public void primitiveBooleanAndCharParamsOnCloseTest() throws Exception { - invoke("onclose", "-1", WSOnClosePathParamServer.RESET); - String[] search = primitiveBooleanAndCharParams(OPS.MESSAGE); - TestUtil.sleepMsec(200); - invoke("onclose", "0", search[0]); - invoke("onclose", "1", search[1]); - } - - /* - * @testName: fullDoubleAndFloatParamsOnCloseTest - * - * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; - * WebSocket:SPEC:WSC-4.3-5; - * - * @test_Strategy: test sending double and float to Full classes - */ - public void fullDoubleAndFloatParamsOnCloseTest() throws Exception { - invoke("onclose", "-1", WSOnClosePathParamServer.RESET); - String[] search = fullDoubleAndFloatParams(OPS.RUNTIMEEXCEPTION); - TestUtil.sleepMsec(200); - invoke("onclose", "0", search[0]); - invoke("onclose", "1", search[1]); - } - - // ------------------------------------------------------------------- - private void multipleStringParams(OPS op) throws Exception { - String param = "param"; - StringBuilder sb = new StringBuilder(); - for (int i = 1; i != 12; i++) { - sb.append("/").append(param).append(i); - setProperty(Property.REQUEST, buildRequest(param, sb.toString())); - setProperty(Property.SEARCH_STRING, sb.toString().replace("/", "")); - setProperty(Property.CONTENT, op.name()); - invoke(); - } - } - - private String noStringParams(OPS op) throws Exception { - String param = "nonused/nonused"; - String search = "null"; - setProperty(Property.REQUEST, buildRequest(param)); - setProperty(Property.SEARCH_STRING, search); - setProperty(Property.CONTENT, op.name()); - invoke(); - return search; - } - - private String directStringParam(OPS op) throws Exception { - String param = "1234567890"; - setProperty(Property.REQUEST, buildRequest(param)); - setProperty(Property.SEARCH_STRING, param); - setProperty(Property.CONTENT, op.name()); - invoke(); - return param; - } - - private String[] primitiveBooleanAndCharParams(OPS op) throws Exception { - String[] param = { "true", "0" }; - setProperty(Property.REQUEST, - buildRequest("different/", param[0], "/", param[1])); - setProperty(Property.SEARCH_STRING, param[0] + param[1]); - setProperty(Property.CONTENT, op.name()); - invoke(); - return param; - } - - private String[] fullDoubleAndFloatParams(OPS op) throws Exception { - String[] param = { String.valueOf(12.34), String.valueOf(56.78f) }; - setProperty(Property.REQUEST, - buildRequest("full/", param[0], "/", param[1])); - setProperty(Property.SEARCH_STRING, param[0] + param[1]); - setProperty(Property.CONTENT, op.name()); - invoke(); - return param; - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSClientIT.java new file mode 100644 index 0000000000..7b31691d96 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSClientIT.java @@ -0,0 +1,474 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.pathparam; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = -6963654147324631018L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_ee_jakarta_websocket_server_pathparam_web.war"); + archive.addPackages(true, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.server.pathparam"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("ws_ee_jakarta_websocket_server_pathparam_web"); + } + + /* Run test */ + + // -----------------------------On Message + + /* + * @testName: multipleStringParamsOnMessageTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-4; + * + * @test_Strategy: test sending more path params + */ + @Test + public void multipleStringParamsOnMessageTest() throws Exception { + multipleStringParams(OPS.MESSAGE); + } + + /* + * @testName: noStringParamsOnMessageTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: test sending zero path params If the name does not match a + * path variable in the URI-template, the value of the method parameter this + * annotation annotates is null. + */ + @Test + public void noStringParamsOnMessageTest() throws Exception { + noStringParams(OPS.MESSAGE); + } + + /* + * @testName: directStringParamOnMessageTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-4; + * + * @test_Strategy: test sending zero path params + */ + @Test + public void directStringParamOnMessageTest() throws Exception { + directStringParam(OPS.MESSAGE); + } + + /* + * @testName: primitiveBooleanAndCharParamsOnMessageTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-5; + * + * @test_Strategy: test sending boolean and char to primitives + */ + @Test + public void primitiveBooleanAndCharParamsOnMessageTest() throws Exception { + primitiveBooleanAndCharParams(OPS.MESSAGE); + } + + /* + * @testName: fullDoubleAndFloatParamsOnMessageTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-5; + * + * @test_Strategy: test sending double and float to Full classes + */ + @Test + public void fullDoubleAndFloatParamsOnMessageTest() throws Exception { + fullDoubleAndFloatParams(OPS.MESSAGE); + } + + // -----------------------------On Open + + /* + * @testName: multipleStringParamsOnOpenTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-4; + * + * @test_Strategy: test sending more path params + */ + @Test + public void multipleStringParamsOnOpenTest() throws Exception { + multipleStringParams(OPS.OPEN); + } + + /* + * @testName: noStringParamsOnOpenTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: test sending zero path params If the name does not match a + * path variable in the URI-template, the value of the method parameter this + * annotation annotates is null. + */ + @Test + public void noStringParamsOnOpenTest() throws Exception { + noStringParams(OPS.OPEN); + } + + /* + * @testName: directStringParamOnOpenTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-4; + * + * @test_Strategy: test sending zero path params + */ + @Test + public void directStringParamOnOpenTest() throws Exception { + directStringParam(OPS.OPEN); + } + + /* + * @testName: primitiveBooleanAndCharParamsOnOpenTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-5; + * + * @test_Strategy: test sending boolean and char to primitives + */ + @Test + public void primitiveBooleanAndCharParamsOnOpenTest() throws Exception { + primitiveBooleanAndCharParams(OPS.OPEN); + } + + /* + * @testName: fullDoubleAndFloatParamsOnOpenTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-5; + * + * @test_Strategy: test sending double and float to Full classes + */ + @Test + public void fullDoubleAndFloatParamsOnOpenTest() throws Exception { + fullDoubleAndFloatParams(OPS.OPEN); + } + + // -----------------------------On IOException + + /* + * @testName: multipleStringParamsOnIOETest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-4; + * + * @test_Strategy: test sending more path params + */ + @Test + public void multipleStringParamsOnIOETest() throws Exception { + multipleStringParams(OPS.IOEXCEPTION); + } + + /* + * @testName: noStringParamsOnIOETest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: test sending zero path params If the name does not match a + * path variable in the URI-template, the value of the method parameter this + * annotation annotates is null. + */ + @Test + public void noStringParamsOnIOETest() throws Exception { + noStringParams(OPS.IOEXCEPTION); + } + + /* + * @testName: directStringParamOnIOETest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-4; + * + * @test_Strategy: test sending zero path params + */ + @Test + public void directStringParamOnIOETest() throws Exception { + directStringParam(OPS.IOEXCEPTION); + } + + /* + * @testName: primitiveBooleanAndCharParamsOnIOETest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-5; + * + * @test_Strategy: test sending boolean and char to primitives + */ + @Test + public void primitiveBooleanAndCharParamsOnIOETest() throws Exception { + primitiveBooleanAndCharParams(OPS.IOEXCEPTION); + } + + /* + * @testName: fullDoubleAndFloatParamsOnIOTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-5; + * + * @test_Strategy: test sending double and float to Full classes + */ + @Test + public void fullDoubleAndFloatParamsOnIOTest() throws Exception { + fullDoubleAndFloatParams(OPS.IOEXCEPTION); + } + + // -----------------------------On RuntimeException + + /* + * @testName: multipleStringParamsOnRETest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-4; + * + * @test_Strategy: test sending more path params + */ + @Test + public void multipleStringParamsOnRETest() throws Exception { + multipleStringParams(OPS.RUNTIMEEXCEPTION); + } + + /* + * @testName: noStringParamsOnRETest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: test sending zero path params If the name does not match a + * path variable in the URI-template, the value of the method parameter this + * annotation annotates is null. + */ + @Test + public void noStringParamsOnRETest() throws Exception { + noStringParams(OPS.RUNTIMEEXCEPTION); + } + + /* + * @testName: directStringParamOnRETest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-4; + * + * @test_Strategy: test sending zero path params + */ + @Test + public void directStringParamOnRETest() throws Exception { + directStringParam(OPS.RUNTIMEEXCEPTION); + } + + /* + * @testName: primitiveBooleanAndCharParamsOnRETest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-5; + * + * @test_Strategy: test sending boolean and char to primitives + */ + @Test + public void primitiveBooleanAndCharParamsOnRETest() throws Exception { + primitiveBooleanAndCharParams(OPS.RUNTIMEEXCEPTION); + } + + /* + * @testName: fullDoubleAndFloatParamsOnRETest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-5; + * + * @test_Strategy: test sending double and float to Full classes + */ + @Test + public void fullDoubleAndFloatParamsOnRETest() throws Exception { + fullDoubleAndFloatParams(OPS.RUNTIMEEXCEPTION); + } + + // -----------------------------On Close + + /* + * @testName: multipleStringParamsOnCloseTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-4; + * + * @test_Strategy: test sending more path params + */ + @Test + public void multipleStringParamsOnCloseTest() throws Exception { + String param = "param"; + StringBuilder sb = new StringBuilder(); + for (int i = 1; i != 12; i++) { + invoke("onclose", "-1", WSOnClosePathParamServer.RESET); + sb.append("/").append(param).append(i); + setProperty(Property.REQUEST, buildRequest(param, sb.toString())); + setProperty(Property.SEARCH_STRING, sb.toString().replace("/", "")); + setProperty(Property.CONTENT, OPS.MESSAGE.name()); + invoke(); + TestUtil.sleepMsec(200); + for (int j = 0; j != i; j++) + invoke("onclose", String.valueOf(j), param + String.valueOf(j + 1)); + } + } + + /* + * @testName: noStringParamsOnCloseTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: test sending zero path params If the name does not match a + * path variable in the URI-template, the value of the method parameter this + * annotation annotates is null. + */ + @Test + public void noStringParamsOnCloseTest() throws Exception { + invoke("onclose", "-1", WSOnClosePathParamServer.RESET); + String search = noStringParams(OPS.MESSAGE); + TestUtil.sleepMsec(200); + invoke("onclose", "0", search); + } + + /* + * @testName: directStringParamOnCloseTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-4; + * + * @test_Strategy: test sending zero path params + */ + @Test + public void directStringParamOnCloseTest() throws Exception { + invoke("onclose", "-1", WSOnClosePathParamServer.RESET); + String search = directStringParam(OPS.MESSAGE); + TestUtil.sleepMsec(200); + invoke("onclose", "0", search); + } + + /* + * @testName: primitiveBooleanAndCharParamsOnCloseTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-5; + * + * @test_Strategy: test sending boolean and char to primitives + */ + @Test + public void primitiveBooleanAndCharParamsOnCloseTest() throws Exception { + invoke("onclose", "-1", WSOnClosePathParamServer.RESET); + String[] search = primitiveBooleanAndCharParams(OPS.MESSAGE); + TestUtil.sleepMsec(200); + invoke("onclose", "0", search[0]); + invoke("onclose", "1", search[1]); + } + + /* + * @testName: fullDoubleAndFloatParamsOnCloseTest + * + * @assertion_ids: WebSocket:JAVADOC:181; WebSocket:SPEC:WSC-4.3-3; + * WebSocket:SPEC:WSC-4.3-5; + * + * @test_Strategy: test sending double and float to Full classes + */ + @Test + public void fullDoubleAndFloatParamsOnCloseTest() throws Exception { + invoke("onclose", "-1", WSOnClosePathParamServer.RESET); + String[] search = fullDoubleAndFloatParams(OPS.RUNTIMEEXCEPTION); + TestUtil.sleepMsec(200); + invoke("onclose", "0", search[0]); + invoke("onclose", "1", search[1]); + } + + // ------------------------------------------------------------------- + private void multipleStringParams(OPS op) throws Exception { + String param = "param"; + StringBuilder sb = new StringBuilder(); + for (int i = 1; i != 12; i++) { + sb.append("/").append(param).append(i); + setProperty(Property.REQUEST, buildRequest(param, sb.toString())); + setProperty(Property.SEARCH_STRING, sb.toString().replace("/", "")); + setProperty(Property.CONTENT, op.name()); + invoke(); + } + } + + private String noStringParams(OPS op) throws Exception { + String param = "nonused/nonused"; + String search = "null"; + setProperty(Property.REQUEST, buildRequest(param)); + setProperty(Property.SEARCH_STRING, search); + setProperty(Property.CONTENT, op.name()); + invoke(); + return search; + } + + private String directStringParam(OPS op) throws Exception { + String param = "1234567890"; + setProperty(Property.REQUEST, buildRequest(param)); + setProperty(Property.SEARCH_STRING, param); + setProperty(Property.CONTENT, op.name()); + invoke(); + return param; + } + + private String[] primitiveBooleanAndCharParams(OPS op) throws Exception { + String[] param = { "true", "0" }; + setProperty(Property.REQUEST, buildRequest("different/", param[0], "/", param[1])); + setProperty(Property.SEARCH_STRING, param[0] + param[1]); + setProperty(Property.CONTENT, op.name()); + invoke(); + return param; + } + + private String[] fullDoubleAndFloatParams(OPS op) throws Exception { + String[] param = { String.valueOf(12.34), String.valueOf(56.78f) }; + setProperty(Property.REQUEST, buildRequest("full/", param[0], "/", param[1])); + setProperty(Property.SEARCH_STRING, param[0] + param[1]); + setProperty(Property.CONTENT, op.name()); + invoke(); + return param; + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSDirectLongPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSDirectLongPathParamServer.java index 1d7a999831..761f4272e3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSDirectLongPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSDirectLongPathParamServer.java @@ -31,49 +31,48 @@ @ServerEndpoint(value = "/{param1}") public class WSDirectLongPathParamServer { - private final static String ERR = "TCK INTENDED ERROR"; - private String p; + private final static String ERR = "TCK INTENDED ERROR"; - @OnOpen - public void onOpen(@PathParam("param1") Long p1) { - p = p1.toString(); - } + private String p; - @OnMessage - public String param(@PathParam("param1") Long p1, String content) - throws IOException { - OPS op = OPS.valueOf(content); - switch (op) { - case OPEN: - content = p; - break; - case MESSAGE: - content = p1.toString(); - break; - case IOEXCEPTION: - throw new IOException(ERR); - case RUNTIMEEXCEPTION: - throw new RuntimeException(ERR); - } - return content; - } + @OnOpen + public void onOpen(@PathParam("param1") Long p1) { + p = p1.toString(); + } - @OnError - public void onError(@PathParam("param1") Long p1, Session session, - Throwable t) throws IOException { - String msg = t.getMessage(); - if (ERR.equals(msg)) { - session.getBasicRemote().sendText(p1.toString()); - } else { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } - } + @OnMessage + public String param(@PathParam("param1") Long p1, String content) throws IOException { + OPS op = OPS.valueOf(content); + switch (op) { + case OPEN: + content = p; + break; + case MESSAGE: + content = p1.toString(); + break; + case IOEXCEPTION: + throw new IOException(ERR); + case RUNTIMEEXCEPTION: + throw new RuntimeException(ERR); + } + return content; + } - @OnClose - public void onClose(@PathParam("param1") Long p1) { - WSOnClosePathParamServer.set(0, p1.toString()); - } + @OnError + public void onError(@PathParam("param1") Long p1, Session session, Throwable t) throws IOException { + String msg = t.getMessage(); + if (ERR.equals(msg)) { + session.getBasicRemote().sendText(p1.toString()); + } else { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } + } + + @OnClose + public void onClose(@PathParam("param1") Long p1) { + WSOnClosePathParamServer.set(0, p1.toString()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSOnClosePathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSOnClosePathParamServer.java index 3b0c8791f1..9b356a6ef3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSOnClosePathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/pathparam/WSOnClosePathParamServer.java @@ -29,34 +29,34 @@ @ServerEndpoint(value = "/onclose") public class WSOnClosePathParamServer { - public static final String RESET = "path params has been reset"; - - private static final String[] p = new String[11]; - - @OnMessage - public String param(String content) { - int i = Integer.parseInt(content); - if (i == -1) { - for (int j = 0; j != p.length; j++) - p[j] = ""; - return RESET; - } - return get(i); - } - - public static final void set(int i, String param) { - p[i] = param; - } - - private static final String get(int i) { - return p[i]; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + public static final String RESET = "path params has been reset"; + + private static final String[] p = new String[11]; + + @OnMessage + public String param(String content) { + int i = Integer.parseInt(content); + if (i == -1) { + for (int j = 0; j != p.length; j++) + p[j] = ""; + return RESET; + } + return get(i); + } + + public static final void set(int i, String param) { + p[i] = param; + } + + private static final String get(int i) { + return p[i]; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/AppConfig.java index 1a38d32554..1e60debe49 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/AppConfig.java @@ -26,18 +26,17 @@ public class AppConfig implements ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - set.add(new UsedServerEndpointConfig()); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + set.add(new UsedServerEndpointConfig()); + return set; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(WSUsedServer.class); - return set; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(WSUsedServer.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/OtherAppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/OtherAppConfig.java index c2ed198e30..d521d814dd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/OtherAppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/OtherAppConfig.java @@ -26,17 +26,16 @@ public class OtherAppConfig implements ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - return null; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + return null; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(WSOtherUsedServer.class); - return set; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(WSOtherUsedServer.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/UnusedServerEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/UnusedServerEndpointConfig.java index 220aac1b8f..cb37fde707 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/UnusedServerEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/UnusedServerEndpointConfig.java @@ -28,45 +28,45 @@ public class UnusedServerEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSConfiguredServer.class; - } + @Override + public Class getEndpointClass() { + return WSConfiguredServer.class; + } - @Override - public String getPath() { - return "/unusedconfig"; - } + @Override + public String getPath() { + return "/unusedconfig"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + @Override + public List> getDecoders() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/UsedServerEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/UsedServerEndpointConfig.java index aec6c5588c..c25dec216f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/UsedServerEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/UsedServerEndpointConfig.java @@ -31,48 +31,48 @@ public class UsedServerEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSConfiguredServer.class; - } + @Override + public Class getEndpointClass() { + return WSConfiguredServer.class; + } - @Override - public String getPath() { - return "/configured"; - } + @Override + public String getPath() { + return "/configured"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - Class clazz = StringBeanTextDecoder.class; - List> list = new LinkedList<>(); - list.add(clazz); - return list; - } + @Override + public List> getDecoders() { + Class clazz = StringBeanTextDecoder.class; + List> list = new LinkedList<>(); + list.add(clazz); + return list; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSClient.java deleted file mode 100644 index c48e475f8e..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSClient.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverapplicationconfig; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = -6963654147324631018L; - - private final static String CONTENT = WSClient.class.getName(); - - public WSClient() { - setContextRoot("ws_ee_jakarta_websocket_server_appconfig_web"); - - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - /* - * @testName: usedServerTest - * - * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; - * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-5; - * - * @test_Strategy: Test the Endpoint which should be used by - * ServerApplicationConfig is really used Return a set of annotated endpoint - * classes that the server container must deploy. The set of classes passed in - * to this method is the set obtained by scanning the archive containing the - * implementation of this interface. - */ - public void usedServerTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("used")); - setProperty(Property.SEARCH_STRING, CONTENT); - setProperty(Property.CONTENT, CONTENT); - invoke(); - } - - /* - * @testName: unusedServerTest - * - * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; - * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-5; - * - * @test_Strategy: Test the Endpoint which should be NOT used by - * ServerApplicationConfig is really NOT used - * - * Therefore, this set passed in contains all the annotated endpoint classes - * in the JAR or WAR file containing the implementation of this interface. - */ - public void unusedServerTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("unused")); - setProperty(Property.CONTENT, CONTENT); - invokeFail(); - String message = getResponseAsString(); - assertTrue(isNullOrEmpty(message), - "The unused server endpoint should not be registered"); - } - - /* - * @testName: otherUsedServerTest - * - * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; - * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; - * WebSocket:SPEC:WSC-6.2-5; - * - * @test_Strategy: Test all - * ServerApplicationConfig#getAnnotatedEndpointClasses methods are really used - */ - public void otherUsedServerTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("other")); - setProperty(Property.SEARCH_STRING, CONTENT); - setProperty(Property.CONTENT, CONTENT); - invoke(); - } - - /* - * @testName: configuredServerTest - * - * @assertion_ids: WebSocket:JAVADOC:183; WebSocket:SPEC:WSC-6.2-1; - * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; - * WebSocket:SPEC:WSC-6.2-5; - * - * @test_Strategy: Test the correct ServerEndpointConfig is used - * - * Return a set of ServerEndpointConfig instances that the server container - * will use to deploy the programmatic endpoints. The set of Endpoint classes - * passed in to this method is the set obtained by scanning the archive - * containing the implementation of this ServerApplication Config. This set - * passed in may be used the build the set of ServerEndpointConfig instances - * to return to the container for deployment. - */ - public void configuredServerTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("configured")); - setProperty(Property.SEARCH_STRING, CONTENT); - setProperty(Property.CONTENT, CONTENT); - invoke(); - } - - /* - * @testName: unusedConfiguredServerTest - * - * @assertion_ids: WebSocket:JAVADOC:183; WebSocket:SPEC:WSC-6.2-1; - * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; - * WebSocket:SPEC:WSC-6.2-5; - * - * @test_Strategy: Test the incorrect ServerEndpointConfig is NOT used - */ - public void unusedConfiguredServerTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("unusedconfig")); - setProperty(Property.CONTENT, CONTENT); - invokeFail(); - String message = getResponseAsString(); - assertTrue(isNullOrEmpty(message), - "The unused server endpoint config should not register an endpoint"); - } - - /////////////////////////////////////////////////////////////////////// - // Chances are that an exception is thrown when 404 - private void invokeFail() { - try { - invoke(false); - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSClientIT.java new file mode 100644 index 0000000000..8c9846da92 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSClientIT.java @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverapplicationconfig; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.server.handshakerequest.WSCClientIT; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = -6963654147324631018L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_ee_jakarta_websocket_server_appconfig_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverapplicationconfig"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + private final static String CONTENT = WSClientIT.class.getName(); + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("ws_ee_jakarta_websocket_server_appconfig_web"); + + } + + /* Run test */ + + /* + * @testName: usedServerTest + * + * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; + * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-5; + * + * @test_Strategy: Test the Endpoint which should be used by + * ServerApplicationConfig is really used Return a set of annotated endpoint + * classes that the server container must deploy. The set of classes passed in + * to this method is the set obtained by scanning the archive containing the + * implementation of this interface. + */ + @Test + public void usedServerTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("used")); + setProperty(Property.SEARCH_STRING, CONTENT); + setProperty(Property.CONTENT, CONTENT); + invoke(); + } + + /* + * @testName: unusedServerTest + * + * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; + * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-5; + * + * @test_Strategy: Test the Endpoint which should be NOT used by + * ServerApplicationConfig is really NOT used + * + * Therefore, this set passed in contains all the annotated endpoint classes in + * the JAR or WAR file containing the implementation of this interface. + */ + @Test + public void unusedServerTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("unused")); + setProperty(Property.CONTENT, CONTENT); + invokeFail(); + String message = getResponseAsString(); + assertTrue(isNullOrEmpty(message), "The unused server endpoint should not be registered"); + } + + /* + * @testName: otherUsedServerTest + * + * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; + * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; WebSocket:SPEC:WSC-6.2-5; + * + * @test_Strategy: Test all ServerApplicationConfig#getAnnotatedEndpointClasses + * methods are really used + */ + @Test + public void otherUsedServerTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("other")); + setProperty(Property.SEARCH_STRING, CONTENT); + setProperty(Property.CONTENT, CONTENT); + invoke(); + } + + /* + * @testName: configuredServerTest + * + * @assertion_ids: WebSocket:JAVADOC:183; WebSocket:SPEC:WSC-6.2-1; + * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; WebSocket:SPEC:WSC-6.2-5; + * + * @test_Strategy: Test the correct ServerEndpointConfig is used + * + * Return a set of ServerEndpointConfig instances that the server container will + * use to deploy the programmatic endpoints. The set of Endpoint classes passed + * in to this method is the set obtained by scanning the archive containing the + * implementation of this ServerApplication Config. This set passed in may be + * used the build the set of ServerEndpointConfig instances to return to the + * container for deployment. + */ + @Test + public void configuredServerTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("configured")); + setProperty(Property.SEARCH_STRING, CONTENT); + setProperty(Property.CONTENT, CONTENT); + invoke(); + } + + /* + * @testName: unusedConfiguredServerTest + * + * @assertion_ids: WebSocket:JAVADOC:183; WebSocket:SPEC:WSC-6.2-1; + * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; WebSocket:SPEC:WSC-6.2-5; + * + * @test_Strategy: Test the incorrect ServerEndpointConfig is NOT used + */ + @Test + public void unusedConfiguredServerTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("unusedconfig")); + setProperty(Property.CONTENT, CONTENT); + invokeFail(); + String message = getResponseAsString(); + assertTrue(isNullOrEmpty(message), "The unused server endpoint config should not register an endpoint"); + } + + /////////////////////////////////////////////////////////////////////// + // Chances are that an exception is thrown when 404 + private void invokeFail() { + try { + invoke(false); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSConfiguredServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSConfiguredServer.java index 9beaf8e493..cdcecdc610 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSConfiguredServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSConfiguredServer.java @@ -27,29 +27,28 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class WSConfiguredServer extends Endpoint - implements MessageHandler.Whole { - - Session session; - - @Override - public void onMessage(StringBean bean) { - try { - session.getBasicRemote().sendText(bean.get()); - } catch (IOException e) { - e.printStackTrace(); - try { - session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } - - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - session.addMessageHandler(this); - } +public class WSConfiguredServer extends Endpoint implements MessageHandler.Whole { + + Session session; + + @Override + public void onMessage(StringBean bean) { + try { + session.getBasicRemote().sendText(bean.get()); + } catch (IOException e) { + e.printStackTrace(); + try { + session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } + + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + session.addMessageHandler(this); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSOtherUsedServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSOtherUsedServer.java index f780e35381..a5808b49d2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSOtherUsedServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSOtherUsedServer.java @@ -29,15 +29,15 @@ @ServerEndpoint("/other") public class WSOtherUsedServer { - @OnMessage - public String echo(String echo) { - return echo; - } + @OnMessage + public String echo(String echo) { + return echo; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSUnusedServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSUnusedServer.java index c827d35565..8e5f589d74 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSUnusedServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSUnusedServer.java @@ -29,15 +29,15 @@ @ServerEndpoint("/unused") public class WSUnusedServer { - @OnMessage - public String echo(String echo) { - return echo; - } + @OnMessage + public String echo(String echo) { + return echo; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSUsedServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSUsedServer.java index ff95491c91..8478d5c2a7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSUsedServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfig/WSUsedServer.java @@ -29,15 +29,15 @@ @ServerEndpoint("/used") public class WSUsedServer { - @OnMessage - public String echo(String echo) { - return echo; - } + @OnMessage + public String echo(String echo) { + return echo; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/AppConfig.java index bbdf182cb0..e54f830fd3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/AppConfig.java @@ -29,18 +29,17 @@ public class AppConfig implements ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - set.add(new UsedServerEndpointConfig()); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + set.add(new UsedServerEndpointConfig()); + return set; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(WSUsedServer.class); - return set; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(WSUsedServer.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/OtherAppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/OtherAppConfig.java index 91de96210b..e27e37a7ef 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/OtherAppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/OtherAppConfig.java @@ -28,17 +28,16 @@ public class OtherAppConfig implements ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - return null; - } - - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(WSOtherUsedServer.class); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + return null; + } + + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(WSOtherUsedServer.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/WSLibClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/WSLibClient.java deleted file mode 100644 index 6617e3eb60..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/WSLibClient.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverapplicationconfiginlib; - -import com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverapplicationconfig.WSClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSLibClient extends WSClient { - - private static final long serialVersionUID = 1544727768161691523L; - - public WSLibClient() { - setContextRoot("wsc_ee_server_appconfig_lib_web"); - - } - - public static void main(String[] args) { - new WSLibClient().run(args); - } - - /* Run test */ - - /* - * @testName: usedServerTest - * - * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; - * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-5; - * - * @test_Strategy: Test the Endpoint which should be used by - * ServerApplicationConfig is really used Return a set of annotated endpoint - * classes that the server container must deploy. The set of classes passed in - * to this method is the set obtained by scanning the archive containing the - * implementation of this interface. - */ - @Override - public void usedServerTest() throws Exception { - super.usedServerTest(); - } - - /* - * @testName: unusedServerTest - * - * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; - * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-5; - * - * @test_Strategy: Test the Endpoint which should be NOT used by - * ServerApplicationConfig is really NOT used - * - * Therefore, this set passed in contains all the annotated endpoint classes - * in the JAR or WAR file containing the implementation of this interface. - */ - @Override - public void unusedServerTest() throws Exception { - super.unusedServerTest(); - } - - /* - * @testName: otherUsedServerTest - * - * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; - * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; - * WebSocket:SPEC:WSC-6.2-5; - * - * @test_Strategy: Test all - * ServerApplicationConfig#getAnnotatedEndpointClasses methods are really used - */ - @Override - public void otherUsedServerTest() throws Exception { - super.otherUsedServerTest(); - } - - /* - * @testName: configuredServerTest - * - * @assertion_ids: WebSocket:JAVADOC:183; WebSocket:SPEC:WSC-6.2-1; - * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; - * WebSocket:SPEC:WSC-6.2-5; - * - * @test_Strategy: Test the correct ServerEndpointConfig is used - * - * Return a set of ServerEndpointConfig instances that the server container - * will use to deploy the programmatic endpoints. The set of Endpoint classes - * passed in to this method is the set obtained by scanning the archive - * containing the implementation of this ServerApplication Config. This set - * passed in may be used the build the set of ServerEndpointConfig instances - * to return to the container for deployment. - */ - @Override - public void configuredServerTest() throws Exception { - super.configuredServerTest(); - } - - /* - * @testName: unusedConfiguredServerTest - * - * @assertion_ids: WebSocket:JAVADOC:183; WebSocket:SPEC:WSC-6.2-1; - * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; - * WebSocket:SPEC:WSC-6.2-5; - * - * @test_Strategy: Test the incorrect ServerEndpointConfig is NOT used - */ - @Override - public void unusedConfiguredServerTest() throws Exception { - super.unusedConfiguredServerTest(); - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/WSLibClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/WSLibClientIT.java new file mode 100644 index 0000000000..1ec8b6d252 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverapplicationconfiginlib/WSLibClientIT.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverapplicationconfiginlib; + +import org.junit.jupiter.api.Test; + +import com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverapplicationconfig.WSClientIT; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +public class WSLibClientIT extends WSClientIT { + + private static final long serialVersionUID = 1544727768161691523L; + + public WSLibClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_server_appconfig_lib_web"); + + } + + /* Run test */ + + /* + * @testName: usedServerTest + * + * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; + * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-5; + * + * @test_Strategy: Test the Endpoint which should be used by + * ServerApplicationConfig is really used Return a set of annotated endpoint + * classes that the server container must deploy. The set of classes passed in + * to this method is the set obtained by scanning the archive containing the + * implementation of this interface. + */ + @Override + @Test + public void usedServerTest() throws Exception { + super.usedServerTest(); + } + + /* + * @testName: unusedServerTest + * + * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; + * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-5; + * + * @test_Strategy: Test the Endpoint which should be NOT used by + * ServerApplicationConfig is really NOT used + * + * Therefore, this set passed in contains all the annotated endpoint classes in + * the JAR or WAR file containing the implementation of this interface. + */ + @Override + @Test + public void unusedServerTest() throws Exception { + super.unusedServerTest(); + } + + /* + * @testName: otherUsedServerTest + * + * @assertion_ids: WebSocket:JAVADOC:182; WebSocket:SPEC:WSC-6.2-1; + * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; WebSocket:SPEC:WSC-6.2-5; + * + * @test_Strategy: Test all ServerApplicationConfig#getAnnotatedEndpointClasses + * methods are really used + */ + @Override + @Test + public void otherUsedServerTest() throws Exception { + super.otherUsedServerTest(); + } + + /* + * @testName: configuredServerTest + * + * @assertion_ids: WebSocket:JAVADOC:183; WebSocket:SPEC:WSC-6.2-1; + * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; WebSocket:SPEC:WSC-6.2-5; + * + * @test_Strategy: Test the correct ServerEndpointConfig is used + * + * Return a set of ServerEndpointConfig instances that the server container will + * use to deploy the programmatic endpoints. The set of Endpoint classes passed + * in to this method is the set obtained by scanning the archive containing the + * implementation of this ServerApplication Config. This set passed in may be + * used the build the set of ServerEndpointConfig instances to return to the + * container for deployment. + */ + @Override + @Test + public void configuredServerTest() throws Exception { + super.configuredServerTest(); + } + + /* + * @testName: unusedConfiguredServerTest + * + * @assertion_ids: WebSocket:JAVADOC:183; WebSocket:SPEC:WSC-6.2-1; + * WebSocket:SPEC:WSC-6.2-2; WebSocket:SPEC:WSC-6.2-4; WebSocket:SPEC:WSC-6.2-5; + * + * @test_Strategy: Test the incorrect ServerEndpointConfig is NOT used + */ + @Override + @Test + public void unusedConfiguredServerTest() throws Exception { + super.unusedConfiguredServerTest(); + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/CountingConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/CountingConfigurator.java index 3ab3cf09ab..5ec0d33b7a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/CountingConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/CountingConfigurator.java @@ -22,13 +22,13 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class CountingConfigurator extends Configurator { - public final static AtomicInteger COUNTER = new AtomicInteger(0); + public final static AtomicInteger COUNTER = new AtomicInteger(0); - public CountingConfigurator() { - COUNTER.incrementAndGet(); - } + public CountingConfigurator() { + COUNTER.incrementAndGet(); + } - public int getCounterValue() { - return COUNTER.intValue(); - } + public int getCounterValue() { + return COUNTER.intValue(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSAbstractServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSAbstractServer.java index 56fe60bcf3..5a9edcb708 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSAbstractServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSAbstractServer.java @@ -32,62 +32,62 @@ public class WSAbstractServer { - public String op(String op) { - if (op.equals("configurator")) - return getConfigurator(); - if (op.equals("encoders")) - return getEncoders(); - if (op.equals("decoders")) - return getDecoders(); - if (op.equals("subprotocols")) - return getSubprotocols(); - if (op.equals("value")) - return getValue(); - return null; - } + public String op(String op) { + if (op.equals("configurator")) + return getConfigurator(); + if (op.equals("encoders")) + return getEncoders(); + if (op.equals("decoders")) + return getDecoders(); + if (op.equals("subprotocols")) + return getSubprotocols(); + if (op.equals("value")) + return getValue(); + return null; + } - protected String getConfigurator() { - Annotation ann = getClass().getAnnotations()[0]; - ServerEndpoint endpoint = (ServerEndpoint) ann; - Class config = endpoint.configurator(); - return config.getName(); - } + protected String getConfigurator() { + Annotation ann = getClass().getAnnotations()[0]; + ServerEndpoint endpoint = (ServerEndpoint) ann; + Class config = endpoint.configurator(); + return config.getName(); + } - protected String getEncoders() { - Annotation ann = getClass().getAnnotations()[0]; - ServerEndpoint endpoint = (ServerEndpoint) ann; - Class[] encoders = endpoint.encoders(); - String encs = objectsToString((Object[]) encoders); - return encs; - } + protected String getEncoders() { + Annotation ann = getClass().getAnnotations()[0]; + ServerEndpoint endpoint = (ServerEndpoint) ann; + Class[] encoders = endpoint.encoders(); + String encs = objectsToString((Object[]) encoders); + return encs; + } - protected String getDecoders() { - Annotation ann = getClass().getAnnotations()[0]; - ServerEndpoint endpoint = (ServerEndpoint) ann; - Class[] decoders = endpoint.decoders(); - String decs = objectsToString((Object[]) decoders); - return decs; - } + protected String getDecoders() { + Annotation ann = getClass().getAnnotations()[0]; + ServerEndpoint endpoint = (ServerEndpoint) ann; + Class[] decoders = endpoint.decoders(); + String decs = objectsToString((Object[]) decoders); + return decs; + } - protected String getSubprotocols() { - Annotation ann = getClass().getAnnotations()[0]; - ServerEndpoint endpoint = (ServerEndpoint) ann; - String[] subprotocols = endpoint.subprotocols(); - String subs = objectsToString((Object[]) subprotocols); - return subs; - } + protected String getSubprotocols() { + Annotation ann = getClass().getAnnotations()[0]; + ServerEndpoint endpoint = (ServerEndpoint) ann; + String[] subprotocols = endpoint.subprotocols(); + String subs = objectsToString((Object[]) subprotocols); + return subs; + } - public String getValue() { - Annotation ann = getClass().getAnnotations()[0]; - ServerEndpoint endpoint = (ServerEndpoint) ann; - return endpoint.value(); - } + public String getValue() { + Annotation ann = getClass().getAnnotations()[0]; + ServerEndpoint endpoint = (ServerEndpoint) ann; + return endpoint.value(); + } - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSClient.java deleted file mode 100644 index 8c41b50405..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSClient.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpoint; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryDecoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryEncoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamDecoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamEncoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextEncoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamDecoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamEncoder; - -import jakarta.websocket.server.ServerEndpointConfig.Configurator; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 3021625862493775185L; - - public WSClient() { - setContextRoot("wsc_ee_server_serverendpoint_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - /* - * @testName: getDefaultConfiguratorTest - * - * @assertion_ids: WebSocket:JAVADOC:188; - * - * @test_Strategy: Default: ServerEndpointConfig.Configurator.class - */ - public void getDefaultConfiguratorTest() throws Exception { - String[] sequence = { "default", "encoded", "decoded", "subprotocoled" }; - invokeDefaults(sequence, "configurator", Configurator.class.getName()); - } - - /* - * @testName: getDefaultEncodersTest - * - * @assertion_ids: WebSocket:JAVADOC:190; - * - * @test_Strategy: Default: {} - */ - public void getDefaultEncodersTest() throws Exception { - String[] sequence = { "default", "configured", "decoded", "subprotocoled" }; - invokeDefaults(sequence, "encoders", "{}"); - } - - /* - * @testName: getDefaultDecodersTest - * - * @assertion_ids: WebSocket:JAVADOC:189; - * - * @test_Strategy: Default: {} - */ - public void getDefaultDecodersTest() throws Exception { - String[] sequence = { "default", "encoded", "configured", "subprotocoled" }; - invokeDefaults(sequence, "decoders", "{}"); - } - - /* - * @testName: getDefaultSubprotocolsTest - * - * @assertion_ids: WebSocket:JAVADOC:191; - * - * @test_Strategy: Default: {} - */ - public void getDefaultSubprotocolsTest() throws Exception { - String[] sequence = { "default", "encoded", "configured", "decoded" }; - invokeDefaults(sequence, "subprotocols", "{}"); - } - - /* - * @testName: getDefaultValueTest - * - * @assertion_ids: WebSocket:JAVADOC:192; - * - * @test_Strategy: Default: {} - */ - public void getDefaultValueTest() throws Exception { - String[] sequence = { "default", "encoded", "configured", "decoded", - "subprotocoled" }; - invokeValues(sequence, "value"); - } - - /* - * @testName: getEncodersTest - * - * @assertion_ids: WebSocket:JAVADOC:190; - * - * @test_Strategy: The ordered array of encoder classes this endpoint will - * use. - */ - public void getEncodersTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("encoded")); - setProperty(Property.CONTENT, "encoders"); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanBinaryEncoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanBinaryStreamEncoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanTextEncoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanTextStreamEncoder.class.getName()); - invoke(); - } - - /* - * @testName: getDecodersTest - * - * @assertion_ids: WebSocket:JAVADOC:189; - * - * @test_Strategy: The ordered array of decoder classes this endpoint will - * use. - */ - public void getDecodersTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("decoded")); - setProperty(Property.CONTENT, "decoders"); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanBinaryDecoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanBinaryStreamDecoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanTextDecoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanTextStreamDecoder.class.getName()); - invoke(); - } - - /* - * @testName: getSubprotocolsTest - * - * @assertion_ids: WebSocket:JAVADOC:191; - * - * @test_Strategy: The ordered array of web socket protocols this endpoint - * supports. - */ - public void getSubprotocolsTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("subprotocoled")); - setProperty(Property.CONTENT, "subprotocols"); - setProperty(Property.UNORDERED_SEARCH_STRING, "abc"); - setProperty(Property.UNORDERED_SEARCH_STRING, "def"); - setProperty(Property.UNORDERED_SEARCH_STRING, "ghi"); - invoke(); - } - - /* - * @testName: getConfiguratorTest - * - * @assertion_ids: WebSocket:JAVADOC:188; - * - * @test_Strategy: The optional custom configurator class that the developer - * would like to use to further configure new instances of this endpoint. - */ - public void getConfiguratorTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("configured")); - setProperty(Property.CONTENT, "configurator"); - setProperty(Property.SEARCH_STRING, SimpleConfigurator.class.getName()); - invoke(); - } - - /* - * @testName: countConfigurationInstancesTest - * - * @assertion_ids: WebSocket:JAVADOC:188; - * - * @test_Strategy: The implementation creates a new instance of the - * configurator per logical endpoint. - */ - public void countConfigurationInstancesTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("countone")); - setProperty(Property.CONTENT, "any"); - invoke(); - setProperty(Property.REQUEST, buildRequest("counttwo")); - setProperty(Property.CONTENT, "any"); - setProperty(Property.SEARCH_STRING, "2"); - invoke(); - } - - // /////////////////////////////////////////////////////////////////////// - - private void invokeDefaults(String[] endpointSequence, String content, - String search) throws Exception { - for (String endpoint : endpointSequence) { - setProperty(Property.REQUEST, buildRequest(endpoint)); - setProperty(Property.CONTENT, content); - setProperty(Property.SEARCH_STRING, search); - invoke(); - } - } - - private void invokeValues(String[] endpointSequence, String content) - throws Exception { - for (String endpoint : endpointSequence) { - setProperty(Property.REQUEST, buildRequest(endpoint)); - setProperty(Property.CONTENT, content); - setProperty(Property.SEARCH_STRING, endpoint); - invoke(); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSClientIT.java new file mode 100644 index 0000000000..961e9b9778 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSClientIT.java @@ -0,0 +1,224 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpoint; + +import org.junit.jupiter.api.Test; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamEncoder; + +import jakarta.websocket.server.ServerEndpointConfig.Configurator; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ts_home; + * ws_wait; + */ +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 3021625862493775185L; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_server_serverendpoint_web"); + } + + /* Run test */ + + /* + * @testName: getDefaultConfiguratorTest + * + * @assertion_ids: WebSocket:JAVADOC:188; + * + * @test_Strategy: Default: ServerEndpointConfig.Configurator.class + */ + @Test + public void getDefaultConfiguratorTest() throws Exception { + String[] sequence = { "default", "encoded", "decoded", "subprotocoled" }; + invokeDefaults(sequence, "configurator", Configurator.class.getName()); + } + + /* + * @testName: getDefaultEncodersTest + * + * @assertion_ids: WebSocket:JAVADOC:190; + * + * @test_Strategy: Default: {} + */ + @Test + public void getDefaultEncodersTest() throws Exception { + String[] sequence = { "default", "configured", "decoded", "subprotocoled" }; + invokeDefaults(sequence, "encoders", "{}"); + } + + /* + * @testName: getDefaultDecodersTest + * + * @assertion_ids: WebSocket:JAVADOC:189; + * + * @test_Strategy: Default: {} + */ + @Test + public void getDefaultDecodersTest() throws Exception { + String[] sequence = { "default", "encoded", "configured", "subprotocoled" }; + invokeDefaults(sequence, "decoders", "{}"); + } + + /* + * @testName: getDefaultSubprotocolsTest + * + * @assertion_ids: WebSocket:JAVADOC:191; + * + * @test_Strategy: Default: {} + */ + @Test + public void getDefaultSubprotocolsTest() throws Exception { + String[] sequence = { "default", "encoded", "configured", "decoded" }; + invokeDefaults(sequence, "subprotocols", "{}"); + } + + /* + * @testName: getDefaultValueTest + * + * @assertion_ids: WebSocket:JAVADOC:192; + * + * @test_Strategy: Default: {} + */ + @Test + public void getDefaultValueTest() throws Exception { + String[] sequence = { "default", "encoded", "configured", "decoded", "subprotocoled" }; + invokeValues(sequence, "value"); + } + + /* + * @testName: getEncodersTest + * + * @assertion_ids: WebSocket:JAVADOC:190; + * + * @test_Strategy: The ordered array of encoder classes this endpoint will use. + */ + @Test + public void getEncodersTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("encoded")); + setProperty(Property.CONTENT, "encoders"); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanBinaryEncoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanBinaryStreamEncoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanTextEncoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanTextStreamEncoder.class.getName()); + invoke(); + } + + /* + * @testName: getDecodersTest + * + * @assertion_ids: WebSocket:JAVADOC:189; + * + * @test_Strategy: The ordered array of decoder classes this endpoint will use. + */ + @Test + public void getDecodersTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("decoded")); + setProperty(Property.CONTENT, "decoders"); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanBinaryDecoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanBinaryStreamDecoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanTextDecoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanTextStreamDecoder.class.getName()); + invoke(); + } + + /* + * @testName: getSubprotocolsTest + * + * @assertion_ids: WebSocket:JAVADOC:191; + * + * @test_Strategy: The ordered array of web socket protocols this endpoint + * supports. + */ + @Test + public void getSubprotocolsTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("subprotocoled")); + setProperty(Property.CONTENT, "subprotocols"); + setProperty(Property.UNORDERED_SEARCH_STRING, "abc"); + setProperty(Property.UNORDERED_SEARCH_STRING, "def"); + setProperty(Property.UNORDERED_SEARCH_STRING, "ghi"); + invoke(); + } + + /* + * @testName: getConfiguratorTest + * + * @assertion_ids: WebSocket:JAVADOC:188; + * + * @test_Strategy: The optional custom configurator class that the developer + * would like to use to further configure new instances of this endpoint. + */ + @Test + public void getConfiguratorTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("configured")); + setProperty(Property.CONTENT, "configurator"); + setProperty(Property.SEARCH_STRING, SimpleConfigurator.class.getName()); + invoke(); + } + + /* + * @testName: countConfigurationInstancesTest + * + * @assertion_ids: WebSocket:JAVADOC:188; + * + * @test_Strategy: The implementation creates a new instance of the configurator + * per logical endpoint. + */ + @Test + public void countConfigurationInstancesTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("countone")); + setProperty(Property.CONTENT, "any"); + invoke(); + setProperty(Property.REQUEST, buildRequest("counttwo")); + setProperty(Property.CONTENT, "any"); + setProperty(Property.SEARCH_STRING, "2"); + invoke(); + } + + // /////////////////////////////////////////////////////////////////////// + + private void invokeDefaults(String[] endpointSequence, String content, String search) throws Exception { + for (String endpoint : endpointSequence) { + setProperty(Property.REQUEST, buildRequest(endpoint)); + setProperty(Property.CONTENT, content); + setProperty(Property.SEARCH_STRING, search); + invoke(); + } + } + + private void invokeValues(String[] endpointSequence, String content) throws Exception { + for (String endpoint : endpointSequence) { + setProperty(Property.REQUEST, buildRequest(endpoint)); + setProperty(Property.CONTENT, content); + setProperty(Property.SEARCH_STRING, endpoint); + invoke(); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSConfiguredServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSConfiguredServer.java index e4674284b7..7deb361d88 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSConfiguredServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSConfiguredServer.java @@ -27,39 +27,39 @@ @ServerEndpoint(value = "/configured", configurator = SimpleConfigurator.class) public class WSConfiguredServer extends WSAbstractServer { - @OnMessage - public String operation(String op) { - return super.op(op); - } + @OnMessage + public String operation(String op) { + return super.op(op); + } - @Override - protected String getConfigurator() { - String config = super.getConfigurator(); - return config; - } + @Override + protected String getConfigurator() { + String config = super.getConfigurator(); + return config; + } - @Override - protected String getEncoders() { - String encoders = super.getEncoders(); - return "{" + encoders + "}"; - } + @Override + protected String getEncoders() { + String encoders = super.getEncoders(); + return "{" + encoders + "}"; + } - @Override - protected String getDecoders() { - String decoders = super.getDecoders(); - return "{" + decoders + "}"; - } + @Override + protected String getDecoders() { + String decoders = super.getDecoders(); + return "{" + decoders + "}"; + } - @Override - protected String getSubprotocols() { - String subprotocols = super.getSubprotocols(); - return "{" + subprotocols + "}"; - } + @Override + protected String getSubprotocols() { + String subprotocols = super.getSubprotocols(); + return "{" + subprotocols + "}"; + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSCountConfiguratorInstancesFirstServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSCountConfiguratorInstancesFirstServer.java index 0b0007bd3a..f23ade6eed 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSCountConfiguratorInstancesFirstServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSCountConfiguratorInstancesFirstServer.java @@ -28,18 +28,17 @@ @ServerEndpoint(value = "/countone", configurator = CountingConfigurator.class) public class WSCountConfiguratorInstancesFirstServer { - @SuppressWarnings("unused") - @OnMessage - public String getCountingConfiguratorValue(String entity) { - Annotation ann = getClass().getAnnotations()[0]; - ServerEndpoint endpoint = (ServerEndpoint) ann; - Class config = endpoint.configurator(); - try { - CountingConfigurator cc = (CountingConfigurator) config - .getConstructor(boolean.class).newInstance(true); - return String.valueOf(cc.getCounterValue()); - } catch (Exception e) { - return IOUtil.printStackTrace(e); - } - } + @SuppressWarnings("unused") + @OnMessage + public String getCountingConfiguratorValue(String entity) { + Annotation ann = getClass().getAnnotations()[0]; + ServerEndpoint endpoint = (ServerEndpoint) ann; + Class config = endpoint.configurator(); + try { + CountingConfigurator cc = (CountingConfigurator) config.getConstructor(boolean.class).newInstance(true); + return String.valueOf(cc.getCounterValue()); + } catch (Exception e) { + return IOUtil.printStackTrace(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSCountConfiguratorInstancesSecondServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSCountConfiguratorInstancesSecondServer.java index 3c96dd9121..f47d261b26 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSCountConfiguratorInstancesSecondServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSCountConfiguratorInstancesSecondServer.java @@ -28,19 +28,18 @@ @ServerEndpoint(value = "/counttwo", configurator = CountingConfigurator.class) public class WSCountConfiguratorInstancesSecondServer { - @SuppressWarnings("unused") - @OnMessage - public String getCountingConfiguratorValue(String op) { - Annotation ann = getClass().getAnnotations()[0]; - ServerEndpoint endpoint = (ServerEndpoint) ann; - Class config = endpoint.configurator(); - try { - CountingConfigurator cc = (CountingConfigurator) config - .getConstructor(boolean.class).newInstance(true); - String ret = String.valueOf(cc.getCounterValue()); - return ret; - } catch (Exception e) { - return IOUtil.printStackTrace(e); - } - } + @SuppressWarnings("unused") + @OnMessage + public String getCountingConfiguratorValue(String op) { + Annotation ann = getClass().getAnnotations()[0]; + ServerEndpoint endpoint = (ServerEndpoint) ann; + Class config = endpoint.configurator(); + try { + CountingConfigurator cc = (CountingConfigurator) config.getConstructor(boolean.class).newInstance(true); + String ret = String.valueOf(cc.getCounterValue()); + return ret; + } catch (Exception e) { + return IOUtil.printStackTrace(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSDecodedServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSDecodedServer.java index 364e6cc74a..2cfe03ad0d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSDecodedServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSDecodedServer.java @@ -29,44 +29,43 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/decoded", decoders = { - StringBeanBinaryStreamDecoder.class, StringBeanTextDecoder.class, - StringBeanBinaryDecoder.class, StringBeanTextStreamDecoder.class }) +@ServerEndpoint(value = "/decoded", decoders = { StringBeanBinaryStreamDecoder.class, StringBeanTextDecoder.class, + StringBeanBinaryDecoder.class, StringBeanTextStreamDecoder.class }) public class WSDecodedServer extends WSAbstractServer { - @OnMessage - public String operation(String op) { - return super.op(op); - } + @OnMessage + public String operation(String op) { + return super.op(op); + } - @Override - protected String getConfigurator() { - String config = super.getConfigurator(); - return config; - } + @Override + protected String getConfigurator() { + String config = super.getConfigurator(); + return config; + } - @Override - protected String getEncoders() { - String encoders = super.getEncoders(); - return "{" + encoders + "}"; - } + @Override + protected String getEncoders() { + String encoders = super.getEncoders(); + return "{" + encoders + "}"; + } - @Override - protected String getDecoders() { - String decoders = super.getDecoders(); - return "{" + decoders + "}"; - } + @Override + protected String getDecoders() { + String decoders = super.getDecoders(); + return "{" + decoders + "}"; + } - @Override - protected String getSubprotocols() { - String subprotocols = super.getSubprotocols(); - return "{" + subprotocols + "}"; - } + @Override + protected String getSubprotocols() { + String subprotocols = super.getSubprotocols(); + return "{" + subprotocols + "}"; + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSDefaultServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSDefaultServer.java index d0a12f430a..cddd73f728 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSDefaultServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSDefaultServer.java @@ -27,39 +27,39 @@ @ServerEndpoint("/default") public class WSDefaultServer extends WSAbstractServer { - @OnMessage - public String operation(String op) { - return super.op(op); - } + @OnMessage + public String operation(String op) { + return super.op(op); + } - @Override - protected String getConfigurator() { - String config = super.getConfigurator(); - return config; - } + @Override + protected String getConfigurator() { + String config = super.getConfigurator(); + return config; + } - @Override - protected String getEncoders() { - String encoders = super.getEncoders(); - return "{" + encoders + "}"; - } + @Override + protected String getEncoders() { + String encoders = super.getEncoders(); + return "{" + encoders + "}"; + } - @Override - protected String getDecoders() { - String decoders = super.getDecoders(); - return "{" + decoders + "}"; - } + @Override + protected String getDecoders() { + String decoders = super.getDecoders(); + return "{" + decoders + "}"; + } - @Override - protected String getSubprotocols() { - String subprotocols = super.getSubprotocols(); - return "{" + subprotocols + "}"; - } + @Override + protected String getSubprotocols() { + String subprotocols = super.getSubprotocols(); + return "{" + subprotocols + "}"; + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSEncodedServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSEncodedServer.java index 33dd78977a..c50c08b16b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSEncodedServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSEncodedServer.java @@ -29,44 +29,43 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/encoded", encoders = { - StringBeanTextStreamEncoder.class, StringBeanBinaryEncoder.class, - StringBeanTextEncoder.class, StringBeanBinaryStreamEncoder.class }) +@ServerEndpoint(value = "/encoded", encoders = { StringBeanTextStreamEncoder.class, StringBeanBinaryEncoder.class, + StringBeanTextEncoder.class, StringBeanBinaryStreamEncoder.class }) public class WSEncodedServer extends WSAbstractServer { - @OnMessage - public String operation(String op) { - return super.op(op); - } + @OnMessage + public String operation(String op) { + return super.op(op); + } - @Override - protected String getConfigurator() { - String config = super.getConfigurator(); - return config; - } + @Override + protected String getConfigurator() { + String config = super.getConfigurator(); + return config; + } - @Override - protected String getEncoders() { - String encoders = super.getEncoders(); - return "{" + encoders + "}"; - } + @Override + protected String getEncoders() { + String encoders = super.getEncoders(); + return "{" + encoders + "}"; + } - @Override - protected String getDecoders() { - String decoders = super.getDecoders(); - return "{" + decoders + "}"; - } + @Override + protected String getDecoders() { + String decoders = super.getDecoders(); + return "{" + decoders + "}"; + } - @Override - protected String getSubprotocols() { - String subprotocols = super.getSubprotocols(); - return "{" + subprotocols + "}"; - } + @Override + protected String getSubprotocols() { + String subprotocols = super.getSubprotocols(); + return "{" + subprotocols + "}"; + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSSubprotocoledServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSSubprotocoledServer.java index 85a7ec96c7..7b238cd3ff 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSSubprotocoledServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpoint/WSSubprotocoledServer.java @@ -24,43 +24,42 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/subprotocoled", subprotocols = { "def", "abc", - "ghi" }) +@ServerEndpoint(value = "/subprotocoled", subprotocols = { "def", "abc", "ghi" }) public class WSSubprotocoledServer extends WSAbstractServer { - @OnMessage - public String operation(String op) { - return super.op(op); - } + @OnMessage + public String operation(String op) { + return super.op(op); + } - @Override - protected String getConfigurator() { - String config = super.getConfigurator(); - return config; - } + @Override + protected String getConfigurator() { + String config = super.getConfigurator(); + return config; + } - @Override - protected String getEncoders() { - String encoders = super.getEncoders(); - return "{" + encoders + "}"; - } + @Override + protected String getEncoders() { + String encoders = super.getEncoders(); + return "{" + encoders + "}"; + } - @Override - protected String getDecoders() { - String decoders = super.getDecoders(); - return "{" + decoders + "}"; - } + @Override + protected String getDecoders() { + String decoders = super.getDecoders(); + return "{" + decoders + "}"; + } - @Override - protected String getSubprotocols() { - String subprotocols = super.getSubprotocols(); - return "{" + subprotocols + "}"; - } + @Override + protected String getSubprotocols() { + String subprotocols = super.getSubprotocols(); + return "{" + subprotocols + "}"; + } - @Override - @OnError - public void onError(Session session, Throwable t) throws IOException { - super.onError(session, t); - } + @Override + @OnError + public void onError(Session session, Throwable t) throws IOException { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/AppConfig.java index f9e915fdfa..dcaa2284d7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/AppConfig.java @@ -26,22 +26,21 @@ public class AppConfig implements ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - set.add(new SubprotocolsServerEndpointConfig()); - set.add(new ConfiguratorServerEndpointConfig()); - set.add(new ExtensionsServerEndpointConfig()); - set.add(new UserPropertiesServerEndpointConfig()); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + set.add(new SubprotocolsServerEndpointConfig()); + set.add(new ConfiguratorServerEndpointConfig()); + set.add(new ExtensionsServerEndpointConfig()); + set.add(new UserPropertiesServerEndpointConfig()); + return set; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(WSAnnotatedSubprotocolsServer.class); - set.add(WSAnnotatedConfiguratorServer.class); - return set; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(WSAnnotatedSubprotocolsServer.class); + set.add(WSAnnotatedConfiguratorServer.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/ConfiguratorServerEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/ConfiguratorServerEndpointConfig.java index e4552b40a9..9cc39eb72f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/ConfiguratorServerEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/ConfiguratorServerEndpointConfig.java @@ -28,44 +28,44 @@ public class ConfiguratorServerEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSProgramaticConfiguratorServer.class; - } + @Override + public Class getEndpointClass() { + return WSProgramaticConfiguratorServer.class; + } - @Override - public String getPath() { - return "/programatic/configurator"; - } + @Override + public String getPath() { + return "/programatic/configurator"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfigConfigurator(); - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfigConfigurator(); + } - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + @Override + public List> getDecoders() { + return Collections.emptyList(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/ExtensionsServerEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/ExtensionsServerEndpointConfig.java index 9340bd6b86..9cebd37e24 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/ExtensionsServerEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/ExtensionsServerEndpointConfig.java @@ -29,70 +29,70 @@ public class ExtensionsServerEndpointConfig implements ServerEndpointConfig { - static final String[] EXT_NAMES = new String[] { "empty", "secondEmpty" }; - - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } - - @Override - public Class getEndpointClass() { - return WSProgramaticExtensionsServer.class; - } - - @Override - public String getPath() { - return "/programatic/extensions"; - } - - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } - - @Override - public List getExtensions() { - Extension firstExt = new Extension() { - @Override - public String getName() { - return EXT_NAMES[0]; - } - - @Override - public List getParameters() { - return Collections.emptyList(); - } - }; - - Extension secondExt = new Extension() { - @Override - public String getName() { - return EXT_NAMES[1]; - } - - @Override - public List getParameters() { - return Collections.emptyList(); - } - }; - return Arrays.asList(firstExt, secondExt); - } - - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } - - @Override - public List> getEncoders() { - return Collections.emptyList(); - } - - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + static final String[] EXT_NAMES = new String[] { "empty", "secondEmpty" }; + + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } + + @Override + public Class getEndpointClass() { + return WSProgramaticExtensionsServer.class; + } + + @Override + public String getPath() { + return "/programatic/extensions"; + } + + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } + + @Override + public List getExtensions() { + Extension firstExt = new Extension() { + @Override + public String getName() { + return EXT_NAMES[0]; + } + + @Override + public List getParameters() { + return Collections.emptyList(); + } + }; + + Extension secondExt = new Extension() { + @Override + public String getName() { + return EXT_NAMES[1]; + } + + @Override + public List getParameters() { + return Collections.emptyList(); + } + }; + return Arrays.asList(firstExt, secondExt); + } + + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } + + @Override + public List> getEncoders() { + return Collections.emptyList(); + } + + @Override + public List> getDecoders() { + return Collections.emptyList(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/SubprotocolsServerEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/SubprotocolsServerEndpointConfig.java index 39d5134ab2..0242df9c36 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/SubprotocolsServerEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/SubprotocolsServerEndpointConfig.java @@ -29,45 +29,45 @@ public class SubprotocolsServerEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSProgramaticSubprotocolsServer.class; - } + @Override + public Class getEndpointClass() { + return WSProgramaticSubprotocolsServer.class; + } - @Override - public String getPath() { - return "/programatic/subprotocols"; - } + @Override + public String getPath() { + return "/programatic/subprotocols"; + } - @Override - public List getSubprotocols() { - return Arrays.asList("abc", "def"); - } + @Override + public List getSubprotocols() { + return Arrays.asList("abc", "def"); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator() { - }; - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator() { + }; + } - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + @Override + public List> getDecoders() { + return Collections.emptyList(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/UserPropertiesConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/UserPropertiesConfigurator.java index ef3c060c61..01c020e8ed 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/UserPropertiesConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/UserPropertiesConfigurator.java @@ -25,33 +25,32 @@ public class UserPropertiesConfigurator extends Configurator { - public static final String KEY_3 = "UPC-1"; - public static final String KEY_4 = "UPC-2"; - - @Override - public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { - Map userProperties = sec.getUserProperties(); - - // First check that the expected properties are present - if (userProperties.size() != 2) { - throw new IllegalStateException( - "User properties map has [" + userProperties.size() + "] entries when 2 are expected"); - } - - // Then check that both expected keys are present - checkKey(userProperties, UserPropertiesServerEndpointConfig.KEY_1); - checkKey(userProperties, UserPropertiesServerEndpointConfig.KEY_2); - - // Now remove key 2 and and two keys of our own - userProperties.remove(UserPropertiesServerEndpointConfig.KEY_2); - userProperties.put(KEY_3, new Object()); - userProperties.put(KEY_4, new Object()); - } - - - private void checkKey(Map map, String key) { - if (!map.containsKey(key)) { - throw new IllegalStateException("User properties map is missing entry with key [" + key + "]"); - } - } + public static final String KEY_3 = "UPC-1"; + public static final String KEY_4 = "UPC-2"; + + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + Map userProperties = sec.getUserProperties(); + + // First check that the expected properties are present + if (userProperties.size() != 2) { + throw new IllegalStateException( + "User properties map has [" + userProperties.size() + "] entries when 2 are expected"); + } + + // Then check that both expected keys are present + checkKey(userProperties, UserPropertiesServerEndpointConfig.KEY_1); + checkKey(userProperties, UserPropertiesServerEndpointConfig.KEY_2); + + // Now remove key 2 and and two keys of our own + userProperties.remove(UserPropertiesServerEndpointConfig.KEY_2); + userProperties.put(KEY_3, new Object()); + userProperties.put(KEY_4, new Object()); + } + + private void checkKey(Map map, String key) { + if (!map.containsKey(key)) { + throw new IllegalStateException("User properties map is missing entry with key [" + key + "]"); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/UserPropertiesServerEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/UserPropertiesServerEndpointConfig.java index 9ce433c612..d06f020230 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/UserPropertiesServerEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/UserPropertiesServerEndpointConfig.java @@ -28,56 +28,56 @@ public class UserPropertiesServerEndpointConfig implements ServerEndpointConfig { - public static final String KEY_1 = "SEC-1"; - public static final String KEY_2 = "SEC-2"; - - private static final Map SEC_USER_PROPERTIES = new HashMap<>(); - - static { - SEC_USER_PROPERTIES.put(KEY_1, new Object()); - SEC_USER_PROPERTIES.put(KEY_2, new Object()); - } - - @Override - public Map getUserProperties() { - // Need to always return the same object to test that the user properties - // exposed to modifyHandshake() are a shallow copy - return SEC_USER_PROPERTIES; - } - - @Override - public Class getEndpointClass() { - return WSProgramaticUserPropertiesServer.class; - } - - @Override - public String getPath() { - return "/programatic/userproperties"; - } - - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } - - @Override - public List getExtensions() { - return Collections.emptyList(); - } - - @Override - public Configurator getConfigurator() { - return new UserPropertiesConfigurator(); - } - - @Override - public List> getEncoders() { - return Collections.emptyList(); - } - - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + public static final String KEY_1 = "SEC-1"; + public static final String KEY_2 = "SEC-2"; + + private static final Map SEC_USER_PROPERTIES = new HashMap<>(); + + static { + SEC_USER_PROPERTIES.put(KEY_1, new Object()); + SEC_USER_PROPERTIES.put(KEY_2, new Object()); + } + + @Override + public Map getUserProperties() { + // Need to always return the same object to test that the user properties + // exposed to modifyHandshake() are a shallow copy + return SEC_USER_PROPERTIES; + } + + @Override + public Class getEndpointClass() { + return WSProgramaticUserPropertiesServer.class; + } + + @Override + public String getPath() { + return "/programatic/userproperties"; + } + + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } + + @Override + public List getExtensions() { + return Collections.emptyList(); + } + + @Override + public Configurator getConfigurator() { + return new UserPropertiesConfigurator(); + } + + @Override + public List> getEncoders() { + return Collections.emptyList(); + } + + @Override + public List> getDecoders() { + return Collections.emptyList(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSAnnotatedConfiguratorServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSAnnotatedConfiguratorServer.java index 34c2e5841f..bd17f6ea0a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSAnnotatedConfiguratorServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSAnnotatedConfiguratorServer.java @@ -34,52 +34,50 @@ @ServerEndpoint(value = "/annotated/configurator", configurator = ServerEndpointConfigConfigurator.class) public class WSAnnotatedConfiguratorServer { - Session session; + Session session; - ServerEndpointConfig config; + ServerEndpointConfig config; - @OnMessage - public void onMessage(String msg) { - try { - if (msg.equals("subprotocols")) - session.getBasicRemote().sendText( - StringUtil.objectsToString(config.getSubprotocols().toArray())); - else if (msg.equals("path")) - session.getBasicRemote().sendText(config.getPath()); - else if (msg.equals("endpoint")) - session.getBasicRemote().sendText(config.getEndpointClass().getName()); - else if (msg.equals("configurator")) - session.getBasicRemote() - .sendText(config.getConfigurator().getClass().getName()); - else if (msg.equals("extensions")) { - StringBuilder sb = new StringBuilder().append("["); - Extension[] ext = config.getExtensions().toArray(new Extension[0]); - for (Extension e : ext) - sb.append(e.getName()).append(" "); - sb.append("]"); - session.getBasicRemote().sendText(sb.toString()); - } - } catch (IOException e) { - e.printStackTrace(); - try { - session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } + @OnMessage + public void onMessage(String msg) { + try { + if (msg.equals("subprotocols")) + session.getBasicRemote().sendText(StringUtil.objectsToString(config.getSubprotocols().toArray())); + else if (msg.equals("path")) + session.getBasicRemote().sendText(config.getPath()); + else if (msg.equals("endpoint")) + session.getBasicRemote().sendText(config.getEndpointClass().getName()); + else if (msg.equals("configurator")) + session.getBasicRemote().sendText(config.getConfigurator().getClass().getName()); + else if (msg.equals("extensions")) { + StringBuilder sb = new StringBuilder().append("["); + Extension[] ext = config.getExtensions().toArray(new Extension[0]); + for (Extension e : ext) + sb.append(e.getName()).append(" "); + sb.append("]"); + session.getBasicRemote().sendText(sb.toString()); + } + } catch (IOException e) { + e.printStackTrace(); + try { + session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - this.config = (ServerEndpointConfig) config; - } + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + this.config = (ServerEndpointConfig) config; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSAnnotatedSubprotocolsServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSAnnotatedSubprotocolsServer.java index eaecb67cc2..567426f905 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSAnnotatedSubprotocolsServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSAnnotatedSubprotocolsServer.java @@ -31,57 +31,54 @@ import jakarta.websocket.server.ServerEndpoint; import jakarta.websocket.server.ServerEndpointConfig; -@ServerEndpoint(value = "/annotated/subprotocols", subprotocols = { "abc", - "def" }) +@ServerEndpoint(value = "/annotated/subprotocols", subprotocols = { "abc", "def" }) public class WSAnnotatedSubprotocolsServer { - Session session; + Session session; - ServerEndpointConfig config; + ServerEndpointConfig config; - @OnMessage - public void onMessage(String msg) { - try { - if (msg.equals("subprotocols")) - session.getBasicRemote() - .sendText(StringUtil.objectsToString(config.getSubprotocols())); - else if (msg.equals("path")) - session.getBasicRemote().sendText(config.getPath()); - else if (msg.equals("endpoint")) - session.getBasicRemote().sendText(config.getEndpointClass().getName()); - else if (msg.equals("configurator")) - session.getBasicRemote() - .sendText(config.getConfigurator().getClass().getName()); - else if (msg.equals("extensions")) { - StringBuilder sb = new StringBuilder().append("["); - Extension[] ext = config.getExtensions().toArray(new Extension[0]); - for (Extension e : ext) - sb.append(e.getName()).append(" "); - sb.append("]"); - session.getBasicRemote().sendText(sb.toString()); - } else - session.getBasicRemote().sendText(session.getNegotiatedSubprotocol()); - } catch (IOException e) { - e.printStackTrace(); - try { - session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } + @OnMessage + public void onMessage(String msg) { + try { + if (msg.equals("subprotocols")) + session.getBasicRemote().sendText(StringUtil.objectsToString(config.getSubprotocols())); + else if (msg.equals("path")) + session.getBasicRemote().sendText(config.getPath()); + else if (msg.equals("endpoint")) + session.getBasicRemote().sendText(config.getEndpointClass().getName()); + else if (msg.equals("configurator")) + session.getBasicRemote().sendText(config.getConfigurator().getClass().getName()); + else if (msg.equals("extensions")) { + StringBuilder sb = new StringBuilder().append("["); + Extension[] ext = config.getExtensions().toArray(new Extension[0]); + for (Extension e : ext) + sb.append(e.getName()).append(" "); + sb.append("]"); + session.getBasicRemote().sendText(sb.toString()); + } else + session.getBasicRemote().sendText(session.getNegotiatedSubprotocol()); + } catch (IOException e) { + e.printStackTrace(); + try { + session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - this.config = (ServerEndpointConfig) config; - } + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + this.config = (ServerEndpointConfig) config; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSClient.java deleted file mode 100644 index dce86d4c51..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSClient.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 6621336154397058231L; - - public WSClient() { - setContextRoot("wsc_ee_jakarta_websocket_server_serverendpointconfig_web"); - - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - /* - * @testName: getConfiguratorTest - * - * @assertion_ids: WebSocket:JAVADOC:193; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; - * - * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getConfigurator - * jakarta.websocket.Endpoint.onOpen; - * jakarta.websocket.MessageHandler.Whole.onMessage - */ - public void getConfiguratorTest() throws Exception { - String[] endpoints = new String[] { "programatic/subprotocols", - "annotated/configurator", "programatic/configurator" }; - String[] responses = new String[] { - SubprotocolsServerEndpointConfig.class.getName(), - ServerEndpointConfigConfigurator.class.getName(), - ServerEndpointConfigConfigurator.class.getName() }; - for (int i = 0; i != endpoints.length; i++) { - setProperty(Property.REQUEST, buildRequest(endpoints[i])); - setProperty(Property.CONTENT, "configurator"); - setProperty(Property.SEARCH_STRING, responses[i]); - invoke(); - } - } - - /* - * @testName: getEndpointClassTest - * - * @assertion_ids: WebSocket:JAVADOC:194; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; - * - * @test_Strategy: - * jakarta.websocket.server.ServerEndpointConfig.getEndpointClass - * jakarta.websocket.Endpoint.onOpen; - * jakarta.websocket.MessageHandler.Whole.onMessage - */ - public void getEndpointClassTest() throws Exception { - String[] endpoints = new String[] { "programatic/subprotocols", - "annotated/subprotocols", "annotated/configurator", - "programatic/configurator", "programatic/extensions" }; - String[] responses = new String[] { - WSProgramaticSubprotocolsServer.class.getName(), - WSAnnotatedSubprotocolsServer.class.getName(), - WSAnnotatedConfiguratorServer.class.getName(), - WSProgramaticConfiguratorServer.class.getName(), - WSProgramaticExtensionsServer.class.getName() }; - for (int i = 0; i != endpoints.length; i++) { - setProperty(Property.REQUEST, buildRequest(endpoints[i])); - setProperty(Property.CONTENT, "endpoint"); - setProperty(Property.SEARCH_STRING, responses[i]); - invoke(); - } - } - - /* - * @testName: getExtensionsTest - * - * @assertion_ids: WebSocket:JAVADOC:195; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; - * - * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getExtensions - * jakarta.websocket.Endpoint.onOpen; - * jakarta.websocket.MessageHandler.Whole.onMessage - */ - public void getExtensionsTest() throws Exception { - String[] endpoints = new String[] { "programatic/subprotocols", - "annotated/subprotocols", "annotated/configurator", - "programatic/configurator", "programatic/extensions" }; - String[] responses = new String[] { "[]", "[]", "[]", "[]", - ExtensionsServerEndpointConfig.EXT_NAMES[0] + "|" - + ExtensionsServerEndpointConfig.EXT_NAMES[1] }; - for (int i = 0; i != endpoints.length; i++) { - setProperty(Property.REQUEST, buildRequest(endpoints[i])); - setProperty(Property.CONTENT, "extensions"); - setProperty(Property.UNORDERED_SEARCH_STRING, responses[i]); - invoke(); - } - } - - /* - * @testName: getPathTest - * - * @assertion_ids: WebSocket:JAVADOC:196; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; - * - * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getPath - * jakarta.websocket.Endpoint.onOpen; - * jakarta.websocket.MessageHandler.Whole.onMessage - */ - public void getPathTest() throws Exception { - String[] sequence = new String[] { "programatic/subprotocols", - "annotated/subprotocols", "annotated/configurator", - "programatic/configurator", "programatic/extensions" }; - for (String endpoint : sequence) { - setProperty(Property.REQUEST, buildRequest(endpoint)); - setProperty(Property.CONTENT, "path"); - setProperty(Property.SEARCH_STRING, endpoint); - invoke(); - } - } - - /* - * @testName: getSubprotocolsTest - * - * @assertion_ids: WebSocket:JAVADOC:197; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; - * - * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getSubprotocols - * Return the websocket subprotocols configured. - * jakarta.websocket.Endpoint.onOpen; - * jakarta.websocket.MessageHandler.Whole.onMessage - */ - public void getSubprotocolsTest() throws Exception { - String[] endpoints = new String[] { "programatic/subprotocols", - "annotated/subprotocols" }; - for (String endpoint : endpoints) { - setProperty(Property.REQUEST, buildRequest(endpoint)); - setProperty(Property.CONTENT, "subprotocols"); - setProperty(Property.UNORDERED_SEARCH_STRING, "abc"); - setProperty(Property.UNORDERED_SEARCH_STRING, "def"); - invoke(); - } - } - - /* - * @testName: getEmptySubprotocolsTest - * - * @assertion_ids: WebSocket:JAVADOC:197; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; - * - * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getSubprotocols - * Return the websocket subprotocols configured. - * jakarta.websocket.Endpoint.onOpen; - * jakarta.websocket.MessageHandler.Whole.onMessage - */ - public void getEmptySubprotocolsTest() throws Exception { - String[] endpoints = new String[] { "annotated/configurator", - "programatic/configurator", "programatic/extensions" }; - for (String endpoint : endpoints) { - setProperty(Property.REQUEST, buildRequest(endpoint)); - setProperty(Property.CONTENT, "subprotocols"); - invoke(false); - String response = getResponseAsString(); - assertEqualsInt(0, - response.replace("[", "").replace("]", "").trim().length(), - "Unexpected subprotocol list received", response); - cleanup(); - } - } - - /* - * @testName: getUserPropertiesTest - * - * @assertion_ids: - * - * @test_Strategy: Run test twice. Modifications to user properties in first - * run should not be visible to second run as shallow copies should be used. - */ - public void getUserPropertiesTest() throws Exception { - String[] endpoints = new String[] { "programatic/userproperties", "programatic/userproperties" }; - for (String endpoint : endpoints) { - setProperty(Property.REQUEST, buildRequest(endpoint)); - setProperty(Property.CONTENT, "userproperties"); - invoke(false); - String response = getResponseAsString(); - assertEquals("PASS", response, - "Unexpected result received", response); - cleanup(); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSClientIT.java new file mode 100644 index 0000000000..94b7d86d3b --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSClientIT.java @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.ExtensionImpl; +import com.sun.ts.tests.websocket.common.impl.ExtensionParameterImpl; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.common.util.StringUtil; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 6621336154397058231L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_ee_jakarta_websocket_server_serverendpointconfig_builder_web.war"); + archive.addPackages(true, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(ExtensionImpl.class, ExtensionParameterImpl.class); + archive.addClasses(IOUtil.class, StringUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + this.setup(); + setContextRoot("wsc_ee_jakarta_websocket_server_serverendpointconfig_web"); + + } + + /* Run test */ + + /* + * @testName: getConfiguratorTest + * + * @assertion_ids: WebSocket:JAVADOC:193; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; + * + * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getConfigurator + * jakarta.websocket.Endpoint.onOpen; + * jakarta.websocket.MessageHandler.Whole.onMessage + */ + @Test + public void getConfiguratorTest() throws Exception { + String[] endpoints = new String[] { "programatic/subprotocols", "annotated/configurator", + "programatic/configurator" }; + String[] responses = new String[] { SubprotocolsServerEndpointConfig.class.getName(), + ServerEndpointConfigConfigurator.class.getName(), ServerEndpointConfigConfigurator.class.getName() }; + for (int i = 0; i != endpoints.length; i++) { + setProperty(Property.REQUEST, buildRequest(endpoints[i])); + setProperty(Property.CONTENT, "configurator"); + setProperty(Property.SEARCH_STRING, responses[i]); + invoke(); + } + } + + /* + * @testName: getEndpointClassTest + * + * @assertion_ids: WebSocket:JAVADOC:194; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; + * + * @test_Strategy: + * jakarta.websocket.server.ServerEndpointConfig.getEndpointClass + * jakarta.websocket.Endpoint.onOpen; + * jakarta.websocket.MessageHandler.Whole.onMessage + */ + @Test + public void getEndpointClassTest() throws Exception { + String[] endpoints = new String[] { "programatic/subprotocols", "annotated/subprotocols", + "annotated/configurator", "programatic/configurator", "programatic/extensions" }; + String[] responses = new String[] { WSProgramaticSubprotocolsServer.class.getName(), + WSAnnotatedSubprotocolsServer.class.getName(), WSAnnotatedConfiguratorServer.class.getName(), + WSProgramaticConfiguratorServer.class.getName(), WSProgramaticExtensionsServer.class.getName() }; + for (int i = 0; i != endpoints.length; i++) { + setProperty(Property.REQUEST, buildRequest(endpoints[i])); + setProperty(Property.CONTENT, "endpoint"); + setProperty(Property.SEARCH_STRING, responses[i]); + invoke(); + } + } + + /* + * @testName: getExtensionsTest + * + * @assertion_ids: WebSocket:JAVADOC:195; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; + * + * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getExtensions + * jakarta.websocket.Endpoint.onOpen; + * jakarta.websocket.MessageHandler.Whole.onMessage + */ + @Test + public void getExtensionsTest() throws Exception { + String[] endpoints = new String[] { "programatic/subprotocols", "annotated/subprotocols", + "annotated/configurator", "programatic/configurator", "programatic/extensions" }; + String[] responses = new String[] { "[]", "[]", "[]", "[]", + ExtensionsServerEndpointConfig.EXT_NAMES[0] + "|" + ExtensionsServerEndpointConfig.EXT_NAMES[1] }; + for (int i = 0; i != endpoints.length; i++) { + setProperty(Property.REQUEST, buildRequest(endpoints[i])); + setProperty(Property.CONTENT, "extensions"); + setProperty(Property.UNORDERED_SEARCH_STRING, responses[i]); + invoke(); + } + } + + /* + * @testName: getPathTest + * + * @assertion_ids: WebSocket:JAVADOC:196; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; + * + * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getPath + * jakarta.websocket.Endpoint.onOpen; + * jakarta.websocket.MessageHandler.Whole.onMessage + */ + @Test + public void getPathTest() throws Exception { + String[] sequence = new String[] { "programatic/subprotocols", "annotated/subprotocols", + "annotated/configurator", "programatic/configurator", "programatic/extensions" }; + for (String endpoint : sequence) { + setProperty(Property.REQUEST, buildRequest(endpoint)); + setProperty(Property.CONTENT, "path"); + setProperty(Property.SEARCH_STRING, endpoint); + invoke(); + } + } + + /* + * @testName: getSubprotocolsTest + * + * @assertion_ids: WebSocket:JAVADOC:197; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; + * + * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getSubprotocols + * Return the websocket subprotocols configured. + * jakarta.websocket.Endpoint.onOpen; + * jakarta.websocket.MessageHandler.Whole.onMessage + */ + @Test + public void getSubprotocolsTest() throws Exception { + String[] endpoints = new String[] { "programatic/subprotocols", "annotated/subprotocols" }; + for (String endpoint : endpoints) { + setProperty(Property.REQUEST, buildRequest(endpoint)); + setProperty(Property.CONTENT, "subprotocols"); + setProperty(Property.UNORDERED_SEARCH_STRING, "abc"); + setProperty(Property.UNORDERED_SEARCH_STRING, "def"); + invoke(); + } + } + + /* + * @testName: getEmptySubprotocolsTest + * + * @assertion_ids: WebSocket:JAVADOC:197; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; + * + * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getSubprotocols + * Return the websocket subprotocols configured. + * jakarta.websocket.Endpoint.onOpen; + * jakarta.websocket.MessageHandler.Whole.onMessage + */ + @Test + public void getEmptySubprotocolsTest() throws Exception { + String[] endpoints = new String[] { "annotated/configurator", "programatic/configurator", + "programatic/extensions" }; + for (String endpoint : endpoints) { + setProperty(Property.REQUEST, buildRequest(endpoint)); + setProperty(Property.CONTENT, "subprotocols"); + invoke(false); + String response = getResponseAsString(); + assertEqualsInt(0, response.replace("[", "").replace("]", "").trim().length(), + "Unexpected subprotocol list received", response); + cleanup(); + } + } + + /* + * @testName: getUserPropertiesTest + * + * @assertion_ids: + * + * @test_Strategy: Run test twice. Modifications to user properties in first run + * should not be visible to second run as shallow copies should be used. + */ + @Test + public void getUserPropertiesTest() throws Exception { + String[] endpoints = new String[] { "programatic/userproperties", "programatic/userproperties" }; + for (String endpoint : endpoints) { + setProperty(Property.REQUEST, buildRequest(endpoint)); + setProperty(Property.CONTENT, "userproperties"); + invoke(false); + String response = getResponseAsString(); + assertEquals("PASS", response, "Unexpected result received", response); + cleanup(); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticConfiguratorServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticConfiguratorServer.java index 24ff462636..efa99034a0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticConfiguratorServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticConfiguratorServer.java @@ -29,60 +29,57 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpointConfig; -public class WSProgramaticConfiguratorServer extends Endpoint - implements MessageHandler.Whole { +public class WSProgramaticConfiguratorServer extends Endpoint implements MessageHandler.Whole { - Session session; + Session session; - ServerEndpointConfig config; + ServerEndpointConfig config; - @Override - public void onMessage(String msg) { - try { - if (msg.equals("subprotocols")) - session.getBasicRemote() - .sendText(StringUtil.objectsToString(config.getSubprotocols())); - else if (msg.equals("path")) - session.getBasicRemote().sendText(config.getPath()); - else if (msg.equals("endpoint")) - session.getBasicRemote().sendText(config.getEndpointClass().getName()); - else if (msg.equals("configurator")) - session.getBasicRemote() - .sendText(config.getConfigurator().getClass().getName()); - else if (msg.equals("extensions")) { - StringBuilder sb = new StringBuilder().append("["); - Extension[] ext = config.getExtensions().toArray(new Extension[0]); - for (Extension e : ext) - sb.append(e.getName()).append(" "); - sb.append("]"); - session.getBasicRemote().sendText(sb.toString()); - } - } catch (IOException e) { - e.printStackTrace(); - try { - session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } + @Override + public void onMessage(String msg) { + try { + if (msg.equals("subprotocols")) + session.getBasicRemote().sendText(StringUtil.objectsToString(config.getSubprotocols())); + else if (msg.equals("path")) + session.getBasicRemote().sendText(config.getPath()); + else if (msg.equals("endpoint")) + session.getBasicRemote().sendText(config.getEndpointClass().getName()); + else if (msg.equals("configurator")) + session.getBasicRemote().sendText(config.getConfigurator().getClass().getName()); + else if (msg.equals("extensions")) { + StringBuilder sb = new StringBuilder().append("["); + Extension[] ext = config.getExtensions().toArray(new Extension[0]); + for (Extension e : ext) + sb.append(e.getName()).append(" "); + sb.append("]"); + session.getBasicRemote().sendText(sb.toString()); + } + } catch (IOException e) { + e.printStackTrace(); + try { + session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - this.config = (ServerEndpointConfig) config; - session.addMessageHandler(this); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + this.config = (ServerEndpointConfig) config; + session.addMessageHandler(this); + } - @Override - public void onError(Session session, Throwable thr) { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } + @Override + public void onError(Session session, Throwable thr) { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticExtensionsServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticExtensionsServer.java index 32f9f69fde..997b469fab 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticExtensionsServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticExtensionsServer.java @@ -29,60 +29,57 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpointConfig; -public class WSProgramaticExtensionsServer extends Endpoint - implements MessageHandler.Whole { +public class WSProgramaticExtensionsServer extends Endpoint implements MessageHandler.Whole { - Session session; + Session session; - ServerEndpointConfig config; + ServerEndpointConfig config; - @Override - public void onMessage(String msg) { - try { - if (msg.equals("subprotocols")) - session.getBasicRemote() - .sendText(StringUtil.objectsToString(config.getSubprotocols())); - else if (msg.equals("path")) - session.getBasicRemote().sendText(config.getPath()); - else if (msg.equals("endpoint")) - session.getBasicRemote().sendText(config.getEndpointClass().getName()); - else if (msg.equals("configurator")) - session.getBasicRemote() - .sendText(config.getConfigurator().getClass().getName()); - else if (msg.equals("extensions")) { - StringBuilder sb = new StringBuilder().append("["); - Extension[] ext = config.getExtensions().toArray(new Extension[0]); - for (Extension e : ext) - sb.append(e.getName()).append(" "); - sb.append("]"); - session.getBasicRemote().sendText(sb.toString()); - } - } catch (IOException e) { - e.printStackTrace(); - try { - session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } + @Override + public void onMessage(String msg) { + try { + if (msg.equals("subprotocols")) + session.getBasicRemote().sendText(StringUtil.objectsToString(config.getSubprotocols())); + else if (msg.equals("path")) + session.getBasicRemote().sendText(config.getPath()); + else if (msg.equals("endpoint")) + session.getBasicRemote().sendText(config.getEndpointClass().getName()); + else if (msg.equals("configurator")) + session.getBasicRemote().sendText(config.getConfigurator().getClass().getName()); + else if (msg.equals("extensions")) { + StringBuilder sb = new StringBuilder().append("["); + Extension[] ext = config.getExtensions().toArray(new Extension[0]); + for (Extension e : ext) + sb.append(e.getName()).append(" "); + sb.append("]"); + session.getBasicRemote().sendText(sb.toString()); + } + } catch (IOException e) { + e.printStackTrace(); + try { + session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - this.config = (ServerEndpointConfig) config; - session.addMessageHandler(this); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + this.config = (ServerEndpointConfig) config; + session.addMessageHandler(this); + } - @Override - public void onError(Session session, Throwable thr) { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } + @Override + public void onError(Session session, Throwable thr) { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticSubprotocolsServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticSubprotocolsServer.java index 33ce3930c5..48f97557fa 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticSubprotocolsServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticSubprotocolsServer.java @@ -29,62 +29,59 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpointConfig; -public class WSProgramaticSubprotocolsServer extends Endpoint - implements MessageHandler.Whole { +public class WSProgramaticSubprotocolsServer extends Endpoint implements MessageHandler.Whole { - Session session; + Session session; - ServerEndpointConfig config; + ServerEndpointConfig config; - @Override - public void onMessage(String msg) { - try { - if (msg.equals("subprotocols")) - session.getBasicRemote() - .sendText(StringUtil.objectsToString(config.getSubprotocols())); - else if (msg.equals("path")) - session.getBasicRemote().sendText(config.getPath()); - else if (msg.equals("endpoint")) - session.getBasicRemote().sendText(config.getEndpointClass().getName()); - else if (msg.equals("configurator")) - session.getBasicRemote() - .sendText(config.getConfigurator().getClass().getName()); - else if (msg.equals("extensions")) { - StringBuilder sb = new StringBuilder().append("["); - Extension[] ext = config.getExtensions().toArray(new Extension[0]); - for (Extension e : ext) - sb.append(e.getName()).append(" "); - sb.append("]"); - session.getBasicRemote().sendText(sb.toString()); - } else - session.getBasicRemote().sendText(session.getNegotiatedSubprotocol()); + @Override + public void onMessage(String msg) { + try { + if (msg.equals("subprotocols")) + session.getBasicRemote().sendText(StringUtil.objectsToString(config.getSubprotocols())); + else if (msg.equals("path")) + session.getBasicRemote().sendText(config.getPath()); + else if (msg.equals("endpoint")) + session.getBasicRemote().sendText(config.getEndpointClass().getName()); + else if (msg.equals("configurator")) + session.getBasicRemote().sendText(config.getConfigurator().getClass().getName()); + else if (msg.equals("extensions")) { + StringBuilder sb = new StringBuilder().append("["); + Extension[] ext = config.getExtensions().toArray(new Extension[0]); + for (Extension e : ext) + sb.append(e.getName()).append(" "); + sb.append("]"); + session.getBasicRemote().sendText(sb.toString()); + } else + session.getBasicRemote().sendText(session.getNegotiatedSubprotocol()); - } catch (IOException e) { - e.printStackTrace(); - try { - session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } + } catch (IOException e) { + e.printStackTrace(); + try { + session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - this.config = (ServerEndpointConfig) config; - session.addMessageHandler(this); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + this.config = (ServerEndpointConfig) config; + session.addMessageHandler(this); + } - @Override - public void onError(Session session, Throwable thr) { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } + @Override + public void onError(Session session, Throwable thr) { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticUserPropertiesServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticUserPropertiesServer.java index 483844b355..a1f6aa8243 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticUserPropertiesServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/WSProgramaticUserPropertiesServer.java @@ -26,52 +26,50 @@ public class WSProgramaticUserPropertiesServer extends Endpoint implements MessageHandler.Whole { - Session session; + Session session; - private static final String KEY_5 = "UPS-5"; - - @Override - public void onMessage(String msg) { - Map userProperties = session.getUserProperties(); - - // First check that the expected properties are present - if (userProperties.size() != 3) { - throw new IllegalStateException( - "User properties map has [" + userProperties.size() + "] entries when 3 are expected"); - } + private static final String KEY_5 = "UPS-5"; - // Then check expected keys are present - checkKey(userProperties, UserPropertiesServerEndpointConfig.KEY_1); - checkKey(userProperties, UserPropertiesConfigurator.KEY_3); - checkKey(userProperties, UserPropertiesConfigurator.KEY_4); + @Override + public void onMessage(String msg) { + Map userProperties = session.getUserProperties(); - // Now remove key 4 and add one of our own - userProperties.remove(UserPropertiesConfigurator.KEY_4); - userProperties.put(KEY_5, new Object()); + // First check that the expected properties are present + if (userProperties.size() != 3) { + throw new IllegalStateException( + "User properties map has [" + userProperties.size() + "] entries when 3 are expected"); + } - try { - session.getBasicRemote().sendText("PASS"); - } catch (IOException e) { - e.printStackTrace(); - } - } + // Then check expected keys are present + checkKey(userProperties, UserPropertiesServerEndpointConfig.KEY_1); + checkKey(userProperties, UserPropertiesConfigurator.KEY_3); + checkKey(userProperties, UserPropertiesConfigurator.KEY_4); - - private void checkKey(Map map, String key) { - if (!map.containsKey(key)) { - throw new IllegalStateException("User properties map is missing entry with key [" + key + "]"); - } - } + // Now remove key 4 and add one of our own + userProperties.remove(UserPropertiesConfigurator.KEY_4); + userProperties.put(KEY_5, new Object()); + try { + session.getBasicRemote().sendText("PASS"); + } catch (IOException e) { + e.printStackTrace(); + } + } - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - session.addMessageHandler(this); - } + private void checkKey(Map map, String key) { + if (!map.containsKey(key)) { + throw new IllegalStateException("User properties map is missing entry with key [" + key + "]"); + } + } - @Override - public void onError(Session session, Throwable thr) { - thr.printStackTrace(); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + session.addMessageHandler(this); + } + + @Override + public void onError(Session session, Throwable thr) { + thr.printStackTrace(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/AppConfig.java index 83d1bf31e9..14227cca4f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/AppConfig.java @@ -41,91 +41,82 @@ import jakarta.websocket.server.ServerEndpointConfig; public class AppConfig implements ServerApplicationConfig { - static final String[] EXT_NAMES = new String[] { "empty", "secondEmpty" }; - - public static final ServerEndpointConfig.Configurator CONFIG = new ServerEndpointConfig.Configurator() { - }; - - ServerEndpointConfig getSubprotocolsConfig() { - ServerEndpointConfig config = ServerEndpointConfig.Builder - .create(WSCommonServer.class, "/builder/subprotocols") - .subprotocols(Arrays.asList("abc", "def")).configurator(CONFIG).build(); - return config; - } - - ServerEndpointConfig getConfiguratorConfig() { - ServerEndpointConfig config = ServerEndpointConfig.Builder - .create(WSCommonServer.class, "/builder/configurator") - .configurator(new ServerEndpointConfigConfigurator()).build(); - return config; - } - - ServerEndpointConfig getExtensionsConfig() { - Extension firstExt = new Extension() { - @Override - public String getName() { - return EXT_NAMES[0]; - } - - @Override - public List getParameters() { - return Collections.emptyList(); - } - }; - - Extension secondExt = new Extension() { - @Override - public String getName() { - return EXT_NAMES[1]; - } - - @Override - public List getParameters() { - return Collections.emptyList(); - } - }; - ServerEndpointConfig config = ServerEndpointConfig.Builder - .create(WSCommonServer.class, "/builder/extensions") - .configurator(CONFIG).extensions(Arrays.asList(firstExt, secondExt)) - .build(); - return config; - } - - ServerEndpointConfig getDecodersConfig() { - List> decoders = Arrays.asList( - StringBeanBinaryStreamDecoder.class, StringBeanTextDecoder.class, - StringBeanBinaryDecoder.class, StringBeanTextStreamDecoder.class); - ServerEndpointConfig config = ServerEndpointConfig.Builder - .create(WSCommonServer.class, "/builder/decoders").decoders(decoders) - .configurator(CONFIG).build(); - return config; - } - - ServerEndpointConfig getEncodersConfig() { - List> encoders = Arrays.asList( - StringBeanTextStreamEncoder.class, StringBeanBinaryEncoder.class, - StringBeanTextEncoder.class, StringBeanBinaryStreamEncoder.class); - ServerEndpointConfig config = ServerEndpointConfig.Builder - .create(WSCommonServer.class, "/builder/encoders").encoders(encoders) - .configurator(CONFIG).build(); - return config; - } - - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - set.add(getSubprotocolsConfig()); - set.add(getConfiguratorConfig()); - set.add(getExtensionsConfig()); - set.add(getDecodersConfig()); - set.add(getEncodersConfig()); - return set; - } - - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - return set; - } + static final String[] EXT_NAMES = new String[] { "empty", "secondEmpty" }; + + public static final ServerEndpointConfig.Configurator CONFIG = new ServerEndpointConfig.Configurator() { + }; + + ServerEndpointConfig getSubprotocolsConfig() { + ServerEndpointConfig config = ServerEndpointConfig.Builder.create(WSCommonServer.class, "/builder/subprotocols") + .subprotocols(Arrays.asList("abc", "def")).configurator(CONFIG).build(); + return config; + } + + ServerEndpointConfig getConfiguratorConfig() { + ServerEndpointConfig config = ServerEndpointConfig.Builder.create(WSCommonServer.class, "/builder/configurator") + .configurator(new ServerEndpointConfigConfigurator()).build(); + return config; + } + + ServerEndpointConfig getExtensionsConfig() { + Extension firstExt = new Extension() { + @Override + public String getName() { + return EXT_NAMES[0]; + } + + @Override + public List getParameters() { + return Collections.emptyList(); + } + }; + + Extension secondExt = new Extension() { + @Override + public String getName() { + return EXT_NAMES[1]; + } + + @Override + public List getParameters() { + return Collections.emptyList(); + } + }; + ServerEndpointConfig config = ServerEndpointConfig.Builder.create(WSCommonServer.class, "/builder/extensions") + .configurator(CONFIG).extensions(Arrays.asList(firstExt, secondExt)).build(); + return config; + } + + ServerEndpointConfig getDecodersConfig() { + List> decoders = Arrays.asList(StringBeanBinaryStreamDecoder.class, + StringBeanTextDecoder.class, StringBeanBinaryDecoder.class, StringBeanTextStreamDecoder.class); + ServerEndpointConfig config = ServerEndpointConfig.Builder.create(WSCommonServer.class, "/builder/decoders") + .decoders(decoders).configurator(CONFIG).build(); + return config; + } + + ServerEndpointConfig getEncodersConfig() { + List> encoders = Arrays.asList(StringBeanTextStreamEncoder.class, + StringBeanBinaryEncoder.class, StringBeanTextEncoder.class, StringBeanBinaryStreamEncoder.class); + ServerEndpointConfig config = ServerEndpointConfig.Builder.create(WSCommonServer.class, "/builder/encoders") + .encoders(encoders).configurator(CONFIG).build(); + return config; + } + + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + set.add(getSubprotocolsConfig()); + set.add(getConfiguratorConfig()); + set.add(getExtensionsConfig()); + set.add(getDecodersConfig()); + set.add(getEncodersConfig()); + return set; + } + + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/WSClient.java deleted file mode 100644 index e4bfba3538..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/WSClient.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.builder; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryDecoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryEncoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamDecoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamEncoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextEncoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamDecoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamEncoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.ServerEndpointConfigConfigurator; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 1217261514689339373L; - - public WSClient() { - setContextRoot( - "wsc_ee_jakarta_websocket_server_serverendpointconfig_builder_web"); - - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - static String[] endpoints = new String[] { "builder/configurator", - "builder/decoders", "builder/encoders", "builder/extensions", - "builder/subprotocols" }; - - /* Run test */ - - /* - * @testName: getConfiguratorTest - * - * @assertion_ids: WebSocket:JAVADOC:199; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:200; WebSocket:JAVADOC:193; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; - * - * @test_Strategy: - * jakarta.websocket.server.ServerEndpointConfig.Builder.configurator - * jakarta.websocket.server.ServerEndpointConfig.Builder.build - * jakarta.websocket.server.ServerEndpointConfig.Builder.create - * jakarta.websocket.server.ServerEndpointConfig.getConfigurator - * jakarta.websocket.Endpoint.onOpen; - * jakarta.websocket.MessageHandler.Whole.onMessage - */ - public void getConfiguratorTest() throws Exception { - String name = AppConfig.CONFIG.getClass().getName(); - String[] responses = new String[] { - ServerEndpointConfigConfigurator.class.getName(), name, name, name, - name }; - for (int i = 0; i != endpoints.length; i++) { - setProperty(Property.REQUEST, buildRequest(endpoints[i])); - setProperty(Property.CONTENT, "configurator"); - setProperty(Property.SEARCH_STRING, responses[i]); - invoke(); - } - } - - /* - * @testName: getExtensionsTest - * - * @assertion_ids: WebSocket:JAVADOC:203; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:200; WebSocket:JAVADOC:195; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; - * - * @test_Strategy: - * jakarta.websocket.server.ServerEndpointConfig.Builder.extensions - * jakarta.websocket.server.ServerEndpointConfig.Builder.build - * jakarta.websocket.server.ServerEndpointConfig.Builder.create - * jakarta.websocket.server.ServerEndpointConfig.getExtensions - * jakarta.websocket.Endpoint.onOpen; - * jakarta.websocket.MessageHandler.Whole.onMessage - */ - public void getExtensionsTest() throws Exception { - String[] responses = new String[] { "[]", "[]", "[]", - AppConfig.EXT_NAMES[0] + "|" + AppConfig.EXT_NAMES[1], "[]" }; - for (int i = 0; i != endpoints.length; i++) { - setProperty(Property.REQUEST, buildRequest(endpoints[i])); - setProperty(Property.CONTENT, "extensions"); - setProperty(Property.UNORDERED_SEARCH_STRING, responses[i]); - invoke(); - } - } - - /* - * @testName: getPathTest - * - * @assertion_ids: WebSocket:JAVADOC:196; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; - * - * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getPath - * jakarta.websocket.Endpoint.onOpen; - * jakarta.websocket.MessageHandler.Whole.onMessage - */ - public void getPathTest() throws Exception { - for (String endpoint : endpoints) { - setProperty(Property.REQUEST, buildRequest(endpoint)); - setProperty(Property.CONTENT, "path"); - setProperty(Property.SEARCH_STRING, endpoint); - invoke(); - } - } - - /* - * @testName: getSubprotocolsTest - * - * @assertion_ids: WebSocket:JAVADOC:204; WebSocket:JAVADOC:198; - * WebSocket:JAVADOC:200; WebSocket:JAVADOC:197; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; - * - * @test_Strategy: - * jakarta.websocket.server.ServerEndpointConfig.Builder.subprotocols - * jakarta.websocket.server.ServerEndpointConfig.Builder.build - * jakarta.websocket.server.ServerEndpointConfig.Builder.create - * jakarta.websocket.server.ServerEndpointConfig.getSubprotocols Return the - * websocket subprotocols configured. jakarta.websocket.Endpoint.onOpen; - * jakarta.websocket.MessageHandler.Whole.onMessage - */ - public void getSubprotocolsTest() throws Exception { - setProperty(Property.REQUEST, - buildRequest(endpoints[endpoints.length - 1])); - setProperty(Property.CONTENT, "subprotocols"); - setProperty(Property.UNORDERED_SEARCH_STRING, "abc"); - setProperty(Property.UNORDERED_SEARCH_STRING, "def"); - invoke(); - } - - /* - * @testName: getEmptySubprotocolsTest - * - * @assertion_ids: WebSocket:JAVADOC:197; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; - * - * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getSubprotocols - * Return the websocket subprotocols configured. - * jakarta.websocket.Endpoint.onOpen; - * jakarta.websocket.MessageHandler.Whole.onMessage - */ - public void getEmptySubprotocolsTest() throws Exception { - for (int i = 0; i != endpoints.length - 1; i++) { - setProperty(Property.REQUEST, buildRequest(endpoints[i])); - setProperty(Property.CONTENT, "subprotocols"); - invoke(false); - String response = getResponseAsString(); - assertEqualsInt(0, - response.replace("[", "").replace("]", "").trim().length(), - "Unexpected subprotocol list received", response); - cleanup(); - } - } - - /* - * @testName: getEncodersTest - * - * @assertion_ids: WebSocket:JAVADOC:202; WebSocket:JAVADOC:200; - * WebSocket:JAVADOC:198; - * - * @test_Strategy: - * jakarta.websocket.server.ServerEndpointConfig.Builder.encoders - * jakarta.websocket.server.ServerEndpointConfig.Builder.create - * jakarta.websocket.server.ServerEndpointConfig.Builder.build - */ - public void getEncodersTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("builder/encoders")); - setProperty(Property.CONTENT, "encoders"); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanBinaryEncoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanBinaryStreamEncoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanTextEncoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanTextStreamEncoder.class.getName()); - invoke(); - } - - /* - * @testName: getDecodersTest - * - * @assertion_ids: WebSocket:JAVADOC:201; WebSocket:JAVADOC:200; - * WebSocket:JAVADOC:198; - * - * @test_Strategy: - * jakarta.websocket.server.ServerEndpointConfig.Builder.decoders - * jakarta.websocket.server.ServerEndpointConfig.Builder.create - * jakarta.websocket.server.ServerEndpointConfig.Builder.build - */ - public void getDecodersTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("builder/decoders")); - setProperty(Property.CONTENT, "decoders"); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanBinaryDecoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanBinaryStreamDecoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanTextDecoder.class.getName()); - setProperty(Property.UNORDERED_SEARCH_STRING, - StringBeanTextStreamDecoder.class.getName()); - invoke(); - } - - /* - * @testName: getDefaultEncodersTest - * - * @assertion_ids: WebSocket:JAVADOC:202; - * - * @test_Strategy: Default: {} - * jakarta.websocket.server.ServerEndpointConfig.Builder.encoders - */ - public void getDefaultEncodersTest() throws Exception { - for (int i = 0; i != endpoints.length; i++) - if (i != 2) { - setProperty(Property.REQUEST, buildRequest(endpoints[i])); - setProperty(Property.CONTENT, "encoders"); - setProperty(Property.SEARCH_STRING, "{}"); - invoke(); - } - } - - /* - * @testName: getDefaultDecodersTest - * - * @assertion_ids: WebSocket:JAVADOC:201; - * - * @test_Strategy: Default: {} - * jakarta.websocket.server.ServerEndpointConfig.Builder.decoders - */ - public void getDefaultDecodersTest() throws Exception { - for (int i = 0; i != endpoints.length; i++) - if (i != 1) { - setProperty(Property.REQUEST, buildRequest(endpoints[i])); - setProperty(Property.CONTENT, "decoders"); - setProperty(Property.SEARCH_STRING, "{}"); - invoke(); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/WSClientIT.java new file mode 100644 index 0000000000..58619063bd --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/WSClientIT.java @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.builder; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.ExtensionImpl; +import com.sun.ts.tests.websocket.common.impl.ExtensionParameterImpl; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextEncoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamEncoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.common.util.StringUtil; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.ServerEndpointConfigConfigurator; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.configurator.WSCClientIT; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 1217261514689339373L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_ee_jakarta_websocket_server_serverendpointconfig_builder_web.war"); + archive.addPackages(true, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.builder"); + archive.addPackages(true, "com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(ExtensionImpl.class, ExtensionParameterImpl.class); + archive.addClasses(IOUtil.class, StringUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_jakarta_websocket_server_serverendpointconfig_builder_web"); + + } + + static String[] endpoints = new String[] { "builder/configurator", "builder/decoders", "builder/encoders", + "builder/extensions", "builder/subprotocols" }; + + /* Run test */ + + /* + * @testName: getConfiguratorTest + * + * @assertion_ids: WebSocket:JAVADOC:199; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:200; WebSocket:JAVADOC:193; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; + * + * @test_Strategy: + * jakarta.websocket.server.ServerEndpointConfig.Builder.configurator + * jakarta.websocket.server.ServerEndpointConfig.Builder.build + * jakarta.websocket.server.ServerEndpointConfig.Builder.create + * jakarta.websocket.server.ServerEndpointConfig.getConfigurator + * jakarta.websocket.Endpoint.onOpen; + * jakarta.websocket.MessageHandler.Whole.onMessage + */ + @Test + public void getConfiguratorTest() throws Exception { + String name = AppConfig.CONFIG.getClass().getName(); + String[] responses = new String[] { ServerEndpointConfigConfigurator.class.getName(), name, name, name, name }; + for (int i = 0; i != endpoints.length; i++) { + setProperty(Property.REQUEST, buildRequest(endpoints[i])); + setProperty(Property.CONTENT, "configurator"); + setProperty(Property.SEARCH_STRING, responses[i]); + invoke(); + } + } + + /* + * @testName: getExtensionsTest + * + * @assertion_ids: WebSocket:JAVADOC:203; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:200; WebSocket:JAVADOC:195; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; + * + * @test_Strategy: + * jakarta.websocket.server.ServerEndpointConfig.Builder.extensions + * jakarta.websocket.server.ServerEndpointConfig.Builder.build + * jakarta.websocket.server.ServerEndpointConfig.Builder.create + * jakarta.websocket.server.ServerEndpointConfig.getExtensions + * jakarta.websocket.Endpoint.onOpen; + * jakarta.websocket.MessageHandler.Whole.onMessage + */ + @Test + public void getExtensionsTest() throws Exception { + String[] responses = new String[] { "[]", "[]", "[]", AppConfig.EXT_NAMES[0] + "|" + AppConfig.EXT_NAMES[1], + "[]" }; + for (int i = 0; i != endpoints.length; i++) { + setProperty(Property.REQUEST, buildRequest(endpoints[i])); + setProperty(Property.CONTENT, "extensions"); + setProperty(Property.UNORDERED_SEARCH_STRING, responses[i]); + invoke(); + } + } + + /* + * @testName: getPathTest + * + * @assertion_ids: WebSocket:JAVADOC:196; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; + * + * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getPath + * jakarta.websocket.Endpoint.onOpen; + * jakarta.websocket.MessageHandler.Whole.onMessage + */ + @Test + public void getPathTest() throws Exception { + for (String endpoint : endpoints) { + setProperty(Property.REQUEST, buildRequest(endpoint)); + setProperty(Property.CONTENT, "path"); + setProperty(Property.SEARCH_STRING, endpoint); + invoke(); + } + } + + /* + * @testName: getSubprotocolsTest + * + * @assertion_ids: WebSocket:JAVADOC:204; WebSocket:JAVADOC:198; + * WebSocket:JAVADOC:200; WebSocket:JAVADOC:197; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; + * + * @test_Strategy: + * jakarta.websocket.server.ServerEndpointConfig.Builder.subprotocols + * jakarta.websocket.server.ServerEndpointConfig.Builder.build + * jakarta.websocket.server.ServerEndpointConfig.Builder.create + * jakarta.websocket.server.ServerEndpointConfig.getSubprotocols Return the + * websocket subprotocols configured. jakarta.websocket.Endpoint.onOpen; + * jakarta.websocket.MessageHandler.Whole.onMessage + */ + @Test + public void getSubprotocolsTest() throws Exception { + setProperty(Property.REQUEST, buildRequest(endpoints[endpoints.length - 1])); + setProperty(Property.CONTENT, "subprotocols"); + setProperty(Property.UNORDERED_SEARCH_STRING, "abc"); + setProperty(Property.UNORDERED_SEARCH_STRING, "def"); + invoke(); + } + + /* + * @testName: getEmptySubprotocolsTest + * + * @assertion_ids: WebSocket:JAVADOC:197; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; + * + * @test_Strategy: jakarta.websocket.server.ServerEndpointConfig.getSubprotocols + * Return the websocket subprotocols configured. + * jakarta.websocket.Endpoint.onOpen; + * jakarta.websocket.MessageHandler.Whole.onMessage + */ + @Test + public void getEmptySubprotocolsTest() throws Exception { + for (int i = 0; i != endpoints.length - 1; i++) { + setProperty(Property.REQUEST, buildRequest(endpoints[i])); + setProperty(Property.CONTENT, "subprotocols"); + invoke(false); + String response = getResponseAsString(); + assertEqualsInt(0, response.replace("[", "").replace("]", "").trim().length(), + "Unexpected subprotocol list received", response); + cleanup(); + } + } + + /* + * @testName: getEncodersTest + * + * @assertion_ids: WebSocket:JAVADOC:202; WebSocket:JAVADOC:200; + * WebSocket:JAVADOC:198; + * + * @test_Strategy: + * jakarta.websocket.server.ServerEndpointConfig.Builder.encoders + * jakarta.websocket.server.ServerEndpointConfig.Builder.create + * jakarta.websocket.server.ServerEndpointConfig.Builder.build + */ + @Test + public void getEncodersTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("builder/encoders")); + setProperty(Property.CONTENT, "encoders"); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanBinaryEncoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanBinaryStreamEncoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanTextEncoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanTextStreamEncoder.class.getName()); + invoke(); + } + + /* + * @testName: getDecodersTest + * + * @assertion_ids: WebSocket:JAVADOC:201; WebSocket:JAVADOC:200; + * WebSocket:JAVADOC:198; + * + * @test_Strategy: + * jakarta.websocket.server.ServerEndpointConfig.Builder.decoders + * jakarta.websocket.server.ServerEndpointConfig.Builder.create + * jakarta.websocket.server.ServerEndpointConfig.Builder.build + */ + @Test + public void getDecodersTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("builder/decoders")); + setProperty(Property.CONTENT, "decoders"); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanBinaryDecoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanBinaryStreamDecoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanTextDecoder.class.getName()); + setProperty(Property.UNORDERED_SEARCH_STRING, StringBeanTextStreamDecoder.class.getName()); + invoke(); + } + + /* + * @testName: getDefaultEncodersTest + * + * @assertion_ids: WebSocket:JAVADOC:202; + * + * @test_Strategy: Default: {} + * jakarta.websocket.server.ServerEndpointConfig.Builder.encoders + */ + @Test + public void getDefaultEncodersTest() throws Exception { + for (int i = 0; i != endpoints.length; i++) + if (i != 2) { + setProperty(Property.REQUEST, buildRequest(endpoints[i])); + setProperty(Property.CONTENT, "encoders"); + setProperty(Property.SEARCH_STRING, "{}"); + invoke(); + } + } + + /* + * @testName: getDefaultDecodersTest + * + * @assertion_ids: WebSocket:JAVADOC:201; + * + * @test_Strategy: Default: {} + * jakarta.websocket.server.ServerEndpointConfig.Builder.decoders + */ + @Test + public void getDefaultDecodersTest() throws Exception { + for (int i = 0; i != endpoints.length; i++) + if (i != 1) { + setProperty(Property.REQUEST, buildRequest(endpoints[i])); + setProperty(Property.CONTENT, "decoders"); + setProperty(Property.SEARCH_STRING, "{}"); + invoke(); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/WSCommonServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/WSCommonServer.java index c4c7c65832..481224a763 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/WSCommonServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/builder/WSCommonServer.java @@ -32,68 +32,63 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpointConfig; -public class WSCommonServer extends Endpoint - implements MessageHandler.Whole { +public class WSCommonServer extends Endpoint implements MessageHandler.Whole { - protected Session session; + protected Session session; - protected ServerEndpointConfig config; + protected ServerEndpointConfig config; - @Override - public void onMessage(String message) { - try { - if (message.equals("subprotocols")) - session.getBasicRemote() - .sendText(StringUtil.objectsToString(config.getSubprotocols())); - else if (message.equals("path")) - session.getBasicRemote().sendText(config.getPath()); - else if (message.equals("endpoint")) - session.getBasicRemote().sendText(config.getEndpointClass().getName()); - else if (message.equals("configurator")) - session.getBasicRemote() - .sendText(config.getConfigurator().getClass().getName()); - else if (message.equals("extensions")) { - StringBuilder sb = new StringBuilder().append("["); - Extension[] ext = config.getExtensions().toArray(new Extension[0]); - for (Extension e : ext) - sb.append(e.getName()).append(" "); - sb.append("]"); - session.getBasicRemote().sendText(sb.toString()); - } else if (message.equals("decoders")) { - List> list = config.getDecoders(); - session.getBasicRemote() - .sendText("{" + StringUtil.objectsToString(list) + "}"); - } else if (message.equals("encoders")) { - List> list = config.getEncoders(); - session.getBasicRemote() - .sendText("{" + StringUtil.objectsToString(list) + "}"); - } - } catch (IOException e) { - e.printStackTrace(); - try { - session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } + @Override + public void onMessage(String message) { + try { + if (message.equals("subprotocols")) + session.getBasicRemote().sendText(StringUtil.objectsToString(config.getSubprotocols())); + else if (message.equals("path")) + session.getBasicRemote().sendText(config.getPath()); + else if (message.equals("endpoint")) + session.getBasicRemote().sendText(config.getEndpointClass().getName()); + else if (message.equals("configurator")) + session.getBasicRemote().sendText(config.getConfigurator().getClass().getName()); + else if (message.equals("extensions")) { + StringBuilder sb = new StringBuilder().append("["); + Extension[] ext = config.getExtensions().toArray(new Extension[0]); + for (Extension e : ext) + sb.append(e.getName()).append(" "); + sb.append("]"); + session.getBasicRemote().sendText(sb.toString()); + } else if (message.equals("decoders")) { + List> list = config.getDecoders(); + session.getBasicRemote().sendText("{" + StringUtil.objectsToString(list) + "}"); + } else if (message.equals("encoders")) { + List> list = config.getEncoders(); + session.getBasicRemote().sendText("{" + StringUtil.objectsToString(list) + "}"); + } + } catch (IOException e) { + e.printStackTrace(); + try { + session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - this.config = (ServerEndpointConfig) config; - session.addMessageHandler(this); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + this.config = (ServerEndpointConfig) config; + session.addMessageHandler(this); + } - @Override - public void onError(Session session, Throwable thr) { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } + @Override + public void onError(Session session, Throwable thr) { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/AppConfig.java index 96c459ae69..273fe23b72 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/AppConfig.java @@ -29,25 +29,24 @@ */ public class AppConfig implements ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - set.add(new ExtensionsServerEndpointConfig()); - set.add(new SubprotocolsServerEndpointConfig()); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + set.add(new ExtensionsServerEndpointConfig()); + set.add(new SubprotocolsServerEndpointConfig()); + return set; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(WSCGetEndpointInstanceServer.class); - set.add(WSCOriginServer.class); - set.add(WSCOriginServerReturningFalse.class); - set.add(WSCOriginServerReturningFalseConfigurator.class); - set.add(WSCModifyHandshakeServer.class); - set.add(WSCGetContainerDefaultConfiguratorServerA.class); - set.add(WSCGetContainerDefaultConfiguratorServerB.class); - return set; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(WSCGetEndpointInstanceServer.class); + set.add(WSCOriginServer.class); + set.add(WSCOriginServerReturningFalse.class); + set.add(WSCOriginServerReturningFalseConfigurator.class); + set.add(WSCModifyHandshakeServer.class); + set.add(WSCGetContainerDefaultConfiguratorServerA.class); + set.add(WSCGetContainerDefaultConfiguratorServerB.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ContainerDefaultConfiguratorA.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ContainerDefaultConfiguratorA.java index 3f2e5e17d8..9c0484484c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ContainerDefaultConfiguratorA.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ContainerDefaultConfiguratorA.java @@ -19,14 +19,14 @@ public class ContainerDefaultConfiguratorA extends Configurator { - private static String containerDefaultConfiguratorID; - - public ContainerDefaultConfiguratorA() { - Configurator c = getContainerDefaultConfigurator(); - containerDefaultConfiguratorID = Integer.toString(System.identityHashCode(c)); - } - - public static String getPlatformDefaultConfiguratorID() { - return containerDefaultConfiguratorID; - } + private static String containerDefaultConfiguratorID; + + public ContainerDefaultConfiguratorA() { + Configurator c = getContainerDefaultConfigurator(); + containerDefaultConfiguratorID = Integer.toString(System.identityHashCode(c)); + } + + public static String getPlatformDefaultConfiguratorID() { + return containerDefaultConfiguratorID; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ContainerDefaultConfiguratorB.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ContainerDefaultConfiguratorB.java index 4f75e79a3c..97e00498b0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ContainerDefaultConfiguratorB.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ContainerDefaultConfiguratorB.java @@ -19,14 +19,14 @@ public class ContainerDefaultConfiguratorB extends Configurator { - private static String containerDefaultConfiguratorID; - - public ContainerDefaultConfiguratorB() { - Configurator c = getContainerDefaultConfigurator(); - containerDefaultConfiguratorID = Integer.toString(System.identityHashCode(c)); - } - - public static String getPlatformDefaultConfiguratorID() { - return containerDefaultConfiguratorID; - } + private static String containerDefaultConfiguratorID; + + public ContainerDefaultConfiguratorB() { + Configurator c = getContainerDefaultConfigurator(); + containerDefaultConfiguratorID = Integer.toString(System.identityHashCode(c)); + } + + public static String getPlatformDefaultConfiguratorID() { + return containerDefaultConfiguratorID; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ExtensionsConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ExtensionsConfigurator.java index 57b349261f..efd1cab65b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ExtensionsConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ExtensionsConfigurator.java @@ -26,47 +26,43 @@ public class ExtensionsConfigurator extends Configurator { - private static List installed; - - private static List requested; - - private static List resulted; - - @Override - public List getNegotiatedExtensions(List installed, - List requested) { - List resulted = super.getNegotiatedExtensions(installed, - requested); - ExtensionsConfigurator - .setRequested(ExtensionImpl.transformToImpl(requested)); - ExtensionsConfigurator.setResulted(ExtensionImpl.transformToImpl(resulted)); - ExtensionsConfigurator - .setInstalled(ExtensionImpl.transformToImpl(installed)); - return resulted; - } - - static List getInstalled() { - return installed; - } - - static void setInstalled(List installed) { - ExtensionsConfigurator.installed = installed; - } - - static List getRequested() { - return requested; - } - - static void setRequested(List requested) { - ExtensionsConfigurator.requested = requested; - } - - static List getResulted() { - return resulted; - } - - static void setResulted(List resulted) { - ExtensionsConfigurator.resulted = resulted; - } + private static List installed; + + private static List requested; + + private static List resulted; + + @Override + public List getNegotiatedExtensions(List installed, List requested) { + List resulted = super.getNegotiatedExtensions(installed, requested); + ExtensionsConfigurator.setRequested(ExtensionImpl.transformToImpl(requested)); + ExtensionsConfigurator.setResulted(ExtensionImpl.transformToImpl(resulted)); + ExtensionsConfigurator.setInstalled(ExtensionImpl.transformToImpl(installed)); + return resulted; + } + + static List getInstalled() { + return installed; + } + + static void setInstalled(List installed) { + ExtensionsConfigurator.installed = installed; + } + + static List getRequested() { + return requested; + } + + static void setRequested(List requested) { + ExtensionsConfigurator.requested = requested; + } + + static List getResulted() { + return resulted; + } + + static void setResulted(List resulted) { + ExtensionsConfigurator.resulted = resulted; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ExtensionsServerEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ExtensionsServerEndpointConfig.java index a0e814fd13..90e996fabd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ExtensionsServerEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ExtensionsServerEndpointConfig.java @@ -32,54 +32,52 @@ public class ExtensionsServerEndpointConfig implements ServerEndpointConfig { - static final String[] EXT_NAMES = new String[] { "firstExtName", - "secondExtName", "thirdExtName" }; - - static final ExtensionParameterImpl[] PARAMETER = { - new ExtensionParameterImpl("firstName", "firstValue"), - new ExtensionParameterImpl("secondName", "secondValue") }; - - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } - - @Override - public Class getEndpointClass() { - return WSCExtensionsServer.class; - } - - @Override - public String getPath() { - return "/extensions"; - } - - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } - - @Override - public List getExtensions() { - Extension firstExt = new ExtensionImpl(EXT_NAMES[0], PARAMETER); - Extension secondExt = new ExtensionImpl(EXT_NAMES[1], PARAMETER); - Extension thirdExt = new ExtensionImpl(EXT_NAMES[2]); - return Arrays.asList(firstExt, secondExt, thirdExt); - } - - @Override - public Configurator getConfigurator() { - return new ExtensionsConfigurator(); - } - - @Override - public List> getEncoders() { - return Collections.emptyList(); - } - - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + static final String[] EXT_NAMES = new String[] { "firstExtName", "secondExtName", "thirdExtName" }; + + static final ExtensionParameterImpl[] PARAMETER = { new ExtensionParameterImpl("firstName", "firstValue"), + new ExtensionParameterImpl("secondName", "secondValue") }; + + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } + + @Override + public Class getEndpointClass() { + return WSCExtensionsServer.class; + } + + @Override + public String getPath() { + return "/extensions"; + } + + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } + + @Override + public List getExtensions() { + Extension firstExt = new ExtensionImpl(EXT_NAMES[0], PARAMETER); + Extension secondExt = new ExtensionImpl(EXT_NAMES[1], PARAMETER); + Extension thirdExt = new ExtensionImpl(EXT_NAMES[2]); + return Arrays.asList(firstExt, secondExt, thirdExt); + } + + @Override + public Configurator getConfigurator() { + return new ExtensionsConfigurator(); + } + + @Override + public List> getEncoders() { + return Collections.emptyList(); + } + + @Override + public List> getDecoders() { + return Collections.emptyList(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/GetEndpointInstanceConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/GetEndpointInstanceConfigurator.java index a8a1336739..6b955f7b1e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/GetEndpointInstanceConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/GetEndpointInstanceConfigurator.java @@ -20,26 +20,25 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class GetEndpointInstanceConfigurator extends Configurator { - private static String instanceName; + private static String instanceName; - static final String ADDITIONAL_INFORMATION = "Additional information passed to instance"; + static final String ADDITIONAL_INFORMATION = "Additional information passed to instance"; - @SuppressWarnings("unchecked") - @Override - public T getEndpointInstance(Class endpointClass) - throws InstantiationException { - T t = super.getEndpointInstance(endpointClass); - GetEndpointInstanceConfigurator.setInstanceName(t.getClass().getName()); - if (endpointClass == WSCGetEndpointInstanceServer.class) - t = (T) new WSCGetEndpointInstanceServer(ADDITIONAL_INFORMATION); - return t; - } + @SuppressWarnings("unchecked") + @Override + public T getEndpointInstance(Class endpointClass) throws InstantiationException { + T t = super.getEndpointInstance(endpointClass); + GetEndpointInstanceConfigurator.setInstanceName(t.getClass().getName()); + if (endpointClass == WSCGetEndpointInstanceServer.class) + t = (T) new WSCGetEndpointInstanceServer(ADDITIONAL_INFORMATION); + return t; + } - static String getInstanceName() { - return instanceName; - } + static String getInstanceName() { + return instanceName; + } - static void setInstanceName(String instanceName) { - GetEndpointInstanceConfigurator.instanceName = instanceName; - } + static void setInstanceName(String instanceName) { + GetEndpointInstanceConfigurator.instanceName = instanceName; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/GetNegotiatedSubprotocolConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/GetNegotiatedSubprotocolConfigurator.java index 89501a462d..0c9cf4c50b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/GetNegotiatedSubprotocolConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/GetNegotiatedSubprotocolConfigurator.java @@ -22,43 +22,41 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class GetNegotiatedSubprotocolConfigurator extends Configurator { - private static List supported; + private static List supported; - private static List requested; + private static List requested; - private static String resulted; + private static String resulted; - @Override - public String getNegotiatedSubprotocol(List supported, - List requested) { - GetNegotiatedSubprotocolConfigurator.setRequested(requested); - GetNegotiatedSubprotocolConfigurator.setSupported(supported); - GetNegotiatedSubprotocolConfigurator - .setResulted(super.getNegotiatedSubprotocol(supported, requested)); - return GetNegotiatedSubprotocolConfigurator.getResulted(); - } + @Override + public String getNegotiatedSubprotocol(List supported, List requested) { + GetNegotiatedSubprotocolConfigurator.setRequested(requested); + GetNegotiatedSubprotocolConfigurator.setSupported(supported); + GetNegotiatedSubprotocolConfigurator.setResulted(super.getNegotiatedSubprotocol(supported, requested)); + return GetNegotiatedSubprotocolConfigurator.getResulted(); + } - static List getSupported() { - return supported; - } + static List getSupported() { + return supported; + } - static List getRequested() { - return requested; - } + static List getRequested() { + return requested; + } - static String getResulted() { - return resulted; - } + static String getResulted() { + return resulted; + } - private static void setSupported(List supported) { - GetNegotiatedSubprotocolConfigurator.supported = supported; - } + private static void setSupported(List supported) { + GetNegotiatedSubprotocolConfigurator.supported = supported; + } - private static void setRequested(List requested) { - GetNegotiatedSubprotocolConfigurator.requested = requested; - } + private static void setRequested(List requested) { + GetNegotiatedSubprotocolConfigurator.requested = requested; + } - private static void setResulted(String resulted) { - GetNegotiatedSubprotocolConfigurator.resulted = resulted; - } + private static void setResulted(String resulted) { + GetNegotiatedSubprotocolConfigurator.resulted = resulted; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ModifyHandshakeConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ModifyHandshakeConfigurator.java index fd8f0643fc..296e3189a8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ModifyHandshakeConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/ModifyHandshakeConfigurator.java @@ -23,63 +23,60 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class ModifyHandshakeConfigurator extends Configurator { - private static ServerEndpointConfig config; + private static ServerEndpointConfig config; - private static HandshakeRequest request; + private static HandshakeRequest request; - private static HandshakeResponse response; + private static HandshakeResponse response; - private boolean isCheckedOrigin = false; + private boolean isCheckedOrigin = false; - private static boolean isCheckedOriginBeforeModifyHandshake = false; + private static boolean isCheckedOriginBeforeModifyHandshake = false; - @Override - public boolean checkOrigin(String originHeaderValue) { - isCheckedOrigin = true; - return super.checkOrigin(originHeaderValue); - } + @Override + public boolean checkOrigin(String originHeaderValue) { + isCheckedOrigin = true; + return super.checkOrigin(originHeaderValue); + } - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - ModifyHandshakeConfigurator - .setCheckedOriginBeforeModifyHandshake(isCheckedOrigin); - ModifyHandshakeConfigurator.setConfig(sec); - ModifyHandshakeConfigurator.setRequest(request); - ModifyHandshakeConfigurator.setResponse(response); - super.modifyHandshake(sec, request, response); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + ModifyHandshakeConfigurator.setCheckedOriginBeforeModifyHandshake(isCheckedOrigin); + ModifyHandshakeConfigurator.setConfig(sec); + ModifyHandshakeConfigurator.setRequest(request); + ModifyHandshakeConfigurator.setResponse(response); + super.modifyHandshake(sec, request, response); + } - static ServerEndpointConfig getConfig() { - return config; - } + static ServerEndpointConfig getConfig() { + return config; + } - static HandshakeRequest getRequest() { - return request; - } + static HandshakeRequest getRequest() { + return request; + } - static HandshakeResponse getResponse() { - return response; - } + static HandshakeResponse getResponse() { + return response; + } - static boolean isCheckedOriginBeforeModifyHandshake() { - return isCheckedOriginBeforeModifyHandshake; - } + static boolean isCheckedOriginBeforeModifyHandshake() { + return isCheckedOriginBeforeModifyHandshake; + } - private static void setConfig(ServerEndpointConfig config) { - ModifyHandshakeConfigurator.config = config; - } + private static void setConfig(ServerEndpointConfig config) { + ModifyHandshakeConfigurator.config = config; + } - private static void setRequest(HandshakeRequest request) { - ModifyHandshakeConfigurator.request = request; - } + private static void setRequest(HandshakeRequest request) { + ModifyHandshakeConfigurator.request = request; + } - private static void setResponse(HandshakeResponse response) { - ModifyHandshakeConfigurator.response = response; - } + private static void setResponse(HandshakeResponse response) { + ModifyHandshakeConfigurator.response = response; + } - private static void setCheckedOriginBeforeModifyHandshake( - boolean isCheckedOriginBeforeModifyHandshake) { - ModifyHandshakeConfigurator.isCheckedOriginBeforeModifyHandshake = isCheckedOriginBeforeModifyHandshake; - } + private static void setCheckedOriginBeforeModifyHandshake(boolean isCheckedOriginBeforeModifyHandshake) { + ModifyHandshakeConfigurator.isCheckedOriginBeforeModifyHandshake = isCheckedOriginBeforeModifyHandshake; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/OriginConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/OriginConfigurator.java index a4108a9792..5246617881 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/OriginConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/OriginConfigurator.java @@ -20,21 +20,21 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class OriginConfigurator extends Configurator { - private static String origin; + private static String origin; - public static String NULL = "NULL"; + public static String NULL = "NULL"; - @Override - public boolean checkOrigin(String originHeaderValue) { - OriginConfigurator.setOrigin(originHeaderValue); - return super.checkOrigin(originHeaderValue); - } + @Override + public boolean checkOrigin(String originHeaderValue) { + OriginConfigurator.setOrigin(originHeaderValue); + return super.checkOrigin(originHeaderValue); + } - static String getOrigin() { - return origin == null ? NULL : origin; - } + static String getOrigin() { + return origin == null ? NULL : origin; + } - static void setOrigin(String origin) { - OriginConfigurator.origin = origin; - } + static void setOrigin(String origin) { + OriginConfigurator.origin = origin; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/OriginConfiguratorReturningFalse.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/OriginConfiguratorReturningFalse.java index ff4f27cee8..477e73c55c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/OriginConfiguratorReturningFalse.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/OriginConfiguratorReturningFalse.java @@ -20,18 +20,18 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class OriginConfiguratorReturningFalse extends Configurator { - private static boolean origin = true; + private static boolean origin = true; - @Override - public boolean checkOrigin(String originHeaderValue) { - return origin; - } + @Override + public boolean checkOrigin(String originHeaderValue) { + return origin; + } - static boolean isOrigin() { - return origin; - } + static boolean isOrigin() { + return origin; + } - static void setOrigin(boolean origin) { - OriginConfiguratorReturningFalse.origin = origin; - } + static void setOrigin(boolean origin) { + OriginConfiguratorReturningFalse.origin = origin; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/SubprotocolsServerEndpointConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/SubprotocolsServerEndpointConfig.java index 9edfdf7de4..4d173e8bc5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/SubprotocolsServerEndpointConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/SubprotocolsServerEndpointConfig.java @@ -28,44 +28,44 @@ public class SubprotocolsServerEndpointConfig implements ServerEndpointConfig { - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return WSCSubprotocolServer.class; - } + @Override + public Class getEndpointClass() { + return WSCSubprotocolServer.class; + } - @Override - public String getPath() { - return "/subprotocols"; - } + @Override + public String getPath() { + return "/subprotocols"; + } - @Override - public List getSubprotocols() { - return WSCSubprotocolServer.getSupportedSubprotocols(); - } + @Override + public List getSubprotocols() { + return WSCSubprotocolServer.getSupportedSubprotocols(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new GetNegotiatedSubprotocolConfigurator(); - } + @Override + public Configurator getConfigurator() { + return new GetNegotiatedSubprotocolConfigurator(); + } - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + @Override + public List> getDecoders() { + return Collections.emptyList(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCClient.java deleted file mode 100644 index d80f0b47a3..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCClient.java +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.configurator; - -import java.util.Arrays; -import java.util.List; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.ExtensionImpl; -import com.sun.ts.tests.websocket.common.util.StringUtil; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.Extension; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSCClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 3657966075180214792L; - - public WSCClient() { - setContextRoot( - "wsc_ee_jakarta_websocket_server_serverendpointconfig_configurator_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* Run test */ - - /* - * @testName: checkOriginTest - * - * @assertion_ids: WebSocket:JAVADOC:205; - * - * @test_Strategy: Check the value of the Origin header (See Origin Header) - * the client passed during the opening handshake. - */ - public void checkOriginTest() throws Exception { - invoke("origin", "reset", ""); - - // invoke("origin", "get", _hostname); - // RFC-6455 section 1.3 [1] text that states: - // "This header field is sent by browser clients; for non-browser - // clients, this header field may be sent if it makes sense in the - // context of those clients." - - invoke("origin", "get", "", false); - String origin = getResponseAsString(); - assertTrue( - OriginConfigurator.NULL.equals(origin) || origin.contains(_hostname), - "Unexpected origin received", origin); - } - - /* - * @testName: checkOriginReturnsFalseTest - * - * @assertion_ids: WebSocket:JAVADOC:205; WebSocket:SPEC:WSC-3.1.4-1; - * - * @test_Strategy: Check the value of the Origin header (See Origin Header) - * the client passed during the opening handshake. - */ - public void checkOriginReturnsFalseTest() throws Exception { - // set false - invoke("originreturnsfalseconfig", "false", "false"); - // check false - setProperty(Property.REQUEST, buildRequest("originreturnsfalse")); - setProperty(Property.CONTENT, "anything"); - try { - logExceptionOnInvoke = false; - invoke(); - fault("First attempt for handshake should return false due to origin"); - } catch (Exception e) { - // that's all right - logMsg("thrown exception as expected when checkOrigin == false"); - } - // set true - invoke("originreturnsfalseconfig", "true", "true"); - // check true - invoke("originreturnsfalse", "anything", "anything"); - } - - /* - * @testName: getEndpointInstanceTest - * - * @assertion_ids: WebSocket:JAVADOC:206; WebSocket:SPEC:WSC-3.1.7-1; - * WebSocket:SPEC:WSC-3.1.7-2; - * - * @test_Strategy: This method is called by the container each time a new - * client connects to the logical endpoint this configurator configures. - * Developers may override this method to control instantiation of endpoint - * instances in order to customize the initialization of the endpoint - * instance, or manage them in some other way. The platform default - * implementation of this method returns a new endpoint instance per call, - * thereby ensuring that there is one endpoint instance per client. - * - * The implementation must call this method each time a new client connects to - * the logical endpoint. - * - * The platform default implementation of this method is to return a new - * instance of the endpoint class each time it is called - */ - public void getEndpointInstanceTest() throws Exception { - String search = WSCGetEndpointInstanceServer.class.getName() - + GetEndpointInstanceConfigurator.ADDITIONAL_INFORMATION; - // first request sets instance to null - invoke("endpointinstance", "anything", search); - // make sure second request does not have instance null - invoke("endpointinstance", "anything", search); - } - - /* - * @testName: getNegotiatedExtensionsRequestedTest - * - * @assertion_ids: WebSocket:JAVADOC:208; WebSocket:JAVADOC:195; - * WebSocket:JAVADOC:13; WebSocket:JAVADOC:211; WebSocket:JAVADOC:73; - * WebSocket:JAVADOC:74; WebSocket:JAVADOC:75; WebSocket:JAVADOC:76; - * - * @test_Strategy: what we send is what we receive - * ServerEndpointConfig.Configurator.getNegotiatedExtensions - * ServerEndpointConfig.getExtensions ClientEndpointConfig.Builder.extensions - * ServerEndpointConfig.Configurator.Configurator() - * Extension.{getName,getParameters} Extension.Parameter.{getName,getValue} - */ - @SuppressWarnings("unchecked") - public void getNegotiatedExtensionsRequestedTest() throws Exception { - List extensions = WSCExtensionsServer - .getRequestedExtension(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .extensions((List) extensions).build(); - setClientEndpointConfig(config); - invoke("extensions", "requested", ExtensionImpl.toString(extensions)); - } - - /* - * @testName: getNegotiatedExtensionsInstalledTest - * - * @assertion_ids: WebSocket:JAVADOC:208; WebSocket:JAVADOC:195; - * WebSocket:JAVADOC:13; WebSocket:JAVADOC:211; WebSocket:JAVADOC:73; - * WebSocket:JAVADOC:74; WebSocket:JAVADOC:75; WebSocket:JAVADOC:76; - * - * @test_Strategy: check installed is what ServerEndpoint gets us - * ServerEndpointConfig.Configurator.getNegotiatedExtensions - * ServerEndpointConfig.getExtensions ClientEndpointConfig.Builder.extensions - * ServerEndpointConfig.Configurator.Configurator() - * Extension.{getName,getParameters} Extension.Parameter.{getName,getValue} - */ - @SuppressWarnings("unchecked") - public void getNegotiatedExtensionsInstalledTest() throws Exception { - List extensions = WSCExtensionsServer - .getRequestedExtension(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .extensions((List) extensions).build(); - setClientEndpointConfig(config); - - // order must be kept, no need to sort - List installed = new ExtensionsServerEndpointConfig().getExtensions(); - String search = ExtensionImpl.toString(installed); - // There may be container provided extensions added to the end of the list. - // Therefore remove the closing '}'. Leaving the opening '{' as that ensures - // that the extensions configured by the application appear first. - search = search.substring(0, search.length() - 1); - invoke("extensions", "installed", search); - } - - /* - * @testName: getNegotiatedExtensionsResultedTest - * - * @assertion_ids: WebSocket:JAVADOC:208; WebSocket:JAVADOC:195; - * WebSocket:JAVADOC:13; WebSocket:JAVADOC:211; WebSocket:JAVADOC:73; - * WebSocket:JAVADOC:74; WebSocket:JAVADOC:75; WebSocket:JAVADOC:76; - * WebSocket:SPEC:WSC-3.1.3-1; WebSocket:SPEC:WSC-3.2.2-1; - * - * @test_Strategy: check the resulted extensions - * ServerEndpointConfig.Configurator.getNegotiatedExtensions - * ServerEndpointConfig.getExtensions ClientEndpointConfig.Builder.extensions - * ServerEndpointConfig.Configurator.Configurator() - * Extension.{getName,getParameters} Extension.Parameter.{getName,getValue} - * - * The default client configuration must use the developer provided list of - * extensions to send, in order of preference, the extensions, including - * parameters, that it would like to use in the opening handshake it - * formulates. - */ - @SuppressWarnings("unchecked") - public void getNegotiatedExtensionsResultedTest() throws Exception { - List extensions = WSCExtensionsServer - .getRequestedExtension(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .extensions((List) extensions).build(); - setClientEndpointConfig(config); - invoke("extensions", "resulted", ExtensionImpl.toString(extensions)); - } - - /* - * @testName: getNegotiatedExtensionsOrderedByRequestTest - * - * @assertion_ids: WebSocket:JAVADOC:208; WebSocket:JAVADOC:195; - * WebSocket:JAVADOC:13; WebSocket:JAVADOC:211; WebSocket:JAVADOC:73; - * WebSocket:JAVADOC:74; WebSocket:JAVADOC:75; WebSocket:JAVADOC:76; - * WebSocket:SPEC:WSC-3.1.3-1; WebSocket:SPEC:WSC-3.2.2-1; - * - * @test_Strategy: check the resulted extensions - * ServerEndpointConfig.Configurator.getNegotiatedExtensions The default - * platform implementation of this method returns a list containing all of the - * requested extensions passed to this method that it supports, using the - * order in the requested extensions ServerEndpointConfig.getExtensions - * ClientEndpointConfig.Builder.extensions - * ServerEndpointConfig.Configurator.Configurator() - * Extension.{getName,getParameters} Extension.Parameter.{getName,getValue} - * - * The default client configuration must use the developer provided list of - * extensions to send, in order of preference, the extensions, including - * parameters, that it would like to use in the opening handshake it - * formulates. - */ - @SuppressWarnings("unchecked") - public void getNegotiatedExtensionsOrderedByRequestTest() throws Exception { - List extensions = WSCExtensionsServer - .getOrderedExtensions(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .extensions((List) extensions).build(); - setClientEndpointConfig(config); - invoke("extensions", "resultedinorder", ExtensionImpl.toString(extensions)); - } - - /* - * @testName: getNegotiatedSubprotocolRequestedTest - * - * @assertion_ids: WebSocket:JAVADOC:209; WebSocket:JAVADOC:197; - * WebSocket:JAVADOC:14; WebSocket:JAVADOC:211; - * - * @test_Strategy: ServerEndpointConfig.Configurator.getNegotiatedSubprotocol - * ServerEndpointConfig.getSubprotocols - * ClientEndpointConfig.Builder.preferredSubprotocols - * ServerEndpointConfig.Configurator.Configurator() - */ - public void getNegotiatedSubprotocolRequestedTest() throws Exception { - List subprotocols = WSCSubprotocolServer.getRequestedSubprotocols(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(subprotocols).build(); - setClientEndpointConfig(config); - invoke("subprotocols", "requested", - StringUtil.collectionToString(subprotocols)); - } - - /* - * @testName: getNegotiatedSubprotocolSupportedTest - * - * @assertion_ids: WebSocket:JAVADOC:209; WebSocket:JAVADOC:197; - * WebSocket:JAVADOC:14; WebSocket:JAVADOC:211; - * - * @test_Strategy: ServerEndpointConfig.Configurator.getNegotiatedSubprotocol - * ServerEndpointConfig.getSubprotocols - * ClientEndpointConfig.Builder.preferredSubprotocols - * ServerEndpointConfig.Configurator.Configurator() - */ - public void getNegotiatedSubprotocolSupportedTest() throws Exception { - List subprotocols = WSCSubprotocolServer.getRequestedSubprotocols(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(subprotocols).build(); - setClientEndpointConfig(config); - invoke("subprotocols", "supported", StringUtil - .collectionToString(WSCSubprotocolServer.getSupportedSubprotocols())); - } - - /* - * @testName: getNegotiatedSubprotocolResultedTest - * - * @assertion_ids: WebSocket:JAVADOC:209; WebSocket:JAVADOC:197; - * WebSocket:JAVADOC:14; WebSocket:JAVADOC:211; WebSocket:SPEC:WSC-3.1.2-1; - * WebSocket:SPEC:WSC-3.2.1-1; - * - * @test_Strategy: ServerEndpointConfig.Configurator.getNegotiatedSubprotocol - * ServerEndpointConfig.getSubprotocols - * ClientEndpointConfig.Builder.preferredSubprotocols - * ServerEndpointConfig.Configurator.Configurator() - * - * The default platform implementation of this method returns the FIRST - * subprotocol in the list sent by the CLIENT that the server supports, - * - * The default client configuration uses the developer provided list of - * subprotocols, to send in order of preference, the names of the subprotocols - * it would like to use in the opening handshake it formulates - */ - public void getNegotiatedSubprotocolResultedTest() throws Exception { - List subprotocols = WSCSubprotocolServer.getRequestedSubprotocols(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .preferredSubprotocols(subprotocols).build(); - setClientEndpointConfig(config); - invoke("subprotocols", "resulted", StringUtil.WEBSOCKET_SUBPROTOCOLS[2]); - } - - /* - * @testName: getNegotiatedSubprotocolResultedIsEmptyTest - * - * @assertion_ids: WebSocket:JAVADOC:209; WebSocket:JAVADOC:197; - * WebSocket:JAVADOC:14; WebSocket:JAVADOC:211; WebSocket:SPEC:WSC-3.1.2-1; - * WebSocket:SPEC:WSC-3.2.1-1; - * - * @test_Strategy: ServerEndpointConfig.Configurator.getNegotiatedSubprotocol - * ServerEndpointConfig.getSubprotocols - * ClientEndpointConfig.Builder.preferredSubprotocols - * ServerEndpointConfig.Configurator.Configurator() - * - * Returns: the empty string if there isn't one. - * - * The default client configuration uses the developer provided list of - * subprotocols, to send in order of preference, the names of the subprotocols - * it would like to use in the opening handshake it formulates - */ - public void getNegotiatedSubprotocolResultedIsEmptyTest() throws Exception { - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .preferredSubprotocols( - Arrays.asList(StringUtil.WEBSOCKET_SUBPROTOCOLS[6])) - .build(); - setClientEndpointConfig(config); - invoke("subprotocols", "resulted", "{}"); - } - - /* - * @testName: modifyHandshakeAfterCheckOriginTest - * - * @assertion_ids: WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-3.1.5-1; - * - * @test_Strategy: ServerEndpointConfig.Configurator.modifyHandhsake - * - * The container has already determined the validity of the origin using the - * checkOrigin method. - * - * The default server configuration makes no modification of the opening - * handshake process other than that described above - */ - public void modifyHandshakeAfterCheckOriginTest() throws Exception { - invoke("modifyhandshake", "origin", "true"); - } - - /* - * @testName: modifyHandshakeConfigTest - * - * @assertion_ids: WebSocket:JAVADOC:210; - * - * @test_Strategy: ServerEndpointConfig.Configurator.modifyHandhsake - */ - public void modifyHandshakeConfigTest() throws Exception { - invoke("modifyhandshake", "config", "true"); - } - - /* - * @testName: modifyHandshakeRequestTest - * - * @assertion_ids: WebSocket:JAVADOC:210; - * - * @test_Strategy: ServerEndpointConfig.Configurator.modifyHandhsake - */ - public void modifyHandshakeRequestTest() throws Exception { - invoke("modifyhandshake", "request", "true"); - } - - /* - * @testName: modifyHandshakeResponseTest - * - * @assertion_ids: WebSocket:JAVADOC:210; - * - * @test_Strategy: ServerEndpointConfig.Configurator.modifyHandhsake - */ - public void modifyHandshakeResponseTest() throws Exception { - invoke("modifyhandshake", "response", "true"); - } - /* - * @testName: getContainerDefaultConfiguratorTest - * - * @assertion_ids: - * - * @test_Strategy: Obtain the container default configurator from two separate - * endpoints and check that the same object is ontained. - */ - - public void getContainerDefaultConfiguratorTest() throws Exception { - invoke("containerdefaultconfiguratorA", "anything", ""); - String containerdefaultconfiguratorIdA = getResponseAsString(); - - invoke("containerdefaultconfiguratorB", "anything", ""); - String containerdefaultconfiguratorIdB = getResponseAsString(); - - assertEquals(containerdefaultconfiguratorIdA, containerdefaultconfiguratorIdB, - "Different instances returned for container default configurator"); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCClientIT.java new file mode 100644 index 0000000000..710660961f --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCClientIT.java @@ -0,0 +1,432 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.configurator; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.ExtensionImpl; +import com.sun.ts.tests.websocket.common.impl.ExtensionParameterImpl; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.common.util.StringUtil; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.Extension; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 3657966075180214792L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_ee_jakarta_websocket_server_serverendpointconfig_configurator_web.war"); + archive.addPackages(true, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.server.serverendpointconfig.configurator"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class, StringUtil.class); + archive.addClasses(ExtensionImpl.class, ExtensionParameterImpl.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_jakarta_websocket_server_serverendpointconfig_configurator_web"); + } + + /* Run test */ + + /* + * @testName: checkOriginTest + * + * @assertion_ids: WebSocket:JAVADOC:205; + * + * @test_Strategy: Check the value of the Origin header (See Origin Header) the + * client passed during the opening handshake. + */ + @Test + public void checkOriginTest() throws Exception { + invoke("origin", "reset", ""); + + // invoke("origin", "get", _hostname); + // RFC-6455 section 1.3 [1] text that states: + // "This header field is sent by browser clients; for non-browser + // clients, this header field may be sent if it makes sense in the + // context of those clients." + + invoke("origin", "get", "", false); + String origin = getResponseAsString(); + assertTrue(OriginConfigurator.NULL.equals(origin) || origin.contains(_hostname), "Unexpected origin received", + origin); + } + + /* + * @testName: checkOriginReturnsFalseTest + * + * @assertion_ids: WebSocket:JAVADOC:205; WebSocket:SPEC:WSC-3.1.4-1; + * + * @test_Strategy: Check the value of the Origin header (See Origin Header) the + * client passed during the opening handshake. + */ + @Test + public void checkOriginReturnsFalseTest() throws Exception { + // set false + invoke("originreturnsfalseconfig", "false", "false"); + // check false + setProperty(Property.REQUEST, buildRequest("originreturnsfalse")); + setProperty(Property.CONTENT, "anything"); + try { + logExceptionOnInvoke = false; + invoke(); + new Exception("First attempt for handshake should return false due to origin"); + } catch (Exception e) { + // that's all right + logMsg("thrown exception as expected when checkOrigin == false"); + } + // set true + invoke("originreturnsfalseconfig", "true", "true"); + // check true + invoke("originreturnsfalse", "anything", "anything"); + } + + /* + * @testName: getEndpointInstanceTest + * + * @assertion_ids: WebSocket:JAVADOC:206; WebSocket:SPEC:WSC-3.1.7-1; + * WebSocket:SPEC:WSC-3.1.7-2; + * + * @test_Strategy: This method is called by the container each time a new client + * connects to the logical endpoint this configurator configures. Developers may + * override this method to control instantiation of endpoint instances in order + * to customize the initialization of the endpoint instance, or manage them in + * some other way. The platform default implementation of this method returns a + * new endpoint instance per call, thereby ensuring that there is one endpoint + * instance per client. + * + * The implementation must call this method each time a new client connects to + * the logical endpoint. + * + * The platform default implementation of this method is to return a new + * instance of the endpoint class each time it is called + */ + @Test + public void getEndpointInstanceTest() throws Exception { + String search = WSCGetEndpointInstanceServer.class.getName() + + GetEndpointInstanceConfigurator.ADDITIONAL_INFORMATION; + // first request sets instance to null + invoke("endpointinstance", "anything", search); + // make sure second request does not have instance null + invoke("endpointinstance", "anything", search); + } + + /* + * @testName: getNegotiatedExtensionsRequestedTest + * + * @assertion_ids: WebSocket:JAVADOC:208; WebSocket:JAVADOC:195; + * WebSocket:JAVADOC:13; WebSocket:JAVADOC:211; WebSocket:JAVADOC:73; + * WebSocket:JAVADOC:74; WebSocket:JAVADOC:75; WebSocket:JAVADOC:76; + * + * @test_Strategy: what we send is what we receive + * ServerEndpointConfig.Configurator.getNegotiatedExtensions + * ServerEndpointConfig.getExtensions ClientEndpointConfig.Builder.extensions + * ServerEndpointConfig.Configurator.Configurator() + * Extension.{getName,getParameters} Extension.Parameter.{getName,getValue} + */ + @SuppressWarnings("unchecked") + @Test + public void getNegotiatedExtensionsRequestedTest() throws Exception { + List extensions = WSCExtensionsServer.getRequestedExtension(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().extensions((List) extensions) + .build(); + setClientEndpointConfig(config); + invoke("extensions", "requested", ExtensionImpl.toString(extensions)); + } + + /* + * @testName: getNegotiatedExtensionsInstalledTest + * + * @assertion_ids: WebSocket:JAVADOC:208; WebSocket:JAVADOC:195; + * WebSocket:JAVADOC:13; WebSocket:JAVADOC:211; WebSocket:JAVADOC:73; + * WebSocket:JAVADOC:74; WebSocket:JAVADOC:75; WebSocket:JAVADOC:76; + * + * @test_Strategy: check installed is what ServerEndpoint gets us + * ServerEndpointConfig.Configurator.getNegotiatedExtensions + * ServerEndpointConfig.getExtensions ClientEndpointConfig.Builder.extensions + * ServerEndpointConfig.Configurator.Configurator() + * Extension.{getName,getParameters} Extension.Parameter.{getName,getValue} + */ + @SuppressWarnings("unchecked") + @Test + public void getNegotiatedExtensionsInstalledTest() throws Exception { + List extensions = WSCExtensionsServer.getRequestedExtension(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().extensions((List) extensions) + .build(); + setClientEndpointConfig(config); + + // order must be kept, no need to sort + List installed = new ExtensionsServerEndpointConfig().getExtensions(); + String search = ExtensionImpl.toString(installed); + // There may be container provided extensions added to the end of the list. + // Therefore remove the closing '}'. Leaving the opening '{' as that ensures + // that the extensions configured by the application appear first. + search = search.substring(0, search.length() - 1); + invoke("extensions", "installed", search); + } + + /* + * @testName: getNegotiatedExtensionsResultedTest + * + * @assertion_ids: WebSocket:JAVADOC:208; WebSocket:JAVADOC:195; + * WebSocket:JAVADOC:13; WebSocket:JAVADOC:211; WebSocket:JAVADOC:73; + * WebSocket:JAVADOC:74; WebSocket:JAVADOC:75; WebSocket:JAVADOC:76; + * WebSocket:SPEC:WSC-3.1.3-1; WebSocket:SPEC:WSC-3.2.2-1; + * + * @test_Strategy: check the resulted extensions + * ServerEndpointConfig.Configurator.getNegotiatedExtensions + * ServerEndpointConfig.getExtensions ClientEndpointConfig.Builder.extensions + * ServerEndpointConfig.Configurator.Configurator() + * Extension.{getName,getParameters} Extension.Parameter.{getName,getValue} + * + * The default client configuration must use the developer provided list of + * extensions to send, in order of preference, the extensions, including + * parameters, that it would like to use in the opening handshake it formulates. + */ + @SuppressWarnings("unchecked") + @Test + public void getNegotiatedExtensionsResultedTest() throws Exception { + List extensions = WSCExtensionsServer.getRequestedExtension(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().extensions((List) extensions) + .build(); + setClientEndpointConfig(config); + invoke("extensions", "resulted", ExtensionImpl.toString(extensions)); + } + + /* + * @testName: getNegotiatedExtensionsOrderedByRequestTest + * + * @assertion_ids: WebSocket:JAVADOC:208; WebSocket:JAVADOC:195; + * WebSocket:JAVADOC:13; WebSocket:JAVADOC:211; WebSocket:JAVADOC:73; + * WebSocket:JAVADOC:74; WebSocket:JAVADOC:75; WebSocket:JAVADOC:76; + * WebSocket:SPEC:WSC-3.1.3-1; WebSocket:SPEC:WSC-3.2.2-1; + * + * @test_Strategy: check the resulted extensions + * ServerEndpointConfig.Configurator.getNegotiatedExtensions The default + * platform implementation of this method returns a list containing all of the + * requested extensions passed to this method that it supports, using the order + * in the requested extensions ServerEndpointConfig.getExtensions + * ClientEndpointConfig.Builder.extensions + * ServerEndpointConfig.Configurator.Configurator() + * Extension.{getName,getParameters} Extension.Parameter.{getName,getValue} + * + * The default client configuration must use the developer provided list of + * extensions to send, in order of preference, the extensions, including + * parameters, that it would like to use in the opening handshake it formulates. + */ + @SuppressWarnings("unchecked") + @Test + public void getNegotiatedExtensionsOrderedByRequestTest() throws Exception { + List extensions = WSCExtensionsServer.getOrderedExtensions(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().extensions((List) extensions) + .build(); + setClientEndpointConfig(config); + invoke("extensions", "resultedinorder", ExtensionImpl.toString(extensions)); + } + + /* + * @testName: getNegotiatedSubprotocolRequestedTest + * + * @assertion_ids: WebSocket:JAVADOC:209; WebSocket:JAVADOC:197; + * WebSocket:JAVADOC:14; WebSocket:JAVADOC:211; + * + * @test_Strategy: ServerEndpointConfig.Configurator.getNegotiatedSubprotocol + * ServerEndpointConfig.getSubprotocols + * ClientEndpointConfig.Builder.preferredSubprotocols + * ServerEndpointConfig.Configurator.Configurator() + */ + @Test + public void getNegotiatedSubprotocolRequestedTest() throws Exception { + List subprotocols = WSCSubprotocolServer.getRequestedSubprotocols(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().preferredSubprotocols(subprotocols).build(); + setClientEndpointConfig(config); + invoke("subprotocols", "requested", StringUtil.collectionToString(subprotocols)); + } + + /* + * @testName: getNegotiatedSubprotocolSupportedTest + * + * @assertion_ids: WebSocket:JAVADOC:209; WebSocket:JAVADOC:197; + * WebSocket:JAVADOC:14; WebSocket:JAVADOC:211; + * + * @test_Strategy: ServerEndpointConfig.Configurator.getNegotiatedSubprotocol + * ServerEndpointConfig.getSubprotocols + * ClientEndpointConfig.Builder.preferredSubprotocols + * ServerEndpointConfig.Configurator.Configurator() + */ + @Test + public void getNegotiatedSubprotocolSupportedTest() throws Exception { + List subprotocols = WSCSubprotocolServer.getRequestedSubprotocols(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().preferredSubprotocols(subprotocols).build(); + setClientEndpointConfig(config); + invoke("subprotocols", "supported", + StringUtil.collectionToString(WSCSubprotocolServer.getSupportedSubprotocols())); + } + + /* + * @testName: getNegotiatedSubprotocolResultedTest + * + * @assertion_ids: WebSocket:JAVADOC:209; WebSocket:JAVADOC:197; + * WebSocket:JAVADOC:14; WebSocket:JAVADOC:211; WebSocket:SPEC:WSC-3.1.2-1; + * WebSocket:SPEC:WSC-3.2.1-1; + * + * @test_Strategy: ServerEndpointConfig.Configurator.getNegotiatedSubprotocol + * ServerEndpointConfig.getSubprotocols + * ClientEndpointConfig.Builder.preferredSubprotocols + * ServerEndpointConfig.Configurator.Configurator() + * + * The default platform implementation of this method returns the FIRST + * subprotocol in the list sent by the CLIENT that the server supports, + * + * The default client configuration uses the developer provided list of + * subprotocols, to send in order of preference, the names of the subprotocols + * it would like to use in the opening handshake it formulates + */ + @Test + public void getNegotiatedSubprotocolResultedTest() throws Exception { + List subprotocols = WSCSubprotocolServer.getRequestedSubprotocols(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().preferredSubprotocols(subprotocols).build(); + setClientEndpointConfig(config); + invoke("subprotocols", "resulted", StringUtil.WEBSOCKET_SUBPROTOCOLS[2]); + } + + /* + * @testName: getNegotiatedSubprotocolResultedIsEmptyTest + * + * @assertion_ids: WebSocket:JAVADOC:209; WebSocket:JAVADOC:197; + * WebSocket:JAVADOC:14; WebSocket:JAVADOC:211; WebSocket:SPEC:WSC-3.1.2-1; + * WebSocket:SPEC:WSC-3.2.1-1; + * + * @test_Strategy: ServerEndpointConfig.Configurator.getNegotiatedSubprotocol + * ServerEndpointConfig.getSubprotocols + * ClientEndpointConfig.Builder.preferredSubprotocols + * ServerEndpointConfig.Configurator.Configurator() + * + * Returns: the empty string if there isn't one. + * + * The default client configuration uses the developer provided list of + * subprotocols, to send in order of preference, the names of the subprotocols + * it would like to use in the opening handshake it formulates + */ + @Test + public void getNegotiatedSubprotocolResultedIsEmptyTest() throws Exception { + ClientEndpointConfig config = ClientEndpointConfig.Builder.create() + .preferredSubprotocols(Arrays.asList(StringUtil.WEBSOCKET_SUBPROTOCOLS[6])).build(); + setClientEndpointConfig(config); + invoke("subprotocols", "resulted", "{}"); + } + + /* + * @testName: modifyHandshakeAfterCheckOriginTest + * + * @assertion_ids: WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-3.1.5-1; + * + * @test_Strategy: ServerEndpointConfig.Configurator.modifyHandhsake + * + * The container has already determined the validity of the origin using the + * checkOrigin method. + * + * The default server configuration makes no modification of the opening + * handshake process other than that described above + */ + @Test + public void modifyHandshakeAfterCheckOriginTest() throws Exception { + invoke("modifyhandshake", "origin", "true"); + } + + /* + * @testName: modifyHandshakeConfigTest + * + * @assertion_ids: WebSocket:JAVADOC:210; + * + * @test_Strategy: ServerEndpointConfig.Configurator.modifyHandhsake + */ + @Test + public void modifyHandshakeConfigTest() throws Exception { + invoke("modifyhandshake", "config", "true"); + } + + /* + * @testName: modifyHandshakeRequestTest + * + * @assertion_ids: WebSocket:JAVADOC:210; + * + * @test_Strategy: ServerEndpointConfig.Configurator.modifyHandhsake + */ + @Test + public void modifyHandshakeRequestTest() throws Exception { + invoke("modifyhandshake", "request", "true"); + } + + /* + * @testName: modifyHandshakeResponseTest + * + * @assertion_ids: WebSocket:JAVADOC:210; + * + * @test_Strategy: ServerEndpointConfig.Configurator.modifyHandhsake + */ + @Test + public void modifyHandshakeResponseTest() throws Exception { + invoke("modifyhandshake", "response", "true"); + } + + /* + * @testName: getContainerDefaultConfiguratorTest + * + * @assertion_ids: + * + * @test_Strategy: Obtain the container default configurator from two separate + * endpoints and check that the same object is ontained. + */ + @Test + public void getContainerDefaultConfiguratorTest() throws Exception { + invoke("containerdefaultconfiguratorA", "anything", ""); + String containerdefaultconfiguratorIdA = getResponseAsString(); + + invoke("containerdefaultconfiguratorB", "anything", ""); + String containerdefaultconfiguratorIdB = getResponseAsString(); + + assertEquals(containerdefaultconfiguratorIdA, containerdefaultconfiguratorIdB, + "Different instances returned for container default configurator"); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCExtensionsServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCExtensionsServer.java index 428a78a611..dddc045fec 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCExtensionsServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCExtensionsServer.java @@ -38,97 +38,86 @@ * within Extension. Also, the serialization and deserialization would not help * the search of sublist, here we can use StringUtil.contains */ -public class WSCExtensionsServer extends Endpoint - implements MessageHandler.Whole { +public class WSCExtensionsServer extends Endpoint implements MessageHandler.Whole { - Session session; + Session session; - ServerEndpointConfig config; + ServerEndpointConfig config; - @Override - public void onMessage(String msg) { - boolean contains = false; - List response = null; - try { - if (msg.equals("requested")) { - contains = StringUtil.contains(ExtensionsConfigurator.getRequested(), - getRequestedExtension()); - response = contains ? getRequestedExtension() - : ExtensionsConfigurator.getRequested(); - } else if (msg.equals("resulted")) { - contains = StringUtil.contains(ExtensionsConfigurator.getResulted(), - getRequestedExtension()); - response = contains ? getRequestedExtension() - : ExtensionsConfigurator.getResulted(); - } else if (msg.equals("installed")) { - List configured = ExtensionImpl - .transformToImpl(config.getExtensions()); - contains = StringUtil.contains(ExtensionsConfigurator.getInstalled(), - configured); - response = contains ? ExtensionsConfigurator.getInstalled() - : configured; - } else if (msg.equals("resultedinorder")) { - contains = StringUtil.containsInOrder( - ExtensionsConfigurator.getResulted(), getOrderedExtensions()); - response = contains ? getOrderedExtensions() - : ExtensionsConfigurator.getResulted(); - } - session.getBasicRemote().sendText(ExtensionImpl.toString(response)); - } catch (IOException e) { - e.printStackTrace(); - try { - session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } + @Override + public void onMessage(String msg) { + boolean contains = false; + List response = null; + try { + if (msg.equals("requested")) { + contains = StringUtil.contains(ExtensionsConfigurator.getRequested(), getRequestedExtension()); + response = contains ? getRequestedExtension() : ExtensionsConfigurator.getRequested(); + } else if (msg.equals("resulted")) { + contains = StringUtil.contains(ExtensionsConfigurator.getResulted(), getRequestedExtension()); + response = contains ? getRequestedExtension() : ExtensionsConfigurator.getResulted(); + } else if (msg.equals("installed")) { + List configured = ExtensionImpl.transformToImpl(config.getExtensions()); + contains = StringUtil.contains(ExtensionsConfigurator.getInstalled(), configured); + response = contains ? ExtensionsConfigurator.getInstalled() : configured; + } else if (msg.equals("resultedinorder")) { + contains = StringUtil.containsInOrder(ExtensionsConfigurator.getResulted(), getOrderedExtensions()); + response = contains ? getOrderedExtensions() : ExtensionsConfigurator.getResulted(); + } + session.getBasicRemote().sendText(ExtensionImpl.toString(response)); + } catch (IOException e) { + e.printStackTrace(); + try { + session.getBasicRemote().sendText(IOUtil.printStackTrace(e)); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - this.config = (ServerEndpointConfig) config; - session.addMessageHandler(this); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + this.config = (ServerEndpointConfig) config; + session.addMessageHandler(this); + } - @Override - public void onError(Session session, Throwable thr) { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } + @Override + public void onError(Session session, Throwable thr) { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } - public static List getRequestedExtension() { - Extension.Parameter firstParam = ExtensionsServerEndpointConfig.PARAMETER[0]; - Extension.Parameter secondParam = ExtensionsServerEndpointConfig.PARAMETER[1]; - ExtensionImpl extension = new ExtensionImpl( - ExtensionsServerEndpointConfig.EXT_NAMES[0], firstParam, secondParam); - List list = new ArrayList<>(); - list.add(extension); - return list; - } + public static List getRequestedExtension() { + Extension.Parameter firstParam = ExtensionsServerEndpointConfig.PARAMETER[0]; + Extension.Parameter secondParam = ExtensionsServerEndpointConfig.PARAMETER[1]; + ExtensionImpl extension = new ExtensionImpl(ExtensionsServerEndpointConfig.EXT_NAMES[0], firstParam, + secondParam); + List list = new ArrayList<>(); + list.add(extension); + return list; + } - public static List getOrderedExtensions() { - Extension.Parameter firstParam = ExtensionsServerEndpointConfig.PARAMETER[0]; - Extension.Parameter secondParam = ExtensionsServerEndpointConfig.PARAMETER[1]; - ExtensionImpl extension = new ExtensionImpl( - ExtensionsServerEndpointConfig.EXT_NAMES[1], firstParam, secondParam); - List list = new ArrayList<>(); - list.add(extension); - list.add(getRequestedExtension().iterator().next()); - return list; - } + public static List getOrderedExtensions() { + Extension.Parameter firstParam = ExtensionsServerEndpointConfig.PARAMETER[0]; + Extension.Parameter secondParam = ExtensionsServerEndpointConfig.PARAMETER[1]; + ExtensionImpl extension = new ExtensionImpl(ExtensionsServerEndpointConfig.EXT_NAMES[1], firstParam, + secondParam); + List list = new ArrayList<>(); + list.add(extension); + list.add(getRequestedExtension().iterator().next()); + return list; + } - public static List getNotNegotiableExtension() { - Extension.Parameter secondParam = new ExtensionParameterImpl("thirdName", - "thirdValue"); - List list = getRequestedExtension(); - list.iterator().next().addParameters(secondParam); - return list; - } + public static List getNotNegotiableExtension() { + Extension.Parameter secondParam = new ExtensionParameterImpl("thirdName", "thirdValue"); + List list = getRequestedExtension(); + list.iterator().next().addParameters(secondParam); + return list; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetContainerDefaultConfiguratorServerA.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetContainerDefaultConfiguratorServerA.java index b0976d26aa..0c2cf935df 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetContainerDefaultConfiguratorServerA.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetContainerDefaultConfiguratorServerA.java @@ -17,27 +17,27 @@ import java.io.IOException; +import com.sun.ts.tests.websocket.common.util.IOUtil; + import jakarta.websocket.OnError; import jakarta.websocket.OnMessage; import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -import com.sun.ts.tests.websocket.common.util.IOUtil; - @ServerEndpoint(value = "/containerdefaultconfiguratorA", configurator = ContainerDefaultConfiguratorA.class) public class WSCGetContainerDefaultConfiguratorServerA { - @SuppressWarnings("unused") - @OnMessage - public String onMessage(String msg) { - String response = ContainerDefaultConfiguratorA.getPlatformDefaultConfiguratorID(); - return response; - } + @SuppressWarnings("unused") + @OnMessage + public String onMessage(String msg) { + String response = ContainerDefaultConfiguratorA.getPlatformDefaultConfiguratorID(); + return response; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetContainerDefaultConfiguratorServerB.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetContainerDefaultConfiguratorServerB.java index 6b7236e5a8..07606a0f4d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetContainerDefaultConfiguratorServerB.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetContainerDefaultConfiguratorServerB.java @@ -17,27 +17,27 @@ import java.io.IOException; +import com.sun.ts.tests.websocket.common.util.IOUtil; + import jakarta.websocket.OnError; import jakarta.websocket.OnMessage; import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -import com.sun.ts.tests.websocket.common.util.IOUtil; - @ServerEndpoint(value = "/containerdefaultconfiguratorB", configurator = ContainerDefaultConfiguratorB.class) public class WSCGetContainerDefaultConfiguratorServerB { - @SuppressWarnings("unused") - @OnMessage - public String onMessage(String msg) { - String response = ContainerDefaultConfiguratorB.getPlatformDefaultConfiguratorID(); - return response; - } + @SuppressWarnings("unused") + @OnMessage + public String onMessage(String msg) { + String response = ContainerDefaultConfiguratorB.getPlatformDefaultConfiguratorID(); + return response; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetEndpointInstanceServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetEndpointInstanceServer.java index 3466511d50..6c63a0af74 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetEndpointInstanceServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCGetEndpointInstanceServer.java @@ -29,29 +29,29 @@ @ServerEndpoint(value = "/endpointinstance", configurator = GetEndpointInstanceConfigurator.class) public class WSCGetEndpointInstanceServer { - public WSCGetEndpointInstanceServer() { - // default - } - - public WSCGetEndpointInstanceServer(String additionalInformation) { - this.additionalInformation = additionalInformation; - } - - String additionalInformation; - - @SuppressWarnings("unused") - @OnMessage - public String onMessage(String msg) { - String instance = GetEndpointInstanceConfigurator.getInstanceName(); - GetEndpointInstanceConfigurator.setInstanceName("null"); // rather string - return instance + additionalInformation; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + public WSCGetEndpointInstanceServer() { + // default + } + + public WSCGetEndpointInstanceServer(String additionalInformation) { + this.additionalInformation = additionalInformation; + } + + String additionalInformation; + + @SuppressWarnings("unused") + @OnMessage + public String onMessage(String msg) { + String instance = GetEndpointInstanceConfigurator.getInstanceName(); + GetEndpointInstanceConfigurator.setInstanceName("null"); // rather string + return instance + additionalInformation; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCModifyHandshakeServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCModifyHandshakeServer.java index bf6ce93161..d3f547c7db 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCModifyHandshakeServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCModifyHandshakeServer.java @@ -32,33 +32,32 @@ @ServerEndpoint(value = "/modifyhandshake", configurator = ModifyHandshakeConfigurator.class) public class WSCModifyHandshakeServer { - ServerEndpointConfig config; - - @OnMessage - public String onMessage(String msg) { - boolean ret = false; - if (msg.equals("origin")) - ret = ModifyHandshakeConfigurator.isCheckedOriginBeforeModifyHandshake(); - else if (msg.equals("config")) - ret = ModifyHandshakeConfigurator.getConfig().getClass().getName() - .equals(config.getClass().getName()); - else if (msg.equals("request")) - ret = ModifyHandshakeConfigurator.getRequest() != null; - else if (msg.equals("response")) - ret = ModifyHandshakeConfigurator.getResponse() != null; - return String.valueOf(ret); - } - - @OnOpen - public void onOpen(EndpointConfig config) { - this.config = (ServerEndpointConfig) config; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + ServerEndpointConfig config; + + @OnMessage + public String onMessage(String msg) { + boolean ret = false; + if (msg.equals("origin")) + ret = ModifyHandshakeConfigurator.isCheckedOriginBeforeModifyHandshake(); + else if (msg.equals("config")) + ret = ModifyHandshakeConfigurator.getConfig().getClass().getName().equals(config.getClass().getName()); + else if (msg.equals("request")) + ret = ModifyHandshakeConfigurator.getRequest() != null; + else if (msg.equals("response")) + ret = ModifyHandshakeConfigurator.getResponse() != null; + return String.valueOf(ret); + } + + @OnOpen + public void onOpen(EndpointConfig config) { + this.config = (ServerEndpointConfig) config; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServer.java index 0277758c3d..bea5b136b1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServer.java @@ -29,20 +29,20 @@ @ServerEndpoint(value = "/origin", configurator = OriginConfigurator.class) public class WSCOriginServer { - @OnMessage - public String onMessage(String msg) { - if (msg.equals("reset")) { - OriginConfigurator.setOrigin(""); - } else if (msg.equals("get")) - return OriginConfigurator.getOrigin(); - return ""; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String onMessage(String msg) { + if (msg.equals("reset")) { + OriginConfigurator.setOrigin(""); + } else if (msg.equals("get")) + return OriginConfigurator.getOrigin(); + return ""; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServerReturningFalse.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServerReturningFalse.java index a423b0cfe5..814f79a75b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServerReturningFalse.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServerReturningFalse.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/originreturnsfalse", configurator = OriginConfiguratorReturningFalse.class) public class WSCOriginServerReturningFalse { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServerReturningFalseConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServerReturningFalseConfigurator.java index e4fec8e2d5..f3034b70ca 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServerReturningFalseConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCOriginServerReturningFalseConfigurator.java @@ -28,17 +28,17 @@ @ServerEndpoint(value = "/originreturnsfalseconfig") public class WSCOriginServerReturningFalseConfigurator { - @OnMessage - public String onMessage(String msg) { - OriginConfiguratorReturningFalse.setOrigin(Boolean.parseBoolean(msg)); - return msg; - } + @OnMessage + public String onMessage(String msg) { + OriginConfiguratorReturningFalse.setOrigin(Boolean.parseBoolean(msg)); + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCSubprotocolServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCSubprotocolServer.java index 81fe89bcc7..c7b6c0075c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCSubprotocolServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/server/serverendpointconfig/configurator/WSCSubprotocolServer.java @@ -31,70 +31,61 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpointConfig; -public class WSCSubprotocolServer extends Endpoint - implements MessageHandler.Whole { +public class WSCSubprotocolServer extends Endpoint implements MessageHandler.Whole { - Session session; + Session session; - ServerEndpointConfig config; + ServerEndpointConfig config; - @Override - public void onMessage(String msg) { - List ret = null; - boolean contains = false; - if (msg.equals("requested")) { - contains = StringUtil.contains( - GetNegotiatedSubprotocolConfigurator.getRequested(), - getRequestedSubprotocols()); - ret = contains ? getRequestedSubprotocols() - : GetNegotiatedSubprotocolConfigurator.getRequested(); - } else if (msg.equals("supported")) { - List subprotocols = config.getSubprotocols(); - contains = StringUtil.contains( - GetNegotiatedSubprotocolConfigurator.getSupported(), subprotocols); - ret = contains ? subprotocols - : GetNegotiatedSubprotocolConfigurator.getSupported(); - } else if (msg.equals("resulted")) { - ret = Collections.singletonList( - "{" + GetNegotiatedSubprotocolConfigurator.getResulted() + "}"); - } - try { - session.getBasicRemote().sendText(StringUtil.collectionToString(ret)); - } catch (IOException e) { - e.printStackTrace(); - } - } + @Override + public void onMessage(String msg) { + List ret = null; + boolean contains = false; + if (msg.equals("requested")) { + contains = StringUtil.contains(GetNegotiatedSubprotocolConfigurator.getRequested(), + getRequestedSubprotocols()); + ret = contains ? getRequestedSubprotocols() : GetNegotiatedSubprotocolConfigurator.getRequested(); + } else if (msg.equals("supported")) { + List subprotocols = config.getSubprotocols(); + contains = StringUtil.contains(GetNegotiatedSubprotocolConfigurator.getSupported(), subprotocols); + ret = contains ? subprotocols : GetNegotiatedSubprotocolConfigurator.getSupported(); + } else if (msg.equals("resulted")) { + ret = Collections.singletonList("{" + GetNegotiatedSubprotocolConfigurator.getResulted() + "}"); + } + try { + session.getBasicRemote().sendText(StringUtil.collectionToString(ret)); + } catch (IOException e) { + e.printStackTrace(); + } + } - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - this.config = (ServerEndpointConfig) config; - session.addMessageHandler(this); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + this.config = (ServerEndpointConfig) config; + session.addMessageHandler(this); + } - @Override - public void onError(Session session, Throwable thr) { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } + @Override + public void onError(Session session, Throwable thr) { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } - public static List getRequestedSubprotocols() { - return Arrays.asList(StringUtil.WEBSOCKET_SUBPROTOCOLS[0], - StringUtil.WEBSOCKET_SUBPROTOCOLS[2], - StringUtil.WEBSOCKET_SUBPROTOCOLS[4]); - } + public static List getRequestedSubprotocols() { + return Arrays.asList(StringUtil.WEBSOCKET_SUBPROTOCOLS[0], StringUtil.WEBSOCKET_SUBPROTOCOLS[2], + StringUtil.WEBSOCKET_SUBPROTOCOLS[4]); + } - public static List getSupportedSubprotocols() { - return Arrays.asList(StringUtil.WEBSOCKET_SUBPROTOCOLS[1], - StringUtil.WEBSOCKET_SUBPROTOCOLS[3], - StringUtil.WEBSOCKET_SUBPROTOCOLS[5], - StringUtil.WEBSOCKET_SUBPROTOCOLS[4], - StringUtil.WEBSOCKET_SUBPROTOCOLS[2]); - } + public static List getSupportedSubprotocols() { + return Arrays.asList(StringUtil.WEBSOCKET_SUBPROTOCOLS[1], StringUtil.WEBSOCKET_SUBPROTOCOLS[3], + StringUtil.WEBSOCKET_SUBPROTOCOLS[5], StringUtil.WEBSOCKET_SUBPROTOCOLS[4], + StringUtil.WEBSOCKET_SUBPROTOCOLS[2]); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSClient.java deleted file mode 100644 index 191fc8a906..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSClient.java +++ /dev/null @@ -1,1995 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.session; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.net.URI; -import java.nio.ByteBuffer; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import com.sun.ts.tests.websocket.common.client.ClientEndpoint; -import com.sun.ts.tests.websocket.common.client.EndpointCallback; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.util.IOUtil; -import com.sun.ts.tests.websocket.common.util.MessageValidator; -import com.sun.ts.tests.websocket.common.util.SessionUtil; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.CloseReason; -import jakarta.websocket.ContainerProvider; -import jakarta.websocket.Endpoint; -import jakarta.websocket.EndpointConfig; -import jakarta.websocket.MessageHandler; -import jakarta.websocket.Session; -import jakarta.websocket.WebSocketContainer; - -public class WSClient extends WebSocketCommonClient { - - private static final String CONTEXT_ROOT = "/ws_session_web"; - - private static final String SENT_STRING_MESSAGE = "Hello World in String"; - - private static ByteBuffer SENT_BYTE_MESSAGE = ByteBuffer - .allocate("Hello World in ByteBuffer".getBytes().length + 1); - - private static StringBuffer receivedMessageString = new StringBuffer(); - - static volatile CountDownLatch messageLatch; - - public static void main(String[] args) { - new WSClient().run(args); - } - - public WSClient() { - setContextRoot("ws_session_web"); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; - */ - /* Run test */ - /* - * @testName: isOpenTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; - * WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void isOpenTest() throws Exception { - String testName = "isOpenTest"; - String search = "TCKTestServer opened|" - + "session from Server is open=TRUE"; - - setCountDownLatchCount(2); - setClientCallback(new TCKGetIdEndpoint()); - setProperty(Property.REQUEST, buildRequest("TCKTestServer")); - setProperty(Property.UNORDERED_SEARCH_STRING, search); - invoke(false); - - search = "TCKTestServer received String: testName=" + testName + "|" - + "session from Server is still open=TRUE"; - setProperty(Property.UNORDERED_SEARCH_STRING, search); - setProperty(Property.CONTENT, "testName=isOpenTest"); - invokeAgain(true); - } - - /* - * @testName: isOpenTest1 - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; - * WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void isOpenTest1() throws Exception { - String search = "TCKTestServer opened|" - + "session from Server is open=TRUE"; - - setCountDownLatchCount(2); - setClientCallback(new TCKGetIdEndpoint()); - setProperty(Property.REQUEST, buildRequest("TCKTestServer")); - setProperty(Property.UNORDERED_SEARCH_STRING, search); - invoke(false); - - try { - ClientEndpoint.getCountDownLatch().await(_ws_wait, TimeUnit.SECONDS); - if (!getSession().isOpen()) { - throw new Exception("Client side Session is not open"); - } - } catch (Exception ioe) { - fault(ioe); - } - invoke(true); - } - - /* - * @testName: addMessageHandlerBasicStringTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void addMessageHandlerBasicStringTest() throws Exception { - String search = "Expected IllegalStateException thrown by Second TextMessageHandler|" - + "First TextMessageHander received|" + "TCKTestServerString opened|" - + "First TextMessageHander received|" - + "TCKTestServerString received String: Hello World in String|" - + "First TextMessageHander received|" + "TCKTestServerString responds|" - + "TCKTestServerString received String: |" - + "First TextMessageHander received|" + "TCKTestServerString responds"; - setCountDownLatchCount(3); - setClientEndpoint(TCKBasicStringEndpoint.class); - setProperty(Property.REQUEST, buildRequest("TCKTestServerString")); - setProperty(Property.UNORDERED_SEARCH_STRING, search); - invoke(true); - } - - /* - * @testName: addMessageHandlerBasicByteBufferTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:105; - * WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; WebSocket:SPEC:WSC-2.1.3-1; - * WebSocket:SPEC:WSC-2.1.3-2; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void addMessageHandlerBasicByteBufferTest() throws Exception { - String search = "Expected IllegalStateException thrown by Second ByteBuffer MessageHandler|" - + "First Basic ByteBuffer MessageHander received|" - + "TCKTestServerByte opened|" - + "First Basic ByteBuffer MessageHander received|" - + "TCKTestServerByte received ByteBuffer: Hello World in ByteBuffer|" - + "TCKTestServerByte responds: Message in bytes"; - setCountDownLatchCount(2); - setClientEndpoint(TCKBasicByteEndpoint.class); - setProperty(Property.REQUEST, buildRequest("TCKTestServerByte")); - setProperty(Property.UNORDERED_SEARCH_STRING, search); - invoke(true); - } - - /* - * @testName: addMessageHandlersTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:105; - * WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; - * WebSocket:JAVADOC:134; WebSocket:JAVADOC:147; WebSocket:SPEC:WSC-2.1.3-1; - * WebSocket:SPEC:WSC-2.1.3-2; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; - * WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void addMessageHandlersTest() throws Exception { - boolean passed = true; - String message_sent_bytebuffer = "BasicByteBufferMessageHandler added"; - String message_sent_string = "BasicStringMessageHandler added"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - final Session session = clientContainer - .connectToServer(TCKBasicEndpoint.class, config, new URI("ws://" - + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - Set msgHanders = session.getMessageHandlers(); - receivedMessageString - .append("Start with MessageHandler=" + msgHanders.size()); - - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText(message_sent_string); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - ByteBuffer data = ByteBuffer - .allocate(message_sent_bytebuffer.getBytes().length); - data.put(message_sent_bytebuffer.getBytes()); - data.flip(); - messageLatch = new CountDownLatch(3); - session.getBasicRemote().sendBinary(data); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - for (MessageHandler msgHander : msgHanders) { - session.removeMessageHandler(msgHander); - receivedMessageString - .append("MessageHandler=" + session.getMessageHandlers().size()); - } - - passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" - + "TCKTestServer opened|" + "Start with MessageHandler=2|" - + "TCKTestServer received String:|" + message_sent_string + "|" - + "TCKTestServer responds, please close your session|" - + "Basic ByteBuffer MessageHander received|" - + "TCKTestServer received ByteBuffer:|" - + "Basic ByteBuffer MessageHander received|" + message_sent_bytebuffer - + "|" + "Basic ByteBuffer MessageHander received|" - + "TCKTestServer responds: Message in bytes|" + "MessageHandler=1|" - + "MessageHandler=0", receivedMessageString.toString()); - session.close(); - - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: addMessageHandlersTest1 - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:103; - * WebSocket:JAVADOC:105; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; - * WebSocket:JAVADOC:122; WebSocket:JAVADOC:134; WebSocket:JAVADOC:147; - * WebSocket:SPEC:WSC-2.1.3-1; WebSocket:SPEC:WSC-2.1.3-2; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void addMessageHandlersTest1() throws Exception { - boolean passed = true; - final String message_sent_bytebuffer = "BasicByteBufferMessageHandler added"; - final String message_sent_reader = "BasicTextReaderMessageHandler added"; - final String message_reader_msghandler = "BasicReaderMessageHander received="; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - final Session session = clientContainer - .connectToServer(TCKBasicEndpoint1.class, config, new URI("ws://" - + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); - - Set msgHanders_1 = session.getMessageHandlers(); - receivedMessageString - .append("Start with MessageHandler=" + msgHanders_1.size()); - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(Reader r) { - char[] buffer = new char[128]; - try { - int i = r.read(buffer); - receivedMessageString.append("========" + message_reader_msghandler - + new String(buffer, 0, i)); - messageLatch.countDown(); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - - messageLatch = new CountDownLatch(4); - Writer writer = session.getBasicRemote().getSendWriter(); - writer.append(message_sent_reader); - writer.close(); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - Set msgHanders_2 = session.getMessageHandlers(); - receivedMessageString - .append("Now we Have MessageHandler=" + msgHanders_2.size()); - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(ByteBuffer data) { - byte[] data1 = new byte[data.remaining()]; - data.get(data1); - receivedMessageString.append(new String(data1)); - messageLatch.countDown(); - } - }); - - ByteBuffer data = ByteBuffer - .allocate((message_sent_bytebuffer).getBytes().length); - data.put((message_sent_bytebuffer).getBytes()); - data.flip(); - messageLatch = new CountDownLatch(3); - session.getBasicRemote().sendBinary(data); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - Set msgHanders_3 = session.getMessageHandlers(); - receivedMessageString - .append("Now it is MessageHandler=" + msgHanders_3.size()); - - for (MessageHandler msgHander : msgHanders_3) { - session.removeMessageHandler(msgHander); - receivedMessageString - .append("MessageHandler=" + session.getMessageHandlers().size()); - } - - passed = MessageValidator.checkSearchStrings( - "Start with MessageHandler=0|" + message_reader_msghandler + "|" - + "TCKTestServer received String:|" + message_sent_reader + "|" - + "TCKTestServer responds, please close your session|" - + "Now we Have MessageHandler=1|" - + "TCKTestServer received ByteBuffer:|" + message_sent_bytebuffer - + "|" + "TCKTestServer responds: Message in bytes|" - + "Now it is MessageHandler=2|" + "MessageHandler=1|" - + "MessageHandler=0", - receivedMessageString.toString()); - - session.close(); - - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - - System.out.println(receivedMessageString.toString()); - - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: closeTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void closeTest() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close()"); - } - - } catch (Exception e) { - e.printStackTrace(); - passed = false; - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close1Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close1Test() throws Exception { - String testName = "close1Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.getBasicRemote().sendText("testName=" + testName); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKTestServer opened|" + "session from Server is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - passed = false; - receivedMessageString.append(e.getMessage()); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close2Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; - * WebSocket:JAVADOC:20; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close2Test() throws Exception { - String testName = "close2Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.getBasicRemote().sendText("testName=" + testName); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" - + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close3Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close3Test() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" - + "session from WSCloseTestServer is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close()"); - } - - } catch (Exception e) { - e.printStackTrace(); - passed = false; - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close4Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close4Test() throws Exception { - String testName = "close1Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" - + "session from WSCloseTestServer is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - passed = false; - receivedMessageString.append(e.getMessage()); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close5Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; - * WebSocket:JAVADOC:20; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close5Test() throws Exception { - String testName = "close2Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" - + "session from WSCloseTestServer is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" - + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close6Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close6Test() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer1")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" - + "session from WSCloseTestServer1 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close()"); - } - - } catch (Exception e) { - e.printStackTrace(); - passed = false; - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close7Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close7Test() throws Exception { - String testName = "close1Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer1")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" - + "session from WSCloseTestServer1 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - passed = false; - receivedMessageString.append(e.getMessage()); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close8Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; - * WebSocket:JAVADOC:20; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close8Test() throws Exception { - String testName = "close2Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer1")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" - + "session from WSCloseTestServer1 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" - + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close9Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close9Test() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer2")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" - + "session from WSCloseTestServer2 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close()"); - } - - } catch (Exception e) { - e.printStackTrace(); - passed = false; - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close10Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close10Test() throws Exception { - String testName = "close1Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer2")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" - + "session from WSCloseTestServer2 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - passed = false; - receivedMessageString.append(e.getMessage()); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close11Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; - * WebSocket:JAVADOC:20; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close11Test() throws Exception { - String testName = "close2Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer2")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" - + "session from WSCloseTestServer2 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" - + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close12Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; - * WebSocket:JAVADOC:20; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * WebSocket:SPEC:WSC-4.5-2; - * - * @test_Strategy: - */ - public void close12Test() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKCloseEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKCloseEndpoint OnOpen|" + "TCKTestServer opened|" - + "TCKCloseEndpoint OnClose|" + "TCKCloseEndpoint OnError", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: getContainerTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:129; - * - * @test_Strategy: - */ - public void getContainerTest() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - WebSocketContainer tmp = session.getContainer(); - - if (clientContainer != tmp) { - passed = false; - System.err.println("Incorrect return from getContainer" + tmp); - System.err.println("Expecting " + clientContainer); - } - - session.close(); - - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: getId1Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void getId1Test() throws Exception { - boolean passed = true; - String testName = "getId1Test"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - String tmp = session.getId(); - - receivedMessageString.append("getId returned from client side" + tmp); - - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out.println(receivedMessageString.toString()); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKTestServer received String: testName=" + testName, - receivedMessageString.toString()); - - session.close(); - - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: setMaxBinaryMessageBufferSizeTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:131; WebSocket:JAVADOC:148; - * - * @test_Strategy: - */ - public void setMaxBinaryMessageBufferSizeTest() throws Exception { - int size = 98765432; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - receivedMessageString - .append("getMaxBinaryMessageBufferSize returned default value =" - + session.getMaxBinaryMessageBufferSize()); - session.setMaxBinaryMessageBufferSize(size); - - int tmp = session.getMaxBinaryMessageBufferSize(); - if (tmp == size) { - receivedMessageString.append( - "getMaxBinaryMessageBufferSize returned expected value =" + tmp); - } else { - passed = false; - receivedMessageString.append( - "getMaxBinaryMessageBufferSize returned unexpected value =" + tmp); - receivedMessageString.append("expected value =" + size); - } - - session.close(); - - } catch (Exception e) { - passed = false; - receivedMessageString.append(e.getMessage()); - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: setMaxTextMessageBufferSizeTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:133; WebSocket:JAVADOC:150; - * - * @test_Strategy: - */ - public void setMaxTextMessageBufferSizeTest() throws Exception { - int size = 987654321; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out.println("getMaxTextMessageBufferSize returned default value =" - + session.getMaxTextMessageBufferSize()); - session.setMaxTextMessageBufferSize(size); - int tmp = session.getMaxTextMessageBufferSize(); - if (tmp == size) { - System.out.println( - "getMaxTextMessageBufferSize returned expected value =" + tmp); - } else { - System.out.println( - "getMaxTextMessageBufferSize returned unexpected value =" + tmp); - System.out.println("expected value =" + size); - } - - session.close(); - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: setTimeoutTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; - * - * @test_Strategy: - */ - public void setTimeoutTest() throws Exception { - long tt = 9876543210L; - messageLatch = new CountDownLatch(1); // not to throw NPE in - // TCKBasicEndpoint - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - - System.out - .println("getMaxIdleTimeout returned default value on client side =" - + session.getMaxIdleTimeout()); - session.setMaxIdleTimeout(tt); - long tmp = session.getMaxIdleTimeout(); - if (tmp == tt) { - System.out.println("getMaxIdleTimeout returned expected value =" + tmp); - } else { - System.out - .println("getMaxIdleTimeout returned unexpected value =" + tmp); - System.out.println("expected value =" + tt); - } - session.close(); - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: setTimeout1Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; WebSocket:JAVADOC:140; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * WebSocket:SPEC:WSC-4.4-1; WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void setTimeout1Test() throws Exception { - String testName = "setTimeout1Test"; - boolean passed = true; - long tt = _ws_wait * 4 * 1000L; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer?timeout=" + _ws_wait)); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out - .println("getMaxIdleTimeout returned default value on client side =" - + session.getMaxIdleTimeout()); - session.setMaxIdleTimeout(tt); - - // Wait for 2 messages but not third (which should be sent after timeout) - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait * 8, TimeUnit.SECONDS); - if (session.isOpen()) { - passed = false; - receivedMessageString.append("Session is still open after timeout"); - } - - System.out.println(receivedMessageString.toString()); - - boolean tmp = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKTestServer received String: testName=setTimeout1Test", - receivedMessageString.toString()); - if (!tmp) { - passed = false; - } - - if (receivedMessageString.indexOf("AnyString=") > -1 - || receivedMessageString - .indexOf("TCKTestServer second message after sleep") > -1) { - passed = false; - System.err.println( - "Test failed due to message sent and/or received after timeout from client side"); - - } - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: setTimeout2Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; WebSocket:JAVADOC:140; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * WebSocket:SPEC:WSC-4.4-1; WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void setTimeout2Test() throws Exception { - String testName = "setTimeout2Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer?timeout=" + _ws_wait)); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out - .println("getMaxIdleTimeout returned default value on client side =" - + session.getMaxIdleTimeout()); - - // Session timeout is set on server - // Wait for 2 messages but not third (which should be sent after timeout) - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait * 8, TimeUnit.SECONDS); - if (session.isOpen()) { - passed = false; - receivedMessageString.append("Session is still open after timeout"); - } - - System.out.println(receivedMessageString.toString()); - boolean tmp = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKTestServer received String: testName=setTimeout2Test", - receivedMessageString.toString()); - - if (!tmp) { - passed = false; - } - - if (receivedMessageString.indexOf("AnyString=") > -1 - || receivedMessageString - .indexOf("TCKTestServer second message after sleep") > -1) { - passed = false; - System.err.println( - "Test failed due to message sent and/or received after timeout from server side"); - - } - - if (!passed) { - throw new Exception("Test Failed"); - } - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: getQueryStringTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:140; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; - * WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void getQueryStringTest() throws Exception { - String testName = "getQueryStringTest"; - boolean passed = true; - String querystring = "test1=value1&test2=value2&test3=value3"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer?" + querystring)); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out.println(receivedMessageString.toString()); - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKTestServer received String: testName=" + testName + "|" - + "TCKTestServer: expected Query String returned|" + querystring, - receivedMessageString.toString()); - - if (!passed) { - throw new Exception("Test Failed"); - } - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: getPathParametersTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:JAVADOC:138; - * WebSocket:SPEC:WSC-4.4-1; WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void getPathParametersTest() throws Exception { - String message = "invoke test"; - boolean passed = true; - String param1 = "test1"; - String param2 = "test2=xyz"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(1); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServerPathParam/" + param1 + "/" + param2)); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText(message); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator - .checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSTestServerPathParam opened|" - + "WSTestServerPathParam received String: " + message + "|" - + "WSTestServerPathParam: pathparams returned;param1=" - + param1 + ";param2=" + param2, - receivedMessageString.toString()); - - session.close(); - - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - - System.out.println(receivedMessageString.toString()); - - if (!passed) { - throw new Exception("Test Failed"); - } - } - - /* - * @testName: getRequestURITest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:142; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; - * WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void getRequestURITest() throws Exception { - String testName = "getRequestURITest"; - boolean passed = true; - String querystring = "test1=value1&test2=value2&test3=value3"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - - StringBuilder uriBuilder = new StringBuilder(); - uriBuilder.append("ws://"); - uriBuilder.append(_hostname); - if (_port != 80) { - uriBuilder.append(':'); - uriBuilder.append(_port); - } - uriBuilder.append(CONTEXT_ROOT); - uriBuilder.append("/TCKTestServer?"); - uriBuilder.append(querystring); - String uri = uriBuilder.toString(); - - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, new URI(uri)); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out.println(receivedMessageString.toString()); - passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" - + "TCKTestServer opened|" + "session from Server is open=TRUE|" - + "TCKTestServer received String: testName=" + testName + "|" - + "TCKTestServer: getRequestURI returned=" + uri, - receivedMessageString.toString()); - - if (!passed) { - throw new Exception("Test Failed"); - } - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: getProtocolVersionTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:139; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-4.4-1; - * - * @test_Strategy: - */ - public void getProtocolVersionTest() throws Exception { - String expectedProtocolVersion = "13"; - String testName = "getProtocolVersionTest"; - String search = "TCKTestServer opened|" - + "session from Server is open=TRUE"; - setCountDownLatchCount(2); - setClientCallback(new TCKGetIdEndpoint()); - setProperty(Property.REQUEST, buildRequest("TCKTestServer")); - setProperty(Property.SEARCH_STRING, search); - invoke(false); - - assertEquals(expectedProtocolVersion, getSession().getProtocolVersion(), - "getProtocolVersion() is not", expectedProtocolVersion, "as expected"); - logMsg("getProtocolVersion() is", expectedProtocolVersion, "as expected"); - - setProperty(Property.UNORDERED_SEARCH_STRING, - "TCKTestServer received String:"); - setProperty(Property.UNORDERED_SEARCH_STRING, - "testName=getProtocolVersionTest"); - setProperty(Property.UNORDERED_SEARCH_STRING, - "TCKTestServer: getProtocolVersion returned=13"); - setProperty(Property.CONTENT, "testName=" + testName); - invokeAgain(true); - } - - /* - * @testName: getOpenSessionsTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:137; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void getOpenSessionsTest() throws Exception { - boolean passed = true; - String testName = "getOpenSessionsTest"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer - .connectToServer(TCKOpenSessionEndpoint.class, config, new URI("ws://" - + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - int os = getOpenSessions(receivedMessageString.toString()); - - messageLatch = new CountDownLatch(2); - Session session1 = clientContainer - .connectToServer(TCKOpenSessionEndpoint.class, config, new URI("ws://" - + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session1.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - int os1 = getOpenSessions(receivedMessageString.toString()); - - messageLatch = new CountDownLatch(2); - Session session2 = clientContainer - .connectToServer(TCKOpenSessionEndpoint.class, config, new URI("ws://" - + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session2.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - int os2 = getOpenSessions(receivedMessageString.toString()); - - session.close(); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session1.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - int os3 = getOpenSessions(receivedMessageString.toString()); - - session1.close(); - SessionUtil.waitUntilClosed(session1, _ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session2.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - int os4 = getOpenSessions(receivedMessageString.toString()); - - session2.close(); - - if (os == 1) { - if (os1 != 2 || os2 != 3) { - passed = false; - System.out.print("Not perfect 12321 pattern for open session"); - } - } - - if (os4 > os3 || os3 > os2) { - passed = false; - System.out.print("Incorrect XXX++ pattern for open session"); - } - - if (os < 1 || os1 < 2 || os2 < 3 || os3 < 2 || os4 < 1) { - passed = false; - System.out.print("Cannot have less open session than 12321"); - } - - if (os1 - os > 1 || os2 - os1 > 1) { - passed = false; - System.out.print("Too many session are open"); - } - - } catch (Exception ioe) { - passed = false; - ioe.printStackTrace(); - } - System.out.println(receivedMessageString.toString()); - - if (!passed) { - throw new Exception("Incorrect response received"); - } - } - - @Override - public void cleanup() throws Exception { - super.cleanup(); - } - - public final static class TCKBasicEndpoint extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - receivedMessageString.append("TCKBasicEndpoint OnOpen"); - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - receivedMessageString.append(message); - messageLatch.countDown(); - } - }); - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(ByteBuffer data) { - byte[] data1 = new byte[data.remaining()]; - data.get(data1); - receivedMessageString - .append("========Basic ByteBuffer MessageHander received=" - + new String(data1)); - messageLatch.countDown(); - } - }); - - } - - @Override - public void onClose(Session session, CloseReason closeReason) { - receivedMessageString.append( - "TCKBasicEndpoint OnClose CloseCode=" + closeReason.getCloseCode()); - receivedMessageString.append("TCKBasicEndpoint OnClose ReasonPhrase=" - + closeReason.getReasonPhrase()); - } - } - - public final static class TCKBasicEndpoint1 extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - } - } - - public final static class TCKGetIdEndpoint extends EndpointCallback { - - @Override - public void onOpen(Session session, EndpointConfig config) { - ClientEndpoint.getMessageBuilder().append("======Another SessionID=") - .append(session.getId()); - System.out.println(session.getId()); - } - } - - public final static class TCKBasicStringEndpoint - extends ClientEndpoint { - - @Override - public void onMessage(String message) { - getMessageBuilder().append("========First TextMessageHander received=") - .append(message); - getCountDownLatch().countDown(); - } - - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - try { - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - getMessageBuilder() - .append("========Second TextMessageHander received=") - .append(message); - getCountDownLatch().countDown(); - } - }); - } catch (IllegalStateException ile) { - getMessageBuilder().append( - "========Expected IllegalStateException thrown by Second TextMessageHandler"); - // ile.printStackTrace(); - } - try { - session.getBasicRemote().sendText(SENT_STRING_MESSAGE); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public final static class TCKBasicByteEndpoint - extends ClientEndpoint { - - @Override - public void onMessage(ByteBuffer message) { - String message_string = IOUtil.byteBufferToString(message); - - getMessageBuilder() - .append("========First Basic ByteBuffer MessageHander received=") - .append(message_string); - getCountDownLatch().countDown(); - } - - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - SENT_BYTE_MESSAGE.put("Hello World in ByteBuffer".getBytes()); - SENT_BYTE_MESSAGE.flip(); - try { - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(ByteBuffer data) { - String message_string = IOUtil.byteBufferToString(data); - getMessageBuilder() - .append( - "========Second Basic ByteBuffer MessageHander received=") - .append(message_string); - getCountDownLatch().countDown(); - } - }); - } catch (IllegalStateException ile) { - getMessageBuilder().append( - "========Expected IllegalStateException thrown by Second ByteBuffer MessageHandler"); - // ile.printStackTrace(); - } - try { - session.getBasicRemote().sendBinary(SENT_BYTE_MESSAGE); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public final static class TCKOpenSessionEndpoint extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - receivedMessageString.append(message); - messageLatch.countDown(); - } - }); - } - - @Override - public void onClose(Session session, CloseReason closeReason) { - receivedMessageString.append("onClose"); - } - } - - public final static class TCKCloseEndpoint extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - receivedMessageString.append("TCKCloseEndpoint OnOpen"); - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - receivedMessageString.append(message); - messageLatch.countDown(); - } - }); - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(ByteBuffer data) { - String message_string = IOUtil.byteBufferToString(data); - - receivedMessageString - .append("========Basic ByteBuffer MessageHander received=" - + message_string); - messageLatch.countDown(); - } - }); - } - - @Override - public void onClose(Session session, CloseReason closeReason) { - receivedMessageString.append("TCKCloseEndpoint OnClose"); - receivedMessageString.append("Pass_On_To_Error="); - @SuppressWarnings("unused") - int i = 1 / 0; - } - - @Override - public void onError(Session session, Throwable t) { - receivedMessageString.append("TCKCloseEndpoint OnError"); - receivedMessageString.append(t.getMessage()); - } - } - - @SuppressWarnings("unused") - private int getOpenSessions(String message) { - int start = receivedMessageString.lastIndexOf("getOpenSessions="); - int stop = receivedMessageString - .lastIndexOf("========TCKTestServer responded"); - int os = Integer - .parseInt(receivedMessageString.substring(start + 16, stop)); - System.out.println("open session=" + os); - return os; - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSClientIT.java new file mode 100644 index 0000000000..a33ea9a6e1 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSClientIT.java @@ -0,0 +1,1866 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.session; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.net.URI; +import java.nio.ByteBuffer; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.ClientEndpoint; +import com.sun.ts.tests.websocket.common.client.EndpointCallback; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.common.util.MessageValidator; +import com.sun.ts.tests.websocket.common.util.SessionUtil; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.CloseReason; +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.Endpoint; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.MessageHandler; +import jakarta.websocket.Session; +import jakarta.websocket.WebSocketContainer; + +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_session_web.war"); + archive.addPackages(false, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.session"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common"); + archive.addAsWebInfResource(WSClientIT.class.getPackage(), "web.xml", "web.xml"); + return archive; + } + + private static final String CONTEXT_ROOT = "/ws_session_web"; + + private static final String SENT_STRING_MESSAGE = "Hello World in String"; + + private static ByteBuffer SENT_BYTE_MESSAGE = ByteBuffer + .allocate("Hello World in ByteBuffer".getBytes().length + 1); + + private static StringBuffer receivedMessageString = new StringBuffer(); + + static volatile CountDownLatch messageLatch; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("ws_session_web"); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; + */ + /* Run test */ + /* + * @testName: isOpenTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; + * WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void isOpenTest() throws Exception { + String testName = "isOpenTest"; + String search = "TCKTestServer opened|" + "session from Server is open=TRUE"; + + setCountDownLatchCount(2); + setClientCallback(new TCKGetIdEndpoint()); + setProperty(Property.REQUEST, buildRequest("TCKTestServer")); + setProperty(Property.UNORDERED_SEARCH_STRING, search); + invoke(false); + + search = "TCKTestServer received String: testName=" + testName + "|" + "session from Server is still open=TRUE"; + setProperty(Property.UNORDERED_SEARCH_STRING, search); + setProperty(Property.CONTENT, "testName=isOpenTest"); + invokeAgain(true); + } + + /* + * @testName: isOpenTest1 + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; + * WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void isOpenTest1() throws Exception { + String search = "TCKTestServer opened|" + "session from Server is open=TRUE"; + + setCountDownLatchCount(2); + setClientCallback(new TCKGetIdEndpoint()); + setProperty(Property.REQUEST, buildRequest("TCKTestServer")); + setProperty(Property.UNORDERED_SEARCH_STRING, search); + invoke(false); + + try { + ClientEndpoint.getCountDownLatch().await(_ws_wait, TimeUnit.SECONDS); + if (!getSession().isOpen()) { + throw new Exception("Client side Session is not open"); + } + } catch (Exception ioe) { + new Exception(ioe); + } + invoke(true); + } + + /* + * @testName: addMessageHandlerBasicStringTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void addMessageHandlerBasicStringTest() throws Exception { + String search = "Expected IllegalStateException thrown by Second TextMessageHandler|" + + "First TextMessageHander received|" + "TCKTestServerString opened|" + + "First TextMessageHander received|" + "TCKTestServerString received String: Hello World in String|" + + "First TextMessageHander received|" + "TCKTestServerString responds|" + + "TCKTestServerString received String: |" + "First TextMessageHander received|" + + "TCKTestServerString responds"; + setCountDownLatchCount(3); + setClientEndpoint(TCKBasicStringEndpoint.class); + setProperty(Property.REQUEST, buildRequest("TCKTestServerString")); + setProperty(Property.UNORDERED_SEARCH_STRING, search); + invoke(true); + } + + /* + * @testName: addMessageHandlerBasicByteBufferTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:105; + * WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; WebSocket:SPEC:WSC-2.1.3-1; + * WebSocket:SPEC:WSC-2.1.3-2; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void addMessageHandlerBasicByteBufferTest() throws Exception { + String search = "Expected IllegalStateException thrown by Second ByteBuffer MessageHandler|" + + "First Basic ByteBuffer MessageHander received|" + "TCKTestServerByte opened|" + + "First Basic ByteBuffer MessageHander received|" + + "TCKTestServerByte received ByteBuffer: Hello World in ByteBuffer|" + + "TCKTestServerByte responds: Message in bytes"; + setCountDownLatchCount(2); + setClientEndpoint(TCKBasicByteEndpoint.class); + setProperty(Property.REQUEST, buildRequest("TCKTestServerByte")); + setProperty(Property.UNORDERED_SEARCH_STRING, search); + invoke(true); + } + + /* + * @testName: addMessageHandlersTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:105; + * WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; + * WebSocket:JAVADOC:134; WebSocket:JAVADOC:147; WebSocket:SPEC:WSC-2.1.3-1; + * WebSocket:SPEC:WSC-2.1.3-2; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; + * WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void addMessageHandlersTest() throws Exception { + boolean passed = true; + String message_sent_bytebuffer = "BasicByteBufferMessageHandler added"; + String message_sent_string = "BasicStringMessageHandler added"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + final Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + Set msgHanders = session.getMessageHandlers(); + receivedMessageString.append("Start with MessageHandler=" + msgHanders.size()); + + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText(message_sent_string); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + ByteBuffer data = ByteBuffer.allocate(message_sent_bytebuffer.getBytes().length); + data.put(message_sent_bytebuffer.getBytes()); + data.flip(); + messageLatch = new CountDownLatch(3); + session.getBasicRemote().sendBinary(data); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + for (MessageHandler msgHander : msgHanders) { + session.removeMessageHandler(msgHander); + receivedMessageString.append("MessageHandler=" + session.getMessageHandlers().size()); + } + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + + "Start with MessageHandler=2|" + "TCKTestServer received String:|" + message_sent_string + "|" + + "TCKTestServer responds, please close your session|" + "Basic ByteBuffer MessageHander received|" + + "TCKTestServer received ByteBuffer:|" + "Basic ByteBuffer MessageHander received|" + + message_sent_bytebuffer + "|" + "Basic ByteBuffer MessageHander received|" + + "TCKTestServer responds: Message in bytes|" + "MessageHandler=1|" + "MessageHandler=0", + receivedMessageString.toString()); + session.close(); + + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: addMessageHandlersTest1 + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:103; + * WebSocket:JAVADOC:105; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; + * WebSocket:JAVADOC:122; WebSocket:JAVADOC:134; WebSocket:JAVADOC:147; + * WebSocket:SPEC:WSC-2.1.3-1; WebSocket:SPEC:WSC-2.1.3-2; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void addMessageHandlersTest1() throws Exception { + boolean passed = true; + final String message_sent_bytebuffer = "BasicByteBufferMessageHandler added"; + final String message_sent_reader = "BasicTextReaderMessageHandler added"; + final String message_reader_msghandler = "BasicReaderMessageHander received="; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + final Session session = clientContainer.connectToServer(TCKBasicEndpoint1.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + + Set msgHanders_1 = session.getMessageHandlers(); + receivedMessageString.append("Start with MessageHandler=" + msgHanders_1.size()); + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(Reader r) { + char[] buffer = new char[128]; + try { + int i = r.read(buffer); + receivedMessageString.append("========" + message_reader_msghandler + new String(buffer, 0, i)); + messageLatch.countDown(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }); + + messageLatch = new CountDownLatch(4); + Writer writer = session.getBasicRemote().getSendWriter(); + writer.append(message_sent_reader); + writer.close(); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + Set msgHanders_2 = session.getMessageHandlers(); + receivedMessageString.append("Now we Have MessageHandler=" + msgHanders_2.size()); + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(ByteBuffer data) { + byte[] data1 = new byte[data.remaining()]; + data.get(data1); + receivedMessageString.append(new String(data1)); + messageLatch.countDown(); + } + }); + + ByteBuffer data = ByteBuffer.allocate((message_sent_bytebuffer).getBytes().length); + data.put((message_sent_bytebuffer).getBytes()); + data.flip(); + messageLatch = new CountDownLatch(3); + session.getBasicRemote().sendBinary(data); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + Set msgHanders_3 = session.getMessageHandlers(); + receivedMessageString.append("Now it is MessageHandler=" + msgHanders_3.size()); + + for (MessageHandler msgHander : msgHanders_3) { + session.removeMessageHandler(msgHander); + receivedMessageString.append("MessageHandler=" + session.getMessageHandlers().size()); + } + + passed = MessageValidator.checkSearchStrings( + "Start with MessageHandler=0|" + message_reader_msghandler + "|" + "TCKTestServer received String:|" + + message_sent_reader + "|" + "TCKTestServer responds, please close your session|" + + "Now we Have MessageHandler=1|" + "TCKTestServer received ByteBuffer:|" + + message_sent_bytebuffer + "|" + "TCKTestServer responds: Message in bytes|" + + "Now it is MessageHandler=2|" + "MessageHandler=1|" + "MessageHandler=0", + receivedMessageString.toString()); + + session.close(); + + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + + System.out.println(receivedMessageString.toString()); + + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: closeTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void closeTest() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator + .checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", + receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString.append("=================Session stays open after calling close()"); + } + + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close1Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close1Test() throws Exception { + String testName = "close1Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.getBasicRemote().sendText("testName=" + testName); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + passed = false; + receivedMessageString.append(e.getMessage()); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close2Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; + * WebSocket:JAVADOC:20; WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close2Test() throws Exception { + String testName = "close2Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.getBasicRemote().sendText("testName=" + testName); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" + + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", + receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close3Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close3Test() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" + + "session from WSCloseTestServer is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString.append("=================Session stays open after calling close()"); + } + + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close4Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close4Test() throws Exception { + String testName = "close1Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" + + "session from WSCloseTestServer is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + passed = false; + receivedMessageString.append(e.getMessage()); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close5Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; + * WebSocket:JAVADOC:20; WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close5Test() throws Exception { + String testName = "close2Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" + + "session from WSCloseTestServer is open=TRUE|" + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" + + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close6Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close6Test() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer1")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" + + "session from WSCloseTestServer1 is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString.append("=================Session stays open after calling close()"); + } + + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close7Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close7Test() throws Exception { + String testName = "close1Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer1")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" + + "session from WSCloseTestServer1 is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + passed = false; + receivedMessageString.append(e.getMessage()); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close8Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; + * WebSocket:JAVADOC:20; WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close8Test() throws Exception { + String testName = "close2Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer1")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" + + "session from WSCloseTestServer1 is open=TRUE|" + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" + + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close9Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close9Test() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer2")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" + + "session from WSCloseTestServer2 is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString.append("=================Session stays open after calling close()"); + } + + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close10Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close10Test() throws Exception { + String testName = "close1Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer2")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" + + "session from WSCloseTestServer2 is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + passed = false; + receivedMessageString.append(e.getMessage()); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close11Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; + * WebSocket:JAVADOC:20; WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close11Test() throws Exception { + String testName = "close2Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer2")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" + + "session from WSCloseTestServer2 is open=TRUE|" + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" + + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close12Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; + * WebSocket:JAVADOC:20; WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.5-2; + * + * @test_Strategy: + */ + @Test + public void close12Test() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKCloseEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKCloseEndpoint OnOpen|" + "TCKTestServer opened|" + + "TCKCloseEndpoint OnClose|" + "TCKCloseEndpoint OnError", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: getContainerTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:129; + * + * @test_Strategy: + */ + @Test + public void getContainerTest() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + WebSocketContainer tmp = session.getContainer(); + + if (clientContainer != tmp) { + passed = false; + System.err.println("Incorrect return from getContainer" + tmp); + System.err.println("Expecting " + clientContainer); + } + + session.close(); + + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: getId1Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void getId1Test() throws Exception { + boolean passed = true; + String testName = "getId1Test"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + String tmp = session.getId(); + + receivedMessageString.append("getId returned from client side" + tmp); + + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out.println(receivedMessageString.toString()); + + passed = MessageValidator + .checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKTestServer received String: testName=" + testName, + receivedMessageString.toString()); + + session.close(); + + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: setMaxBinaryMessageBufferSizeTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:131; WebSocket:JAVADOC:148; + * + * @test_Strategy: + */ + @Test + public void setMaxBinaryMessageBufferSizeTest() throws Exception { + int size = 98765432; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + receivedMessageString.append( + "getMaxBinaryMessageBufferSize returned default value =" + session.getMaxBinaryMessageBufferSize()); + session.setMaxBinaryMessageBufferSize(size); + + int tmp = session.getMaxBinaryMessageBufferSize(); + if (tmp == size) { + receivedMessageString.append("getMaxBinaryMessageBufferSize returned expected value =" + tmp); + } else { + passed = false; + receivedMessageString.append("getMaxBinaryMessageBufferSize returned unexpected value =" + tmp); + receivedMessageString.append("expected value =" + size); + } + + session.close(); + + } catch (Exception e) { + passed = false; + receivedMessageString.append(e.getMessage()); + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: setMaxTextMessageBufferSizeTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:133; WebSocket:JAVADOC:150; + * + * @test_Strategy: + */ + @Test + public void setMaxTextMessageBufferSizeTest() throws Exception { + int size = 987654321; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out.println( + "getMaxTextMessageBufferSize returned default value =" + session.getMaxTextMessageBufferSize()); + session.setMaxTextMessageBufferSize(size); + int tmp = session.getMaxTextMessageBufferSize(); + if (tmp == size) { + System.out.println("getMaxTextMessageBufferSize returned expected value =" + tmp); + } else { + System.out.println("getMaxTextMessageBufferSize returned unexpected value =" + tmp); + System.out.println("expected value =" + size); + } + + session.close(); + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: setTimeoutTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; + * + * @test_Strategy: + */ + @Test + public void setTimeoutTest() throws Exception { + long tt = 9876543210L; + messageLatch = new CountDownLatch(1); // not to throw NPE in + // TCKBasicEndpoint + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + + System.out + .println("getMaxIdleTimeout returned default value on client side =" + session.getMaxIdleTimeout()); + session.setMaxIdleTimeout(tt); + long tmp = session.getMaxIdleTimeout(); + if (tmp == tt) { + System.out.println("getMaxIdleTimeout returned expected value =" + tmp); + } else { + System.out.println("getMaxIdleTimeout returned unexpected value =" + tmp); + System.out.println("expected value =" + tt); + } + session.close(); + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: setTimeout1Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; WebSocket:JAVADOC:140; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-4.4-1; WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void setTimeout1Test() throws Exception { + String testName = "setTimeout1Test"; + boolean passed = true; + long tt = _ws_wait * 4 * 1000L; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer?timeout=" + _ws_wait)); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out + .println("getMaxIdleTimeout returned default value on client side =" + session.getMaxIdleTimeout()); + session.setMaxIdleTimeout(tt); + + // Wait for 2 messages but not third (which should be sent after timeout) + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait * 8, TimeUnit.SECONDS); + if (session.isOpen()) { + passed = false; + receivedMessageString.append("Session is still open after timeout"); + } + + System.out.println(receivedMessageString.toString()); + + boolean tmp = MessageValidator.checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKTestServer received String: testName=setTimeout1Test", + receivedMessageString.toString()); + if (!tmp) { + passed = false; + } + + if (receivedMessageString.indexOf("AnyString=") > -1 + || receivedMessageString.indexOf("TCKTestServer second message after sleep") > -1) { + passed = false; + System.err.println("Test failed due to message sent and/or received after timeout from client side"); + + } + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: setTimeout2Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; WebSocket:JAVADOC:140; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-4.4-1; WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void setTimeout2Test() throws Exception { + String testName = "setTimeout2Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer?timeout=" + _ws_wait)); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out + .println("getMaxIdleTimeout returned default value on client side =" + session.getMaxIdleTimeout()); + + // Session timeout is set on server + // Wait for 2 messages but not third (which should be sent after timeout) + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait * 8, TimeUnit.SECONDS); + if (session.isOpen()) { + passed = false; + receivedMessageString.append("Session is still open after timeout"); + } + + System.out.println(receivedMessageString.toString()); + boolean tmp = MessageValidator.checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKTestServer received String: testName=setTimeout2Test", + receivedMessageString.toString()); + + if (!tmp) { + passed = false; + } + + if (receivedMessageString.indexOf("AnyString=") > -1 + || receivedMessageString.indexOf("TCKTestServer second message after sleep") > -1) { + passed = false; + System.err.println("Test failed due to message sent and/or received after timeout from server side"); + + } + + if (!passed) { + throw new Exception("Test Failed"); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: getQueryStringTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:140; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; + * WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void getQueryStringTest() throws Exception { + String testName = "getQueryStringTest"; + boolean passed = true; + String querystring = "test1=value1&test2=value2&test3=value3"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer?" + querystring)); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out.println(receivedMessageString.toString()); + passed = MessageValidator.checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKTestServer received String: testName=" + testName + "|" + + "TCKTestServer: expected Query String returned|" + querystring, + receivedMessageString.toString()); + + if (!passed) { + throw new Exception("Test Failed"); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: getPathParametersTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:JAVADOC:138; WebSocket:SPEC:WSC-4.4-1; + * WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void getPathParametersTest() throws Exception { + String message = "invoke test"; + boolean passed = true; + String param1 = "test1"; + String param2 = "test2=xyz"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(1); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, new URI("ws://" + + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServerPathParam/" + param1 + "/" + param2)); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText(message); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "WSTestServerPathParam opened|" + + "WSTestServerPathParam received String: " + message + "|" + + "WSTestServerPathParam: pathparams returned;param1=" + param1 + ";param2=" + param2, + receivedMessageString.toString()); + + session.close(); + + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + + System.out.println(receivedMessageString.toString()); + + if (!passed) { + throw new Exception("Test Failed"); + } + } + + /* + * @testName: getRequestURITest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:142; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; + * WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void getRequestURITest() throws Exception { + String testName = "getRequestURITest"; + boolean passed = true; + String querystring = "test1=value1&test2=value2&test3=value3"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + + StringBuilder uriBuilder = new StringBuilder(); + uriBuilder.append("ws://"); + uriBuilder.append(_hostname); + if (_port != 80) { + uriBuilder.append(':'); + uriBuilder.append(_port); + } + uriBuilder.append(CONTEXT_ROOT); + uriBuilder.append("/TCKTestServer?"); + uriBuilder.append(querystring); + String uri = uriBuilder.toString(); + + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, new URI(uri)); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out.println(receivedMessageString.toString()); + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + + "session from Server is open=TRUE|" + "TCKTestServer received String: testName=" + testName + "|" + + "TCKTestServer: getRequestURI returned=" + uri, receivedMessageString.toString()); + + if (!passed) { + throw new Exception("Test Failed"); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: getProtocolVersionTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:139; WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-4.4-1; + * + * @test_Strategy: + */ + @Test + public void getProtocolVersionTest() throws Exception { + String expectedProtocolVersion = "13"; + String testName = "getProtocolVersionTest"; + String search = "TCKTestServer opened|" + "session from Server is open=TRUE"; + setCountDownLatchCount(2); + setClientCallback(new TCKGetIdEndpoint()); + setProperty(Property.REQUEST, buildRequest("TCKTestServer")); + setProperty(Property.SEARCH_STRING, search); + invoke(false); + + assertEquals(expectedProtocolVersion, getSession().getProtocolVersion(), "getProtocolVersion() is not", + expectedProtocolVersion, "as expected"); + logMsg("getProtocolVersion() is", expectedProtocolVersion, "as expected"); + + setProperty(Property.UNORDERED_SEARCH_STRING, "TCKTestServer received String:"); + setProperty(Property.UNORDERED_SEARCH_STRING, "testName=getProtocolVersionTest"); + setProperty(Property.UNORDERED_SEARCH_STRING, "TCKTestServer: getProtocolVersion returned=13"); + setProperty(Property.CONTENT, "testName=" + testName); + invokeAgain(true); + } + + /* + * @testName: getOpenSessionsTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:137; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void getOpenSessionsTest() throws Exception { + boolean passed = true; + String testName = "getOpenSessionsTest"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKOpenSessionEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + int os = getOpenSessions(receivedMessageString.toString()); + + messageLatch = new CountDownLatch(2); + Session session1 = clientContainer.connectToServer(TCKOpenSessionEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session1.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + int os1 = getOpenSessions(receivedMessageString.toString()); + + messageLatch = new CountDownLatch(2); + Session session2 = clientContainer.connectToServer(TCKOpenSessionEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session2.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + int os2 = getOpenSessions(receivedMessageString.toString()); + + session.close(); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session1.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + int os3 = getOpenSessions(receivedMessageString.toString()); + + session1.close(); + SessionUtil.waitUntilClosed(session1, _ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session2.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + int os4 = getOpenSessions(receivedMessageString.toString()); + + session2.close(); + + if (os == 1) { + if (os1 != 2 || os2 != 3) { + passed = false; + System.out.print("Not perfect 12321 pattern for open session"); + } + } + + if (os4 > os3 || os3 > os2) { + passed = false; + System.out.print("Incorrect XXX++ pattern for open session"); + } + + if (os < 1 || os1 < 2 || os2 < 3 || os3 < 2 || os4 < 1) { + passed = false; + System.out.print("Cannot have less open session than 12321"); + } + + if (os1 - os > 1 || os2 - os1 > 1) { + passed = false; + System.out.print("Too many session are open"); + } + + } catch (Exception ioe) { + passed = false; + ioe.printStackTrace(); + } + System.out.println(receivedMessageString.toString()); + + if (!passed) { + throw new Exception("Incorrect response received"); + } + } + + @Override + public void cleanup() throws Exception { + super.cleanup(); + } + + public final static class TCKBasicEndpoint extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + receivedMessageString.append("TCKBasicEndpoint OnOpen"); + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append(message); + messageLatch.countDown(); + } + }); + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(ByteBuffer data) { + byte[] data1 = new byte[data.remaining()]; + data.get(data1); + receivedMessageString + .append("========Basic ByteBuffer MessageHander received=" + new String(data1)); + messageLatch.countDown(); + } + }); + + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + receivedMessageString.append("TCKBasicEndpoint OnClose CloseCode=" + closeReason.getCloseCode()); + receivedMessageString.append("TCKBasicEndpoint OnClose ReasonPhrase=" + closeReason.getReasonPhrase()); + } + } + + public final static class TCKBasicEndpoint1 extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + } + } + + public final static class TCKGetIdEndpoint extends EndpointCallback { + + @Override + public void onOpen(Session session, EndpointConfig config) { + ClientEndpoint.getMessageBuilder().append("======Another SessionID=").append(session.getId()); + System.out.println(session.getId()); + } + } + + public final static class TCKBasicStringEndpoint extends ClientEndpoint { + + @Override + public void onMessage(String message) { + getMessageBuilder().append("========First TextMessageHander received=").append(message); + getCountDownLatch().countDown(); + } + + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + try { + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + getMessageBuilder().append("========Second TextMessageHander received=").append(message); + getCountDownLatch().countDown(); + } + }); + } catch (IllegalStateException ile) { + getMessageBuilder() + .append("========Expected IllegalStateException thrown by Second TextMessageHandler"); + // ile.printStackTrace(); + } + try { + session.getBasicRemote().sendText(SENT_STRING_MESSAGE); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public final static class TCKBasicByteEndpoint extends ClientEndpoint { + + @Override + public void onMessage(ByteBuffer message) { + String message_string = IOUtil.byteBufferToString(message); + + getMessageBuilder().append("========First Basic ByteBuffer MessageHander received=").append(message_string); + getCountDownLatch().countDown(); + } + + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + SENT_BYTE_MESSAGE.put("Hello World in ByteBuffer".getBytes()); + SENT_BYTE_MESSAGE.flip(); + try { + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(ByteBuffer data) { + String message_string = IOUtil.byteBufferToString(data); + getMessageBuilder().append("========Second Basic ByteBuffer MessageHander received=") + .append(message_string); + getCountDownLatch().countDown(); + } + }); + } catch (IllegalStateException ile) { + getMessageBuilder() + .append("========Expected IllegalStateException thrown by Second ByteBuffer MessageHandler"); + // ile.printStackTrace(); + } + try { + session.getBasicRemote().sendBinary(SENT_BYTE_MESSAGE); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public final static class TCKOpenSessionEndpoint extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append(message); + messageLatch.countDown(); + } + }); + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + receivedMessageString.append("onClose"); + } + } + + public final static class TCKCloseEndpoint extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + receivedMessageString.append("TCKCloseEndpoint OnOpen"); + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append(message); + messageLatch.countDown(); + } + }); + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(ByteBuffer data) { + String message_string = IOUtil.byteBufferToString(data); + + receivedMessageString.append("========Basic ByteBuffer MessageHander received=" + message_string); + messageLatch.countDown(); + } + }); + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + receivedMessageString.append("TCKCloseEndpoint OnClose"); + receivedMessageString.append("Pass_On_To_Error="); + @SuppressWarnings("unused") + int i = 1 / 0; + } + + @Override + public void onError(Session session, Throwable t) { + receivedMessageString.append("TCKCloseEndpoint OnError"); + receivedMessageString.append(t.getMessage()); + } + } + + @SuppressWarnings("unused") + private int getOpenSessions(String message) { + int start = receivedMessageString.lastIndexOf("getOpenSessions="); + int stop = receivedMessageString.lastIndexOf("========TCKTestServer responded"); + int os = Integer.parseInt(receivedMessageString.substring(start + 16, stop)); + System.out.println("open session=" + os); + return os; + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer.java index a484db8397..23712693ea 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer.java @@ -35,98 +35,87 @@ @ServerEndpoint(value = "/WSCloseTestServer") public class WSCloseTestServer { - private static final Class[] TEST_ARGS = { String.class, Session.class }; + private static final Class[] TEST_ARGS = { String.class, Session.class }; - static String testName; + static String testName; - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========WSCloseTestServer opened"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer is open=FALSE"); - } - } + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========WSCloseTestServer opened"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from WSCloseTestServer is open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from WSCloseTestServer is open=FALSE"); + } + } - @OnMessage - public void respondString(String message, Session session) { - System.out.println("WSCloseTestServer got String message: " + message); - try { - if (message.startsWith("testName=") && message.endsWith("Test")) { - testName = message.substring(9); - Method method = WSCloseTestServer.class.getMethod(testName, TEST_ARGS); - method.invoke(this, new Object[] { message, session }); - } else { - session.getBasicRemote() - .sendText("========WSCloseTestServer received String:" + message); - session.getBasicRemote().sendText( - "========WSCloseTestServer responds, please close your session"); - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnMessage + public void respondString(String message, Session session) { + System.out.println("WSCloseTestServer got String message: " + message); + try { + if (message.startsWith("testName=") && message.endsWith("Test")) { + testName = message.substring(9); + Method method = WSCloseTestServer.class.getMethod(testName, TEST_ARGS); + method.invoke(this, new Object[] { message, session }); + } else { + session.getBasicRemote().sendText("========WSCloseTestServer received String:" + message); + session.getBasicRemote().sendText("========WSCloseTestServer responds, please close your session"); + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========WSCloseTestServer onError"); - if (session.isOpen()) { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer is open=TRUE"); - } else { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer is open=FALSE"); - } - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer onError"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer is open=TRUE"); + } else { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer is open=FALSE"); + } + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } - @OnClose - public void onClose() { - System.out.println("==From WSCloseTestServer onClose()=="); - } + @OnClose + public void onClose() { + System.out.println("==From WSCloseTestServer onClose()=="); + } - public void close1Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer received String: " + message); - session.close(); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close1Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer received String: " + message); + session.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close2Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close2Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close3Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close3Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer1.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer1.java index c786527a47..a49d13858a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer1.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer1.java @@ -35,98 +35,87 @@ @ServerEndpoint(value = "/WSCloseTestServer1") public class WSCloseTestServer1 { - private static final Class[] TEST_ARGS = { String.class, Session.class }; + private static final Class[] TEST_ARGS = { String.class, Session.class }; - static String testName; + static String testName; - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========WSCloseTestServer1 opened"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer1 is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer1 is open=FALSE"); - } - } + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========WSCloseTestServer1 opened"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from WSCloseTestServer1 is open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from WSCloseTestServer1 is open=FALSE"); + } + } - @OnMessage - public void respondString(String message, Session session) { - System.out.println("WSCloseTestServer1 got String message: " + message); - try { - if (message.startsWith("testName=") && message.endsWith("Test")) { - testName = message.substring(9); - Method method = WSCloseTestServer1.class.getMethod(testName, TEST_ARGS); - method.invoke(this, new Object[] { message, session }); - } else { - session.getBasicRemote() - .sendText("========WSCloseTestServer1 received String:" + message); - session.getBasicRemote().sendText( - "========WSCloseTestServer1 responds, please close your session"); - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnMessage + public void respondString(String message, Session session) { + System.out.println("WSCloseTestServer1 got String message: " + message); + try { + if (message.startsWith("testName=") && message.endsWith("Test")) { + testName = message.substring(9); + Method method = WSCloseTestServer1.class.getMethod(testName, TEST_ARGS); + method.invoke(this, new Object[] { message, session }); + } else { + session.getBasicRemote().sendText("========WSCloseTestServer1 received String:" + message); + session.getBasicRemote().sendText("========WSCloseTestServer1 responds, please close your session"); + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========WSCloseTestServer1 onError"); - if (session.isOpen()) { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer1 is open=TRUE"); - } else { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer1 is open=FALSE"); - } - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer1 onError"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer1 is open=TRUE"); + } else { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer1 is open=FALSE"); + } + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } - @OnClose - public void onClose3() { - System.out.println("==From WSCloseTestServer1 onClose(CloseReason)=="); - } + @OnClose + public void onClose3() { + System.out.println("==From WSCloseTestServer1 onClose(CloseReason)=="); + } - public void close1Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer1 received String: " + message); - session.close(); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close1Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer1 received String: " + message); + session.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close2Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer1 received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close2Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer1 received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close3Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer1 received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close3Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer1 received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer2.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer2.java index 3db3af6a53..1db9e244c8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer2.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSCloseTestServer2.java @@ -35,105 +35,92 @@ @ServerEndpoint(value = "/WSCloseTestServer2") public class WSCloseTestServer2 { - private static final Class[] TEST_ARGS = { String.class, Session.class }; + private static final Class[] TEST_ARGS = { String.class, Session.class }; - static String testName; + static String testName; - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========WSCloseTestServer2 opened"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer2 is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer2 is open=FALSE"); - } - } + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========WSCloseTestServer2 opened"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from WSCloseTestServer2 is open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from WSCloseTestServer2 is open=FALSE"); + } + } - @OnMessage - public void respondString(String message, Session session) { - System.out.println("WSCloseTestServer2 got String message: " + message); - try { - if (message.startsWith("testName=") && message.endsWith("Test")) { - testName = message.substring(9); - Method method = WSCloseTestServer2.class.getMethod(testName, TEST_ARGS); - method.invoke(this, new Object[] { message, session }); - } else { - session.getBasicRemote() - .sendText("========WSCloseTestServer2 received String:" + message); - session.getBasicRemote().sendText( - "========WSCloseTestServer2 responds, please close your session"); - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnMessage + public void respondString(String message, Session session) { + System.out.println("WSCloseTestServer2 got String message: " + message); + try { + if (message.startsWith("testName=") && message.endsWith("Test")) { + testName = message.substring(9); + Method method = WSCloseTestServer2.class.getMethod(testName, TEST_ARGS); + method.invoke(this, new Object[] { message, session }); + } else { + session.getBasicRemote().sendText("========WSCloseTestServer2 received String:" + message); + session.getBasicRemote().sendText("========WSCloseTestServer2 responds, please close your session"); + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========WSCloseTestServer2 onError"); - if (session.isOpen()) { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer2 is open=TRUE"); - } else { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer2 is open=FALSE"); - } - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer2 onError"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer2 is open=TRUE"); + } else { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer2 is open=FALSE"); + } + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } - @OnClose - public void onClose3(Session session) { - System.out - .println("==From WSCloseTestServer2 onClose(Session, CloseReason)=="); - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer2 OnClose(Session, CloseReason)"); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnClose + public void onClose3(Session session) { + System.out.println("==From WSCloseTestServer2 onClose(Session, CloseReason)=="); + try { + session.getBasicRemote().sendText("========WSCloseTestServer2 OnClose(Session, CloseReason)"); + } catch (Exception e) { + e.printStackTrace(); + } + } - public void close1Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer2 received String: " + message); - session.close(); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close1Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer2 received String: " + message); + session.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close2Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer2 received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close2Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer2 received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close3Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer2 received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close3Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer2 received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServer.java index f7addb4c75..1261df0b07 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -42,329 +42,280 @@ @ServerEndpoint(value = "/TCKTestServer") public class WSTestServer { - private static final Class[] TEST_ARGS = { String.class, Session.class }; - - private static final Class[] TEST_ARGS_BYTEBUFFER = { ByteBuffer.class, - Session.class }; - - static String testName; - - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========TCKTestServer opened"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from Server is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from Server is open=FALSE"); - } - } - - @OnMessage - public void respondString(String message, Session session) { - System.out.println("TCKTestServer got String message: " + message); - try { - if (message.startsWith("testName=") && message.endsWith("Test")) { - testName = message.substring(9); - Method method = WSTestServer.class.getMethod(testName, TEST_ARGS); - method.invoke(this, new Object[] { message, session }); - } else { - session.getBasicRemote() - .sendText("========TCKTestServer received String:" + message); - session.getBasicRemote().sendText( - "========TCKTestServer responds, please close your session"); - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @OnMessage - public void respondByte(ByteBuffer message, Session session) { - String message_string = IOUtil.byteBufferToString(message); - - System.out - .println("TCKTestServer got ByteBuffer message: " + message_string); - - try { - if (message_string.startsWith("testName=")) { - testName = message_string.substring(9); - Method method = WSTestServer.class.getMethod(testName, - TEST_ARGS_BYTEBUFFER); - method.invoke(this, new Object[] { message, session }); - } else { - ByteBuffer data = ByteBuffer - .wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); - ByteBuffer data1 = ByteBuffer.wrap( - ("========TCKTestServer responds: Message in bytes").getBytes()); - - try { - session.getBasicRemote().sendBinary(data); - session.getBasicRemote().sendBinary(message); - session.getBasicRemote().sendBinary(data1); - } catch (Exception e) { - e.printStackTrace(); - } - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @OnError - public void onError(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========TCKTestServer onError"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========onError: session from Server is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========onError: session from Server is open=FALSE"); - } - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } - - @OnClose - public void onClose(Session session) { - System.out.println("==From WSTestServer onClose(Session)=="); - try { - session.getBasicRemote() - .sendText("========WSTestServer OnClose(Session)"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void isOpenTest(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from Server is still open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from Server is still open=FALSE"); - } - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - public void getId1Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - session.getBasicRemote().sendText( - "========TCKTestServer responds: default getId=" + session.getId()); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - @SuppressWarnings("unused") - public void close1Test(String message, Session session) { - try { - session.close(); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - @SuppressWarnings("unused") - public void close2Test(String message, Session session) { - try { - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - public void setTimeout1Test(String message, Session session) { - System.out.println( - "========In setMaxIdleTimeout1Test: TCKTestServer received String:" - + message); - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - session.getBasicRemote() - .sendText("========TCKTestServer default timeout: " - + session.getMaxIdleTimeout()); - String query_string = session.getQueryString(); - int timeout = 0; - if (query_string.startsWith("timeout")) { - timeout = Integer.parseInt(query_string.substring(8)); - Thread.sleep(timeout * 8000); - session.getBasicRemote() - .sendText("========TCKTestServer second message after sleep " - + timeout * 8 + " second"); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void setTimeout2Test(String message, Session session) { - System.out.println("========TCKTestServer received String:" + message); - CountDownLatch messageLatch = new CountDownLatch(1); - - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - session.getBasicRemote() - .sendText("========TCKTestServer default timeout: " - + session.getMaxIdleTimeout()); - - String query_string = session.getQueryString(); - int timeout = 0; - if (query_string.startsWith("timeout")) { - timeout = Integer.parseInt(query_string.substring(8)); - session.setMaxIdleTimeout(timeout * 4000); - session.getBasicRemote().sendText( - "========TCKTestServer set timeout to " + timeout * 4 + " second"); - session.getBasicRemote() - .sendText("========TCKTestServer getTimeout return " - + session.getMaxIdleTimeout() + " milliseconds"); - messageLatch.await(timeout * 6, TimeUnit.SECONDS); - session.getBasicRemote() - .sendText("========TCKTestServer second message after sleep " - + timeout * 6 + " second"); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void getQueryStringTest(String message, Session session) { - System.out.println("========TCKTestServer received String:" + message); - String expected_querystring = "test1=value1&test2=value2&test3=value3"; - - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - String query_string = session.getQueryString(); - if (expected_querystring.equals(query_string)) { - session.getBasicRemote() - .sendText("========TCKTestServer: expected Query String returned" - + query_string); - } else { - session.getBasicRemote() - .sendText("========TCKTestServer: unexpected Query String returned" - + query_string); - session.getBasicRemote().sendText( - "========TCKTestServer: expecting " + expected_querystring); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void getRequestURITest(String message, Session session) { - System.out.println("========TCKTestServer received String:" + message); - - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - URI requestURI = session.getRequestURI(); - session.getBasicRemote() - .sendText("========TCKTestServer: getRequestURI returned=" - + requestURI.toString()); - session.getBasicRemote() - .sendText("========TCKTestServer: getRequestURI returned queryString=" - + requestURI.getQuery()); - session.getBasicRemote() - .sendText("========TCKTestServer: getRequestURI returned scheme=" - + requestURI.getScheme()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void getProtocolVersionTest(String message, Session session) { - System.out.println("========TCKTestServer received String:" + message); - - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - String protocolVersion = session.getProtocolVersion(); - session.getBasicRemote() - .sendText("========TCKTestServer: getProtocolVersion returned=" - + protocolVersion); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void setMaxBinaryMessageBufferSizeTest2(ByteBuffer message_b, - Session session) { - System.out.println("In setMaxBinaryMessageBufferSizeTest2"); - String message = "Binary Message over size 64=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - ByteBuffer data = ByteBuffer - .wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); - ByteBuffer data1 = ByteBuffer - .wrap(("========TCKTestServer responds:").getBytes()); - ByteBuffer data2 = ByteBuffer.wrap(message.getBytes()); - - try { - session.getBasicRemote().sendBinary(data); - session.getBasicRemote().sendBinary(message_b); - session.getBasicRemote().sendBinary(data1); - session.getBasicRemote().sendBinary(data2); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - @SuppressWarnings("unused") - public void setMaxTextMessageBufferSize2Test(String message_r, - Session session) { - System.out.println("In setMaxTextMessageBufferSize2Test"); - String message = "String Message over size 64=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String Message: "); - session.getBasicRemote().sendText(message); - session.getBasicRemote().sendText("========TCKTestServer responded"); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - public void getOpenSessionsTest(String message, Session session) { - System.out.println("In getOpenSessionsTest"); - - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String Message: "); - session.getBasicRemote().sendText(message); - Set tmp = session.getOpenSessions(); - session.getBasicRemote() - .sendText("========getOpenSessions=" + tmp.size()); - session.getBasicRemote().sendText("========TCKTestServer responded"); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + private static final Class[] TEST_ARGS = { String.class, Session.class }; + + private static final Class[] TEST_ARGS_BYTEBUFFER = { ByteBuffer.class, Session.class }; + + static String testName; + + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========TCKTestServer opened"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from Server is open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from Server is open=FALSE"); + } + } + + @OnMessage + public void respondString(String message, Session session) { + System.out.println("TCKTestServer got String message: " + message); + try { + if (message.startsWith("testName=") && message.endsWith("Test")) { + testName = message.substring(9); + Method method = WSTestServer.class.getMethod(testName, TEST_ARGS); + method.invoke(this, new Object[] { message, session }); + } else { + session.getBasicRemote().sendText("========TCKTestServer received String:" + message); + session.getBasicRemote().sendText("========TCKTestServer responds, please close your session"); + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @OnMessage + public void respondByte(ByteBuffer message, Session session) { + String message_string = IOUtil.byteBufferToString(message); + + System.out.println("TCKTestServer got ByteBuffer message: " + message_string); + + try { + if (message_string.startsWith("testName=")) { + testName = message_string.substring(9); + Method method = WSTestServer.class.getMethod(testName, TEST_ARGS_BYTEBUFFER); + method.invoke(this, new Object[] { message, session }); + } else { + ByteBuffer data = ByteBuffer.wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); + ByteBuffer data1 = ByteBuffer.wrap(("========TCKTestServer responds: Message in bytes").getBytes()); + + try { + session.getBasicRemote().sendBinary(data); + session.getBasicRemote().sendBinary(message); + session.getBasicRemote().sendBinary(data1); + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @OnError + public void onError(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========TCKTestServer onError"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========onError: session from Server is open=TRUE"); + } else { + session.getBasicRemote().sendText("========onError: session from Server is open=FALSE"); + } + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } + + @OnClose + public void onClose(Session session) { + System.out.println("==From WSTestServer onClose(Session)=="); + try { + session.getBasicRemote().sendText("========WSTestServer OnClose(Session)"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void isOpenTest(String message, Session session) { + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from Server is still open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from Server is still open=FALSE"); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public void getId1Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + session.getBasicRemote().sendText("========TCKTestServer responds: default getId=" + session.getId()); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + @SuppressWarnings("unused") + public void close1Test(String message, Session session) { + try { + session.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + @SuppressWarnings("unused") + public void close2Test(String message, Session session) { + try { + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public void setTimeout1Test(String message, Session session) { + System.out.println("========In setMaxIdleTimeout1Test: TCKTestServer received String:" + message); + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + session.getBasicRemote().sendText("========TCKTestServer default timeout: " + session.getMaxIdleTimeout()); + String query_string = session.getQueryString(); + int timeout = 0; + if (query_string.startsWith("timeout")) { + timeout = Integer.parseInt(query_string.substring(8)); + Thread.sleep(timeout * 8000); + session.getBasicRemote() + .sendText("========TCKTestServer second message after sleep " + timeout * 8 + " second"); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void setTimeout2Test(String message, Session session) { + System.out.println("========TCKTestServer received String:" + message); + CountDownLatch messageLatch = new CountDownLatch(1); + + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + session.getBasicRemote().sendText("========TCKTestServer default timeout: " + session.getMaxIdleTimeout()); + + String query_string = session.getQueryString(); + int timeout = 0; + if (query_string.startsWith("timeout")) { + timeout = Integer.parseInt(query_string.substring(8)); + session.setMaxIdleTimeout(timeout * 4000); + session.getBasicRemote().sendText("========TCKTestServer set timeout to " + timeout * 4 + " second"); + session.getBasicRemote().sendText( + "========TCKTestServer getTimeout return " + session.getMaxIdleTimeout() + " milliseconds"); + messageLatch.await(timeout * 6, TimeUnit.SECONDS); + session.getBasicRemote() + .sendText("========TCKTestServer second message after sleep " + timeout * 6 + " second"); + } + + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void getQueryStringTest(String message, Session session) { + System.out.println("========TCKTestServer received String:" + message); + String expected_querystring = "test1=value1&test2=value2&test3=value3"; + + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + String query_string = session.getQueryString(); + if (expected_querystring.equals(query_string)) { + session.getBasicRemote() + .sendText("========TCKTestServer: expected Query String returned" + query_string); + } else { + session.getBasicRemote() + .sendText("========TCKTestServer: unexpected Query String returned" + query_string); + session.getBasicRemote().sendText("========TCKTestServer: expecting " + expected_querystring); + } + + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void getRequestURITest(String message, Session session) { + System.out.println("========TCKTestServer received String:" + message); + + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + URI requestURI = session.getRequestURI(); + session.getBasicRemote().sendText("========TCKTestServer: getRequestURI returned=" + requestURI.toString()); + session.getBasicRemote() + .sendText("========TCKTestServer: getRequestURI returned queryString=" + requestURI.getQuery()); + session.getBasicRemote() + .sendText("========TCKTestServer: getRequestURI returned scheme=" + requestURI.getScheme()); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void getProtocolVersionTest(String message, Session session) { + System.out.println("========TCKTestServer received String:" + message); + + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + String protocolVersion = session.getProtocolVersion(); + session.getBasicRemote().sendText("========TCKTestServer: getProtocolVersion returned=" + protocolVersion); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void setMaxBinaryMessageBufferSizeTest2(ByteBuffer message_b, Session session) { + System.out.println("In setMaxBinaryMessageBufferSizeTest2"); + String message = "Binary Message over size 64=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + ByteBuffer data = ByteBuffer.wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); + ByteBuffer data1 = ByteBuffer.wrap(("========TCKTestServer responds:").getBytes()); + ByteBuffer data2 = ByteBuffer.wrap(message.getBytes()); + + try { + session.getBasicRemote().sendBinary(data); + session.getBasicRemote().sendBinary(message_b); + session.getBasicRemote().sendBinary(data1); + session.getBasicRemote().sendBinary(data2); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + @SuppressWarnings("unused") + public void setMaxTextMessageBufferSize2Test(String message_r, Session session) { + System.out.println("In setMaxTextMessageBufferSize2Test"); + String message = "String Message over size 64=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + try { + session.getBasicRemote().sendText("========TCKTestServer received String Message: "); + session.getBasicRemote().sendText(message); + session.getBasicRemote().sendText("========TCKTestServer responded"); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public void getOpenSessionsTest(String message, Session session) { + System.out.println("In getOpenSessionsTest"); + + try { + session.getBasicRemote().sendText("========TCKTestServer received String Message: "); + session.getBasicRemote().sendText(message); + Set tmp = session.getOpenSessions(); + session.getBasicRemote().sendText("========getOpenSessions=" + tmp.size()); + session.getBasicRemote().sendText("========TCKTestServer responded"); + } catch (IOException ex) { + ex.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerByte.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerByte.java index 6e2e327556..ddf5802548 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerByte.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerByte.java @@ -34,46 +34,41 @@ @ServerEndpoint(value = "/TCKTestServerByte") public class WSTestServerByte { - @OnOpen - public void init(Session session) throws IOException { - String message = "========TCKTestServerByte opened"; - ByteBuffer data = ByteBuffer.allocate(message.getBytes().length); - data.put(message.getBytes()); - data.flip(); - session.getBasicRemote().sendBinary(data); - } + @OnOpen + public void init(Session session) throws IOException { + String message = "========TCKTestServerByte opened"; + ByteBuffer data = ByteBuffer.allocate(message.getBytes().length); + data.put(message.getBytes()); + data.flip(); + session.getBasicRemote().sendBinary(data); + } - @OnMessage - public void respond(ByteBuffer message, Session session) { - String message_string = IOUtil.byteBufferToString(message); + @OnMessage + public void respond(ByteBuffer message, Session session) { + String message_string = IOUtil.byteBufferToString(message); - System.out.println("TCKTestServerByte got ByteBuffer message: " - + message_string + " from session " + session); - try { - ByteBuffer data = ByteBuffer - .allocate(("========TCKTestServerByte received ByteBuffer: " - + "========TCKTestServerByte responds: Message in bytes") - .getBytes().length - + message.capacity()); - data.put(("========TCKTestServerByte received ByteBuffer: ").getBytes()); - data.put(message_string.getBytes()); - data.put( - ("========TCKTestServerByte responds: Message in bytes").getBytes()); - data.flip(); - session.getBasicRemote().sendBinary(data); - } catch (Exception e) { - e.printStackTrace(); - } - } + System.out.println("TCKTestServerByte got ByteBuffer message: " + message_string + " from session " + session); + try { + ByteBuffer data = ByteBuffer.allocate(("========TCKTestServerByte received ByteBuffer: " + + "========TCKTestServerByte responds: Message in bytes").getBytes().length + message.capacity()); + data.put(("========TCKTestServerByte received ByteBuffer: ").getBytes()); + data.put(message_string.getBytes()); + data.put(("========TCKTestServerByte responds: Message in bytes").getBytes()); + data.flip(); + session.getBasicRemote().sendBinary(data); + } catch (Exception e) { + e.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - System.out.println("TCKTestServerByte onError"); - try { - session.getBasicRemote().sendText("========TCKTestServerByte onError"); - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + System.out.println("TCKTestServerByte onError"); + try { + session.getBasicRemote().sendText("========TCKTestServerByte onError"); + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerPathParam.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerPathParam.java index abdd1c0dfb..527b9ed913 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerPathParam.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerPathParam.java @@ -33,44 +33,39 @@ @ServerEndpoint(value = "/TCKTestServerPathParam/{param1}/{param2}") public class WSTestServerPathParam { - @OnOpen - public void init(Session session) throws IOException { - String message = "========WSTestServerPathParam opened"; - session.getBasicRemote().sendText(message); - } + @OnOpen + public void init(Session session) throws IOException { + String message = "========WSTestServerPathParam opened"; + session.getBasicRemote().sendText(message); + } - @OnMessage - public void respond(String message, Session session) { - System.out - .println("========WSTestServerPathParam received String:" + message); - StringBuffer sb = new StringBuffer(); + @OnMessage + public void respond(String message, Session session) { + System.out.println("========WSTestServerPathParam received String:" + message); + StringBuffer sb = new StringBuffer(); - try { - session.getBasicRemote().sendText( - "========WSTestServerPathParam received String: " + message); - Map pathparams = session.getPathParameters(); - Set keys = pathparams.keySet(); - for (Object key : keys) { - System.out.println( - ";" + key.toString() + "=" + pathparams.get(key.toString())); - sb.append(";" + key.toString() + "=" + pathparams.get(key.toString())); - } - session.getBasicRemote().sendText( - "========WSTestServerPathParam: pathparams returned" + sb.toString()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } + try { + session.getBasicRemote().sendText("========WSTestServerPathParam received String: " + message); + Map pathparams = session.getPathParameters(); + Set keys = pathparams.keySet(); + for (Object key : keys) { + System.out.println(";" + key.toString() + "=" + pathparams.get(key.toString())); + sb.append(";" + key.toString() + "=" + pathparams.get(key.toString())); + } + session.getBasicRemote().sendText("========WSTestServerPathParam: pathparams returned" + sb.toString()); + } catch (Exception ex) { + ex.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - System.out.println("WSTestServerPathParam onError"); - try { - session.getBasicRemote() - .sendText("========WSTestServerPathParam onError"); - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + System.out.println("WSTestServerPathParam onError"); + try { + session.getBasicRemote().sendText("========WSTestServerPathParam onError"); + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerString.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerString.java index 76c7b4f37d..5dea807781 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerString.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/WSTestServerString.java @@ -31,29 +31,28 @@ @ServerEndpoint(value = "/TCKTestServerString") public class WSTestServerString { - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========TCKTestServerString opened"); - } + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========TCKTestServerString opened"); + } - @OnMessage - public void respond(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========TCKTestServerString received String: " + message); - session.getBasicRemote().sendText("========TCKTestServerString responds"); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnMessage + public void respond(String message, Session session) { + try { + session.getBasicRemote().sendText("========TCKTestServerString received String: " + message); + session.getBasicRemote().sendText("========TCKTestServerString responds"); + } catch (Exception e) { + e.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========TCKTestServerString onError"); - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========TCKTestServerString onError"); + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedBinaryClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedBinaryClient.java index 9ee7fcd3eb..086558ef9c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedBinaryClient.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedBinaryClient.java @@ -34,28 +34,27 @@ @ClientEndpoint(decoders = { AlternativeInputStreamDecoder.class }) public class AnnotatedBinaryClient extends AnnotatedClientEndpoint { - public AnnotatedBinaryClient() { - super(new StringClientEndpoint()); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - session.addMessageHandler(InputStream.class, - new InputStreamMessageHandler(clientEndpoint)); - super.onOpen(session, config); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + public AnnotatedBinaryClient() { + super(new StringClientEndpoint()); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + session.addMessageHandler(InputStream.class, new InputStreamMessageHandler(clientEndpoint)); + super.onOpen(session, config); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedTextClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedTextClient.java index 42c3397a8d..d2f989179b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedTextClient.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedTextClient.java @@ -34,27 +34,26 @@ @ClientEndpoint(decoders = { AlternativeReaderDecoder.class }) public class AnnotatedTextClient extends AnnotatedClientEndpoint { - public AnnotatedTextClient() { - super(new StringClientEndpoint()); - } - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - session.addMessageHandler(Reader.class, - new ReaderMessageHandler(clientEndpoint)); - super.onOpen(session, config); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + public AnnotatedTextClient() { + super(new StringClientEndpoint()); + } + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + session.addMessageHandler(Reader.class, new ReaderMessageHandler(clientEndpoint)); + super.onOpen(session, config); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedThrowingClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedThrowingClient.java index 1313b5462f..51102ce63a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedThrowingClient.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/AnnotatedThrowingClient.java @@ -36,78 +36,70 @@ @ClientEndpoint public class AnnotatedThrowingClient extends AnnotatedClientEndpoint { - TypeEnum typeEnum; + TypeEnum typeEnum; - RuntimeException thrown = null; + RuntimeException thrown = null; - public AnnotatedThrowingClient(TypeEnum typeEnum) { - super(new StringClientEndpoint()); - this.typeEnum = typeEnum; - } + public AnnotatedThrowingClient(TypeEnum typeEnum) { + super(new StringClientEndpoint()); + this.typeEnum = typeEnum; + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - switch (typeEnum) { - case PONG: - session.addMessageHandler(PongMessage.class, - new PongMessageHandler(clientEndpoint)); - try { - session.addMessageHandler(PongMessage.class, - new PongMessageHandler(clientEndpoint)); - } catch (RuntimeException e) { - thrown = e; - } - break; - case READER: - session.addMessageHandler(Reader.class, - new ReaderMessageHandler(clientEndpoint)); - try { - session.addMessageHandler(Reader.class, - new ReaderMessageHandler(clientEndpoint)); - } catch (RuntimeException e) { - thrown = e; - } - break; - case INPUTSTREAM: - session.addMessageHandler(InputStream.class, - new InputStreamMessageHandler(clientEndpoint)); - try { - session.addMessageHandler(InputStream.class, - new InputStreamMessageHandler(clientEndpoint)); - } catch (RuntimeException e) { - thrown = e; - } - break; - case STRING_PARTIAL: - session.addMessageHandler(String.class, - new StringPartialMessageHandler(clientEndpoint)); - try { - session.addMessageHandler(String.class, - new StringPartialMessageHandler(clientEndpoint)); - } catch (RuntimeException e) { - thrown = e; - } - break; - default: - break; - } - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + switch (typeEnum) { + case PONG: + session.addMessageHandler(PongMessage.class, new PongMessageHandler(clientEndpoint)); + try { + session.addMessageHandler(PongMessage.class, new PongMessageHandler(clientEndpoint)); + } catch (RuntimeException e) { + thrown = e; + } + break; + case READER: + session.addMessageHandler(Reader.class, new ReaderMessageHandler(clientEndpoint)); + try { + session.addMessageHandler(Reader.class, new ReaderMessageHandler(clientEndpoint)); + } catch (RuntimeException e) { + thrown = e; + } + break; + case INPUTSTREAM: + session.addMessageHandler(InputStream.class, new InputStreamMessageHandler(clientEndpoint)); + try { + session.addMessageHandler(InputStream.class, new InputStreamMessageHandler(clientEndpoint)); + } catch (RuntimeException e) { + thrown = e; + } + break; + case STRING_PARTIAL: + session.addMessageHandler(String.class, new StringPartialMessageHandler(clientEndpoint)); + try { + session.addMessageHandler(String.class, new StringPartialMessageHandler(clientEndpoint)); + } catch (RuntimeException e) { + thrown = e; + } + break; + default: + break; + } + super.onOpen(session, config); + } - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } - public RuntimeException getThrown() { - return thrown; - } + public RuntimeException getThrown() { + return thrown; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteArrayMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteArrayMessageHandler.java index 129f6e3d91..69f0f5a4e5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteArrayMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteArrayMessageHandler.java @@ -21,17 +21,17 @@ public class ByteArrayMessageHandler implements MessageHandler.Whole { - MixedProgramaticEndpoint endpoint; + MixedProgramaticEndpoint endpoint; - public static final String HANDLER_SAYS = "ByteArrayMessageHandler says: "; + public static final String HANDLER_SAYS = "ByteArrayMessageHandler says: "; - public ByteArrayMessageHandler(MixedProgramaticEndpoint endpoint) { - super(); - this.endpoint = endpoint; - } + public ByteArrayMessageHandler(MixedProgramaticEndpoint endpoint) { + super(); + this.endpoint = endpoint; + } - @Override - public void onMessage(byte[] message) { - endpoint.onMessage(HANDLER_SAYS + new String(message)); - } + @Override + public void onMessage(byte[] message) { + endpoint.onMessage(HANDLER_SAYS + new String(message)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteArrayPartialMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteArrayPartialMessageHandler.java index 9228aa68a4..277d0cb0f4 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteArrayPartialMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteArrayPartialMessageHandler.java @@ -19,24 +19,23 @@ import jakarta.websocket.MessageHandler; -public class ByteArrayPartialMessageHandler - implements MessageHandler.Partial { +public class ByteArrayPartialMessageHandler implements MessageHandler.Partial { - MixedProgramaticEndpoint endpoint; + MixedProgramaticEndpoint endpoint; - public static final String HANDLER_SAYS = "ByteArrayPartialMessageHandler says: "; + public static final String HANDLER_SAYS = "ByteArrayPartialMessageHandler says: "; - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); - public ByteArrayPartialMessageHandler(MixedProgramaticEndpoint endpoint) { - super(); - this.endpoint = endpoint; - } + public ByteArrayPartialMessageHandler(MixedProgramaticEndpoint endpoint) { + super(); + this.endpoint = endpoint; + } - @Override - public void onMessage(byte[] message, boolean finite) { - sb.append(new String(message)); - if (finite) - endpoint.onMessage(HANDLER_SAYS + sb.toString()); - } + @Override + public void onMessage(byte[] message, boolean finite) { + sb.append(new String(message)); + if (finite) + endpoint.onMessage(HANDLER_SAYS + sb.toString()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteBufferMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteBufferMessageHandler.java index 7e4825bbc6..9a3c38c4bc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteBufferMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteBufferMessageHandler.java @@ -23,20 +23,19 @@ import jakarta.websocket.MessageHandler; -public class ByteBufferMessageHandler - implements MessageHandler.Whole { +public class ByteBufferMessageHandler implements MessageHandler.Whole { - MixedProgramaticEndpoint endpoint; + MixedProgramaticEndpoint endpoint; - public static final String HANDLER_SAYS = "ByteBufferMessageHandler says: "; + public static final String HANDLER_SAYS = "ByteBufferMessageHandler says: "; - public ByteBufferMessageHandler(MixedProgramaticEndpoint endpoint) { - super(); - this.endpoint = endpoint; - } + public ByteBufferMessageHandler(MixedProgramaticEndpoint endpoint) { + super(); + this.endpoint = endpoint; + } - @Override - public void onMessage(ByteBuffer message) { - endpoint.onMessage(HANDLER_SAYS + IOUtil.byteBufferToString(message)); - } + @Override + public void onMessage(ByteBuffer message) { + endpoint.onMessage(HANDLER_SAYS + IOUtil.byteBufferToString(message)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteBufferPartialMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteBufferPartialMessageHandler.java index d112d3f0f7..bfcf228e44 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteBufferPartialMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ByteBufferPartialMessageHandler.java @@ -24,24 +24,23 @@ import jakarta.websocket.MessageHandler; -public class ByteBufferPartialMessageHandler - implements MessageHandler.Partial { +public class ByteBufferPartialMessageHandler implements MessageHandler.Partial { - ClientEndpoint endpoint; + ClientEndpoint endpoint; - public static final String HANDLER_SAYS = "ByteBufferPartialMessageHandler says: "; + public static final String HANDLER_SAYS = "ByteBufferPartialMessageHandler says: "; - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); - public ByteBufferPartialMessageHandler(ClientEndpoint endpoint) { - super(); - this.endpoint = endpoint; - } + public ByteBufferPartialMessageHandler(ClientEndpoint endpoint) { + super(); + this.endpoint = endpoint; + } - @Override - public void onMessage(ByteBuffer message, boolean finite) { - sb.append(IOUtil.byteBufferToString(message)); - if (finite) - endpoint.onMessage(HANDLER_SAYS + sb.toString()); - } + @Override + public void onMessage(ByteBuffer message, boolean finite) { + sb.append(IOUtil.byteBufferToString(message)); + if (finite) + endpoint.onMessage(HANDLER_SAYS + sb.toString()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/InputStreamMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/InputStreamMessageHandler.java index c9ed19a487..77954e1f7e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/InputStreamMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/InputStreamMessageHandler.java @@ -24,24 +24,23 @@ import jakarta.websocket.MessageHandler; -public class InputStreamMessageHandler - implements MessageHandler.Whole { - - ClientEndpoint endpoint; - - public static final String HANDLER_SAYS = "InputStreamMessageHandler says: "; - - public InputStreamMessageHandler(ClientEndpoint endpoint) { - super(); - this.endpoint = endpoint; - } - - @Override - public void onMessage(InputStream message) { - try { - endpoint.onMessage(HANDLER_SAYS + IOUtil.readFromStream(message)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } +public class InputStreamMessageHandler implements MessageHandler.Whole { + + ClientEndpoint endpoint; + + public static final String HANDLER_SAYS = "InputStreamMessageHandler says: "; + + public InputStreamMessageHandler(ClientEndpoint endpoint) { + super(); + this.endpoint = endpoint; + } + + @Override + public void onMessage(InputStream message) { + try { + endpoint.onMessage(HANDLER_SAYS + IOUtil.readFromStream(message)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/LinkedListHashSetMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/LinkedListHashSetMessageHandler.java index b1ddc6ef65..487abab78e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/LinkedListHashSetMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/LinkedListHashSetMessageHandler.java @@ -24,22 +24,20 @@ import jakarta.websocket.MessageHandler; -public class LinkedListHashSetMessageHandler - implements MessageHandler.Whole>> { +public class LinkedListHashSetMessageHandler implements MessageHandler.Whole>> { - MixedProgramaticEndpoint endpoint; + MixedProgramaticEndpoint endpoint; - public static final String HANDLER_SAYS = "LinkedListHashSetMessageHandler says: "; + public static final String HANDLER_SAYS = "LinkedListHashSetMessageHandler says: "; - public LinkedListHashSetMessageHandler(MixedProgramaticEndpoint endpoint) { - super(); - this.endpoint = endpoint; - } + public LinkedListHashSetMessageHandler(MixedProgramaticEndpoint endpoint) { + super(); + this.endpoint = endpoint; + } - @Override - public void onMessage(LinkedList> arg0) { - endpoint.onMessage( - HANDLER_SAYS + ListHashSetTextEncoder.listHashSetToString(arg0)); - } + @Override + public void onMessage(LinkedList> arg0) { + endpoint.onMessage(HANDLER_SAYS + ListHashSetTextEncoder.listHashSetToString(arg0)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/MixedProgramaticEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/MixedProgramaticEndpoint.java index f1fa57a045..97fba7982a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/MixedProgramaticEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/MixedProgramaticEndpoint.java @@ -37,85 +37,74 @@ public class MixedProgramaticEndpoint extends ClientEndpoint { - TypeEnum type; + TypeEnum type; - Entity entity; + Entity entity; - public MixedProgramaticEndpoint(TypeEnum type, Entity entity) { - this.type = type; - this.entity = entity; - } + public MixedProgramaticEndpoint(TypeEnum type, Entity entity) { + this.type = type; + this.entity = entity; + } - @Override - @SuppressWarnings("unchecked") - public void onOpen(Session session, EndpointConfig config) { - switch (type) { - case LINKEDLIST_HASHSET_TEXT: - LinkedList> list = new LinkedList<>(); + @Override + @SuppressWarnings("unchecked") + public void onOpen(Session session, EndpointConfig config) { + switch (type) { + case LINKEDLIST_HASHSET_TEXT: + LinkedList> list = new LinkedList<>(); - Class>> clzLLHS = (Class>>) list - .getClass(); - session.addMessageHandler(clzLLHS, - new LinkedListHashSetMessageHandler(this)); - break; - case LIST_TEXT: - session.addMessageHandler(StringList.class, - new StringListWholeMessageHandler(this)); - break; - case STRINGBEAN: - session.addMessageHandler(StringBean.class, - new StringBeanMessageHandler(this)); - break; - case STRING_WHOLE: - session.addMessageHandler(String.class, - new StringTextMessageHandler(this)); - break; - case STRING_PARTIAL: - session.addMessageHandler(String.class, - new StringPartialMessageHandler(this)); - break; - case READER: - session.addMessageHandler(Reader.class, new ReaderMessageHandler(this)); - break; - case PONG: - session.addMessageHandler(PongMessage.class, - new PongMessageHandler(this)); - // send pingmessage to receive pongmessage - break; - case BYTEBUFFER_WHOLE: - session.addMessageHandler(ByteBuffer.class, - new ByteBufferMessageHandler(this)); - break; - case BYTEBUFFER_PARTIAL: - session.addMessageHandler(ByteBuffer.class, - new ByteBufferPartialMessageHandler(this)); - break; - case BYTEARRAY_WHOLE: - byte[] ba = new byte[0]; - Class baclz = (Class) ba.getClass(); - session.addMessageHandler(baclz, new ByteArrayMessageHandler(this)); - break; - case BYTEARRAY_PARTIAL: - ba = new byte[0]; - baclz = (Class) ba.getClass(); - session.addMessageHandler(baclz, - new ByteArrayPartialMessageHandler(this)); - break; - case INPUTSTREAM: - session.addMessageHandler(InputStream.class, - new InputStreamMessageHandler(this)); - break; - default: - break; - } - new SendMessageCallback(entity).onOpen(session, config); - } + Class>> clzLLHS = (Class>>) list.getClass(); + session.addMessageHandler(clzLLHS, new LinkedListHashSetMessageHandler(this)); + break; + case LIST_TEXT: + session.addMessageHandler(StringList.class, new StringListWholeMessageHandler(this)); + break; + case STRINGBEAN: + session.addMessageHandler(StringBean.class, new StringBeanMessageHandler(this)); + break; + case STRING_WHOLE: + session.addMessageHandler(String.class, new StringTextMessageHandler(this)); + break; + case STRING_PARTIAL: + session.addMessageHandler(String.class, new StringPartialMessageHandler(this)); + break; + case READER: + session.addMessageHandler(Reader.class, new ReaderMessageHandler(this)); + break; + case PONG: + session.addMessageHandler(PongMessage.class, new PongMessageHandler(this)); + // send pingmessage to receive pongmessage + break; + case BYTEBUFFER_WHOLE: + session.addMessageHandler(ByteBuffer.class, new ByteBufferMessageHandler(this)); + break; + case BYTEBUFFER_PARTIAL: + session.addMessageHandler(ByteBuffer.class, new ByteBufferPartialMessageHandler(this)); + break; + case BYTEARRAY_WHOLE: + byte[] ba = new byte[0]; + Class baclz = (Class) ba.getClass(); + session.addMessageHandler(baclz, new ByteArrayMessageHandler(this)); + break; + case BYTEARRAY_PARTIAL: + ba = new byte[0]; + baclz = (Class) ba.getClass(); + session.addMessageHandler(baclz, new ByteArrayPartialMessageHandler(this)); + break; + case INPUTSTREAM: + session.addMessageHandler(InputStream.class, new InputStreamMessageHandler(this)); + break; + default: + break; + } + new SendMessageCallback(entity).onOpen(session, config); + } - public void sendMessage(Session session) { - try { - session.getBasicRemote().sendText(entity.getEntityAt(String.class, 0)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + public void sendMessage(Session session) { + try { + session.getBasicRemote().sendText(entity.getEntityAt(String.class, 0)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/PongMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/PongMessageHandler.java index 03d74faee8..108a2c75c3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/PongMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/PongMessageHandler.java @@ -25,18 +25,17 @@ public class PongMessageHandler implements MessageHandler.Whole { - ClientEndpoint endpoint; + ClientEndpoint endpoint; - public static final String HANDLER_SAYS = "PongMessageHandler says: "; + public static final String HANDLER_SAYS = "PongMessageHandler says: "; - public PongMessageHandler(ClientEndpoint endpoint) { - this.endpoint = endpoint; - } + public PongMessageHandler(ClientEndpoint endpoint) { + this.endpoint = endpoint; + } - @Override - public void onMessage(PongMessage msg) { - endpoint.onMessage( - HANDLER_SAYS + IOUtil.byteBufferToString(msg.getApplicationData())); - } + @Override + public void onMessage(PongMessage msg) { + endpoint.onMessage(HANDLER_SAYS + IOUtil.byteBufferToString(msg.getApplicationData())); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ReaderMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ReaderMessageHandler.java index 8f617efb25..712ba2ffd7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ReaderMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/ReaderMessageHandler.java @@ -26,23 +26,23 @@ import jakarta.websocket.MessageHandler; public class ReaderMessageHandler implements MessageHandler.Whole { - ClientEndpoint endpoint; - - public static final String HANDLER_SAYS = "ReaderMessageHandler says: "; - - public ReaderMessageHandler(ClientEndpoint endpoint) { - this.endpoint = endpoint; - } - - @Override - public void onMessage(Reader message) { - String msg = null; - try { - msg = IOUtil.readFromReader(message); - } catch (IOException e) { - throw new RuntimeException(e); - } - endpoint.onMessage(HANDLER_SAYS + msg); - } + ClientEndpoint endpoint; + + public static final String HANDLER_SAYS = "ReaderMessageHandler says: "; + + public ReaderMessageHandler(ClientEndpoint endpoint) { + this.endpoint = endpoint; + } + + @Override + public void onMessage(Reader message) { + String msg = null; + try { + msg = IOUtil.readFromReader(message); + } catch (IOException e) { + throw new RuntimeException(e); + } + endpoint.onMessage(HANDLER_SAYS + msg); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringBeanMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringBeanMessageHandler.java index 85be57e8a7..835d475147 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringBeanMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringBeanMessageHandler.java @@ -21,20 +21,19 @@ import jakarta.websocket.MessageHandler; -public class StringBeanMessageHandler - implements MessageHandler.Whole { +public class StringBeanMessageHandler implements MessageHandler.Whole { - MixedProgramaticEndpoint endpoint; + MixedProgramaticEndpoint endpoint; - public static final String HANDLER_SAYS = "StringBeanMessageHandler says: "; + public static final String HANDLER_SAYS = "StringBeanMessageHandler says: "; - public StringBeanMessageHandler(MixedProgramaticEndpoint endpoint) { - this.endpoint = endpoint; - } + public StringBeanMessageHandler(MixedProgramaticEndpoint endpoint) { + this.endpoint = endpoint; + } - @Override - public void onMessage(StringBean message) { - endpoint.onMessage(HANDLER_SAYS + message.get()); - } + @Override + public void onMessage(StringBean message) { + endpoint.onMessage(HANDLER_SAYS + message.get()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringListWholeMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringListWholeMessageHandler.java index 8500b44fa0..64a711281c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringListWholeMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringListWholeMessageHandler.java @@ -21,20 +21,19 @@ import jakarta.websocket.MessageHandler; -public class StringListWholeMessageHandler - implements MessageHandler.Whole { +public class StringListWholeMessageHandler implements MessageHandler.Whole { - MixedProgramaticEndpoint endpoint; + MixedProgramaticEndpoint endpoint; - public static final String HANDLER_SAYS = "LinkedListWholeMessageHandler says: "; + public static final String HANDLER_SAYS = "LinkedListWholeMessageHandler says: "; - public StringListWholeMessageHandler(MixedProgramaticEndpoint endpoint) { - super(); - this.endpoint = endpoint; - } + public StringListWholeMessageHandler(MixedProgramaticEndpoint endpoint) { + super(); + this.endpoint = endpoint; + } - @Override - public void onMessage(StringList message) { - endpoint.onMessage(HANDLER_SAYS + message.get(0).toString()); - } + @Override + public void onMessage(StringList message) { + endpoint.onMessage(HANDLER_SAYS + message.get(0).toString()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringPartialMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringPartialMessageHandler.java index e25859ef8f..f28b2c1c22 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringPartialMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringPartialMessageHandler.java @@ -21,25 +21,24 @@ import jakarta.websocket.MessageHandler; -public class StringPartialMessageHandler - implements MessageHandler.Partial { +public class StringPartialMessageHandler implements MessageHandler.Partial { - ClientEndpoint endpoint; + ClientEndpoint endpoint; - public static final String HANDLER_SAYS = "StringPartialMessageHandler says: "; + public static final String HANDLER_SAYS = "StringPartialMessageHandler says: "; - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); - public StringPartialMessageHandler(ClientEndpoint endpoint) { - super(); - this.endpoint = endpoint; - } + public StringPartialMessageHandler(ClientEndpoint endpoint) { + super(); + this.endpoint = endpoint; + } - @Override - public void onMessage(String message, boolean finite) { - sb.append(message); - if (finite) - endpoint.onMessage(HANDLER_SAYS + sb.toString()); - } + @Override + public void onMessage(String message, boolean finite) { + sb.append(message); + if (finite) + endpoint.onMessage(HANDLER_SAYS + sb.toString()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringTextMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringTextMessageHandler.java index a7a936e2b9..d3cfef8a67 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringTextMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/StringTextMessageHandler.java @@ -23,18 +23,18 @@ public class StringTextMessageHandler implements MessageHandler.Whole { - ClientEndpoint endpoint; + ClientEndpoint endpoint; - public static final String HANDLER_SAYS = "StringTextMessageHandler says: "; + public static final String HANDLER_SAYS = "StringTextMessageHandler says: "; - public StringTextMessageHandler(ClientEndpoint endpoint) { - super(); - this.endpoint = endpoint; - } + public StringTextMessageHandler(ClientEndpoint endpoint) { + super(); + this.endpoint = endpoint; + } - @Override - public void onMessage(String message) { - endpoint.onMessage(HANDLER_SAYS + message); - } + @Override + public void onMessage(String message) { + endpoint.onMessage(HANDLER_SAYS + message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCBinaryEchoServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCBinaryEchoServerEndpoint.java index 954b30f8d0..8a2e9a5a09 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCBinaryEchoServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCBinaryEchoServerEndpoint.java @@ -29,18 +29,18 @@ @ServerEndpoint(value = "/binecho") public class WSCBinaryEchoServerEndpoint { - public static final String SAYS = "Binary Server says:"; + public static final String SAYS = "Binary Server says:"; - @OnMessage - public ByteBuffer onMessage(ByteBuffer text) { - return ByteBuffer.wrap((SAYS + IOUtil.byteBufferToString(text)).getBytes()); - } + @OnMessage + public ByteBuffer onMessage(ByteBuffer text) { + return ByteBuffer.wrap((SAYS + IOUtil.byteBufferToString(text)).getBytes()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendBinary(ByteBuffer.wrap(message.getBytes())); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendBinary(ByteBuffer.wrap(message.getBytes())); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCClient.java deleted file mode 100644 index da251ecd23..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCClient.java +++ /dev/null @@ -1,474 +0,0 @@ -/* - * Copyright (c) 2014, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.client; - -import java.nio.ByteBuffer; -import java.util.LinkedList; -import java.util.List; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.StringPingMessage; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryDecoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamDecoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; -import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.AlternativeInputStreamDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.AlternativeReaderDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.LinkedListHashSetTextDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.StringListTextDecoder; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.TypeEnum; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.Decoder; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSCClient extends WebSocketCommonClient { - private static final long serialVersionUID = 0; - - protected static final String ECHO = "Echo message"; - - protected static final String ECHO_PARTIAL = "second part send partially"; - - protected static final String ANYTHING = "Anything"; - - public WSCClient() { - setContextRoot("wsc_ee_jakarta_websocket_session11_client_web"); - logExceptionOnInvocation(false); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* Run test */ - /* - * @testName: linkedListHashSetTextHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void linkedListHashSetTextHandlerTest() throws Exception { - setDecoder(TypeEnum.LINKEDLIST_HASHSET_TEXT, - LinkedListHashSetTextDecoder.class); - invoke("echo", ANYTHING, LinkedListHashSetMessageHandler.HANDLER_SAYS, - WSCEchoServerEndpoint.SAYS, ECHO); - logMsg( - "addMessageHandler(LinkedList>.class, Whole>>) works as expected."); - } - - /* - * @testName: textStringBeanHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void textStringBeanHandlerTest() throws Exception { - setDecoder(TypeEnum.STRINGBEAN, StringBeanTextDecoder.class); - invoke("echo", ANYTHING, StringBeanMessageHandler.HANDLER_SAYS, - WSCEchoServerEndpoint.SAYS, ECHO); - logMsg( - "addMessageHandler(StringBean.class, Whole) works as expected."); - } - - /* - * @testName: textStreamStringBeanHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void textStreamStringBeanHandlerTest() throws Exception { - setDecoder(TypeEnum.STRINGBEAN, StringBeanTextStreamDecoder.class); - invoke("echo", ANYTHING, StringBeanMessageHandler.HANDLER_SAYS, - WSCEchoServerEndpoint.SAYS, ECHO); - logMsg( - "addMessageHandler(StringBean.class, Whole) works as expected."); - } - - /* - * @testName: linkedListTextHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void linkedListTextHandlerTest() throws Exception { - setDecoder(TypeEnum.LIST_TEXT, StringListTextDecoder.class); - invoke("echo", ANYTHING, StringListWholeMessageHandler.HANDLER_SAYS, - WSCEchoServerEndpoint.SAYS, ECHO); - logMsg( - "addMessageHandler(StringList.class, Whole) works as expected."); - } - - /* - * @testName: stringTextHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void stringTextHandlerTest() throws Exception { - setDecoder(TypeEnum.STRING_WHOLE, null); - invoke("echo", ANYTHING, StringTextMessageHandler.HANDLER_SAYS, - WSCEchoServerEndpoint.SAYS, ECHO); - logMsg("addMessageHandler(String.class, Whole) works as expected."); - } - - /* - * @testName: readerMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:38; - * - * @test_Strategy: test the binary decoder throws decoderException and it is - * caught in @OnError - */ - public void readerMessageHandlerTest() throws Exception { - setDecoderAndEntity(TypeEnum.READER, null, ECHO); - invoke("echo", ANYTHING, ReaderMessageHandler.HANDLER_SAYS, - WSCEchoServerEndpoint.SAYS, ECHO); - logMsg("addMessageHandler(Reader.class, Whole) works as expected."); - } - - // ----------------------------------------------------------------------- - // Control - // ----------------------------------------------------------------------- - - /* - * @testName: pongMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void pongMessageHandlerTest() throws Exception { - setDecoderAndEntity(TypeEnum.PONG, null, new StringPingMessage(ECHO)); - invoke("echo", ANYTHING, PongMessageHandler.HANDLER_SAYS, ECHO); - logMsg( - "addMessageHandler(PongMessage.class, Whole) works as expected."); - } - - // ----------------------------------------------------------------------- - // Binary - // ----------------------------------------------------------------------- - - /* - * @testName: byteBufferMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void byteBufferMessageHandlerTest() throws Exception { - setDecoderAndEntity(TypeEnum.BYTEBUFFER_WHOLE, null, - ByteBuffer.wrap(ECHO.getBytes())); - invoke("binecho", ANYTHING, ByteBufferMessageHandler.HANDLER_SAYS, - WSCBinaryEchoServerEndpoint.SAYS, ECHO); - logMsg( - "addMessageHandler(ByteBuffer.class, Whole) works as expected."); - } - - /* - * @testName: byteArrayMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void byteArrayMessageHandlerTest() throws Exception { - setDecoderAndEntity(TypeEnum.BYTEARRAY_WHOLE, null, ECHO.getBytes()); - invoke("binecho", ANYTHING, ByteArrayMessageHandler.HANDLER_SAYS, - WSCBinaryEchoServerEndpoint.SAYS, ECHO); - logMsg("addMessageHandler(byte[].class, Whole) works as expected."); - } - - /* - * @testName: inputStreamMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void inputStreamMessageHandlerTest() throws Exception { - setDecoderAndEntity(TypeEnum.INPUTSTREAM, null, - ByteBuffer.wrap(ECHO.getBytes())); - invoke("binecho", ANYTHING, InputStreamMessageHandler.HANDLER_SAYS, - WSCBinaryEchoServerEndpoint.SAYS, ECHO); - logMsg( - "addMessageHandler(InputStream.class, Whole) works as expected."); - } - - /* - * @testName: binaryStringBeanMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void binaryStringBeanMessageHandlerTest() throws Exception { - setDecoderAndEntity(TypeEnum.STRINGBEAN, StringBeanBinaryDecoder.class, - ByteBuffer.wrap(ECHO.getBytes())); - invoke("binecho", ANYTHING, StringBeanMessageHandler.HANDLER_SAYS, - WSCBinaryEchoServerEndpoint.SAYS, ECHO); - logMsg( - "addMessageHandler(StringBean.class, Whole) works as expected."); - } - - /* - * @testName: binaryStreamStringBeanMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void binaryStreamStringBeanMessageHandlerTest() throws Exception { - setDecoderAndEntity(TypeEnum.STRINGBEAN, - StringBeanBinaryStreamDecoder.class, ByteBuffer.wrap(ECHO.getBytes())); - invoke("binecho", ANYTHING, StringBeanMessageHandler.HANDLER_SAYS, - WSCBinaryEchoServerEndpoint.SAYS, ECHO); - logMsg( - "addMessageHandler(StringBean.class, Whole) works as expected."); - } - - // ----------------------------------------------------------------------- - // Partial - // ----------------------------------------------------------------------- - /* - * @testName: stringPartialHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:213; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void stringPartialHandlerTest() throws Exception { - setDecoderAndEntity(TypeEnum.STRING_PARTIAL, null, ECHO, ECHO_PARTIAL); - invoke("echo", ANYTHING, StringPartialMessageHandler.HANDLER_SAYS, - WSCEchoServerEndpoint.SAYS, ECHO, ECHO_PARTIAL); - logMsg( - "addMessageHandler(String.class, Partial) works as expected."); - } - - /* - * @testName: byteBufferPartialMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:213; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void byteBufferPartialMessageHandlerTest() throws Exception { - setDecoderAndEntity(TypeEnum.BYTEBUFFER_PARTIAL, null, - ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(ECHO_PARTIAL.getBytes())); - invoke("binecho", ANYTHING, ByteBufferPartialMessageHandler.HANDLER_SAYS, - WSCBinaryEchoServerEndpoint.SAYS, ECHO, ECHO_PARTIAL); - logMsg( - "addMessageHandler(ByteBuffer.class, Partial) works as expected."); - } - - /* - * @testName: byteArrayPartialMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:213; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void byteArrayPartialMessageHandlerTest() throws Exception { - setDecoderAndEntity(TypeEnum.BYTEARRAY_PARTIAL, null, - ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(ECHO_PARTIAL.getBytes())); - invoke("binecho", ANYTHING, ByteArrayPartialMessageHandler.HANDLER_SAYS, - WSCBinaryEchoServerEndpoint.SAYS, ECHO, ECHO_PARTIAL); - logMsg( - "addMessageHandler(byte[].class, Partial) works as expected."); - } - - // ----------------------------------------------------------------------- - // Annotated - // ----------------------------------------------------------------------- - - /* - * @testName: annotatedTextReaderClientTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void annotatedTextReaderClientTest() throws Exception { - setAnnotatedClientEndpoint(new AnnotatedTextClient()); - invoke("echo", ECHO, ReaderMessageHandler.HANDLER_SAYS, - AlternativeReaderDecoder.DECODER_SAYS, WSCEchoServerEndpoint.SAYS, - ECHO); - logMsg("addMessageHandler(Reader.class, Whole) works as expected."); - } - - /* - * @testName: annotatedBinaryInputStreamClientTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void annotatedBinaryInputStreamClientTest() throws Exception { - setAnnotatedClientEndpoint(new AnnotatedBinaryClient()); - invoke("binecho", ByteBuffer.wrap(ECHO.getBytes()), - InputStreamMessageHandler.HANDLER_SAYS, - AlternativeInputStreamDecoder.DECODER_SAYS, - WSCBinaryEchoServerEndpoint.SAYS, ECHO); - logMsg( - "addMessageHandler(InputStream.class, Whole) works as expected."); - } - - // ----------------------------------------------------------------------- - // Exceptions - // ----------------------------------------------------------------------- - - /* - * @testName: twiceAddMessageHandlerReaderThrowsExceptionTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Adding more than one of any one type will result in a - * runtime exception. - */ - public void twiceAddMessageHandlerReaderThrowsExceptionTest() throws Exception { - AnnotatedThrowingClient client = new AnnotatedThrowingClient( - TypeEnum.READER); - setAnnotatedClientEndpoint(client); - invoke("echo", ECHO, ReaderMessageHandler.HANDLER_SAYS, - WSCEchoServerEndpoint.SAYS, ECHO); - assertNotNull(client.getThrown(), - "there is no exception thrown when adding MessageHandler twice"); - logMsg( - "addMessageHandler(Reader.class, Whole) throws RuntimeException as expected when called twice:", - client.getThrown().getMessage()); - } - - /* - * @testName: twiceAddMessageHandlerInputStreamThrowsExceptionTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Adding more than one of any one type will result in a - * runtime exception. - */ - public void twiceAddMessageHandlerInputStreamThrowsExceptionTest() - throws Exception { - AnnotatedThrowingClient client = new AnnotatedThrowingClient( - TypeEnum.INPUTSTREAM); - setAnnotatedClientEndpoint(client); - invoke("binecho", ByteBuffer.wrap(ECHO.getBytes()), - InputStreamMessageHandler.HANDLER_SAYS, - WSCBinaryEchoServerEndpoint.SAYS, ECHO); - assertNotNull(client.getThrown(), - "there is no exception thrown when adding MessageHandler twice"); - logMsg( - "addMessageHandler(InputStream.class, Whole) throws RuntimeException as expected when called twice:", - client.getThrown().getMessage()); - } - - /* - * @testName: twiceAddMessageHandlerPongMessageThrowsExceptionTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Adding more than one of any one type will result in a - * runtime exception. - */ - public void twiceAddMessageHandlerPongMessageThrowsExceptionTest() - throws Exception { - AnnotatedThrowingClient client = new AnnotatedThrowingClient(TypeEnum.PONG); - setAnnotatedClientEndpoint(client); - invoke("echo", new StringPingMessage(ECHO), PongMessageHandler.HANDLER_SAYS, - ECHO); - assertNotNull(client.getThrown(), - "there is no exception thrown when adding MessageHandler twice"); - logMsg( - "addMessageHandler(PongMessage.class, Whole) throws RuntimeException as expected when called twice:", - client.getThrown().getMessage()); - } - - /* - * @testName: twiceAddMessageHandlerPartialStringThrowsExceptionTest - * - * @assertion_ids: WebSocket:JAVADOC:213; - * - * @test_Strategy: Adding more than one of any one type will result in a - * runtime exception. - */ - public void twiceAddMessageHandlerPartialStringThrowsExceptionTest() - throws Exception { - AnnotatedThrowingClient client = new AnnotatedThrowingClient( - TypeEnum.STRING_PARTIAL); - setAnnotatedClientEndpoint(client); - setEntity(ECHO, ECHO_PARTIAL); - setProperty(Property.SEARCH_STRING, - StringPartialMessageHandler.HANDLER_SAYS); - setProperty(Property.SEARCH_STRING, WSCEchoServerEndpoint.SAYS); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, ECHO_PARTIAL); - setProperty(Property.REQUEST, buildRequest("echo")); - invoke(); - assertNotNull(client.getThrown(), - "there is no exception thrown when adding MessageHandler twice"); - logMsg( - "addMessageHandler(String.class, Partial) throws RuntimeException as expected when called twice:", - client.getThrown().getMessage()); - } - - // /////////////////////////////////////////////////////////////////////// - protected void setDecoder(TypeEnum type, - Class decoderClass) { - setDecoderAndEntity(type, decoderClass, ECHO); - } - - protected void setDecoderAndEntity(TypeEnum type, - Class decoderClass, Object... entity) { - setEntity(entity); - MixedProgramaticEndpoint endpoint = new MixedProgramaticEndpoint(type, - this.entity); - setClientEndpointInstance(endpoint); - List> list = new LinkedList<>(); - if (decoderClass != null) - list.add(decoderClass); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .decoders(list).build(); - setClientEndpointConfig(config); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCClientIT.java new file mode 100644 index 0000000000..76acf805d7 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCClientIT.java @@ -0,0 +1,438 @@ +/* + * Copyright (c) 2014, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.client; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.LinkedList; +import java.util.List; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.StringPingMessage; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanBinaryStreamDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextStreamDecoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.AlternativeInputStreamDecoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.AlternativeReaderDecoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.LinkedListHashSetTextDecoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.StringListTextDecoder; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.TypeEnum; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.Decoder; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = 0; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_jakarta_websocket_session11_client_web.war"); + archive.addPackages(true, "com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.client"); + archive.addPackage(IOUtil.class.getPackage()); + return archive; + } + + protected static final String ECHO = "Echo message"; + + protected static final String ECHO_PARTIAL = "second part send partially"; + + protected static final String ANYTHING = "Anything"; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_jakarta_websocket_session11_client_web"); + logExceptionOnInvocation(false); + } + + /* Run test */ + /* + * @testName: linkedListHashSetTextHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void linkedListHashSetTextHandlerTest() throws Exception { + setDecoder(TypeEnum.LINKEDLIST_HASHSET_TEXT, LinkedListHashSetTextDecoder.class); + invoke("echo", ANYTHING, LinkedListHashSetMessageHandler.HANDLER_SAYS, WSCEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(LinkedList>.class, Whole>>) works as expected."); + } + + /* + * @testName: textStringBeanHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void textStringBeanHandlerTest() throws Exception { + setDecoder(TypeEnum.STRINGBEAN, StringBeanTextDecoder.class); + invoke("echo", ANYTHING, StringBeanMessageHandler.HANDLER_SAYS, WSCEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(StringBean.class, Whole) works as expected."); + } + + /* + * @testName: textStreamStringBeanHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void textStreamStringBeanHandlerTest() throws Exception { + setDecoder(TypeEnum.STRINGBEAN, StringBeanTextStreamDecoder.class); + invoke("echo", ANYTHING, StringBeanMessageHandler.HANDLER_SAYS, WSCEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(StringBean.class, Whole) works as expected."); + } + + /* + * @testName: linkedListTextHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void linkedListTextHandlerTest() throws Exception { + setDecoder(TypeEnum.LIST_TEXT, StringListTextDecoder.class); + invoke("echo", ANYTHING, StringListWholeMessageHandler.HANDLER_SAYS, WSCEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(StringList.class, Whole) works as expected."); + } + + /* + * @testName: stringTextHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void stringTextHandlerTest() throws Exception { + setDecoder(TypeEnum.STRING_WHOLE, null); + invoke("echo", ANYTHING, StringTextMessageHandler.HANDLER_SAYS, WSCEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(String.class, Whole) works as expected."); + } + + /* + * @testName: readerMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:38; + * + * @test_Strategy: test the binary decoder throws decoderException and it is + * caught in @OnError + */ + @Test + public void readerMessageHandlerTest() throws Exception { + setDecoderAndEntity(TypeEnum.READER, null, ECHO); + invoke("echo", ANYTHING, ReaderMessageHandler.HANDLER_SAYS, WSCEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(Reader.class, Whole) works as expected."); + } + + // ----------------------------------------------------------------------- + // Control + // ----------------------------------------------------------------------- + + /* + * @testName: pongMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void pongMessageHandlerTest() throws Exception { + setDecoderAndEntity(TypeEnum.PONG, null, new StringPingMessage(ECHO)); + invoke("echo", ANYTHING, PongMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(PongMessage.class, Whole) works as expected."); + } + + // ----------------------------------------------------------------------- + // Binary + // ----------------------------------------------------------------------- + + /* + * @testName: byteBufferMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void byteBufferMessageHandlerTest() throws Exception { + setDecoderAndEntity(TypeEnum.BYTEBUFFER_WHOLE, null, ByteBuffer.wrap(ECHO.getBytes())); + invoke("binecho", ANYTHING, ByteBufferMessageHandler.HANDLER_SAYS, WSCBinaryEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(ByteBuffer.class, Whole) works as expected."); + } + + /* + * @testName: byteArrayMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void byteArrayMessageHandlerTest() throws Exception { + setDecoderAndEntity(TypeEnum.BYTEARRAY_WHOLE, null, ECHO.getBytes()); + invoke("binecho", ANYTHING, ByteArrayMessageHandler.HANDLER_SAYS, WSCBinaryEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(byte[].class, Whole) works as expected."); + } + + /* + * @testName: inputStreamMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void inputStreamMessageHandlerTest() throws Exception { + setDecoderAndEntity(TypeEnum.INPUTSTREAM, null, ByteBuffer.wrap(ECHO.getBytes())); + invoke("binecho", ANYTHING, InputStreamMessageHandler.HANDLER_SAYS, WSCBinaryEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(InputStream.class, Whole) works as expected."); + } + + /* + * @testName: binaryStringBeanMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void binaryStringBeanMessageHandlerTest() throws Exception { + setDecoderAndEntity(TypeEnum.STRINGBEAN, StringBeanBinaryDecoder.class, ByteBuffer.wrap(ECHO.getBytes())); + invoke("binecho", ANYTHING, StringBeanMessageHandler.HANDLER_SAYS, WSCBinaryEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(StringBean.class, Whole) works as expected."); + } + + /* + * @testName: binaryStreamStringBeanMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void binaryStreamStringBeanMessageHandlerTest() throws Exception { + setDecoderAndEntity(TypeEnum.STRINGBEAN, StringBeanBinaryStreamDecoder.class, ByteBuffer.wrap(ECHO.getBytes())); + invoke("binecho", ANYTHING, StringBeanMessageHandler.HANDLER_SAYS, WSCBinaryEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(StringBean.class, Whole) works as expected."); + } + + // ----------------------------------------------------------------------- + // Partial + // ----------------------------------------------------------------------- + /* + * @testName: stringPartialHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:213; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void stringPartialHandlerTest() throws Exception { + setDecoderAndEntity(TypeEnum.STRING_PARTIAL, null, ECHO, ECHO_PARTIAL); + invoke("echo", ANYTHING, StringPartialMessageHandler.HANDLER_SAYS, WSCEchoServerEndpoint.SAYS, ECHO, + ECHO_PARTIAL); + logMsg("addMessageHandler(String.class, Partial) works as expected."); + } + + /* + * @testName: byteBufferPartialMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:213; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void byteBufferPartialMessageHandlerTest() throws Exception { + setDecoderAndEntity(TypeEnum.BYTEBUFFER_PARTIAL, null, ByteBuffer.wrap(ECHO.getBytes()), + ByteBuffer.wrap(ECHO_PARTIAL.getBytes())); + invoke("binecho", ANYTHING, ByteBufferPartialMessageHandler.HANDLER_SAYS, WSCBinaryEchoServerEndpoint.SAYS, + ECHO, ECHO_PARTIAL); + logMsg("addMessageHandler(ByteBuffer.class, Partial) works as expected."); + } + + /* + * @testName: byteArrayPartialMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:213; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void byteArrayPartialMessageHandlerTest() throws Exception { + setDecoderAndEntity(TypeEnum.BYTEARRAY_PARTIAL, null, ByteBuffer.wrap(ECHO.getBytes()), + ByteBuffer.wrap(ECHO_PARTIAL.getBytes())); + invoke("binecho", ANYTHING, ByteArrayPartialMessageHandler.HANDLER_SAYS, WSCBinaryEchoServerEndpoint.SAYS, ECHO, + ECHO_PARTIAL); + logMsg("addMessageHandler(byte[].class, Partial) works as expected."); + } + + // ----------------------------------------------------------------------- + // Annotated + // ----------------------------------------------------------------------- + + /* + * @testName: annotatedTextReaderClientTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void annotatedTextReaderClientTest() throws Exception { + setAnnotatedClientEndpoint(new AnnotatedTextClient()); + invoke("echo", ECHO, ReaderMessageHandler.HANDLER_SAYS, AlternativeReaderDecoder.DECODER_SAYS, + WSCEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(Reader.class, Whole) works as expected."); + } + + /* + * @testName: annotatedBinaryInputStreamClientTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void annotatedBinaryInputStreamClientTest() throws Exception { + setAnnotatedClientEndpoint(new AnnotatedBinaryClient()); + invoke("binecho", ByteBuffer.wrap(ECHO.getBytes()), InputStreamMessageHandler.HANDLER_SAYS, + AlternativeInputStreamDecoder.DECODER_SAYS, WSCBinaryEchoServerEndpoint.SAYS, ECHO); + logMsg("addMessageHandler(InputStream.class, Whole) works as expected."); + } + + // ----------------------------------------------------------------------- + // Exceptions + // ----------------------------------------------------------------------- + + /* + * @testName: twiceAddMessageHandlerReaderThrowsExceptionTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Adding more than one of any one type will result in a runtime + * exception. + */ + @Test + public void twiceAddMessageHandlerReaderThrowsExceptionTest() throws Exception { + AnnotatedThrowingClient client = new AnnotatedThrowingClient(TypeEnum.READER); + setAnnotatedClientEndpoint(client); + invoke("echo", ECHO, ReaderMessageHandler.HANDLER_SAYS, WSCEchoServerEndpoint.SAYS, ECHO); + assertNotNull(client.getThrown(), "there is no exception thrown when adding MessageHandler twice"); + logMsg("addMessageHandler(Reader.class, Whole) throws RuntimeException as expected when called twice:", + client.getThrown().getMessage()); + } + + /* + * @testName: twiceAddMessageHandlerInputStreamThrowsExceptionTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Adding more than one of any one type will result in a runtime + * exception. + */ + @Test + public void twiceAddMessageHandlerInputStreamThrowsExceptionTest() throws Exception { + AnnotatedThrowingClient client = new AnnotatedThrowingClient(TypeEnum.INPUTSTREAM); + setAnnotatedClientEndpoint(client); + invoke("binecho", ByteBuffer.wrap(ECHO.getBytes()), InputStreamMessageHandler.HANDLER_SAYS, + WSCBinaryEchoServerEndpoint.SAYS, ECHO); + assertNotNull(client.getThrown(), "there is no exception thrown when adding MessageHandler twice"); + logMsg("addMessageHandler(InputStream.class, Whole) throws RuntimeException as expected when called twice:", + client.getThrown().getMessage()); + } + + /* + * @testName: twiceAddMessageHandlerPongMessageThrowsExceptionTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Adding more than one of any one type will result in a runtime + * exception. + */ + @Test + public void twiceAddMessageHandlerPongMessageThrowsExceptionTest() throws Exception { + AnnotatedThrowingClient client = new AnnotatedThrowingClient(TypeEnum.PONG); + setAnnotatedClientEndpoint(client); + invoke("echo", new StringPingMessage(ECHO), PongMessageHandler.HANDLER_SAYS, ECHO); + assertNotNull(client.getThrown(), "there is no exception thrown when adding MessageHandler twice"); + logMsg("addMessageHandler(PongMessage.class, Whole) throws RuntimeException as expected when called twice:", + client.getThrown().getMessage()); + } + + /* + * @testName: twiceAddMessageHandlerPartialStringThrowsExceptionTest + * + * @assertion_ids: WebSocket:JAVADOC:213; + * + * @test_Strategy: Adding more than one of any one type will result in a runtime + * exception. + */ + @Test + public void twiceAddMessageHandlerPartialStringThrowsExceptionTest() throws Exception { + AnnotatedThrowingClient client = new AnnotatedThrowingClient(TypeEnum.STRING_PARTIAL); + setAnnotatedClientEndpoint(client); + setEntity(ECHO, ECHO_PARTIAL); + setProperty(Property.SEARCH_STRING, StringPartialMessageHandler.HANDLER_SAYS); + setProperty(Property.SEARCH_STRING, WSCEchoServerEndpoint.SAYS); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, ECHO_PARTIAL); + setProperty(Property.REQUEST, buildRequest("echo")); + invoke(); + assertNotNull(client.getThrown(), "there is no exception thrown when adding MessageHandler twice"); + logMsg("addMessageHandler(String.class, Partial) throws RuntimeException as expected when called twice:", + client.getThrown().getMessage()); + } + + // /////////////////////////////////////////////////////////////////////// + protected void setDecoder(TypeEnum type, Class decoderClass) { + setDecoderAndEntity(type, decoderClass, ECHO); + } + + protected void setDecoderAndEntity(TypeEnum type, Class decoderClass, Object... entity) { + setEntity(entity); + MixedProgramaticEndpoint endpoint = new MixedProgramaticEndpoint(type, this.entity); + setClientEndpointInstance(endpoint); + List> list = new LinkedList<>(); + if (decoderClass != null) + list.add(decoderClass); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().decoders(list).build(); + setClientEndpointConfig(config); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCEchoServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCEchoServerEndpoint.java index e3a1ec9457..3813a1cf45 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCEchoServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/client/WSCEchoServerEndpoint.java @@ -28,18 +28,19 @@ @ServerEndpoint(value = "/echo") public class WSCEchoServerEndpoint { - public static final String SAYS = "Text Server says:"; - - @OnMessage - public String onMessage(String text) { - return SAYS + text; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + + public static final String SAYS = "Text Server says:"; + + @OnMessage + public String onMessage(String text) { + return SAYS + text; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/AlternativeInputStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/AlternativeInputStreamDecoder.java index 9567ccdc7a..9a100b435e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/AlternativeInputStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/AlternativeInputStreamDecoder.java @@ -27,28 +27,27 @@ import jakarta.websocket.Decoder; import jakarta.websocket.EndpointConfig; -public class AlternativeInputStreamDecoder - implements Decoder.Binary { - - public static final String DECODER_SAYS = "InputStream decoder"; - - @Override - public void init(EndpointConfig config) { - } - - @Override - public void destroy() { - } - - @Override - public boolean willDecode(ByteBuffer bytes) { - return true; - } - - @Override - public InputStream decode(ByteBuffer bytes) throws DecodeException { - String s = DECODER_SAYS + IOUtil.byteBufferToString(bytes); - ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes()); - return bais; - } +public class AlternativeInputStreamDecoder implements Decoder.Binary { + + public static final String DECODER_SAYS = "InputStream decoder"; + + @Override + public void init(EndpointConfig config) { + } + + @Override + public void destroy() { + } + + @Override + public boolean willDecode(ByteBuffer bytes) { + return true; + } + + @Override + public InputStream decode(ByteBuffer bytes) throws DecodeException { + String s = DECODER_SAYS + IOUtil.byteBufferToString(bytes); + ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes()); + return bais; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/AlternativeReaderDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/AlternativeReaderDecoder.java index 3af856d741..a96fdc23aa 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/AlternativeReaderDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/AlternativeReaderDecoder.java @@ -27,27 +27,26 @@ public class AlternativeReaderDecoder implements Decoder.Text { - public static final String DECODER_SAYS = "Reader decoder"; - - @Override - public void init(EndpointConfig config) { - } - - @Override - public void destroy() { - } - - @Override - public Reader decode(String s) throws DecodeException { - ByteArrayInputStream bais = new ByteArrayInputStream( - (DECODER_SAYS + s).getBytes()); - Reader r = new InputStreamReader(bais); - return r; - } - - @Override - public boolean willDecode(String s) { - return true; - } + public static final String DECODER_SAYS = "Reader decoder"; + + @Override + public void init(EndpointConfig config) { + } + + @Override + public void destroy() { + } + + @Override + public Reader decode(String s) throws DecodeException { + ByteArrayInputStream bais = new ByteArrayInputStream((DECODER_SAYS + s).getBytes()); + Reader r = new InputStreamReader(bais); + return r; + } + + @Override + public boolean willDecode(String s) { + return true; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/LinkedListHashSetTextDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/LinkedListHashSetTextDecoder.java index 10690afd2b..69891f28c9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/LinkedListHashSetTextDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/LinkedListHashSetTextDecoder.java @@ -24,30 +24,28 @@ import jakarta.websocket.Decoder; import jakarta.websocket.EndpointConfig; -public class LinkedListHashSetTextDecoder - implements Decoder.Text>> { - - @Override - public void destroy() { - } - - @Override - public void init(EndpointConfig arg0) { - } - - @Override - public LinkedList> decode(String arg0) - throws DecodeException { - HashSet set = new HashSet<>(); - set.add(arg0); - LinkedList> list = new LinkedList<>(); - list.add(set); - return list; - } - - @Override - public boolean willDecode(String arg0) { - return true; - } +public class LinkedListHashSetTextDecoder implements Decoder.Text>> { + + @Override + public void destroy() { + } + + @Override + public void init(EndpointConfig arg0) { + } + + @Override + public LinkedList> decode(String arg0) throws DecodeException { + HashSet set = new HashSet<>(); + set.add(arg0); + LinkedList> list = new LinkedList<>(); + list.add(set); + return list; + } + + @Override + public boolean willDecode(String arg0) { + return true; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/ListHashSetTextEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/ListHashSetTextEncoder.java index 25311bc3cd..086e82a9dd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/ListHashSetTextEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/ListHashSetTextEncoder.java @@ -25,25 +25,23 @@ import jakarta.websocket.Encoder; import jakarta.websocket.EndpointConfig; -public class ListHashSetTextEncoder - implements Encoder.Text>> { - - @Override - public void destroy() { - } - - @Override - public void init(EndpointConfig arg0) { - } - - @Override - public String encode(LinkedList> arg0) - throws EncodeException { - return listHashSetToString(arg0); - } - - public static final String listHashSetToString(List> arg0) { - return arg0.get(0).iterator().next(); - } +public class ListHashSetTextEncoder implements Encoder.Text>> { + + @Override + public void destroy() { + } + + @Override + public void init(EndpointConfig arg0) { + } + + @Override + public String encode(LinkedList> arg0) throws EncodeException { + return listHashSetToString(arg0); + } + + public static final String listHashSetToString(List> arg0) { + return arg0.get(0).iterator().next(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/StringLinkedList.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/StringLinkedList.java index 23fd76818f..540604645f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/StringLinkedList.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/StringLinkedList.java @@ -19,5 +19,5 @@ import java.util.LinkedList; public class StringLinkedList extends LinkedList implements StringList { - private static final long serialVersionUID = -38485068447284390L; + private static final long serialVersionUID = -38485068447284390L; } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/StringListTextDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/StringListTextDecoder.java index dc9d6eebfc..6cf2e9253d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/StringListTextDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/StringListTextDecoder.java @@ -23,24 +23,24 @@ public class StringListTextDecoder implements Decoder.Text { - @Override - public void init(EndpointConfig config) { - } - - @Override - public void destroy() { - } - - @Override - public StringList decode(String s) throws DecodeException { - StringList list = new StringLinkedList(); - list.add(s); - return list; - } - - @Override - public boolean willDecode(String s) { - return true; - } + @Override + public void init(EndpointConfig config) { + } + + @Override + public void destroy() { + } + + @Override + public StringList decode(String s) throws DecodeException { + StringList list = new StringLinkedList(); + list.add(s); + return list; + } + + @Override + public boolean willDecode(String s) { + return true; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/TypeEnum.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/TypeEnum.java index 857c2efbdd..c29429ecf3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/TypeEnum.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/common/TypeEnum.java @@ -17,11 +17,12 @@ package com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common; public enum TypeEnum { - BYTEARRAY_WHOLE, BYTEARRAY_PARTIAL, BYTEBUFFER_WHOLE, BYTEBUFFER_PARTIAL, LIST_TEXT, LINKEDLIST_HASHSET_TEXT, READER, STRING_WHOLE, STRING_PARTIAL, INPUTSTREAM, STRINGBEAN, STRINGBEANSTREAM, // used - // on - // server - // only - STRINGBEANBINARY, // used on server only - STRINGBEANBINARYSTREAM, // used on server only - PONG + BYTEARRAY_WHOLE, BYTEARRAY_PARTIAL, BYTEBUFFER_WHOLE, BYTEBUFFER_PARTIAL, LIST_TEXT, LINKEDLIST_HASHSET_TEXT, + READER, STRING_WHOLE, STRING_PARTIAL, INPUTSTREAM, STRINGBEAN, STRINGBEANSTREAM, // used + // on + // server + // only + STRINGBEANBINARY, // used on server only + STRINGBEANBINARYSTREAM, // used on server only + PONG } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/AppConfig.java index 7d986c2063..f6ab7a57bb 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/AppConfig.java @@ -37,56 +37,49 @@ public class AppConfig implements ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - addServerEndpoint(set, LinkedListHashSetTextDecoder.class, - TypeEnum.LINKEDLIST_HASHSET_TEXT); - addServerEndpoint(set, StringListTextDecoder.class, TypeEnum.LIST_TEXT); - addServerEndpoint(set, StringBeanTextDecoder.class, TypeEnum.STRINGBEAN); - addServerEndpoint(set, StringBeanTextStreamDecoder.class, - TypeEnum.STRINGBEANSTREAM); - addServerEndpoint(set, StringBeanBinaryDecoder.class, - TypeEnum.STRINGBEANBINARY); - addServerEndpoint(set, StringBeanBinaryStreamDecoder.class, - TypeEnum.STRINGBEANBINARYSTREAM); - addServerEndpoint(set, null, TypeEnum.STRING_WHOLE); - addServerEndpoint(set, null, TypeEnum.STRING_PARTIAL); - addServerEndpoint(set, null, TypeEnum.PONG); - addServerEndpoint(set, null, TypeEnum.BYTEBUFFER_WHOLE); - addServerEndpoint(set, null, TypeEnum.BYTEARRAY_WHOLE); - addServerEndpoint(set, null, TypeEnum.BYTEBUFFER_PARTIAL); - addServerEndpoint(set, null, TypeEnum.BYTEARRAY_PARTIAL); - addServerEndpoint(set, null, TypeEnum.INPUTSTREAM); - addServerEndpoint(set, null, TypeEnum.READER); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + addServerEndpoint(set, LinkedListHashSetTextDecoder.class, TypeEnum.LINKEDLIST_HASHSET_TEXT); + addServerEndpoint(set, StringListTextDecoder.class, TypeEnum.LIST_TEXT); + addServerEndpoint(set, StringBeanTextDecoder.class, TypeEnum.STRINGBEAN); + addServerEndpoint(set, StringBeanTextStreamDecoder.class, TypeEnum.STRINGBEANSTREAM); + addServerEndpoint(set, StringBeanBinaryDecoder.class, TypeEnum.STRINGBEANBINARY); + addServerEndpoint(set, StringBeanBinaryStreamDecoder.class, TypeEnum.STRINGBEANBINARYSTREAM); + addServerEndpoint(set, null, TypeEnum.STRING_WHOLE); + addServerEndpoint(set, null, TypeEnum.STRING_PARTIAL); + addServerEndpoint(set, null, TypeEnum.PONG); + addServerEndpoint(set, null, TypeEnum.BYTEBUFFER_WHOLE); + addServerEndpoint(set, null, TypeEnum.BYTEARRAY_WHOLE); + addServerEndpoint(set, null, TypeEnum.BYTEBUFFER_PARTIAL); + addServerEndpoint(set, null, TypeEnum.BYTEARRAY_PARTIAL); + addServerEndpoint(set, null, TypeEnum.INPUTSTREAM); + addServerEndpoint(set, null, TypeEnum.READER); + return set; + } - private Set addServerEndpoint( - Set set, Class decoder, - final TypeEnum typeEnum) { - List> decoders = new LinkedList<>(); - decoders.add(decoder); - ServerEndpointConfig.Configurator configurator = new ServerEndpointConfig.Configurator() { - @SuppressWarnings("unchecked") - @Override - public T getEndpointInstance(Class endpointClass) - throws InstantiationException { - return (T) new WSCServerEndpoint(typeEnum); - } - }; - ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder - .create(WSCServerEndpoint.class, "/" + typeEnum.name().toLowerCase()); - if (decoder != null) - builder = builder.decoders(decoders); - ServerEndpointConfig config = builder.configurator(configurator).build(); - set.add(config); - return set; - } + private Set addServerEndpoint(Set set, Class decoder, + final TypeEnum typeEnum) { + List> decoders = new LinkedList<>(); + decoders.add(decoder); + ServerEndpointConfig.Configurator configurator = new ServerEndpointConfig.Configurator() { + @SuppressWarnings("unchecked") + @Override + public T getEndpointInstance(Class endpointClass) throws InstantiationException { + return (T) new WSCServerEndpoint(typeEnum); + } + }; + ServerEndpointConfig.Builder builder = ServerEndpointConfig.Builder.create(WSCServerEndpoint.class, + "/" + typeEnum.name().toLowerCase()); + if (decoder != null) + builder = builder.decoders(decoders); + ServerEndpointConfig config = builder.configurator(configurator).build(); + set.add(config); + return set; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - return scanned; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + return scanned; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteArrayMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteArrayMessageHandler.java index ffdf9a2aea..82e76f301d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteArrayMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteArrayMessageHandler.java @@ -24,21 +24,21 @@ public class ByteArrayMessageHandler implements MessageHandler.Whole { - private Session session; - - public static final String HANDLER_SAYS = "ByteArrayMessageHandler says: "; - - public ByteArrayMessageHandler(Session session) { - super(); - this.session = session; - } - - @Override - public void onMessage(byte[] message) { - try { - session.getBasicRemote().sendText(HANDLER_SAYS + new String(message)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + private Session session; + + public static final String HANDLER_SAYS = "ByteArrayMessageHandler says: "; + + public ByteArrayMessageHandler(Session session) { + super(); + this.session = session; + } + + @Override + public void onMessage(byte[] message) { + try { + session.getBasicRemote().sendText(HANDLER_SAYS + new String(message)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteArrayPartialMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteArrayPartialMessageHandler.java index 336a670767..30c2a5b7ce 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteArrayPartialMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteArrayPartialMessageHandler.java @@ -22,28 +22,27 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class ByteArrayPartialMessageHandler - implements MessageHandler.Partial { - - private Session session; - - public static final String HANDLER_SAYS = "ByteArrayPartialMessageHandler says: "; - - StringBuilder sb = new StringBuilder(); - - public ByteArrayPartialMessageHandler(Session session) { - super(); - this.session = session; - } - - @Override - public void onMessage(byte[] message, boolean finite) { - sb.append(new String(message)); - try { - if (finite) - session.getBasicRemote().sendText(HANDLER_SAYS + sb.toString()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } +public class ByteArrayPartialMessageHandler implements MessageHandler.Partial { + + private Session session; + + public static final String HANDLER_SAYS = "ByteArrayPartialMessageHandler says: "; + + StringBuilder sb = new StringBuilder(); + + public ByteArrayPartialMessageHandler(Session session) { + super(); + this.session = session; + } + + @Override + public void onMessage(byte[] message, boolean finite) { + sb.append(new String(message)); + try { + if (finite) + session.getBasicRemote().sendText(HANDLER_SAYS + sb.toString()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteBufferMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteBufferMessageHandler.java index e7b55d4930..96f82f72f5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteBufferMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteBufferMessageHandler.java @@ -25,26 +25,25 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class ByteBufferMessageHandler - implements MessageHandler.Whole { - - private Session session; - - public static final String HANDLER_SAYS = "ByteBufferMessageHandler says: "; - - public ByteBufferMessageHandler(Session session) { - super(); - this.session = session; - } - - @Override - public void onMessage(ByteBuffer message) { - String msg = null; - try { - msg = IOUtil.byteBufferToString(message); - session.getBasicRemote().sendText(HANDLER_SAYS + msg); - } catch (IOException e) { - throw new RuntimeException(e); - } - } +public class ByteBufferMessageHandler implements MessageHandler.Whole { + + private Session session; + + public static final String HANDLER_SAYS = "ByteBufferMessageHandler says: "; + + public ByteBufferMessageHandler(Session session) { + super(); + this.session = session; + } + + @Override + public void onMessage(ByteBuffer message) { + String msg = null; + try { + msg = IOUtil.byteBufferToString(message); + session.getBasicRemote().sendText(HANDLER_SAYS + msg); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteBufferPartialMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteBufferPartialMessageHandler.java index 71ffc3593b..11e4747a6c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteBufferPartialMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ByteBufferPartialMessageHandler.java @@ -25,28 +25,27 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class ByteBufferPartialMessageHandler - implements MessageHandler.Partial { - - private Session session; - - public static final String HANDLER_SAYS = "ByteBufferPartialMessageHandler says: "; - - StringBuilder sb = new StringBuilder(); - - public ByteBufferPartialMessageHandler(Session session) { - super(); - this.session = session; - } - - @Override - public void onMessage(ByteBuffer message, boolean finite) { - sb.append(IOUtil.byteBufferToString(message)); - try { - if (finite) - session.getBasicRemote().sendText(HANDLER_SAYS + sb.toString()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } +public class ByteBufferPartialMessageHandler implements MessageHandler.Partial { + + private Session session; + + public static final String HANDLER_SAYS = "ByteBufferPartialMessageHandler says: "; + + StringBuilder sb = new StringBuilder(); + + public ByteBufferPartialMessageHandler(Session session) { + super(); + this.session = session; + } + + @Override + public void onMessage(ByteBuffer message, boolean finite) { + sb.append(IOUtil.byteBufferToString(message)); + try { + if (finite) + session.getBasicRemote().sendText(HANDLER_SAYS + sb.toString()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/InputStreamMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/InputStreamMessageHandler.java index 29e032160c..2809197f00 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/InputStreamMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/InputStreamMessageHandler.java @@ -25,26 +25,25 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class InputStreamMessageHandler - implements MessageHandler.Whole { - - protected Session session; - - public static final String HANDLER_SAYS = "InputStreamMessageHandler says: "; - - public InputStreamMessageHandler(Session session) { - super(); - this.session = session; - } - - @Override - public void onMessage(InputStream message) { - String msg = null; - try { - msg = IOUtil.readFromStream(message); - session.getBasicRemote().sendText(HANDLER_SAYS + msg); - } catch (IOException e) { - throw new RuntimeException(e); - } - } +public class InputStreamMessageHandler implements MessageHandler.Whole { + + protected Session session; + + public static final String HANDLER_SAYS = "InputStreamMessageHandler says: "; + + public InputStreamMessageHandler(Session session) { + super(); + this.session = session; + } + + @Override + public void onMessage(InputStream message) { + String msg = null; + try { + msg = IOUtil.readFromStream(message); + session.getBasicRemote().sendText(HANDLER_SAYS + msg); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/LinkedListHashSetMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/LinkedListHashSetMessageHandler.java index b419fdcaaf..bdcb012f8e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/LinkedListHashSetMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/LinkedListHashSetMessageHandler.java @@ -26,26 +26,24 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class LinkedListHashSetMessageHandler - implements MessageHandler.Whole>> { - - public static final String HANDLER_SAYS = "LinkedListHashSetMessageHandler says: "; - - private Session session; - - public LinkedListHashSetMessageHandler(Session session) { - super(); - this.session = session; - } - - @Override - public void onMessage(LinkedList> arg0) { - try { - session.getBasicRemote().sendText( - HANDLER_SAYS + ListHashSetTextEncoder.listHashSetToString(arg0)); - } catch (IOException e) { - throw new RuntimeException(e); - } - } +public class LinkedListHashSetMessageHandler implements MessageHandler.Whole>> { + + public static final String HANDLER_SAYS = "LinkedListHashSetMessageHandler says: "; + + private Session session; + + public LinkedListHashSetMessageHandler(Session session) { + super(); + this.session = session; + } + + @Override + public void onMessage(LinkedList> arg0) { + try { + session.getBasicRemote().sendText(HANDLER_SAYS + ListHashSetTextEncoder.listHashSetToString(arg0)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/PongMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/PongMessageHandler.java index 5f47fcbe4e..aa7e71b019 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/PongMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/PongMessageHandler.java @@ -27,23 +27,23 @@ public class PongMessageHandler implements MessageHandler.Whole { - protected Session session; - - public static final String HANDLER_SAYS = "PongMessageHandler says: "; - - public PongMessageHandler(Session session) { - this.session = session; - } - - @Override - public void onMessage(PongMessage pong) { - String msg = null; - try { - msg = IOUtil.byteBufferToString(pong.getApplicationData()); - session.getBasicRemote().sendText(HANDLER_SAYS + msg); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + protected Session session; + + public static final String HANDLER_SAYS = "PongMessageHandler says: "; + + public PongMessageHandler(Session session) { + this.session = session; + } + + @Override + public void onMessage(PongMessage pong) { + String msg = null; + try { + msg = IOUtil.byteBufferToString(pong.getApplicationData()); + session.getBasicRemote().sendText(HANDLER_SAYS + msg); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ReaderMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ReaderMessageHandler.java index 2a81206de9..680f8b35e6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ReaderMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/ReaderMessageHandler.java @@ -27,22 +27,22 @@ public class ReaderMessageHandler implements MessageHandler.Whole { - public static final String HANDLER_SAYS = "ReaderMessageHandler says: "; - - protected Session session; - - public ReaderMessageHandler(Session session) { - this.session = session; - } - - @Override - public void onMessage(Reader message) { - String msg = null; - try { - msg = IOUtil.readFromReader(message); - session.getBasicRemote().sendText(HANDLER_SAYS + msg); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + public static final String HANDLER_SAYS = "ReaderMessageHandler says: "; + + protected Session session; + + public ReaderMessageHandler(Session session) { + this.session = session; + } + + @Override + public void onMessage(Reader message) { + String msg = null; + try { + msg = IOUtil.readFromReader(message); + session.getBasicRemote().sendText(HANDLER_SAYS + msg); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringBeanMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringBeanMessageHandler.java index 4a490a9f72..b578d70572 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringBeanMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringBeanMessageHandler.java @@ -24,24 +24,23 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class StringBeanMessageHandler - implements MessageHandler.Whole { +public class StringBeanMessageHandler implements MessageHandler.Whole { - private Session session; + private Session session; - public static final String HANDLER_SAYS = "StringBeanMessageHandler says: "; + public static final String HANDLER_SAYS = "StringBeanMessageHandler says: "; - public StringBeanMessageHandler(Session session) { - this.session = session; - } + public StringBeanMessageHandler(Session session) { + this.session = session; + } - @Override - public void onMessage(StringBean message) { - try { - session.getBasicRemote().sendText(HANDLER_SAYS + message.get()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + @Override + public void onMessage(StringBean message) { + try { + session.getBasicRemote().sendText(HANDLER_SAYS + message.get()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringListWholeMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringListWholeMessageHandler.java index 147835df52..41f5d39377 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringListWholeMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringListWholeMessageHandler.java @@ -24,25 +24,23 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class StringListWholeMessageHandler - implements MessageHandler.Whole { - - private Session session; - - public static final String HANDLER_SAYS = "StringListWholeMessageHandler says: "; - - public StringListWholeMessageHandler(Session session) { - super(); - this.session = session; - } - - @Override - public void onMessage(StringList message) { - try { - session.getBasicRemote() - .sendText(HANDLER_SAYS + message.get(0).toString()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } +public class StringListWholeMessageHandler implements MessageHandler.Whole { + + private Session session; + + public static final String HANDLER_SAYS = "StringListWholeMessageHandler says: "; + + public StringListWholeMessageHandler(Session session) { + super(); + this.session = session; + } + + @Override + public void onMessage(StringList message) { + try { + session.getBasicRemote().sendText(HANDLER_SAYS + message.get(0).toString()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringPartialMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringPartialMessageHandler.java index d94e145ca4..a18506de68 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringPartialMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringPartialMessageHandler.java @@ -22,29 +22,28 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class StringPartialMessageHandler - implements MessageHandler.Partial { - - protected Session session; - - public static final String HANDLER_SAYS = "StringPartialMessageHandler says: "; - - StringBuilder sb = new StringBuilder(); - - public StringPartialMessageHandler(Session session) { - super(); - this.session = session; - } - - @Override - public void onMessage(String message, boolean finite) { - sb.append(message); - try { - if (finite) - session.getBasicRemote().sendText(HANDLER_SAYS + sb.toString()); - } catch (IOException e) { - throw new RuntimeException(e); - } - } +public class StringPartialMessageHandler implements MessageHandler.Partial { + + protected Session session; + + public static final String HANDLER_SAYS = "StringPartialMessageHandler says: "; + + StringBuilder sb = new StringBuilder(); + + public StringPartialMessageHandler(Session session) { + super(); + this.session = session; + } + + @Override + public void onMessage(String message, boolean finite) { + sb.append(message); + try { + if (finite) + session.getBasicRemote().sendText(HANDLER_SAYS + sb.toString()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringWholeMessageHandler.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringWholeMessageHandler.java index f1211b42b2..073c7775f6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringWholeMessageHandler.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/StringWholeMessageHandler.java @@ -24,22 +24,22 @@ public class StringWholeMessageHandler implements MessageHandler.Whole { - private Session session; - - public static final String HANDLER_SAYS = "StringWholeMessageHandler says: "; - - public StringWholeMessageHandler(Session session) { - super(); - this.session = session; - } - - @Override - public void onMessage(String message) { - try { - session.getBasicRemote().sendText(HANDLER_SAYS + message); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + private Session session; + + public static final String HANDLER_SAYS = "StringWholeMessageHandler says: "; + + public StringWholeMessageHandler(Session session) { + super(); + this.session = session; + } + + @Override + public void onMessage(String message) { + try { + session.getBasicRemote().sendText(HANDLER_SAYS + message); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedBinaryServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedBinaryServerEndpoint.java index 53bca0737f..6e6114d99a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedBinaryServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedBinaryServerEndpoint.java @@ -32,17 +32,16 @@ @ServerEndpoint(value = "/annotatedbinary", decoders = StringBeanBinaryDecoder.class) public class WSCAnnotatedBinaryServerEndpoint { - @OnOpen - public void onOpen(Session session) { - session.addMessageHandler(StringBean.class, - new StringBeanMessageHandler(session)); - } + @OnOpen + public void onOpen(Session session) { + session.addMessageHandler(StringBean.class, new StringBeanMessageHandler(session)); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendBinary(ByteBuffer.wrap(message.getBytes())); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendBinary(ByteBuffer.wrap(message.getBytes())); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedMixedServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedMixedServerEndpoint.java index 39175c51bd..6fc9771871 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedMixedServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedMixedServerEndpoint.java @@ -34,84 +34,79 @@ @ServerEndpoint("/exception") public class WSCAnnotatedMixedServerEndpoint { - public static final String EXCEPTION = "Exception: "; + public static final String EXCEPTION = "Exception: "; - static class StringThrowingPartialMessageHandler - extends StringPartialMessageHandler { - public StringThrowingPartialMessageHandler(Session session) { - super(session); - } + static class StringThrowingPartialMessageHandler extends StringPartialMessageHandler { + public StringThrowingPartialMessageHandler(Session session) { + super(session); + } - @Override - public void onMessage(String partialMessage, boolean last) { - if (TypeEnum.STRING_PARTIAL.name().equals(partialMessage)) { - if (last) - session.addMessageHandler(String.class, this); - } else - super.onMessage(partialMessage, last); - } - } + @Override + public void onMessage(String partialMessage, boolean last) { + if (TypeEnum.STRING_PARTIAL.name().equals(partialMessage)) { + if (last) + session.addMessageHandler(String.class, this); + } else + super.onMessage(partialMessage, last); + } + } - static class InputStreamThrowingMessageHandler - extends InputStreamMessageHandler { - public InputStreamThrowingMessageHandler(Session session) { - super(session); - } + static class InputStreamThrowingMessageHandler extends InputStreamMessageHandler { + public InputStreamThrowingMessageHandler(Session session) { + super(session); + } - @Override - public void onMessage(InputStream message) { - String msg = null; - try { - msg = IOUtil.readFromStream(message); - } catch (IOException e) { - // do nothing - } - if (TypeEnum.INPUTSTREAM.name().equals(msg)) - session.addMessageHandler(InputStream.class, this); - else - super.onMessage(new StringInputStream(msg)); - } - } + @Override + public void onMessage(InputStream message) { + String msg = null; + try { + msg = IOUtil.readFromStream(message); + } catch (IOException e) { + // do nothing + } + if (TypeEnum.INPUTSTREAM.name().equals(msg)) + session.addMessageHandler(InputStream.class, this); + else + super.onMessage(new StringInputStream(msg)); + } + } - static class PongMessageThrowingMessageHandler extends PongMessageHandler { - public PongMessageThrowingMessageHandler(Session session) { - super(session); - } + static class PongMessageThrowingMessageHandler extends PongMessageHandler { + public PongMessageThrowingMessageHandler(Session session) { + super(session); + } - @Override - public void onMessage(PongMessage message) { - String msg = null; - msg = IOUtil.byteBufferToString(message.getApplicationData()); - if (TypeEnum.PONG.name().equals(msg)) - session.addMessageHandler(PongMessage.class, this); - else - super.onMessage(new StringPongMessage(msg)); - } - } + @Override + public void onMessage(PongMessage message) { + String msg = null; + msg = IOUtil.byteBufferToString(message.getApplicationData()); + if (TypeEnum.PONG.name().equals(msg)) + session.addMessageHandler(PongMessage.class, this); + else + super.onMessage(new StringPongMessage(msg)); + } + } - @OnOpen - public void onOpen(Session session) { - session.addMessageHandler(String.class, - new StringThrowingPartialMessageHandler(session)); - session.addMessageHandler(InputStream.class, - new InputStreamThrowingMessageHandler(session)); - session.addMessageHandler(PongMessage.class, - new PongMessageThrowingMessageHandler(session)); - } + @OnOpen + public void onOpen(Session session) { + session.addMessageHandler(String.class, new StringThrowingPartialMessageHandler(session)); + session.addMessageHandler(InputStream.class, new InputStreamThrowingMessageHandler(session)); + session.addMessageHandler(PongMessage.class, new PongMessageThrowingMessageHandler(session)); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - // this @OnError should catch RuntimeException thrown by second - // session.addMessageHandler call - sendException(session, t); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + // this @OnError should catch RuntimeException thrown by second + // session.addMessageHandler call + sendException(session, t); + } - static void sendException(Session session, Throwable t) { - String ex = EXCEPTION + t.getMessage(); - try { - session.getBasicRemote().sendText(ex); - } catch (IOException ioe) { - throw new RuntimeException(ioe); - } - } + static void sendException(Session session, Throwable t) { + String ex = EXCEPTION + t.getMessage(); + try { + session.getBasicRemote().sendText(ex); + } catch (IOException ioe) { + throw new RuntimeException(ioe); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedTextServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedTextServerEndpoint.java index f3dcf1bb1f..b1bf281c43 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedTextServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCAnnotatedTextServerEndpoint.java @@ -31,17 +31,16 @@ @ServerEndpoint(value = "/annotatedtext", decoders = StringBeanTextDecoder.class) public class WSCAnnotatedTextServerEndpoint { - @OnOpen - public void onOpen(Session session) { - session.addMessageHandler(StringBean.class, - new StringBeanMessageHandler(session)); - } + @OnOpen + public void onOpen(Session session) { + session.addMessageHandler(StringBean.class, new StringBeanMessageHandler(session)); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCClient.java deleted file mode 100644 index 76aa9bbaaf..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCClient.java +++ /dev/null @@ -1,439 +0,0 @@ -/* - * Copyright (c) 2014, 2020 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.server; - -import java.nio.ByteBuffer; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.StringPongMessage; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.TypeEnum; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSCClient extends WebSocketCommonClient { - private static final long serialVersionUID = 0; - - protected static final String ECHO = "Echo message"; - - protected static final String ECHO_PARTIAL = "second part send partially"; - - protected static final String ANYTHING = "Anything"; - - public WSCClient() { - setContextRoot("wsc_ee_jakarta_websocket_session11_server_web"); - logExceptionOnInvocation(false); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* Run test */ - /* - * @testName: linkedListHashSetTextHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void linkedListHashSetTextHandlerTest() throws Exception { - invoke(TypeEnum.LINKEDLIST_HASHSET_TEXT.name().toLowerCase(), ECHO, - LinkedListHashSetMessageHandler.HANDLER_SAYS, ECHO); - logMsg( - "addMessageHandler(LinkedList>.class, Whole>>) works as expected."); - } - - /* - * @testName: linkedListTextHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void linkedListTextHandlerTest() throws Exception { - invoke(TypeEnum.LIST_TEXT.name().toLowerCase(), ECHO, - StringListWholeMessageHandler.HANDLER_SAYS, ECHO); - logMsg( - "addMessageHandler(StringList.class, Whole) works as expected."); - } - - /* - * @testName: textStringBeanHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void textStringBeanHandlerTest() throws Exception { - invoke(TypeEnum.STRINGBEAN.name().toLowerCase(), ECHO, - StringBeanMessageHandler.HANDLER_SAYS, ECHO); - logMsg( - "addMessageHandler(StringBean.class, Whole) works as expected."); - } - - /* - * @testName: textStreamStringBeanHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void textStreamStringBeanHandlerTest() throws Exception { - invoke(TypeEnum.STRINGBEANSTREAM.name().toLowerCase(), ECHO, - StringBeanMessageHandler.HANDLER_SAYS, ECHO); - logMsg( - "addMessageHandler(StringBean.class, Whole) works as expected."); - } - - /* - * @testName: stringTextHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void stringTextHandlerTest() throws Exception { - invoke(TypeEnum.STRING_WHOLE.name().toLowerCase(), ECHO, - StringWholeMessageHandler.HANDLER_SAYS, ECHO); - logMsg("addMessageHandler(String.class, Whole) works as expected."); - } - - /* - * @testName: readerMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void readerMessageHandlerTest() throws Exception { - invoke(TypeEnum.READER.name().toLowerCase(), ECHO, - ReaderMessageHandler.HANDLER_SAYS, ECHO); - logMsg("addMessageHandler(Reader.class, Whole) works as expected."); - } - - // ----------------------------------------------------------------------- - // Control - // ----------------------------------------------------------------------- - - /* - * @testName: pongMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void pongMessageHandlerTest() throws Exception { - invoke(TypeEnum.PONG.name().toLowerCase(), new StringPongMessage(ECHO), - PongMessageHandler.HANDLER_SAYS, ECHO); - logMsg( - "addMessageHandler(PongMessage.class, Whole) works as expected."); - } - - // ----------------------------------------------------------------------- - // Binary - // ----------------------------------------------------------------------- - - /* - * @testName: byteBufferMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void byteBufferMessageHandlerTest() throws Exception { - invoke(TypeEnum.BYTEBUFFER_WHOLE.name().toLowerCase(), - ByteBuffer.wrap(ECHO.getBytes()), ByteBufferMessageHandler.HANDLER_SAYS, - ECHO); - logMsg( - "addMessageHandler(ByteBuffer.class, Whole) works as expected."); - } - - /* - * @testName: byteArrayMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void byteArrayMessageHandlerTest() throws Exception { - invoke(TypeEnum.BYTEARRAY_WHOLE.name().toLowerCase(), - ByteBuffer.wrap(ECHO.getBytes()), ByteArrayMessageHandler.HANDLER_SAYS, - ECHO); - logMsg("addMessageHandler(byte[].class, Whole) works as expected."); - } - - /* - * @testName: inputStreamMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void inputStreamMessageHandlerTest() throws Exception { - invoke(TypeEnum.INPUTSTREAM.name().toLowerCase(), - ByteBuffer.wrap(ECHO.getBytes()), - InputStreamMessageHandler.HANDLER_SAYS, ECHO); - logMsg( - "addMessageHandler(InputStream.class, Whole) works as expected."); - } - - /* - * @testName: binaryStringBeanMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void binaryStringBeanMessageHandlerTest() throws Exception { - invoke(TypeEnum.STRINGBEANBINARY.name().toLowerCase(), - ByteBuffer.wrap(ECHO.getBytes()), StringBeanMessageHandler.HANDLER_SAYS, - ECHO); - logMsg( - "addMessageHandler(StringBean.class, Whole) works as expected."); - } - - /* - * @testName: binaryStreamStringBeanMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void binaryStreamStringBeanMessageHandlerTest() throws Exception { - invoke(TypeEnum.STRINGBEANBINARYSTREAM.name().toLowerCase(), - ByteBuffer.wrap(ECHO.getBytes()), StringBeanMessageHandler.HANDLER_SAYS, - ECHO); - logMsg( - "addMessageHandler(StringBean.class, Whole) works as expected."); - } - - // ----------------------------------------------------------------------- - // Partial - // ----------------------------------------------------------------------- - - /* - * @testName: stringPartialHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:213 - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void stringPartialHandlerTest() throws Exception { - setEntity(ECHO, ECHO_PARTIAL); - - setProperty(Property.SEARCH_STRING, - StringPartialMessageHandler.HANDLER_SAYS); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, ECHO_PARTIAL); - setProperty(Property.REQUEST, - buildRequest(TypeEnum.STRING_PARTIAL.name().toLowerCase())); - - invoke(); - logMsg( - "addMessageHandler(String.class, Partial) works as expected."); - } - - /* - * @testName: byteBufferPartialMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:213; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void byteBufferPartialMessageHandlerTest() throws Exception { - setEntity(ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(ECHO_PARTIAL.getBytes())); - - setProperty(Property.SEARCH_STRING, - ByteBufferPartialMessageHandler.HANDLER_SAYS); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, ECHO_PARTIAL); - setProperty(Property.REQUEST, - buildRequest(TypeEnum.BYTEBUFFER_PARTIAL.name().toLowerCase())); - - invoke(); - logMsg( - "addMessageHandler(ByteBuffer.class, Partial) works as expected."); - } - - /* - * @testName: byteArrayPartialMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:213; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void byteArrayPartialMessageHandlerTest() throws Exception { - setEntity(ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(ECHO_PARTIAL.getBytes())); - - setProperty(Property.SEARCH_STRING, - ByteArrayPartialMessageHandler.HANDLER_SAYS); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, ECHO_PARTIAL); - setProperty(Property.REQUEST, - buildRequest(TypeEnum.BYTEARRAY_PARTIAL.name().toLowerCase())); - - invoke(); - logMsg( - "addMessageHandler(byte[].class, Partial) works as expected."); - } - - // ----------------------------------------------------------------------- - // Annotated - // ----------------------------------------------------------------------- - - /* - * @testName: binaryAnnotatedStringBeanMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void binaryAnnotatedStringBeanMessageHandlerTest() throws Exception { - invoke("annotatedbinary", ByteBuffer.wrap(ECHO.getBytes()), - StringBeanMessageHandler.HANDLER_SAYS, ECHO); - logMsg( - "addMessageHandler(StringBean.class, Whole) works as expected."); - } - - /* - * @testName: textAnnotatedStringBeanMessageHandlerTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Register to handle to incoming messages in this - * conversation. - */ - public void textAnnotatedStringBeanMessageHandlerTest() throws Exception { - invoke("annotatedtext", ECHO, StringBeanMessageHandler.HANDLER_SAYS, ECHO); - logMsg( - "addMessageHandler(StringBean.class, Whole) works as expected."); - } - - // ----------------------------------------------------------------------- - // Exception - // ----------------------------------------------------------------------- - - /* - * @testName: addMessageHandlerPongMessageThrowsExceptionTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Adding more than one of any one type will result in a - * runtime exception. - */ - public void addMessageHandlerPongMessageThrowsExceptionTest() throws Exception { - // do not throw - setEntity(new StringPongMessage(ECHO)); - setProperty(Property.REQUEST, buildRequest("exception")); - setProperty(Property.UNEXPECTED_RESPONSE_MATCH, - WSCAnnotatedMixedServerEndpoint.EXCEPTION); - setProperty(Property.SEARCH_STRING, PongMessageHandler.HANDLER_SAYS); - setProperty(Property.SEARCH_STRING, ECHO); - invoke(); - // throw - setEntity(new StringPongMessage(TypeEnum.PONG.name())); - setProperty(Property.REQUEST, buildRequest("exception")); - setProperty(Property.SEARCH_STRING, - WSCAnnotatedMixedServerEndpoint.EXCEPTION); - invoke(false); - logMsg( - "addMessageHandler(PongMessage.class, Partial) throws RuntimeException as expected when called twice:", - getResponseAsString().split(": ")[1]); - } - - /* - * @testName: addMessageHandlerStringPartialMessageThrowsExceptionTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Adding more than one of any one type will result in a - * runtime exception. - */ - public void addMessageHandlerStringPartialMessageThrowsExceptionTest() - throws Exception { - // do not throw - setEntity(ECHO, ECHO_PARTIAL); - setProperty(Property.REQUEST, buildRequest("exception")); - setProperty(Property.UNEXPECTED_RESPONSE_MATCH, - WSCAnnotatedMixedServerEndpoint.EXCEPTION); - setProperty(Property.SEARCH_STRING, - StringPartialMessageHandler.HANDLER_SAYS); - setProperty(Property.SEARCH_STRING, ECHO); - invoke(); - // throw - setEntity(TypeEnum.STRING_PARTIAL.name(), TypeEnum.STRING_PARTIAL.name()); - setProperty(Property.REQUEST, buildRequest("exception")); - setProperty(Property.SEARCH_STRING, - WSCAnnotatedMixedServerEndpoint.EXCEPTION); - invoke(false); - logMsg( - "addMessageHandler(String.class, Partial) throws RuntimeException as expected when called twice:", - getResponseAsString().split(": ")[1]); - } - - /* - * @testName: addMessageHandlerInputStreamThrowsExceptionTest - * - * @assertion_ids: WebSocket:JAVADOC:212; - * - * @test_Strategy: Adding more than one of any one type will result in a - * runtime exception. - */ - public void addMessageHandlerInputStreamThrowsExceptionTest() throws Exception { - // do not throw - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - setProperty(Property.REQUEST, buildRequest("exception")); - setProperty(Property.UNEXPECTED_RESPONSE_MATCH, - WSCAnnotatedMixedServerEndpoint.EXCEPTION); - setProperty(Property.SEARCH_STRING, InputStreamMessageHandler.HANDLER_SAYS); - setProperty(Property.SEARCH_STRING, ECHO); - invoke(); - // throw - setEntity(ByteBuffer.wrap(TypeEnum.INPUTSTREAM.name().getBytes())); - setProperty(Property.REQUEST, buildRequest("exception")); - setProperty(Property.SEARCH_STRING, - WSCAnnotatedMixedServerEndpoint.EXCEPTION); - invoke(false); - logMsg( - "addMessageHandler(InputStream.class, Whole) throws RuntimeException as expected when called twice:", - getResponseAsString().split(": ")[1]); - } - - // /////////////////////////////////////////////////////////////////////// -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCClientIT.java new file mode 100644 index 0000000000..13e68ec57c --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCClientIT.java @@ -0,0 +1,411 @@ +/* + * Copyright (c) 2014, 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.server; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.StringPongMessage; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common.TypeEnum; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = 0; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_ee_jakarta_websocket_session11_server_web.war"); + archive.addPackages(true, "com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.server"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common"); + archive.addPackages(true, "com.sun.ts.tests.websocket.ee.jakarta.websocket.session11.common"); + return archive; + } + + protected static final String ECHO = "Echo message"; + + protected static final String ECHO_PARTIAL = "second part send partially"; + + protected static final String ANYTHING = "Anything"; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_ee_jakarta_websocket_session11_server_web"); + logExceptionOnInvocation(false); + } + + /* Run test */ + /* + * @testName: linkedListHashSetTextHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void linkedListHashSetTextHandlerTest() throws Exception { + invoke(TypeEnum.LINKEDLIST_HASHSET_TEXT.name().toLowerCase(), ECHO, + LinkedListHashSetMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(LinkedList>.class, Whole>>) works as expected."); + } + + /* + * @testName: linkedListTextHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void linkedListTextHandlerTest() throws Exception { + invoke(TypeEnum.LIST_TEXT.name().toLowerCase(), ECHO, StringListWholeMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(StringList.class, Whole) works as expected."); + } + + /* + * @testName: textStringBeanHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void textStringBeanHandlerTest() throws Exception { + invoke(TypeEnum.STRINGBEAN.name().toLowerCase(), ECHO, StringBeanMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(StringBean.class, Whole) works as expected."); + } + + /* + * @testName: textStreamStringBeanHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void textStreamStringBeanHandlerTest() throws Exception { + invoke(TypeEnum.STRINGBEANSTREAM.name().toLowerCase(), ECHO, StringBeanMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(StringBean.class, Whole) works as expected."); + } + + /* + * @testName: stringTextHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void stringTextHandlerTest() throws Exception { + invoke(TypeEnum.STRING_WHOLE.name().toLowerCase(), ECHO, StringWholeMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(String.class, Whole) works as expected."); + } + + /* + * @testName: readerMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void readerMessageHandlerTest() throws Exception { + invoke(TypeEnum.READER.name().toLowerCase(), ECHO, ReaderMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(Reader.class, Whole) works as expected."); + } + + // ----------------------------------------------------------------------- + // Control + // ----------------------------------------------------------------------- + + /* + * @testName: pongMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void pongMessageHandlerTest() throws Exception { + invoke(TypeEnum.PONG.name().toLowerCase(), new StringPongMessage(ECHO), PongMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(PongMessage.class, Whole) works as expected."); + } + + // ----------------------------------------------------------------------- + // Binary + // ----------------------------------------------------------------------- + + /* + * @testName: byteBufferMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void byteBufferMessageHandlerTest() throws Exception { + invoke(TypeEnum.BYTEBUFFER_WHOLE.name().toLowerCase(), ByteBuffer.wrap(ECHO.getBytes()), + ByteBufferMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(ByteBuffer.class, Whole) works as expected."); + } + + /* + * @testName: byteArrayMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void byteArrayMessageHandlerTest() throws Exception { + invoke(TypeEnum.BYTEARRAY_WHOLE.name().toLowerCase(), ByteBuffer.wrap(ECHO.getBytes()), + ByteArrayMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(byte[].class, Whole) works as expected."); + } + + /* + * @testName: inputStreamMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void inputStreamMessageHandlerTest() throws Exception { + invoke(TypeEnum.INPUTSTREAM.name().toLowerCase(), ByteBuffer.wrap(ECHO.getBytes()), + InputStreamMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(InputStream.class, Whole) works as expected."); + } + + /* + * @testName: binaryStringBeanMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void binaryStringBeanMessageHandlerTest() throws Exception { + invoke(TypeEnum.STRINGBEANBINARY.name().toLowerCase(), ByteBuffer.wrap(ECHO.getBytes()), + StringBeanMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(StringBean.class, Whole) works as expected."); + } + + /* + * @testName: binaryStreamStringBeanMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void binaryStreamStringBeanMessageHandlerTest() throws Exception { + invoke(TypeEnum.STRINGBEANBINARYSTREAM.name().toLowerCase(), ByteBuffer.wrap(ECHO.getBytes()), + StringBeanMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(StringBean.class, Whole) works as expected."); + } + + // ----------------------------------------------------------------------- + // Partial + // ----------------------------------------------------------------------- + + /* + * @testName: stringPartialHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:213 + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void stringPartialHandlerTest() throws Exception { + setEntity(ECHO, ECHO_PARTIAL); + + setProperty(Property.SEARCH_STRING, StringPartialMessageHandler.HANDLER_SAYS); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, ECHO_PARTIAL); + setProperty(Property.REQUEST, buildRequest(TypeEnum.STRING_PARTIAL.name().toLowerCase())); + + invoke(); + logMsg("addMessageHandler(String.class, Partial) works as expected."); + } + + /* + * @testName: byteBufferPartialMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:213; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void byteBufferPartialMessageHandlerTest() throws Exception { + setEntity(ByteBuffer.wrap(ECHO.getBytes()), ByteBuffer.wrap(ECHO_PARTIAL.getBytes())); + + setProperty(Property.SEARCH_STRING, ByteBufferPartialMessageHandler.HANDLER_SAYS); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, ECHO_PARTIAL); + setProperty(Property.REQUEST, buildRequest(TypeEnum.BYTEBUFFER_PARTIAL.name().toLowerCase())); + + invoke(); + logMsg("addMessageHandler(ByteBuffer.class, Partial) works as expected."); + } + + /* + * @testName: byteArrayPartialMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:213; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void byteArrayPartialMessageHandlerTest() throws Exception { + setEntity(ByteBuffer.wrap(ECHO.getBytes()), ByteBuffer.wrap(ECHO_PARTIAL.getBytes())); + + setProperty(Property.SEARCH_STRING, ByteArrayPartialMessageHandler.HANDLER_SAYS); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, ECHO_PARTIAL); + setProperty(Property.REQUEST, buildRequest(TypeEnum.BYTEARRAY_PARTIAL.name().toLowerCase())); + + invoke(); + logMsg("addMessageHandler(byte[].class, Partial) works as expected."); + } + + // ----------------------------------------------------------------------- + // Annotated + // ----------------------------------------------------------------------- + + /* + * @testName: binaryAnnotatedStringBeanMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void binaryAnnotatedStringBeanMessageHandlerTest() throws Exception { + invoke("annotatedbinary", ByteBuffer.wrap(ECHO.getBytes()), StringBeanMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(StringBean.class, Whole) works as expected."); + } + + /* + * @testName: textAnnotatedStringBeanMessageHandlerTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Register to handle to incoming messages in this conversation. + */ + @Test + public void textAnnotatedStringBeanMessageHandlerTest() throws Exception { + invoke("annotatedtext", ECHO, StringBeanMessageHandler.HANDLER_SAYS, ECHO); + logMsg("addMessageHandler(StringBean.class, Whole) works as expected."); + } + + // ----------------------------------------------------------------------- + // Exception + // ----------------------------------------------------------------------- + + /* + * @testName: addMessageHandlerPongMessageThrowsExceptionTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Adding more than one of any one type will result in a runtime + * exception. + */ + @Test + public void addMessageHandlerPongMessageThrowsExceptionTest() throws Exception { + // do not throw + setEntity(new StringPongMessage(ECHO)); + setProperty(Property.REQUEST, buildRequest("exception")); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, WSCAnnotatedMixedServerEndpoint.EXCEPTION); + setProperty(Property.SEARCH_STRING, PongMessageHandler.HANDLER_SAYS); + setProperty(Property.SEARCH_STRING, ECHO); + invoke(); + // throw + setEntity(new StringPongMessage(TypeEnum.PONG.name())); + setProperty(Property.REQUEST, buildRequest("exception")); + setProperty(Property.SEARCH_STRING, WSCAnnotatedMixedServerEndpoint.EXCEPTION); + invoke(false); + logMsg("addMessageHandler(PongMessage.class, Partial) throws RuntimeException as expected when called twice:", + getResponseAsString().split(": ")[1]); + } + + /* + * @testName: addMessageHandlerStringPartialMessageThrowsExceptionTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Adding more than one of any one type will result in a runtime + * exception. + */ + @Test + public void addMessageHandlerStringPartialMessageThrowsExceptionTest() throws Exception { + // do not throw + setEntity(ECHO, ECHO_PARTIAL); + setProperty(Property.REQUEST, buildRequest("exception")); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, WSCAnnotatedMixedServerEndpoint.EXCEPTION); + setProperty(Property.SEARCH_STRING, StringPartialMessageHandler.HANDLER_SAYS); + setProperty(Property.SEARCH_STRING, ECHO); + invoke(); + // throw + setEntity(TypeEnum.STRING_PARTIAL.name(), TypeEnum.STRING_PARTIAL.name()); + setProperty(Property.REQUEST, buildRequest("exception")); + setProperty(Property.SEARCH_STRING, WSCAnnotatedMixedServerEndpoint.EXCEPTION); + invoke(false); + logMsg("addMessageHandler(String.class, Partial) throws RuntimeException as expected when called twice:", + getResponseAsString().split(": ")[1]); + } + + /* + * @testName: addMessageHandlerInputStreamThrowsExceptionTest + * + * @assertion_ids: WebSocket:JAVADOC:212; + * + * @test_Strategy: Adding more than one of any one type will result in a runtime + * exception. + */ + @Test + public void addMessageHandlerInputStreamThrowsExceptionTest() throws Exception { + // do not throw + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + setProperty(Property.REQUEST, buildRequest("exception")); + setProperty(Property.UNEXPECTED_RESPONSE_MATCH, WSCAnnotatedMixedServerEndpoint.EXCEPTION); + setProperty(Property.SEARCH_STRING, InputStreamMessageHandler.HANDLER_SAYS); + setProperty(Property.SEARCH_STRING, ECHO); + invoke(); + // throw + setEntity(ByteBuffer.wrap(TypeEnum.INPUTSTREAM.name().getBytes())); + setProperty(Property.REQUEST, buildRequest("exception")); + setProperty(Property.SEARCH_STRING, WSCAnnotatedMixedServerEndpoint.EXCEPTION); + invoke(false); + logMsg("addMessageHandler(InputStream.class, Whole) throws RuntimeException as expected when called twice:", + getResponseAsString().split(": ")[1]); + } + + // /////////////////////////////////////////////////////////////////////// +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCServerEndpoint.java index 4b8a928956..47546ae286 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session11/server/WSCServerEndpoint.java @@ -35,89 +35,78 @@ import jakarta.websocket.Session; public class WSCServerEndpoint extends Endpoint { - public WSCServerEndpoint(TypeEnum typeEnum) { - super(); - this.typeEnum = typeEnum; - } - private TypeEnum typeEnum; + public WSCServerEndpoint(TypeEnum typeEnum) { + super(); + this.typeEnum = typeEnum; + } - @SuppressWarnings("unchecked") - @Override - public void onOpen(Session session, EndpointConfig config) { - switch (typeEnum) { - case LINKEDLIST_HASHSET_TEXT: - LinkedList> list = new LinkedList<>(); - Class>> clzLLHS = (Class>>) list - .getClass(); - session.addMessageHandler(clzLLHS, - new LinkedListHashSetMessageHandler(session)); - break; - case LIST_TEXT: - session.addMessageHandler(StringList.class, - new StringListWholeMessageHandler(session)); - break; - case STRINGBEAN: - case STRINGBEANSTREAM: - case STRINGBEANBINARY: - case STRINGBEANBINARYSTREAM: - session.addMessageHandler(StringBean.class, - new StringBeanMessageHandler(session)); - break; - case STRING_WHOLE: - session.addMessageHandler(String.class, - new StringWholeMessageHandler(session)); - break; - case STRING_PARTIAL: - session.addMessageHandler(String.class, - new StringPartialMessageHandler(session)); - break; - case READER: - session.addMessageHandler(Reader.class, - new ReaderMessageHandler(session)); - break; - case PONG: - session.addMessageHandler(PongMessage.class, - new PongMessageHandler(session)); - // send pingmessage to receive pongmessage - break; - case BYTEBUFFER_WHOLE: - session.addMessageHandler(ByteBuffer.class, - new ByteBufferMessageHandler(session)); - break; - case BYTEBUFFER_PARTIAL: - session.addMessageHandler(ByteBuffer.class, - new ByteBufferPartialMessageHandler(session)); - break; - case BYTEARRAY_WHOLE: - byte[] ba = new byte[0]; - Class baclz = (Class) ba.getClass(); - session.addMessageHandler(baclz, new ByteArrayMessageHandler(session)); - break; - case BYTEARRAY_PARTIAL: - ba = new byte[0]; - baclz = (Class) ba.getClass(); - session.addMessageHandler(baclz, - new ByteArrayPartialMessageHandler(session)); - break; - case INPUTSTREAM: - session.addMessageHandler(InputStream.class, - new InputStreamMessageHandler(session)); - break; - default: - break; - } - } + private TypeEnum typeEnum; - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } + @SuppressWarnings("unchecked") + @Override + public void onOpen(Session session, EndpointConfig config) { + switch (typeEnum) { + case LINKEDLIST_HASHSET_TEXT: + LinkedList> list = new LinkedList<>(); + Class>> clzLLHS = (Class>>) list.getClass(); + session.addMessageHandler(clzLLHS, new LinkedListHashSetMessageHandler(session)); + break; + case LIST_TEXT: + session.addMessageHandler(StringList.class, new StringListWholeMessageHandler(session)); + break; + case STRINGBEAN: + case STRINGBEANSTREAM: + case STRINGBEANBINARY: + case STRINGBEANBINARYSTREAM: + session.addMessageHandler(StringBean.class, new StringBeanMessageHandler(session)); + break; + case STRING_WHOLE: + session.addMessageHandler(String.class, new StringWholeMessageHandler(session)); + break; + case STRING_PARTIAL: + session.addMessageHandler(String.class, new StringPartialMessageHandler(session)); + break; + case READER: + session.addMessageHandler(Reader.class, new ReaderMessageHandler(session)); + break; + case PONG: + session.addMessageHandler(PongMessage.class, new PongMessageHandler(session)); + // send pingmessage to receive pongmessage + break; + case BYTEBUFFER_WHOLE: + session.addMessageHandler(ByteBuffer.class, new ByteBufferMessageHandler(session)); + break; + case BYTEBUFFER_PARTIAL: + session.addMessageHandler(ByteBuffer.class, new ByteBufferPartialMessageHandler(session)); + break; + case BYTEARRAY_WHOLE: + byte[] ba = new byte[0]; + Class baclz = (Class) ba.getClass(); + session.addMessageHandler(baclz, new ByteArrayMessageHandler(session)); + break; + case BYTEARRAY_PARTIAL: + ba = new byte[0]; + baclz = (Class) ba.getClass(); + session.addMessageHandler(baclz, new ByteArrayPartialMessageHandler(session)); + break; + case INPUTSTREAM: + session.addMessageHandler(InputStream.class, new InputStreamMessageHandler(session)); + break; + default: + break; + } + } + + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/WSClient.java deleted file mode 100644 index ed6ba6774e..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/WSClient.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates and others. - * 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 - */ - -/* - * $Id$ - */ -package com.sun.ts.tests.websocket.ee.jakarta.websocket.sessionexception; - -import java.net.URI; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.util.MessageValidator; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.CloseReason; -import jakarta.websocket.ContainerProvider; -import jakarta.websocket.Endpoint; -import jakarta.websocket.EndpointConfig; -import jakarta.websocket.MessageHandler; -import jakarta.websocket.Session; -import jakarta.websocket.SessionException; -import jakarta.websocket.WebSocketContainer; - -public class WSClient extends WebSocketCommonClient { - - private static final String CONTEXT_ROOT = "/ws_sessionexception_web"; - - private static final String SENT_STRING_MESSAGE = "Hello World in String"; - - private static StringBuffer receivedMessageString = new StringBuffer(); - - static CountDownLatch messageLatch; - - public static void main(String[] args) { - new WSClient().run(args); - } - - public WSClient() { - setContextRoot("ws_session_web"); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; - */ - /* Run test */ - /* - * @testName: test1 - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:162; WebSocket:JAVADOC:67; - * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; - * WebSocket:JAVADOC:112; WebSocket:JAVADOC:151; WebSocket:JAVADOC:152; - * - * @test_Strategy: - */ - public void test1() throws Exception { - boolean passed = true; - String message_expected = "TCKTest"; - String message_sent_string = "SessionException test"; - - try { - messageLatch = new CountDownLatch(5); - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - final Session session = clientContainer.connectToServer( - com.sun.ts.tests.websocket.ee.jakarta.websocket.sessionexception.WSClient.TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - receivedMessageString - .append("========Just setup to get a real working session"); - session.getBasicRemote().sendText(message_sent_string); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - Throwable cause_expected = new Throwable(message_expected + 1); - SessionException ex = new SessionException(message_expected, - new Throwable(cause_expected), session); - - Session tmp = ex.getSession(); - if (tmp != session) { - passed = false; - receivedMessageString - .append("========Incorrect session returned, expecting " + session - + ", got " + tmp); - } - - String msg = ex.getMessage(); - if (!message_expected.equals(msg)) { - passed = false; - receivedMessageString - .append("========Incorrect message returned, expecting " - + message_expected + ", got " + msg); - } - - Throwable cause = ex.getCause(); - if (cause.getCause() != null) { - cause = cause.getCause(); - } else { - passed = false; - receivedMessageString - .append("Lost one wrap of Throwable during the process"); - } - if (cause_expected != cause) { - passed = false; - receivedMessageString - .append("========Incorrect cause returned, expecting " - + cause_expected + ", got " + cause); - } - - session.close(); - - Boolean passed_tmp = MessageValidator.checkSearchStrings( - "TCKTestServer opened|" + "TCKTestServer received String:|" - + message_sent_string + "|" - + "TCKTestServer responds, please close your session", - receivedMessageString.toString()); - - if (!passed_tmp) { - passed = false; - } - - } catch (Exception e) { - e.printStackTrace(); - passed = false; - receivedMessageString.append("========unexpected Exception caught"); - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - @Override - public void cleanup() throws Exception { - super.cleanup(); - } - - public final static class TCKBasicEndpoint extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - receivedMessageString.append(message); - messageLatch.countDown(); - } - }); - } - - @Override - public void onClose(Session session, CloseReason closeReason) { - receivedMessageString.append("CloseCode=" + closeReason.getCloseCode()); - receivedMessageString - .append("ReasonPhrase=" + closeReason.getReasonPhrase()); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/WSClientIT.java new file mode 100644 index 0000000000..3bca1ba530 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/WSClientIT.java @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $Id$ + */ +package com.sun.ts.tests.websocket.ee.jakarta.websocket.sessionexception; + +import java.io.IOException; +import java.net.URI; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.MessageValidator; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.CloseReason; +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.Endpoint; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.MessageHandler; +import jakarta.websocket.Session; +import jakarta.websocket.SessionException; +import jakarta.websocket.WebSocketContainer; + +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_sessionexception_web.war"); + archive.addClass(WSTestServer.class); + archive.addAsWebInfResource(WSClientIT.class.getPackage(), "web.xml", "web.xml"); + return archive; + } + + private static final String CONTEXT_ROOT = "/ws_sessionexception_web"; + + private static final String SENT_STRING_MESSAGE = "Hello World in String"; + + private static StringBuffer receivedMessageString = new StringBuffer(); + + static CountDownLatch messageLatch; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("ws_sessionexception_web"); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; + */ + /* Run test */ + /* + * @testName: test1 + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:162; WebSocket:JAVADOC:67; + * WebSocket:JAVADOC:69; WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; + * WebSocket:JAVADOC:112; WebSocket:JAVADOC:151; WebSocket:JAVADOC:152; + * + * @test_Strategy: + */ + @Test + public void test1() throws Exception { + boolean passed = true; + String message_expected = "TCKTest"; + String message_sent_string = "SessionException test"; + + try { + messageLatch = new CountDownLatch(5); + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + final Session session = clientContainer.connectToServer( + com.sun.ts.tests.websocket.ee.jakarta.websocket.sessionexception.WSClientIT.TCKBasicEndpoint.class, + config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + receivedMessageString.append("========Just setup to get a real working session"); + session.getBasicRemote().sendText(message_sent_string); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + Throwable cause_expected = new Throwable(message_expected + 1); + SessionException ex = new SessionException(message_expected, new Throwable(cause_expected), session); + + Session tmp = ex.getSession(); + if (tmp != session) { + passed = false; + receivedMessageString + .append("========Incorrect session returned, expecting " + session + ", got " + tmp); + } + + String msg = ex.getMessage(); + if (!message_expected.equals(msg)) { + passed = false; + receivedMessageString + .append("========Incorrect message returned, expecting " + message_expected + ", got " + msg); + } + + Throwable cause = ex.getCause(); + if (cause.getCause() != null) { + cause = cause.getCause(); + } else { + passed = false; + receivedMessageString.append("Lost one wrap of Throwable during the process"); + } + if (cause_expected != cause) { + passed = false; + receivedMessageString + .append("========Incorrect cause returned, expecting " + cause_expected + ", got " + cause); + } + + session.close(); + + Boolean passed_tmp = MessageValidator + .checkSearchStrings( + "TCKTestServer opened|" + "TCKTestServer received String:|" + message_sent_string + "|" + + "TCKTestServer responds, please close your session", + receivedMessageString.toString()); + + if (!passed_tmp) { + passed = false; + } + + } catch (Exception e) { + e.printStackTrace(); + passed = false; + receivedMessageString.append("========unexpected Exception caught"); + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + @Override + public void cleanup() throws Exception { + super.cleanup(); + } + + public final static class TCKBasicEndpoint extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append(message); + messageLatch.countDown(); + } + }); + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + receivedMessageString.append("CloseCode=" + closeReason.getCloseCode()); + receivedMessageString.append("ReasonPhrase=" + closeReason.getReasonPhrase()); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/WSTestServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/WSTestServer.java index 8ce92a303a..9934af7b61 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/WSTestServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/WSTestServer.java @@ -33,59 +33,54 @@ @ServerEndpoint(value = "/TCKTestServer") public class WSTestServer { - private static final Class[] TEST_ARGS = { String.class, Session.class }; + private static final Class[] TEST_ARGS = { String.class, Session.class }; - static String testName; + static String testName; - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========TCKTestServer opened"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from Server is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from Server is open=FALSE"); - } - } + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========TCKTestServer opened"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from Server is open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from Server is open=FALSE"); + } + } - @OnMessage - public void respondString(String message, Session session) { - System.out.println("TCKTestServer got String message: " + message); - try { - if (message.startsWith("testName=") && message.endsWith("Test")) { - testName = message.substring(9); - Method method = WSTestServer.class.getMethod(testName, TEST_ARGS); - method.invoke(this, new Object[] { message, session }); - } else { - session.getBasicRemote() - .sendText("========TCKTestServer received String:" + message); - session.getBasicRemote().sendText( - "========TCKTestServer responds, please close your session"); - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnMessage + public void respondString(String message, Session session) { + System.out.println("TCKTestServer got String message: " + message); + try { + if (message.startsWith("testName=") && message.endsWith("Test")) { + testName = message.substring(9); + Method method = WSTestServer.class.getMethod(testName, TEST_ARGS); + method.invoke(this, new Object[] { message, session }); + } else { + session.getBasicRemote().sendText("========TCKTestServer received String:" + message); + session.getBasicRemote().sendText("========TCKTestServer responds, please close your session"); + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } - @OnError - public void error(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========TCKTestServer onError"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========onError: session from Server is open=TRUE"); - session.close(); - } - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void error(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========TCKTestServer onError"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========onError: session from Server is open=TRUE"); + session.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryDecoder.java index 3ee149630a..3d29e4a80a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryDecoder.java @@ -26,8 +26,8 @@ public class ThrowingBinaryDecoder extends StringBeanBinaryDecoder { - @Override - public StringBean decode(ByteBuffer arg0) throws DecodeException { - throw new DecodeException(arg0, ThrowingTextDecoder.ERR_MSG); - } + @Override + public StringBean decode(ByteBuffer arg0) throws DecodeException { + throw new DecodeException(arg0, ThrowingTextDecoder.ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryEncoder.java index 49a241d5bf..2d86b2df2f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryEncoder.java @@ -26,8 +26,8 @@ public class ThrowingBinaryEncoder extends StringBeanBinaryEncoder { - @Override - public ByteBuffer encode(StringBean bean) throws EncodeException { - throw new EncodeException(bean.get(), ThrowingTextDecoder.ERR_MSG); - } + @Override + public ByteBuffer encode(StringBean bean) throws EncodeException { + throw new EncodeException(bean.get(), ThrowingTextDecoder.ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryStreamDecoder.java index 345854c1a9..4d2311edde 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryStreamDecoder.java @@ -28,10 +28,8 @@ public class ThrowingBinaryStreamDecoder extends StringBeanBinaryStreamDecoder { - @Override - public StringBean decode(InputStream arg0) - throws DecodeException, IOException { - throw new DecodeException(IOUtil.readFromStream(arg0), - ThrowingTextDecoder.ERR_MSG); - } + @Override + public StringBean decode(InputStream arg0) throws DecodeException, IOException { + throw new DecodeException(IOUtil.readFromStream(arg0), ThrowingTextDecoder.ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryStreamEncoder.java index 14b0460223..225ab18bbb 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingBinaryStreamEncoder.java @@ -27,9 +27,8 @@ public class ThrowingBinaryStreamEncoder extends StringBeanBinaryStreamEncoder { - @Override - public void encode(StringBean bean, OutputStream stream) - throws EncodeException, IOException { - throw new EncodeException(bean.get(), ThrowingTextDecoder.ERR_MSG); - } + @Override + public void encode(StringBean bean, OutputStream stream) throws EncodeException, IOException { + throw new EncodeException(bean.get(), ThrowingTextDecoder.ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOBinaryStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOBinaryStreamDecoder.java index d7f39b6af8..389828fada 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOBinaryStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOBinaryStreamDecoder.java @@ -25,12 +25,10 @@ import jakarta.websocket.DecodeException; -public class ThrowingIOBinaryStreamDecoder - extends StringBeanBinaryStreamDecoder { +public class ThrowingIOBinaryStreamDecoder extends StringBeanBinaryStreamDecoder { - @Override - public StringBean decode(InputStream arg0) - throws DecodeException, IOException { - throw new IOException(ThrowingTextDecoder.IO_ERR_MSG); - } + @Override + public StringBean decode(InputStream arg0) throws DecodeException, IOException { + throw new IOException(ThrowingTextDecoder.IO_ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOBinaryStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOBinaryStreamEncoder.java index 09c5d4cd6e..47ad4c7ebd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOBinaryStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOBinaryStreamEncoder.java @@ -25,12 +25,10 @@ import jakarta.websocket.EncodeException; -public class ThrowingIOBinaryStreamEncoder - extends StringBeanBinaryStreamEncoder { +public class ThrowingIOBinaryStreamEncoder extends StringBeanBinaryStreamEncoder { - @Override - public void encode(StringBean bean, OutputStream stream) - throws EncodeException, IOException { - throw new IOException(ThrowingTextDecoder.IO_ERR_MSG); - } + @Override + public void encode(StringBean bean, OutputStream stream) throws EncodeException, IOException { + throw new IOException(ThrowingTextDecoder.IO_ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOTextStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOTextStreamDecoder.java index 46ab89f047..7a2def8962 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOTextStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOTextStreamDecoder.java @@ -27,8 +27,8 @@ public class ThrowingIOTextStreamDecoder extends StringBeanTextStreamDecoder { - @Override - public StringBean decode(Reader r) throws DecodeException, IOException { - throw new IOException(ThrowingTextDecoder.IO_ERR_MSG); - } + @Override + public StringBean decode(Reader r) throws DecodeException, IOException { + throw new IOException(ThrowingTextDecoder.IO_ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOTextStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOTextStreamEncoder.java index 778fbb249e..42b4fef8c3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOTextStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingIOTextStreamEncoder.java @@ -27,9 +27,8 @@ public class ThrowingIOTextStreamEncoder extends StringBeanTextStreamEncoder { - @Override - public void encode(StringBean bean, Writer writer) - throws EncodeException, IOException { - throw new IOException(ThrowingTextDecoder.IO_ERR_MSG); - } + @Override + public void encode(StringBean bean, Writer writer) throws EncodeException, IOException { + throw new IOException(ThrowingTextDecoder.IO_ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextDecoder.java index 3f310e0a00..90a71c86ce 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextDecoder.java @@ -23,21 +23,21 @@ import jakarta.websocket.DecodeException; public class ThrowingTextDecoder extends StringBeanTextDecoder { - public static final String ERR_MSG = "TCK coder exception for test"; + public static final String ERR_MSG = "TCK coder exception for test"; - public static final String IO_ERR_MSG = "TCK IO exception for test"; + public static final String IO_ERR_MSG = "TCK IO exception for test"; - @Override - public StringBean decode(String s) throws DecodeException { - throw new DecodeException(s, ERR_MSG); - } + @Override + public StringBean decode(String s) throws DecodeException { + throw new DecodeException(s, ERR_MSG); + } - public static String getCauseMessage(Throwable t) { - String msg = null; - while (t != null) { - msg = t.getMessage(); - t = t.getCause(); - } - return msg; - } + public static String getCauseMessage(Throwable t) { + String msg = null; + while (t != null) { + msg = t.getMessage(); + t = t.getCause(); + } + return msg; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextEncoder.java index af9b5687fc..e23bda1788 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextEncoder.java @@ -24,8 +24,8 @@ public class ThrowingTextEncoder extends StringBeanTextEncoder { - @Override - public String encode(StringBean bean) throws EncodeException { - throw new EncodeException(bean.get(), ThrowingTextDecoder.ERR_MSG); - } + @Override + public String encode(StringBean bean) throws EncodeException { + throw new EncodeException(bean.get(), ThrowingTextDecoder.ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextStreamDecoder.java index bbe0379a75..7b14195b6e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextStreamDecoder.java @@ -28,9 +28,9 @@ public class ThrowingTextStreamDecoder extends StringBeanTextStreamDecoder { - @Override - public StringBean decode(Reader r) throws DecodeException, IOException { - String text = IOUtil.readFromReader(r); - throw new DecodeException(text, ThrowingTextDecoder.ERR_MSG); - } + @Override + public StringBean decode(Reader r) throws DecodeException, IOException { + String text = IOUtil.readFromReader(r); + throw new DecodeException(text, ThrowingTextDecoder.ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextStreamEncoder.java index 7f5fd21035..e7a3c1d671 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/ThrowingTextStreamEncoder.java @@ -27,9 +27,8 @@ public class ThrowingTextStreamEncoder extends StringBeanTextStreamEncoder { - @Override - public void encode(StringBean bean, Writer writer) - throws EncodeException, IOException { - throw new EncodeException(bean.get(), ThrowingTextDecoder.ERR_MSG); - } + @Override + public void encode(StringBean bean, Writer writer) throws EncodeException, IOException { + throw new EncodeException(bean.get(), ThrowingTextDecoder.ERR_MSG); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryDecoderServer.java index 921e1f01e6..c5b4416624 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryDecoderServer.java @@ -28,19 +28,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarydecoder", decoders = { - ThrowingBinaryDecoder.class }) +@ServerEndpoint(value = "/binarydecoder", decoders = { ThrowingBinaryDecoder.class }) public class WSCBinaryDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryEncoderServer.java index 0b2a92364d..7ac67792b2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryEncoderServer.java @@ -29,20 +29,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binaryencoder", encoders = { - ThrowingBinaryEncoder.class }) +@ServerEndpoint(value = "/binaryencoder", encoders = { ThrowingBinaryEncoder.class }) public class WSCBinaryEncoderServer { - @OnMessage - public void echo(String data, Session session) - throws IOException, EncodeException { - session.getBasicRemote().sendObject(new StringBean(data)); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public void echo(String data, Session session) throws IOException, EncodeException { + session.getBasicRemote().sendObject(new StringBean(data)); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryStreamDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryStreamDecoderServer.java index 10e9af194a..60e7a4b7e6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryStreamDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryStreamDecoderServer.java @@ -28,18 +28,17 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarystreamdecoder", decoders = { - ThrowingBinaryStreamDecoder.class }) +@ServerEndpoint(value = "/binarystreamdecoder", decoders = { ThrowingBinaryStreamDecoder.class }) public class WSCBinaryStreamDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryStreamEncoderServer.java index a1f9d3991a..081acb3095 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCBinaryStreamEncoderServer.java @@ -30,22 +30,19 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarystreamencoder", encoders = { - ThrowingBinaryStreamEncoder.class }) +@ServerEndpoint(value = "/binarystreamencoder", encoders = { ThrowingBinaryStreamEncoder.class }) public class WSCBinaryStreamEncoderServer { - @OnMessage - public void echo(String data, Session session) - throws InterruptedException, ExecutionException { - Future future = session.getAsyncRemote() - .sendObject(new StringBean(data)); - future.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public void echo(String data, Session session) throws InterruptedException, ExecutionException { + Future future = session.getAsyncRemote().sendObject(new StringBean(data)); + future.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryDecoder.java index 059e312020..67d65ca652 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryDecoder.java @@ -33,38 +33,37 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = ThrowingBinaryDecoder.class) -public class WSCClientEndpointWithBinaryDecoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithBinaryDecoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithBinaryDecoder() { - super(new StringBeanClientEndpoint()); - } + public WSCClientEndpointWithBinaryDecoder() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - StringBean bean = new StringBean(error); - onMessage(bean); - onMessage(bean); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + StringBean bean = new StringBean(error); + onMessage(bean); + onMessage(bean); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryEncoder.java index b9c35bb82f..dca66d0b12 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryEncoder.java @@ -32,37 +32,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingBinaryEncoder.class) -public class WSCClientEndpointWithBinaryEncoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithBinaryEncoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithBinaryEncoder() { - super(new StringClientEndpoint()); - } + public WSCClientEndpointWithBinaryEncoder() { + super(new StringClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config);// should throw on SendMessageCallback - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config);// should throw on SendMessageCallback + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - onMessage(error); - onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + onMessage(error); + onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryStreamDecoder.java index 3fb352f3e5..db3de41674 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryStreamDecoder.java @@ -33,38 +33,37 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = ThrowingBinaryStreamDecoder.class) -public class WSCClientEndpointWithBinaryStreamDecoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithBinaryStreamDecoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithBinaryStreamDecoder() { - super(new StringBeanClientEndpoint()); - } + public WSCClientEndpointWithBinaryStreamDecoder() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - StringBean bean = new StringBean(error); - onMessage(bean); - onMessage(bean); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + StringBean bean = new StringBean(error); + onMessage(bean); + onMessage(bean); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryStreamEncoder.java index 7825a0451e..32aa9c8ba0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithBinaryStreamEncoder.java @@ -32,37 +32,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingBinaryStreamEncoder.class) -public class WSCClientEndpointWithBinaryStreamEncoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithBinaryStreamEncoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithBinaryStreamEncoder() { - super(new StringClientEndpoint()); - } + public WSCClientEndpointWithBinaryStreamEncoder() { + super(new StringClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); // should throw on SendMessageCallback - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); // should throw on SendMessageCallback + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - onMessage(error); - onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + onMessage(error); + onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOBinaryStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOBinaryStreamDecoder.java index 22eb04c1bd..79c78936fd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOBinaryStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOBinaryStreamDecoder.java @@ -33,38 +33,37 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = ThrowingIOBinaryStreamDecoder.class) -public class WSCClientEndpointWithIOBinaryStreamDecoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithIOBinaryStreamDecoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithIOBinaryStreamDecoder() { - super(new StringBeanClientEndpoint()); - } + public WSCClientEndpointWithIOBinaryStreamDecoder() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - StringBean bean = new StringBean(error); - onMessage(bean); - onMessage(bean); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + StringBean bean = new StringBean(error); + onMessage(bean); + onMessage(bean); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOBinaryStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOBinaryStreamEncoder.java index 39e24d426a..557510d6b5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOBinaryStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOBinaryStreamEncoder.java @@ -32,37 +32,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingIOBinaryStreamEncoder.class) -public class WSCClientEndpointWithIOBinaryStreamEncoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithIOBinaryStreamEncoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithIOBinaryStreamEncoder() { - super(new StringClientEndpoint()); - } + public WSCClientEndpointWithIOBinaryStreamEncoder() { + super(new StringClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); // should throw on SendMessageCallback - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); // should throw on SendMessageCallback + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - onMessage(error); - onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + onMessage(error); + onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOTextStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOTextStreamDecoder.java index e01b5f82a6..2e31b1b938 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOTextStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOTextStreamDecoder.java @@ -33,38 +33,37 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = ThrowingIOTextStreamDecoder.class) -public class WSCClientEndpointWithIOTextStreamDecoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithIOTextStreamDecoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithIOTextStreamDecoder() { - super(new StringBeanClientEndpoint()); - } + public WSCClientEndpointWithIOTextStreamDecoder() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - StringBean bean = new StringBean(error); - onMessage(bean); - onMessage(bean); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + StringBean bean = new StringBean(error); + onMessage(bean); + onMessage(bean); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOTextStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOTextStreamEncoder.java index d784d37e25..7e31429008 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOTextStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithIOTextStreamEncoder.java @@ -32,37 +32,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingIOTextStreamEncoder.class) -public class WSCClientEndpointWithIOTextStreamEncoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithIOTextStreamEncoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithIOTextStreamEncoder() { - super(new StringClientEndpoint()); - } + public WSCClientEndpointWithIOTextStreamEncoder() { + super(new StringClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); // should throw on SendMessageCallback - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); // should throw on SendMessageCallback + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - onMessage(error); - onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + onMessage(error); + onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextDecoder.java index db33b1215e..a7beebe42f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextDecoder.java @@ -33,38 +33,37 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = ThrowingTextDecoder.class) -public class WSCClientEndpointWithTextDecoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithTextDecoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithTextDecoder() { - super(new StringBeanClientEndpoint()); - } + public WSCClientEndpointWithTextDecoder() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - StringBean bean = new StringBean(error); - onMessage(bean); - onMessage(bean); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + StringBean bean = new StringBean(error); + onMessage(bean); + onMessage(bean); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextEncoder.java index eb661747e0..595af63d02 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextEncoder.java @@ -32,37 +32,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingTextEncoder.class) -public class WSCClientEndpointWithTextEncoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithTextEncoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithTextEncoder() { - super(new StringClientEndpoint()); - } + public WSCClientEndpointWithTextEncoder() { + super(new StringClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); // should throw on SendMessageCallback - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); // should throw on SendMessageCallback + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - onMessage(error); - onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + onMessage(error); + onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextStreamDecoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextStreamDecoder.java index e2881d9421..5b28d33251 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextStreamDecoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextStreamDecoder.java @@ -33,38 +33,37 @@ import jakarta.websocket.Session; @ClientEndpoint(decoders = ThrowingTextStreamDecoder.class) -public class WSCClientEndpointWithTextStreamDecoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithTextStreamDecoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithTextStreamDecoder() { - super(new StringBeanClientEndpoint()); - } + public WSCClientEndpointWithTextStreamDecoder() { + super(new StringBeanClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(StringBean msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(StringBean msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - StringBean bean = new StringBean(error); - onMessage(bean); - onMessage(bean); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + StringBean bean = new StringBean(error); + onMessage(bean); + onMessage(bean); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextStreamEncoder.java index 9ab2b4b7ed..0941cb3497 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCClientEndpointWithTextStreamEncoder.java @@ -32,37 +32,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingTextStreamEncoder.class) -public class WSCClientEndpointWithTextStreamEncoder - extends AnnotatedClientEndpoint { +public class WSCClientEndpointWithTextStreamEncoder extends AnnotatedClientEndpoint { - public WSCClientEndpointWithTextStreamEncoder() { - super(new StringClientEndpoint()); - } + public WSCClientEndpointWithTextStreamEncoder() { + super(new StringClientEndpoint()); + } - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); // should throw on SendMessageCallback - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); // should throw on SendMessageCallback + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - onMessage(error); - onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + onMessage(error); + onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOBinaryStreamDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOBinaryStreamDecoderServer.java index 0d19b4a48c..300da2cbd5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOBinaryStreamDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOBinaryStreamDecoderServer.java @@ -28,18 +28,17 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/iobinarystreamdecoder", decoders = { - ThrowingIOBinaryStreamDecoder.class }) +@ServerEndpoint(value = "/iobinarystreamdecoder", decoders = { ThrowingIOBinaryStreamDecoder.class }) public class WSCIOBinaryStreamDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOBinaryStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOBinaryStreamEncoderServer.java index a371488235..e4ab81fcd4 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOBinaryStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOBinaryStreamEncoderServer.java @@ -30,22 +30,19 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/iobinarystreamencoder", encoders = { - ThrowingIOBinaryStreamEncoder.class }) +@ServerEndpoint(value = "/iobinarystreamencoder", encoders = { ThrowingIOBinaryStreamEncoder.class }) public class WSCIOBinaryStreamEncoderServer { - @OnMessage - public void echo(String data, Session session) - throws InterruptedException, ExecutionException { - Future future = session.getAsyncRemote() - .sendObject(new StringBean(data)); - future.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public void echo(String data, Session session) throws InterruptedException, ExecutionException { + Future future = session.getAsyncRemote().sendObject(new StringBean(data)); + future.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOTextStreamDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOTextStreamDecoderServer.java index 31b3df03dd..971aa2bc6e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOTextStreamDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOTextStreamDecoderServer.java @@ -28,19 +28,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/iotextstreamdecoder", decoders = { - ThrowingIOTextStreamDecoder.class }) +@ServerEndpoint(value = "/iotextstreamdecoder", decoders = { ThrowingIOTextStreamDecoder.class }) public class WSCIOTextStreamDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOTextStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOTextStreamEncoderServer.java index 5f5c6f69f9..824b73c0c3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOTextStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCIOTextStreamEncoderServer.java @@ -31,24 +31,22 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/iotextstreamencoder", encoders = { - ThrowingIOTextStreamEncoder.class }) +@ServerEndpoint(value = "/iotextstreamencoder", encoders = { ThrowingIOTextStreamEncoder.class }) public class WSCIOTextStreamEncoderServer { - @OnMessage - public void echo(String data, Session session) - throws InterruptedException, ExecutionException { - WaitingSendHandler handler = new WaitingSendHandler(); - session.getAsyncRemote().sendObject(new StringBean(data), handler); - SendResult result = handler.waitForResult(4); - if (result.getException() != null) - throw new RuntimeException(result.getException()); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public void echo(String data, Session session) throws InterruptedException, ExecutionException { + WaitingSendHandler handler = new WaitingSendHandler(); + session.getAsyncRemote().sendObject(new StringBean(data), handler); + SendResult result = handler.waitForResult(4); + if (result.getException() != null) + throw new RuntimeException(result.getException()); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningBinaryEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningBinaryEncoderServer.java index 0b31374b7b..c693f7ede1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningBinaryEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningBinaryEncoderServer.java @@ -28,19 +28,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/returningbinaryencoder", encoders = { - ThrowingBinaryEncoder.class }) +@ServerEndpoint(value = "/returningbinaryencoder", encoders = { ThrowingBinaryEncoder.class }) public class WSCReturningBinaryEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningBinaryStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningBinaryStreamEncoderServer.java index a6fef987ba..a65ecd2bb1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningBinaryStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningBinaryStreamEncoderServer.java @@ -28,19 +28,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/returningbinarystreamencoder", encoders = { - ThrowingBinaryStreamEncoder.class }) +@ServerEndpoint(value = "/returningbinarystreamencoder", encoders = { ThrowingBinaryStreamEncoder.class }) public class WSCReturningBinaryStreamEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithBinaryEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithBinaryEncoder.java index d4ea38025e..b9ea12e634 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithBinaryEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithBinaryEncoder.java @@ -33,37 +33,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingBinaryEncoder.class) -public class WSCReturningClientEndpointWithBinaryEncoder - extends AnnotatedClientEndpoint { +public class WSCReturningClientEndpointWithBinaryEncoder extends AnnotatedClientEndpoint { - public WSCReturningClientEndpointWithBinaryEncoder() { - super(new StringClientEndpoint()); - } + public WSCReturningClientEndpointWithBinaryEncoder() { + super(new StringClientEndpoint()); + } - @SuppressWarnings("unused") - @OnMessage - public StringBean onMessage(String msg, Session session) { - return new StringBean(msg); - } + @SuppressWarnings("unused") + @OnMessage + public StringBean onMessage(String msg, Session session) { + return new StringBean(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); // throwing encoder is not used here! - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); // throwing encoder is not used here! + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - super.onMessage(error); - super.onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + super.onMessage(error); + super.onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithBinaryStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithBinaryStreamEncoder.java index c2396e96f2..61eb9be69d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithBinaryStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithBinaryStreamEncoder.java @@ -33,37 +33,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingBinaryStreamEncoder.class) -public class WSCReturningClientEndpointWithBinaryStreamEncoder - extends AnnotatedClientEndpoint { +public class WSCReturningClientEndpointWithBinaryStreamEncoder extends AnnotatedClientEndpoint { - public WSCReturningClientEndpointWithBinaryStreamEncoder() { - super(new StringClientEndpoint()); - } + public WSCReturningClientEndpointWithBinaryStreamEncoder() { + super(new StringClientEndpoint()); + } - @SuppressWarnings("unused") - @OnMessage - public StringBean onMessage(String msg, Session session) { - return new StringBean(msg); - } + @SuppressWarnings("unused") + @OnMessage + public StringBean onMessage(String msg, Session session) { + return new StringBean(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); // throwing encoder is not used here! - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); // throwing encoder is not used here! + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - super.onMessage(error); - super.onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + super.onMessage(error); + super.onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithIOBinaryStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithIOBinaryStreamEncoder.java index c64be3b422..8f6d6aa09b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithIOBinaryStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithIOBinaryStreamEncoder.java @@ -33,37 +33,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingIOBinaryStreamEncoder.class) -public class WSCReturningClientEndpointWithIOBinaryStreamEncoder - extends AnnotatedClientEndpoint { +public class WSCReturningClientEndpointWithIOBinaryStreamEncoder extends AnnotatedClientEndpoint { - public WSCReturningClientEndpointWithIOBinaryStreamEncoder() { - super(new StringClientEndpoint()); - } + public WSCReturningClientEndpointWithIOBinaryStreamEncoder() { + super(new StringClientEndpoint()); + } - @SuppressWarnings("unused") - @OnMessage - public StringBean onMessage(String msg, Session session) { - return new StringBean(msg); - } + @SuppressWarnings("unused") + @OnMessage + public StringBean onMessage(String msg, Session session) { + return new StringBean(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); // throwing encoder is not used here! - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); // throwing encoder is not used here! + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - super.onMessage(error); - super.onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + super.onMessage(error); + super.onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithIOTextStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithIOTextStreamEncoder.java index b8480b2324..53d1a33c1a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithIOTextStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithIOTextStreamEncoder.java @@ -33,37 +33,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingIOTextStreamEncoder.class) -public class WSCReturningClientEndpointWithIOTextStreamEncoder - extends AnnotatedClientEndpoint { +public class WSCReturningClientEndpointWithIOTextStreamEncoder extends AnnotatedClientEndpoint { - public WSCReturningClientEndpointWithIOTextStreamEncoder() { - super(new StringClientEndpoint()); - } + public WSCReturningClientEndpointWithIOTextStreamEncoder() { + super(new StringClientEndpoint()); + } - @SuppressWarnings("unused") - @OnMessage - public StringBean onMessage(String msg, Session session) { - return new StringBean(msg); - } + @SuppressWarnings("unused") + @OnMessage + public StringBean onMessage(String msg, Session session) { + return new StringBean(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); // throwing encoder is not used here! - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); // throwing encoder is not used here! + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - super.onMessage(error); - super.onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + super.onMessage(error); + super.onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithTextEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithTextEncoder.java index 54d831f1e9..e70b473eed 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithTextEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithTextEncoder.java @@ -33,37 +33,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingTextEncoder.class) -public class WSCReturningClientEndpointWithTextEncoder - extends AnnotatedClientEndpoint { +public class WSCReturningClientEndpointWithTextEncoder extends AnnotatedClientEndpoint { - public WSCReturningClientEndpointWithTextEncoder() { - super(new StringClientEndpoint()); - } + public WSCReturningClientEndpointWithTextEncoder() { + super(new StringClientEndpoint()); + } - @SuppressWarnings("unused") - @OnMessage - public StringBean onMessage(String msg, Session session) { - return new StringBean(msg); - } + @SuppressWarnings("unused") + @OnMessage + public StringBean onMessage(String msg, Session session) { + return new StringBean(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); // throwing encoder is not used here! - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); // throwing encoder is not used here! + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - super.onMessage(error); - super.onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + super.onMessage(error); + super.onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithTextStreamEncoder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithTextStreamEncoder.java index 9ed1112fe4..cd3156455f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithTextStreamEncoder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningClientEndpointWithTextStreamEncoder.java @@ -33,37 +33,36 @@ import jakarta.websocket.Session; @ClientEndpoint(encoders = ThrowingTextStreamEncoder.class) -public class WSCReturningClientEndpointWithTextStreamEncoder - extends AnnotatedClientEndpoint { +public class WSCReturningClientEndpointWithTextStreamEncoder extends AnnotatedClientEndpoint { - public WSCReturningClientEndpointWithTextStreamEncoder() { - super(new StringClientEndpoint()); - } + public WSCReturningClientEndpointWithTextStreamEncoder() { + super(new StringClientEndpoint()); + } - @SuppressWarnings("unused") - @OnMessage - public StringBean onMessage(String msg, Session session) { - return new StringBean(msg); - } + @SuppressWarnings("unused") + @OnMessage + public StringBean onMessage(String msg, Session session) { + return new StringBean(msg); + } - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); // throwing encoder is not used here! - } + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); // throwing encoder is not used here! + } - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } - @Override - @OnError - public void onError(Session session, Throwable t) { - String error = WebSocketCommonClient.getCauseMessage(t); - super.onMessage(error); - super.onMessage(error); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + String error = WebSocketCommonClient.getCauseMessage(t); + super.onMessage(error); + super.onMessage(error); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningIOBinaryStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningIOBinaryStreamEncoderServer.java index 16fe59b77a..a8c472ca6e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningIOBinaryStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningIOBinaryStreamEncoderServer.java @@ -28,19 +28,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/ioreturningbinarystreamencoder", encoders = { - ThrowingIOBinaryStreamEncoder.class }) +@ServerEndpoint(value = "/ioreturningbinarystreamencoder", encoders = { ThrowingIOBinaryStreamEncoder.class }) public class WSCReturningIOBinaryStreamEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningIOTextStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningIOTextStreamEncoderServer.java index 96c91fbc10..d952749879 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningIOTextStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningIOTextStreamEncoderServer.java @@ -28,19 +28,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/ioreturningtextstreamencoder", encoders = { - ThrowingIOTextStreamEncoder.class }) +@ServerEndpoint(value = "/ioreturningtextstreamencoder", encoders = { ThrowingIOTextStreamEncoder.class }) public class WSCReturningIOTextStreamEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningTextEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningTextEncoderServer.java index 6fb8faca12..c8bc3ce8be 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningTextEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningTextEncoderServer.java @@ -28,19 +28,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/returningtextencoder", encoders = { - ThrowingTextEncoder.class }) +@ServerEndpoint(value = "/returningtextencoder", encoders = { ThrowingTextEncoder.class }) public class WSCReturningTextEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningTextStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningTextStreamEncoderServer.java index 8543a454af..25ca022919 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningTextStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCReturningTextStreamEncoderServer.java @@ -28,19 +28,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/returningtextstreamencoder", encoders = { - ThrowingTextStreamEncoder.class }) +@ServerEndpoint(value = "/returningtextstreamencoder", encoders = { ThrowingTextStreamEncoder.class }) public class WSCReturningTextStreamEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCSimpleBinaryEchoServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCSimpleBinaryEchoServer.java index 155ba89b70..c78c63d0cd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCSimpleBinaryEchoServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCSimpleBinaryEchoServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/simplebin") public class WSCSimpleBinaryEchoServer { - @OnMessage - public ByteBuffer echo(String echo) { - return ByteBuffer.wrap(echo.getBytes()); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public ByteBuffer echo(String echo) { + return ByteBuffer.wrap(echo.getBytes()); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCSimpleEchoServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCSimpleEchoServer.java index 875ae2fe4b..eea2d8939c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCSimpleEchoServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCSimpleEchoServer.java @@ -32,36 +32,36 @@ @ServerEndpoint("/simpleecho") public class WSCSimpleEchoServer { - @OnOpen - public void onOpen(final Session session) { - session.addMessageHandler(new MessageHandler.Whole() { - @Override - public void onMessage(ByteBuffer message) { - String ret = echo(IOUtil.byteBufferToString(message)); - try { - session.getBasicRemote().sendText(ret); - } catch (IOException e) { - try { - onError(session, e); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } - }); - } + @OnOpen + public void onOpen(final Session session) { + session.addMessageHandler(new MessageHandler.Whole() { + @Override + public void onMessage(ByteBuffer message) { + String ret = echo(IOUtil.byteBufferToString(message)); + try { + session.getBasicRemote().sendText(ret); + } catch (IOException e) { + try { + onError(session, e); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } + }); + } - @OnMessage - public String echo(String echo) { - return echo; - } + @OnMessage + public String echo(String echo) { + return echo; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextDecoderServer.java index f3685b9fe6..8e35101e46 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextDecoderServer.java @@ -27,19 +27,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textdecoder", decoders = { - ThrowingTextDecoder.class }) +@ServerEndpoint(value = "/textdecoder", decoders = { ThrowingTextDecoder.class }) public class WSCTextDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextEncoderServer.java index 2ad38942f6..1dbee57a2a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextEncoderServer.java @@ -29,20 +29,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textencoder", encoders = { - ThrowingTextEncoder.class }) +@ServerEndpoint(value = "/textencoder", encoders = { ThrowingTextEncoder.class }) public class WSCTextEncoderServer { - @OnMessage - public void echo(String data, Session session) - throws IOException, EncodeException { - session.getBasicRemote().sendObject(new StringBean(data)); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public void echo(String data, Session session) throws IOException, EncodeException { + session.getBasicRemote().sendObject(new StringBean(data)); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextStreamDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextStreamDecoderServer.java index 20aa3f7710..eb300d9e7d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextStreamDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextStreamDecoderServer.java @@ -28,19 +28,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstreamdecoder", decoders = { - ThrowingTextStreamDecoder.class }) +@ServerEndpoint(value = "/textstreamdecoder", decoders = { ThrowingTextStreamDecoder.class }) public class WSCTextStreamDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextStreamEncoderServer.java index d12fd12c0d..25f0ffed82 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSCTextStreamEncoderServer.java @@ -31,24 +31,22 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstreamencoder", encoders = { - ThrowingTextStreamEncoder.class }) +@ServerEndpoint(value = "/textstreamencoder", encoders = { ThrowingTextStreamEncoder.class }) public class WSCTextStreamEncoderServer { - @OnMessage - public void echo(String data, Session session) - throws InterruptedException, ExecutionException { - WaitingSendHandler handler = new WaitingSendHandler(); - session.getAsyncRemote().sendObject(new StringBean(data), handler); - SendResult result = handler.waitForResult(4); - if (result.getException() != null) - throw new RuntimeException(result.getException()); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = ThrowingTextDecoder.getCauseMessage(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public void echo(String data, Session session) throws InterruptedException, ExecutionException { + WaitingSendHandler handler = new WaitingSendHandler(); + session.getAsyncRemote().sendObject(new StringBean(data), handler); + SendResult result = handler.waitForResult(4); + if (result.getException() != null) + throw new RuntimeException(result.getException()); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = ThrowingTextDecoder.getCauseMessage(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSClient.java deleted file mode 100644 index 4f2d51dcab..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSClient.java +++ /dev/null @@ -1,583 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.throwingcoder.annotated; - -import java.nio.ByteBuffer; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.stringbean.StringBean; -import com.sun.ts.tests.websocket.ee.jakarta.websocket.throwingcoder.ThrowingTextDecoder; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = -8094860820359975543L; - - protected static final String ECHO = "Echo message"; - - public WSClient() { - setContextRoot("ee_java_websocket_throwingcoder_annotated_web"); - logExceptionOnInvocation(false); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - /* - * @testName: binaryDecoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:38; - * - * @test_Strategy: test the binary decoder throws decoderException and it is - * caught in @OnError - */ - public void binaryDecoderThrowAndCatchOnServerTest() throws Exception { - invoke("binarydecoder", ByteBuffer.wrap(ECHO.getBytes()), - ThrowingTextDecoder.ERR_MSG); - logMsg("The DecoderException has been propagated to @OnError"); - } - - /* - * @testName: binaryDecoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:38; - * - * @test_Strategy: test the binary decoder throws decoderException and it is - * caught in @OnError - */ - public void binaryDecoderThrowAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithBinaryDecoder endpoint = new WSCClientEndpointWithBinaryDecoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simplebin", ECHO); - logMsg("The DecoderException has been propagated to @OnError"); - } - - /* - * @testName: binaryStreamDecoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:41; - * - * @test_Strategy: test the binary stream decoder throws decoderException and - * it is caught in @OnError - */ - public void binaryStreamDecoderThrowAndCatchOnServerTest() throws Exception { - invoke("binarystreamdecoder", ByteBuffer.wrap(ECHO.getBytes()), - ThrowingTextDecoder.ERR_MSG); - logMsg("The DecoderException has been propagated to @OnError"); - } - - /* - * @testName: binaryStreamDecoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:41; - * - * @test_Strategy: test the binary stream decoder throws decoderException and - * it is caught in @OnError - */ - public void binaryStreamDecoderThrowAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithBinaryStreamDecoder endpoint = new WSCClientEndpointWithBinaryStreamDecoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simplebin", ECHO); - logMsg("The DecoderException has been propagated to @OnError"); - } - - /* - * @testName: textDecoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:44; - * - * @test_Strategy: test the text decoder throws decoderException and it is - * caught in @OnError - */ - public void textDecoderThrowAndCatchOnServerTest() throws Exception { - invoke("textdecoder", ECHO, ThrowingTextDecoder.ERR_MSG); - logMsg("The DecoderException has been propagated to @OnError"); - } - - /* - * @testName: textDecoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:44; - * - * @test_Strategy: test the text decoder throws decoderException and it is - * caught in @OnError - */ - public void textDecoderThrowAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithTextDecoder endpoint = new WSCClientEndpointWithTextDecoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simpleecho", ECHO); - logMsg("The DecoderException has been propagated to @OnError"); - } - - /* - * @testName: textStreamDecoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:47; - * - * @test_Strategy: test the text stream decoder throws decoderException and it - * is caught in @OnError - */ - public void textStreamDecoderThrowAndCatchOnServerTest() throws Exception { - invoke("textstreamdecoder", ECHO, ThrowingTextDecoder.ERR_MSG); - logMsg("The DecoderException has been propagated to @OnError"); - } - - /* - * @testName: textStreamDecoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:47; - * - * @test_Strategy: test the text stream decoder throws decoderException and it - * is caught in @OnError - */ - public void textStreamDecoderThrowAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithTextStreamDecoder endpoint = new WSCClientEndpointWithTextStreamDecoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simpleecho", ECHO); - logMsg("The DecoderException has been propagated to @OnError"); - } - - // --------------------------------------------------------------------- - - /* - * @testName: binaryEncoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:57; - * - * @test_Strategy: test the binary encoder throws EncoderException and it is - * caught in @OnError - */ - public void binaryEncoderThrowAndCatchOnServerTest() throws Exception { - invoke("binaryencoder", ECHO, ThrowingTextDecoder.ERR_MSG); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: binaryEncoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:57; - * - * @test_Strategy: test the binary encoder throws EncoderException and it is - * caught in @OnError - */ - public void binaryEncoderThrowAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithBinaryEncoder endpoint = new WSCClientEndpointWithBinaryEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simpleecho", new StringBean(ECHO)); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: binaryStreamEncoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:59; - * - * @test_Strategy: test the binary stream encoder throws EncoderException and - * it is caught in @OnError - */ - public void binaryStreamEncoderThrowAndCatchOnServerTest() throws Exception { - invoke("binarystreamencoder", ECHO, ThrowingTextDecoder.ERR_MSG); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: binaryStreamEncoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:59; - * - * @test_Strategy: test the binary stream encoder throws EncoderException and - * it is caught in @OnError - */ - public void binaryStreamEncoderThrowAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithBinaryStreamEncoder endpoint = new WSCClientEndpointWithBinaryStreamEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simpleecho", new StringBean(ECHO)); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: textEncoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:62; - * - * @test_Strategy: test the text encoder throws EncoderException and it is - * caught in @OnError - */ - public void textEncoderThrowAndCatchOnServerTest() throws Exception { - invoke("textencoder", ECHO, ThrowingTextDecoder.ERR_MSG); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: textEncoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:62; - * - * @test_Strategy: test the text encoder throws EncoderException and it is - * caught in @OnError - */ - public void textEncoderThrowAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithTextEncoder endpoint = new WSCClientEndpointWithTextEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simpleecho", new StringBean(ECHO)); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: textStreamEncoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:64; - * - * @test_Strategy: test the text stream encoder throws EncoderException and it - * is caught in @OnError - */ - public void textStreamEncoderThrowAndCatchOnServerTest() throws Exception { - invoke("textstreamencoder", ECHO, ThrowingTextDecoder.ERR_MSG); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: textStreamEncoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:64; - * - * @test_Strategy: test the text stream encoder throws EncoderException and it - * is caught in @OnError - */ - public void textStreamEncoderThrowAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithTextStreamEncoder endpoint = new WSCClientEndpointWithTextStreamEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simpleecho", new StringBean(ECHO)); - logMsg("The EncoderException has been propagated to @OnError"); - } - - // ----------------------------------------------------------------------- - // returning encoders - - /* - * @testName: returningBinaryEncoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:57; - * - * @test_Strategy: test the binary encoder throws EncoderException and it is - * caught in @OnError - */ - public void returningBinaryEncoderThrowAndCatchOnServerTest() throws Exception { - invoke("returningbinaryencoder", ECHO, ThrowingTextDecoder.ERR_MSG); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: returningBinaryEncoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:57; - * - * @test_Strategy: test the binary encoder throws EncoderException and it is - * caught in @OnError - */ - public void returningBinaryEncoderThrowAndCatchOnClientTest() throws Exception { - WSCReturningClientEndpointWithBinaryEncoder endpoint = new WSCReturningClientEndpointWithBinaryEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simpleecho", ECHO); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: returningBinaryStreamEncoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:59; - * - * @test_Strategy: test the binary stream encoder throws EncoderException and - * it is caught in @OnError - */ - public void returningBinaryStreamEncoderThrowAndCatchOnServerTest() - throws Exception { - invoke("returningbinarystreamencoder", ECHO, ThrowingTextDecoder.ERR_MSG); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: returningBinaryStreamEncoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:59; - * - * @test_Strategy: test the binary stream encoder throws EncoderException and - * it is caught in @OnError - */ - public void returningBinaryStreamEncoderThrowAndCatchOnClientTest() - throws Exception { - WSCReturningClientEndpointWithBinaryStreamEncoder endpoint = new WSCReturningClientEndpointWithBinaryStreamEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simpleecho", ECHO); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: returningTextEncoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:62; - * - * @test_Strategy: test the text encoder throws EncoderException and it is - * caught in @OnError - */ - public void returningTextEncoderThrowAndCatchOnServerTest() throws Exception { - invoke("returningtextencoder", ECHO, ThrowingTextDecoder.ERR_MSG); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: returningTextEncoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:62; - * - * @test_Strategy: test the text encoder throws EncoderException and it is - * caught in @OnError - */ - public void returningTextEncoderThrowAndCatchOnClientTest() throws Exception { - WSCReturningClientEndpointWithTextEncoder endpoint = new WSCReturningClientEndpointWithTextEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simpleecho", ECHO); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: returningTextStreamEncoderThrowAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:64; - * - * @test_Strategy: test the text stream encoder throws EncoderException and it - * is caught in @OnError - */ - public void returningTextStreamEncoderThrowAndCatchOnServerTest() - throws Exception { - invoke("returningtextstreamencoder", ECHO, ThrowingTextDecoder.ERR_MSG); - logMsg("The EncoderException has been propagated to @OnError"); - } - - /* - * @testName: returningTextStreamEncoderThrowAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:64; - * - * @test_Strategy: test the text stream encoder throws EncoderException and it - * is caught in @OnError - */ - public void returningTextStreamEncoderThrowAndCatchOnClientTest() - throws Exception { - WSCReturningClientEndpointWithTextStreamEncoder endpoint = new WSCReturningClientEndpointWithTextStreamEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeOnClient("simpleecho", ECHO); - logMsg("The EncoderException has been propagated to @OnError"); - } - - // ------------------------------------------------------------------------ - // IO Exceptions - - /* - * @testName: binaryStreamDecoderThrowIOAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:42; - * - * @test_Strategy: test the binary stream decoder throws IOException and it is - * caught in @OnError - */ - public void binaryStreamDecoderThrowIOAndCatchOnServerTest() throws Exception { - invoke("iobinarystreamdecoder", ByteBuffer.wrap(ECHO.getBytes()), - ThrowingTextDecoder.IO_ERR_MSG); - logMsg("The IOException has been propagated to @OnError"); - } - - /* - * @testName: binaryStreamDecoderThrowIOAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:42; - * - * @test_Strategy: test the binary stream decoder throws IOException and it is - * caught in @OnError - */ - public void binaryStreamDecoderThrowIOAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithIOBinaryStreamDecoder endpoint = new WSCClientEndpointWithIOBinaryStreamDecoder(); - setAnnotatedClientEndpoint(endpoint); - invokeIOOnClient("simplebin", ECHO); - logMsg("The IOException has been propagated to @OnError"); - } - - /* - * @testName: textStreamDecoderThrowIOAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:48; - * - * @test_Strategy: test the text stream decoder throws IOException and it is - * caught in @OnError - */ - public void textStreamDecoderThrowIOAndCatchOnServerTest() throws Exception { - invoke("iotextstreamdecoder", ECHO, ThrowingTextDecoder.IO_ERR_MSG); - logMsg("The IOException has been propagated to @OnError"); - } - - /* - * @testName: textStreamDecoderThrowIOAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:48; - * - * @test_Strategy: test the text stream decoder throws IOException and it is - * caught in @OnError - */ - public void textStreamDecoderThrowIOAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithIOTextStreamDecoder endpoint = new WSCClientEndpointWithIOTextStreamDecoder(); - setAnnotatedClientEndpoint(endpoint); - invokeIOOnClient("simpleecho", ECHO); - logMsg("The IOException has been propagated to @OnError"); - } - - /* - * @testName: binaryStreamEncoderThrowIOAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:60; - * - * @test_Strategy: test the binary stream encoder throws IOException and it is - * caught in @OnError - */ - public void binaryStreamEncoderThrowIOAndCatchOnServerTest() throws Exception { - invoke("iobinarystreamencoder", ECHO, ThrowingTextDecoder.IO_ERR_MSG); - logMsg("The IOException has been propagated to @OnError"); - } - - /* - * @testName: binaryStreamEncoderThrowIOAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:60; - * - * @test_Strategy: test the binary stream encoder throws IOException and it is - * caught in @OnError - */ - public void binaryStreamEncoderThrowIOAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithIOBinaryStreamEncoder endpoint = new WSCClientEndpointWithIOBinaryStreamEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeIOOnClient("simpleecho", new StringBean(ECHO)); - logMsg("The IOException has been propagated to @OnError"); - } - - /* - * @testName: textStreamEncoderThrowIOAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:65; - * - * @test_Strategy: test the text stream encoder throws IOException and it is - * caught in @OnError - */ - public void textStreamEncoderThrowIOAndCatchOnServerTest() throws Exception { - invoke("iotextstreamencoder", ECHO, ThrowingTextDecoder.IO_ERR_MSG); - logMsg("The IOException has been propagated to @OnError"); - } - - /* - * @testName: textStreamEncoderThrowIOAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:65; - * - * @test_Strategy: test the text stream encoder throws IOException and it is - * caught in @OnError - */ - public void textStreamEncoderThrowIOAndCatchOnClientTest() throws Exception { - WSCClientEndpointWithIOTextStreamEncoder endpoint = new WSCClientEndpointWithIOTextStreamEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeIOOnClient("simpleecho", new StringBean(ECHO)); - logMsg("The IOException has been propagated to @OnError"); - } - - /* - * @testName: returningBinaryStreamEncoderThrowIOAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:60; - * - * @test_Strategy: test the binary stream encoder throws IOException and it is - * caught in @OnError - */ - public void returningBinaryStreamEncoderThrowIOAndCatchOnServerTest() - throws Exception { - invoke("ioreturningbinarystreamencoder", ECHO, - ThrowingTextDecoder.IO_ERR_MSG); - logMsg("The IOException has been propagated to @OnError"); - } - - /* - * @testName: returningBinaryStreamEncoderThrowIOAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:60; - * - * @test_Strategy: test the binary stream encoder throws IOException and it is - * caught in @OnError - */ - public void returningBinaryStreamEncoderThrowIOAndCatchOnClientTest() - throws Exception { - WSCReturningClientEndpointWithIOBinaryStreamEncoder endpoint = new WSCReturningClientEndpointWithIOBinaryStreamEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeIOOnClient("simpleecho", ECHO); - logMsg("The IOException has been propagated to @OnError"); - } - - /* - * @testName: returningTextStreamEncoderThrowIOAndCatchOnServerTest - * - * @assertion_ids: WebSocket:JAVADOC:65; - * - * @test_Strategy: test the text stream encoder throws IOException and it is - * caught in @OnError - */ - public void returningTextStreamEncoderThrowIOAndCatchOnServerTest() - throws Exception { - invoke("ioreturningtextstreamencoder", ECHO, - ThrowingTextDecoder.IO_ERR_MSG); - logMsg("The IOException has been propagated to @OnError"); - } - - /* - * @testName: returningTextStreamEncoderThrowIOAndCatchOnClientTest - * - * @assertion_ids: WebSocket:JAVADOC:65; - * - * @test_Strategy: test the text stream encoder throws IOException and it is - * caught in @OnError - */ - public void returningTextStreamEncoderThrowIOAndCatchOnClientTest() - throws Exception { - WSCReturningClientEndpointWithIOTextStreamEncoder endpoint = new WSCReturningClientEndpointWithIOTextStreamEncoder(); - setAnnotatedClientEndpoint(endpoint); - invokeIOOnClient("simpleecho", ECHO); - logMsg("The IOException has been propagated to @OnError"); - } - - // /////////////////////////////////////////////////////////////////////// - private void invokeOnClient(String endpoint, Object entity) throws Exception { - setCountDownLatchCount(2); - invoke(endpoint, entity, ThrowingTextDecoder.ERR_MSG, - ThrowingTextDecoder.ERR_MSG); - } - - private void invokeIOOnClient(String endpoint, Object entity) throws Exception { - setCountDownLatchCount(2); - invoke(endpoint, entity, ThrowingTextDecoder.IO_ERR_MSG, - ThrowingTextDecoder.IO_ERR_MSG); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSClientIT.java new file mode 100644 index 0000000000..3ef7836ddf --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/throwingcoder/annotated/WSClientIT.java @@ -0,0 +1,625 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.throwingcoder.annotated; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.ExtensionImpl; +import com.sun.ts.tests.websocket.common.impl.ExtensionParameterImpl; +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.common.util.StringUtil; +import com.sun.ts.tests.websocket.ee.jakarta.websocket.throwingcoder.ThrowingTextDecoder; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = -8094860820359975543L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_sessionexception_web.war"); + archive.addPackages(true, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.throwingcoder"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class, StringUtil.class); + archive.addClasses(ExtensionImpl.class, ExtensionParameterImpl.class); + return archive; + } + + protected static final String ECHO = "Echo message"; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("ee_java_websocket_throwingcoder_annotated_web"); + logExceptionOnInvocation(false); + } + + /* Run test */ + /* + * @testName: binaryDecoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:38; + * + * @test_Strategy: test the binary decoder throws decoderException and it is + * caught in @OnError + */ + @Test + public void binaryDecoderThrowAndCatchOnServerTest() throws Exception { + invoke("binarydecoder", ByteBuffer.wrap(ECHO.getBytes()), ThrowingTextDecoder.ERR_MSG); + logMsg("The DecoderException has been propagated to @OnError"); + } + + /* + * @testName: binaryDecoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:38; + * + * @test_Strategy: test the binary decoder throws decoderException and it is + * caught in @OnError + */ + @Test + public void binaryDecoderThrowAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithBinaryDecoder endpoint = new WSCClientEndpointWithBinaryDecoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simplebin", ECHO); + logMsg("The DecoderException has been propagated to @OnError"); + } + + /* + * @testName: binaryStreamDecoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:41; + * + * @test_Strategy: test the binary stream decoder throws decoderException and it + * is caught in @OnError + */ + @Test + public void binaryStreamDecoderThrowAndCatchOnServerTest() throws Exception { + invoke("binarystreamdecoder", ByteBuffer.wrap(ECHO.getBytes()), ThrowingTextDecoder.ERR_MSG); + logMsg("The DecoderException has been propagated to @OnError"); + } + + /* + * @testName: binaryStreamDecoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:41; + * + * @test_Strategy: test the binary stream decoder throws decoderException and it + * is caught in @OnError + */ + @Test + public void binaryStreamDecoderThrowAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithBinaryStreamDecoder endpoint = new WSCClientEndpointWithBinaryStreamDecoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simplebin", ECHO); + logMsg("The DecoderException has been propagated to @OnError"); + } + + /* + * @testName: textDecoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:44; + * + * @test_Strategy: test the text decoder throws decoderException and it is + * caught in @OnError + */ + @Test + public void textDecoderThrowAndCatchOnServerTest() throws Exception { + invoke("textdecoder", ECHO, ThrowingTextDecoder.ERR_MSG); + logMsg("The DecoderException has been propagated to @OnError"); + } + + /* + * @testName: textDecoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:44; + * + * @test_Strategy: test the text decoder throws decoderException and it is + * caught in @OnError + */ + @Test + public void textDecoderThrowAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithTextDecoder endpoint = new WSCClientEndpointWithTextDecoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simpleecho", ECHO); + logMsg("The DecoderException has been propagated to @OnError"); + } + + /* + * @testName: textStreamDecoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:47; + * + * @test_Strategy: test the text stream decoder throws decoderException and it + * is caught in @OnError + */ + @Test + public void textStreamDecoderThrowAndCatchOnServerTest() throws Exception { + invoke("textstreamdecoder", ECHO, ThrowingTextDecoder.ERR_MSG); + logMsg("The DecoderException has been propagated to @OnError"); + } + + /* + * @testName: textStreamDecoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:47; + * + * @test_Strategy: test the text stream decoder throws decoderException and it + * is caught in @OnError + */ + @Test + public void textStreamDecoderThrowAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithTextStreamDecoder endpoint = new WSCClientEndpointWithTextStreamDecoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simpleecho", ECHO); + logMsg("The DecoderException has been propagated to @OnError"); + } + + // --------------------------------------------------------------------- + + /* + * @testName: binaryEncoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:57; + * + * @test_Strategy: test the binary encoder throws EncoderException and it is + * caught in @OnError + */ + @Test + public void binaryEncoderThrowAndCatchOnServerTest() throws Exception { + invoke("binaryencoder", ECHO, ThrowingTextDecoder.ERR_MSG); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: binaryEncoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:57; + * + * @test_Strategy: test the binary encoder throws EncoderException and it is + * caught in @OnError + */ + @Test + public void binaryEncoderThrowAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithBinaryEncoder endpoint = new WSCClientEndpointWithBinaryEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simpleecho", new StringBean(ECHO)); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: binaryStreamEncoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:59; + * + * @test_Strategy: test the binary stream encoder throws EncoderException and it + * is caught in @OnError + */ + @Test + public void binaryStreamEncoderThrowAndCatchOnServerTest() throws Exception { + invoke("binarystreamencoder", ECHO, ThrowingTextDecoder.ERR_MSG); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: binaryStreamEncoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:59; + * + * @test_Strategy: test the binary stream encoder throws EncoderException and it + * is caught in @OnError + */ + @Test + public void binaryStreamEncoderThrowAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithBinaryStreamEncoder endpoint = new WSCClientEndpointWithBinaryStreamEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simpleecho", new StringBean(ECHO)); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: textEncoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:62; + * + * @test_Strategy: test the text encoder throws EncoderException and it is + * caught in @OnError + */ + @Test + public void textEncoderThrowAndCatchOnServerTest() throws Exception { + invoke("textencoder", ECHO, ThrowingTextDecoder.ERR_MSG); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: textEncoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:62; + * + * @test_Strategy: test the text encoder throws EncoderException and it is + * caught in @OnError + */ + @Test + public void textEncoderThrowAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithTextEncoder endpoint = new WSCClientEndpointWithTextEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simpleecho", new StringBean(ECHO)); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: textStreamEncoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:64; + * + * @test_Strategy: test the text stream encoder throws EncoderException and it + * is caught in @OnError + */ + @Test + public void textStreamEncoderThrowAndCatchOnServerTest() throws Exception { + invoke("textstreamencoder", ECHO, ThrowingTextDecoder.ERR_MSG); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: textStreamEncoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:64; + * + * @test_Strategy: test the text stream encoder throws EncoderException and it + * is caught in @OnError + */ + @Test + public void textStreamEncoderThrowAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithTextStreamEncoder endpoint = new WSCClientEndpointWithTextStreamEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simpleecho", new StringBean(ECHO)); + logMsg("The EncoderException has been propagated to @OnError"); + } + + // ----------------------------------------------------------------------- + // returning encoders + + /* + * @testName: returningBinaryEncoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:57; + * + * @test_Strategy: test the binary encoder throws EncoderException and it is + * caught in @OnError + */ + @Test + public void returningBinaryEncoderThrowAndCatchOnServerTest() throws Exception { + invoke("returningbinaryencoder", ECHO, ThrowingTextDecoder.ERR_MSG); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: returningBinaryEncoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:57; + * + * @test_Strategy: test the binary encoder throws EncoderException and it is + * caught in @OnError + */ + @Test + public void returningBinaryEncoderThrowAndCatchOnClientTest() throws Exception { + WSCReturningClientEndpointWithBinaryEncoder endpoint = new WSCReturningClientEndpointWithBinaryEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simpleecho", ECHO); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: returningBinaryStreamEncoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:59; + * + * @test_Strategy: test the binary stream encoder throws EncoderException and it + * is caught in @OnError + */ + @Test + public void returningBinaryStreamEncoderThrowAndCatchOnServerTest() throws Exception { + invoke("returningbinarystreamencoder", ECHO, ThrowingTextDecoder.ERR_MSG); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: returningBinaryStreamEncoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:59; + * + * @test_Strategy: test the binary stream encoder throws EncoderException and it + * is caught in @OnError + */ + @Test + public void returningBinaryStreamEncoderThrowAndCatchOnClientTest() throws Exception { + WSCReturningClientEndpointWithBinaryStreamEncoder endpoint = new WSCReturningClientEndpointWithBinaryStreamEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simpleecho", ECHO); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: returningTextEncoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:62; + * + * @test_Strategy: test the text encoder throws EncoderException and it is + * caught in @OnError + */ + @Test + public void returningTextEncoderThrowAndCatchOnServerTest() throws Exception { + invoke("returningtextencoder", ECHO, ThrowingTextDecoder.ERR_MSG); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: returningTextEncoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:62; + * + * @test_Strategy: test the text encoder throws EncoderException and it is + * caught in @OnError + */ + @Test + public void returningTextEncoderThrowAndCatchOnClientTest() throws Exception { + WSCReturningClientEndpointWithTextEncoder endpoint = new WSCReturningClientEndpointWithTextEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simpleecho", ECHO); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: returningTextStreamEncoderThrowAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:64; + * + * @test_Strategy: test the text stream encoder throws EncoderException and it + * is caught in @OnError + */ + @Test + public void returningTextStreamEncoderThrowAndCatchOnServerTest() throws Exception { + invoke("returningtextstreamencoder", ECHO, ThrowingTextDecoder.ERR_MSG); + logMsg("The EncoderException has been propagated to @OnError"); + } + + /* + * @testName: returningTextStreamEncoderThrowAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:64; + * + * @test_Strategy: test the text stream encoder throws EncoderException and it + * is caught in @OnError + */ + @Test + public void returningTextStreamEncoderThrowAndCatchOnClientTest() throws Exception { + WSCReturningClientEndpointWithTextStreamEncoder endpoint = new WSCReturningClientEndpointWithTextStreamEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeOnClient("simpleecho", ECHO); + logMsg("The EncoderException has been propagated to @OnError"); + } + + // ------------------------------------------------------------------------ + // IO Exceptions + + /* + * @testName: binaryStreamDecoderThrowIOAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:42; + * + * @test_Strategy: test the binary stream decoder throws IOException and it is + * caught in @OnError + */ + @Test + public void binaryStreamDecoderThrowIOAndCatchOnServerTest() throws Exception { + invoke("iobinarystreamdecoder", ByteBuffer.wrap(ECHO.getBytes()), ThrowingTextDecoder.IO_ERR_MSG); + logMsg("The IOException has been propagated to @OnError"); + } + + /* + * @testName: binaryStreamDecoderThrowIOAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:42; + * + * @test_Strategy: test the binary stream decoder throws IOException and it is + * caught in @OnError + */ + @Test + public void binaryStreamDecoderThrowIOAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithIOBinaryStreamDecoder endpoint = new WSCClientEndpointWithIOBinaryStreamDecoder(); + setAnnotatedClientEndpoint(endpoint); + invokeIOOnClient("simplebin", ECHO); + logMsg("The IOException has been propagated to @OnError"); + } + + /* + * @testName: textStreamDecoderThrowIOAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:48; + * + * @test_Strategy: test the text stream decoder throws IOException and it is + * caught in @OnError + */ + @Test + public void textStreamDecoderThrowIOAndCatchOnServerTest() throws Exception { + invoke("iotextstreamdecoder", ECHO, ThrowingTextDecoder.IO_ERR_MSG); + logMsg("The IOException has been propagated to @OnError"); + } + + /* + * @testName: textStreamDecoderThrowIOAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:48; + * + * @test_Strategy: test the text stream decoder throws IOException and it is + * caught in @OnError + */ + @Test + public void textStreamDecoderThrowIOAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithIOTextStreamDecoder endpoint = new WSCClientEndpointWithIOTextStreamDecoder(); + setAnnotatedClientEndpoint(endpoint); + invokeIOOnClient("simpleecho", ECHO); + logMsg("The IOException has been propagated to @OnError"); + } + + /* + * @testName: binaryStreamEncoderThrowIOAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:60; + * + * @test_Strategy: test the binary stream encoder throws IOException and it is + * caught in @OnError + */ + @Test + public void binaryStreamEncoderThrowIOAndCatchOnServerTest() throws Exception { + invoke("iobinarystreamencoder", ECHO, ThrowingTextDecoder.IO_ERR_MSG); + logMsg("The IOException has been propagated to @OnError"); + } + + /* + * @testName: binaryStreamEncoderThrowIOAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:60; + * + * @test_Strategy: test the binary stream encoder throws IOException and it is + * caught in @OnError + */ + @Test + public void binaryStreamEncoderThrowIOAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithIOBinaryStreamEncoder endpoint = new WSCClientEndpointWithIOBinaryStreamEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeIOOnClient("simpleecho", new StringBean(ECHO)); + logMsg("The IOException has been propagated to @OnError"); + } + + /* + * @testName: textStreamEncoderThrowIOAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:65; + * + * @test_Strategy: test the text stream encoder throws IOException and it is + * caught in @OnError + */ + @Test + public void textStreamEncoderThrowIOAndCatchOnServerTest() throws Exception { + invoke("iotextstreamencoder", ECHO, ThrowingTextDecoder.IO_ERR_MSG); + logMsg("The IOException has been propagated to @OnError"); + } + + /* + * @testName: textStreamEncoderThrowIOAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:65; + * + * @test_Strategy: test the text stream encoder throws IOException and it is + * caught in @OnError + */ + @Test + public void textStreamEncoderThrowIOAndCatchOnClientTest() throws Exception { + WSCClientEndpointWithIOTextStreamEncoder endpoint = new WSCClientEndpointWithIOTextStreamEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeIOOnClient("simpleecho", new StringBean(ECHO)); + logMsg("The IOException has been propagated to @OnError"); + } + + /* + * @testName: returningBinaryStreamEncoderThrowIOAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:60; + * + * @test_Strategy: test the binary stream encoder throws IOException and it is + * caught in @OnError + */ + @Test + public void returningBinaryStreamEncoderThrowIOAndCatchOnServerTest() throws Exception { + invoke("ioreturningbinarystreamencoder", ECHO, ThrowingTextDecoder.IO_ERR_MSG); + logMsg("The IOException has been propagated to @OnError"); + } + + /* + * @testName: returningBinaryStreamEncoderThrowIOAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:60; + * + * @test_Strategy: test the binary stream encoder throws IOException and it is + * caught in @OnError + */ + @Test + public void returningBinaryStreamEncoderThrowIOAndCatchOnClientTest() throws Exception { + WSCReturningClientEndpointWithIOBinaryStreamEncoder endpoint = new WSCReturningClientEndpointWithIOBinaryStreamEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeIOOnClient("simpleecho", ECHO); + logMsg("The IOException has been propagated to @OnError"); + } + + /* + * @testName: returningTextStreamEncoderThrowIOAndCatchOnServerTest + * + * @assertion_ids: WebSocket:JAVADOC:65; + * + * @test_Strategy: test the text stream encoder throws IOException and it is + * caught in @OnError + */ + @Test + public void returningTextStreamEncoderThrowIOAndCatchOnServerTest() throws Exception { + invoke("ioreturningtextstreamencoder", ECHO, ThrowingTextDecoder.IO_ERR_MSG); + logMsg("The IOException has been propagated to @OnError"); + } + + /* + * @testName: returningTextStreamEncoderThrowIOAndCatchOnClientTest + * + * @assertion_ids: WebSocket:JAVADOC:65; + * + * @test_Strategy: test the text stream encoder throws IOException and it is + * caught in @OnError + */ + @Test + public void returningTextStreamEncoderThrowIOAndCatchOnClientTest() throws Exception { + WSCReturningClientEndpointWithIOTextStreamEncoder endpoint = new WSCReturningClientEndpointWithIOTextStreamEncoder(); + setAnnotatedClientEndpoint(endpoint); + invokeIOOnClient("simpleecho", ECHO); + logMsg("The IOException has been propagated to @OnError"); + } + + // /////////////////////////////////////////////////////////////////////// + private void invokeOnClient(String endpoint, Object entity) throws Exception { + setCountDownLatchCount(2); + invoke(endpoint, entity, ThrowingTextDecoder.ERR_MSG, ThrowingTextDecoder.ERR_MSG); + } + + private void invokeIOOnClient(String endpoint, Object entity) throws Exception { + setCountDownLatchCount(2); + invoke(endpoint, entity, ThrowingTextDecoder.IO_ERR_MSG, ThrowingTextDecoder.IO_ERR_MSG); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/WSClient.java deleted file mode 100644 index ceddb640bf..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/WSClient.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 - */ - -/* - * $Id$ - */ -package com.sun.ts.tests.websocket.ee.jakarta.websocket.websocketcontainer; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ws_wait; - * ts_home; - */ -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 5168766356852793713L; - - private static final String CONTEXT_ROOT = "ws_websocketcontainer_web"; - - private static final String SENT_STRING_MESSAGE = "Hello World"; - - public static void main(String[] args) { - new WSClient().run(args); - } - - public WSClient() { - setContextRoot(CONTEXT_ROOT); - } - - /* Run test */ - /* - * @testName: simpleTest - * - * @assertion_ids: - * - * @test_Strategy: - */ - public void simpleTest() throws Exception { - String expected = "TCKTestServer opened|" + "TCKTestServer received: " - + SENT_STRING_MESSAGE + "|TCKTestServer responds"; - setCountDownLatchCount(3); - setProperty(Property.REQUEST, buildRequest("TCKTestServer")); - setProperty(Property.SEARCH_STRING, expected); - setProperty(Property.CONTENT, SENT_STRING_MESSAGE); - invoke(); - - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/WSClientIT.java new file mode 100644 index 0000000000..984787137b --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/WSClientIT.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2013, 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 + */ + +/* + * $Id$ + */ +package com.sun.ts.tests.websocket.ee.jakarta.websocket.websocketcontainer; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 5168766356852793713L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_websocketcontainer_web.war"); + archive.addPackages(true, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.websocketcontainer"); + archive.addAsWebInfResource(WSClientIT.class.getPackage(), "web.xml", "web.xml"); + return archive; + } + + private static final String CONTEXT_ROOT = "ws_websocketcontainer_web"; + + private static final String SENT_STRING_MESSAGE = "Hello World"; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot(CONTEXT_ROOT); + } + + /* Run test */ + /* + * @testName: simpleTest + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void simpleTest() throws Exception { + String expected = "TCKTestServer opened|" + "TCKTestServer received: " + SENT_STRING_MESSAGE + + "|TCKTestServer responds"; + setCountDownLatchCount(3); + setProperty(Property.REQUEST, buildRequest("TCKTestServer")); + setProperty(Property.SEARCH_STRING, expected); + setProperty(Property.CONTENT, SENT_STRING_MESSAGE); + invoke(); + + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/WSTestServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/WSTestServer.java index 8731ec8fbb..38b1a18798 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/WSTestServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/WSTestServer.java @@ -31,23 +31,22 @@ @ServerEndpoint(value = "/TCKTestServer") public class WSTestServer { - @OnOpen - public void init(Session session) throws IOException { - System.out.println("==============================="); - session.getBasicRemote().sendText("TCKTestServer opened"); - } + @OnOpen + public void init(Session session) throws IOException { + System.out.println("==============================="); + session.getBasicRemote().sendText("TCKTestServer opened"); + } - @OnMessage - public void respond(String message, Session session) throws IOException { - System.out.println( - "TCKTestServer got message: " + message + " from session " + session); - session.getBasicRemote().sendText("TCKTestServer received: " + message); - session.getBasicRemote().sendText("TCKTestServer responds"); - } + @OnMessage + public void respond(String message, Session session) throws IOException { + System.out.println("TCKTestServer got message: " + message + " from session " + session); + session.getBasicRemote().sendText("TCKTestServer received: " + message); + session.getBasicRemote().sendText("TCKTestServer responds"); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - session.getBasicRemote().sendText("TCKTestServer onError"); - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + session.getBasicRemote().sendText("TCKTestServer onError"); + t.printStackTrace(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndPathParamServer.java index 1b0aac6aaa..58b23bf3b7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndPathParamServer.java @@ -29,21 +29,20 @@ import jakarta.websocket.server.PathParam; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarydecoderpathparam/{param}", decoders = { - StringBeanBinaryDecoder.class }) +@ServerEndpoint(value = "/binarydecoderpathparam/{param}", decoders = { StringBeanBinaryDecoder.class }) public class WSBinaryDecoderAndPathParamServer { - @OnMessage - public String echo(@PathParam("param") String param, StringBean bean) { - return bean.get() + param; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("param") String param, StringBean bean) { + return bean.get() + param; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndSessionAndPathParamServer.java index f393405c3b..c0f2a85bae 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndSessionAndPathParamServer.java @@ -29,23 +29,21 @@ import jakarta.websocket.server.PathParam; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarydecodersessionpathparam/{param}", decoders = { - StringBeanBinaryDecoder.class }) +@ServerEndpoint(value = "/binarydecodersessionpathparam/{param}", decoders = { StringBeanBinaryDecoder.class }) public class WSBinaryDecoderAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(StringBean bean, Session session, - @PathParam("param") String param) { - return bean.get() + param; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(StringBean bean, Session session, @PathParam("param") String param) { + return bean.get() + param; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndSessionServer.java index 1ecca27907..8b07fa9a0c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderAndSessionServer.java @@ -28,21 +28,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarydecodersession", decoders = { - StringBeanBinaryDecoder.class }) +@ServerEndpoint(value = "/binarydecodersession", decoders = { StringBeanBinaryDecoder.class }) public class WSBinaryDecoderAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(StringBean bean, Session session) { - return bean.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(StringBean bean, Session session) { + return bean.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderServer.java index 24c9e1e56b..d3b7d2da48 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryDecoderServer.java @@ -28,21 +28,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarydecoder", decoders = { - StringBeanBinaryDecoder.class }) +@ServerEndpoint(value = "/binarydecoder", decoders = { StringBeanBinaryDecoder.class }) public class WSBinaryDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndPathParamServer.java index 7a570d5506..df75a43f7e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndPathParamServer.java @@ -29,20 +29,19 @@ import jakarta.websocket.server.PathParam; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarystreamdecoderpathparam/{param}", decoders = { - StringBeanBinaryStreamDecoder.class }) +@ServerEndpoint(value = "/binarystreamdecoderpathparam/{param}", decoders = { StringBeanBinaryStreamDecoder.class }) public class WSBinaryStreamDecoderAndPathParamServer { - @OnMessage - public String echo(StringBean bean, @PathParam("param") String param) { - return bean.get() + param; - } + @OnMessage + public String echo(StringBean bean, @PathParam("param") String param) { + return bean.get() + param; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndSessionAndPathParamServer.java index f1dcfbb8aa..3486c51424 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndSessionAndPathParamServer.java @@ -30,21 +30,20 @@ import jakarta.websocket.server.ServerEndpoint; @ServerEndpoint(value = "/binarystreamdecodersessionpathparam/{param}", decoders = { - StringBeanBinaryStreamDecoder.class }) + StringBeanBinaryStreamDecoder.class }) public class WSBinaryStreamDecoderAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(StringBean bean, @PathParam("param") String param, - Session s) { - return bean.get() + param; - } + @SuppressWarnings("unused") + @OnMessage + public String echo(StringBean bean, @PathParam("param") String param, Session s) { + return bean.get() + param; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndSessionServer.java index a0f40148dd..1867b434d2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderAndSessionServer.java @@ -28,21 +28,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarystreamdecodersession", decoders = { - StringBeanBinaryStreamDecoder.class }) +@ServerEndpoint(value = "/binarystreamdecodersession", decoders = { StringBeanBinaryStreamDecoder.class }) public class WSBinaryStreamDecoderAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(StringBean bean, Session s) { - return bean.get(); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(StringBean bean, Session s) { + return bean.get(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderServer.java index 1958c898e0..e06e4fc2c1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSBinaryStreamDecoderServer.java @@ -28,20 +28,19 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarystreamdecoder", decoders = { - StringBeanBinaryStreamDecoder.class }) +@ServerEndpoint(value = "/binarystreamdecoder", decoders = { StringBeanBinaryStreamDecoder.class }) public class WSBinaryStreamDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndPathParamServer.java index e6f99218d4..e91d372c53 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndPathParamServer.java @@ -30,16 +30,16 @@ @ServerEndpoint(value = "/bytearraypathparam/{param}") public class WSByteArrayAndPathParamServer { - @OnMessage - public String bytesToString(@PathParam("param") String param, byte[] array) { - return new String(array) + param; - } + @OnMessage + public String bytesToString(@PathParam("param") String param, byte[] array) { + return new String(array) + param; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndSessionAndPathParamServer.java index bdc17f91e9..89d136d30d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndSessionAndPathParamServer.java @@ -30,18 +30,17 @@ @ServerEndpoint(value = "/bytearraysessionpathparam/{param}") public class WSByteArrayAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String bytesToString(@PathParam("param") String param, byte[] array, - Session s) { - return new String(array) + param; - } + @SuppressWarnings("unused") + @OnMessage + public String bytesToString(@PathParam("param") String param, byte[] array, Session s) { + return new String(array) + param; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndSessionServer.java index ea752a7719..1d86ff13e3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayAndSessionServer.java @@ -29,17 +29,17 @@ @ServerEndpoint(value = "/bytearraysession") public class WSByteArrayAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String bytesToString(byte[] array, Session s) { - return new String(array); - } + @SuppressWarnings("unused") + @OnMessage + public String bytesToString(byte[] array, Session s) { + return new String(array); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndPathParamServer.java index 1e8d6dc013..53e885fb53 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndPathParamServer.java @@ -30,18 +30,17 @@ @ServerEndpoint(value = "/partialbytearraypathparam/{param}") public class WSByteArrayPartialAndPathParamServer { - @OnMessage - public String bytesToString(@PathParam("param") String param, byte[] array, - boolean finito) { - return new StringBuilder().append(new String(array)).append("(") - .append(finito).append(")[").append(param).append("]").toString(); - } + @OnMessage + public String bytesToString(@PathParam("param") String param, byte[] array, boolean finito) { + return new StringBuilder().append(new String(array)).append("(").append(finito).append(")[").append(param) + .append("]").toString(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndSessionAndPathParamServer.java index 773ae638f5..defa5f68f7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndSessionAndPathParamServer.java @@ -30,24 +30,24 @@ @ServerEndpoint(value = "/partialbytearraysessionpathparam/{param}") public class WSByteArrayPartialAndSessionAndPathParamServer { - StringBuffer sb = new StringBuffer(); - - @OnMessage - public void bytesToString(@PathParam("param") String param, byte[] array, - Session s, boolean finito) throws IOException { - sb.append(new String(array)).append("(").append(finito).append(")"); - sb.append('[').append(param).append("]"); - if (finito) { - s.getBasicRemote().sendText(sb.toString()); - sb = new StringBuffer(); - } - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + StringBuffer sb = new StringBuffer(); + + @OnMessage + public void bytesToString(@PathParam("param") String param, byte[] array, Session s, boolean finito) + throws IOException { + sb.append(new String(array)).append("(").append(finito).append(")"); + sb.append('[').append(param).append("]"); + if (finito) { + s.getBasicRemote().sendText(sb.toString()); + sb = new StringBuffer(); + } + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndSessionServer.java index 2e79b91d86..8fc4760188 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialAndSessionServer.java @@ -29,23 +29,22 @@ @ServerEndpoint(value = "/partialbytearraysession") public class WSByteArrayPartialAndSessionServer { - StringBuffer sb = new StringBuffer(); - - @OnMessage - public void bytesToString(byte[] array, Session s, boolean finito) - throws IOException { - sb.append(new String(array)).append("(").append(finito).append(")"); - if (finito) { - s.getBasicRemote().sendText(sb.toString()); - sb = new StringBuffer(); - } - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + StringBuffer sb = new StringBuffer(); + + @OnMessage + public void bytesToString(byte[] array, Session s, boolean finito) throws IOException { + sb.append(new String(array)).append("(").append(finito).append(")"); + if (finito) { + s.getBasicRemote().sendText(sb.toString()); + sb = new StringBuffer(); + } + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialServer.java index 66c9c476af..f6fc8739b7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayPartialServer.java @@ -29,17 +29,16 @@ @ServerEndpoint(value = "/partialbytearray") public class WSByteArrayPartialServer { - @OnMessage - public String bytesToString(byte[] array, boolean finito) { - return new StringBuilder().append(new String(array)).append("(") - .append(finito).append(")").toString(); - } + @OnMessage + public String bytesToString(byte[] array, boolean finito) { + return new StringBuilder().append(new String(array)).append("(").append(finito).append(")").toString(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayServer.java index f1484473b9..4c107bcfa0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteArrayServer.java @@ -29,16 +29,16 @@ @ServerEndpoint(value = "/bytearray") public class WSByteArrayServer { - @OnMessage - public String bytesToString(byte[] array) { - return new String(array); - } + @OnMessage + public String bytesToString(byte[] array) { + return new String(array); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndPathParamServer.java index 2c89169b8e..3513d06bc3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndPathParamServer.java @@ -30,16 +30,16 @@ @ServerEndpoint("/bytebufferpathparam/{param}") public class WSByteBufferAndPathParamServer { - @OnMessage - public String echo(@PathParam("param") String param, ByteBuffer b) { - return IOUtil.byteBufferToString(b) + param; - } + @OnMessage + public String echo(@PathParam("param") String param, ByteBuffer b) { + return IOUtil.byteBufferToString(b) + param; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndSessionAndPathParamServer.java index e87fdaa8af..c100cb2a22 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndSessionAndPathParamServer.java @@ -30,19 +30,18 @@ @ServerEndpoint("/bytebuffersessionpathparam/{param}") public class WSByteBufferAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(ByteBuffer b, @PathParam("param") String param, - Session s) { - return IOUtil.byteBufferToString(b) + param; - } + @SuppressWarnings("unused") + @OnMessage + public String echo(ByteBuffer b, @PathParam("param") String param, Session s) { + return IOUtil.byteBufferToString(b) + param; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndSessionServer.java index 1a7150e3b0..7fb6371654 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferAndSessionServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/bytebuffersession") public class WSByteBufferAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(ByteBuffer b, Session s) { - return IOUtil.byteBufferToString(b); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(ByteBuffer b, Session s) { + return IOUtil.byteBufferToString(b); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndPathParamServer.java index c6a77a09dd..433fa02618 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndPathParamServer.java @@ -30,19 +30,17 @@ @ServerEndpoint("/partialbytebufferpathparam/{param}") public class WSByteBufferPartialAndPathParamServer { - @OnMessage - public String echo(ByteBuffer buf, boolean finito, - @PathParam("param") String param) { - return new StringBuilder().append(IOUtil.byteBufferToString(buf)) - .append("(").append(finito).append(")[").append(param).append("]") - .toString(); - } + @OnMessage + public String echo(ByteBuffer buf, boolean finito, @PathParam("param") String param) { + return new StringBuilder().append(IOUtil.byteBufferToString(buf)).append("(").append(finito).append(")[") + .append(param).append("]").toString(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndSessionAndPathParamServer.java index e28d8072ce..6065c5365b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndSessionAndPathParamServer.java @@ -30,25 +30,24 @@ @ServerEndpoint("/partialbytebuffersessionpathparam/{param}") public class WSByteBufferPartialAndSessionAndPathParamServer { - StringBuilder sb = new StringBuilder(); - - @OnMessage - public void echo(ByteBuffer buf, Session s, boolean finito, - @PathParam("param") String param) throws IOException { - sb.append(IOUtil.byteBufferToString(buf)).append("(").append(finito); - sb.append(")").append('[').append(param).append(']'); - if (finito) { - s.getBasicRemote().sendText(sb.toString()); - sb = new StringBuilder(); - } - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in" + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + StringBuilder sb = new StringBuilder(); + + @OnMessage + public void echo(ByteBuffer buf, Session s, boolean finito, @PathParam("param") String param) throws IOException { + sb.append(IOUtil.byteBufferToString(buf)).append("(").append(finito); + sb.append(")").append('[').append(param).append(']'); + if (finito) { + s.getBasicRemote().sendText(sb.toString()); + sb = new StringBuilder(); + } + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in" + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndSessionServer.java index 624ac42e5d..7bd801b6a2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialAndSessionServer.java @@ -29,24 +29,22 @@ @ServerEndpoint("/partialbytebuffersession") public class WSByteBufferPartialAndSessionServer { - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); - @OnMessage - public void echo(ByteBuffer buf, Session s, boolean finito) - throws IOException { - sb.append(IOUtil.byteBufferToString(buf)).append("(").append(finito) - .append(")"); - if (finito) { - s.getBasicRemote().sendText(sb.toString()); - sb = new StringBuilder(); - } - } + @OnMessage + public void echo(ByteBuffer buf, Session s, boolean finito) throws IOException { + sb.append(IOUtil.byteBufferToString(buf)).append("(").append(finito).append(")"); + if (finito) { + s.getBasicRemote().sendText(sb.toString()); + sb = new StringBuilder(); + } + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialServer.java index 6aef827ce6..ae78394d55 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferPartialServer.java @@ -29,17 +29,16 @@ @ServerEndpoint("/partialbytebuffer") public class WSByteBufferPartialServer { - @OnMessage - public String echo(ByteBuffer buf, boolean bol) { - return new StringBuilder(IOUtil.byteBufferToString(buf)).append("(") - .append(bol).append(")").toString(); - } + @OnMessage + public String echo(ByteBuffer buf, boolean bol) { + return new StringBuilder(IOUtil.byteBufferToString(buf)).append("(").append(bol).append(")").toString(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferServer.java index 7f9c6a7a68..63bdd82256 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSByteBufferServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/bytebuffer") public class WSByteBufferServer { - @OnMessage - public String echo(ByteBuffer b) { - return IOUtil.byteBufferToString(b); - } + @OnMessage + public String echo(ByteBuffer b) { + return IOUtil.byteBufferToString(b); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSClient.java deleted file mode 100644 index 3afc37af2e..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSClient.java +++ /dev/null @@ -1,926 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.websocketmessage; - -import java.nio.ByteBuffer; -import java.util.concurrent.atomic.AtomicInteger; - -import com.sun.ts.tests.websocket.common.client.EndpointCallback; -import com.sun.ts.tests.websocket.common.client.SendMessageCallback; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.StringPongMessage; - -import jakarta.websocket.CloseReason; -import jakarta.websocket.Session; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 932557106496525508L; - - static final String ECHO = "Echo message to be sent to server endpoint"; - - static final String[] TEXT_PRIMITIVE_SEQUENCE = { "byte", "short", "int", - "long", "double", "float" }; - - static final String[] TEXT_TYPE_SEQUENCE = { "string", "reader", - "textdecoder", "textstreamdecoder" }; - - static final String[] BINARY_SEQUENCE = { "bytearray", "bytebuffer", - "inputstream", "binarydecoder", "binarystreamdecoder" }; - - public static int getIndex(String item) { - for (int i = 0; i != TEXT_PRIMITIVE_SEQUENCE.length; i++) - if (TEXT_PRIMITIVE_SEQUENCE[i].equals(item)) - return i; - return -1; - } - - public WSClient() { - setContextRoot("ws_ee_websocketmessage_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - // TEXT ------------------------------------------ - - /* - * @testName: echoStringTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Echo String - */ - public void echoStringTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("string")); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - invoke(); - } - - /* - * @testName: echoIntTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo int - */ - public void echoIntTest() throws Exception { - int entity = Integer.MIN_VALUE; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("primitiveint")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoByteTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo byte - */ - public void echoByteTest() throws Exception { - byte entity = 123; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("primitivebyte")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoCharTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo char - */ - public void echoCharTest() throws Exception { - char entity = 'E'; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("primitivechar")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity) + "char"); - invoke(); - } - - /* - * @testName: echoBooleanTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo boolean - */ - public void echoBooleanTest() throws Exception { - boolean entity = true; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("primitiveboolean")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoShortTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo short - */ - public void echoShortTest() throws Exception { - short entity = -32100; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("primitiveshort")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoDoubleTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo double - */ - public void echoDoubleTest() throws Exception { - double entity = -12345678.88; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("primitivedouble")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoFloatTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo float - */ - public void echoFloatTest() throws Exception { - float entity = -12345678.88f; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("primitivefloat")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoLongTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo long - */ - public void echoLongTest() throws Exception { - long entity = Long.MIN_VALUE; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("primitivelong")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoFullIntTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo int - */ - public void echoFullIntTest() throws Exception { - Integer entity = Integer.MIN_VALUE; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("fullint")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoFullByteTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo byte - */ - public void echoFullByteTest() throws Exception { - Byte entity = Byte.MIN_VALUE; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("fullbyte")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoFullCharTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo char - */ - public void echoFullCharTest() throws Exception { - Character entity = 'E'; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("fullchar")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoFullBooleanTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo boolean - */ - public void echoFullBooleanTest() throws Exception { - Boolean entity = true; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("fullboolean")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoFullShortTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo short - */ - public void echoFullShortTest() throws Exception { - Short entity = Short.MAX_VALUE; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("fullshort")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoFullDoubleTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo double - */ - public void echoFullDoubleTest() throws Exception { - Double entity = Double.MIN_VALUE; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("fulldouble")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoFullFloatTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo float - */ - public void echoFullFloatTest() throws Exception { - Float entity = Float.MAX_VALUE; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("fullfloat")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - /* - * @testName: echoFullLongTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; - * - * @test_Strategy: echo long - */ - public void echoFullLongTest() throws Exception { - Long entity = Long.MAX_VALUE; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("fulllong")); - setProperty(Property.SEARCH_STRING, String.valueOf(entity)); - invoke(); - } - - // ------------------------------------------------------------------ - - /* - * @testName: byteToTextsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send byte receive other texts - */ - public void byteToTextsTest() throws Exception { - byte entity = 123; - setEntity(entity); - int index = getIndex("byte"); - invokeTextSequences(index + 1, String.valueOf(entity)); - invokeTextSequencesWithPathParam(index, String.valueOf(entity), "101"); - } - - /* - * @testName: shortToTextsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send short receive other - */ - public void shortToTextsTest() throws Exception { - short entity = Short.MAX_VALUE; - setEntity(entity); - int index = getIndex("short"); - invokeTextSequences(index + 1, String.valueOf(entity)); - invokeTextSequencesWithPathParam(index, String.valueOf(entity), "1001"); - } - - /* - * @testName: intToTextsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send int receive other - */ - public void intToTextsTest() throws Exception { - int entity = Short.MAX_VALUE; // Integer.MAX_VALUE is - // 2.147483647E9 at Double - setEntity(entity); - int index = getIndex("int"); - invokeTextSequences(index + 1, String.valueOf(entity)); - invokeTextSequencesWithPathParam(index, String.valueOf(entity), "100001"); - } - - /* - * @testName: longToTextsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send long receive other - */ - public void longToTextsTest() throws Exception { - long entity = Short.MIN_VALUE; // Long.MIN_VALUE is - // -9.223372036854776E18 at Double - setEntity(entity); - int index = getIndex("long"); - invokeTextSequences(index + 1, String.valueOf(entity)); - invokeTextSequencesWithPathParam(index, String.valueOf(entity), "100001"); - } - - /* - * @testName: floatToTextsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send float receive other - */ - public void floatToTextsTest() throws Exception { - float entity = Float.MIN_VALUE; - setEntity(entity); - int index = getIndex("float"); - invokeTextSequences(index + 1, String.valueOf(entity)); - invokeTextSequencesWithPathParam(index, String.valueOf(entity), - String.valueOf(101.101f)); - } - - /* - * @testName: doubleToTextsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send double receive other - */ - public void doubleToTextsTest() throws Exception { - double entity = Double.MAX_VALUE; - setEntity(entity); - invokeSequence(0, String.valueOf(entity), "", "", TEXT_TYPE_SEQUENCE); - invokeSequence(0, String.valueOf(entity), "", "session", - TEXT_TYPE_SEQUENCE); - String pathParam = String.valueOf(101.101); - invokeSequence(0, String.valueOf(entity) + pathParam, "", - "pathparam/" + pathParam, TEXT_TYPE_SEQUENCE); - invokeSequence(0, String.valueOf(entity) + pathParam, "", - "sessionpathparam/" + pathParam, TEXT_TYPE_SEQUENCE); - } - - /* - * @testName: stringToTextsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send string receive other - */ - public void stringToTextsTest() throws Exception { - String param = "StringParam"; - setEntity(ECHO); - invokeSequence(0, ECHO, "", "", TEXT_TYPE_SEQUENCE); - invokeSequence(0, ECHO, "", "session", TEXT_TYPE_SEQUENCE); - invokeSequence(0, ECHO + param, "", "pathparam/" + param, - TEXT_TYPE_SEQUENCE); - invokeSequence(0, ECHO + param, "", "sessionpathparam/" + param, - TEXT_TYPE_SEQUENCE); - } - - /* - * @testName: stringToAllNumbersTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send string receive other - */ - public void stringToAllNumbersTest() throws Exception { - String entity = String.valueOf(Byte.MAX_VALUE); - String param = "111"; - setEntity(entity); - invokeSequence(0, String.valueOf(entity), "primitive", "", - TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(0, String.valueOf(entity), "full", "", - TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(0, String.valueOf(entity), "primitive", "session", - TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(0, String.valueOf(entity), "full", "session", - TEXT_PRIMITIVE_SEQUENCE); - - invokeSequence(0, String.valueOf(entity) + param, "primitive", - "pathparam/" + param, TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(0, String.valueOf(entity) + param, "full", - "pathparam/" + param, TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(0, String.valueOf(entity) + param, "primitive", - "sessionpathparam/" + param, TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(0, String.valueOf(entity) + param, "full", - "sessionpathparam/" + param, TEXT_PRIMITIVE_SEQUENCE); - } - - /* - * @testName: booleanToBooleanWithPathParamTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send boolean receive boolean - */ - public void booleanToBooleanWithPathParamTest() throws Exception { - boolean entity = true; - String[] SEQUENCE = { "primitiveboolean", "fullboolean" }; - setEntity(entity); - invokeSequence(0, "true", "", "", SEQUENCE); - invokeSequence(0, "true", "", "session", SEQUENCE); - invokeSequence(0, "truefalse", "", "pathparam/false", SEQUENCE); - invokeSequence(0, "truefalse", "", "sessionpathparam/false", SEQUENCE); - } - - /* - * @testName: stringToBooleanTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send string receive boolean - */ - public void stringToBooleanTest() throws Exception { - String entity = "true"; - String[] SEQUENCE = { "primitiveboolean", "fullboolean" }; - setEntity(entity); - invokeSequence(0, entity, "", "", SEQUENCE); - invokeSequence(0, entity, "", "session", SEQUENCE); - invokeSequence(0, "truefalse", "", "pathparam/false", SEQUENCE); - invokeSequence(0, "truefalse", "", "sessionpathparam/false", SEQUENCE); - } - - /* - * @testName: stringToCharTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send string receive char - */ - public void stringToCharTest() throws Exception { - String entity = "&"; - String[] SEQUENCE = { "primitivechar", "fullchar" }; - setEntity(entity); - invokeSequence(0, entity, "", "", SEQUENCE); - invokeSequence(0, entity, "", "session", SEQUENCE); - invokeSequence(0, entity + "X", "", "pathparam/X", SEQUENCE); - invokeSequence(0, entity + "y", "", "sessionpathparam/y", SEQUENCE); - } - - /* - * @testName: charToTextsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send char receive other - */ - public void charToTextsTest() throws Exception { - char entity = '1'; - setEntity(entity); - invokeTextSequences(0, String.valueOf(entity)); - invokeTextSequencesWithPathParam(0, String.valueOf(entity), "99"); - } - - /* - * @testName: partialStringTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send string and string receive the strings, too - */ - public void partialStringTest() throws Exception { - setCountDownLatchCount(2); - String partial2 = "partialStringTest"; - String response = ECHO + "(false)" + partial2 + "(true)"; - setEntity(ECHO, partial2); - setProperty(Property.REQUEST, buildRequest("partialstring")); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - /* - * @testName: partialStringAndSessionTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send string and string receive the combined string - */ - public void partialStringAndSessionTest() throws Exception { - String partial2 = "partialStringAndSessionTest"; - String response = ECHO + "(false)" + partial2 + "(true)"; - setEntity(ECHO, partial2); - setProperty(Property.REQUEST, buildRequest("partialstringsession")); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - /* - * @testName: partialStringWithPathParamTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send string and string receive the strings, too - */ - public void partialStringWithPathParamTest() throws Exception { - setCountDownLatchCount(2); - String partial2 = "partialStringTest"; - String response = ECHO + "(false)" + partial2 + partial2 + "(true)" - + partial2; - setEntity(ECHO, partial2); - setProperty(Property.REQUEST, - buildRequest("partialstringpathparam/" + partial2)); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - /* - * @testName: partialStringAndSessionWithPathParamTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: send string and string receive the combined string - */ - public void partialStringAndSessionWithPathParamTest() throws Exception { - String partial2 = "partialStringAndSessionTest"; - String response = ECHO + "(false)" + partial2 + partial2 + "(true)" - + partial2; - setEntity(ECHO, partial2); - setProperty(Property.REQUEST, - buildRequest("partialstringsessionpathparam/" + partial2)); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - // ----------------- BINARY ----------------------------------- - - /* - * @testName: echoByteBufferTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Echo ByteBuffer - */ - public void echoByteBufferTest() throws Exception { - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - setProperty(Property.REQUEST, buildRequest("bytebuffer")); - setProperty(Property.SEARCH_STRING, ECHO); - invoke(); - } - - /* - * @testName: byteBufferToBytesTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Send ByteBuffer receive bytes - */ - public void byteBufferToBytesTest() throws Exception { - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - setProperty(Property.REQUEST, buildRequest("bytearray")); - setProperty(Property.SEARCH_STRING, ECHO); - invoke(); - } - - /* - * @testName: byteBufferToBinaryTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: echo byte array - */ - public void byteBufferToBinaryTest() throws Exception { - String param = "byteBufferToBinaryTest"; - setEntity(ByteBuffer.wrap(ECHO.getBytes())); - invokeSequence(0, ECHO, "", "", BINARY_SEQUENCE); - invokeSequence(0, ECHO, "", "session", BINARY_SEQUENCE); - invokeSequence(0, ECHO + param, "", "pathparam/" + param, BINARY_SEQUENCE); - invokeSequence(0, ECHO + param, "", "sessionpathparam/" + param, - BINARY_SEQUENCE); - } - - /* - * @testName: pongToPongTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: echo byte array - */ - public void pongToPongTest() throws Exception { - setEntity(new StringPongMessage(ECHO)); - String[] sequence = { "pongmessage", "pongmessagesession" }; - invokeSequence(0, ECHO, "", "", sequence); - String[] paramsequence = { "pongmessagepathparam/param", - "pongmessagesessionpathparam/param" }; - invokeSequence(0, ECHO + "param", "", "", paramsequence); - } - - /* - * @testName: partialByteArrayTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send bytearray and bytearray receive the combined message - */ - public void partialByteArrayTest() throws Exception { - setCountDownLatchCount(2); - String partial2 = "partialByteArrayTest"; - String response = ECHO + "(false)" + partial2 + "(true)"; - setEntity(ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(partial2.getBytes())); - setProperty(Property.REQUEST, buildRequest("partialbytearray")); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - /* - * @testName: partialByteArrayAndSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send bytearray and bytearray receive the combined message - */ - public void partialByteArrayAndSessionTest() throws Exception { - String partial2 = "partialByteArrayAndSessionTest"; - String response = ECHO + "(false)" + partial2 + "(true)"; - setEntity(ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(partial2.getBytes())); - setProperty(Property.REQUEST, buildRequest("partialbytearraysession")); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - /* - * @testName: partialByteArrayWithPathParamTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send bytearray and bytearray receive the combined message - */ - public void partialByteArrayWithPathParamTest() throws Exception { - setCountDownLatchCount(2); - String partial2 = "partialByteArrayWithPathParamTest"; - String response = ECHO + "(false)[" + partial2 + "]" + partial2 + "(true)[" - + partial2 + "]"; - setEntity(ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(partial2.getBytes())); - setProperty(Property.REQUEST, - buildRequest("partialbytearraypathparam/" + partial2)); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - /* - * @testName: partialByteArrayAndSessionWithPathParamTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send bytearray and bytearray receive the combined message - */ - public void partialByteArrayAndSessionWithPathParamTest() throws Exception { - String partial2 = "partialByteArrayAndSessionWithPathParamTest"; - String response = ECHO + "(false)[" + partial2 + "]" + partial2 + "(true)[" - + partial2 + "]"; - setEntity(ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(partial2.getBytes())); - setProperty(Property.REQUEST, - buildRequest("partialbytearraysessionpathparam/" + partial2)); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - /* - * @testName: partialByteBufferTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message - */ - public void partialByteBufferTest() throws Exception { - setCountDownLatchCount(2); - String partial2 = "partialByteBufferTest"; - String response = ECHO + "(false)" + partial2 + "(true)"; - setEntity(ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(partial2.getBytes())); - setProperty(Property.REQUEST, buildRequest("partialbytebuffer")); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - /* - * @testName: partialByteBufferAndSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message - */ - public void partialByteBufferAndSessionTest() throws Exception { - String partial2 = "partialByteBufferAndSessionTest"; - String response = ECHO + "(false)" + partial2 + "(true)"; - setEntity(ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(partial2.getBytes())); - setProperty(Property.REQUEST, buildRequest("partialbytebuffersession")); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - /* - * @testName: partialByteBufferWithPathParamTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message - */ - public void partialByteBufferWithPathParamTest() throws Exception { - setCountDownLatchCount(2); - String partial2 = "partialByteBufferWithPathParamTest"; - String response = ECHO + "(false)[" + partial2 + "]" + partial2 + "(true)[" - + partial2 + "]"; - setEntity(ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(partial2.getBytes())); - setProperty(Property.REQUEST, - buildRequest("partialbytebufferpathparam/" + partial2)); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - /* - * @testName: partialByteBufferAndSessionWithPathParamTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message - */ - public void partialByteBufferAndSessionWithPathParamTest() throws Exception { - String partial2 = "partialByteBufferAndSessionWithPathParamTest"; - String response = ECHO + "(false)[" + partial2 + "]" + partial2 + "(true)[" - + partial2 + "]"; - setEntity(ByteBuffer.wrap(ECHO.getBytes()), - ByteBuffer.wrap(partial2.getBytes())); - setProperty(Property.REQUEST, - buildRequest("partialbytebuffersessionpathparam/" + partial2)); - setProperty(Property.SEARCH_STRING, response); - invoke(); - } - - // --------------------------------- MAX LEN - /* - * @testName: maxLengthOKTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: the message is shorter than maxMessageLength - */ - public void maxLengthOKTest() throws Exception { - String entity = "12345"; - setEntity(entity); - setProperty(Property.REQUEST, buildRequest("maxlen")); - setProperty(Property.SEARCH_STRING, entity); - invoke(); - } - - /* - * @testName: maxLengthFailsTest - * - * @assertion_ids: WebSocket:JAVADOC:80; WebSocket:SPEC:WSC-4.7.1-1; - * - * @test_Strategy: the message is longer than maxMessageLength - */ - public void maxLengthFailsTest() throws Exception { - final AtomicInteger ai = new AtomicInteger(0); - setEntity("123456"); - EndpointCallback callback = new SendMessageCallback(entity) { - @Override - public void onClose(Session session, CloseReason closeReason) { - ai.set(closeReason.getCloseCode().getCode()); - getCountDownLatch().countDown(); - } - }; - setClientCallback(callback); - setProperty(Property.REQUEST, buildRequest("maxlen")); - invoke(false); - assertEqualsInt(1009, ai.get(), "Unexpected close reason found", ai.get()); - logMsg("Found expected close reason code", 1009); - } - - /* - * @testName: defaultMaxLengthTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: Default -1; - */ - public void defaultMaxLengthTest() throws Exception { - setEntity("123456789"); - setProperty(Property.REQUEST, buildRequest("defaultmaxlen")); - setProperty(Property.SEARCH_STRING, "-1"); - invoke(); - } - - // //////////////////////////////////////////////////////////////////// - private void invokeSequence(int startIndex, String search, String prefix, - String suffix, String[] sequence) throws Exception { - for (int i = startIndex; i != sequence.length; i++) { - setProperty(Property.REQUEST, buildRequest(prefix, sequence[i], suffix)); - setProperty(Property.SEARCH_STRING, search); - invoke(); - } - } - - private void invokeTextSequences(int startIndex, String search) throws Exception { - invokeSequence(startIndex, search, "primitive", "", - TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(startIndex, search, "full", "", TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(0, search, "", "", TEXT_TYPE_SEQUENCE); - invokeSequence(startIndex, search, "primitive", "session", - TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(startIndex, search, "full", "session", - TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(0, search, "", "session", TEXT_TYPE_SEQUENCE); - } - - private void invokeTextSequencesWithPathParam(int startIndex, String content, - String pathParam) throws Exception { - String suffix = "pathparam/" + pathParam; - String search = content + pathParam; - invokeSequence(startIndex, search, "primitive", suffix, - TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(startIndex, search, "full", suffix, TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(0, search, "", suffix, TEXT_TYPE_SEQUENCE); - invokeSequence(startIndex, search, "primitive", "session" + suffix, - TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(startIndex, search, "full", "session" + suffix, - TEXT_PRIMITIVE_SEQUENCE); - invokeSequence(0, search, "", "session" + suffix, TEXT_TYPE_SEQUENCE); - - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSClientIT.java new file mode 100644 index 0000000000..87799c98d3 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSClientIT.java @@ -0,0 +1,947 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.websocketmessage; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.concurrent.atomic.AtomicInteger; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.EndpointCallback; +import com.sun.ts.tests.websocket.common.client.SendMessageCallback; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.StringPongMessage; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +import jakarta.websocket.CloseReason; +import jakarta.websocket.Session; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 932557106496525508L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_ee_websocketmessage_web.war"); + archive.addPackages(false, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.websocketmessage"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + static final String ECHO = "Echo message to be sent to server endpoint"; + + static final String[] TEXT_PRIMITIVE_SEQUENCE = { "byte", "short", "int", "long", "double", "float" }; + + static final String[] TEXT_TYPE_SEQUENCE = { "string", "reader", "textdecoder", "textstreamdecoder" }; + + static final String[] BINARY_SEQUENCE = { "bytearray", "bytebuffer", "inputstream", "binarydecoder", + "binarystreamdecoder" }; + + public static int getIndex(String item) { + for (int i = 0; i != TEXT_PRIMITIVE_SEQUENCE.length; i++) + if (TEXT_PRIMITIVE_SEQUENCE[i].equals(item)) + return i; + return -1; + } + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("ws_ee_websocketmessage_web"); + } + + /* Run test */ + + // TEXT ------------------------------------------ + + /* + * @testName: echoStringTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Echo String + */ + @Test + public void echoStringTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("string")); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + invoke(); + } + + /* + * @testName: echoIntTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo int + */ + @Test + public void echoIntTest() throws Exception { + int entity = Integer.MIN_VALUE; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("primitiveint")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoByteTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo byte + */ + @Test + public void echoByteTest() throws Exception { + byte entity = 123; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("primitivebyte")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoCharTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo char + */ + @Test + public void echoCharTest() throws Exception { + char entity = 'E'; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("primitivechar")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity) + "char"); + invoke(); + } + + /* + * @testName: echoBooleanTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo boolean + */ + @Test + public void echoBooleanTest() throws Exception { + boolean entity = true; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("primitiveboolean")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoShortTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo short + */ + @Test + public void echoShortTest() throws Exception { + short entity = -32100; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("primitiveshort")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoDoubleTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo double + */ + @Test + public void echoDoubleTest() throws Exception { + double entity = -12345678.88; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("primitivedouble")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoFloatTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo float + */ + @Test + public void echoFloatTest() throws Exception { + float entity = -12345678.88f; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("primitivefloat")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoLongTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo long + */ + @Test + public void echoLongTest() throws Exception { + long entity = Long.MIN_VALUE; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("primitivelong")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoFullIntTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo int + */ + @Test + public void echoFullIntTest() throws Exception { + Integer entity = Integer.MIN_VALUE; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("fullint")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoFullByteTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo byte + */ + @Test + public void echoFullByteTest() throws Exception { + Byte entity = Byte.MIN_VALUE; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("fullbyte")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoFullCharTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo char + */ + @Test + public void echoFullCharTest() throws Exception { + Character entity = 'E'; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("fullchar")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoFullBooleanTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo boolean + */ + @Test + public void echoFullBooleanTest() throws Exception { + Boolean entity = true; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("fullboolean")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoFullShortTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo short + */ + @Test + public void echoFullShortTest() throws Exception { + Short entity = Short.MAX_VALUE; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("fullshort")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoFullDoubleTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo double + */ + @Test + public void echoFullDoubleTest() throws Exception { + Double entity = Double.MIN_VALUE; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("fulldouble")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoFullFloatTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo float + */ + @Test + public void echoFullFloatTest() throws Exception { + Float entity = Float.MAX_VALUE; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("fullfloat")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + /* + * @testName: echoFullLongTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-3; WebSocket:JAVADOC:80; + * + * @test_Strategy: echo long + */ + @Test + public void echoFullLongTest() throws Exception { + Long entity = Long.MAX_VALUE; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("fulllong")); + setProperty(Property.SEARCH_STRING, String.valueOf(entity)); + invoke(); + } + + // ------------------------------------------------------------------ + + /* + * @testName: byteToTextsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send byte receive other texts + */ + @Test + public void byteToTextsTest() throws Exception { + byte entity = 123; + setEntity(entity); + int index = getIndex("byte"); + invokeTextSequences(index + 1, String.valueOf(entity)); + invokeTextSequencesWithPathParam(index, String.valueOf(entity), "101"); + } + + /* + * @testName: shortToTextsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send short receive other + */ + @Test + public void shortToTextsTest() throws Exception { + short entity = Short.MAX_VALUE; + setEntity(entity); + int index = getIndex("short"); + invokeTextSequences(index + 1, String.valueOf(entity)); + invokeTextSequencesWithPathParam(index, String.valueOf(entity), "1001"); + } + + /* + * @testName: intToTextsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send int receive other + */ + @Test + public void intToTextsTest() throws Exception { + int entity = Short.MAX_VALUE; // Integer.MAX_VALUE is + // 2.147483647E9 at Double + setEntity(entity); + int index = getIndex("int"); + invokeTextSequences(index + 1, String.valueOf(entity)); + invokeTextSequencesWithPathParam(index, String.valueOf(entity), "100001"); + } + + /* + * @testName: longToTextsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send long receive other + */ + @Test + public void longToTextsTest() throws Exception { + long entity = Short.MIN_VALUE; // Long.MIN_VALUE is + // -9.223372036854776E18 at Double + setEntity(entity); + int index = getIndex("long"); + invokeTextSequences(index + 1, String.valueOf(entity)); + invokeTextSequencesWithPathParam(index, String.valueOf(entity), "100001"); + } + + /* + * @testName: floatToTextsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send float receive other + */ + @Test + public void floatToTextsTest() throws Exception { + float entity = Float.MIN_VALUE; + setEntity(entity); + int index = getIndex("float"); + invokeTextSequences(index + 1, String.valueOf(entity)); + invokeTextSequencesWithPathParam(index, String.valueOf(entity), String.valueOf(101.101f)); + } + + /* + * @testName: doubleToTextsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send double receive other + */ + @Test + public void doubleToTextsTest() throws Exception { + double entity = Double.MAX_VALUE; + setEntity(entity); + invokeSequence(0, String.valueOf(entity), "", "", TEXT_TYPE_SEQUENCE); + invokeSequence(0, String.valueOf(entity), "", "session", TEXT_TYPE_SEQUENCE); + String pathParam = String.valueOf(101.101); + invokeSequence(0, String.valueOf(entity) + pathParam, "", "pathparam/" + pathParam, TEXT_TYPE_SEQUENCE); + invokeSequence(0, String.valueOf(entity) + pathParam, "", "sessionpathparam/" + pathParam, TEXT_TYPE_SEQUENCE); + } + + /* + * @testName: stringToTextsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send string receive other + */ + @Test + public void stringToTextsTest() throws Exception { + String param = "StringParam"; + setEntity(ECHO); + invokeSequence(0, ECHO, "", "", TEXT_TYPE_SEQUENCE); + invokeSequence(0, ECHO, "", "session", TEXT_TYPE_SEQUENCE); + invokeSequence(0, ECHO + param, "", "pathparam/" + param, TEXT_TYPE_SEQUENCE); + invokeSequence(0, ECHO + param, "", "sessionpathparam/" + param, TEXT_TYPE_SEQUENCE); + } + + /* + * @testName: stringToAllNumbersTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send string receive other + */ + @Test + public void stringToAllNumbersTest() throws Exception { + String entity = String.valueOf(Byte.MAX_VALUE); + String param = "111"; + setEntity(entity); + invokeSequence(0, String.valueOf(entity), "primitive", "", TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(0, String.valueOf(entity), "full", "", TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(0, String.valueOf(entity), "primitive", "session", TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(0, String.valueOf(entity), "full", "session", TEXT_PRIMITIVE_SEQUENCE); + + invokeSequence(0, String.valueOf(entity) + param, "primitive", "pathparam/" + param, TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(0, String.valueOf(entity) + param, "full", "pathparam/" + param, TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(0, String.valueOf(entity) + param, "primitive", "sessionpathparam/" + param, + TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(0, String.valueOf(entity) + param, "full", "sessionpathparam/" + param, TEXT_PRIMITIVE_SEQUENCE); + } + + /* + * @testName: booleanToBooleanWithPathParamTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send boolean receive boolean + */ + @Test + public void booleanToBooleanWithPathParamTest() throws Exception { + boolean entity = true; + String[] SEQUENCE = { "primitiveboolean", "fullboolean" }; + setEntity(entity); + invokeSequence(0, "true", "", "", SEQUENCE); + invokeSequence(0, "true", "", "session", SEQUENCE); + invokeSequence(0, "truefalse", "", "pathparam/false", SEQUENCE); + invokeSequence(0, "truefalse", "", "sessionpathparam/false", SEQUENCE); + } + + /* + * @testName: stringToBooleanTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send string receive boolean + */ + @Test + public void stringToBooleanTest() throws Exception { + String entity = "true"; + String[] SEQUENCE = { "primitiveboolean", "fullboolean" }; + setEntity(entity); + invokeSequence(0, entity, "", "", SEQUENCE); + invokeSequence(0, entity, "", "session", SEQUENCE); + invokeSequence(0, "truefalse", "", "pathparam/false", SEQUENCE); + invokeSequence(0, "truefalse", "", "sessionpathparam/false", SEQUENCE); + } + + /* + * @testName: stringToCharTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send string receive char + */ + @Test + public void stringToCharTest() throws Exception { + String entity = "&"; + String[] SEQUENCE = { "primitivechar", "fullchar" }; + setEntity(entity); + invokeSequence(0, entity, "", "", SEQUENCE); + invokeSequence(0, entity, "", "session", SEQUENCE); + invokeSequence(0, entity + "X", "", "pathparam/X", SEQUENCE); + invokeSequence(0, entity + "y", "", "sessionpathparam/y", SEQUENCE); + } + + /* + * @testName: charToTextsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send char receive other + */ + @Test + public void charToTextsTest() throws Exception { + char entity = '1'; + setEntity(entity); + invokeTextSequences(0, String.valueOf(entity)); + invokeTextSequencesWithPathParam(0, String.valueOf(entity), "99"); + } + + /* + * @testName: partialStringTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send string and string receive the strings, too + */ + @Test + public void partialStringTest() throws Exception { + setCountDownLatchCount(2); + String partial2 = "partialStringTest"; + String response = ECHO + "(false)" + partial2 + "(true)"; + setEntity(ECHO, partial2); + setProperty(Property.REQUEST, buildRequest("partialstring")); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + /* + * @testName: partialStringAndSessionTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send string and string receive the combined string + */ + @Test + public void partialStringAndSessionTest() throws Exception { + String partial2 = "partialStringAndSessionTest"; + String response = ECHO + "(false)" + partial2 + "(true)"; + setEntity(ECHO, partial2); + setProperty(Property.REQUEST, buildRequest("partialstringsession")); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + /* + * @testName: partialStringWithPathParamTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send string and string receive the strings, too + */ + @Test + public void partialStringWithPathParamTest() throws Exception { + setCountDownLatchCount(2); + String partial2 = "partialStringTest"; + String response = ECHO + "(false)" + partial2 + partial2 + "(true)" + partial2; + setEntity(ECHO, partial2); + setProperty(Property.REQUEST, buildRequest("partialstringpathparam/" + partial2)); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + /* + * @testName: partialStringAndSessionWithPathParamTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: send string and string receive the combined string + */ + @Test + public void partialStringAndSessionWithPathParamTest() throws Exception { + String partial2 = "partialStringAndSessionTest"; + String response = ECHO + "(false)" + partial2 + partial2 + "(true)" + partial2; + setEntity(ECHO, partial2); + setProperty(Property.REQUEST, buildRequest("partialstringsessionpathparam/" + partial2)); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + // ----------------- BINARY ----------------------------------- + + /* + * @testName: echoByteBufferTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Echo ByteBuffer + */ + @Test + public void echoByteBufferTest() throws Exception { + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + setProperty(Property.REQUEST, buildRequest("bytebuffer")); + setProperty(Property.SEARCH_STRING, ECHO); + invoke(); + } + + /* + * @testName: byteBufferToBytesTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Send ByteBuffer receive bytes + */ + @Test + public void byteBufferToBytesTest() throws Exception { + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + setProperty(Property.REQUEST, buildRequest("bytearray")); + setProperty(Property.SEARCH_STRING, ECHO); + invoke(); + } + + /* + * @testName: byteBufferToBinaryTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: echo byte array + */ + @Test + public void byteBufferToBinaryTest() throws Exception { + String param = "byteBufferToBinaryTest"; + setEntity(ByteBuffer.wrap(ECHO.getBytes())); + invokeSequence(0, ECHO, "", "", BINARY_SEQUENCE); + invokeSequence(0, ECHO, "", "session", BINARY_SEQUENCE); + invokeSequence(0, ECHO + param, "", "pathparam/" + param, BINARY_SEQUENCE); + invokeSequence(0, ECHO + param, "", "sessionpathparam/" + param, BINARY_SEQUENCE); + } + + /* + * @testName: pongToPongTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: echo byte array + */ + @Test + public void pongToPongTest() throws Exception { + setEntity(new StringPongMessage(ECHO)); + String[] sequence = { "pongmessage", "pongmessagesession" }; + invokeSequence(0, ECHO, "", "", sequence); + String[] paramsequence = { "pongmessagepathparam/param", "pongmessagesessionpathparam/param" }; + invokeSequence(0, ECHO + "param", "", "", paramsequence); + } + + /* + * @testName: partialByteArrayTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send bytearray and bytearray receive the combined message + */ + @Test + public void partialByteArrayTest() throws Exception { + setCountDownLatchCount(2); + String partial2 = "partialByteArrayTest"; + String response = ECHO + "(false)" + partial2 + "(true)"; + setEntity(ByteBuffer.wrap(ECHO.getBytes()), ByteBuffer.wrap(partial2.getBytes())); + setProperty(Property.REQUEST, buildRequest("partialbytearray")); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + /* + * @testName: partialByteArrayAndSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send bytearray and bytearray receive the combined message + */ + @Test + public void partialByteArrayAndSessionTest() throws Exception { + String partial2 = "partialByteArrayAndSessionTest"; + String response = ECHO + "(false)" + partial2 + "(true)"; + setEntity(ByteBuffer.wrap(ECHO.getBytes()), ByteBuffer.wrap(partial2.getBytes())); + setProperty(Property.REQUEST, buildRequest("partialbytearraysession")); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + /* + * @testName: partialByteArrayWithPathParamTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send bytearray and bytearray receive the combined message + */ + @Test + public void partialByteArrayWithPathParamTest() throws Exception { + setCountDownLatchCount(2); + String partial2 = "partialByteArrayWithPathParamTest"; + String response = ECHO + "(false)[" + partial2 + "]" + partial2 + "(true)[" + partial2 + "]"; + setEntity(ByteBuffer.wrap(ECHO.getBytes()), ByteBuffer.wrap(partial2.getBytes())); + setProperty(Property.REQUEST, buildRequest("partialbytearraypathparam/" + partial2)); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + /* + * @testName: partialByteArrayAndSessionWithPathParamTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send bytearray and bytearray receive the combined message + */ + @Test + public void partialByteArrayAndSessionWithPathParamTest() throws Exception { + String partial2 = "partialByteArrayAndSessionWithPathParamTest"; + String response = ECHO + "(false)[" + partial2 + "]" + partial2 + "(true)[" + partial2 + "]"; + setEntity(ByteBuffer.wrap(ECHO.getBytes()), ByteBuffer.wrap(partial2.getBytes())); + setProperty(Property.REQUEST, buildRequest("partialbytearraysessionpathparam/" + partial2)); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + /* + * @testName: partialByteBufferTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message + */ + @Test + public void partialByteBufferTest() throws Exception { + setCountDownLatchCount(2); + String partial2 = "partialByteBufferTest"; + String response = ECHO + "(false)" + partial2 + "(true)"; + setEntity(ByteBuffer.wrap(ECHO.getBytes()), ByteBuffer.wrap(partial2.getBytes())); + setProperty(Property.REQUEST, buildRequest("partialbytebuffer")); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + /* + * @testName: partialByteBufferAndSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message + */ + @Test + public void partialByteBufferAndSessionTest() throws Exception { + String partial2 = "partialByteBufferAndSessionTest"; + String response = ECHO + "(false)" + partial2 + "(true)"; + setEntity(ByteBuffer.wrap(ECHO.getBytes()), ByteBuffer.wrap(partial2.getBytes())); + setProperty(Property.REQUEST, buildRequest("partialbytebuffersession")); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + /* + * @testName: partialByteBufferWithPathParamTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message + */ + @Test + public void partialByteBufferWithPathParamTest() throws Exception { + setCountDownLatchCount(2); + String partial2 = "partialByteBufferWithPathParamTest"; + String response = ECHO + "(false)[" + partial2 + "]" + partial2 + "(true)[" + partial2 + "]"; + setEntity(ByteBuffer.wrap(ECHO.getBytes()), ByteBuffer.wrap(partial2.getBytes())); + setProperty(Property.REQUEST, buildRequest("partialbytebufferpathparam/" + partial2)); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + /* + * @testName: partialByteBufferAndSessionWithPathParamTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: send ByteBuffer and ByteBuffer receive the combined message + */ + @Test + public void partialByteBufferAndSessionWithPathParamTest() throws Exception { + String partial2 = "partialByteBufferAndSessionWithPathParamTest"; + String response = ECHO + "(false)[" + partial2 + "]" + partial2 + "(true)[" + partial2 + "]"; + setEntity(ByteBuffer.wrap(ECHO.getBytes()), ByteBuffer.wrap(partial2.getBytes())); + setProperty(Property.REQUEST, buildRequest("partialbytebuffersessionpathparam/" + partial2)); + setProperty(Property.SEARCH_STRING, response); + invoke(); + } + + // --------------------------------- MAX LEN + /* + * @testName: maxLengthOKTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: the message is shorter than maxMessageLength + */ + @Test + public void maxLengthOKTest() throws Exception { + String entity = "12345"; + setEntity(entity); + setProperty(Property.REQUEST, buildRequest("maxlen")); + setProperty(Property.SEARCH_STRING, entity); + invoke(); + } + + /* + * @testName: maxLengthFailsTest + * + * @assertion_ids: WebSocket:JAVADOC:80; WebSocket:SPEC:WSC-4.7.1-1; + * + * @test_Strategy: the message is longer than maxMessageLength + */ + @Test + public void maxLengthFailsTest() throws Exception { + final AtomicInteger ai = new AtomicInteger(0); + setEntity("123456"); + EndpointCallback callback = new SendMessageCallback(entity) { + @Override + public void onClose(Session session, CloseReason closeReason) { + ai.set(closeReason.getCloseCode().getCode()); + getCountDownLatch().countDown(); + } + }; + setClientCallback(callback); + setProperty(Property.REQUEST, buildRequest("maxlen")); + invoke(false); + assertEqualsInt(1009, ai.get(), "Unexpected close reason found", ai.get()); + logMsg("Found expected close reason code", 1009); + } + + /* + * @testName: defaultMaxLengthTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: Default -1; + */ + @Test + public void defaultMaxLengthTest() throws Exception { + setEntity("123456789"); + setProperty(Property.REQUEST, buildRequest("defaultmaxlen")); + setProperty(Property.SEARCH_STRING, "-1"); + invoke(); + } + + // //////////////////////////////////////////////////////////////////// + private void invokeSequence(int startIndex, String search, String prefix, String suffix, String[] sequence) + throws Exception { + for (int i = startIndex; i != sequence.length; i++) { + setProperty(Property.REQUEST, buildRequest(prefix, sequence[i], suffix)); + setProperty(Property.SEARCH_STRING, search); + invoke(); + } + } + + private void invokeTextSequences(int startIndex, String search) throws Exception { + invokeSequence(startIndex, search, "primitive", "", TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(startIndex, search, "full", "", TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(0, search, "", "", TEXT_TYPE_SEQUENCE); + invokeSequence(startIndex, search, "primitive", "session", TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(startIndex, search, "full", "session", TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(0, search, "", "session", TEXT_TYPE_SEQUENCE); + } + + private void invokeTextSequencesWithPathParam(int startIndex, String content, String pathParam) throws Exception { + String suffix = "pathparam/" + pathParam; + String search = content + pathParam; + invokeSequence(startIndex, search, "primitive", suffix, TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(startIndex, search, "full", suffix, TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(0, search, "", suffix, TEXT_TYPE_SEQUENCE); + invokeSequence(startIndex, search, "primitive", "session" + suffix, TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(startIndex, search, "full", "session" + suffix, TEXT_PRIMITIVE_SEQUENCE); + invokeSequence(0, search, "", "session" + suffix, TEXT_TYPE_SEQUENCE); + + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSDefaultMaxLengthServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSDefaultMaxLengthServer.java index 625c231e47..57cde50d05 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSDefaultMaxLengthServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSDefaultMaxLengthServer.java @@ -30,25 +30,25 @@ @ServerEndpoint("/defaultmaxlen") public class WSDefaultMaxLengthServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(String echo) { - try { - Method m = getClass().getMethod("echo", String.class); - OnMessage onm = m.getAnnotation(OnMessage.class); - long size = onm.maxMessageSize(); - return String.valueOf(size); - } catch (Exception e) { - return IOUtil.printStackTrace(e); - } - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(String echo) { + try { + Method m = getClass().getMethod("echo", String.class); + OnMessage onm = m.getAnnotation(OnMessage.class); + long size = onm.maxMessageSize(); + return String.valueOf(size); + } catch (Exception e) { + return IOUtil.printStackTrace(e); + } + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndPathParamServer.java index aa1d2f1b5b..a2b0b4e887 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndPathParamServer.java @@ -30,17 +30,16 @@ @ServerEndpoint("/fullbooleanpathparam/{param}") public class WSFullBooleanAndPathParamServer { - @OnMessage - public String echo(@PathParam("param") Boolean param, Boolean b) { - return String.valueOf(b.booleanValue()) - + String.valueOf(param.booleanValue()); - } + @OnMessage + public String echo(@PathParam("param") Boolean param, Boolean b) { + return String.valueOf(b.booleanValue()) + String.valueOf(param.booleanValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndSessionAndPathParamServer.java index 2b6a148de4..162e9ceb4b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndSessionAndPathParamServer.java @@ -30,19 +30,17 @@ @ServerEndpoint("/fullbooleansessionpathparam/{param}") public class WSFullBooleanAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(@PathParam("{param}") Boolean param, Boolean b, - Session s) { - return String.valueOf(b.booleanValue()) - + String.valueOf(param.booleanValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(@PathParam("{param}") Boolean param, Boolean b, Session s) { + return String.valueOf(b.booleanValue()) + String.valueOf(param.booleanValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndSessionServer.java index 124f9147d1..bf75dd8fcf 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanAndSessionServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/fullbooleansession") public class WSFullBooleanAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Boolean b, Session s) { - return String.valueOf(b.booleanValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Boolean b, Session s) { + return String.valueOf(b.booleanValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanServer.java index 2708f453cb..aca942b9a6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullBooleanServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/fullboolean") public class WSFullBooleanServer { - @OnMessage - public String echo(Boolean b) { - return String.valueOf(b.booleanValue()); - } + @OnMessage + public String echo(Boolean b) { + return String.valueOf(b.booleanValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndPathParamServer.java index defc6ceb7f..c221f7a515 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndPathParamServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/fullbytepathparam/{param}") public class WSFullByteAndPathParamServer { - @OnMessage - public String echo(Byte b, @PathParam("param") Byte param) { - return String.valueOf(b.byteValue()) + String.valueOf(param.byteValue()); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(Byte b, @PathParam("param") Byte param) { + return String.valueOf(b.byteValue()) + String.valueOf(param.byteValue()); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndSessionAndPathParamServer.java index c271d4cf71..101a00a8b7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndSessionAndPathParamServer.java @@ -30,18 +30,18 @@ @ServerEndpoint("/fullbytesessionpathparam/{param}") public class WSFullByteAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Byte b, @PathParam("param") Byte param, Session s) { - return String.valueOf(b.byteValue()) + String.valueOf(param.byteValue()); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Byte b, @PathParam("param") Byte param, Session s) { + return String.valueOf(b.byteValue()) + String.valueOf(param.byteValue()); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndSessionServer.java index f6ba9b3ff1..a9f18b3647 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteAndSessionServer.java @@ -29,18 +29,18 @@ @ServerEndpoint("/fullbytesession") public class WSFullByteAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Byte b, Session s) { - return String.valueOf(b.byteValue()); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Byte b, Session s) { + return String.valueOf(b.byteValue()); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteServer.java index 3d77911582..9201fd92ea 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullByteServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/fullbyte") public class WSFullByteServer { - @OnMessage - public String echo(Byte b) { - return String.valueOf(b.byteValue()); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(Byte b) { + return String.valueOf(b.byteValue()); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndPathParamServer.java index cee5caf0b5..1e53fe3201 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndPathParamServer.java @@ -30,16 +30,16 @@ @ServerEndpoint("/fullcharpathparam/{param}") public class WSFullCharAndPathParamServer { - @OnMessage - public String echo(@PathParam("param") Character param, Character c) { - return String.valueOf(c.charValue()) + String.valueOf(param.charValue()); - } + @OnMessage + public String echo(@PathParam("param") Character param, Character c) { + return String.valueOf(c.charValue()) + String.valueOf(param.charValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndSessionAndPathParamServer.java index bef90f7fcc..91a1b9d7d1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndSessionAndPathParamServer.java @@ -30,18 +30,17 @@ @ServerEndpoint("/fullcharsessionpathparam/{param}") public class WSFullCharAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Session s, Character c, - @PathParam("param") Character param) { - return String.valueOf(c.charValue()) + String.valueOf(param.charValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Session s, Character c, @PathParam("param") Character param) { + return String.valueOf(c.charValue()) + String.valueOf(param.charValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndSessionServer.java index 67eaf42cc0..5c2bddc080 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharAndSessionServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/fullcharsession") public class WSFullCharAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Session s, Character c) { - return String.valueOf(c.charValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Session s, Character c) { + return String.valueOf(c.charValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharServer.java index 660ec2be6e..a2de83323c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullCharServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/fullchar") public class WSFullCharServer { - @OnMessage - public String echo(Character c) { - return String.valueOf(c.charValue()); - } + @OnMessage + public String echo(Character c) { + return String.valueOf(c.charValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndPathParamServer.java index 1450e61bb8..c6e2a9c4b9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndPathParamServer.java @@ -29,17 +29,16 @@ @ServerEndpoint("/fulldoublepathparam/{param}") public class WSFullDoubleAndPathParamServer { - @OnMessage - public String echo(Double d, @PathParam("param") Double param) { - return (String.valueOf(d.doubleValue()) - + String.valueOf(param.doubleValue())).replace(".0", ""); - } + @OnMessage + public String echo(Double d, @PathParam("param") Double param) { + return (String.valueOf(d.doubleValue()) + String.valueOf(param.doubleValue())).replace(".0", ""); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndSessionAndPathParamServer.java index f8e76a058c..1ab1627f1d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndSessionAndPathParamServer.java @@ -29,18 +29,17 @@ @ServerEndpoint("/fulldoublesessionpathparam/{param}") public class WSFullDoubleAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Session s, Double d, @PathParam("param") Double param) { - return (String.valueOf(d.doubleValue()) - + String.valueOf(param.doubleValue())).replace(".0", ""); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Session s, Double d, @PathParam("param") Double param) { + return (String.valueOf(d.doubleValue()) + String.valueOf(param.doubleValue())).replace(".0", ""); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndSessionServer.java index 180e088eac..e12082fc8b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleAndSessionServer.java @@ -28,17 +28,17 @@ @ServerEndpoint("/fulldoublesession") public class WSFullDoubleAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Session s, Double d) { - return String.valueOf(d.doubleValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Session s, Double d) { + return String.valueOf(d.doubleValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleServer.java index 396e2ca6cd..f894960f24 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullDoubleServer.java @@ -28,16 +28,16 @@ @ServerEndpoint("/fulldouble") public class WSFullDoubleServer { - @OnMessage - public String echo(Double d) { - return String.valueOf(d.doubleValue()); - } + @OnMessage + public String echo(Double d) { + return String.valueOf(d.doubleValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndPathParamServer.java index 59bb22a17d..7983ad151b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndPathParamServer.java @@ -29,17 +29,16 @@ @ServerEndpoint("/fullfloatpathparam/{param}") public class WSFullFloatAndPathParamServer { - @OnMessage - public String echo(Float f, @PathParam("param") Float param) { - return (String.valueOf(f.floatValue()) + String.valueOf(param.floatValue())) - .replace(".0", ""); - } + @OnMessage + public String echo(Float f, @PathParam("param") Float param) { + return (String.valueOf(f.floatValue()) + String.valueOf(param.floatValue())).replace(".0", ""); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndSessionAndPathParamServer.java index 5fa9788e15..d963e853f0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndSessionAndPathParamServer.java @@ -29,18 +29,17 @@ @ServerEndpoint("/fullfloatsessionpathparam/{param}") public class WSFullFloatAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(@PathParam("param") Float param, Float f, Session s) { - return (String.valueOf(f.floatValue()) + String.valueOf(param.floatValue())) - .replace(".0", ""); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(@PathParam("param") Float param, Float f, Session s) { + return (String.valueOf(f.floatValue()) + String.valueOf(param.floatValue())).replace(".0", ""); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndSessionServer.java index 856df2b5c1..b425742326 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatAndSessionServer.java @@ -28,17 +28,17 @@ @ServerEndpoint("/fullfloatsession") public class WSFullFloatAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Float f, Session s) { - return String.valueOf(f.floatValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Float f, Session s) { + return String.valueOf(f.floatValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatServer.java index f35f7be8ea..2e242c715b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullFloatServer.java @@ -28,16 +28,16 @@ @ServerEndpoint("/fullfloat") public class WSFullFloatServer { - @OnMessage - public String echo(Float f) { - return String.valueOf(f.floatValue()); - } + @OnMessage + public String echo(Float f) { + return String.valueOf(f.floatValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndPathParamServer.java index f63a051121..71211b2663 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndPathParamServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/fullintpathparam/{param}") public class WSFullIntAndPathParamServer { - @OnMessage - public String echo(Integer i, @PathParam("param") Integer param) { - return String.valueOf(i.intValue()) + String.valueOf(param.intValue()); - } + @OnMessage + public String echo(Integer i, @PathParam("param") Integer param) { + return String.valueOf(i.intValue()) + String.valueOf(param.intValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndSessionAndPathParamServer.java index 5205b1c180..c911d55452 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndSessionAndPathParamServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/fullintsessionpathparam/{param}") public class WSFullIntAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Integer i, @PathParam("param") Integer param, Session s) { - return String.valueOf(i.intValue()) + String.valueOf(param.intValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Integer i, @PathParam("param") Integer param, Session s) { + return String.valueOf(i.intValue()) + String.valueOf(param.intValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndSessionServer.java index 035b98775e..28b3e6aedd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntAndSessionServer.java @@ -28,17 +28,17 @@ @ServerEndpoint("/fullintsession") public class WSFullIntAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Integer i, Session s) { - return String.valueOf(i.intValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Integer i, Session s) { + return String.valueOf(i.intValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntServer.java index 9c4488a5b1..c3f2001c0b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullIntServer.java @@ -28,16 +28,16 @@ @ServerEndpoint("/fullint") public class WSFullIntServer { - @OnMessage - public String echo(Integer i) { - return String.valueOf(i.intValue()); - } + @OnMessage + public String echo(Integer i) { + return String.valueOf(i.intValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndPathParamServer.java index 071e4f5057..7da63f3f87 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndPathParamServer.java @@ -30,16 +30,16 @@ @ServerEndpoint("/fulllongpathparam/{param}") public class WSFullLongAndPathParamServer { - @OnMessage - public String echo(@PathParam("param") Long param, Long l) { - return String.valueOf(l.longValue()) + String.valueOf(param.longValue()); - } + @OnMessage + public String echo(@PathParam("param") Long param, Long l) { + return String.valueOf(l.longValue()) + String.valueOf(param.longValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndSessionAndPathParamServer.java index ea9069672f..4f12191616 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndSessionAndPathParamServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/fulllongsessionpathparam/{param}") public class WSFullLongAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(@PathParam("param") Long param, Long l, Session s) { - return String.valueOf(l.longValue()) + String.valueOf(param.longValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(@PathParam("param") Long param, Long l, Session s) { + return String.valueOf(l.longValue()) + String.valueOf(param.longValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndSessionServer.java index 76af8d6ac7..4690f87002 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongAndSessionServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/fulllongsession") public class WSFullLongAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Long l, Session s) { - return String.valueOf(l.longValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Long l, Session s) { + return String.valueOf(l.longValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongServer.java index b8a9ea0ee7..3a5bad0bb5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullLongServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/fulllong") public class WSFullLongServer { - @OnMessage - public String echo(Long l) { - return String.valueOf(l.longValue()); - } + @OnMessage + public String echo(Long l) { + return String.valueOf(l.longValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndPathParamServer.java index 75d49784f9..80c9b04402 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndPathParamServer.java @@ -30,16 +30,16 @@ @ServerEndpoint("/fullshortpathparam/{param}") public class WSFullShortAndPathParamServer { - @OnMessage - public String echo(@PathParam("param") Short param, Short s) { - return String.valueOf(s.shortValue()) + String.valueOf(param.shortValue()); - } + @OnMessage + public String echo(@PathParam("param") Short param, Short s) { + return String.valueOf(s.shortValue()) + String.valueOf(param.shortValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndSessionAndPathParamServer.java index 5bed8fcdfa..3c28a1fc76 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndSessionAndPathParamServer.java @@ -30,18 +30,17 @@ @ServerEndpoint("/fullshortsessionpathparam/{param}") public class WSFullShortAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Short s, Session session, - @PathParam("param") Short param) { - return String.valueOf(s.shortValue()) + String.valueOf(param.shortValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Short s, Session session, @PathParam("param") Short param) { + return String.valueOf(s.shortValue()) + String.valueOf(param.shortValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndSessionServer.java index f180673231..9514e85171 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortAndSessionServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/fullshortsession") public class WSFullShortAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Short s, Session session) { - return String.valueOf(s.shortValue()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Short s, Session session) { + return String.valueOf(s.shortValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortServer.java index 634adbff9e..3339678ea4 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSFullShortServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/fullshort") public class WSFullShortServer { - @OnMessage - public String echo(Short s) { - return String.valueOf(s.shortValue()); - } + @OnMessage + public String echo(Short s) { + return String.valueOf(s.shortValue()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndPathParamServer.java index 1753098868..28222f4715 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndPathParamServer.java @@ -31,19 +31,18 @@ @ServerEndpoint("/inputstreampathparam/{param}") public class WSInputStreamAndPathParamServer { - @OnMessage - public String echo(@PathParam("param") String param, InputStream stream) - throws IOException { - String message = IOUtil.readFromStream(stream) + param; - return message; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("param") String param, InputStream stream) throws IOException { + String message = IOUtil.readFromStream(stream) + param; + return message; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndSessionAndPathParamServer.java index d3105de102..50cb758287 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndSessionAndPathParamServer.java @@ -31,20 +31,19 @@ @ServerEndpoint("/inputstreamsessionpathparam/{param}") public class WSInputStreamAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Session s, @PathParam("param") String param, - InputStream stream) throws IOException { - String message = IOUtil.readFromStream(stream) + param; - return message; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Session s, @PathParam("param") String param, InputStream stream) throws IOException { + String message = IOUtil.readFromStream(stream) + param; + return message; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndSessionServer.java index d384c9dd44..bc2d5a4891 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamAndSessionServer.java @@ -30,19 +30,19 @@ @ServerEndpoint("/inputstreamsession") public class WSInputStreamAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(InputStream stream, Session s) throws IOException { - String message = IOUtil.readFromStream(stream); - return message; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(InputStream stream, Session s) throws IOException { + String message = IOUtil.readFromStream(stream); + return message; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamServer.java index b6a4790bd1..8e38df8ee8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSInputStreamServer.java @@ -30,18 +30,18 @@ @ServerEndpoint("/inputstream") public class WSInputStreamServer { - @OnMessage - public String echo(InputStream stream) throws IOException { - String message = IOUtil.readFromStream(stream); - return message; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(InputStream stream) throws IOException { + String message = IOUtil.readFromStream(stream); + return message; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSMaxLengthServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSMaxLengthServer.java index 029f7c4ac6..369f378f48 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSMaxLengthServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSMaxLengthServer.java @@ -28,17 +28,17 @@ @ServerEndpoint("/maxlen") public class WSMaxLengthServer { - public static final String MSG = "maxMessageSize cased an exception as expected"; - - @OnMessage(maxMessageSize = 5L) - public String echo(String echo) { - return echo; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - String message = MSG + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + public static final String MSG = "maxMessageSize cased an exception as expected"; + + @OnMessage(maxMessageSize = 5L) + public String echo(String echo) { + return echo; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + String message = MSG + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndPathParamServer.java index ab933dad06..908ce0be41 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndPathParamServer.java @@ -31,16 +31,16 @@ @ServerEndpoint("/pongmessagepathparam/{param}") public class WSPongMessageAndPathParamServer { - @OnMessage - public String echo(PongMessage msg, @PathParam("param") String param) { - return IOUtil.byteBufferToString(msg.getApplicationData()) + param; - } + @OnMessage + public String echo(PongMessage msg, @PathParam("param") String param) { + return IOUtil.byteBufferToString(msg.getApplicationData()) + param; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndSessionAndPathParamServer.java index dbebc83b87..5aa08bf1d7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndSessionAndPathParamServer.java @@ -31,18 +31,17 @@ @ServerEndpoint("/pongmessagesessionpathparam/{param}") public class WSPongMessageAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(PongMessage msg, @PathParam("param") String param, - Session s) { - return IOUtil.byteBufferToString(msg.getApplicationData()) + param; - } + @SuppressWarnings("unused") + @OnMessage + public String echo(PongMessage msg, @PathParam("param") String param, Session s) { + return IOUtil.byteBufferToString(msg.getApplicationData()) + param; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndSessionServer.java index 59260ede55..0d3894fd4c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageAndSessionServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/pongmessagesession") public class WSPongMessageAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(PongMessage msg, Session s) { - return IOUtil.byteBufferToString(msg.getApplicationData()); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(PongMessage msg, Session s) { + return IOUtil.byteBufferToString(msg.getApplicationData()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageServer.java index 87f53d27bc..105982da66 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPongMessageServer.java @@ -30,16 +30,16 @@ @ServerEndpoint("/pongmessage") public class WSPongMessageServer { - @OnMessage - public String echo(PongMessage msg) { - return IOUtil.byteBufferToString(msg.getApplicationData()); - } + @OnMessage + public String echo(PongMessage msg) { + return IOUtil.byteBufferToString(msg.getApplicationData()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndPathParamServer.java index a06591df95..e89d6241aa 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndPathParamServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/primitivebooleanpathparam/{param}") public class WSPrimitiveBooleanAndPathParamServer { - @OnMessage - public String echo(boolean b, @PathParam("param") boolean param) { - return String.valueOf(b) + String.valueOf(param); - } + @OnMessage + public String echo(boolean b, @PathParam("param") boolean param) { + return String.valueOf(b) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndSessionAndPathParamServer.java index 871566f092..e5b1cf8b4f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndSessionAndPathParamServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/primitivebooleansessionpathparam/{param}") public class WSPrimitiveBooleanAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(boolean b, Session s, @PathParam("param") boolean param) { - return String.valueOf(b) + String.valueOf(param); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(boolean b, Session s, @PathParam("param") boolean param) { + return String.valueOf(b) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndSessionServer.java index e429d6fa46..af8f4e76a3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanAndSessionServer.java @@ -28,17 +28,17 @@ @ServerEndpoint("/primitivebooleansession") public class WSPrimitiveBooleanAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(boolean b, Session s) { - return String.valueOf(b); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(boolean b, Session s) { + return String.valueOf(b); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanServer.java index ee72955fbb..0fdb76f02e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveBooleanServer.java @@ -28,16 +28,16 @@ @ServerEndpoint("/primitiveboolean") public class WSPrimitiveBooleanServer { - @OnMessage - public String echo(boolean b) { - return String.valueOf(b); - } + @OnMessage + public String echo(boolean b) { + return String.valueOf(b); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndPathParamServer.java index cb99334328..a8a922768d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndPathParamServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/primitivebytepathparam/{param}") public class WSPrimitiveByteAndPathParamServer { - @OnMessage - public String echo(byte b, @PathParam("param") byte param) { - return String.valueOf(b) + String.valueOf(param); - } + @OnMessage + public String echo(byte b, @PathParam("param") byte param) { + return String.valueOf(b) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndSessionAndPathParamServer.java index ab58808c12..b84b6e1475 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndSessionAndPathParamServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/primitivebytesessionpathparam/{param}") public class WSPrimitiveByteAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Session s, @PathParam("param") byte param, byte b) { - return String.valueOf(b) + String.valueOf(param); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Session s, @PathParam("param") byte param, byte b) { + return String.valueOf(b) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndSessionServer.java index 4212aa3e75..b88a621c2c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteAndSessionServer.java @@ -28,17 +28,17 @@ @ServerEndpoint("/primitivebytesession") public class WSPrimitiveByteAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(byte b, Session s) { - return String.valueOf(b); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(byte b, Session s) { + return String.valueOf(b); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteServer.java index 039801ebb3..7a7f7bc5bf 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveByteServer.java @@ -28,16 +28,16 @@ @ServerEndpoint("/primitivebyte") public class WSPrimitiveByteServer { - @OnMessage - public String echo(byte b) { - return String.valueOf(b); - } + @OnMessage + public String echo(byte b) { + return String.valueOf(b); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndPatahParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndPatahParamServer.java index f8dcb90170..94537d407f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndPatahParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndPatahParamServer.java @@ -30,16 +30,16 @@ @ServerEndpoint("/primitivecharpathparam/{param}") public class WSPrimitiveCharAndPatahParamServer { - @OnMessage - public String echo(@PathParam("param") char param, char c) { - return String.valueOf(c) + String.valueOf(param); - } + @OnMessage + public String echo(@PathParam("param") char param, char c) { + return String.valueOf(c) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndSessionAndPathParamServer.java index 5db4b84714..abf0288f49 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndSessionAndPathParamServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/primitivecharsessionpathparam/{param}") public class WSPrimitiveCharAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(char c, @PathParam("param") char param, Session s) { - return String.valueOf(c) + String.valueOf(param); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(char c, @PathParam("param") char param, Session s) { + return String.valueOf(c) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndSessionServer.java index 42c100687e..64f883c830 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharAndSessionServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/primitivecharsession") public class WSPrimitiveCharAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(char c, Session s) { - return String.valueOf(c) + "char"; - } + @SuppressWarnings("unused") + @OnMessage + public String echo(char c, Session s) { + return String.valueOf(c) + "char"; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharServer.java index bc4f21e92f..2f848561f5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveCharServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/primitivechar") public class WSPrimitiveCharServer { - @OnMessage - public String echo(char c) { - return String.valueOf(c) + "char"; - } + @OnMessage + public String echo(char c) { + return String.valueOf(c) + "char"; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndPathParamServer.java index 3e5af195f6..92fd15f3d2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndPathParamServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/primitivedoublepathparam/{param}") public class WSPrimitiveDoubleAndPathParamServer { - @OnMessage - public String echo(double d, @PathParam("param") double param) { - return (String.valueOf(d) + String.valueOf(param)).replace(".0", ""); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(double d, @PathParam("param") double param) { + return (String.valueOf(d) + String.valueOf(param)).replace(".0", ""); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndSessionAndPathParamServer.java index 506f4cb60e..0270304e81 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndSessionAndPathParamServer.java @@ -30,18 +30,18 @@ @ServerEndpoint("/primitivedoublesessionpathparam/{param}") public class WSPrimitiveDoubleAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(@PathParam("param") double param, double d, Session s) { - return (String.valueOf(d) + String.valueOf(param)).replace(".0", ""); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(@PathParam("param") double param, double d, Session s) { + return (String.valueOf(d) + String.valueOf(param)).replace(".0", ""); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndSessionServer.java index d14d2e2585..a35dd5637e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleAndSessionServer.java @@ -29,18 +29,18 @@ @ServerEndpoint("/primitivedoublesession") public class WSPrimitiveDoubleAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(double d, Session s) { - return String.valueOf(d); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(double d, Session s) { + return String.valueOf(d); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleServer.java index 1ccb54dd80..644b1cd023 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveDoubleServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/primitivedouble") public class WSPrimitiveDoubleServer { - @OnMessage - public String echo(double d) { - return String.valueOf(d); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(double d) { + return String.valueOf(d); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndPathParamServer.java index 72f970a063..7011825008 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndPathParamServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/primitivefloatpathparam/{param}") public class WSPrimitiveFloatAndPathParamServer { - @OnMessage - public String echo(float f, @PathParam("param") float param) { - return (String.valueOf(f) + String.valueOf(param)).replace(".0", ""); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(float f, @PathParam("param") float param) { + return (String.valueOf(f) + String.valueOf(param)).replace(".0", ""); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndSessionAndPathParamServer.java index 89bdefd8c5..ec98da2532 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndSessionAndPathParamServer.java @@ -30,18 +30,18 @@ @ServerEndpoint("/primitivefloatsessionpathparam/{param}") public class WSPrimitiveFloatAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(float f, Session s, @PathParam("param") float param) { - return (String.valueOf(f) + String.valueOf(param)).replace(".0", ""); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(float f, Session s, @PathParam("param") float param) { + return (String.valueOf(f) + String.valueOf(param)).replace(".0", ""); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndSessionServer.java index 65acb4643e..d54c510254 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatAndSessionServer.java @@ -29,18 +29,18 @@ @ServerEndpoint("/primitivefloatsession") public class WSPrimitiveFloatAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(float f, Session s) { - return String.valueOf(f); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(float f, Session s) { + return String.valueOf(f); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatServer.java index 52f6edbf6b..33ac09d364 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveFloatServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/primitivefloat") public class WSPrimitiveFloatServer { - @OnMessage - public String echo(float f) { - return String.valueOf(f); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(float f) { + return String.valueOf(f); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndPathParamServer.java index b9af427450..263c6ec943 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndPathParamServer.java @@ -30,16 +30,16 @@ @ServerEndpoint("/primitiveintpathparam/{param}") public class WSPrimitiveIntAndPathParamServer { - @OnMessage - public String echoInt(int i, @PathParam("param") int param) { - return String.valueOf(i) + String.valueOf(param); - } + @OnMessage + public String echoInt(int i, @PathParam("param") int param) { + return String.valueOf(i) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndSessionAndPathParamServer.java index 160d469f6c..404d40e3da 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndSessionAndPathParamServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/primitiveintsessionpathparam/{param}") public class WSPrimitiveIntAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echoInt(int i, Session s, @PathParam("param") int param) { - return String.valueOf(i) + String.valueOf(param); - } + @SuppressWarnings("unused") + @OnMessage + public String echoInt(int i, Session s, @PathParam("param") int param) { + return String.valueOf(i) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndSessionServer.java index 55e7901ec8..a0529f899b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntAndSessionServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/primitiveintsession") public class WSPrimitiveIntAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echoInt(int i, Session s) { - return String.valueOf(i); - } + @SuppressWarnings("unused") + @OnMessage + public String echoInt(int i, Session s) { + return String.valueOf(i); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntServer.java index 1460a7d989..8d710687da 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveIntServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/primitiveint") public class WSPrimitiveIntServer { - @OnMessage - public String echoInt(int i) { - return String.valueOf(i); - } + @OnMessage + public String echoInt(int i) { + return String.valueOf(i); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndPathParamServer.java index e22f9e171b..e673c9d0d9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndPathParamServer.java @@ -30,16 +30,16 @@ @ServerEndpoint("/primitivelongpathparam/{param}") public class WSPrimitiveLongAndPathParamServer { - @OnMessage - public String echo(long l, @PathParam("param") long param) { - return String.valueOf(l) + String.valueOf(param); - } + @OnMessage + public String echo(long l, @PathParam("param") long param) { + return String.valueOf(l) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndSessionAndPathParamServer.java index ecf3f72993..e9745b190a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndSessionAndPathParamServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/primitivelongsessionpathparam/{param}") public class WSPrimitiveLongAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Session s, @PathParam("param") long param, long l) { - return String.valueOf(l) + String.valueOf(param); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Session s, @PathParam("param") long param, long l) { + return String.valueOf(l) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndSessionServer.java index d857b9a049..9c21318c93 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongAndSessionServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/primitivelongsession") public class WSPrimitiveLongAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Session s, long l) { - return String.valueOf(l); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Session s, long l) { + return String.valueOf(l); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongServer.java index c00930160a..429842aae5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveLongServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/primitivelong") public class WSPrimitiveLongServer { - @OnMessage - public String echo(long l) { - return String.valueOf(l); - } + @OnMessage + public String echo(long l) { + return String.valueOf(l); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndPathParamServer.java index cd6b4825dd..7c24812ccc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndPathParamServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/primitiveshortpathparam/{param}") public class WSPrimitiveShortAndPathParamServer { - @OnMessage - public String echo(short s, @PathParam("param") short param) { - return String.valueOf(s) + String.valueOf(param); - } + @OnMessage + public String echo(short s, @PathParam("param") short param) { + return String.valueOf(s) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndSessionAndPathParamServer.java index 2ba1c5b5be..a4a11015fb 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndSessionAndPathParamServer.java @@ -29,18 +29,17 @@ @ServerEndpoint("/primitiveshortsessionpathparam/{param}") public class WSPrimitiveShortAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(short s, @PathParam("param") short param, - Session session) { - return String.valueOf(s) + String.valueOf(param); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(short s, @PathParam("param") short param, Session session) { + return String.valueOf(s) + String.valueOf(param); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndSessionServer.java index cddfe2f9c2..335f083439 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortAndSessionServer.java @@ -28,17 +28,17 @@ @ServerEndpoint("/primitiveshortsession") public class WSPrimitiveShortAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(short s, Session session) { - return String.valueOf(s); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(short s, Session session) { + return String.valueOf(s); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortServer.java index 41025d563f..2bd411b7f1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSPrimitiveShortServer.java @@ -28,16 +28,16 @@ @ServerEndpoint("/primitiveshort") public class WSPrimitiveShortServer { - @OnMessage - public String echo(short s) { - return String.valueOf(s); - } + @OnMessage + public String echo(short s) { + return String.valueOf(s); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndPathParamServer.java index dfafd8bec0..09472675b2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndPathParamServer.java @@ -30,18 +30,17 @@ @ServerEndpoint("/readerpathparam/{param}") public class WSReaderAndPathParamServer { - @OnMessage - public String reader(java.io.Reader r, @PathParam("param") String param) - throws IOException { - String msg = IOUtil.readFromReader(r) + param; - return msg; - } + @OnMessage + public String reader(java.io.Reader r, @PathParam("param") String param) throws IOException { + String msg = IOUtil.readFromReader(r) + param; + return msg; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndSessionAndPathParamServer.java index 7391d7876b..5f9d708645 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndSessionAndPathParamServer.java @@ -30,19 +30,18 @@ @ServerEndpoint("/readersessionpathparam/{param}") public class WSReaderAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String reader(java.io.Reader r, @PathParam("param") String param, - Session s) throws IOException { - String msg = IOUtil.readFromReader(r) + param; - return msg; - } + @SuppressWarnings("unused") + @OnMessage + public String reader(java.io.Reader r, @PathParam("param") String param, Session s) throws IOException { + String msg = IOUtil.readFromReader(r) + param; + return msg; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndSessionServer.java index 52acaad593..9b19b6923e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderAndSessionServer.java @@ -29,18 +29,18 @@ @ServerEndpoint("/readersession") public class WSReaderAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String reader(java.io.Reader r, Session s) throws IOException { - String msg = IOUtil.readFromReader(r); - return msg; - } + @SuppressWarnings("unused") + @OnMessage + public String reader(java.io.Reader r, Session s) throws IOException { + String msg = IOUtil.readFromReader(r); + return msg; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderServer.java index 94a7832b90..009f1fdf68 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSReaderServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/reader") public class WSReaderServer { - @OnMessage - public String reader(java.io.Reader r) throws IOException { - String msg = IOUtil.readFromReader(r); - return msg; - } + @OnMessage + public String reader(java.io.Reader r) throws IOException { + String msg = IOUtil.readFromReader(r); + return msg; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndPathParamServer.java index c3e75ca50a..a2c47fccce 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndPathParamServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/stringpathparam/{param}") public class WSStringAndPathParamServer { - @OnMessage - public String echo(String echo, @PathParam("param") String param) { - return echo + param; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo, @PathParam("param") String param) { + return echo + param; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndSessionAndPathParamServer.java index 5ca23b0fee..b4c709a06f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndSessionAndPathParamServer.java @@ -30,18 +30,18 @@ @ServerEndpoint("/stringsessionpathparam/{param}") public class WSStringAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(@PathParam("param") String param, String echo, Session s) { - return echo + param; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(@PathParam("param") String param, String echo, Session s) { + return echo + param; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndSessionServer.java index 83d801a963..69a349e955 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringAndSessionServer.java @@ -29,18 +29,18 @@ @ServerEndpoint("/stringsession") public class WSStringAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(String echo, Session s) { - return echo; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(String echo, Session s) { + return echo; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndPathParamServer.java index 93b1444202..7a9894f0b6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndPathParamServer.java @@ -30,17 +30,16 @@ @ServerEndpoint("/partialstringpathparam/{param}") public class WSStringPartialAndPathParamServer { - @OnMessage - public String partial(String msg, @PathParam("param") String param, - boolean finito) { - return msg + "(" + finito + ")" + param; - } + @OnMessage + public String partial(String msg, @PathParam("param") String param, boolean finito) { + return msg + "(" + finito + ")" + param; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndSessionAndPathParamServer.java index d96d6a8a81..0f8bd3881f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndSessionAndPathParamServer.java @@ -30,26 +30,25 @@ @ServerEndpoint("/partialstringsessionpathparam/{param}") public class WSStringPartialAndSessionAndPathParamServer { - /** - * Buffer the messages until they are all received - */ - StringBuilder sb = new StringBuilder(); - - @OnMessage - public void partial(String msg, boolean finito, Session s, - @PathParam("param") String param) throws IOException { - sb.append(msg).append("(").append(finito).append(")").append(param); - if (finito) { - s.getBasicRemote().sendText(sb.toString()); - sb = new StringBuilder(); - } - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + /** + * Buffer the messages until they are all received + */ + StringBuilder sb = new StringBuilder(); + + @OnMessage + public void partial(String msg, boolean finito, Session s, @PathParam("param") String param) throws IOException { + sb.append(msg).append("(").append(finito).append(")").append(param); + if (finito) { + s.getBasicRemote().sendText(sb.toString()); + sb = new StringBuilder(); + } + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndSessionServer.java index c3109a8c5d..64ab00d1e9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialAndSessionServer.java @@ -29,26 +29,25 @@ @ServerEndpoint("/partialstringsession") public class WSStringPartialAndSessionServer { - /** - * Buffer the messages until they are all received - */ - StringBuilder sb = new StringBuilder(); - - @OnMessage - public void partial(String msg, boolean finito, Session s) - throws IOException { - sb.append(msg).append("(").append(finito).append(")"); - if (finito) { - s.getBasicRemote().sendText(sb.toString()); - sb = new StringBuilder(); - } - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + /** + * Buffer the messages until they are all received + */ + StringBuilder sb = new StringBuilder(); + + @OnMessage + public void partial(String msg, boolean finito, Session s) throws IOException { + sb.append(msg).append("(").append(finito).append(")"); + if (finito) { + s.getBasicRemote().sendText(sb.toString()); + sb = new StringBuilder(); + } + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialServer.java index 72782499a0..b222aaa16a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringPartialServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/partialstring") public class WSStringPartialServer { - @OnMessage - public String partial(String msg, boolean finito) { - return msg + "(" + finito + ")"; - } + @OnMessage + public String partial(String msg, boolean finito) { + return msg + "(" + finito + ")"; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringServer.java index 6e1bb01755..7b445927be 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSStringServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/string") public class WSStringServer { - @OnMessage - public String echo(String echo) { - return echo; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo) { + return echo; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndPathParamServer.java index 7a347771af..a197c9addc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndPathParamServer.java @@ -29,20 +29,19 @@ import jakarta.websocket.server.PathParam; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textdecoderpathparam/{param}", decoders = { - StringBeanTextDecoder.class }) +@ServerEndpoint(value = "/textdecoderpathparam/{param}", decoders = { StringBeanTextDecoder.class }) public class WSTextDecoderAndPathParamServer { - @OnMessage - public String echo(@PathParam("param") String param, StringBean bean) { - return bean.get() + param; - } + @OnMessage + public String echo(@PathParam("param") String param, StringBean bean) { + return bean.get() + param; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndSessionAndPathParamServer.java index b69617e426..953da02e1f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndSessionAndPathParamServer.java @@ -29,22 +29,20 @@ import jakarta.websocket.server.PathParam; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textdecodersessionpathparam/{param}", decoders = { - StringBeanTextDecoder.class }) +@ServerEndpoint(value = "/textdecodersessionpathparam/{param}", decoders = { StringBeanTextDecoder.class }) public class WSTextDecoderAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(@PathParam("param") String param, StringBean bean, - Session s) { - return bean.get() + param; - } + @SuppressWarnings("unused") + @OnMessage + public String echo(@PathParam("param") String param, StringBean bean, Session s) { + return bean.get() + param; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndSessionServer.java index 13288e0bad..9c7311c942 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderAndSessionServer.java @@ -28,21 +28,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textdecodersession", decoders = { - StringBeanTextDecoder.class }) +@ServerEndpoint(value = "/textdecodersession", decoders = { StringBeanTextDecoder.class }) public class WSTextDecoderAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(StringBean bean, Session s) { - return bean.get(); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(StringBean bean, Session s) { + return bean.get(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderServer.java index 9e43b32505..371dd7384c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextDecoderServer.java @@ -28,20 +28,19 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textdecoder", decoders = { - StringBeanTextDecoder.class }) +@ServerEndpoint(value = "/textdecoder", decoders = { StringBeanTextDecoder.class }) public class WSTextDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndPathParamServer.java index 63f89e5f40..b7bf34d229 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndPathParamServer.java @@ -29,21 +29,20 @@ import jakarta.websocket.server.PathParam; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstreamdecoderpathparam/{param}", decoders = { - StringBeanTextStreamDecoder.class }) +@ServerEndpoint(value = "/textstreamdecoderpathparam/{param}", decoders = { StringBeanTextStreamDecoder.class }) public class WSTextStreamDecoderAndPathParamServer { - @OnMessage - public String echo(StringBean bean, @PathParam("param") String param) { - return bean.get() + param; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(StringBean bean, @PathParam("param") String param) { + return bean.get() + param; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndSessionAndPathParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndSessionAndPathParamServer.java index 4d5c850685..7f55e2e87a 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndSessionAndPathParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndSessionAndPathParamServer.java @@ -29,23 +29,21 @@ import jakarta.websocket.server.PathParam; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstreamdecodersessionpathparam/{param}", decoders = { - StringBeanTextStreamDecoder.class }) +@ServerEndpoint(value = "/textstreamdecodersessionpathparam/{param}", decoders = { StringBeanTextStreamDecoder.class }) public class WSTextStreamDecoderAndSessionAndPathParamServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Session s, StringBean bean, - @PathParam("param") String param) { - return bean.get() + param; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Session s, StringBean bean, @PathParam("param") String param) { + return bean.get() + param; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndSessionServer.java index 98885484d6..0097ca67fb 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderAndSessionServer.java @@ -28,22 +28,21 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstreamdecodersession", decoders = { - StringBeanTextStreamDecoder.class }) +@ServerEndpoint(value = "/textstreamdecodersession", decoders = { StringBeanTextStreamDecoder.class }) public class WSTextStreamDecoderAndSessionServer { - @SuppressWarnings("unused") - @OnMessage - public String echo(Session s, StringBean bean) { - return bean.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Session s, StringBean bean) { + return bean.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderServer.java index b0438959f6..8c2b612373 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessage/WSTextStreamDecoderServer.java @@ -28,21 +28,20 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstreamdecoder", decoders = { - StringBeanTextStreamDecoder.class }) +@ServerEndpoint(value = "/textstreamdecoder", decoders = { StringBeanTextStreamDecoder.class }) public class WSTextStreamDecoderServer { - @OnMessage - public String echo(StringBean bean) { - return bean.get(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(StringBean bean) { + return bean.get(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSBinaryEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSBinaryEncoderServer.java index 03b39ecd17..8ecdb9dd01 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSBinaryEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSBinaryEncoderServer.java @@ -28,20 +28,19 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binaryencoder", encoders = { - StringBeanBinaryEncoder.class }) +@ServerEndpoint(value = "/binaryencoder", encoders = { StringBeanBinaryEncoder.class }) public class WSBinaryEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSBinaryStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSBinaryStreamEncoderServer.java index f3ad99ea9c..d59b66e88d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSBinaryStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSBinaryStreamEncoderServer.java @@ -28,19 +28,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/binarystreamencoder", encoders = { - StringBeanBinaryStreamEncoder.class }) +@ServerEndpoint(value = "/binarystreamencoder", encoders = { StringBeanBinaryStreamEncoder.class }) public class WSBinaryStreamEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSByteArrayServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSByteArrayServer.java index 12d2405269..ce3ac0f273 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSByteArrayServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSByteArrayServer.java @@ -29,15 +29,15 @@ @ServerEndpoint(value = "/bytearray") public class WSByteArrayServer { - @OnMessage - public byte[] bytesToString(String data) { - return data.getBytes(); - } + @OnMessage + public byte[] bytesToString(String data) { + return data.getBytes(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSByteBufferServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSByteBufferServer.java index 19a98e0bfd..7d19e9bb52 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSByteBufferServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSByteBufferServer.java @@ -29,15 +29,15 @@ @ServerEndpoint("/bytebuffer") public class WSByteBufferServer { - @OnMessage - public ByteBuffer echo(String data) { - return ByteBuffer.wrap(data.getBytes()); - } + @OnMessage + public ByteBuffer echo(String data) { + return ByteBuffer.wrap(data.getBytes()); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSClient.java deleted file mode 100644 index a7c9241a39..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSClient.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.websocketmessagereturntype; - -import com.sun.ts.tests.websocket.common.client.ByteBufferClientEndpoint; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = -5623230069104999740L; - - public WSClient() { - setContextRoot("ws_ee_websocketmessagereturntype_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - // TEXT ------------------------------------------ - - /* - * @testName: dataTypesTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; - * WebSocket:JAVADOC:80; - * - * @test_Strategy: test primitive and boxed datatypes - */ - public void dataTypesTest() throws Exception { - invokeDataTypeSequence("true", "boolean"); - invokeDataTypeSequence("123", "byte"); - invokeDataTypeSequence(String.valueOf(Short.MAX_VALUE), "short"); - invokeDataTypeSequence(String.valueOf(Short.MIN_VALUE), "int"); - invokeDataTypeSequence(String.valueOf(Short.MIN_VALUE), "long"); - invokeDataTypeSequence(String.valueOf(123.456f), "float"); - invokeDataTypeSequence(String.valueOf(789.012), "double"); - invokeDataTypeSequence(String.valueOf('A'), "char"); - } - - /* - * @testName: textEncoderTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test text encoder - */ - public void textEncoderTest() throws Exception { - invokeSequence("textEncoderTest", "textencoder"); - } - - /* - * @testName: textStreamEncoderTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test text stream encoder - */ - public void textStreamEncoderTest() throws Exception { - invokeSequence("textStreamEncoderTest", "textstreamencoder"); - } - - // -----------------Binary -------------------------------- - - /* - * @testName: binaryEncoderTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test binary encoder - */ - public void binaryEncoderTest() throws Exception { - setClientEndpoint(ByteBufferClientEndpoint.class); - invokeSequence("binaryEncoderTest", "binaryencoder"); - } - - /* - * @testName: binaryStreamEncoderTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test binary stream encoder - */ - public void binaryStreamEncoderTest() throws Exception { - setClientEndpoint(ByteBufferClientEndpoint.class); - invokeSequence("binaryStreamEncoderTest", "binarystreamencoder"); - } - - /* - * @testName: byteArrayTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test byte array - */ - public void byteArrayTest() throws Exception { - setClientEndpoint(ByteBufferClientEndpoint.class); - invokeSequence("byteArrayTest", "bytearray"); - } - - /* - * @testName: byteBufferTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test byte buffer - */ - public void byteBufferTest() throws Exception { - setClientEndpoint(ByteBufferClientEndpoint.class); - invokeSequence("byteBufferTest", "bytebuffer"); - } - - /* - * @testName: directByteBufferTest - * - * @assertion_ids: WebSocket:JAVADOC:80; - * - * @test_Strategy: test direct byte buffer - */ - public void directByteBufferTest() throws Exception { - setClientEndpoint(ByteBufferClientEndpoint.class); - invokeSequence("byteBufferTest", "directbytebuffer"); - } - - // Private ----------------------------------------- - private void invokeSequence(String search, String... sequence) throws Exception { - for (int i = 0; i != sequence.length; i++) { - setProperty(Property.REQUEST, buildRequest(sequence[i])); - setProperty(Property.SEARCH_STRING, search); - setProperty(Property.CONTENT, search); - invoke(); - } - } - - private void invokeDataTypeSequence(String search, String type) throws Exception { - String[] sequence = { "primitive" + type, "full" + type }; - invokeSequence(search, sequence); - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSClientIT.java new file mode 100644 index 0000000000..cea0ee3555 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSClientIT.java @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.ee.jakarta.websocket.websocketmessagereturntype; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.ByteBufferClientEndpoint; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = -5623230069104999740L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_ee_websocketmessagereturntype_web.war"); + archive.addPackages(true, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.ee.jakarta.websocket.websocketmessagereturntype"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("ws_ee_websocketmessagereturntype_web"); + } + + /* Run test */ + + // TEXT ------------------------------------------ + + /* + * @testName: dataTypesTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.7-2; WebSocket:SPEC:WSC-4.7-3; + * WebSocket:JAVADOC:80; + * + * @test_Strategy: test primitive and boxed datatypes + */ + @Test + public void dataTypesTest() throws Exception { + invokeDataTypeSequence("true", "boolean"); + invokeDataTypeSequence("123", "byte"); + invokeDataTypeSequence(String.valueOf(Short.MAX_VALUE), "short"); + invokeDataTypeSequence(String.valueOf(Short.MIN_VALUE), "int"); + invokeDataTypeSequence(String.valueOf(Short.MIN_VALUE), "long"); + invokeDataTypeSequence(String.valueOf(123.456f), "float"); + invokeDataTypeSequence(String.valueOf(789.012), "double"); + invokeDataTypeSequence(String.valueOf('A'), "char"); + } + + /* + * @testName: textEncoderTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test text encoder + */ + @Test + public void textEncoderTest() throws Exception { + invokeSequence("textEncoderTest", "textencoder"); + } + + /* + * @testName: textStreamEncoderTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test text stream encoder + */ + @Test + public void textStreamEncoderTest() throws Exception { + invokeSequence("textStreamEncoderTest", "textstreamencoder"); + } + + // -----------------Binary -------------------------------- + + /* + * @testName: binaryEncoderTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test binary encoder + */ + @Test + public void binaryEncoderTest() throws Exception { + setClientEndpoint(ByteBufferClientEndpoint.class); + invokeSequence("binaryEncoderTest", "binaryencoder"); + } + + /* + * @testName: binaryStreamEncoderTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test binary stream encoder + */ + @Test + public void binaryStreamEncoderTest() throws Exception { + setClientEndpoint(ByteBufferClientEndpoint.class); + invokeSequence("binaryStreamEncoderTest", "binarystreamencoder"); + } + + /* + * @testName: byteArrayTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test byte array + */ + @Test + public void byteArrayTest() throws Exception { + setClientEndpoint(ByteBufferClientEndpoint.class); + invokeSequence("byteArrayTest", "bytearray"); + } + + /* + * @testName: byteBufferTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test byte buffer + */ + @Test + public void byteBufferTest() throws Exception { + setClientEndpoint(ByteBufferClientEndpoint.class); + invokeSequence("byteBufferTest", "bytebuffer"); + } + + /* + * @testName: directByteBufferTest + * + * @assertion_ids: WebSocket:JAVADOC:80; + * + * @test_Strategy: test direct byte buffer + */ + @Test + public void directByteBufferTest() throws Exception { + setClientEndpoint(ByteBufferClientEndpoint.class); + invokeSequence("byteBufferTest", "directbytebuffer"); + } + + // Private ----------------------------------------- + private void invokeSequence(String search, String... sequence) throws Exception { + for (int i = 0; i != sequence.length; i++) { + setProperty(Property.REQUEST, buildRequest(sequence[i])); + setProperty(Property.SEARCH_STRING, search); + setProperty(Property.CONTENT, search); + invoke(); + } + } + + private void invokeDataTypeSequence(String search, String type) throws Exception { + String[] sequence = { "primitive" + type, "full" + type }; + invokeSequence(search, sequence); + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSDirectByteBufferServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSDirectByteBufferServer.java index 8d60f940e6..789e0b1569 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSDirectByteBufferServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSDirectByteBufferServer.java @@ -35,36 +35,35 @@ @ServerEndpoint("/directbytebuffer") public class WSDirectByteBufferServer { - private File f; + private File f; - @OnClose - public void onClose() { - f.delete(); - } + @OnClose + public void onClose() { + f.delete(); + } - private static File createTempFile(String data) throws IOException { - File f = File.createTempFile("tcktemp", "file"); - FileOutputStream fos = new FileOutputStream(f); - fos.write(data.getBytes()); - fos.close(); - return f; - } + private static File createTempFile(String data) throws IOException { + File f = File.createTempFile("tcktemp", "file"); + FileOutputStream fos = new FileOutputStream(f); + fos.write(data.getBytes()); + fos.close(); + return f; + } - @OnMessage - public ByteBuffer echo(String data) throws IOException { - f = createTempFile(data); + @OnMessage + public ByteBuffer echo(String data) throws IOException { + f = createTempFile(data); - FileInputStream fis = new FileInputStream(f); - MappedByteBuffer mbb = fis.getChannel().map(MapMode.READ_ONLY, 0, - data.length()); - fis.close(); - return mbb; - } + FileInputStream fis = new FileInputStream(f); + MappedByteBuffer mbb = fis.getChannel().map(MapMode.READ_ONLY, 0, data.length()); + fis.close(); + return mbb; + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullBooleanServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullBooleanServer.java index 369b3b483e..0a6d7bbebc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullBooleanServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullBooleanServer.java @@ -29,15 +29,15 @@ @ServerEndpoint("/fullboolean") public class WSFullBooleanServer { - @OnMessage - public Boolean echo(String data) { - return Boolean.valueOf(data); - } + @OnMessage + public Boolean echo(String data) { + return Boolean.valueOf(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullByteServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullByteServer.java index c27418077e..6ad94fde01 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullByteServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullByteServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/fullbyte") public class WSFullByteServer { - @OnMessage - public Byte echo(String data) { - return Byte.valueOf(data); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public Byte echo(String data) { + return Byte.valueOf(data); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullCharServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullCharServer.java index 7eded49e4b..3b5c97d1bf 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullCharServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullCharServer.java @@ -29,15 +29,15 @@ @ServerEndpoint("/fullchar") public class WSFullCharServer { - @OnMessage - public Character echo(String data) { - return Character.valueOf(data.charAt(0)); - } + @OnMessage + public Character echo(String data) { + return Character.valueOf(data.charAt(0)); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullDoubleServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullDoubleServer.java index 467ea1b389..6b10c4ff1f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullDoubleServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullDoubleServer.java @@ -28,15 +28,15 @@ @ServerEndpoint("/fulldouble") public class WSFullDoubleServer { - @OnMessage - public Double echo(String data) { - return Double.valueOf(data); - } + @OnMessage + public Double echo(String data) { + return Double.valueOf(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullFloatServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullFloatServer.java index 3e7fcf7bc1..4816e8cc98 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullFloatServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullFloatServer.java @@ -28,15 +28,15 @@ @ServerEndpoint("/fullfloat") public class WSFullFloatServer { - @OnMessage - public Float echo(String data) { - return Float.valueOf(data); - } + @OnMessage + public Float echo(String data) { + return Float.valueOf(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullIntServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullIntServer.java index 735b7859e2..8946c5ecd2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullIntServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullIntServer.java @@ -28,15 +28,15 @@ @ServerEndpoint("/fullint") public class WSFullIntServer { - @OnMessage - public Integer echo(String data) { - return Integer.valueOf(data); - } + @OnMessage + public Integer echo(String data) { + return Integer.valueOf(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullLongServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullLongServer.java index ff9b6953ec..f0813d407f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullLongServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullLongServer.java @@ -29,15 +29,15 @@ @ServerEndpoint("/fulllong") public class WSFullLongServer { - @OnMessage - public Long echo(String data) { - return Long.valueOf(data); - } + @OnMessage + public Long echo(String data) { + return Long.valueOf(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullShortServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullShortServer.java index f853b04d91..38b3f2744c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullShortServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSFullShortServer.java @@ -29,15 +29,15 @@ @ServerEndpoint("/fullshort") public class WSFullShortServer { - @OnMessage - public Short echo(String data) { - return Short.valueOf(data); - } + @OnMessage + public Short echo(String data) { + return Short.valueOf(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveBooleanServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveBooleanServer.java index 3386f80f42..2d5285049b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveBooleanServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveBooleanServer.java @@ -28,15 +28,15 @@ @ServerEndpoint("/primitiveboolean") public class WSPrimitiveBooleanServer { - @OnMessage - public boolean echo(String data) { - return Boolean.parseBoolean(data); - } + @OnMessage + public boolean echo(String data) { + return Boolean.parseBoolean(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveByteServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveByteServer.java index 71e02644a6..df1ba090d1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveByteServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveByteServer.java @@ -28,15 +28,15 @@ @ServerEndpoint("/primitivebyte") public class WSPrimitiveByteServer { - @OnMessage - public byte echo(String data) { - return Byte.parseByte(data); - } + @OnMessage + public byte echo(String data) { + return Byte.parseByte(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveCharServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveCharServer.java index 338b019d60..faf3ea035f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveCharServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveCharServer.java @@ -29,15 +29,15 @@ @ServerEndpoint("/primitivechar") public class WSPrimitiveCharServer { - @OnMessage - public char echo(String data) { - return Character.valueOf(data.charAt(0)).charValue(); - } + @OnMessage + public char echo(String data) { + return Character.valueOf(data.charAt(0)).charValue(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveDoubleServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveDoubleServer.java index 51b0afcde2..be4d1b9aee 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveDoubleServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveDoubleServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/primitivedouble") public class WSPrimitiveDoubleServer { - @OnMessage - public double echo(String data) { - return Double.parseDouble(data); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public double echo(String data) { + return Double.parseDouble(data); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveFloatServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveFloatServer.java index 1d32088162..e0d0de3eb3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveFloatServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveFloatServer.java @@ -29,16 +29,16 @@ @ServerEndpoint("/primitivefloat") public class WSPrimitiveFloatServer { - @OnMessage - public float echo(String data) { - return Float.parseFloat(data); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public float echo(String data) { + return Float.parseFloat(data); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveIntServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveIntServer.java index 5d25fc38c4..ccf6006d37 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveIntServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveIntServer.java @@ -29,15 +29,15 @@ @ServerEndpoint("/primitiveint") public class WSPrimitiveIntServer { - @OnMessage - public int echoInt(String data) { - return Integer.valueOf(data); - } + @OnMessage + public int echoInt(String data) { + return Integer.valueOf(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveLongServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveLongServer.java index cf241aada7..843bbd8738 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveLongServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveLongServer.java @@ -29,15 +29,15 @@ @ServerEndpoint("/primitivelong") public class WSPrimitiveLongServer { - @OnMessage - public long echo(String data) { - return Long.parseLong(data); - } + @OnMessage + public long echo(String data) { + return Long.parseLong(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveShortServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveShortServer.java index 774fd94fac..ca1cba85f8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveShortServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSPrimitiveShortServer.java @@ -28,15 +28,15 @@ @ServerEndpoint("/primitiveshort") public class WSPrimitiveShortServer { - @OnMessage - public short echo(String data) { - return Short.parseShort(data); - } + @OnMessage + public short echo(String data) { + return Short.parseShort(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSTextEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSTextEncoderServer.java index f47c0496f6..b5e582c1a1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSTextEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSTextEncoderServer.java @@ -28,19 +28,18 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textencoder", encoders = { - StringBeanTextEncoder.class }) +@ServerEndpoint(value = "/textencoder", encoders = { StringBeanTextEncoder.class }) public class WSTextEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSTextStreamEncoderServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSTextStreamEncoderServer.java index 72a5ece929..925e0fdd83 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSTextStreamEncoderServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketmessagereturntype/WSTextStreamEncoderServer.java @@ -28,20 +28,19 @@ import jakarta.websocket.Session; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/textstreamencoder", encoders = { - StringBeanTextStreamEncoder.class }) +@ServerEndpoint(value = "/textstreamencoder", encoders = { StringBeanTextStreamEncoder.class }) public class WSTextStreamEncoderServer { - @OnMessage - public StringBean echo(String data) { - return new StringBean(data); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public StringBean echo(String data) { + return new StringBean(data); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/lib/implementation/sun/common/SunRIURL.java b/websocket/src/main/java/com/sun/ts/tests/websocket/lib/implementation/sun/common/SunRIURL.java new file mode 100644 index 0000000000..cdb56a3551 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/lib/implementation/sun/common/SunRIURL.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2007, 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 com.sun.ts.tests.websocket.lib.implementation.sun.common; + +import java.net.MalformedURLException; +import java.net.URL; + +import com.sun.ts.lib.porting.TSURLInterface; +import com.sun.ts.lib.util.TestUtil; + +// import com.sun.ts.lib.porting.TSURLInterface; +// import ee.jakarta.tck.ws.rs.lib.util.TestUtil; + +/** + * This is a J2EE Reference specific implementation of the TSURLInterface which + * is to be used for J2EE-TS testing. TS tests use this interface to obtain the + * URL String to use to access a given web component. If a given J2EE Server + * implmentation requires that URLs be created in a different manner, then this + * implementation can be replaced. + * + * @author Kyle Grucci + */ +public class SunRIURL implements TSURLInterface { + private URL url = null; + + /** + * This method is called by TS tests to get the URL to use to access a given + * web component. + * + * @param protocol + * - the name of the protocol. + * @param host + * - the name of the host. + * @param port + * - the port number. + * @param file + * - the host file. + * @return a valid URL object. + */ + public URL getURL(String protocol, String host, int port, String file) + throws MalformedURLException { + try { + url = new URL(protocol, host, port, file); + } catch (MalformedURLException e) { + TestUtil.logErr("Failed during URL creation", e); + throw e; + } + return url; + } + + /** + * This method is called by TS tests to get the URL to use to access a given + * web component. + * + * @param protocol + * - the name of the protocol. + * @param host + * - the name of the host. + * @param port + * - the port number. + * @param file + * - the host file. + * @return a valid URL as a String. + */ + public String getURLString(String protocol, String host, int port, + String file) { + if (file.startsWith("/")) + return protocol + "://" + host + ":" + port + file; + else + return protocol + "://" + host + ":" + port + "/" + file; + } + + /** + * This method is called by TS tests to get the request string to use to + * access a given web component. + * + * @param request + * - the request file. + * @return a valid String object. + */ + public String getRequest(String request) { + return request; + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/EchoServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/EchoServerEndpoint.java index 249806b28a..602877ce73 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/EchoServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/EchoServerEndpoint.java @@ -29,21 +29,21 @@ @ServerEndpoint("/echo") public class EchoServerEndpoint { - @OnMessage - public String echo(String echo) { - return echo; - } - - @OnMessage - public String echo(byte[] bytes) { - return new String(bytes); - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo) { + return echo; + } + + @OnMessage + public String echo(byte[] bytes) { + return new String(bytes); + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/NegativeDeploymentClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/NegativeDeploymentClient.java index ac67dc107e..19453a61e2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/NegativeDeploymentClient.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/NegativeDeploymentClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -16,8 +16,6 @@ package com.sun.ts.tests.websocket.negdep; -import java.util.Properties; - import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; /** @@ -29,30 +27,28 @@ */ public class NegativeDeploymentClient extends WebSocketCommonClient { - private static final long serialVersionUID = 111; + private static final long serialVersionUID = 111; - protected String tslib_name; + protected String lib_name; - @Override - public void setup(String[] args, Properties p) throws Exception { - super.setup(args, p); - tslib_name = p.getProperty("tslib.name"); - assertFalse(isNullOrEmpty(tslib_name), - "'tslib.name' was not set in the build.properties."); - } + @Override + public void setup() throws Exception { + super.setup(); + lib_name = System.getProperty("lib.name"); + assertFalse(isNullOrEmpty(lib_name), "'lib.name' was not set in the properties."); + } - protected void throwWhenCts() throws Exception { - if (tslib_name.equalsIgnoreCase("cts")) - throwDeploymentDidNotFail(); - } + protected void throwWhenCts() throws Exception { + if (lib_name.equalsIgnoreCase("cts")) + throwDeploymentDidNotFail(); + } - protected void throwValidEndpointMustBeRemoved() throws Exception { - String msg = "Test Failed - a deployment error raised during the deployment process must halt the deployment of the application, any well formed endpoints deployed prior to the error being raised must be removed from service and no more websocket endpoints from that application may be deployed by the container, even if they are valid"; - throw new Exception(msg); - } + protected void throwValidEndpointMustBeRemoved() throws Exception { + String msg = "Test Failed - a deployment error raised during the deployment process must halt the deployment of the application, any well formed endpoints deployed prior to the error being raised must be removed from service and no more websocket endpoints from that application may be deployed by the container, even if they are valid"; + throw new Exception(msg); + } - protected void throwDeploymentDidNotFail() throws Exception { - throw new Exception( - "Test Failed - expected deployment to fail, but it succeeded!"); - } + protected void throwDeploymentDidNotFail() throws Exception { + throw new Exception("Test Failed - expected deployment to fail, but it succeeded!"); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/StringHolder.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/StringHolder.java index a19f4e10e0..5e6f4f7811 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/StringHolder.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/StringHolder.java @@ -23,32 +23,32 @@ * @since 1.11 */ public class StringHolder implements CharSequence { - public String inner = ""; - - public StringHolder(String hold) { - inner = hold; - } - - public StringHolder() { - } - - @Override - public int length() { - return inner.length(); - } - - @Override - public char charAt(int index) { - return inner.charAt(index); - } - - @Override - public CharSequence subSequence(int start, int end) { - return inner.subSequence(start, end); - } - - @Override - public String toString() { - return inner; - } + public String inner = ""; + + public StringHolder(String hold) { + inner = hold; + } + + public StringHolder() { + } + + @Override + public int length() { + return inner.length(); + } + + @Override + public char charAt(int index) { + return inner.charAt(index); + } + + @Override + public CharSequence subSequence(int start, int end) { + return inner.subSequence(start, end); + } + + @Override + public String toString() { + return inner; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/AppConfig.java index 5928db245b..24a5db56d8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/AppConfig.java @@ -25,21 +25,19 @@ import jakarta.websocket.Endpoint; import jakarta.websocket.server.ServerEndpointConfig; -public class AppConfig - implements jakarta.websocket.server.ServerApplicationConfig { - - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - return set; - } - - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(EchoServerEndpoint.class); - return set; - } +public class AppConfig implements jakarta.websocket.server.ServerApplicationConfig { + + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + return set; + } + + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(EchoServerEndpoint.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/OnCloseStringHolderServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/OnCloseStringHolderServerEndpoint.java index 6819aac007..2d74117a08 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/OnCloseStringHolderServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/OnCloseStringHolderServerEndpoint.java @@ -31,23 +31,24 @@ @ServerEndpoint("/invalid/{arg}") public class OnCloseStringHolderServerEndpoint { - private static String close = ""; - - @OnMessage - public String echo(String echo) { - return close + echo; - } - - @SuppressWarnings("unused") - @OnClose - public void onClose(Session session, @PathParam("arg") StringHolder sb) { - close = sb.toString(); - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + + private static String close = ""; + + @OnMessage + public String echo(String echo) { + return close + echo; + } + + @SuppressWarnings("unused") + @OnClose + public void onClose(Session session, @PathParam("arg") StringHolder sb) { + close = sb.toString(); + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/TestListener.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/TestListener.java index e195ad3e6d..847c6edd14 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/TestListener.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/TestListener.java @@ -26,38 +26,36 @@ @WebListener public class TestListener implements ServletContextListener { - /** - * Receives notification that the web application initialization process is - * starting. - * - * @param sce - * The ServletContextEvent - */ - @Override - public void contextInitialized(ServletContextEvent sce) { - ServletContext context = sce.getServletContext(); - try { - final ServerContainer serverContainer = (ServerContainer) context - .getAttribute("jakarta.websocket.server.ServerContainer"); - serverContainer.addEndpoint(OnCloseStringHolderServerEndpoint.class); - } catch (Exception ex) { - // The DeploymentException thrown here should remove all - // endpoints including the EchoServerEndpoint and no more - // endpoint is allowed to be deployed. Because of that, - // the error cannot be passed to client side and it only - // can be logged in into appserver log. - ex.printStackTrace(); - } - } + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce The ServletContextEvent + */ + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + try { + final ServerContainer serverContainer = (ServerContainer) context + .getAttribute("jakarta.websocket.server.ServerContainer"); + serverContainer.addEndpoint(OnCloseStringHolderServerEndpoint.class); + } catch (Exception ex) { + // The DeploymentException thrown here should remove all + // endpoints including the EchoServerEndpoint and no more + // endpoint is allowed to be deployed. Because of that, + // the error cannot be passed to client side and it only + // can be logged in into appserver log. + ex.printStackTrace(); + } + } - /** - * Receives notification that the servlet context is about to be shut down. - * - * @param sce - * The servlet context event - */ - @Override - public void contextDestroyed(ServletContextEvent sce) { - // Do nothing - } + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce The servlet context event + */ + @Override + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/WSCClient.java deleted file mode 100644 index d2e762c84c..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/WSCClient.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onclose; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_invalidpathparamtype_pasrv_onclose_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: invalidTypeOnCloseUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringHolder to String as argument of @OnClose in - * OnCloseStringHolderServerEndpoint - */ - public void invalidTypeOnCloseUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: invalidTypeOnCloseTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringHolder to String as argument of @OnClose in - * OnCloseStringHolderServerEndpoint - */ - public void invalidTypeOnCloseTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/WSCClientIT.java new file mode 100644 index 0000000000..ab4b69edbb --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onclose/WSCClientIT.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onclose; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_negdep_invalidpathparamtype_pasrv_onclose_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onclose"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_invalidpathparamtype_pasrv_onclose_web"); + } + + /* + * @testName: invalidTypeOnCloseUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringHolder to String as argument of @OnClose in + * OnCloseStringHolderServerEndpoint + */ + @Test + public void invalidTypeOnCloseUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: invalidTypeOnCloseTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringHolder to String as argument of @OnClose in + * OnCloseStringHolderServerEndpoint + */ + @Test + public void invalidTypeOnCloseTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/AppConfig.java index b8444303eb..be13593dba 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/AppConfig.java @@ -25,21 +25,19 @@ import jakarta.websocket.Endpoint; import jakarta.websocket.server.ServerEndpointConfig; -public class AppConfig - implements jakarta.websocket.server.ServerApplicationConfig { - - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - return set; - } - - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(EchoServerEndpoint.class); - return set; - } +public class AppConfig implements jakarta.websocket.server.ServerApplicationConfig { + + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + return set; + } + + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(EchoServerEndpoint.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/OnErrorServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/OnErrorServerEndpoint.java index 78a4b7d1ee..aa3c24aeca 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/OnErrorServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/OnErrorServerEndpoint.java @@ -28,24 +28,23 @@ import jakarta.websocket.server.PathParam; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/invalid/{arg}", decoders = { - StringBeanTextDecoder.class }) +@ServerEndpoint(value = "/invalid/{arg}", decoders = { StringBeanTextDecoder.class }) public class OnErrorServerEndpoint { - private static String exception = ""; - - @OnMessage - public String echo(String echo) { - if ("throw".equals(echo)) - throw new RuntimeException(echo); - return exception + echo; - } - - // This header makes the endpoint invalid, since only Strings can be - // @PathParams - @OnError - public void onError(Session session, Throwable t, - @PathParam("arg") StringBean sb) throws IOException { - exception = sb.get(); - session.getBasicRemote().sendText(t.getMessage()); - } + + private static String exception = ""; + + @OnMessage + public String echo(String echo) { + if ("throw".equals(echo)) + throw new RuntimeException(echo); + return exception + echo; + } + + // This header makes the endpoint invalid, since only Strings can be + // @PathParams + @OnError + public void onError(Session session, Throwable t, @PathParam("arg") StringBean sb) throws IOException { + exception = sb.get(); + session.getBasicRemote().sendText(t.getMessage()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/TestListener.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/TestListener.java index ff31ba4dbd..e3f80556a6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/TestListener.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/TestListener.java @@ -26,38 +26,36 @@ @WebListener public class TestListener implements ServletContextListener { - /** - * Receives notification that the web application initialization process is - * starting. - * - * @param sce - * The ServletContextEvent - */ - @Override - public void contextInitialized(ServletContextEvent sce) { - ServletContext context = sce.getServletContext(); - try { - final ServerContainer serverContainer = (ServerContainer) context - .getAttribute("jakarta.websocket.server.ServerContainer"); - serverContainer.addEndpoint(OnErrorServerEndpoint.class); - } catch (Exception ex) { - // The DeploymentException thrown here should remove all - // endpoints including the EchoServerEndpoint and no more - // endpoint is allowed to be deployed. Because of that, - // the error cannot be passed to client side and it only - // can be logged in into appserver log. - ex.printStackTrace(); - } - } + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce The ServletContextEvent + */ + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + try { + final ServerContainer serverContainer = (ServerContainer) context + .getAttribute("jakarta.websocket.server.ServerContainer"); + serverContainer.addEndpoint(OnErrorServerEndpoint.class); + } catch (Exception ex) { + // The DeploymentException thrown here should remove all + // endpoints including the EchoServerEndpoint and no more + // endpoint is allowed to be deployed. Because of that, + // the error cannot be passed to client side and it only + // can be logged in into appserver log. + ex.printStackTrace(); + } + } - /** - * Receives notification that the servlet context is about to be shut down. - * - * @param sce - * The servlet context event - */ - @Override - public void contextDestroyed(ServletContextEvent sce) { - // Do nothing - } + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce The servlet context event + */ + @Override + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/WSCClient.java deleted file mode 100644 index 738c984e49..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/WSCClient.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onerror; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_invalidpathparamtype_pasrv_onerror_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: invalidTypeOnErrorUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringBean to String as argument of @OnError in OnErrorServerEndpoint - */ - public void invalidTypeOnErrorUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: invalidTypeOnErrorTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringBean to String as argument of @OnError in OnErrorServerEndpoint - */ - public void invalidTypeOnErrorTest() throws Exception { - setProperty(Property.CONTENT, "throw"); - setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("throw".equals(response)) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/WSCClientIT.java new file mode 100644 index 0000000000..369dac66b2 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onerror/WSCClientIT.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onerror; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_negdep_invalidpathparamtype_pasrv_onerror_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onerror"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addClasses(StringBeanTextDecoder.class, StringBean.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_invalidpathparamtype_pasrv_onerror_web"); + } + + /* + * @testName: invalidTypeOnErrorUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringBean to String as argument of @OnError in OnErrorServerEndpoint + */ + @Test + public void invalidTypeOnErrorUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: invalidTypeOnErrorTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringBean to String as argument of @OnError in OnErrorServerEndpoint + */ + @Test + public void invalidTypeOnErrorTest() throws Exception { + setProperty(Property.CONTENT, "throw"); + setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("throw".equals(response)) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/AppConfig.java index a928c3c525..88ceebad0c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/AppConfig.java @@ -25,21 +25,19 @@ import jakarta.websocket.Endpoint; import jakarta.websocket.server.ServerEndpointConfig; -public class AppConfig - implements jakarta.websocket.server.ServerApplicationConfig { - - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - return set; - } - - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(EchoServerEndpoint.class); - return set; - } +public class AppConfig implements jakarta.websocket.server.ServerApplicationConfig { + + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + return set; + } + + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(EchoServerEndpoint.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/OnMessageServerEndpoint.java index c8c637032c..3883543df1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/OnMessageServerEndpoint.java @@ -29,22 +29,21 @@ import jakarta.websocket.server.PathParam; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/invalid/{arg}", decoders = { - StringBeanTextDecoder.class }) +@ServerEndpoint(value = "/invalid/{arg}", decoders = { StringBeanTextDecoder.class }) public class OnMessageServerEndpoint { - // This header makes the endpoint invalid, since only Strings can be - // @PathParams - @SuppressWarnings("unused") - @OnMessage - public String echo(String echo, @PathParam("arg") StringBean bean) { - return echo.toString(); - } + // This header makes the endpoint invalid, since only Strings can be + // @PathParams + @SuppressWarnings("unused") + @OnMessage + public String echo(String echo, @PathParam("arg") StringBean bean) { + return echo.toString(); + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/TestListener.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/TestListener.java index 6de05de8f2..32088f16bc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/TestListener.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/TestListener.java @@ -26,38 +26,36 @@ @WebListener public class TestListener implements ServletContextListener { - /** - * Receives notification that the web application initialization process is - * starting. - * - * @param sce - * The ServletContextEvent - */ - @Override - public void contextInitialized(ServletContextEvent sce) { - ServletContext context = sce.getServletContext(); - try { - final ServerContainer serverContainer = (ServerContainer) context - .getAttribute("jakarta.websocket.server.ServerContainer"); - serverContainer.addEndpoint(OnMessageServerEndpoint.class); - } catch (Exception ex) { - // The DeploymentException thrown here should remove all - // endpoints including the EchoServerEndpoint and no more - // endpoint is allowed to be deployed. Because of that, - // the error cannot be passed to client side and it only - // can be logged in into appserver log. - ex.printStackTrace(); - } - } + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce The ServletContextEvent + */ + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + try { + final ServerContainer serverContainer = (ServerContainer) context + .getAttribute("jakarta.websocket.server.ServerContainer"); + serverContainer.addEndpoint(OnMessageServerEndpoint.class); + } catch (Exception ex) { + // The DeploymentException thrown here should remove all + // endpoints including the EchoServerEndpoint and no more + // endpoint is allowed to be deployed. Because of that, + // the error cannot be passed to client side and it only + // can be logged in into appserver log. + ex.printStackTrace(); + } + } - /** - * Receives notification that the servlet context is about to be shut down. - * - * @param sce - * The servlet context event - */ - @Override - public void contextDestroyed(ServletContextEvent sce) { - // Do nothing - } + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce The servlet context event + */ + @Override + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/WSCClient.java deleted file mode 100644 index 3d78d93d50..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/WSCClient.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onmessage; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_invalidpathparamtype_pasrv_onmessage_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: invalidTypeOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringBean to String as argument of @OnMessage in OnMessageServerEndpoint - */ - public void invalidTypeOnMessageUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: invalidTypeOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringBean to String as argument of @OnMessage in OnMessageServerEndpoint - */ - public void invalidTypeOnMessageTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/WSCClientIT.java new file mode 100644 index 0000000000..b658f54304 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onmessage/WSCClientIT.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onmessage; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_negdep_invalidpathparamtype_pasrv_onmessage_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onmessage"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addClasses(StringBeanTextDecoder.class, StringBean.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_invalidpathparamtype_pasrv_onmessage_web"); + } + + /* + * @testName: invalidTypeOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringBean to String as argument of @OnMessage in OnMessageServerEndpoint + */ + @Test + public void invalidTypeOnMessageUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: invalidTypeOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringBean to String as argument of @OnMessage in OnMessageServerEndpoint + */ + @Test + public void invalidTypeOnMessageTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/AppConfig.java index a6f0384e29..9344157852 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/AppConfig.java @@ -25,21 +25,19 @@ import jakarta.websocket.Endpoint; import jakarta.websocket.server.ServerEndpointConfig; -public class AppConfig - implements jakarta.websocket.server.ServerApplicationConfig { - - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - return set; - } - - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(EchoServerEndpoint.class); - return set; - } +public class AppConfig implements jakarta.websocket.server.ServerApplicationConfig { + + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + return set; + } + + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(EchoServerEndpoint.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/OnOpenServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/OnOpenServerEndpoint.java index 584b034996..1f880c9ae1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/OnOpenServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/OnOpenServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,28 +30,28 @@ import jakarta.websocket.server.PathParam; import jakarta.websocket.server.ServerEndpoint; -@ServerEndpoint(value = "/invalid/{arg}", decoders = { - StringBeanTextDecoder.class }) +@ServerEndpoint(value = "/invalid/{arg}", decoders = { StringBeanTextDecoder.class }) public class OnOpenServerEndpoint { - private String open; - - @OnMessage - public String echo(String echo) { - return open + echo; - } - - // This header makes the endpoint invalid, since only Strings can be - // @PathParams - @SuppressWarnings("unused") - @OnOpen - public void onOpen(Session session, @PathParam("arg") StringBean sb) { - open = sb.get(); - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + + private String open; + + @OnMessage + public String echo(String echo) { + return open + echo; + } + + // This header makes the endpoint invalid, since only Strings can be + // @PathParams + @SuppressWarnings("unused") + @OnOpen + public void onOpen(Session session, @PathParam("arg") StringBean sb) { + open = sb.get(); + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/TestListener.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/TestListener.java index c9f16e4851..2e8d27a1f8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/TestListener.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/TestListener.java @@ -26,38 +26,36 @@ @WebListener public class TestListener implements ServletContextListener { - /** - * Receives notification that the web application initialization process is - * starting. - * - * @param sce - * The ServletContextEvent - */ - @Override - public void contextInitialized(ServletContextEvent sce) { - ServletContext context = sce.getServletContext(); - try { - final ServerContainer serverContainer = (ServerContainer) context - .getAttribute("jakarta.websocket.server.ServerContainer"); - serverContainer.addEndpoint(OnOpenServerEndpoint.class); - } catch (Exception ex) { - // The DeploymentException thrown here should remove all - // endpoints including the EchoServerEndpoint and no more - // endpoint is allowed to be deployed. Because of that, - // the error cannot be passed to client side and it only - // can be logged in into appserver log. - ex.printStackTrace(); - } - } + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce The ServletContextEvent + */ + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + try { + final ServerContainer serverContainer = (ServerContainer) context + .getAttribute("jakarta.websocket.server.ServerContainer"); + serverContainer.addEndpoint(OnOpenServerEndpoint.class); + } catch (Exception ex) { + // The DeploymentException thrown here should remove all + // endpoints including the EchoServerEndpoint and no more + // endpoint is allowed to be deployed. Because of that, + // the error cannot be passed to client side and it only + // can be logged in into appserver log. + ex.printStackTrace(); + } + } - /** - * Receives notification that the servlet context is about to be shut down. - * - * @param sce - * The servlet context event - */ - @Override - public void contextDestroyed(ServletContextEvent sce) { - // Do nothing - } + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce The servlet context event + */ + @Override + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/WSCClient.java deleted file mode 100644 index 6811ddae16..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/WSCClient.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onopen; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_invalidpathparamtype_pasrv_onopen_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: invalidTypeOnOpenUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringBean to String as argument of @OnOpen in OnOpenServerEndpoint - */ - public void invalidTypeOnOpenUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: invalidTypeOnOpenTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringBean to String as argument of @OnOpen in OnOpenServerEndpoint - */ - public void invalidTypeOnOpenTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("pathparamanything".equals(response)) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/WSCClientIT.java new file mode 100644 index 0000000000..2d963b74eb --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/pasrv/onopen/WSCClientIT.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onopen; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_negdep_invalidpathparamtype_pasrv_onopen_webs.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.invalidpathparamtype.pasrv.onopen"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addClasses(StringBeanTextDecoder.class, StringBean.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_invalidpathparamtype_pasrv_onopen_web"); + } + + /* + * @testName: invalidTypeOnOpenUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringBean to String as argument of @OnOpen in OnOpenServerEndpoint + */ + @Test + public void invalidTypeOnOpenUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: invalidTypeOnOpenTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringBean to String as argument of @OnOpen in OnOpenServerEndpoint + */ + @Test + public void invalidTypeOnOpenTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("pathparamanything".equals(response)) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onclose/OnCloseStringHolderServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onclose/OnCloseStringHolderServerEndpoint.java index 743fa9c2ee..8457abd0fb 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onclose/OnCloseStringHolderServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onclose/OnCloseStringHolderServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -31,23 +31,24 @@ @ServerEndpoint("/invalid/{arg}") public class OnCloseStringHolderServerEndpoint { - private static String close = ""; - - @OnMessage - public String echo(String echo) { - return close + echo; - } - - @SuppressWarnings("unused") - @OnClose - public void onClose(Session session, @PathParam("arg") StringHolder sb) { - close = sb.toString(); - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + + private static String close = ""; + + @OnMessage + public String echo(String echo) { + return close + echo; + } + + @SuppressWarnings("unused") + @OnClose + public void onClose(Session session, @PathParam("arg") StringHolder sb) { + close = sb.toString(); + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onclose/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onclose/WSCClient.java deleted file mode 100644 index 2152b82ce6..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onclose/WSCClient.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onclose; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_invalidpathparamtype_srv_onclose_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: invalidTypeOnCloseUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringHolder to String as argument of @OnClose in - * OnCloseStringHolderServerEndpoint - */ - public void invalidTypeOnCloseUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: invalidTypeOnCloseTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringHolder to String as argument of @OnClose in - * OnCloseStringHolderServerEndpoint - */ - public void invalidTypeOnCloseTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - - cleanup(); - // Once again for multiple runs - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - response = getResponseAsString(); - if ("pathparamanything".equals(response)) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onclose/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onclose/WSCClientIT.java new file mode 100644 index 0000000000..31a28e765c --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onclose/WSCClientIT.java @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onclose; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_invalidpathparamtype_srv_onclose_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onclose"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addClasses(StringBeanTextDecoder.class, StringBean.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_invalidpathparamtype_srv_onclose_web"); + } + + /* + * @testName: invalidTypeOnCloseUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringHolder to String as argument of @OnClose in + * OnCloseStringHolderServerEndpoint + */ + @Test + public void invalidTypeOnCloseUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: invalidTypeOnCloseTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringHolder to String as argument of @OnClose in + * OnCloseStringHolderServerEndpoint + */ + @Test + public void invalidTypeOnCloseTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + + cleanup(); + // Once again for multiple runs + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + response = getResponseAsString(); + if ("pathparamanything".equals(response)) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onerror/OnErrorStringHolderServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onerror/OnErrorStringHolderServerEndpoint.java index 0845ee2bad..6e37195def 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onerror/OnErrorStringHolderServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onerror/OnErrorStringHolderServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,19 +29,19 @@ @ServerEndpoint("/invalid/{arg}") public class OnErrorStringHolderServerEndpoint { - private static String exception = ""; - - @OnMessage - public String echo(String echo) { - if ("throw".equals(echo)) - throw new RuntimeException(echo); - return exception + echo; - } - - @OnError - public void onError(Session session, Throwable t, - @PathParam("arg") StringHolder sb) throws IOException { - exception = sb.toString(); - session.getBasicRemote().sendText(t.getMessage()); - } + + private static String exception = ""; + + @OnMessage + public String echo(String echo) { + if ("throw".equals(echo)) + throw new RuntimeException(echo); + return exception + echo; + } + + @OnError + public void onError(Session session, Throwable t, @PathParam("arg") StringHolder sb) throws IOException { + exception = sb.toString(); + session.getBasicRemote().sendText(t.getMessage()); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onerror/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onerror/WSCClient.java deleted file mode 100644 index befafad977..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onerror/WSCClient.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onerror; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_invalidpathparamtype_srv_onerror_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: invalidTypeOnErrorUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringHolder to String as argument of @OnError in - * OnErrorStringHolderServerEndpoint - */ - public void invalidTypeOnErrorUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: invalidTypeOnErrorTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringHolder to String as argument of @OnError in - * OnErrorStringHolderServerEndpoint - */ - public void invalidTypeOnErrorTest() throws Exception { - setProperty(Property.CONTENT, "throw"); - setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("throw".equals(response)) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onerror/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onerror/WSCClientIT.java new file mode 100644 index 0000000000..56d4333a30 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onerror/WSCClientIT.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onerror; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_invalidpathparamtype_srv_onerror_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onerror"); + archive.addPackages(true, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addClasses(StringBeanTextDecoder.class, StringBean.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_invalidpathparamtype_srv_onerror_web"); + } + + /* + * @testName: invalidTypeOnErrorUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringHolder to String as argument of @OnError in + * OnErrorStringHolderServerEndpoint + */ + @Test + public void invalidTypeOnErrorUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: invalidTypeOnErrorTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringHolder to String as argument of @OnError in + * OnErrorStringHolderServerEndpoint + */ + @Test + public void invalidTypeOnErrorTest() throws Exception { + setProperty(Property.CONTENT, "throw"); + setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("throw".equals(response)) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onmessage/OnMessageStringHolderServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onmessage/OnMessageStringHolderServerEndpoint.java index fddae43fb0..2897fd0d82 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onmessage/OnMessageStringHolderServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onmessage/OnMessageStringHolderServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -31,16 +31,16 @@ @ServerEndpoint("/invalid/{arg}") public class OnMessageStringHolderServerEndpoint { - @SuppressWarnings("unused") - @OnMessage - public String echo(String echo, @PathParam("arg") StringHolder bean) { - return echo.toString(); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(String echo, @PathParam("arg") StringHolder bean) { + return echo.toString(); + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onmessage/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onmessage/WSCClient.java deleted file mode 100644 index cacfb2a4c6..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onmessage/WSCClient.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onmessage; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_invalidpathparamtype_srv_onmessage_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: invalidTypeOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringHolder to String as argument of @OnMessage in - * OnMessageStringHolderServerEndpoint - */ - public void invalidTypeOnMessageUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: invalidTypeOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringHolder to String as argument of @OnMessage in - * OnMessageStringHolderServerEndpoint - */ - public void invalidTypeOnMessageTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onmessage/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onmessage/WSCClientIT.java new file mode 100644 index 0000000000..5afb19ba1c --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onmessage/WSCClientIT.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onmessage; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_negdep_invalidpathparamtype_srv_onmessage_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onmessage"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addClasses(StringBeanTextDecoder.class, StringBean.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_invalidpathparamtype_srv_onmessage_web"); + } + + /* + * @testName: invalidTypeOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringHolder to String as argument of @OnMessage in + * OnMessageStringHolderServerEndpoint + */ + @Test + public void invalidTypeOnMessageUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: invalidTypeOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringHolder to String as argument of @OnMessage in + * OnMessageStringHolderServerEndpoint + */ + @Test + public void invalidTypeOnMessageTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onopen/OnOpenStringHolderServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onopen/OnOpenStringHolderServerEndpoint.java index 765bf20eda..42635c102f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onopen/OnOpenStringHolderServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onopen/OnOpenStringHolderServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -31,23 +31,24 @@ @ServerEndpoint("/invalid/{arg}") public class OnOpenStringHolderServerEndpoint { - private String open; - - @OnMessage - public String echo(String echo) { - return open + echo; - } - - @SuppressWarnings("unused") - @OnOpen - public void onOpen(Session session, @PathParam("arg") StringHolder sb) { - open = sb.toString(); - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + + private String open; + + @OnMessage + public String echo(String echo) { + return open + echo; + } + + @SuppressWarnings("unused") + @OnOpen + public void onOpen(Session session, @PathParam("arg") StringHolder sb) { + open = sb.toString(); + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onopen/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onopen/WSCClient.java deleted file mode 100644 index 7462ab04a4..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onopen/WSCClient.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onopen; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_invalidpathparamtype_srv_onopen_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: invalidTypeOnOpenUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringHolder to String as argument of @OnOpen in - * OnOpenStringHolderServerEndpoint - */ - public void invalidTypeOnOpenUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: invalidTypeOnOpenTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The allowed types for these parameters are String, any Java primitive type, - * or boxed version thereof. Any other type annotated with this annotation is - * an error that the implementation must report at deployment time. - * [WSC-4.3-1] - * - * To verify the test fails when the deployment was successful, switch - * StringHolder to String as argument of @OnOpen in - * OnOpenStringHolderServerEndpoint - */ - public void invalidTypeOnOpenTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("pathparamanything".equals(response)) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onopen/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onopen/WSCClientIT.java new file mode 100644 index 0000000000..83f2597a5a --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/invalidpathparamtype/srv/onopen/WSCClientIT.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onopen; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.stringbean.StringBean; +import com.sun.ts.tests.websocket.common.stringbean.StringBeanTextDecoder; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_invalidpathparamtype_srv_onopen_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onmessage"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addClasses(StringBeanTextDecoder.class, StringBean.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_invalidpathparamtype_srv_onopen_web"); + } + + /* + * @testName: invalidTypeOnOpenUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringHolder to String as argument of @OnOpen in + * OnOpenStringHolderServerEndpoint + */ + @Test + public void invalidTypeOnOpenUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: invalidTypeOnOpenTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.3-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The allowed types for these parameters are String, any Java primitive type, + * or boxed version thereof. Any other type annotated with this annotation is an + * error that the implementation must report at deployment time. [WSC-4.3-1] + * + * To verify the test fails when the deployment was successful, switch + * StringHolder to String as argument of @OnOpen in + * OnOpenStringHolderServerEndpoint + */ + @Test + public void invalidTypeOnOpenTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid/pathparam")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("pathparamanything".equals(response)) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/malformedpath/MalformedPathServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/malformedpath/MalformedPathServerEndpoint.java index 11811a898b..9a76a2849f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/malformedpath/MalformedPathServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/malformedpath/MalformedPathServerEndpoint.java @@ -29,16 +29,16 @@ @ServerEndpoint("") public class MalformedPathServerEndpoint { - @OnMessage - public String echo(String echo) { - return echo; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo) { + return echo; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/malformedpath/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/malformedpath/WSCClient.java deleted file mode 100644 index b73d6b5428..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/malformedpath/WSCClient.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.malformedpath; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_malformedpath_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: mallformedPathTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.1.1-3; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The value attribute is mandatory; the implementation must reject a missing - * or malformed path at deployment time [WSC-4.1.1-3] - * - * To verify the test fails when the deployment was successful, set path in - * MalformedPathServerEndpoint - */ - public void mallformedPathTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/malformedpath/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/malformedpath/WSCClientIT.java new file mode 100644 index 0000000000..b41a64a408 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/malformedpath/WSCClientIT.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.malformedpath; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_malformedpath_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.invalidpathparamtype.srv.onmessage"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_malformedpath_web"); + } + + /* + * @testName: mallformedPathTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.1.1-3; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The value attribute is mandatory; the implementation must reject a missing or + * malformed path at deployment time [WSC-4.1.1-3] + * + * To verify the test fails when the deployment was successful, set path in + * MalformedPathServerEndpoint + */ + @Test + public void mallformedPathTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/SamePathServerEndpoint1.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/SamePathServerEndpoint1.java index 5b9168977d..38c747ec77 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/SamePathServerEndpoint1.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/SamePathServerEndpoint1.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2017, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -28,15 +28,16 @@ @ServerEndpoint("/path") public class SamePathServerEndpoint1 { - @OnMessage - public String echo(String echo) { - return echo; - } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo) { + return echo; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/SamePathServerEndpoint2.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/SamePathServerEndpoint2.java index ee685265a9..7ed5c2f764 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/SamePathServerEndpoint2.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/SamePathServerEndpoint2.java @@ -28,15 +28,15 @@ @ServerEndpoint("/path") public class SamePathServerEndpoint2 { - @OnMessage - public String echo(String echo) { - return echo; - } + @OnMessage + public String echo(String echo) { + return echo; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/WSCClient.java deleted file mode 100644 index 79e9fb271f..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/WSCClient.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.multiplepaths; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_multiplepaths_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: twoEndpointsWithTheSamePathThirdEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3; WebSocket:SPEC:WSC-4.1.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The websocket implementation must reject such an application at deployment - * time with an informative error message that there is a duplicate path that - * it cannot resolve. [WSC-4.1.1-4] - * - * To verify the test fails when the deployment was successful, change path in - * SamePathServerEndpoint2 - */ - public void twoEndpointsWithTheSamePathThirdEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: twoEndpointsWithTheSamePathTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3; WebSocket:SPEC:WSC-4.1.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The websocket implementation must reject such an application at deployment - * time with an informative error message that there is a duplicate path that - * it cannot resolve. [WSC-4.1.1-4] - * - * To verify the test fails when the deployment was successful, change path in - * SamePathServerEndpoint2 - */ - public void twoEndpointsWithTheSamePathTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("path")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/WSCClientIT.java new file mode 100644 index 0000000000..a17070705f --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/multiplepaths/WSCClientIT.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.multiplepaths; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_multiplepaths_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.multiplepaths"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_multiplepaths_web"); + } + + /* + * @testName: twoEndpointsWithTheSamePathThirdEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3; WebSocket:SPEC:WSC-4.1.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The websocket implementation must reject such an application at deployment + * time with an informative error message that there is a duplicate path that it + * cannot resolve. [WSC-4.1.1-4] + * + * To verify the test fails when the deployment was successful, change path in + * SamePathServerEndpoint2 + */ + @Test + public void twoEndpointsWithTheSamePathThirdEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: twoEndpointsWithTheSamePathTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3; WebSocket:SPEC:WSC-4.1.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The websocket implementation must reject such an application at deployment + * time with an informative error message that there is a duplicate path that it + * cannot resolve. [WSC-4.1.1-4] + * + * To verify the test fails when the deployment was successful, change path in + * SamePathServerEndpoint2 + */ + @Test + public void twoEndpointsWithTheSamePathTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("path")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/duplicate/AnnotatedOnCloseClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/duplicate/AnnotatedOnCloseClientEndpoint.java index 961cb49771..9bdf007400 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/duplicate/AnnotatedOnCloseClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/duplicate/AnnotatedOnCloseClientEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2017, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,35 +29,34 @@ import jakarta.websocket.Session; @ClientEndpoint -public class AnnotatedOnCloseClientEndpoint - extends AnnotatedStringClientEndpoint { - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } - - @Override - @OnMessage - public void onMessage(String msg) { - clientEndpoint.onMessage(msg); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - clientEndpoint.onClose(session, closeReason); - } - - @OnClose - public void onClose2(Session session, CloseReason closeReason) { - clientEndpoint.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } +public class AnnotatedOnCloseClientEndpoint extends AnnotatedStringClientEndpoint { + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } + + @Override + @OnMessage + public void onMessage(String msg) { + clientEndpoint.onMessage(msg); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + clientEndpoint.onClose(session, closeReason); + } + + @OnClose + public void onClose2(Session session, CloseReason closeReason) { + clientEndpoint.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/duplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/duplicate/WSCClient.java deleted file mode 100644 index b713ed5185..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/duplicate/WSCClient.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onclose.client.duplicate; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onclose_client_duplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnCloseTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.5-4] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To verify the test fails when the deployment was successful, comment out - * one of @OnClose in AnnotatedOnCloseClientEndpoint - */ - public void duplicateOnCloseTest() throws Exception { - AnnotatedOnCloseClientEndpoint endpoint = new AnnotatedOnCloseClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/duplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/duplicate/WSCClientIT.java new file mode 100644 index 0000000000..853e6204f8 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/duplicate/WSCClientIT.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onclose.client.duplicate; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onclose_client_duplicate_web.war"); + archive.addClass(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onclose_client_duplicate_web"); + } + + /* + * @testName: duplicateOnCloseTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.5-4] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To verify the test fails when the deployment was successful, comment out one + * of @OnClose in AnnotatedOnCloseClientEndpoint + */ + @Test + public void duplicateOnCloseTest() throws Exception { + AnnotatedOnCloseClientEndpoint endpoint = new AnnotatedOnCloseClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/toomanyargs/AnnotatedOnCloseClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/toomanyargs/AnnotatedOnCloseClientEndpoint.java index 4376d2bdd7..aa852d18fb 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/toomanyargs/AnnotatedOnCloseClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/toomanyargs/AnnotatedOnCloseClientEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,31 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class AnnotatedOnCloseClientEndpoint - extends AnnotatedStringClientEndpoint { - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } - - @Override - @OnMessage - public void onMessage(String msg) { - clientEndpoint.onMessage(msg); - } - - @SuppressWarnings("unused") - @OnClose - public void onClose(Session session, CloseReason closeReason, - Throwable throwable) { - clientEndpoint.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } +public class AnnotatedOnCloseClientEndpoint extends AnnotatedStringClientEndpoint { + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } + + @Override + @OnMessage + public void onMessage(String msg) { + clientEndpoint.onMessage(msg); + } + + @SuppressWarnings("unused") + @OnClose + public void onClose(Session session, CloseReason closeReason, Throwable throwable) { + clientEndpoint.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/toomanyargs/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/toomanyargs/WSCClient.java deleted file mode 100644 index 7b3ad5dc0a..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/toomanyargs/WSCClient.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onclose.client.toomanyargs; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onclose_client_toomanyarguments_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: tooManyArgumentsOnCloseTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.5-4] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To verify the test fails when the deployment was successful, comment out - * one of @OnClose in AnnotatedOnCloseClientEndpoint - */ - public void tooManyArgumentsOnCloseTest() throws Exception { - AnnotatedOnCloseClientEndpoint endpoint = new AnnotatedOnCloseClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/toomanyargs/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/toomanyargs/WSCClientIT.java new file mode 100644 index 0000000000..7e3b247f03 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/client/toomanyargs/WSCClientIT.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onclose.client.toomanyargs; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onclose_client_toomanyarguments_web.war"); + archive.addClasses(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onclose_client_toomanyarguments_web"); + } + + /* + * @testName: tooManyArgumentsOnCloseTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.5-4] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To verify the test fails when the deployment was successful, comment out one + * of @OnClose in AnnotatedOnCloseClientEndpoint + */ + @Test + public void tooManyArgumentsOnCloseTest() throws Exception { + AnnotatedOnCloseClientEndpoint endpoint = new AnnotatedOnCloseClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/duplicate/OnCloseServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/duplicate/OnCloseServerEndpoint.java index 6b5bfdd8c5..c4e0f481e9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/duplicate/OnCloseServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/duplicate/OnCloseServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,29 +30,30 @@ @ServerEndpoint("/invalid") public class OnCloseServerEndpoint { - private static String close = ""; - - @OnMessage - public String echo(String echo) { - return echo + close; - } - - @SuppressWarnings("unused") - @OnClose - public void onClose(Session session) { - close = "first @OnClose"; - } - - @SuppressWarnings("unused") - @OnClose - public void onClose(Session session, CloseReason reason) { - close = "second @OnClose"; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + + private static String close = ""; + + @OnMessage + public String echo(String echo) { + return echo + close; + } + + @SuppressWarnings("unused") + @OnClose + public void onClose(Session session) { + close = "first @OnClose"; + } + + @SuppressWarnings("unused") + @OnClose + public void onClose(Session session, CloseReason reason) { + close = "second @OnClose"; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/duplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/duplicate/WSCClient.java deleted file mode 100644 index 6d03141ac6..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/duplicate/WSCClient.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onclose.srv.duplicate; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onclose_srv_duplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: multipleOnCloseRemovesAllEndpointsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.5-4] - * - * To verify the test fails when the deployment was successful, comment out - * one of @OnClose in OnCloseServerEndpoint - */ - public void multipleOnCloseRemovesAllEndpointsTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: multipleOnCloseTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.5-4] - * - * To verify the test fails when the deployment was successful, comment out - * one of @OnClose in OnCloseServerEndpoint - */ - public void multipleOnCloseTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/duplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/duplicate/WSCClientIT.java new file mode 100644 index 0000000000..3bf09b68ac --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/duplicate/WSCClientIT.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onclose.srv.duplicate; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onclose_srv_duplicate_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onclose.srv.duplicate"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onclose_srv_duplicate_web"); + } + + /* + * @testName: multipleOnCloseRemovesAllEndpointsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.5-4] + * + * To verify the test fails when the deployment was successful, comment out one + * of @OnClose in OnCloseServerEndpoint + */ + @Test + public void multipleOnCloseRemovesAllEndpointsTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: multipleOnCloseTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.5-4] + * + * To verify the test fails when the deployment was successful, comment out one + * of @OnClose in OnCloseServerEndpoint + */ + @Test + public void multipleOnCloseTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/toomanyargs/OnCloseServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/toomanyargs/OnCloseServerEndpoint.java index 443df62733..e0553da532 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/toomanyargs/OnCloseServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/toomanyargs/OnCloseServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,23 +29,24 @@ @ServerEndpoint("/invalid") public class OnCloseServerEndpoint { - private static String close = ""; - - @OnMessage - public String echo(String echo) { - return echo + close; - } - - @SuppressWarnings("unused") - @OnClose - public void onClose(Session session, Exception thisShouldNotBeHere) { - close = "thisShouldNotBeHere"; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + + private static String close = ""; + + @OnMessage + public String echo(String echo) { + return echo + close; + } + + @SuppressWarnings("unused") + @OnClose + public void onClose(Session session, Exception thisShouldNotBeHere) { + close = "thisShouldNotBeHere"; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/toomanyargs/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/toomanyargs/WSCClient.java deleted file mode 100644 index 75733bad6e..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/toomanyargs/WSCClient.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onclose.srv.toomanyargs; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onclose_srv_toomanyarguments_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: tooManyArgumentsOnCloseRemovesAllEndpointsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.5-4] - * - * To verify the test fails when the deployment was successful, remove - * Exception type argument of @OnClose in OnCloseServerEndpoint - */ - public void tooManyArgumentsOnCloseRemovesAllEndpointsTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: tooManyArgumentsOnCloseTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.5-4] - * - * To verify the test fails when the deployment was successful, remove - * Exception type argument of @OnClose in OnCloseServerEndpoint - */ - public void tooManyArgumentsOnCloseTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/toomanyargs/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/toomanyargs/WSCClientIT.java new file mode 100644 index 0000000000..118b53b905 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onclose/srv/toomanyargs/WSCClientIT.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onclose.srv.toomanyargs; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onclose_srv_toomanyarguments_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onclose.srv.toomanyargs"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onclose_srv_toomanyarguments_web"); + } + + /* + * @testName: tooManyArgumentsOnCloseRemovesAllEndpointsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.5-4] + * + * To verify the test fails when the deployment was successful, remove Exception + * type argument of @OnClose in OnCloseServerEndpoint + */ + @Test + public void tooManyArgumentsOnCloseRemovesAllEndpointsTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: tooManyArgumentsOnCloseTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.5-4] + * + * To verify the test fails when the deployment was successful, remove Exception + * type argument of @OnClose in OnCloseServerEndpoint + */ + @Test + public void tooManyArgumentsOnCloseTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/duplicate/AnnotatedOnErrorClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/duplicate/AnnotatedOnErrorClientEndpoint.java index 237be15c1e..2ba7feeb2b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/duplicate/AnnotatedOnErrorClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/duplicate/AnnotatedOnErrorClientEndpoint.java @@ -29,35 +29,34 @@ import jakarta.websocket.Session; @ClientEndpoint -public class AnnotatedOnErrorClientEndpoint - extends AnnotatedStringClientEndpoint { - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } - - @Override - @OnMessage - public void onMessage(String msg) { - clientEndpoint.onMessage(msg); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - clientEndpoint.onClose(session, closeReason); - } - - @SuppressWarnings("unused") - @OnError - public void onError(Throwable t) { - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } +public class AnnotatedOnErrorClientEndpoint extends AnnotatedStringClientEndpoint { + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } + + @Override + @OnMessage + public void onMessage(String msg) { + clientEndpoint.onMessage(msg); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + clientEndpoint.onClose(session, closeReason); + } + + @SuppressWarnings("unused") + @OnError + public void onError(Throwable t) { + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/duplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/duplicate/WSCClient.java deleted file mode 100644 index fc6c66a02b..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/duplicate/WSCClient.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onerror.client.duplicate; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onerror_client_duplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnCloseTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.6-3; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.6-3] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To verify the test fails when the deployment was successful, comment out - * one of @OnError in OnErrorServerEndpoint - */ - public void duplicateOnCloseTest() throws Exception { - AnnotatedOnErrorClientEndpoint endpoint = new AnnotatedOnErrorClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/duplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/duplicate/WSCClientIT.java new file mode 100644 index 0000000000..43626dbc79 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/duplicate/WSCClientIT.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onerror.client.duplicate; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onerror_client_duplicate_web.war"); + archive.addClass(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onerror_client_duplicate_web"); + } + + /* + * @testName: duplicateOnCloseTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.6-3; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.6-3] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To verify the test fails when the deployment was successful, comment out one + * of @OnError in OnErrorServerEndpoint + */ + @Test + public void duplicateOnCloseTest() throws Exception { + AnnotatedOnErrorClientEndpoint endpoint = new AnnotatedOnErrorClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(true); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/toomanyargs/AnnotatedOnErrorClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/toomanyargs/AnnotatedOnErrorClientEndpoint.java index 8f7f36a734..fe0ec555d7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/toomanyargs/AnnotatedOnErrorClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/toomanyargs/AnnotatedOnErrorClientEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2017, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,30 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class AnnotatedOnErrorClientEndpoint - extends AnnotatedStringClientEndpoint { - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } - - @Override - @OnMessage - public void onMessage(String msg) { - clientEndpoint.onMessage(msg); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - clientEndpoint.onClose(session, closeReason); - } - - @SuppressWarnings("unused") - @OnError - public void onError(Session session, Throwable t, CloseReason closeReason) { - clientEndpoint.onError(session, t); - } +public class AnnotatedOnErrorClientEndpoint extends AnnotatedStringClientEndpoint { + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } + + @Override + @OnMessage + public void onMessage(String msg) { + clientEndpoint.onMessage(msg); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + clientEndpoint.onClose(session, closeReason); + } + + @SuppressWarnings("unused") + @OnError + public void onError(Session session, Throwable t, CloseReason closeReason) { + clientEndpoint.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/toomanyargs/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/toomanyargs/WSCClient.java deleted file mode 100644 index a4b498b51c..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/toomanyargs/WSCClient.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onerror.client.toomanyargs; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onerror_client_toomanyarguments_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnCloseTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.6-3; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.6-3] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To verify the test fails when the deployment was successful, comment out - * the CloseReason argument of @OnError in OnErrorServerEndpoint - */ - public void duplicateOnCloseTest() throws Exception { - AnnotatedOnErrorClientEndpoint endpoint = new AnnotatedOnErrorClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/toomanyargs/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/toomanyargs/WSCClientIT.java new file mode 100644 index 0000000000..842cf5f61d --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/client/toomanyargs/WSCClientIT.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onerror.client.toomanyargs; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onerror_client_toomanyarguments_web.war"); + archive.addClass(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onerror_client_toomanyarguments_web"); + } + + /* + * @testName: duplicateOnCloseTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.6-3; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.6-3] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To verify the test fails when the deployment was successful, comment out the + * CloseReason argument of @OnError in OnErrorServerEndpoint + */ + @Test + public void duplicateOnCloseTest() throws Exception { + AnnotatedOnErrorClientEndpoint endpoint = new AnnotatedOnErrorClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/duplicate/OnErrorServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/duplicate/OnErrorServerEndpoint.java index e433514c65..22154f4f82 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/duplicate/OnErrorServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/duplicate/OnErrorServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,21 +29,21 @@ @ServerEndpoint("/invalid") public class OnErrorServerEndpoint { - @OnMessage - public String echo(String echo) { - return echo; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } - - @OnError - public void onError2(Session session, Throwable thr) throws IOException { - onError(session, thr); - } + @OnMessage + public String echo(String echo) { + return echo; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } + + @OnError + public void onError2(Session session, Throwable thr) throws IOException { + onError(session, thr); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/duplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/duplicate/WSCClient.java deleted file mode 100644 index 403f7d4ab5..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/duplicate/WSCClient.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onerror.srv.duplicate; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onerror_srv_duplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: multipleOnErrorRemovesAllEndpointsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.6-3] - * - * To verify the test fails when the deployment was successful, comment out - * one of @OnError in OnErrorServerEndpoint - */ - public void multipleOnErrorRemovesAllEndpointsTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: multipleOnErrorTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.6-3; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.6-3] - * - * To verify the test fails when the deployment was successful, comment out - * one of @OnError in OnErrorServerEndpoint - */ - public void multipleOnErrorTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/duplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/duplicate/WSCClientIT.java new file mode 100644 index 0000000000..2477244031 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/duplicate/WSCClientIT.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onerror.srv.duplicate; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onerror_srv_duplicate_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onerror.srv.duplicate"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onerror_srv_duplicate_web"); + } + + /* + * @testName: multipleOnErrorRemovesAllEndpointsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.6-3] + * + * To verify the test fails when the deployment was successful, comment out one + * of @OnError in OnErrorServerEndpoint + */ + @Test + public void multipleOnErrorRemovesAllEndpointsTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: multipleOnErrorTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.6-3; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.6-3] + * + * To verify the test fails when the deployment was successful, comment out one + * of @OnError in OnErrorServerEndpoint + */ + public void multipleOnErrorTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/toomanyargs/OnErrorServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/toomanyargs/OnErrorServerEndpoint.java index 68b2a1cac4..df14040fee 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/toomanyargs/OnErrorServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/toomanyargs/OnErrorServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,21 +30,20 @@ @ServerEndpoint("/invalid") public class OnErrorServerEndpoint { - @SuppressWarnings("unused") - @OnMessage - public String echo(String echo) { - - // return echo; - throw new RuntimeException(); - } - - @SuppressWarnings("unused") - @OnError - public void onError(Session session, Throwable thr, CloseReason reason) - throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(String echo) { + + // return echo; + throw new RuntimeException(); + } + + @SuppressWarnings("unused") + @OnError + public void onError(Session session, Throwable thr, CloseReason reason) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/toomanyargs/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/toomanyargs/WSCClient.java deleted file mode 100644 index 78cbad7bd9..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/toomanyargs/WSCClient.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onerror.srv.toomanyargs; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onerror_srv_toomanyarguments_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: tooManyArgsOnErrorRemovesAllEndpointsTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.6-3] - * - * To verify the test fails when the deployment was successful, comment out - * one EndpointConfig argument of @OnError in OnErrorServerEndpoint - */ - public void tooManyArgsOnErrorRemovesAllEndpointsTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: tooManyArgsOnErrorTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.6-3; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.6-3] - * - * To verify the test fails when the deployment was successful, comment out - * one EndpointConfig argument of @OnError in OnErrorServerEndpoint - */ - public void tooManyArgsOnErrorTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/toomanyargs/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/toomanyargs/WSCClientIT.java new file mode 100644 index 0000000000..22f194fb06 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onerror/srv/toomanyargs/WSCClientIT.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onerror.srv.toomanyargs; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onerror_srv_toomanyarguments_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onerror.srv.toomanyargs"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onerror_srv_toomanyarguments_web"); + } + + /* + * @testName: tooManyArgsOnErrorRemovesAllEndpointsTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.5-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.6-3] + * + * To verify the test fails when the deployment was successful, comment out one + * EndpointConfig argument of @OnError in OnErrorServerEndpoint + */ + @Test + public void tooManyArgsOnErrorRemovesAllEndpointsTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: tooManyArgsOnErrorTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.6-3; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.6-3] + * + * To verify the test fails when the deployment was successful, comment out one + * EndpointConfig argument of @OnError in OnErrorServerEndpoint + */ + @Test + public void tooManyArgsOnErrorTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binarybytebufferint/OnMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binarybytebufferint/OnMessageClientEndpoint.java index ad399d4646..e48d55f1f8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binarybytebufferint/OnMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binarybytebufferint/OnMessageClientEndpoint.java @@ -19,6 +19,7 @@ import java.nio.ByteBuffer; + import com.sun.ts.tests.websocket.common.client.AnnotatedByteBufferClientEndpoint; import jakarta.websocket.ClientEndpoint; @@ -31,26 +32,26 @@ @ClientEndpoint public class OnMessageClientEndpoint extends AnnotatedByteBufferClientEndpoint { - @SuppressWarnings("unused") - @OnMessage - public void onMessage(ByteBuffer msg, int i) { - clientEndpoint.onMessage(msg); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } - - @OnMessage - public void onMessage(String msg) { - clientEndpoint.onMessage(ByteBuffer.wrap(msg.getBytes())); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } + @SuppressWarnings("unused") + @OnMessage + public void onMessage(ByteBuffer msg, int i) { + clientEndpoint.onMessage(msg); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } + + @OnMessage + public void onMessage(String msg) { + clientEndpoint.onMessage(ByteBuffer.wrap(msg.getBytes())); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binarybytebufferint/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binarybytebufferint/WSCClient.java deleted file mode 100644 index fbe6a4aeed..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binarybytebufferint/WSCClient.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.binarybytebufferint; - -import java.nio.ByteBuffer; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain ByteBuffer and boolean pair. This test checks that - * ByteBuffer and int pair is out of this scope for partial messages. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_client_binarybytebufferint_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: byteBufferIntOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To check the test fails when deployment pass, comment out the int parameter - * in @OnMessage of OnMessageClientEndpoint - */ - public void byteBufferIntOnMessageTest() throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binarybytebufferint/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binarybytebufferint/WSCClientIT.java new file mode 100644 index 0000000000..0ebfaf1eec --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binarybytebufferint/WSCClientIT.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.binarybytebufferint; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain ByteBuffer and boolean pair. This test checks that + * ByteBuffer and int pair is out of this scope for partial messages. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_negdep_onmessage_client_binarybytebufferint_web.war"); + archive.addClass(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onmessage_client_binarybytebufferint_web"); + } + + /* + * @testName: byteBufferIntOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To check the test fails when deployment pass, comment out the int parameter + * in @OnMessage of OnMessageClientEndpoint + */ + @Test + public void byteBufferIntOnMessageTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(true); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryduplicate/OnMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryduplicate/OnMessageClientEndpoint.java index e238776740..902f8d0b86 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryduplicate/OnMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryduplicate/OnMessageClientEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -31,32 +31,32 @@ @ClientEndpoint public class OnMessageClientEndpoint extends AnnotatedByteBufferClientEndpoint { - @Override - @OnMessage - public void onMessage(ByteBuffer msg) { - clientEndpoint.onMessage(msg); - } - - @SuppressWarnings("unused") - @OnMessage - public void onMessage(ByteBuffer msg, boolean finito) { - clientEndpoint.onMessage(msg); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } - - @OnMessage - public void onMessage(String msg) { - clientEndpoint.onMessage(ByteBuffer.wrap(msg.getBytes())); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } + @Override + @OnMessage + public void onMessage(ByteBuffer msg) { + clientEndpoint.onMessage(msg); + } + + @SuppressWarnings("unused") + @OnMessage + public void onMessage(ByteBuffer msg, boolean finito) { + clientEndpoint.onMessage(msg); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } + + @OnMessage + public void onMessage(String msg) { + clientEndpoint.onMessage(ByteBuffer.wrap(msg.getBytes())); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryduplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryduplicate/WSCClient.java deleted file mode 100644 index 446ad8a125..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryduplicate/WSCClient.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.binaryduplicate; - -import java.nio.ByteBuffer; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain one binary message handling method. This test checks - * two such methods fail the deployment. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_client_binaryduplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Each websocket endpoint may only have one message handling method for each - * of the native websocket message formats: text, binary and pong. The - * websocket implementation must not deploy such an endpoint and must raise a - * deployment error if an attempt is made to deploy such an annotated - * endpoint. [WSC-4.7-4] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To check the test fails when deployment pass, comment out of the - * - * @OnMessage of OnMessageServerEndpoint - */ - public void duplicateOnMessageTest() throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryduplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryduplicate/WSCClientIT.java new file mode 100644 index 0000000000..4f17c14559 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryduplicate/WSCClientIT.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.binaryduplicate; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain one binary message handling method. This test checks + * two such methods fail the deployment. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_client_binaryduplicate_web.war"); + archive.addClass(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onmessage_client_binaryduplicate_web"); + } + + /* + * @testName: duplicateOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Each websocket endpoint may only have one message handling method for each of + * the native websocket message formats: text, binary and pong. The websocket + * implementation must not deploy such an endpoint and must raise a deployment + * error if an attempt is made to deploy such an annotated endpoint. [WSC-4.7-4] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To check the test fails when deployment pass, comment out of the + * + * @OnMessage of OnMessageServerEndpoint + */ + @Test + public void duplicateOnMessageTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryinputstreamboolean/OnMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryinputstreamboolean/OnMessageClientEndpoint.java index f02cb2d8ff..49bf973f16 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryinputstreamboolean/OnMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryinputstreamboolean/OnMessageClientEndpoint.java @@ -32,26 +32,26 @@ @ClientEndpoint public class OnMessageClientEndpoint extends AnnotatedByteBufferClientEndpoint { - @SuppressWarnings("unused") - @OnMessage - public void onMessage(InputStream msg, boolean finito) { - // there is no server endpoint that sends binary messages - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } - - @OnMessage - public void onMessage(String msg) { - clientEndpoint.onMessage(ByteBuffer.wrap(msg.getBytes())); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } + @SuppressWarnings("unused") + @OnMessage + public void onMessage(InputStream msg, boolean finito) { + // there is no server endpoint that sends binary messages + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } + + @OnMessage + public void onMessage(String msg) { + clientEndpoint.onMessage(ByteBuffer.wrap(msg.getBytes())); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryinputstreamboolean/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryinputstreamboolean/WSCClient.java deleted file mode 100644 index 901e11d7da..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryinputstreamboolean/WSCClient.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.binaryinputstreamboolean; - -import java.nio.ByteBuffer; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain InpustStream. This test checks that InpustStream and - * boolean pair is out of this scope for partial messages. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_client_binaryinputstreamboolean_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: byteBufferIntOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To check the test fails when deployment pass, comment out the boolean - * parameter in @OnMessage of OnMessageClientEndpoint - */ - public void byteBufferIntOnMessageTest() throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryinputstreamboolean/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryinputstreamboolean/WSCClientIT.java new file mode 100644 index 0000000000..5564ff0134 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/binaryinputstreamboolean/WSCClientIT.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.binaryinputstreamboolean; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain InpustStream. This test checks that InpustStream and + * boolean pair is out of this scope for partial messages. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_negdep_onmessage_client_binaryinputstreamboolean_web.war"); + archive.addClass(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onmessage_client_binaryinputstreamboolean_web"); + } + + /* + * @testName: byteBufferIntOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To check the test fails when deployment pass, comment out the boolean + * parameter in @OnMessage of OnMessageClientEndpoint + */ + @Test + public void byteBufferIntOnMessageTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/nodecoder/OnMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/nodecoder/OnMessageClientEndpoint.java index 0191db5190..5e436082a2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/nodecoder/OnMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/nodecoder/OnMessageClientEndpoint.java @@ -38,20 +38,20 @@ @ClientEndpoint public class OnMessageClientEndpoint extends AnnotatedByteBufferClientEndpoint { - @OnMessage - public void onMessage(StringHolder holder) { - clientEndpoint.onMessage(ByteBuffer.wrap(holder.toString().getBytes())); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } + @OnMessage + public void onMessage(StringHolder holder) { + clientEndpoint.onMessage(ByteBuffer.wrap(holder.toString().getBytes())); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/nodecoder/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/nodecoder/WSCClient.java deleted file mode 100644 index 163aa09247..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/nodecoder/WSCClient.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.nodecoder; - -import java.nio.ByteBuffer; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain any object parameter for which the endpoint has a - * binary decoder. Make sure the deployment fails where there is - * none. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_client_nodecoder_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: byteBufferIntOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To check the test fails when deployment pass, comment out the boolean - * parameter in @OnMessage of OnMessageClientEndpoint - */ - public void byteBufferIntOnMessageTest() throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/nodecoder/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/nodecoder/WSCClientIT.java new file mode 100644 index 0000000000..cb5c5d293a --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/nodecoder/WSCClientIT.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.nodecoder; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain any object parameter for which the endpoint has a + * binary decoder. Make sure the deployment fails where there is + * none. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_client_nodecoder_web.war"); + archive.addClasses(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onmessage_client_nodecoder_web"); + } + + /* + * @testName: byteBufferIntOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To check the test fails when deployment pass, comment out the boolean + * parameter in @OnMessage of OnMessageClientEndpoint + */ + @Test + public void byteBufferIntOnMessageTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongboolean/OnMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongboolean/OnMessageClientEndpoint.java index e831a0d997..a9aafc51b8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongboolean/OnMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongboolean/OnMessageClientEndpoint.java @@ -32,26 +32,26 @@ @ClientEndpoint public class OnMessageClientEndpoint extends AnnotatedByteBufferClientEndpoint { - @SuppressWarnings("unused") - @OnMessage - public void onMessage(PongMessage msg, boolean finito) { - // there is no server endpoint that sends ping/pong messages - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } - - @OnMessage - public void onMessage(String msg) { - clientEndpoint.onMessage(ByteBuffer.wrap(msg.getBytes())); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } + @SuppressWarnings("unused") + @OnMessage + public void onMessage(PongMessage msg, boolean finito) { + // there is no server endpoint that sends ping/pong messages + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } + + @OnMessage + public void onMessage(String msg) { + clientEndpoint.onMessage(ByteBuffer.wrap(msg.getBytes())); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongboolean/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongboolean/WSCClient.java deleted file mode 100644 index 6aaf6b97eb..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongboolean/WSCClient.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.pongboolean; - -import java.nio.ByteBuffer; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain PongMessage. This test checks that PongMessage and - * boolean pair is out of this scope for partial messages. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_client_pongboolean_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: pongBooleanOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To check the test fails when deployment pass, comment out the boolean - * parameter in @OnMessage of OnMessageClientEndpoint - */ - public void pongBooleanOnMessageTest() throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongboolean/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongboolean/WSCClientIT.java new file mode 100644 index 0000000000..ea47de9cd8 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongboolean/WSCClientIT.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.pongboolean; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain PongMessage. This test checks that PongMessage and + * boolean pair is out of this scope for partial messages. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_client_pongboolean_web.war"); + archive.addClasses(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onmessage_client_pongboolean_web"); + } + + /* + * @testName: pongBooleanOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To check the test fails when deployment pass, comment out the boolean + * parameter in @OnMessage of OnMessageClientEndpoint + */ + @Test + public void pongBooleanOnMessageTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongduplicate/OnMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongduplicate/OnMessageClientEndpoint.java index b90c3d214b..51677cf227 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongduplicate/OnMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongduplicate/OnMessageClientEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -31,34 +31,32 @@ @ClientEndpoint public class OnMessageClientEndpoint extends AnnotatedStringClientEndpoint { - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } - - @OnMessage - public void onMessage(PongMessage msg) { - clientEndpoint - .onMessage(IOUtil.byteBufferToString(msg.getApplicationData())); - } - - @SuppressWarnings("unused") - @OnMessage - public void onMessage(PongMessage msg, Session session) { - clientEndpoint - .onMessage(IOUtil.byteBufferToString(msg.getApplicationData())); - } - - @Override - @OnMessage - public void onMessage(String msg) { - clientEndpoint.onMessage(msg); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } + + @OnMessage + public void onMessage(PongMessage msg) { + clientEndpoint.onMessage(IOUtil.byteBufferToString(msg.getApplicationData())); + } + + @SuppressWarnings("unused") + @OnMessage + public void onMessage(PongMessage msg, Session session) { + clientEndpoint.onMessage(IOUtil.byteBufferToString(msg.getApplicationData())); + } + + @Override + @OnMessage + public void onMessage(String msg) { + clientEndpoint.onMessage(msg); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongduplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongduplicate/WSCClient.java deleted file mode 100644 index f3c11f7b79..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongduplicate/WSCClient.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.pongduplicate; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain one pong message handling method. This test checks two - * such methods fail the deployment. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_client_pongduplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Each websocket endpoint may only have one message handling method for each - * of the native websocket message formats: text, binary and pong. The - * websocket implementation must not deploy such an endpoint and must raise a - * deployment error if an attempt is made to deploy such an annotated - * endpoint. [WSC-4.7-4] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To check the test fails when deployment pass, comment out of the - * - * @OnMessage of OnMessageServerEndpoint - */ - public void duplicateOnMessageTest() throws Exception { - setEntity("anything"); - OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongduplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongduplicate/WSCClientIT.java new file mode 100644 index 0000000000..96bfebb513 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/pongduplicate/WSCClientIT.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.pongduplicate; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain one pong message handling method. This test checks two + * such methods fail the deployment. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_client_pongduplicate_web.war"); + archive.addClass(EchoServerEndpoint.class); + archive.addClass(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onmessage_client_pongduplicate_web"); + } + + /* + * @testName: duplicateOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Each websocket endpoint may only have one message handling method for each of + * the native websocket message formats: text, binary and pong. The websocket + * implementation must not deploy such an endpoint and must raise a deployment + * error if an attempt is made to deploy such an annotated endpoint. [WSC-4.7-4] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To check the test fails when deployment pass, comment out of the + * + * @OnMessage of OnMessageServerEndpoint + */ + @Test + public void duplicateOnMessageTest() throws Exception { + setEntity("anything"); + OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textbigdecimal/OnMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textbigdecimal/OnMessageClientEndpoint.java index af421227c2..c43d8633b2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textbigdecimal/OnMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textbigdecimal/OnMessageClientEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -31,20 +31,20 @@ @ClientEndpoint public class OnMessageClientEndpoint extends AnnotatedStringClientEndpoint { - @OnMessage - public void onMessage(BigDecimal decimal) { - clientEndpoint.onMessage(decimal.toString()); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } + @OnMessage + public void onMessage(BigDecimal decimal) { + clientEndpoint.onMessage(decimal.toString()); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textbigdecimal/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textbigdecimal/WSCClient.java deleted file mode 100644 index cc638e6881..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textbigdecimal/WSCClient.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.textbigdecimal; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage Java primitive or class equivalent to receive the whole message - * converted to that type. This test checks the Bigdecimal is out of - * this scope. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_client_textbigdecimal_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: bigDecimalOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To check the test fails when deployment pass, switch BigDecimal argument - * with String in @OnMessage of OnMessageClientEndpoint - */ - public void bigDecimalOnMessageTest() throws Exception { - setEntity("anything"); - OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textbigdecimal/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textbigdecimal/WSCClientIT.java new file mode 100644 index 0000000000..8eb17572cb --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textbigdecimal/WSCClientIT.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.textbigdecimal; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage Java primitive or class equivalent to receive the whole message + * converted to that type. This test checks the Bigdecimal is out of + * this scope. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_client_textbigdecimal_web.war"); + archive.addClass(EchoServerEndpoint.class); + archive.addClass(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onmessage_client_textbigdecimal_web"); + } + + /* + * @testName: bigDecimalOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To check the test fails when deployment pass, switch BigDecimal argument with + * String in @OnMessage of OnMessageClientEndpoint + */ + @Test + public void bigDecimalOnMessageTest() throws Exception { + setEntity("anything"); + OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textduplicate/OnMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textduplicate/OnMessageClientEndpoint.java index a1bb0db710..a8d01fff16 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textduplicate/OnMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textduplicate/OnMessageClientEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -31,26 +31,26 @@ @ClientEndpoint(decoders = { StringBeanTextDecoder.class }) public class OnMessageClientEndpoint extends AnnotatedStringClientEndpoint { - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } - - @SuppressWarnings("unused") - @OnMessage - public void onMessage(String msg, boolean finito) { - clientEndpoint.onMessage(msg); - } - - @OnMessage - public void onMessage(StringBean bean) { - clientEndpoint.onMessage(bean.get()); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } + + @SuppressWarnings("unused") + @OnMessage + public void onMessage(String msg, boolean finito) { + clientEndpoint.onMessage(msg); + } + + @OnMessage + public void onMessage(StringBean bean) { + clientEndpoint.onMessage(bean.get()); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textduplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textduplicate/WSCClient.java deleted file mode 100644 index 642809a9c7..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textduplicate/WSCClient.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.textduplicate; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain one text message handling method. This test checks two - * such methods fail the deployment. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_client_textduplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Each websocket endpoint may only have one message handling method for each - * of the native websocket message formats: text, binary and pong. The - * websocket implementation must not deploy such an endpoint and must raise a - * deployment error if an attempt is made to deploy such an annotated - * endpoint. [WSC-4.7-4] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To check the test fails when deployment pass, comment out of the - * - * @OnMessage of OnMessageServerEndpoint - */ - public void duplicateOnMessageTest() throws Exception { - setEntity("anything"); - OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textduplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textduplicate/WSCClientIT.java new file mode 100644 index 0000000000..e16de10597 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textduplicate/WSCClientIT.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.textduplicate; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain one text message handling method. This test checks two + * such methods fail the deployment. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_client_textduplicate_web.war"); + archive.addClasses(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onmessage_client_textduplicate_web"); + } + + /* + * @testName: duplicateOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Each websocket endpoint may only have one message handling method for each of + * the native websocket message formats: text, binary and pong. The websocket + * implementation must not deploy such an endpoint and must raise a deployment + * error if an attempt is made to deploy such an annotated endpoint. [WSC-4.7-4] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To check the test fails when deployment pass, comment out of the + * + * @OnMessage of OnMessageServerEndpoint + */ + @Test + public void duplicateOnMessageTest() throws Exception { + setEntity("anything"); + OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textreaderboolean/OnMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textreaderboolean/OnMessageClientEndpoint.java index a28b2e1f8c..9fb15692d9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textreaderboolean/OnMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textreaderboolean/OnMessageClientEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -33,21 +33,21 @@ @ClientEndpoint public class OnMessageClientEndpoint extends AnnotatedStringClientEndpoint { - @SuppressWarnings("unused") - @OnMessage - public void onMessage(Reader reader, boolean finito) throws IOException { - clientEndpoint.onMessage(IOUtil.readFromReader(reader)); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } + @SuppressWarnings("unused") + @OnMessage + public void onMessage(Reader reader, boolean finito) throws IOException { + clientEndpoint.onMessage(IOUtil.readFromReader(reader)); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textreaderboolean/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textreaderboolean/WSCClient.java deleted file mode 100644 index 8d0b8142d4..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textreaderboolean/WSCClient.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.textreaderboolean; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain Reader. This test checks that Reader and boolean pair - * is out of this scope for partial messages. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_client_textreaderboolean_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: readerBooleanOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To check the test fails when deployment pass, comment out boolean argument - * in @OnMessage of OnMessageClientEndpoint - */ - public void readerBooleanOnMessageTest() throws Exception { - setEntity("anything"); - OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textreaderboolean/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textreaderboolean/WSCClientIT.java new file mode 100644 index 0000000000..250bbc0cf6 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textreaderboolean/WSCClientIT.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.textreaderboolean; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain Reader. This test checks that Reader and boolean pair + * is out of this scope for partial messages. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_negdep_onmessage_client_textreaderboolean_web.war"); + archive.addClasses(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onmessage_client_textreaderboolean_web"); + } + + /* + * @testName: readerBooleanOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To check the test fails when deployment pass, comment out boolean argument + * in @OnMessage of OnMessageClientEndpoint + */ + @Test + public void readerBooleanOnMessageTest() throws Exception { + setEntity("anything"); + OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textstringint/OnMessageClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textstringint/OnMessageClientEndpoint.java index 7a30e77849..417d3d8d7f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textstringint/OnMessageClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textstringint/OnMessageClientEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -31,21 +31,21 @@ @ClientEndpoint public class OnMessageClientEndpoint extends AnnotatedStringClientEndpoint { - @SuppressWarnings("unused") - @OnMessage - public void onMessage(String msg, int finito) throws IOException { - clientEndpoint.onMessage(msg); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } + @SuppressWarnings("unused") + @OnMessage + public void onMessage(String msg, int finito) throws IOException { + clientEndpoint.onMessage(msg); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textstringint/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textstringint/WSCClient.java deleted file mode 100644 index e6784d234b..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textstringint/WSCClient.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.textstringint; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain String and boolean. This test checks that String and - * int pair is out of this scope for partial messages. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_client_textstringint_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: stringIntOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To check the test fails when deployment pass, comment out int argument - * in @OnMessage of OnMessageClientEndpoint - */ - public void stringIntOnMessageTest() throws Exception { - setEntity("anything"); - OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textstringint/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textstringint/WSCClientIT.java new file mode 100644 index 0000000000..af8122d38d --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/client/textstringint/WSCClientIT.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onmessage.client.textstringint; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain String and boolean. This test checks that String and + * int pair is out of this scope for partial messages. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_client_textstringint_web.war"); + archive.addClasses(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + super.setup(); + setContextRoot("wsc_negdep_onmessage_client_textstringint_web"); + } + + /* + * @testName: stringIntOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To check the test fails when deployment pass, comment out int argument + * in @OnMessage of OnMessageClientEndpoint + */ + @Test + public void stringIntOnMessageTest() throws Exception { + setEntity("anything"); + OnMessageClientEndpoint endpoint = new OnMessageClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(true); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/AppConfig.java index bba4769e00..38866cd823 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/AppConfig.java @@ -23,21 +23,19 @@ import jakarta.websocket.Endpoint; import jakarta.websocket.server.ServerEndpointConfig; -public class AppConfig - implements jakarta.websocket.server.ServerApplicationConfig { +public class AppConfig implements jakarta.websocket.server.ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + return set; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(OnMessageServerEndpoint.class); - return set; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(OnMessageServerEndpoint.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/OnMessageServerEndpoint.java index 2768f1b824..ce4b80ea2e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/OnMessageServerEndpoint.java @@ -29,21 +29,21 @@ @ServerEndpoint("/invalid") public class OnMessageServerEndpoint { - @OnMessage - public String echo(String echo) { - return echo; - } - - @SuppressWarnings("unused") - @OnMessage - public String echo(String echo, boolean finito) { - return echo; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo) { + return echo; + } + + @SuppressWarnings("unused") + @OnMessage + public String echo(String echo, boolean finito) { + return echo; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/TestListener.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/TestListener.java index d42bf0e056..a394b873f7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/TestListener.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/TestListener.java @@ -28,36 +28,34 @@ @WebListener public class TestListener implements ServletContextListener { - /** - * Receives notification that the web application initialization process is - * starting. - * - * @param sce - * The ServletContextEvent - */ - @Override - public void contextInitialized(ServletContextEvent sce) { - ServletContext context = sce.getServletContext(); - try { - final ServerContainer serverContainer = (ServerContainer) context - .getAttribute("jakarta.websocket.server.ServerContainer"); - serverContainer.addEndpoint(EchoServerEndpoint.class); - } catch (Exception ex) { - // The DeploymentException can be thrown here, since no - // more endpoit can be deployed when there was invalid - // endpoint in the app - ex.printStackTrace(); - } - } + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce The ServletContextEvent + */ + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + try { + final ServerContainer serverContainer = (ServerContainer) context + .getAttribute("jakarta.websocket.server.ServerContainer"); + serverContainer.addEndpoint(EchoServerEndpoint.class); + } catch (Exception ex) { + // The DeploymentException can be thrown here, since no + // more endpoit can be deployed when there was invalid + // endpoint in the app + ex.printStackTrace(); + } + } - /** - * Receives notification that the servlet context is about to be shut down. - * - * @param sce - * The servlet context event - */ - @Override - public void contextDestroyed(ServletContextEvent sce) { - // Do nothing - } + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce The servlet context event + */ + @Override + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/WSCClient.java deleted file mode 100644 index c8efd9c7c5..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/WSCClient.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.pasrv.nomoreendpoints; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain one text message handling method. This test checks two - * such methods fail the deployment. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_pasrv_nomoreendpoints_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnMessagePreventOtherEndpointFromBeingDeployedTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Each websocket endpoint may only have one message handling method for each - * of the native websocket message formats: text, binary and pong. The - * websocket implementation must not deploy such an endpoint and must raise a - * deployment error if an attempt is made to deploy such an annotated - * endpoint. [WSC-4.7-4] - * - * To check the test fails when deployment pass, comment out of the - * - * @OnMessage of OnMessageServerEndpoint - */ - public void duplicateOnMessagePreventOtherEndpointFromBeingDeployedTest() - throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/WSCClientIT.java new file mode 100644 index 0000000000..76cdb34c3b --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/pasrv/nomoreendpoints/WSCClientIT.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onmessage.pasrv.nomoreendpoints; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain one text message handling method. This test checks two + * such methods fail the deployment. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_pasrv_nomoreendpoints_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.pasrv.nomoreendpoints"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_pasrv_nomoreendpoints_web"); + } + + /* + * @testName: duplicateOnMessagePreventOtherEndpointFromBeingDeployedTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Each websocket endpoint may only have one message handling method for each of + * the native websocket message formats: text, binary and pong. The websocket + * implementation must not deploy such an endpoint and must raise a deployment + * error if an attempt is made to deploy such an annotated endpoint. [WSC-4.7-4] + * + * To check the test fails when deployment pass, comment out of the + * + * @OnMessage of OnMessageServerEndpoint + */ + @Test + public void duplicateOnMessagePreventOtherEndpointFromBeingDeployedTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/AppConfig.java index eff3012166..b846bc102f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/AppConfig.java @@ -23,21 +23,19 @@ import jakarta.websocket.Endpoint; import jakarta.websocket.server.ServerEndpointConfig; -public class AppConfig - implements jakarta.websocket.server.ServerApplicationConfig { +public class AppConfig implements jakarta.websocket.server.ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + return set; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(OnMessageServerEndpoint.class); - return set; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(OnMessageServerEndpoint.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/EchoServerConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/EchoServerConfig.java index 72c987b9af..072e04b92c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/EchoServerConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/EchoServerConfig.java @@ -28,44 +28,44 @@ public class EchoServerConfig implements ServerEndpointConfig { - @Override - public List> getEncoders() { - return Collections.emptyList(); - } + @Override + public List> getEncoders() { + return Collections.emptyList(); + } - @Override - public List> getDecoders() { - return Collections.emptyList(); - } + @Override + public List> getDecoders() { + return Collections.emptyList(); + } - @Override - public Map getUserProperties() { - return Collections.emptyMap(); - } + @Override + public Map getUserProperties() { + return Collections.emptyMap(); + } - @Override - public Class getEndpointClass() { - return EchoServerEndpoint.class; - } + @Override + public Class getEndpointClass() { + return EchoServerEndpoint.class; + } - @Override - public String getPath() { - return "/echo"; - } + @Override + public String getPath() { + return "/echo"; + } - @Override - public List getSubprotocols() { - return Collections.emptyList(); - } + @Override + public List getSubprotocols() { + return Collections.emptyList(); + } - @Override - public List getExtensions() { - return Collections.emptyList(); - } + @Override + public List getExtensions() { + return Collections.emptyList(); + } - @Override - public Configurator getConfigurator() { - return new ServerEndpointConfig.Configurator(); - } + @Override + public Configurator getConfigurator() { + return new ServerEndpointConfig.Configurator(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/EchoServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/EchoServerEndpoint.java index c975255d85..ae68748748 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/EchoServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/EchoServerEndpoint.java @@ -26,34 +26,33 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class EchoServerEndpoint extends Endpoint - implements MessageHandler.Whole { - private Session session; - - @Override - public void onOpen(Session session, EndpointConfig config) { - this.session = session; - session.addMessageHandler(this); - } - - @Override - public void onMessage(String message) { - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void onError(Session session, Throwable thr) { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - e.printStackTrace(); - } - } +public class EchoServerEndpoint extends Endpoint implements MessageHandler.Whole { + private Session session; + + @Override + public void onOpen(Session session, EndpointConfig config) { + this.session = session; + session.addMessageHandler(this); + } + + @Override + public void onMessage(String message) { + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void onError(Session session, Throwable thr) { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/OnMessageServerEndpoint.java index 2235ad7bd8..b43c7984c8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/OnMessageServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,21 +29,21 @@ @ServerEndpoint("/invalid") public class OnMessageServerEndpoint { - @OnMessage - public String echo(String echo) { - return echo; - } - - @SuppressWarnings("unused") - @OnMessage - public String echo(String echo, boolean finito) { - return echo; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo) { + return echo; + } + + @SuppressWarnings("unused") + @OnMessage + public String echo(String echo, boolean finito) { + return echo; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/TestListener.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/TestListener.java index aebfae9461..4dddc284b1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/TestListener.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/TestListener.java @@ -26,36 +26,34 @@ @WebListener public class TestListener implements ServletContextListener { - /** - * Receives notification that the web application initialization process is - * starting. - * - * @param sce - * The ServletContextEvent - */ - @Override - public void contextInitialized(ServletContextEvent sce) { - ServletContext context = sce.getServletContext(); - try { - final ServerContainer serverContainer = (ServerContainer) context - .getAttribute("jakarta.websocket.server.ServerContainer"); - serverContainer.addEndpoint(new EchoServerConfig()); - } catch (Exception ex) { - // The DeploymentException can be thrown here, since no - // more endpoit can be deployed when there was invalid - // endpoint in the app - ex.printStackTrace(); - } - } + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce The ServletContextEvent + */ + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + try { + final ServerContainer serverContainer = (ServerContainer) context + .getAttribute("jakarta.websocket.server.ServerContainer"); + serverContainer.addEndpoint(new EchoServerConfig()); + } catch (Exception ex) { + // The DeploymentException can be thrown here, since no + // more endpoit can be deployed when there was invalid + // endpoint in the app + ex.printStackTrace(); + } + } - /** - * Receives notification that the servlet context is about to be shut down. - * - * @param sce - * The servlet context event - */ - @Override - public void contextDestroyed(ServletContextEvent sce) { - // Do nothing - } + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce The servlet context event + */ + @Override + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/WSCClient.java deleted file mode 100644 index 6e6c2d4356..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/WSCClient.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.ppsrv.nomoreendpoints; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain one text message handling method. This test checks two - * such methods fail the deployment. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_ppsrv_nomoreendpoints_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnMessagePreventOtherEndpointFromBeingDeployedTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Each websocket endpoint may only have one message handling method for each - * of the native websocket message formats: text, binary and pong. The - * websocket implementation must not deploy such an endpoint and must raise a - * deployment error if an attempt is made to deploy such an annotated - * endpoint. [WSC-4.7-4] - * - * To check the test fails when deployment pass, comment out of the - * - * @OnMessage of OnMessageServerEndpoint - */ - public void duplicateOnMessagePreventOtherEndpointFromBeingDeployedTest() - throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/WSCClientIT.java new file mode 100644 index 0000000000..4f7de83823 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/ppsrv/nomoreendpoints/WSCClientIT.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onmessage.ppsrv.nomoreendpoints; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain one text message handling method. This test checks two + * such methods fail the deployment. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_ppsrv_nomoreendpoints_web.war"); + archive.addPackages(true, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.ppsrv.nomoreendpoints"); + archive.addPackages(true, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_ppsrv_nomoreendpoints_web"); + } + + /* + * @testName: duplicateOnMessagePreventOtherEndpointFromBeingDeployedTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Each websocket endpoint may only have one message handling method for each of + * the native websocket message formats: text, binary and pong. The websocket + * implementation must not deploy such an endpoint and must raise a deployment + * error if an attempt is made to deploy such an annotated endpoint. [WSC-4.7-4] + * + * To check the test fails when deployment pass, comment out of the + * + * @OnMessage of OnMessageServerEndpoint + */ + @Test + public void duplicateOnMessagePreventOtherEndpointFromBeingDeployedTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarybytebufferint/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarybytebufferint/OnMessageServerEndpoint.java index 7d32a4a6a0..b6928f0150 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarybytebufferint/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarybytebufferint/OnMessageServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -20,6 +20,9 @@ import java.io.IOException; import java.nio.ByteBuffer; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.junit.jupiter.api.extension.ExtendWith; + import com.sun.ts.tests.websocket.common.util.IOUtil; import jakarta.websocket.OnError; @@ -28,20 +31,21 @@ import jakarta.websocket.server.ServerEndpoint; @ServerEndpoint("/invalid") +@ExtendWith(ArquillianExtension.class) public class OnMessageServerEndpoint { - @SuppressWarnings("unused") - @OnMessage - public String echo(ByteBuffer buffer, int finito) { - String s = null; - s = IOUtil.byteBufferToString(buffer); - return s; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @SuppressWarnings("unused") + @OnMessage + public String echo(ByteBuffer buffer, int finito) { + String s = null; + s = IOUtil.byteBufferToString(buffer); + return s; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarybytebufferint/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarybytebufferint/WSCClient.java deleted file mode 100644 index 8048ed06ef..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarybytebufferint/WSCClient.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.binarybytebufferint; - -import java.nio.ByteBuffer; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain ByteBuffer and boolean pair. This test checks that - * ByteBuffer and int pair is out of this scope for partial messages. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_srv_binarybytebufferint_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: byteBufferIntOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, comment out the int parameter - * in @OnMessage of OnMessageServerEndpoint - */ - public void byteBufferIntOnMessageUndeployOtherEndpointTest() throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: byteBufferIntOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, comment out the int parameter - * in @OnMessage of OnMessageServerEndpoint - */ - public void byteBufferIntOnMessageTest() throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarybytebufferint/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarybytebufferint/WSCClientIT.java new file mode 100644 index 0000000000..4bdcd5a563 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarybytebufferint/WSCClientIT.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.binarybytebufferint; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain ByteBuffer and boolean pair. This test checks that + * ByteBuffer and int pair is out of this scope for partial messages. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_negdep_onmessage_srv_binarybytebufferint_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.srv.binarybytebufferint"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_srv_binarybytebufferint_web"); + } + + /* + * @testName: byteBufferIntOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, comment out the int parameter + * in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void byteBufferIntOnMessageUndeployOtherEndpointTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: byteBufferIntOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, comment out the int parameter + * in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void byteBufferIntOnMessageTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryduplicate/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryduplicate/OnMessageServerEndpoint.java index 1613f59ee6..59586c0b08 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryduplicate/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryduplicate/OnMessageServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -20,6 +20,9 @@ import java.io.IOException; import java.io.InputStream; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.junit.jupiter.api.extension.ExtendWith; + import com.sun.ts.tests.websocket.common.util.IOUtil; import jakarta.websocket.OnError; @@ -28,23 +31,24 @@ import jakarta.websocket.server.ServerEndpoint; @ServerEndpoint("/invalid") +@ExtendWith(ArquillianExtension.class) public class OnMessageServerEndpoint { - @OnMessage - public String echo(InputStream stream) throws IOException { - return IOUtil.readFromStream(stream); - } - - @SuppressWarnings("unused") - @OnMessage - public String echo(byte[] data, boolean finito) { - return new String(data); - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(InputStream stream) throws IOException { + return IOUtil.readFromStream(stream); + } + + @SuppressWarnings("unused") + @OnMessage + public String echo(byte[] data, boolean finito) { + return new String(data); + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryduplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryduplicate/WSCClient.java deleted file mode 100644 index 2179ebed58..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryduplicate/WSCClient.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.binaryduplicate; - -import java.nio.ByteBuffer; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain one binary message handling method. This test checks - * two such methods fail the deployment. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_srv_binaryduplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Each websocket endpoint may only have one message handling method for each - * of the native websocket message formats: text, binary and pong. The - * websocket implementation must not deploy such an endpoint and must raise a - * deployment error if an attempt is made to deploy such an annotated - * endpoint. [WSC-4.7-4] - * - * To check the test fails when deployment pass, comment out of the - * - * @OnMessage of OnMessageServerEndpoint - */ - public void duplicateOnMessageUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: duplicateOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Each websocket endpoint may only have one message handling method for each - * of the native websocket message formats: text, binary and pong. The - * websocket implementation must not deploy such an endpoint and must raise a - * deployment error if an attempt is made to deploy such an annotated - * endpoint. [WSC-4.7-4] - * - * To check the test fails when deployment pass, comment out of the - * - * @OnMessage of OnMessageServerEndpoint - */ - public void duplicateOnMessageTest() throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryduplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryduplicate/WSCClientIT.java new file mode 100644 index 0000000000..f4467626c5 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryduplicate/WSCClientIT.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.binaryduplicate; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain one binary message handling method. This test checks + * two such methods fail the deployment. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_negdep_onmessage_srv_binaryinputstreamboolean_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.srv.binaryduplicate"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_srv_binaryduplicate_web"); + } + + /* + * @testName: duplicateOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Each websocket endpoint may only have one message handling method for each of + * the native websocket message formats: text, binary and pong. The websocket + * implementation must not deploy such an endpoint and must raise a deployment + * error if an attempt is made to deploy such an annotated endpoint. [WSC-4.7-4] + * + * To check the test fails when deployment pass, comment out of the + * + * @OnMessage of OnMessageServerEndpoint + */ + @Test + public void duplicateOnMessageUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: duplicateOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Each websocket endpoint may only have one message handling method for each of + * the native websocket message formats: text, binary and pong. The websocket + * implementation must not deploy such an endpoint and must raise a deployment + * error if an attempt is made to deploy such an annotated endpoint. [WSC-4.7-4] + * + * To check the test fails when deployment pass, comment out of the + * + * @OnMessage of OnMessageServerEndpoint + */ + @Test + public void duplicateOnMessageTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryinputstreamboolean/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryinputstreamboolean/OnMessageServerEndpoint.java index 080fac35f0..4aa95f8cef 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryinputstreamboolean/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryinputstreamboolean/OnMessageServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,18 +30,18 @@ @ServerEndpoint("/invalid") public class OnMessageServerEndpoint { - @SuppressWarnings("unused") - @OnMessage - public String echo(InputStream stream, boolean finito) throws IOException { - String s = null; - s = IOUtil.readFromStream(stream); - return s; - } + @SuppressWarnings("unused") + @OnMessage + public String echo(InputStream stream, boolean finito) throws IOException { + String s = null; + s = IOUtil.readFromStream(stream); + return s; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryinputstreamboolean/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryinputstreamboolean/WSCClient.java deleted file mode 100644 index 9aad19c805..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryinputstreamboolean/WSCClient.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.binaryinputstreamboolean; - -import java.nio.ByteBuffer; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain ByteBuffer and boolean pair. This test checks that - * InputStream and boolean pair is out of this scope for partial - * messages. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_srv_binaryinputstreamboolean_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: inputStreamBooleanOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, comment out the int parameter - * in @OnMessage of OnMessageServerEndpoint - */ - public void inputStreamBooleanOnMessageUndeployOtherEndpointTest() - throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: inputStreamBooleanOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, comment out the int parameter - * in @OnMessage of OnMessageServerEndpoint - */ - public void inputStreamBooleanOnMessageTest() throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryinputstreamboolean/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryinputstreamboolean/WSCClientIT.java new file mode 100644 index 0000000000..86a18c3c62 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binaryinputstreamboolean/WSCClientIT.java @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.binaryinputstreamboolean; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain ByteBuffer and boolean pair. This test checks that + * InputStream and boolean pair is out of this scope for partial + * messages. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, + "wsc_negdep_onmessage_srv_binaryinputstreamboolean_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.srv.binaryinputstreamboolean"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_srv_binaryinputstreamboolean_web"); + } + + /* + * @testName: inputStreamBooleanOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, comment out the int parameter + * in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void inputStreamBooleanOnMessageUndeployOtherEndpointTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: inputStreamBooleanOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, comment out the int parameter + * in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void inputStreamBooleanOnMessageTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarynodecoder/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarynodecoder/OnMessageServerEndpoint.java index 8b244212a5..19760998af 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarynodecoder/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarynodecoder/OnMessageServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,17 +30,17 @@ @ServerEndpoint("/invalid") public class OnMessageServerEndpoint { - @OnMessage - public String echo(StringHolder holder) throws IOException { - String s = null; - s = holder.toString(); - return s; - } + @OnMessage + public String echo(StringHolder holder) throws IOException { + String s = null; + s = holder.toString(); + return s; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarynodecoder/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarynodecoder/WSCClient.java deleted file mode 100644 index c0f49b85b7..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarynodecoder/WSCClient.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.binarynodecoder; - -import java.nio.ByteBuffer; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain any object parameter for which the endpoint has a - * binary decoder Make sure the deployment fails where there is none - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_srv_binarynodecoder_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: noDecoderOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, switch StringHolder argument - * to byte[] in @OnMessage of OnMessageServerEndpoint - */ - public void noDecoderOnMessageUndeployOtherEndpointTest() throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: noDecoderOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, switch StringHolder argument - * to byte[] in @OnMessage of OnMessageServerEndpoint - */ - public void noDecoderOnMessageTest() throws Exception { - setEntity(ByteBuffer.wrap("anything".getBytes())); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarynodecoder/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarynodecoder/WSCClientIT.java new file mode 100644 index 0000000000..32f6abe027 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/binarynodecoder/WSCClientIT.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.binarynodecoder; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain any object parameter for which the endpoint has a + * binary decoder Make sure the deployment fails where there is none + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_srv_binarynodecoder_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.srv.binarynodecoder"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_srv_binarynodecoder_web"); + } + + /* + * @testName: noDecoderOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, switch StringHolder argument to + * byte[] in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void noDecoderOnMessageUndeployOtherEndpointTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: noDecoderOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, switch StringHolder argument to + * byte[] in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void noDecoderOnMessageTest() throws Exception { + setEntity(ByteBuffer.wrap("anything".getBytes())); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongboolean/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongboolean/OnMessageServerEndpoint.java index 63f43b8214..5c7b75af34 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongboolean/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongboolean/OnMessageServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,18 +30,18 @@ @ServerEndpoint("/invalid") public class OnMessageServerEndpoint { - @SuppressWarnings("unused") - @OnMessage - public String echo(PongMessage pong, boolean finito) { - String s = null; - s = IOUtil.byteBufferToString(pong.getApplicationData()); - return s; - } + @SuppressWarnings("unused") + @OnMessage + public String echo(PongMessage pong, boolean finito) { + String s = null; + s = IOUtil.byteBufferToString(pong.getApplicationData()); + return s; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongboolean/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongboolean/WSCClient.java deleted file mode 100644 index eda21bc6d3..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongboolean/WSCClient.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.pongboolean; - -import com.sun.ts.tests.websocket.common.impl.StringPongMessage; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain PongMessage. This test checks that PongMessage and - * boolean pair is undeployable. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_srv_pongboolean_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: pongMessageBooleanOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, comment out the boolean - * argument in @OnMessage of OnMessageServerEndpoint - */ - public void pongMessageBooleanOnMessageUndeployOtherEndpointTest() - throws Exception { - setEntity("anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: pongMessageBooleanOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, comment out the boolean - * argument in @OnMessage of OnMessageServerEndpoint - */ - public void pongMessageBooleanOnMessageTest() throws Exception { - setEntity(new StringPongMessage("anything")); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongboolean/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongboolean/WSCClientIT.java new file mode 100644 index 0000000000..cd623c18d5 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongboolean/WSCClientIT.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.pongboolean; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.impl.StringPongMessage; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain PongMessage. This test checks that PongMessage and + * boolean pair is undeployable. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_srv_pongboolean_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.srv.pongboolean"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_srv_pongboolean_web"); + } + + /* + * @testName: pongMessageBooleanOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, comment out the boolean + * argument in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void pongMessageBooleanOnMessageUndeployOtherEndpointTest() throws Exception { + setEntity("anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: pongMessageBooleanOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, comment out the boolean + * argument in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void pongMessageBooleanOnMessageTest() throws Exception { + setEntity(new StringPongMessage("anything")); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongduplicate/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongduplicate/OnMessageServerEndpoint.java index 5093932e94..7ec453d71b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongduplicate/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongduplicate/OnMessageServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,21 +30,21 @@ @ServerEndpoint("/invalid") public class OnMessageServerEndpoint { - @OnMessage - public String echo(PongMessage pong) { - return IOUtil.byteBufferToString(pong.getApplicationData()); - } - - @SuppressWarnings("unused") - @OnMessage - public String echo(PongMessage pong, Session session) { - return IOUtil.byteBufferToString(pong.getApplicationData()); - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(PongMessage pong) { + return IOUtil.byteBufferToString(pong.getApplicationData()); + } + + @SuppressWarnings("unused") + @OnMessage + public String echo(PongMessage pong, Session session) { + return IOUtil.byteBufferToString(pong.getApplicationData()); + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongduplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongduplicate/WSCClient.java deleted file mode 100644 index 1ecd4a9b9d..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongduplicate/WSCClient.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.pongduplicate; - -import com.sun.ts.tests.websocket.common.impl.StringPongMessage; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain one pong message handling method. This test checks two - * such methods fail the deployment. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_srv_pongduplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Each websocket endpoint may only have one message handling method for each - * of the native websocket message formats: text, binary and pong. The - * websocket implementation must not deploy such an endpoint and must raise a - * deployment error if an attempt is made to deploy such an annotated - * endpoint. [WSC-4.7-4] - * - * To check the test fails when deployment pass, comment out of the - * - * @OnMessage of OnMessageServerEndpoint - */ - public void duplicateOnMessageUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: duplicateOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Each websocket endpoint may only have one message handling method for each - * of the native websocket message formats: text, binary and pong. The - * websocket implementation must not deploy such an endpoint and must raise a - * deployment error if an attempt is made to deploy such an annotated - * endpoint. [WSC-4.7-4] - * - * To check the test fails when deployment pass, comment out of the - * - * @OnMessage of OnMessageServerEndpoint - */ - public void duplicateOnMessageTest() throws Exception { - setEntity(new StringPongMessage("anything")); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongduplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongduplicate/WSCClientIT.java new file mode 100644 index 0000000000..00866ab7f3 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/pongduplicate/WSCClientIT.java @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.pongduplicate; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.impl.StringPongMessage; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain one pong message handling method. This test checks two + * such methods fail the deployment. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_srv_pongduplicate_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.srv.pongduplicate"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_srv_pongduplicate_web"); + } + + /* + * @testName: duplicateOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Each websocket endpoint may only have one message handling method for each of + * the native websocket message formats: text, binary and pong. The websocket + * implementation must not deploy such an endpoint and must raise a deployment + * error if an attempt is made to deploy such an annotated endpoint. [WSC-4.7-4] + * + * To check the test fails when deployment pass, comment out of the + * + * @OnMessage of OnMessageServerEndpoint + */ + @Test + public void duplicateOnMessageUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: duplicateOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Each websocket endpoint may only have one message handling method for each of + * the native websocket message formats: text, binary and pong. The websocket + * implementation must not deploy such an endpoint and must raise a deployment + * error if an attempt is made to deploy such an annotated endpoint. [WSC-4.7-4] + * + * To check the test fails when deployment pass, comment out of the + * + * @OnMessage of OnMessageServerEndpoint + */ + @Test + public void duplicateOnMessageTest() throws Exception { + setEntity(new StringPongMessage("anything")); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textbigdecimal/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textbigdecimal/OnMessageServerEndpoint.java index c2fe01e810..a95d65819d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textbigdecimal/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textbigdecimal/OnMessageServerEndpoint.java @@ -30,15 +30,15 @@ @ServerEndpoint("/invalid") public class OnMessageServerEndpoint { - @OnMessage - public String echo(BigDecimal echo) { - return echo.toString(); - } + @OnMessage + public String echo(BigDecimal echo) { + return echo.toString(); + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textbigdecimal/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textbigdecimal/WSCClient.java deleted file mode 100644 index 9b85780ea8..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textbigdecimal/WSCClient.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.textbigdecimal; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain only java primitive types or the boxed version of it. - * This test checks the BigDecimal number is out of this scope - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_srv_textbigdecimal_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: bigdecimalArgumentsOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, change the bigdecimal - * parameter to String in @OnMessage of OnMessageServerEndpoint - */ - public void bigdecimalArgumentsOnMessageUndeployOtherEndpointTest() - throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: bigDecimalArgumentsOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, change the bigdecimal - * parameter to String in @OnMessage of OnMessageServerEndpoint - */ - public void bigDecimalArgumentsOnMessageTest() throws Exception { - setProperty(Property.CONTENT, "111"); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("111")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textbigdecimal/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textbigdecimal/WSCClientIT.java new file mode 100644 index 0000000000..3d12d07961 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textbigdecimal/WSCClientIT.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.textbigdecimal; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * tslib.name; + */ +/** + * @OnMessage can contain only java primitive types or the boxed version of it. + * This test checks the BigDecimal number is out of this scope + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_srv_textbigdecimal_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.srv.textbigdecimal"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_srv_textbigdecimal_web"); + } + + /* + * @testName: bigdecimalArgumentsOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, change the bigdecimal parameter + * to String in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void bigdecimalArgumentsOnMessageUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: bigDecimalArgumentsOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, change the bigdecimal parameter + * to String in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void bigDecimalArgumentsOnMessageTest() throws Exception { + setProperty(Property.CONTENT, "111"); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("111")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textduplicate/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textduplicate/OnMessageServerEndpoint.java index 01e317d2c2..1e11a80016 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textduplicate/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textduplicate/OnMessageServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,21 +30,21 @@ @ServerEndpoint("/invalid") public class OnMessageServerEndpoint { - @OnMessage - public String echo(Reader reader) throws IOException { - return IOUtil.readFromReader(reader); - } - - @SuppressWarnings("unused") - @OnMessage - public String echo(String echo, boolean finito) { - return echo; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(Reader reader) throws IOException { + return IOUtil.readFromReader(reader); + } + + @SuppressWarnings("unused") + @OnMessage + public String echo(String echo, boolean finito) { + return echo; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textduplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textduplicate/WSCClient.java deleted file mode 100644 index 6611d7f47a..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textduplicate/WSCClient.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.textduplicate; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain one text message handling method. This test checks two - * such methods fail the deployment. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_srv_textduplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Each websocket endpoint may only have one message handling method for each - * of the native websocket message formats: text, binary and pong. The - * websocket implementation must not deploy such an endpoint and must raise a - * deployment error if an attempt is made to deploy such an annotated - * endpoint. [WSC-4.7-4] - * - * To check the test fails when deployment pass, comment out of the - * - * @OnMessage of OnMessageServerEndpoint - */ - public void duplicateOnMessageUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: duplicateOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Each websocket endpoint may only have one message handling method for each - * of the native websocket message formats: text, binary and pong. The - * websocket implementation must not deploy such an endpoint and must raise a - * deployment error if an attempt is made to deploy such an annotated - * endpoint. [WSC-4.7-4] - * - * To check the test fails when deployment pass, comment out of the - * - * @OnMessage of OnMessageServerEndpoint - */ - public void duplicateOnMessageTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textduplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textduplicate/WSCClientIT.java new file mode 100644 index 0000000000..76864148bd --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textduplicate/WSCClientIT.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.textduplicate; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain one text message handling method. This test checks two + * such methods fail the deployment. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_srv_textduplicate_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.srv.textduplicate"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_srv_textduplicate_web"); + } + + /* + * @testName: duplicateOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Each websocket endpoint may only have one message handling method for each of + * the native websocket message formats: text, binary and pong. The websocket + * implementation must not deploy such an endpoint and must raise a deployment + * error if an attempt is made to deploy such an annotated endpoint. [WSC-4.7-4] + * + * To check the test fails when deployment pass, comment out of the + * + * @OnMessage of OnMessageServerEndpoint + */ + @Test + public void duplicateOnMessageUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: duplicateOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Each websocket endpoint may only have one message handling method for each of + * the native websocket message formats: text, binary and pong. The websocket + * implementation must not deploy such an endpoint and must raise a deployment + * error if an attempt is made to deploy such an annotated endpoint. [WSC-4.7-4] + * + * To check the test fails when deployment pass, comment out of the + * + * @OnMessage of OnMessageServerEndpoint + */ + @Test + public void duplicateOnMessageTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textnodecoder/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textnodecoder/OnMessageServerEndpoint.java index 06b1a1d516..aff5399c12 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textnodecoder/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textnodecoder/OnMessageServerEndpoint.java @@ -30,15 +30,15 @@ @ServerEndpoint("/invalid") public class OnMessageServerEndpoint { - @OnMessage - public String echo(StringHolder echo) { - return echo.toString(); - } + @OnMessage + public String echo(StringHolder echo) { + return echo.toString(); + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textnodecoder/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textnodecoder/WSCClient.java deleted file mode 100644 index 7d9b5bad10..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textnodecoder/WSCClient.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.textnodecoder; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain any java class the decoder for it exists. This test - * checks the StringHolder argument. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_srv_textnodecoder_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: noDecoderOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, switch the StringHolder - * argument to String in @OnMessage of OnMessageServerEndpoint - */ - public void noDecoderOnMessageUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: noDecoderOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, switch the StringHolder - * argument to String in @OnMessage of OnMessageServerEndpoint - */ - public void noDecoderOnMessageTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textnodecoder/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textnodecoder/WSCClientIT.java new file mode 100644 index 0000000000..0a856c228e --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textnodecoder/WSCClientIT.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2015, 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.textnodecoder; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain any java class the decoder for it exists. This test + * checks the StringHolder argument. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_srv_textnodecoder_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.srv.textnodecoder"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_srv_textnodecoder_web"); + } + + /* + * @testName: noDecoderOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, switch the StringHolder + * argument to String in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void noDecoderOnMessageUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: noDecoderOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, switch the StringHolder + * argument to String in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void noDecoderOnMessageTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textreaderboolean/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textreaderboolean/OnMessageServerEndpoint.java index 3f24a309d9..c1634968fc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textreaderboolean/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textreaderboolean/OnMessageServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,18 +30,18 @@ @ServerEndpoint("/invalid") public class OnMessageServerEndpoint { - @SuppressWarnings("unused") - @OnMessage - public String echo(Reader reader, boolean finito) throws IOException { - String s = null; - s = IOUtil.readFromReader(reader); - return s; - } + @SuppressWarnings("unused") + @OnMessage + public String echo(Reader reader, boolean finito) throws IOException { + String s = null; + s = IOUtil.readFromReader(reader); + return s; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textreaderboolean/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textreaderboolean/WSCClient.java deleted file mode 100644 index ff347fa6d5..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textreaderboolean/WSCClient.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.textreaderboolean; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain String and boolean pair. This test checks that Reader - * and boolean pair is out of this scope for partial messages. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_srv_textreaderboolean_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: tooManyArgumentsOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, comment out the boolean - * parameter in @OnMessage of OnMessageServerEndpoint - */ - public void tooManyArgumentsOnMessageUndeployOtherEndpointTest() - throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: tooManyArgumentsOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, comment out the boolean - * parameter in @OnMessage of OnMessageServerEndpoint - */ - public void tooManyArgumentsOnMessageTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textreaderboolean/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textreaderboolean/WSCClientIT.java new file mode 100644 index 0000000000..9dacaa862b --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textreaderboolean/WSCClientIT.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.textreaderboolean; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ts_home; + * ws_wait; + * tslib.name; + */ +/** + * @OnMessage can contain String and boolean pair. This test checks that Reader + * and boolean pair is out of this scope for partial messages. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_srv_textreaderboolean_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.srv.textreaderboolean"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_srv_textreaderboolean_web"); + } + + /* + * @testName: tooManyArgumentsOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, comment out the boolean + * parameter in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void tooManyArgumentsOnMessageUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: tooManyArgumentsOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, comment out the boolean + * parameter in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void tooManyArgumentsOnMessageTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textstringint/OnMessageServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textstringint/OnMessageServerEndpoint.java index b8aa5aa390..d7391d0152 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textstringint/OnMessageServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textstringint/OnMessageServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,16 +29,16 @@ @ServerEndpoint("/invalid") public class OnMessageServerEndpoint { - @SuppressWarnings("unused") - @OnMessage - public String echo(String echo, int i) { - return echo; - } + @SuppressWarnings("unused") + @OnMessage + public String echo(String echo, int i) { + return echo; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textstringint/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textstringint/WSCClient.java deleted file mode 100644 index 92aaac69de..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textstringint/WSCClient.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.textstringint; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @OnMessage can contain String and boolean pair. This test checks that String - * and int pair is out of this scope. - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onmessage_srv_textstringint_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: tooManyArgumentsOnMessageUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, comment out the int parameter - * in @OnMessage of OnMessageServerEndpoint - */ - public void tooManyArgumentsOnMessageUndeployOtherEndpointTest() - throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: tooManyArgumentsOnMessageTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any method annotated with @OnMessage that does not conform to the forms - * defied therein is invalid. The websocket implementation must not deploy - * such an endpoint and must raise a deployment error if an attempt is made to - * deploy such an annotated endpoint. [WSC-4.7-1] - * - * To check the test fails when deployment pass, comment out the int parameter - * in @OnMessage of OnMessageServerEndpoint - */ - public void tooManyArgumentsOnMessageTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textstringint/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textstringint/WSCClientIT.java new file mode 100644 index 0000000000..4c7be0c64e --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onmessage/srv/textstringint/WSCClientIT.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onmessage.srv.textstringint; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @OnMessage can contain String and boolean pair. This test checks that String + * and int pair is out of this scope. + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onmessage_srv_textstringint_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.negdep.onmessage.srv.textstringint"); + archive.addPackages(false, Filters.exclude(NegativeDeploymentClient.class), + "com.sun.ts.tests.websocket.negdep"); + archive.addPackages(true, "com.sun.ts.tests.websocket.common.stringbean"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onmessage_srv_textstringint_web"); + } + + /* + * @testName: tooManyArgumentsOnMessageUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, comment out the int parameter + * in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void tooManyArgumentsOnMessageUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: tooManyArgumentsOnMessageTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.7-1; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any method annotated with @OnMessage that does not conform to the forms + * defied therein is invalid. The websocket implementation must not deploy such + * an endpoint and must raise a deployment error if an attempt is made to deploy + * such an annotated endpoint. [WSC-4.7-1] + * + * To check the test fails when deployment pass, comment out the int parameter + * in @OnMessage of OnMessageServerEndpoint + */ + @Test + public void tooManyArgumentsOnMessageTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/duplicate/AnnotatedOnOpenClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/duplicate/AnnotatedOnOpenClientEndpoint.java index b24ef2e0aa..3677a37ee1 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/duplicate/AnnotatedOnOpenClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/duplicate/AnnotatedOnOpenClientEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2017, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,35 +29,34 @@ import jakarta.websocket.Session; @ClientEndpoint -public class AnnotatedOnOpenClientEndpoint - extends AnnotatedStringClientEndpoint { - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } - - @OnOpen - public void onOpen2(Session session, EndpointConfig config) { - clientEndpoint.onOpen(session, config, false); - } - - @Override - @OnMessage - public void onMessage(String msg) { - clientEndpoint.onMessage(msg); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - clientEndpoint.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } +public class AnnotatedOnOpenClientEndpoint extends AnnotatedStringClientEndpoint { + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } + + @OnOpen + public void onOpen2(Session session, EndpointConfig config) { + clientEndpoint.onOpen(session, config, false); + } + + @Override + @OnMessage + public void onMessage(String msg) { + clientEndpoint.onMessage(msg); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + clientEndpoint.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/duplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/duplicate/WSCClient.java deleted file mode 100644 index 9a84120203..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/duplicate/WSCClient.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onopen.client.duplicate; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onopen_client_duplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOnClientTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.4-3] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To verify the test fails when the deployment was successful, comment out - * one of the @OnOpen methods of OnOpenServerEndpoint - */ - public void duplicateOnClientTest() throws Exception { - AnnotatedOnOpenClientEndpoint endpoint = new AnnotatedOnOpenClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/duplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/duplicate/WSCClientIT.java new file mode 100644 index 0000000000..eaab65a962 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/duplicate/WSCClientIT.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onopen.client.duplicate; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onopen_client_duplicate_web.war"); + archive.addClasses(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onopen_client_duplicate_web"); + } + + /* + * @testName: duplicateOnClientTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.4-3] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To verify the test fails when the deployment was successful, comment out one + * of the @OnOpen methods of OnOpenServerEndpoint + */ + @Test + public void duplicateOnClientTest() throws Exception { + AnnotatedOnOpenClientEndpoint endpoint = new AnnotatedOnOpenClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(false); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } + +} \ No newline at end of file diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/toomanyargs/AnnotatedOnOpenClientEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/toomanyargs/AnnotatedOnOpenClientEndpoint.java index 854588a94d..42d9fcc491 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/toomanyargs/AnnotatedOnOpenClientEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/toomanyargs/AnnotatedOnOpenClientEndpoint.java @@ -29,31 +29,29 @@ import jakarta.websocket.Session; @ClientEndpoint -public class AnnotatedOnOpenClientEndpoint - extends AnnotatedStringClientEndpoint { - - @SuppressWarnings("unused") - @OnOpen - public void onOpen(Session session, EndpointConfig config, - Throwable throwable) { - clientEndpoint.onOpen(session, config, false); - } - - @Override - @OnMessage - public void onMessage(String msg) { - clientEndpoint.onMessage(msg); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - clientEndpoint.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - clientEndpoint.onError(session, t); - } +public class AnnotatedOnOpenClientEndpoint extends AnnotatedStringClientEndpoint { + + @SuppressWarnings("unused") + @OnOpen + public void onOpen(Session session, EndpointConfig config, Throwable throwable) { + clientEndpoint.onOpen(session, config, false); + } + + @Override + @OnMessage + public void onMessage(String msg) { + clientEndpoint.onMessage(msg); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + clientEndpoint.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + clientEndpoint.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/toomanyargs/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/toomanyargs/WSCClient.java deleted file mode 100644 index c6ab2d7ed2..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/toomanyargs/WSCClient.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.negdep.onopen.client.toomanyargs; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onopen_client_toomanyarguments_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: tooManyArgumentsOnOpenTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; - * WebSocket:SPEC:WSC-5.2.1-4; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.4-3] - * - * If the deployment error occurs under the programmatic control of the - * developer, for example, when using the WebSocketContainer API to deploy a - * client endpoint, deployment errors must be reported by the container to the - * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] - * - * To verify the test fails when the deployment was successful, remove the - * String value in @OnOpen of OnOpenServerEndpoint - */ - public void tooManyArgumentsOnOpenTest() throws Exception { - AnnotatedOnOpenClientEndpoint endpoint = new AnnotatedOnOpenClientEndpoint(); - setAnnotatedClientEndpoint(endpoint); - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - logExceptionOnInvocation(false); - printClientCall(false); - boolean thrown = true; - try { - invoke(false); - thrown = false; - } catch (Exception tfe) { - // DeploymentException - assertCause(tfe, DeploymentException.class, - "The DeploymentException has not been thrown!"); - tfe.printStackTrace(); - logMsg("--\n\n"); - logMsg("DeploymentException has been thrown as expected"); - } - if (!thrown) - super.throwDeploymentDidNotFail(); - - boolean isSession = false; - try { - getSession(); - isSession = true; - } catch (Exception f) { - // did not succeeded - TestUtil.logMsg("The session is closed as expected"); - } - if (isSession) { - TestUtil.logErr("Session is not null!"); - throw new Exception("Session is not null! Deployment succeeded"); - } - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/toomanyargs/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/toomanyargs/WSCClientIT.java new file mode 100644 index 0000000000..537900e7ca --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/client/toomanyargs/WSCClientIT.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.negdep.onopen.client.toomanyargs; + + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; +import com.sun.ts.tests.websocket.negdep.StringHolder; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onopen_client_toomanyarguments_web.war"); + archive.addClasses(EchoServerEndpoint.class, StringHolder.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onopen_client_toomanyarguments_web"); + } + + /* + * @testName: tooManyArgumentsOnOpenTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; + * WebSocket:SPEC:WSC-5.2.1-4; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.4-3] + * + * If the deployment error occurs under the programmatic control of the + * developer, for example, when using the WebSocketContainer API to deploy a + * client endpoint, deployment errors must be reported by the container to the + * developer by using an instance of the DeploymentException. [WSC-5.2.1-4] + * + * To verify the test fails when the deployment was successful, remove the + * String value in @OnOpen of OnOpenServerEndpoint + */ + @Test + public void tooManyArgumentsOnOpenTest() throws Exception { + AnnotatedOnOpenClientEndpoint endpoint = new AnnotatedOnOpenClientEndpoint(); + setAnnotatedClientEndpoint(endpoint); + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + logExceptionOnInvocation(false); + printClientCall(true); + boolean thrown = true; + try { + invoke(false); + thrown = false; + } catch (Exception tfe) { + // DeploymentException + assertCause(tfe, DeploymentException.class, "The DeploymentException has not been thrown!"); + tfe.printStackTrace(); + logMsg("--\n\n"); + logMsg("DeploymentException has been thrown as expected"); + } + if (!thrown) + super.throwDeploymentDidNotFail(); + + boolean isSession = false; + try { + getSession(); + isSession = true; + } catch (Exception f) { + // did not succeeded + TestUtil.logMsg("The session is closed as expected"); + } + if (isSession) { + TestUtil.logErr("Session is not null!"); + throw new Exception("Session is not null! Deployment succeeded"); + } + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/duplicate/OnOpenServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/duplicate/OnOpenServerEndpoint.java index eaa301f944..8a05b42c07 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/duplicate/OnOpenServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/duplicate/OnOpenServerEndpoint.java @@ -30,29 +30,30 @@ @ServerEndpoint("/invalid") public class OnOpenServerEndpoint { - private String open; - - @OnMessage - public String echo(String echo) { - return open + echo; - } - - @SuppressWarnings("unused") - @OnOpen - public void onOpen(Session session) { - open = "session"; - } - - @SuppressWarnings("unused") - @OnOpen - public void onOpen(EndpointConfig config) { - open = "config"; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + + private String open; + + @OnMessage + public String echo(String echo) { + return open + echo; + } + + @SuppressWarnings("unused") + @OnOpen + public void onOpen(Session session) { + open = "session"; + } + + @SuppressWarnings("unused") + @OnOpen + public void onOpen(EndpointConfig config) { + open = "config"; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/duplicate/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/duplicate/WSCClient.java deleted file mode 100644 index 43f6d52c60..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/duplicate/WSCClient.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onopen.srv.duplicate; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onopen_srv_duplicate_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: duplicateOfOnOpenUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The value attribute of this annotation must be present otherwise the - * implementation must throw an error. [WSC-4.4-3] - * - * To verify the test fails when the deployment was successful, comment out - * one of the @OnOpen methods of OnOpenServerEndpoint - */ - public void duplicateOfOnOpenUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: duplicateOfOnOpenTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.4-3] - * - * To verify the test fails when the deployment was successful, comment out - * one of the @OnOpen methods of OnOpenServerEndpoint - */ - public void duplicateOfOnOpenTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/duplicate/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/duplicate/WSCClientIT.java new file mode 100644 index 0000000000..2f66e69a8b --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/duplicate/WSCClientIT.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onopen.srv.duplicate; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onopen_srv_duplicate_web.war"); + archive.addClasses(OnOpenServerEndpoint.class); + archive.addClasses(EchoServerEndpoint.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onopen_srv_duplicate_web"); + } + + /* + * @testName: duplicateOfOnOpenUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The value attribute of this annotation must be present otherwise the + * implementation must throw an error. [WSC-4.4-3] + * + * To verify the test fails when the deployment was successful, comment out one + * of the @OnOpen methods of OnOpenServerEndpoint + */ + @Test + public void duplicateOfOnOpenUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: duplicateOfOnOpenTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.4-3] + * + * To verify the test fails when the deployment was successful, comment out one + * of the @OnOpen methods of OnOpenServerEndpoint + */ + @Test + public void duplicateOfOnOpenTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/toomanyargs/OnOpenServerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/toomanyargs/OnOpenServerEndpoint.java index c127490b8a..aea6259707 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/toomanyargs/OnOpenServerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/toomanyargs/OnOpenServerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2015, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -29,23 +29,24 @@ @ServerEndpoint("/invalid") public class OnOpenServerEndpoint { - private String open; - - @OnMessage - public String echo(String echo) { - return open + echo; - } - - @SuppressWarnings("unused") - @OnOpen - public void onOpen(Session session, String thisShouldNotBeHere) { - open = "thisShouldNotBeHere"; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + + private String open; + + @OnMessage + public String echo(String echo) { + return open + echo; + } + + @SuppressWarnings("unused") + @OnOpen + public void onOpen(Session session, String thisShouldNotBeHere) { + open = "thisShouldNotBeHere"; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/toomanyargs/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/toomanyargs/WSCClient.java deleted file mode 100644 index fa3563f5c2..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/toomanyargs/WSCClient.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onopen.srv.toomanyargs; - -import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * tslib.name; - */ -/** - * @since 1.11 - */ -public class WSCClient extends NegativeDeploymentClient { - - private static final long serialVersionUID = 111L; - - public WSCClient() { - setContextRoot("wsc_negdep_onopen_srv_toomanyarguments_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: tooManyArgumentsOnOpenUndeployOtherEndpointTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * The value attribute of this annotation must be present otherwise the - * implementation must throw an error. [WSC-4.4-3] - * - * To verify the test fails when the deployment was successful, remove the - * String value in @OnOpen of OnOpenServerEndpoint - */ - public void tooManyArgumentsOnOpenUndeployOtherEndpointTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("echo")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if ("anything".equals(response)) - throwValidEndpointMustBeRemoved(); - } - - /* - * @testName: tooManyArgumentsOnOpenTest - * - * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; - * - * @test_Strategy: In both cases, a deployment error raised during the - * deployment process must halt the deployment of the application, any well - * formed endpoints deployed prior to the error being raised must be removed - * from service and no more websocket endpoints from that application may be - * deployed by the container, even if they are valid. - * - * Any Java class using this annotation on a method that does not follow these - * rules, or that uses this annotation on more than one method may not be - * deployed by the implementation and the error reported to the deployer. - * [WSC-4.4-3] - * - * To verify the test fails when the deployment was successful, remove the - * String value in @OnOpen of OnOpenServerEndpoint - */ - public void tooManyArgumentsOnOpenTest() throws Exception { - setProperty(Property.CONTENT, "anything"); - setProperty(Property.REQUEST, buildRequest("invalid")); - setProperty(Property.STATUS_CODE, "-1"); - // logExceptionOnInvocation(false); - try { - invoke(false); - } catch (Exception tfe) { - // DeploymentException - } - String response = getResponseAsString(); - if (response != null && response.contains("anything")) - throwValidEndpointMustBeRemoved(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/toomanyargs/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/toomanyargs/WSCClientIT.java new file mode 100644 index 0000000000..6c1942e159 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/negdep/onopen/srv/toomanyargs/WSCClientIT.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2015, 2018 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 com.sun.ts.tests.websocket.negdep.onopen.srv.toomanyargs; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.negdep.EchoServerEndpoint; +import com.sun.ts.tests.websocket.negdep.NegativeDeploymentClient; +import com.sun.ts.tests.websocket.negdep.StringHolder; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * lib.name; + */ +/** + * @since 1.11 + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends NegativeDeploymentClient { + + private static final long serialVersionUID = 111L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_negdep_onopen_srv_toomanyarguments_web.war"); + archive.addClasses(OnOpenServerEndpoint.class); + archive.addClasses(EchoServerEndpoint.class, StringHolder.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_negdep_onopen_srv_toomanyarguments_web"); + } + + /* + * @testName: tooManyArgumentsOnOpenUndeployOtherEndpointTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * The value attribute of this annotation must be present otherwise the + * implementation must throw an error. [WSC-4.4-3] + * + * To verify the test fails when the deployment was successful, remove the + * String value in @OnOpen of OnOpenServerEndpoint + */ + @Test + public void tooManyArgumentsOnOpenUndeployOtherEndpointTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("echo")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if ("anything".equals(response)) + throwValidEndpointMustBeRemoved(); + } + + /* + * @testName: tooManyArgumentsOnOpenTest + * + * @assertion_ids: WebSocket:SPEC:WSC-5.2.1-3;WebSocket:SPEC:WSC-4.4-3; + * + * @test_Strategy: In both cases, a deployment error raised during the + * deployment process must halt the deployment of the application, any well + * formed endpoints deployed prior to the error being raised must be removed + * from service and no more websocket endpoints from that application may be + * deployed by the container, even if they are valid. + * + * Any Java class using this annotation on a method that does not follow these + * rules, or that uses this annotation on more than one method may not be + * deployed by the implementation and the error reported to the deployer. + * [WSC-4.4-3] + * + * To verify the test fails when the deployment was successful, remove the + * String value in @OnOpen of OnOpenServerEndpoint + */ + @Test + public void tooManyArgumentsOnOpenTest() throws Exception { + setProperty(Property.CONTENT, "anything"); + setProperty(Property.REQUEST, buildRequest("invalid")); + setProperty(Property.STATUS_CODE, "-1"); + // logExceptionOnInvocation(false); + try { + invoke(false); + } catch (Exception tfe) { + // DeploymentException + } + String response = getResponseAsString(); + if (response != null && response.contains("anything")) + throwValidEndpointMustBeRemoved(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSClient.java deleted file mode 100644 index 6ff1e16953..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSClient.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2013, 2020 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 com.sun.ts.tests.websocket.platform.cdi; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 5295841512141568599L; - - public WSClient() { - setContextRoot("wsc_platform_cdi_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - /* - * @testName: cdiFieldTest - * - * @assertion_ids: WebSocket:SPEC:WSC-7.1.1-1; - * - * @test_Strategy: Websocket endpoints running in the Java EE platform must - * have full dependency injection support as described in the CDI - * specification. Websocket implementations part of the Java EE platform are - * required to support field, injection using the jakarta.inject.Inject - * annotation into all endpoint classes - */ - public void cdiFieldTest() throws Exception { - String msg = "field"; - setProperty(Property.REQUEST, buildRequest(msg)); - setProperty(Property.CONTENT, msg); - setProperty(Property.SEARCH_STRING, msg); - setProperty(Property.SEARCH_STRING, WSInjectableServer.class.getName()); - invoke(); - } - - /* - * @testName: cdiMethodTest - * - * @assertion_ids: WebSocket:SPEC:WSC-7.1.1-1; - * - * @test_Strategy: Websocket endpoints running in the Java EE platform must - * have full dependency injection support as described in the CDI - * specification. Websocket implementations part of the Java EE platform are - * required to support method injection using the jakarta.inject.Inject - * annotation into all endpoint classes - */ - public void cdiMethodTest() throws Exception { - String msg = "method"; - setProperty(Property.REQUEST, buildRequest(msg)); - setProperty(Property.CONTENT, msg); - setProperty(Property.SEARCH_STRING, msg); - setProperty(Property.SEARCH_STRING, WSInjectableServer.class.getName()); - invoke(); - } - - /* - * @testName: cdiConstructorTest - * - * @assertion_ids: WebSocket:SPEC:WSC-7.1.1-1; - * - * @test_Strategy: Websocket endpoints running in the Java EE platform must - * have full dependency injection support as described in the CDI - * specification. Websocket implementations part of the Java EE platform are - * required to support constructor injection using the jakarta.inject.Inject - * annotation into all endpoint classes - */ - public void cdiConstructorTest() throws Exception { - String msg = "constructor"; - setProperty(Property.REQUEST, buildRequest(msg)); - setProperty(Property.CONTENT, msg); - setProperty(Property.SEARCH_STRING, msg); - setProperty(Property.SEARCH_STRING, WSInjectableServer.class.getName()); - invoke(); - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSClientIT.java new file mode 100644 index 0000000000..93523fe2c6 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSClientIT.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.platform.cdi; + +import java.io.IOException; +import java.io.InputStream; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.authenticated.WSCClientIT; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 5295841512141568599L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_platform_cdi_web.war"); + + InputStream beansStream = WSClientIT.class.getClassLoader().getResourceAsStream("com/sun/ts/tests/websocket/platform/cdi/beans.xml"); + archive.addPackages(true, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.platform.cdi"); + archive.addClasses(IOUtil.class); + archive.addAsWebInfResource(WSCClientIT.class.getPackage(), "web.xml", "web.xml"); + archive.addAsWebInfResource(new StringAsset(toString(beansStream)), "beans.xml"); + return archive; + }; + + + public WSClientIT() throws Exception { + setup(); + setContextRoot("wsc_platform_cdi_web"); + } + + /* Run test */ + + /* + * @testName: cdiFieldTest + * + * @assertion_ids: WebSocket:SPEC:WSC-7.1.1-1; + * + * @test_Strategy: Websocket endpoints running in the Java EE platform must have + * full dependency injection support as described in the CDI specification. + * Websocket implementations part of the Java EE platform are required to + * support field, injection using the jakarta.inject.Inject annotation into all + * endpoint classes + */ + @Test + public void cdiFieldTest() throws Exception { + String msg = "field"; + setProperty(Property.REQUEST, buildRequest(msg)); + setProperty(Property.CONTENT, msg); + setProperty(Property.SEARCH_STRING, msg); + setProperty(Property.SEARCH_STRING, WSInjectableServer.class.getName()); + invoke(); + } + + /* + * @testName: cdiMethodTest + * + * @assertion_ids: WebSocket:SPEC:WSC-7.1.1-1; + * + * @test_Strategy: Websocket endpoints running in the Java EE platform must have + * full dependency injection support as described in the CDI specification. + * Websocket implementations part of the Java EE platform are required to + * support method injection using the jakarta.inject.Inject annotation into all + * endpoint classes + */ + @Test + public void cdiMethodTest() throws Exception { + String msg = "method"; + setProperty(Property.REQUEST, buildRequest(msg)); + setProperty(Property.CONTENT, msg); + setProperty(Property.SEARCH_STRING, msg); + setProperty(Property.SEARCH_STRING, WSInjectableServer.class.getName()); + invoke(); + } + + /* + * @testName: cdiConstructorTest + * + * @assertion_ids: WebSocket:SPEC:WSC-7.1.1-1; + * + * @test_Strategy: Websocket endpoints running in the Java EE platform must have + * full dependency injection support as described in the CDI specification. + * Websocket implementations part of the Java EE platform are required to + * support constructor injection using the jakarta.inject.Inject annotation into + * all endpoint classes + */ + @Test + public void cdiConstructorTest() throws Exception { + String msg = "constructor"; + setProperty(Property.REQUEST, buildRequest(msg)); + setProperty(Property.CONTENT, msg); + setProperty(Property.SEARCH_STRING, msg); + setProperty(Property.SEARCH_STRING, WSInjectableServer.class.getName()); + invoke(); + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSConstructorServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSConstructorServer.java index 4c10b80bca..c3c039e3e5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSConstructorServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSConstructorServer.java @@ -32,30 +32,30 @@ @ApplicationScoped public class WSConstructorServer { - private WSInjectableServer injectableServer; - - @OnMessage - public String inject(String echo) { - if (injectableServer == null) - return "Nothing injected using CDI"; - return injectableServer.getName(echo); - } - - @Inject - public WSConstructorServer(WSInjectableServer injectableServer) { - this.injectableServer = injectableServer; - } - - public WSConstructorServer() { - // This one is mandatory when @Inject constructor - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + private WSInjectableServer injectableServer; + + @OnMessage + public String inject(String echo) { + if (injectableServer == null) + return "Nothing injected using CDI"; + return injectableServer.getName(echo); + } + + @Inject + public WSConstructorServer(WSInjectableServer injectableServer) { + this.injectableServer = injectableServer; + } + + public WSConstructorServer() { + // This one is mandatory when @Inject constructor + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSFieldServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSFieldServer.java index 91091b8c6b..2321dda3b8 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSFieldServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSFieldServer.java @@ -31,22 +31,22 @@ @ServerEndpoint("/field") @ApplicationScoped public class WSFieldServer { - @Inject - private WSInjectableServer injectableServer; - - @OnMessage - public String inject(String echo) { - if (injectableServer == null) - return "Nothing injected using CDI"; - return injectableServer.getName(echo); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @Inject + private WSInjectableServer injectableServer; + + @OnMessage + public String inject(String echo) { + if (injectableServer == null) + return "Nothing injected using CDI"; + return injectableServer.getName(echo); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSInjectableServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSInjectableServer.java index 2ad82c4eed..b3e7f3cea9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSInjectableServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSInjectableServer.java @@ -31,16 +31,16 @@ @ApplicationScoped public class WSInjectableServer { - @OnMessage - public String getName(String echo) { - return echo + " " + getClass().getName(); - } + @OnMessage + public String getName(String echo) { + return echo + " " + getClass().getName(); + } - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSMethodServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSMethodServer.java index 19ccfc1716..e01ea4b5ee 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSMethodServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/cdi/WSMethodServer.java @@ -31,26 +31,26 @@ @ServerEndpoint("/method") @ApplicationScoped public class WSMethodServer { - WSInjectableServer injectableServer; - - @OnMessage - public String inject(String echo) { - if (injectableServer == null) - return "Nothing injected using CDI"; - return injectableServer.getName(echo); - } - - @Inject - private void setInjectableServer(WSInjectableServer injectableServer) { - this.injectableServer = injectableServer; - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + WSInjectableServer injectableServer; + + @OnMessage + public String inject(String echo) { + if (injectableServer == null) + return "Nothing injected using CDI"; + return injectableServer.getName(echo); + } + + @Inject + private void setInjectableServer(WSInjectableServer injectableServer) { + this.injectableServer = injectableServer; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/AppConfig.java index 01bd1b5432..81390e4d96 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/AppConfig.java @@ -29,20 +29,19 @@ */ public class AppConfig implements ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + return set; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(WSCGetUserPrincipalServer.class); - set.add(WSCIsUserInRoleServer.class); - set.add(WSCUnauthEchoServer.class); - set.add(WSCPostUnauthEchoServer.class); - return set; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(WSCGetUserPrincipalServer.class); + set.add(WSCIsUserInRoleServer.class); + set.add(WSCUnauthEchoServer.class); + set.add(WSCPostUnauthEchoServer.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/GetUserPrincipalConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/GetUserPrincipalConfigurator.java index bc9fdf68ed..0a940a10a9 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/GetUserPrincipalConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/GetUserPrincipalConfigurator.java @@ -26,13 +26,12 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class GetUserPrincipalConfigurator extends Configurator { - static final String KEY = "GetUserPrincipalConfigurator"; + static final String KEY = "GetUserPrincipalConfigurator"; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - Principal principal = request.getUserPrincipal(); - String value = principal == null ? "NULL" : principal.getName(); - response.getHeaders().put(KEY, Arrays.asList(value)); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + Principal principal = request.getUserPrincipal(); + String value = principal == null ? "NULL" : principal.getName(); + response.getHeaders().put(KEY, Arrays.asList(value)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/IsUserInRoleConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/IsUserInRoleConfigurator.java index 10481796b6..0307840ac0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/IsUserInRoleConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/IsUserInRoleConfigurator.java @@ -25,14 +25,13 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class IsUserInRoleConfigurator extends Configurator { - static final String KEY = "IsUserInRoleConfigurator"; + static final String KEY = "IsUserInRoleConfigurator"; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - String role = request.getHeaders().get(KEY).iterator().next(); - boolean isInRole = request.isUserInRole(role); - String value = String.valueOf(isInRole); - response.getHeaders().put(KEY, Arrays.asList(value)); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + String role = request.getHeaders().get(KEY).iterator().next(); + boolean isInRole = request.isUserInRole(role); + String value = String.valueOf(isInRole); + response.getHeaders().put(KEY, Arrays.asList(value)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCClient.java deleted file mode 100644 index 15b818c874..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCClient.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.authenticated; - -import java.util.Properties; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; - -/* - * The tests here are not guaranteed to pass in standalone TCK, hence it is put - * into full CTS bundle - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * user; - * password; - */ -public class WSCClient extends WebSocketCommonClient { - - private static final long serialVersionUID = -5851958128006729743L; - - String user; - - String password; - - public WSCClient() { - setContextRoot( - "wsc_platform_jakarta_websocket_handshakeresponse_authenticated_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - @Override - public void setup(String[] args, Properties p) throws Exception { - user = assertProperty(p, "user"); - password = assertProperty(p, "password"); - super.setup(args, p); - } - - /* - * @testName: getUserPrincipalTest - * - * @assertion_ids: WebSocket:JAVADOC:179; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-8.3-1; - * WebSocket:SPEC:WSC-7.2-2; - * - * @test_Strategy: HandshakeRequest.getUserPrincipal - * HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake A transport guarantee of - * NONE - * - * Similarly, if the opening handshake request is already authenticated with - * the server, the opening handshake API allows the developer to query the - * user Principal of the request. If the connection is established with the - * requesting client, the websocket implementation considers the user - * Principal for the associated websocket Session to be the user Principal - * that was present on the opening handshake. - * - * Return the authenticated user - */ - public void getUserPrincipalTest() throws Exception { - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse(GetUserPrincipalConfigurator.KEY, - String.valueOf(user)); - addClientConfigurator(configurator); - addAuthorisation(); - invoke("auth/getuserprincipal", "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: isUserInRoleTest - * - * @assertion_ids: WebSocket:JAVADOC:180; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-8.3-1; - * - * @test_Strategy: HandshakeRequest.isUserInRole HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake A transport guarantee of - * NONE - */ - public void isUserInRoleTest() throws Exception { - // check DIRECTOR role is not known - // and set staff role to check - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse(IsUserInRoleConfigurator.KEY, - String.valueOf(false)); - configurator.addToRequest(IsUserInRoleConfigurator.KEY, "DIRECTOR"); - addClientConfigurator(configurator); - addAuthorisation(); - invoke("auth/isuserinrole", "anything", "anything"); - configurator.assertBeforeRequestHasBeenCalled(); - configurator.assertAfterResponseHasBeenCalled(); - - // check the user is in staff role - configurator = new ClientConfigurator(); - configurator.addToResponse(IsUserInRoleConfigurator.KEY, - String.valueOf(true)); - configurator.addToRequest(IsUserInRoleConfigurator.KEY, "staff"); - addAuthorisation(); - addClientConfigurator(configurator); - invoke("auth/isuserinrole", "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - configurator.assertBeforeRequestHasBeenCalled(); - } - - /* - * @testName: isNotAuthenticatedTest - * - * @assertion_ids: WebSocket:SPEC:WSC-8.1-1; WebSocket:SPEC:WSC-8.3-1; - * - * @test_Strategy: the websocket implementation must return a 401 - * (Unauthorized) response to the opening handshake request and may not - * initiate a websocket connection A transport guarantee of NONE - * - * 401 is not possible to check, but the websocket connection we can check - */ - public void isNotAuthenticatedTest() throws Exception { - boolean connection = false; - try { - logExceptionOnInvocation(false); - invoke("auth/isuserinrole", "staff", "staff"); - connection = true; - } catch (Exception f) { - logMsg("The connection was not initiated as expected:", - getCauseMessage(f)); - } - assertFalse(connection, - "The connection is initiated and 401 response was not returned"); - } - - /* - * @testName: authorizationIsNotUsedForUrlTest - * - * @assertion_ids: WebSocket:SPEC:WSC-8.3-1; WebSocket:SPEC:WSC-8.2-1; - * - * @test_Strategy: The used in the security constraint must be - * used by the container to match the request URI of the opening handshake of - * the websocket A transport guarantee of NONE - */ - public void authorizationIsNotUsedForUrlTest() throws Exception { - invoke("unauth/echo", "echo", "echo"); - } - - /* - * @testName: authorizationIsNotAppliedForPOSTTest - * - * @assertion_ids: WebSocket:SPEC:WSC-8.2-2; WebSocket:SPEC:WSC-8.3-1; - * - * @test_Strategy: The implementation must interpret any http-method other - * than GET (or the default, missing) as not applying to the websocket. A - * transport guarantee of NONE - */ - public void authorizationIsNotAppliedForPOSTTest() throws Exception { - invoke("post/echo", "echo", "echo"); - } - - // ///////////////////////////////////////////////////////////////////// - void addAuthorisation() { - setProperty(Property.BASIC_AUTH_USER, user); - setProperty(Property.BASIC_AUTH_PASSWD, password); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCClientIT.java new file mode 100644 index 0000000000..a818d3a70c --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCClientIT.java @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.authenticated; + +import java.io.IOException; +import java.util.Properties; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +/* + * The tests here are not guaranteed to pass in standalone TCK, hence it is put + * into full CTS bundle + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * user; + * password; + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = -5851958128006729743L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_platform_jakarta_websocket_handshakeresponse_authenticated_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.authenticated"); + archive.addClasses(IOUtil.class); + archive.addAsWebInfResource(WSCClientIT.class.getPackage(), "web.xml", "web.xml"); + return archive; + }; + + + String user; + + String password; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_platform_jakarta_websocket_handshakeresponse_authenticated_web"); + } + + public void setup() throws Exception { + super.setup(); + user = assertProperty(new Properties(), "user"); + password = assertProperty(new Properties(), "password"); + } + + /* + * @testName: getUserPrincipalTest + * + * @assertion_ids: WebSocket:JAVADOC:179; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-8.3-1; + * WebSocket:SPEC:WSC-7.2-2; + * + * @test_Strategy: HandshakeRequest.getUserPrincipal + * HandshakeResponse.getHeaders ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake A transport guarantee of + * NONE + * + * Similarly, if the opening handshake request is already authenticated with the + * server, the opening handshake API allows the developer to query the user + * Principal of the request. If the connection is established with the + * requesting client, the websocket implementation considers the user Principal + * for the associated websocket Session to be the user Principal that was + * present on the opening handshake. + * + * Return the authenticated user + */ + @Test + public void getUserPrincipalTest() throws Exception { + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse(GetUserPrincipalConfigurator.KEY, String.valueOf(user)); + addClientConfigurator(configurator); + addAuthorisation(); + invoke("auth/getuserprincipal", "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: isUserInRoleTest + * + * @assertion_ids: WebSocket:JAVADOC:180; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-8.3-1; + * + * @test_Strategy: HandshakeRequest.isUserInRole HandshakeResponse.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake A transport guarantee of + * NONE + */ + @Test + public void isUserInRoleTest() throws Exception { + // check DIRECTOR role is not known + // and set staff role to check + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse(IsUserInRoleConfigurator.KEY, String.valueOf(false)); + configurator.addToRequest(IsUserInRoleConfigurator.KEY, "DIRECTOR"); + addClientConfigurator(configurator); + addAuthorisation(); + invoke("auth/isuserinrole", "anything", "anything"); + configurator.assertBeforeRequestHasBeenCalled(); + configurator.assertAfterResponseHasBeenCalled(); + + // check the user is in staff role + configurator = new ClientConfigurator(); + configurator.addToResponse(IsUserInRoleConfigurator.KEY, String.valueOf(true)); + configurator.addToRequest(IsUserInRoleConfigurator.KEY, "staff"); + addAuthorisation(); + addClientConfigurator(configurator); + invoke("auth/isuserinrole", "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + configurator.assertBeforeRequestHasBeenCalled(); + } + + /* + * @testName: isNotAuthenticatedTest + * + * @assertion_ids: WebSocket:SPEC:WSC-8.1-1; WebSocket:SPEC:WSC-8.3-1; + * + * @test_Strategy: the websocket implementation must return a 401 (Unauthorized) + * response to the opening handshake request and may not initiate a websocket + * connection A transport guarantee of NONE + * + * 401 is not possible to check, but the websocket connection we can check + */ + @Test + public void isNotAuthenticatedTest() throws Exception { + boolean connection = false; + try { + logExceptionOnInvocation(false); + invoke("auth/isuserinrole", "staff", "staff"); + connection = true; + } catch (Exception f) { + logMsg("The connection was not initiated as expected:", getCauseMessage(f)); + } + assertFalse(connection, "The connection is initiated and 401 response was not returned"); + } + + /* + * @testName: authorizationIsNotUsedForUrlTest + * + * @assertion_ids: WebSocket:SPEC:WSC-8.3-1; WebSocket:SPEC:WSC-8.2-1; + * + * @test_Strategy: The used in the security constraint must be + * used by the container to match the request URI of the opening handshake of + * the websocket A transport guarantee of NONE + */ + @Test + public void authorizationIsNotUsedForUrlTest() throws Exception { + invoke("unauth/echo", "echo", "echo"); + } + + /* + * @testName: authorizationIsNotAppliedForPOSTTest + * + * @assertion_ids: WebSocket:SPEC:WSC-8.2-2; WebSocket:SPEC:WSC-8.3-1; + * + * @test_Strategy: The implementation must interpret any http-method other than + * GET (or the default, missing) as not applying to the websocket. A transport + * guarantee of NONE + */ + @Test + public void authorizationIsNotAppliedForPOSTTest() throws Exception { + invoke("post/echo", "echo", "echo"); + } + + // ///////////////////////////////////////////////////////////////////// + void addAuthorisation() { + setProperty(Property.BASIC_AUTH_USER, user); + setProperty(Property.BASIC_AUTH_PASSWD, password); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCGetUserPrincipalServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCGetUserPrincipalServer.java index bfbdc47b80..52dc4e3078 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCGetUserPrincipalServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCGetUserPrincipalServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/auth/getuserprincipal", configurator = GetUserPrincipalConfigurator.class) public class WSCGetUserPrincipalServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCIsUserInRoleServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCIsUserInRoleServer.java index a2eda0393b..d7daee5ef5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCIsUserInRoleServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCIsUserInRoleServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/auth/isuserinrole", configurator = IsUserInRoleConfigurator.class) public class WSCIsUserInRoleServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCPostUnauthEchoServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCPostUnauthEchoServer.java index d764cdd0b5..5b9968807c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCPostUnauthEchoServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCPostUnauthEchoServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/post/echo") public class WSCPostUnauthEchoServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCUnauthEchoServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCUnauthEchoServer.java index 2c9dfff358..d880f22ba0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCUnauthEchoServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/WSCUnauthEchoServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/unauth/echo") public class WSCUnauthEchoServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/CloseHttpSessionConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/CloseHttpSessionConfigurator.java index 1bcacb4b1a..a15dd5af44 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/CloseHttpSessionConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/CloseHttpSessionConfigurator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -25,21 +25,19 @@ public class CloseHttpSessionConfigurator extends Configurator { - private static HttpSession session; + private static HttpSession session; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - CloseHttpSessionConfigurator - .setSession((HttpSession) request.getHttpSession()); - super.modifyHandshake(sec, request, response); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + CloseHttpSessionConfigurator.setSession((HttpSession) request.getHttpSession()); + super.modifyHandshake(sec, request, response); + } - static HttpSession getSession() { - return session; - } + static HttpSession getSession() { + return session; + } - private static void setSession(HttpSession session) { - CloseHttpSessionConfigurator.session = session; - } + private static void setSession(HttpSession session) { + CloseHttpSessionConfigurator.session = session; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/TCKRequestListener.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/TCKRequestListener.java index c2ab9275ae..217dc365dc 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/TCKRequestListener.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/TCKRequestListener.java @@ -26,15 +26,15 @@ @WebListener public class TCKRequestListener implements ServletRequestListener { - @Override - public void requestDestroyed(ServletRequestEvent arg0) { - } + @Override + public void requestDestroyed(ServletRequestEvent arg0) { + } - @Override - public void requestInitialized(ServletRequestEvent evnt) { - ServletRequest request = evnt.getServletRequest(); - HttpServletRequest httpRequest = (HttpServletRequest) request; - httpRequest.getSession(true); // create - } + @Override + public void requestInitialized(ServletRequestEvent evnt) { + ServletRequest request = evnt.getServletRequest(); + HttpServletRequest httpRequest = (HttpServletRequest) request; + httpRequest.getSession(true); // create + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/WSCClient.java deleted file mode 100644 index 6ae5020dd3..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/WSCClient.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.authenticatedlogoff; - -import java.util.Properties; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * The tests here are not guaranteed to pass in standalone TCK, hence it is put - * into full CTS bundle - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - * user; - * password; - */ -public class WSCClient extends WebSocketCommonClient { - - private static final long serialVersionUID = -7084128651642590169L; - - String user; - - String password; - - int reason = 0; - - public WSCClient() { - setContextRoot( - "wsc_platform_jakarta_websocket_handshakeresponse_authenticated_logoff_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - @Override - public void setup(String[] args, Properties p) throws Exception { - user = assertProperty(p, "user"); - password = assertProperty(p, "password"); - super.setup(args, p); - } - - /* - * @testName: connectionHasBeenClosedWithStatus1008AfterInvalidationTest - * - * @assertion_ids: WebSocket:SPEC:WSC-7.2-3; - * - * @test_Strategy: In the case where a websocket endpoint is a protected - * resource in the web application (see Chapter 8), that is to say, requires - * an authorized user to access it, then the websocket implementation must - * ensure that the websocket endpoint does not remain connected to its peer - * after the underlying implementation has decided the authenticated identity - * is no longer valid. - * - * In this situation, the websocket implementation must immediately close the - * connection using the websocket close status code 1008. - */ - public void connectionHasBeenClosedWithStatus1008AfterInvalidationTest() - throws Exception { - connectionHasBeenClosedWithStatus1008After(0); - } - - // ///////////////////////////////////////////////////////////////////// - void addAuthorisation() { - setProperty(Property.BASIC_AUTH_USER, user); - setProperty(Property.BASIC_AUTH_PASSWD, password); - } - - void connectionHasBeenClosedWithStatus1008After(int opId) throws Exception { - boolean closed = false; - String[] messages = WSCCloseHttpSessionServer.MESSAGES; - logExceptionOnInvocation(false); - // set properties - addAuthorisation(); - // do not cleanup - try { - invoke("closehttpsession", messages[opId], messages[opId], false); - } catch (Exception e) { - // Could have been closed before response returned or it - // could have taken some time, then the validation fails - } - // setMaxIdleTimeout is checked only twice a minute - try { - TestUtil.sleepSec(5); // give time to close connection - invokeAgain("ok", "ok", true); // check for closed - } catch (Exception e) { - closed = true; - logTrace("Connection has been closed as expected:", getCauseMessage(e)); - } - assertTrue(closed, "The connection has not been immediatelly closed"); - // ask for close code - addAuthorisation(); - invoke("closehttpsession", messages[2], "1008"); - logMsg( - "After invalidation of HTTP session, connection has been closed with expected status 1008"); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/WSCClientIT.java new file mode 100644 index 0000000000..3b9bc48591 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/WSCClientIT.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.authenticatedlogoff; + +import java.io.IOException; +import java.util.Properties; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +/* + * The tests here are not guaranteed to pass in standalone TCK, hence it is put + * into full CTS bundle + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + * user; + * password; + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = -7084128651642590169L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_platform_jakarta_websocket_handshakeresponse_authenticated_logoff_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.authenticatedlogoff"); + archive.addClasses(IOUtil.class); + archive.addAsWebInfResource(WSCClientIT.class.getPackage(), "web.xml", "web.xml"); + return archive; + }; + + + String user; + + String password; + + int reason = 0; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_platform_jakarta_websocket_handshakeresponse_authenticated_logoff_web"); + } + + @Override + public void setup() throws Exception { + user = assertProperty(new Properties(), "user"); + password = assertProperty(new Properties(), "password"); + super.setup(); + } + + /* + * @testName: connectionHasBeenClosedWithStatus1008AfterInvalidationTest + * + * @assertion_ids: WebSocket:SPEC:WSC-7.2-3; + * + * @test_Strategy: In the case where a websocket endpoint is a protected + * resource in the web application (see Chapter 8), that is to say, requires an + * authorized user to access it, then the websocket implementation must ensure + * that the websocket endpoint does not remain connected to its peer after the + * underlying implementation has decided the authenticated identity is no longer + * valid. + * + * In this situation, the websocket implementation must immediately close the + * connection using the websocket close status code 1008. + */ + @Test + public void connectionHasBeenClosedWithStatus1008AfterInvalidationTest() throws Exception { + connectionHasBeenClosedWithStatus1008After(0); + } + + // ///////////////////////////////////////////////////////////////////// + void addAuthorisation() { + setProperty(Property.BASIC_AUTH_USER, user); + setProperty(Property.BASIC_AUTH_PASSWD, password); + } + + void connectionHasBeenClosedWithStatus1008After(int opId) throws Exception { + boolean closed = false; + String[] messages = WSCCloseHttpSessionServer.MESSAGES; + logExceptionOnInvocation(false); + // set properties + addAuthorisation(); + // do not cleanup + try { + invoke("closehttpsession", messages[opId], messages[opId], false); + } catch (Exception e) { + // Could have been closed before response returned or it + // could have taken some time, then the validation fails + } + // setMaxIdleTimeout is checked only twice a minute + try { + TestUtil.sleepSec(5); // give time to close connection + invokeAgain("ok", "ok", true); // check for closed + } catch (Exception e) { + closed = true; + logTrace("Connection has been closed as expected:", getCauseMessage(e)); + } + assertTrue(closed, "The connection has not been immediatelly closed"); + // ask for close code + addAuthorisation(); + invoke("closehttpsession", messages[2], "1008"); + logMsg("After invalidation of HTTP session, connection has been closed with expected status 1008"); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/WSCCloseHttpSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/WSCCloseHttpSessionServer.java index 9cb9522e50..b2604613c7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/WSCCloseHttpSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/WSCCloseHttpSessionServer.java @@ -30,43 +30,43 @@ @ServerEndpoint(value = "/closehttpsession", configurator = CloseHttpSessionConfigurator.class) public class WSCCloseHttpSessionServer { - private static int lastCloseCode = 0; + private static int lastCloseCode = 0; - static final String MESSAGES[] = { "invalidate", "interval", "lastcode" }; + static final String MESSAGES[] = { "invalidate", "interval", "lastcode" }; - @OnMessage - public String onMessage(String msg) { - if (MESSAGES[0].equals(msg)) { - WSCCloseHttpSessionServer.setLastCloseCode(0); - CloseHttpSessionConfigurator.getSession().invalidate(); - } else if (MESSAGES[1].equals(msg)) { - WSCCloseHttpSessionServer.setLastCloseCode(0); - CloseHttpSessionConfigurator.getSession().setMaxInactiveInterval(1); - } else if (MESSAGES[2].equals(msg)) - msg = String.valueOf(lastCloseCode); - return msg; - } + @OnMessage + public String onMessage(String msg) { + if (MESSAGES[0].equals(msg)) { + WSCCloseHttpSessionServer.setLastCloseCode(0); + CloseHttpSessionConfigurator.getSession().invalidate(); + } else if (MESSAGES[1].equals(msg)) { + WSCCloseHttpSessionServer.setLastCloseCode(0); + CloseHttpSessionConfigurator.getSession().setMaxInactiveInterval(1); + } else if (MESSAGES[2].equals(msg)) + msg = String.valueOf(lastCloseCode); + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } - @OnClose - public void onClose(CloseReason reason) { - WSCCloseHttpSessionServer.setLastCloseCode(reason.getCloseCode().getCode()); - String msg = "Close code: " + WSCCloseHttpSessionServer.getLastCloseCode(); - CloseHttpSessionConfigurator.getSession().getServletContext().log(msg); - } + @OnClose + public void onClose(CloseReason reason) { + WSCCloseHttpSessionServer.setLastCloseCode(reason.getCloseCode().getCode()); + String msg = "Close code: " + WSCCloseHttpSessionServer.getLastCloseCode(); + CloseHttpSessionConfigurator.getSession().getServletContext().log(msg); + } - private static int getLastCloseCode() { - return lastCloseCode; - } + private static int getLastCloseCode() { + return lastCloseCode; + } - private static void setLastCloseCode(int lastCloseCode) { - WSCCloseHttpSessionServer.lastCloseCode = lastCloseCode; - } + private static void setLastCloseCode(int lastCloseCode) { + WSCCloseHttpSessionServer.lastCloseCode = lastCloseCode; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/AppConfig.java index 5412d66b5b..8adf967897 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/AppConfig.java @@ -29,18 +29,17 @@ */ public class AppConfig implements ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + return set; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - set.add(WSCGetUserPrincipalServer.class); - set.add(WSCIsUserInRoleServer.class); - return set; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + set.add(WSCGetUserPrincipalServer.class); + set.add(WSCIsUserInRoleServer.class); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/GetUserPrincipalConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/GetUserPrincipalConfigurator.java index 250d2c5427..45bf0a9e43 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/GetUserPrincipalConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/GetUserPrincipalConfigurator.java @@ -26,13 +26,12 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class GetUserPrincipalConfigurator extends Configurator { - static final String KEY = "GetUserPrincipalConfigurator"; + static final String KEY = "GetUserPrincipalConfigurator"; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - Principal principal = request.getUserPrincipal(); - String value = principal == null ? "NULL" : principal.getName(); - response.getHeaders().put(KEY, Arrays.asList(value)); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + Principal principal = request.getUserPrincipal(); + String value = principal == null ? "NULL" : principal.getName(); + response.getHeaders().put(KEY, Arrays.asList(value)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/IsUserInRoleConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/IsUserInRoleConfigurator.java index a13c7e618f..a7524499b0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/IsUserInRoleConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/IsUserInRoleConfigurator.java @@ -25,14 +25,13 @@ import jakarta.websocket.server.ServerEndpointConfig.Configurator; public class IsUserInRoleConfigurator extends Configurator { - static final String KEY = "IsUserInRoleConfigurator"; + static final String KEY = "IsUserInRoleConfigurator"; - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - String role = request.getHeaders().get(KEY).iterator().next(); - boolean isInRole = request.isUserInRole(role); - String value = String.valueOf(isInRole); - response.getHeaders().put(KEY, Arrays.asList(value)); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + String role = request.getHeaders().get(KEY).iterator().next(); + boolean isInRole = request.isUserInRole(role); + String value = String.valueOf(isInRole); + response.getHeaders().put(KEY, Arrays.asList(value)); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCClient.java deleted file mode 100644 index 00def1d719..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCClient.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.authenticatedssl; - -import java.util.Properties; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; - -/* - * The tests here are not guaranteed to pass in standalone TCK, hence it is put - * into full CTS bundle - * @class.setup_props: webServerHost; - * webServerPort; - * securedWebServicePort; - * ts_home; - * ws_wait; - * user; - * password; - */ -public class WSCClient extends WebSocketCommonClient { - - private static final long serialVersionUID = -5851958128006729743L; - - String user; - - String password; - - String port; - - public WSCClient() { - setContextRoot("wsc_platform_jakarta_websocket_handshakeresponse_ssl_web"); - setRequestProtocol("wss"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - @Override - public void setup(String[] args, Properties p) throws Exception { - user = assertProperty(p, "user"); - password = assertProperty(p, "password"); - port = assertProperty(p, "securedWebServicePort"); - super.setup(args, p); - _port = Integer.parseInt(port); - } - - /* - * @testName: getUserPrincipalTest - * - * @assertion_ids: WebSocket:JAVADOC:179; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-8.3-2; - * - * @test_Strategy: HandshakeRequest.getUserPrincipal - * HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake A transport guarantee of - * CONFIDENTIAL - * - * Return the authenticated user - */ - public void getUserPrincipalTest() throws Exception { - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse(GetUserPrincipalConfigurator.KEY, - String.valueOf(user)); - addClientConfigurator(configurator); - addAuthorisation(); - invoke("ssl/getuserprincipal", "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - } - - /* - * @testName: isUserInRoleTest - * - * @assertion_ids: WebSocket:JAVADOC:180; WebSocket:JAVADOC:77; - * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-8.3-2; - * - * @test_Strategy: HandshakeRequest.isUserInRole HandshakeResponse.getHeaders - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake A transport guarantee of - * CONFIDENTIAL - */ - public void isUserInRoleTest() throws Exception { - // check DIRECTOR role is not known - // and set staff role to check - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse(IsUserInRoleConfigurator.KEY, - String.valueOf(false)); - configurator.addToRequest(IsUserInRoleConfigurator.KEY, "DIRECTOR"); - addClientConfigurator(configurator); - addAuthorisation(); - invoke("ssl/isuserinrole", "anything", "anything"); - configurator.assertBeforeRequestHasBeenCalled(); - configurator.assertAfterResponseHasBeenCalled(); - - // check the user is in staff role - configurator = new ClientConfigurator(); - configurator.addToResponse(IsUserInRoleConfigurator.KEY, - String.valueOf(true)); - configurator.addToRequest(IsUserInRoleConfigurator.KEY, "staff"); - addAuthorisation(); - addClientConfigurator(configurator); - invoke("ssl/isuserinrole", "anything", "anything"); - configurator.assertAfterResponseHasBeenCalled(); - configurator.assertBeforeRequestHasBeenCalled(); - } - - // ///////////////////////////////////////////////////////////////////// - void addAuthorisation() { - setProperty(Property.BASIC_AUTH_USER, user); - setProperty(Property.BASIC_AUTH_PASSWD, password); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCClientIT.java new file mode 100644 index 0000000000..d6fa59e442 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCClientIT.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.authenticatedssl; + +import java.io.IOException; +import java.util.Properties; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +/* + * The tests here are not guaranteed to pass in standalone TCK, hence it is put + * into full CTS bundle + * @class.setup_props: webServerHost; + * webServerPort; + * securedWebServicePort; + * ws_wait; + * user; + * password; + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = -5851958128006729743L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_platform_jakarta_websocket_handshakeresponse_ssl_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.authenticatedssl"); + archive.addClasses(IOUtil.class); + archive.addAsWebInfResource(WSCClientIT.class.getPackage(), "web.xml", "web.xml"); + return archive; + }; + + String user; + + String password; + + String port; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_platform_jakarta_websocket_handshakeresponse_ssl_web"); + setRequestProtocol("wss"); + } + + @Override + public void setup() throws Exception { + super.setup(); + user = assertProperty(new Properties(), "user"); + password = assertProperty(new Properties(), "password"); + port = assertProperty(new Properties(), "securedWebServicePort"); + _port = Integer.parseInt(port); + } + + /* + * @testName: getUserPrincipalTest + * + * @assertion_ids: WebSocket:JAVADOC:179; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-8.3-2; + * + * @test_Strategy: HandshakeRequest.getUserPrincipal + * HandshakeResponse.getHeaders ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake A transport guarantee of + * CONFIDENTIAL + * + * Return the authenticated user + */ + @Test + public void getUserPrincipalTest() throws Exception { + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse(GetUserPrincipalConfigurator.KEY, String.valueOf(user)); + addClientConfigurator(configurator); + addAuthorisation(); + invoke("ssl/getuserprincipal", "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + } + + /* + * @testName: isUserInRoleTest + * + * @assertion_ids: WebSocket:JAVADOC:180; WebSocket:JAVADOC:77; + * WebSocket:JAVADOC:15; WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-8.3-2; + * + * @test_Strategy: HandshakeRequest.isUserInRole HandshakeResponse.getHeaders + * ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake A transport guarantee of + * CONFIDENTIAL + */ + @Test + public void isUserInRoleTest() throws Exception { + // check DIRECTOR role is not known + // and set staff role to check + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse(IsUserInRoleConfigurator.KEY, String.valueOf(false)); + configurator.addToRequest(IsUserInRoleConfigurator.KEY, "DIRECTOR"); + addClientConfigurator(configurator); + addAuthorisation(); + invoke("ssl/isuserinrole", "anything", "anything"); + configurator.assertBeforeRequestHasBeenCalled(); + configurator.assertAfterResponseHasBeenCalled(); + + // check the user is in staff role + configurator = new ClientConfigurator(); + configurator.addToResponse(IsUserInRoleConfigurator.KEY, String.valueOf(true)); + configurator.addToRequest(IsUserInRoleConfigurator.KEY, "staff"); + addAuthorisation(); + addClientConfigurator(configurator); + invoke("ssl/isuserinrole", "anything", "anything"); + configurator.assertAfterResponseHasBeenCalled(); + configurator.assertBeforeRequestHasBeenCalled(); + } + + // ///////////////////////////////////////////////////////////////////// + void addAuthorisation() { + setProperty(Property.BASIC_AUTH_USER, user); + setProperty(Property.BASIC_AUTH_PASSWD, password); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCGetUserPrincipalServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCGetUserPrincipalServer.java index 5a4dd7728b..299a374b50 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCGetUserPrincipalServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCGetUserPrincipalServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/ssl/getuserprincipal", configurator = GetUserPrincipalConfigurator.class) public class WSCGetUserPrincipalServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCIsUserInRoleServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCIsUserInRoleServer.java index 95ec55c3a4..f2c975084c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCIsUserInRoleServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/WSCIsUserInRoleServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/ssl/isuserinrole", configurator = IsUserInRoleConfigurator.class) public class WSCIsUserInRoleServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/GetHttpSessionConfigurator.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/GetHttpSessionConfigurator.java index c9eca9eba0..d7f53bc116 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/GetHttpSessionConfigurator.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/GetHttpSessionConfigurator.java @@ -26,19 +26,17 @@ public class GetHttpSessionConfigurator extends Configurator { - @Override - public void modifyHandshake(ServerEndpointConfig sec, - HandshakeRequest request, HandshakeResponse response) { - boolean hasHttpSession = request.getHttpSession() != null; - response.getHeaders().put(RESPONSE_KEY, - Arrays.asList(String.valueOf(hasHttpSession))); - super.modifyHandshake(sec, request, response); - } + @Override + public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) { + boolean hasHttpSession = request.getHttpSession() != null; + response.getHeaders().put(RESPONSE_KEY, Arrays.asList(String.valueOf(hasHttpSession))); + super.modifyHandshake(sec, request, response); + } - /* - * The value of this key is set to be checked on a client and the value should - * reflect boolean value of having httpSession or not - */ - static final String RESPONSE_KEY = "hasHttpSession"; + /* + * The value of this key is set to be checked on a client and the value should + * reflect boolean value of having httpSession or not + */ + static final String RESPONSE_KEY = "hasHttpSession"; } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/TCKRequestListener.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/TCKRequestListener.java index 5786f1c881..c0055d731c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/TCKRequestListener.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/TCKRequestListener.java @@ -26,15 +26,15 @@ @WebListener public class TCKRequestListener implements ServletRequestListener { - @Override - public void requestDestroyed(ServletRequestEvent arg0) { - } + @Override + public void requestDestroyed(ServletRequestEvent arg0) { + } - @Override - public void requestInitialized(ServletRequestEvent evnt) { - ServletRequest request = evnt.getServletRequest(); - HttpServletRequest httpRequest = (HttpServletRequest) request; - httpRequest.getSession(true); // create - } + @Override + public void requestInitialized(ServletRequestEvent evnt) { + ServletRequest request = evnt.getServletRequest(); + HttpServletRequest httpRequest = (HttpServletRequest) request; + httpRequest.getSession(true); // create + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/WSCClient.java deleted file mode 100644 index dc0627aca5..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/WSCClient.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.session; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; - -import jakarta.websocket.ClientEndpointConfig; - -/* - * The tests here are not guaranteed to pass in standalone TCK, hence put - * into full CTS bundle - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSCClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 3741198886806200627L; - - public WSCClient() { - setContextRoot("wsc_platform_jakarta_websocket_handshakerequest_session_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: getHttpSessionTest - * - * @assertion_ids: WebSocket:JAVADOC:175; WebSocket:JAVADOC:15; - * WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-7.2-1; - * - * @test_Strategy: HandshakeRequest.getHttpSession - * ClientEndpointConfig.Configurator.afterResponse - * ServerEndpointConfig.Configurator.modifyHandshake - * - * the http session or null if either the websocket implementation is not part - * of a Java EE web container, or there is no HttpSession associated with the - * opening handshake request. - * - * The API allows access in the opening handshake to the unique HttpSession - * corresponding to that same client. - * - * This test is only run as part of CTS, i.e. in full java EE environment, - * i.e. in servlet container - */ - public void getHttpSessionTest() throws Exception { - ClientConfigurator configurator = new ClientConfigurator(); - configurator.addToResponse(GetHttpSessionConfigurator.RESPONSE_KEY, - String.valueOf(true)); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .configurator(configurator).build(); - setClientEndpointConfig(config); - invoke("gethttpsession", "anything", "anything"); - configurator.assertBeforeRequestHasBeenCalled(); - configurator.assertAfterResponseHasBeenCalled(); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/WSCClientIT.java new file mode 100644 index 0000000000..ed655a0b75 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/WSCClientIT.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.session; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.impl.ClientConfigurator; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +import jakarta.websocket.ClientEndpointConfig; + +/* + * The tests here are not guaranteed to pass in standalone TCK, hence put + * into full CTS bundle + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 3741198886806200627L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_platform_jakarta_websocket_handshakerequest_session_web.war"); + archive.addPackages(false, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.platform.jakarta.websocket.server.handshakerequest.session"); + archive.addClasses(IOUtil.class); + return archive; + }; + + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_platform_jakarta_websocket_handshakerequest_session_web"); + } + + /* + * @testName: getHttpSessionTest + * + * @assertion_ids: WebSocket:JAVADOC:175; WebSocket:JAVADOC:15; + * WebSocket:JAVADOC:210; WebSocket:SPEC:WSC-7.2-1; + * + * @test_Strategy: HandshakeRequest.getHttpSession + * ClientEndpointConfig.Configurator.afterResponse + * ServerEndpointConfig.Configurator.modifyHandshake + * + * the http session or null if either the websocket implementation is not part + * of a Java EE web container, or there is no HttpSession associated with the + * opening handshake request. + * + * The API allows access in the opening handshake to the unique HttpSession + * corresponding to that same client. + * + * This test is only run as part of CTS, i.e. in full java EE environment, i.e. + * in servlet container + */ + @Test + public void getHttpSessionTest() throws Exception { + ClientConfigurator configurator = new ClientConfigurator(); + configurator.addToResponse(GetHttpSessionConfigurator.RESPONSE_KEY, String.valueOf(true)); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().configurator(configurator).build(); + setClientEndpointConfig(config); + invoke("gethttpsession", "anything", "anything"); + configurator.assertBeforeRequestHasBeenCalled(); + configurator.assertAfterResponseHasBeenCalled(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/WSCGetHttpSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/WSCGetHttpSessionServer.java index 83e41b3445..87daa92075 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/WSCGetHttpSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/session/WSCGetHttpSessionServer.java @@ -28,16 +28,16 @@ @ServerEndpoint(value = "/gethttpsession", configurator = GetHttpSessionConfigurator.class) public class WSCGetHttpSessionServer { - @OnMessage - public String onMessage(String msg) { - return msg; - } + @OnMessage + public String onMessage(String msg) { + return msg; + } - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointSubclassWithOverrideAndAnnotations.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointSubclassWithOverrideAndAnnotations.java index dbed4b727d..8ef250be6b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointSubclassWithOverrideAndAnnotations.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointSubclassWithOverrideAndAnnotations.java @@ -28,30 +28,30 @@ @ClientEndpoint public class AnnotatedClientEndpointSubclassWithOverrideAndAnnotations - extends AnnotatedClientEndpointSuperclassWithAnnotations { - - @OnOpen - @Override - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } - - @OnMessage - @Override - public void onMessage(String msg) { - super.onMessage(msg); - } - - @OnClose - @Override - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @OnError - @Override - public void onError(Session session, Throwable t) { - super.onError(session, t); - } + extends AnnotatedClientEndpointSuperclassWithAnnotations { + + @OnOpen + @Override + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } + + @OnMessage + @Override + public void onMessage(String msg) { + super.onMessage(msg); + } + + @OnClose + @Override + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @OnError + @Override + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointSuperclassWithAnnotations.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointSuperclassWithAnnotations.java index 9945aba309..efde52340f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointSuperclassWithAnnotations.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointSuperclassWithAnnotations.java @@ -28,34 +28,33 @@ import jakarta.websocket.OnOpen; import jakarta.websocket.Session; -public class AnnotatedClientEndpointSuperclassWithAnnotations - extends AnnotatedClientEndpoint { - - public AnnotatedClientEndpointSuperclassWithAnnotations() { - super(new StringClientEndpoint()); - } - - @Override - @OnOpen - public void onOpen(Session session, EndpointConfig config) { - super.onOpen(session, config); - } - - @Override - @OnMessage - public void onMessage(String msg) { - super.onMessage(msg); - } - - @Override - @OnClose - public void onClose(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } - - @Override - @OnError - public void onError(Session session, Throwable t) { - super.onError(session, t); - } +public class AnnotatedClientEndpointSuperclassWithAnnotations extends AnnotatedClientEndpoint { + + public AnnotatedClientEndpointSuperclassWithAnnotations() { + super(new StringClientEndpoint()); + } + + @Override + @OnOpen + public void onOpen(Session session, EndpointConfig config) { + super.onOpen(session, config); + } + + @Override + @OnMessage + public void onMessage(String msg) { + super.onMessage(msg); + } + + @Override + @OnClose + public void onClose(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } + + @Override + @OnError + public void onError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnCloseAnnotations.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnCloseAnnotations.java index 8fcf578c3b..4619125200 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnCloseAnnotations.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnCloseAnnotations.java @@ -24,11 +24,11 @@ @ClientEndpoint public class AnnotatedClientEndpointWithMultipleOnCloseAnnotations - extends AnnotatedClientEndpointSuperclassWithAnnotations { + extends AnnotatedClientEndpointSuperclassWithAnnotations { - @OnClose - public void close(Session session, CloseReason closeReason) { - super.onClose(session, closeReason); - } + @OnClose + public void close(Session session, CloseReason closeReason) { + super.onClose(session, closeReason); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnErrorAnnotations.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnErrorAnnotations.java index 0d644a8ecc..0ced48913f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnErrorAnnotations.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnErrorAnnotations.java @@ -23,11 +23,11 @@ @ClientEndpoint public class AnnotatedClientEndpointWithMultipleOnErrorAnnotations - extends AnnotatedClientEndpointSuperclassWithAnnotations { + extends AnnotatedClientEndpointSuperclassWithAnnotations { - @OnError - public void gotError(Session session, Throwable t) { - super.onError(session, t); - } + @OnError + public void gotError(Session session, Throwable t) { + super.onError(session, t); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnMessageAnnotations.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnMessageAnnotations.java index 590a2f58e0..783c6c9d11 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnMessageAnnotations.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnMessageAnnotations.java @@ -22,11 +22,11 @@ @ClientEndpoint public class AnnotatedClientEndpointWithMultipleOnMessageAnnotations - extends AnnotatedClientEndpointSuperclassWithAnnotations { + extends AnnotatedClientEndpointSuperclassWithAnnotations { - @OnMessage - public void gotMessage(String msg) { - super.onMessage(msg); - } + @OnMessage + public void gotMessage(String msg) { + super.onMessage(msg); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnOpenAnnotations.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnOpenAnnotations.java index c22f7faba7..a0d2c33a58 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnOpenAnnotations.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedClientEndpointWithMultipleOnOpenAnnotations.java @@ -24,11 +24,11 @@ @ClientEndpoint public class AnnotatedClientEndpointWithMultipleOnOpenAnnotations - extends AnnotatedClientEndpointSuperclassWithAnnotations { + extends AnnotatedClientEndpointSuperclassWithAnnotations { - @OnOpen - public void open(Session session, EndpointConfig config) { - super.onOpen(session, config); - } + @OnOpen + public void open(Session session, EndpointConfig config) { + super.onOpen(session, config); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedSubclassEndpointWithoutAnnotations.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedSubclassEndpointWithoutAnnotations.java index bc1c4f5419..328116541f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedSubclassEndpointWithoutAnnotations.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/AnnotatedSubclassEndpointWithoutAnnotations.java @@ -20,7 +20,6 @@ import jakarta.websocket.ClientEndpoint; @ClientEndpoint -public class AnnotatedSubclassEndpointWithoutAnnotations - extends AnnotatedClientEndpointSuperclassWithAnnotations { +public class AnnotatedSubclassEndpointWithoutAnnotations extends AnnotatedClientEndpointSuperclassWithAnnotations { } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/EchoServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/EchoServer.java index ab57aabc29..76fc3e0fe6 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/EchoServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/EchoServer.java @@ -23,9 +23,9 @@ @ServerEndpoint("/echo") public class EchoServer { - @OnMessage - public String echo(String message) { - return message; - } + @OnMessage + public String echo(String message) { + return message; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/WSCClient.java deleted file mode 100644 index 2b6402e672..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/WSCClient.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2014, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.spec.annotation.inheritance; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -/** - * The Spec is a bit fuzzy about how the annotation should work. But the proper - * meaning should be that it works the way java se states, i.e. annotation - * inheritance from java language specification. - *

- *

    - *
  • So first if the super class has the annotation then the subclass has it, - * too.
  • - *
  • Second, if super class has the annotation and the subclass override the - * method, the annotation is gone
  • - *
  • Third, most tricky, if the annotation is on superclass not overridden in - * subclass and annotation is put to some other method in subclass, the subclass - * has the annotation twice, first from superclass and second from subclass and - * the class should not deploy, i.e. DeploymentException is thrown as stated by - * WSC-4.8.1, Section 4.8 WebSockets and Inheritance, WebSocket - * Specification
  • - *
- * This has proven to be incorrectly understood by various implementing teams, - * but after several discussions, the common agreement is the java se behavior. - */ -public class WSCClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 3037319902828702665L; - - protected final static String MESSAGE = "message"; - - public WSCClient() { - setContextRoot("wsc_spec_annotation_inheritance_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: annotationOnMethodIsInheritedTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; - * - * @test_Strategy: The subclass just inherits @OnMessage - */ - public void annotationOnMethodIsInheritedTest() throws Exception { - setAnnotatedClientEndpoint( - new AnnotatedSubclassEndpointWithoutAnnotations()); - invoke("echo", MESSAGE, MESSAGE); - logMsg("Annotations have been inherited as expected"); - } - - /* - * @testName: annotationOnMethodIsOverridenTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; - * - * @test_Strategy: The subclass overrides @OnMessage - */ - public void annotationOnMethodIsOverridenTest() throws Exception { - setAnnotatedClientEndpoint( - new AnnotatedClientEndpointSubclassWithOverrideAndAnnotations()); - invoke("echo", MESSAGE, MESSAGE); - logMsg("Annotations have been overriden as expected"); - } - - /* - * @testName: annotationOnMessageIsTwiceTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; - * - * @test_Strategy: The subclass defines its own @OnMessage - * - * Implementations should not deploy Java classes that mistakenly mix Java - * inheritance with websocket annotations in these ways. - */ - public void annotationOnMessageIsTwiceTest() throws Exception { - try { - setAnnotatedClientEndpoint( - new AnnotatedClientEndpointWithMultipleOnMessageAnnotations()); - logExceptionOnInvocation(false); - invoke("echo", MESSAGE, MESSAGE); - fault( - "No exception has been thrown when multiple @OnMessage annotations defined"); - } catch (Exception e) { - DeploymentException de = assertCause(e, DeploymentException.class, - "DeploymentException has not been thrown when multiple @OnMessage annotations"); - logMsg("DeploymentException has been thrown as expected:", - de.getMessage()); - } - } - - /* - * @testName: annotationOnOpenIsTwiceTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; - * - * @test_Strategy: The subclass defines its own @OnOpen - * - * Implementations should not deploy Java classes that mistakenly mix Java - * inheritance with websocket annotations in these ways. - */ - public void annotationOnOpenIsTwiceTest() throws Exception { - try { - setAnnotatedClientEndpoint( - new AnnotatedClientEndpointWithMultipleOnOpenAnnotations()); - logExceptionOnInvocation(false); - invoke("echo", MESSAGE, MESSAGE); - fault( - "No exception has been thrown when multiple @OnOpen annotations defined"); - } catch (Exception e) { - DeploymentException de = assertCause(e, DeploymentException.class, - "DeploymentException has not been thrown when multiple @OnOpen annotations"); - logMsg("DeploymentException has been thrown as expected:", de); - } - } - - /* - * @testName: annotationOnCloseIsTwiceTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; - * - * @test_Strategy: The subclass defines its own @OnClose - * - * Implementations should not deploy Java classes that mistakenly mix Java - * inheritance with websocket annotations in these ways. - */ - public void annotationOnCloseIsTwiceTest() throws Exception { - try { - setAnnotatedClientEndpoint( - new AnnotatedClientEndpointWithMultipleOnCloseAnnotations()); - logExceptionOnInvocation(false); - invoke("echo", MESSAGE, MESSAGE); - fault( - "No exception has been thrown when multiple @OnClose annotations defined"); - } catch (Exception e) { - DeploymentException de = assertCause(e, DeploymentException.class, - "DeploymentException has not been thrown when multiple @OnClose annotations"); - logMsg("DeploymentException has been thrown as expected:", - de.getMessage()); - } - } - - /* - * @testName: annotationOnErrorIsTwiceTest - * - * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; - * - * @test_Strategy: The subclass defines its own @OnError - * - * Implementations should not deploy Java classes that mistakenly mix Java - * inheritance with websocket annotations in these ways. - */ - public void annotationOnErrorIsTwiceTest() throws Exception { - try { - setAnnotatedClientEndpoint( - new AnnotatedClientEndpointWithMultipleOnErrorAnnotations()); - logExceptionOnInvocation(false); - invoke("echo", MESSAGE, MESSAGE); - fault( - "No exception has been thrown when multiple @OnError annotations defined"); - } catch (Exception e) { - DeploymentException de = assertCause(e, DeploymentException.class, - "DeploymentException has not been thrown when multiple @OnError annotations"); - logMsg("DeploymentException has been thrown as expected:", - de.getMessage()); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/WSCClientTest.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/WSCClientTest.java new file mode 100644 index 0000000000..b483a0e455 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/annotation/inheritance/WSCClientTest.java @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2014, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.spec.annotation.inheritance; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +/** + * The Spec is a bit fuzzy about how the annotation should work. But the proper + * meaning should be that it works the way java se states, i.e. annotation + * inheritance from java language specification. + *

+ *

    + *
  • So first if the super class has the annotation then the subclass has it, + * too.
  • + *
  • Second, if super class has the annotation and the subclass override the + * method, the annotation is gone
  • + *
  • Third, most tricky, if the annotation is on superclass not overridden in + * subclass and annotation is put to some other method in subclass, the subclass + * has the annotation twice, first from superclass and second from subclass and + * the class should not deploy, i.e. DeploymentException is thrown as stated by + * WSC-4.8.1, Section 4.8 WebSockets and Inheritance, WebSocket + * Specification
  • + *
+ * This has proven to be incorrectly understood by various implementing teams, + * but after several discussions, the common agreement is the java se behavior. + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientTest extends WebSocketCommonClient { + + private static final long serialVersionUID = 3037319902828702665L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_spec_annotation_inheritance_web.war"); + archive.addClasses(EchoServer.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + protected final static String MESSAGE = "message"; + + public WSCClientTest() throws Exception { + setup(); + setContextRoot("wsc_spec_annotation_inheritance_web"); + } + + /* + * @testName: annotationOnMethodIsInheritedTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; + * + * @test_Strategy: The subclass just inherits @OnMessage + */ + @Test + public void annotationOnMethodIsInheritedTest() throws Exception { + setAnnotatedClientEndpoint(new AnnotatedSubclassEndpointWithoutAnnotations()); + invoke("echo", MESSAGE, MESSAGE); + logMsg("Annotations have been inherited as expected"); + } + + /* + * @testName: annotationOnMethodIsOverridenTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; + * + * @test_Strategy: The subclass overrides @OnMessage + */ + @Test + public void annotationOnMethodIsOverridenTest() throws Exception { + setAnnotatedClientEndpoint(new AnnotatedClientEndpointSubclassWithOverrideAndAnnotations()); + invoke("echo", MESSAGE, MESSAGE); + logMsg("Annotations have been overriden as expected"); + } + + /* + * @testName: annotationOnMessageIsTwiceTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; + * + * @test_Strategy: The subclass defines its own @OnMessage + * + * Implementations should not deploy Java classes that mistakenly mix Java + * inheritance with websocket annotations in these ways. + */ + @Test + public void annotationOnMessageIsTwiceTest() throws Exception { + try { + setAnnotatedClientEndpoint(new AnnotatedClientEndpointWithMultipleOnMessageAnnotations()); + logExceptionOnInvocation(false); + invoke("echo", MESSAGE, MESSAGE); + new Exception("No exception has been thrown when multiple @OnMessage annotations defined"); + } catch (Exception e) { + DeploymentException de = assertCause(e, DeploymentException.class, + "DeploymentException has not been thrown when multiple @OnMessage annotations"); + logMsg("DeploymentException has been thrown as expected:", de.getMessage()); + } + } + + /* + * @testName: annotationOnOpenIsTwiceTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; + * + * @test_Strategy: The subclass defines its own @OnOpen + * + * Implementations should not deploy Java classes that mistakenly mix Java + * inheritance with websocket annotations in these ways. + */ + @Test + public void annotationOnOpenIsTwiceTest() throws Exception { + try { + setAnnotatedClientEndpoint(new AnnotatedClientEndpointWithMultipleOnOpenAnnotations()); + logExceptionOnInvocation(false); + invoke("echo", MESSAGE, MESSAGE); + new Exception("No exception has been thrown when multiple @OnOpen annotations defined"); + } catch (Exception e) { + DeploymentException de = assertCause(e, DeploymentException.class, + "DeploymentException has not been thrown when multiple @OnOpen annotations"); + logMsg("DeploymentException has been thrown as expected:", de); + } + } + + /* + * @testName: annotationOnCloseIsTwiceTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; + * + * @test_Strategy: The subclass defines its own @OnClose + * + * Implementations should not deploy Java classes that mistakenly mix Java + * inheritance with websocket annotations in these ways. + */ + @Test + public void annotationOnCloseIsTwiceTest() throws Exception { + try { + setAnnotatedClientEndpoint(new AnnotatedClientEndpointWithMultipleOnCloseAnnotations()); + logExceptionOnInvocation(false); + invoke("echo", MESSAGE, MESSAGE); + new Exception("No exception has been thrown when multiple @OnClose annotations defined"); + } catch (Exception e) { + DeploymentException de = assertCause(e, DeploymentException.class, + "DeploymentException has not been thrown when multiple @OnClose annotations"); + logMsg("DeploymentException has been thrown as expected:", de.getMessage()); + } + } + + /* + * @testName: annotationOnErrorIsTwiceTest + * + * @assertion_ids: WebSocket:SPEC:WSC-4.8.1; + * + * @test_Strategy: The subclass defines its own @OnError + * + * Implementations should not deploy Java classes that mistakenly mix Java + * inheritance with websocket annotations in these ways. + */ + @Test + public void annotationOnErrorIsTwiceTest() throws Exception { + try { + setAnnotatedClientEndpoint(new AnnotatedClientEndpointWithMultipleOnErrorAnnotations()); + logExceptionOnInvocation(false); + invoke("echo", MESSAGE, MESSAGE); + new Exception("No exception has been thrown when multiple @OnError annotations defined"); + } catch (Exception e) { + DeploymentException de = assertCause(e, DeploymentException.class, + "DeploymentException has not been thrown when multiple @OnError annotations"); + logMsg("DeploymentException has been thrown as expected:", de.getMessage()); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/closing/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/closing/WSCClient.java deleted file mode 100644 index caa6d88009..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/closing/WSCClient.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2013, 2018 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 com.sun.ts.tests.websocket.spec.application.closing; - -import com.sun.ts.lib.util.TestUtil; -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * The tests here are not guaranteed to pass in standalone TCK, hence put - * into full CTS bundle - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSCClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 3037319902828702665L; - - public WSCClient() { - setContextRoot("wsc_spec_application_closing_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: connectionHasBeenClosedWithStatus1006AfterTimeoutTest - * - * @assertion_ids: WebSocket:SPEC:WSC-2.1.5-1; - * - * @test_Strategy: If the close was initiated by the local container, for - * example if the local container determines the session has timed out, the - * local implementation must use the websocket protocol close code 1006 - */ - public void connectionHasBeenClosedWithStatus1006AfterTimeoutTest() - throws Exception { - boolean closed = false; - String[] messages = WSCCloseSessionServer.MESSAGES; - logExceptionOnInvocation(false); - // set properties - // do not cleanup - try { - invoke("closesession", messages[0], messages[0], false); - } catch (Exception e) { - // Could have been closed before response returned or it - // could have taken some time, then the validation fails - } - // setMaxIdleTimeout is checked only twice a minute - try { - logExceptionOnInvocation(false); - TestUtil.sleepSec(5); // give time to close connection - invokeAgain("ok", "ok", true); // check for closed - } catch (Exception e) { - closed = true; - logTrace("Connection has been closed as expected:", getCauseMessage(e)); - } - assertTrue(closed, "The connection has not been closed"); - // ask for close code - invoke("closesession", messages[1], "1006"); - logMsg( - "After invalidation of HTTP session, connection has been closed with expected status 1006"); - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/closing/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/closing/WSCClientIT.java new file mode 100644 index 0000000000..52451b0813 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/closing/WSCClientIT.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.spec.application.closing; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +/* + * The tests here are not guaranteed to pass in standalone TCK, hence put + * into full CTS bundle + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 3037319902828702665L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_spec_application_closing_web.war"); + archive.addClasses(WSCCloseSessionServer.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_spec_application_closing_web"); + } + + /* + * @testName: connectionHasBeenClosedWithStatus1006AfterTimeoutTest + * + * @assertion_ids: WebSocket:SPEC:WSC-2.1.5-1; + * + * @test_Strategy: If the close was initiated by the local container, for + * example if the local container determines the session has timed out, the + * local implementation must use the websocket protocol close code 1006 + */ + @Test + public void connectionHasBeenClosedWithStatus1006AfterTimeoutTest() throws Exception { + boolean closed = false; + String[] messages = WSCCloseSessionServer.MESSAGES; + logExceptionOnInvocation(false); + // set properties + // do not cleanup + try { + invoke("closesession", messages[0], messages[0], false); + } catch (Exception e) { + // Could have been closed before response returned or it + // could have taken some time, then the validation fails + } + // setMaxIdleTimeout is checked only twice a minute + try { + logExceptionOnInvocation(false); + TestUtil.sleepSec(5); // give time to close connection + invokeAgain("ok", "ok", true); // check for closed + } catch (Exception e) { + closed = true; + logTrace("Connection has been closed as expected:", getCauseMessage(e)); + } + assertTrue(closed, "The connection has not been closed"); + // ask for close code + invoke("closesession", messages[1], "1006"); + logMsg("After invalidation of HTTP session, connection has been closed with expected status 1006"); + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/closing/WSCCloseSessionServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/closing/WSCCloseSessionServer.java index 4d544e134b..8f67e4978c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/closing/WSCCloseSessionServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/closing/WSCCloseSessionServer.java @@ -30,39 +30,40 @@ @ServerEndpoint(value = "/closesession") public class WSCCloseSessionServer { - static int lastCloseCode = 0; - static final String MESSAGES[] = { "idle", "lastcode" }; + static int lastCloseCode = 0; - @OnMessage - public String onMessage(String msg, Session session) { - if (MESSAGES[0].equals(msg)) { - setLastCloseCode(0); - session.setMaxIdleTimeout(1); - } else if (MESSAGES[1].equals(msg)) - msg = getLastCloseCode(); - return msg; - } + static final String MESSAGES[] = { "idle", "lastcode" }; - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String onMessage(String msg, Session session) { + if (MESSAGES[0].equals(msg)) { + setLastCloseCode(0); + session.setMaxIdleTimeout(1); + } else if (MESSAGES[1].equals(msg)) + msg = getLastCloseCode(); + return msg; + } - @OnClose - public void onClose(CloseReason reason) { - int lastCloseCode = reason.getCloseCode().getCode(); - setLastCloseCode(lastCloseCode); - } + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } - private static String getLastCloseCode() { - return String.valueOf(lastCloseCode); - } + @OnClose + public void onClose(CloseReason reason) { + int lastCloseCode = reason.getCloseCode().getCode(); + setLastCloseCode(lastCloseCode); + } - private static void setLastCloseCode(int lastCloseCode) { - WSCCloseSessionServer.lastCloseCode = lastCloseCode; - } + private static String getLastCloseCode() { + return String.valueOf(lastCloseCode); + } + + private static void setLastCloseCode(int lastCloseCode) { + WSCCloseSessionServer.lastCloseCode = lastCloseCode; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/containers/WSCServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/containers/WSCServer.java index 130716b564..9256efe3cd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/containers/WSCServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/containers/WSCServer.java @@ -29,18 +29,19 @@ @ServerEndpoint("/srv") public class WSCServer { - @OnMessage - public String onMessage(String msg, Session session) { - WebSocketContainer container; - container = session.getContainer(); - msg = String.valueOf(container.hashCode()); - return msg; - } - @OnError - public void onError(Session session, Throwable t) throws IOException { - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String onMessage(String msg, Session session) { + WebSocketContainer container; + container = session.getContainer(); + msg = String.valueOf(container.hashCode()); + return msg; + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/containers/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/containers/WSClient.java deleted file mode 100644 index bcc689c686..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/containers/WSClient.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2013, 2018 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 com.sun.ts.tests.websocket.spec.application.containers; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - private static final long serialVersionUID = -2942255764587010746L; - - public WSClient() { - setContextRoot("wsc_spec_application_containers_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* - * @testName: webSocketContainerIsOnePerVMTest - * - * @assertion_ids: WebSocket:SPEC:WSC-2.1.7-1; - * - * @test_Strategy: In server deployments of websocket implementations, there - * is one unique WebSocketContainer instance per application per Java VM - */ - public void webSocketContainerIsOnePerVMTest() throws Exception { - invoke("srv", "anything", "", false); - String address = getResponseAsString(); - invokeAgain("anything", "", false); - String address2 = getResponseAsString().substring(address.length()); - cleanup(); - assertEquals(address, address2, - "There are is not just one WebSocketContainer instance per application per VM); hashCode of first", - address, "hasCode of the second", address2); - logMsg( - "session#getContainer returns only one instance of WebSocketContainer as expected"); - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/containers/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/containers/WSClientIT.java new file mode 100644 index 0000000000..732a9a2e09 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/containers/WSClientIT.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013, 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 com.sun.ts.tests.websocket.spec.application.containers; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + private static final long serialVersionUID = -2942255764587010746L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_spec_application_containers_web.war"); + archive.addClasses(WSCServer.class); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSClientIT() throws Exception { + setup(); + setContextRoot("wsc_spec_application_containers_web"); + } + + /* + * @testName: webSocketContainerIsOnePerVMTest + * + * @assertion_ids: WebSocket:SPEC:WSC-2.1.7-1; + * + * @test_Strategy: In server deployments of websocket implementations, there is + * one unique WebSocketContainer instance per application per Java VM + */ + @Test + public void webSocketContainerIsOnePerVMTest() throws Exception { + invoke("srv", "anything", "", false); + String address = getResponseAsString(); + invokeAgain("anything", "", false); + String address2 = getResponseAsString().substring(address.length()); + cleanup(); + assertEquals(address, address2, + "There are is not just one WebSocketContainer instance per application per VM); hashCode of first", + address, "hasCode of the second", address2); + logMsg("session#getContainer returns only one instance of WebSocketContainer as expected"); + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/InnerEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/InnerEndpoint.java index ca47e653f0..93f4347b0c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/InnerEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/InnerEndpoint.java @@ -26,50 +26,49 @@ import jakarta.websocket.MessageHandler; import jakarta.websocket.Session; -public class InnerEndpoint extends Endpoint - implements MessageHandler.Whole { +public class InnerEndpoint extends Endpoint implements MessageHandler.Whole { - protected String receivedMessage = ""; + protected String receivedMessage = ""; - protected CountDownLatch latch; + protected CountDownLatch latch; - private Session session; + private Session session; - public InnerEndpoint(CountDownLatch latch) { - super(); - this.latch = latch; - } + public InnerEndpoint(CountDownLatch latch) { + super(); + this.latch = latch; + } - @Override - public void onOpen(Session session, EndpointConfig config) { - session.addMessageHandler(this); - this.session = session; - } + @Override + public void onOpen(Session session, EndpointConfig config) { + session.addMessageHandler(this); + this.session = session; + } - @Override - public void onMessage(String message) { - this.receivedMessage += message; - latch.countDown(); - } + @Override + public void onMessage(String message) { + this.receivedMessage += message; + latch.countDown(); + } - public String getReceivedMessage() { - return receivedMessage; - } + public String getReceivedMessage() { + return receivedMessage; + } - public void sendMessage(String message) { - try { - session.getBasicRemote().sendText(message); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + public void sendMessage(String message) { + try { + session.getBasicRemote().sendText(message); + } catch (IOException e) { + throw new RuntimeException(e); + } + } - public void await(long seconds) { - try { - latch.await(seconds, TimeUnit.SECONDS); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } + public void await(long seconds) { + try { + latch.await(seconds, TimeUnit.SECONDS); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/OuterEndpoint.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/OuterEndpoint.java index fccb3f92c9..37e7b065b3 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/OuterEndpoint.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/OuterEndpoint.java @@ -23,23 +23,23 @@ import jakarta.websocket.Session; public class OuterEndpoint extends InnerEndpoint { - private InnerEndpoint innerEndpoint; + private InnerEndpoint innerEndpoint; - public OuterEndpoint(InnerEndpoint innerEndpoint, CountDownLatch latch) { - super(latch); - this.innerEndpoint = innerEndpoint; - } + public OuterEndpoint(InnerEndpoint innerEndpoint, CountDownLatch latch) { + super(latch); + this.innerEndpoint = innerEndpoint; + } - @Override - public void onOpen(Session session, EndpointConfig config) { - session.addMessageHandler(this); - } + @Override + public void onOpen(Session session, EndpointConfig config) { + session.addMessageHandler(this); + } - @Override - public void onMessage(String message) { - this.receivedMessage += message; - innerEndpoint.sendMessage("anything"); - innerEndpoint.await(5L); - latch.countDown(); - } + @Override + public void onMessage(String message) { + this.receivedMessage += message; + innerEndpoint.sendMessage("anything"); + innerEndpoint.await(5L); + latch.countDown(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/WSCClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/WSCClient.java deleted file mode 100644 index 45f35daf4a..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/WSCClient.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.spec.application.lifecycle; - -import java.net.URI; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.ContainerProvider; -import jakarta.websocket.Session; -import jakarta.websocket.WebSocketContainer; - -/* - * The tests here are not guaranteed to pass in standalone TCK, hence put - * into full CTS bundle - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSCClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 7108001387006240382L; - - public WSCClient() { - setContextRoot("wsc_spec_application_lifecycle_web"); - } - - public static void main(String[] args) { - new WSCClient().run(args); - } - - /* - * @testName: serverLifeCycleTest - * - * @assertion_ids: WebSocket:SPEC:WSC-2.1.1-1; - * - * @test_Strategy: the websocket implementation must use one instance per - * application per VM of the Endpoint class to represent the logical endpoint - * per connected peer. - */ - public void serverLifeCycleTest() throws Exception { - CountDownLatch innerLatch = new CountDownLatch(1); - CountDownLatch outerLatch = new CountDownLatch(1); - WebSocketContainer container = ContainerProvider.getWebSocketContainer(); - InnerEndpoint inner = new InnerEndpoint(innerLatch); - OuterEndpoint outer = new OuterEndpoint(inner, outerLatch); - ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build(); - try { - String path = getAbsoluteUrl() + "/lifecycle"; - URI uri = new URI(path); - logMsg("connecting to", path); - - Session innerSession = container.connectToServer(inner, cec, uri); - Session outerSession = container.connectToServer(outer, cec, uri); - outerSession.getBasicRemote().sendText("anything"); - outerLatch.await(_ws_wait, TimeUnit.SECONDS); - - innerSession.close(); - outerSession.close(); - } catch (Exception e) { - fault(e); - } - assertEquals("0", outer.getReceivedMessage(), - "Server Endpoint has not been created per connection, got", - outer.getReceivedMessage()); - assertEquals("0", inner.getReceivedMessage(), - "Server Endpoint has not been created per connection; got", - inner.getReceivedMessage()); - logMsg( - "The server endpoint has been created one per application as expected"); - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/WSCClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/WSCClientIT.java new file mode 100644 index 0000000000..96de6767b3 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/WSCClientIT.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.spec.application.lifecycle; + +import java.io.IOException; +import java.net.URI; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.Session; +import jakarta.websocket.WebSocketContainer; + +/* + * The tests here are not guaranteed to pass in standalone TCK, hence put + * into full CTS bundle + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSCClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 7108001387006240382L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_spec_application_lifecycle_web.war"); + archive.addPackages(true, Filters.exclude(WSCClientIT.class), + "com.sun.ts.tests.websocket.spec.application.lifecycle"); + archive.addClasses(IOUtil.class); + return archive; + }; + + public WSCClientIT() throws Exception { + setup(); + setContextRoot("wsc_spec_application_lifecycle_web"); + } + + /* + * @testName: serverLifeCycleTest + * + * @assertion_ids: WebSocket:SPEC:WSC-2.1.1-1; + * + * @test_Strategy: the websocket implementation must use one instance per + * application per VM of the Endpoint class to represent the logical endpoint + * per connected peer. + */ + @Test + public void serverLifeCycleTest() throws Exception { + CountDownLatch innerLatch = new CountDownLatch(1); + CountDownLatch outerLatch = new CountDownLatch(1); + WebSocketContainer container = ContainerProvider.getWebSocketContainer(); + InnerEndpoint inner = new InnerEndpoint(innerLatch); + OuterEndpoint outer = new OuterEndpoint(inner, outerLatch); + ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build(); + try { + String path = getAbsoluteUrl() + "/lifecycle"; + URI uri = new URI(path); + logMsg("connecting to", path); + + Session innerSession = container.connectToServer(inner, cec, uri); + Session outerSession = container.connectToServer(outer, cec, uri); + outerSession.getBasicRemote().sendText("anything"); + outerLatch.await(_ws_wait, TimeUnit.SECONDS); + + innerSession.close(); + outerSession.close(); + } catch (Exception e) { + new Exception(e); + } + assertEquals("0", outer.getReceivedMessage(), "Server Endpoint has not been created per connection, got", + outer.getReceivedMessage()); + assertEquals("0", inner.getReceivedMessage(), "Server Endpoint has not been created per connection; got", + inner.getReceivedMessage()); + logMsg("The server endpoint has been created one per application as expected"); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/WSCServerLifecycleServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/WSCServerLifecycleServer.java index 680f03479b..8cb52cb5ff 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/WSCServerLifecycleServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/application/lifecycle/WSCServerLifecycleServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -28,19 +28,20 @@ @ServerEndpoint(value = "/lifecycle") public class WSCServerLifecycleServer { - int hitCount = 0; - - @SuppressWarnings("unused") - @OnMessage - public int onMessage(String msg, Session session) { - return hitCount++; - } - - @OnError - public void onError(Session session, Throwable thr) throws IOException { - thr.printStackTrace(); // Write to error log, too - String message = IOUtil.printStackTrace(thr); - session.getBasicRemote().sendText(message); - } + + int hitCount = 0; + + @SuppressWarnings("unused") + @OnMessage + public int onMessage(String msg, Session session) { + return hitCount++; + } + + @OnError + public void onError(Session session, Throwable thr) throws IOException { + thr.printStackTrace(); // Write to error log, too + String message = IOUtil.printStackTrace(thr); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSClient.java deleted file mode 100644 index cfd67fa73a..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSClient.java +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 com.sun.ts.tests.websocket.spec.configuration.urimatching; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; - -import jakarta.websocket.DeploymentException; - -/* - * @class.setup_props: webServerHost; - * webServerPort; - * ts_home; - * ws_wait; - */ -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = -6954038749538806576L; - - static final String ECHO = "Echo message to be sent to server endpoint"; - - public WSClient() { - setContextRoot("wsc_spec_configuration_urimatching_web"); - } - - public static void main(String[] args) { - new WSClient().run(args); - } - - /* Run test */ - - // TEXT ------------------------------------------ - - /* - * @testName: match1ExactTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /a - */ - public void match1ExactTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("a")); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, WSL1ExactServer.class.getName()); - invoke(); - } - - /* - * @testName: match1ParamTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /{a} - */ - public void match1ParamTest() throws Exception { - String param = "c"; - setProperty(Property.REQUEST, buildRequest(param)); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, param); - setProperty(Property.SEARCH_STRING, WSL1ParamServer.class.getName()); - invoke(); - } - - /* - * @testName: match2CParamDTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /c/{d} - */ - public void match2CParamDTest() throws Exception { - String param = "one"; - setProperty(Property.REQUEST, buildRequest("c/", param)); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, param); - setProperty(Property.SEARCH_STRING, WSL2CParamDServer.class.getName()); - invoke(); - } - - /* - * @testName: match2CDExactTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * - * @test_Strategy: Match /c/d - */ - public void match2CDExactTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("c/d")); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, WSL2ExactCDServer.class.getName()); - invoke(); - } - - /* - * @testName: match2ParamCExactDTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /{c}/d - */ - public void match2ParamCExactDTest() throws Exception { - String c = "one"; - setProperty(Property.REQUEST, buildRequest(c, "/d")); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, c); - setProperty(Property.SEARCH_STRING, WSL2DParamCServer.class.getName()); - invoke(); - } - - /* - * @testName: match2ParamCDTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /{c}/{d} - */ - public void match2ParamCDTest() throws Exception { - String c = "one"; - String d = "two"; - setProperty(Property.REQUEST, buildRequest(c, "/", d)); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, c); - setProperty(Property.SEARCH_STRING, d); - setProperty(Property.SEARCH_STRING, WSL2ParamCDServer.class.getName()); - invoke(); - } - - /* - * @testName: match3ACDExactTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /a/c/d - */ - public void match3ACDExactTest() throws Exception { - setProperty(Property.REQUEST, buildRequest("a/c/d")); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, WSL3ACDExactServer.class.getName()); - invoke(); - } - - /* - * @testName: match3AParamCDTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /a/{c}/{d} - */ - public void match3AParamCDTest() throws Exception { - String c = "one"; - String d = "two"; - setProperty(Property.REQUEST, buildRequest("a/", c, "/", d)); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, c); - setProperty(Property.SEARCH_STRING, d); - setProperty(Property.SEARCH_STRING, WSL3AParamCDServer.class.getName()); - invoke(); - } - - /* - * @testName: match3CParamADTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /{a}/c/{d} - */ - public void match3CParamADTest() throws Exception { - String a = "one"; - String d = "two"; - setProperty(Property.REQUEST, buildRequest(a, "/c/", d)); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, a); - setProperty(Property.SEARCH_STRING, d); - setProperty(Property.SEARCH_STRING, WSL3CParamADServer.class.getName()); - invoke(); - } - - /* - * @testName: match3DParamACTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /{a}/{c}/d - */ - public void match3DParamACTest() throws Exception { - String a = "one"; - String c = "two"; - setProperty(Property.REQUEST, buildRequest(a, "/", c, "/d")); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, a); - setProperty(Property.SEARCH_STRING, c); - setProperty(Property.SEARCH_STRING, WSL3DParamACServer.class.getName()); - invoke(); - } - - /* - * @testName: match3ParamACDTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /{a}/c/{d} - */ - public void match3ParamACDTest() throws Exception { - String a = "one"; - String c = "two"; - String d = "three"; - setProperty(Property.REQUEST, buildRequest(a, "/", c, "/", d)); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, a); - setProperty(Property.SEARCH_STRING, c); - setProperty(Property.SEARCH_STRING, d); - setProperty(Property.SEARCH_STRING, WSL3ParamACDServer.class.getName()); - invoke(); - } - - /* - * @testName: match3ACParamDTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /a/c/{d} - */ - public void match3ACParamDTest() throws Exception { - String d = "three"; - setProperty(Property.REQUEST, buildRequest("a/c/", d)); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, d); - setProperty(Property.SEARCH_STRING, WSL3ACParamDServer.class.getName()); - invoke(); - } - - /* - * @testName: match3ADParamCTest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /a/{c}/d - */ - public void match3ADParamCTest() throws Exception { - String c = "two"; - setProperty(Property.REQUEST, buildRequest("a/", c, "/d")); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, c); - setProperty(Property.SEARCH_STRING, WSL3ADParamCServer.class.getName()); - invoke(); - } - - /* - * @testName: match3CDParamATest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; - * WebSocket:SPEC:WSC-4.3-3; - * - * @test_Strategy: Match /a/{c}/d - */ - public void match3CDParamATest() throws Exception { - String a = "two"; - setProperty(Property.REQUEST, buildRequest(a, "/c/d")); - setProperty(Property.CONTENT, ECHO); - setProperty(Property.SEARCH_STRING, ECHO); - setProperty(Property.SEARCH_STRING, a); - setProperty(Property.SEARCH_STRING, WSL3CDParamAServer.class.getName()); - invoke(); - } - - /* - * @testName: noMatch4ACDETest - * - * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-4; - * - * @test_Strategy: no Match for /a/c/d/e The implementation must not establish - * the connection unless there is a match. Throws: DeploymentException - if - * the configuration is not valid - */ - public void noMatch4ACDETest() throws Exception { - setProperty(Property.REQUEST, buildRequest("a/c/d/e")); - setProperty(Property.CONTENT, ECHO); - try { - invoke(); - } catch (Exception e) { - assertCause(e, DeploymentException.class, - "DeploymentException is not the cause", e); - return; - } - fault("No Deployment exception thrown"); - } - -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSClientIT.java new file mode 100644 index 0000000000..38af5d85f2 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSClientIT.java @@ -0,0 +1,359 @@ +/* + * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * 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 com.sun.ts.tests.websocket.spec.configuration.urimatching; + +import java.io.IOException; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +import jakarta.websocket.DeploymentException; + +/* + * @class.setup_props: webServerHost; + * webServerPort; + * ws_wait; + */ +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = -6954038749538806576L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "wsc_spec_configuration_urimatching_web.war"); + archive.addPackages(true, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.spec.configuration.urimatching"); + archive.addClasses(IOUtil.class); + return archive; + }; + + static final String ECHO = "Echo message to be sent to server endpoint"; + + public WSClientIT() throws Exception { + setup(); + setContextRoot("wsc_spec_configuration_urimatching_web"); + } + + /* Run test */ + + // TEXT ------------------------------------------ + + /* + * @testName: match1ExactTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /a + */ + @Test + public void match1ExactTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("a")); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, WSL1ExactServer.class.getName()); + invoke(); + } + + /* + * @testName: match1ParamTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /{a} + */ + @Test + public void match1ParamTest() throws Exception { + String param = "c"; + setProperty(Property.REQUEST, buildRequest(param)); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, param); + setProperty(Property.SEARCH_STRING, WSL1ParamServer.class.getName()); + invoke(); + } + + /* + * @testName: match2CParamDTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /c/{d} + */ + @Test + public void match2CParamDTest() throws Exception { + String param = "one"; + setProperty(Property.REQUEST, buildRequest("c/", param)); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, param); + setProperty(Property.SEARCH_STRING, WSL2CParamDServer.class.getName()); + invoke(); + } + + /* + * @testName: match2CDExactTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * + * @test_Strategy: Match /c/d + */ + @Test + public void match2CDExactTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("c/d")); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, WSL2ExactCDServer.class.getName()); + invoke(); + } + + /* + * @testName: match2ParamCExactDTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /{c}/d + */ + @Test + public void match2ParamCExactDTest() throws Exception { + String c = "one"; + setProperty(Property.REQUEST, buildRequest(c, "/d")); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, c); + setProperty(Property.SEARCH_STRING, WSL2DParamCServer.class.getName()); + invoke(); + } + + /* + * @testName: match2ParamCDTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /{c}/{d} + */ + @Test + public void match2ParamCDTest() throws Exception { + String c = "one"; + String d = "two"; + setProperty(Property.REQUEST, buildRequest(c, "/", d)); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, c); + setProperty(Property.SEARCH_STRING, d); + setProperty(Property.SEARCH_STRING, WSL2ParamCDServer.class.getName()); + invoke(); + } + + /* + * @testName: match3ACDExactTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /a/c/d + */ + @Test + public void match3ACDExactTest() throws Exception { + setProperty(Property.REQUEST, buildRequest("a/c/d")); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, WSL3ACDExactServer.class.getName()); + invoke(); + } + + /* + * @testName: match3AParamCDTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /a/{c}/{d} + */ + @Test + public void match3AParamCDTest() throws Exception { + String c = "one"; + String d = "two"; + setProperty(Property.REQUEST, buildRequest("a/", c, "/", d)); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, c); + setProperty(Property.SEARCH_STRING, d); + setProperty(Property.SEARCH_STRING, WSL3AParamCDServer.class.getName()); + invoke(); + } + + /* + * @testName: match3CParamADTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /{a}/c/{d} + */ + @Test + public void match3CParamADTest() throws Exception { + String a = "one"; + String d = "two"; + setProperty(Property.REQUEST, buildRequest(a, "/c/", d)); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, a); + setProperty(Property.SEARCH_STRING, d); + setProperty(Property.SEARCH_STRING, WSL3CParamADServer.class.getName()); + invoke(); + } + + /* + * @testName: match3DParamACTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /{a}/{c}/d + */ + @Test + public void match3DParamACTest() throws Exception { + String a = "one"; + String c = "two"; + setProperty(Property.REQUEST, buildRequest(a, "/", c, "/d")); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, a); + setProperty(Property.SEARCH_STRING, c); + setProperty(Property.SEARCH_STRING, WSL3DParamACServer.class.getName()); + invoke(); + } + + /* + * @testName: match3ParamACDTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /{a}/c/{d} + */ + @Test + public void match3ParamACDTest() throws Exception { + String a = "one"; + String c = "two"; + String d = "three"; + setProperty(Property.REQUEST, buildRequest(a, "/", c, "/", d)); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, a); + setProperty(Property.SEARCH_STRING, c); + setProperty(Property.SEARCH_STRING, d); + setProperty(Property.SEARCH_STRING, WSL3ParamACDServer.class.getName()); + invoke(); + } + + /* + * @testName: match3ACParamDTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /a/c/{d} + */ + @Test + public void match3ACParamDTest() throws Exception { + String d = "three"; + setProperty(Property.REQUEST, buildRequest("a/c/", d)); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, d); + setProperty(Property.SEARCH_STRING, WSL3ACParamDServer.class.getName()); + invoke(); + } + + /* + * @testName: match3ADParamCTest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /a/{c}/d + */ + @Test + public void match3ADParamCTest() throws Exception { + String c = "two"; + setProperty(Property.REQUEST, buildRequest("a/", c, "/d")); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, c); + setProperty(Property.SEARCH_STRING, WSL3ADParamCServer.class.getName()); + invoke(); + } + + /* + * @testName: match3CDParamATest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-1; WebSocket:SPEC:WSC-3.1.1-3; + * WebSocket:SPEC:WSC-4.3-3; + * + * @test_Strategy: Match /a/{c}/d + */ + @Test + public void match3CDParamATest() throws Exception { + String a = "two"; + setProperty(Property.REQUEST, buildRequest(a, "/c/d")); + setProperty(Property.CONTENT, ECHO); + setProperty(Property.SEARCH_STRING, ECHO); + setProperty(Property.SEARCH_STRING, a); + setProperty(Property.SEARCH_STRING, WSL3CDParamAServer.class.getName()); + invoke(); + } + + /* + * @testName: noMatch4ACDETest + * + * @assertion_ids: WebSocket:SPEC:WSC-3.1.1-4; + * + * @test_Strategy: no Match for /a/c/d/e The implementation must not establish + * the connection unless there is a match. Throws: DeploymentException - if the + * configuration is not valid + */ + @Test + public void noMatch4ACDETest() throws Exception { + setProperty(Property.REQUEST, buildRequest("a/c/d/e")); + setProperty(Property.CONTENT, ECHO); + try { + invoke(); + } catch (Exception e) { + assertCause(e, DeploymentException.class, "DeploymentException is not the cause", e); + return; + } + new Exception("No Deployment exception thrown"); + } + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL1ExactServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL1ExactServer.java index f6ccdeb1d8..38e8ff65b0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL1ExactServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL1ExactServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/a") public class WSL1ExactServer { - @OnMessage - public String echo(String echo) { - return echo + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo) { + return echo + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL1ParamServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL1ParamServer.java index 5778337332..157bb2075f 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL1ParamServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL1ParamServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/{a}") public class WSL1ParamServer { - @OnMessage - public String echo(@PathParam("a") String param, String echo) { - return echo + param + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("a") String param, String echo) { + return echo + param + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2CParamDServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2CParamDServer.java index c9d94fa99f..4de77b2a27 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2CParamDServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2CParamDServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -30,17 +30,17 @@ @ServerEndpoint("/c/{d}") public class WSL2CParamDServer { - @OnMessage - public String echo(@PathParam("d") String param, String echo) { - return echo + param + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("d") String param, String echo) { + return echo + param + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2DParamCServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2DParamCServer.java index 9af3b8d04d..9a492c0bf0 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2DParamCServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2DParamCServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/{c}/d") public class WSL2DParamCServer { - @OnMessage - public String echo(@PathParam("c") String param, String echo) { - return echo + param + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("c") String param, String echo) { + return echo + param + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2ExactCDServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2ExactCDServer.java index 0aa185c303..28a88f843c 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2ExactCDServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2ExactCDServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/c/d") public class WSL2ExactCDServer { - @OnMessage - public String echo(String echo) { - return echo + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo) { + return echo + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2ParamCDServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2ParamCDServer.java index 608f9f297d..50a85d6ce5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2ParamCDServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL2ParamCDServer.java @@ -30,18 +30,17 @@ @ServerEndpoint("/{c}/{d}") public class WSL2ParamCDServer { - @OnMessage - public String echo(@PathParam("c") String c, @PathParam("d") String d, - String echo) { - return echo + c + d + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("c") String c, @PathParam("d") String d, String echo) { + return echo + c + d + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ACDExactServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ACDExactServer.java index 5c2221b910..6f8ab8d5e4 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ACDExactServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ACDExactServer.java @@ -29,17 +29,17 @@ @ServerEndpoint("/a/c/d") public class WSL3ACDExactServer { - @OnMessage - public String echo(String echo) { - return echo + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(String echo) { + return echo + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ACParamDServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ACParamDServer.java index a9beca77b4..e215f9bffa 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ACParamDServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ACParamDServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/a/c/{d}") public class WSL3ACParamDServer { - @OnMessage - public String echo(@PathParam("d") String d, String echo) { - return echo + d + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("d") String d, String echo) { + return echo + d + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ADParamCServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ADParamCServer.java index ce89db9aa1..408329d120 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ADParamCServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ADParamCServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/a/{c}/d") public class WSL3ADParamCServer { - @OnMessage - public String echo(@PathParam("c") String c, String echo) { - return echo + c + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("c") String c, String echo) { + return echo + c + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3AParamCDServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3AParamCDServer.java index 8097e9b02f..5979440abf 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3AParamCDServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3AParamCDServer.java @@ -30,18 +30,17 @@ @ServerEndpoint("/a/{c}/{d}") public class WSL3AParamCDServer { - @OnMessage - public String echo(@PathParam("c") String c, @PathParam("d") String d, - String echo) { - return echo + c + d + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("c") String c, @PathParam("d") String d, String echo) { + return echo + c + d + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3CDParamAServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3CDParamAServer.java index 7be50fd3b3..76cdcfe3f4 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3CDParamAServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3CDParamAServer.java @@ -30,17 +30,17 @@ @ServerEndpoint("/{a}/c/d") public class WSL3CDParamAServer { - @OnMessage - public String echo(@PathParam("a") String a, String echo) { - return echo + a + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("a") String a, String echo) { + return echo + a + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3CParamADServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3CParamADServer.java index 43f8cbc027..11cd89339d 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3CParamADServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3CParamADServer.java @@ -30,18 +30,17 @@ @ServerEndpoint("/{a}/c/{d}") public class WSL3CParamADServer { - @OnMessage - public String echo(@PathParam("a") String a, @PathParam("d") String d, - String echo) { - return echo + a + d + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("a") String a, @PathParam("d") String d, String echo) { + return echo + a + d + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3DParamACServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3DParamACServer.java index a7bfd4eabf..eba333f7b2 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3DParamACServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3DParamACServer.java @@ -30,18 +30,17 @@ @ServerEndpoint("/{a}/{c}/d") public class WSL3DParamACServer { - @OnMessage - public String echo(@PathParam("a") String a, @PathParam("c") String c, - String echo) { - return echo + a + c + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("a") String a, @PathParam("c") String c, String echo) { + return echo + a + c + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ParamACDServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ParamACDServer.java index 504fe00f34..3590d064d5 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ParamACDServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/configuration/urimatching/WSL3ParamACDServer.java @@ -30,18 +30,17 @@ @ServerEndpoint("/{a}/{c}/{d}") public class WSL3ParamACDServer { - @OnMessage - public String echo(@PathParam("a") String a, @PathParam("c") String c, - @PathParam("d") String d, String echo) { - return echo + a + c + d + getClass().getName(); - } - - @OnError - public void onError(Session session, Throwable t) throws IOException { - System.out.println("@OnError in " + getClass().getName()); - t.printStackTrace(); // Write to error log, too - String message = "Exception: " + IOUtil.printStackTrace(t); - session.getBasicRemote().sendText(message); - } + @OnMessage + public String echo(@PathParam("a") String a, @PathParam("c") String c, @PathParam("d") String d, String echo) { + return echo + a + c + d + getClass().getName(); + } + + @OnError + public void onError(Session session, Throwable t) throws IOException { + System.out.println("@OnError in " + getClass().getName()); + t.printStackTrace(); // Write to error log, too + String message = "Exception: " + IOUtil.printStackTrace(t); + session.getBasicRemote().sendText(message); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/AppConfig.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/AppConfig.java index 5a24eb53cd..2d169e0753 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/AppConfig.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/AppConfig.java @@ -23,20 +23,18 @@ import jakarta.websocket.Endpoint; import jakarta.websocket.server.ServerEndpointConfig; -public class AppConfig - implements jakarta.websocket.server.ServerApplicationConfig { +public class AppConfig implements jakarta.websocket.server.ServerApplicationConfig { - @Override - public Set getEndpointConfigs( - Set> endpointClasses) { - Set set = new HashSet<>(); - return set; - } + @Override + public Set getEndpointConfigs(Set> endpointClasses) { + Set set = new HashSet<>(); + return set; + } - @Override - public Set> getAnnotatedEndpointClasses(Set> scanned) { - Set> set = new HashSet<>(); - return set; - } + @Override + public Set> getAnnotatedEndpointClasses(Set> scanned) { + Set> set = new HashSet<>(); + return set; + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/TCKWebSocketContainerInitializer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/TCKWebSocketContainerInitializer.java index 18a72aa211..df917caf6e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/TCKWebSocketContainerInitializer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/TCKWebSocketContainerInitializer.java @@ -26,13 +26,10 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; -public class TCKWebSocketContainerInitializer - implements ServletContainerInitializer { +public class TCKWebSocketContainerInitializer implements ServletContainerInitializer { - @Override - public void onStartup(Set> arg0, ServletContext context) - throws ServletException { - context.addListener( - com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.TestListener.class); - } + @Override + public void onStartup(Set> arg0, ServletContext context) throws ServletException { + context.addListener(com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.TestListener.class); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/TestListener.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/TestListener.java index 4e260bb886..f43b385b7b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/TestListener.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/TestListener.java @@ -28,59 +28,55 @@ public class TestListener implements ServletContextListener { - /** - * Receives notification that the web application initialization process is - * starting. - * - * @param sce - * The ServletContextEvent - */ - @Override - public void contextInitialized(ServletContextEvent sce) { - boolean passed = true; - ServletContext context = sce.getServletContext(); - StringBuilder log = new StringBuilder(); + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce The ServletContextEvent + */ + @Override + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); - try { - final ServerContainer serverContainer = (ServerContainer) sce - .getServletContext() - .getAttribute("jakarta.websocket.server.ServerContainer"); - serverContainer.addEndpoint( - com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSTestServer.class); - serverContainer.addEndpoint( - com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSCloseTestServer.class); - serverContainer.addEndpoint( - com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSCloseTestServer1.class); - serverContainer.addEndpoint( - com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSCloseTestServer2.class); - serverContainer.addEndpoint( - com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSTestServerByte.class); - serverContainer.addEndpoint( - com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSTestServerPathParam.class); - serverContainer.addEndpoint( - com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSTestServerString.class); - } catch (DeploymentException ex) { - passed = false; - log.append("DeploymentException: " + ex.getMessage()); - } catch (UnsupportedOperationException ex1) { - passed = false; - log.append("UnsupportedOperationException:" + ex1.getMessage()); - } + try { + final ServerContainer serverContainer = (ServerContainer) sce.getServletContext() + .getAttribute("jakarta.websocket.server.ServerContainer"); + serverContainer.addEndpoint(com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSTestServer.class); + serverContainer + .addEndpoint(com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSCloseTestServer.class); + serverContainer + .addEndpoint(com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSCloseTestServer1.class); + serverContainer + .addEndpoint(com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSCloseTestServer2.class); + serverContainer + .addEndpoint(com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSTestServerByte.class); + serverContainer.addEndpoint( + com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSTestServerPathParam.class); + serverContainer + .addEndpoint(com.sun.ts.tests.websocket.spec.servercontainer.addendpoint.WSTestServerString.class); + } catch (DeploymentException ex) { + passed = false; + log.append("DeploymentException: " + ex.getMessage()); + } catch (UnsupportedOperationException ex1) { + passed = false; + log.append("UnsupportedOperationException:" + ex1.getMessage()); + } - context.setAttribute("TCK_TEST_STATUS", log.toString()); - context.setAttribute("TCK_TEST_PASS_STATUS", passed); + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); - System.err.println("==========TestListener: " + log.toString()); - } + System.err.println("==========TestListener: " + log.toString()); + } - /** - * Receives notification that the servlet context is about to be shut down. - * - * @param sce - * The servlet context event - */ - @Override - public void contextDestroyed(ServletContextEvent sce) { - // Do nothing - } + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce The servlet context event + */ + @Override + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSClient.java deleted file mode 100644 index 8e41f8c840..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSClient.java +++ /dev/null @@ -1,1991 +0,0 @@ -/* - * Copyright (c) 2013, 2021 Oracle and/or its affiliates and others. - * 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 - */ - -/* - * $Id$ - */ -package com.sun.ts.tests.websocket.spec.servercontainer.addendpoint; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.net.URI; -import java.nio.ByteBuffer; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.util.IOUtil; -import com.sun.ts.tests.websocket.common.util.MessageValidator; -import com.sun.ts.tests.websocket.common.util.SessionUtil; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.CloseReason; -import jakarta.websocket.ContainerProvider; -import jakarta.websocket.Endpoint; -import jakarta.websocket.EndpointConfig; -import jakarta.websocket.MessageHandler; -import jakarta.websocket.Session; -import jakarta.websocket.WebSocketContainer; - -public class WSClient extends WebSocketCommonClient { - - private static final String CONTEXT_ROOT = "/websocket_servercontainer_addendpoint_web"; - - private static final String SENT_STRING_MESSAGE = "Hello World in String"; - - private static ByteBuffer SENT_BYTE_MESSAGE = ByteBuffer - .allocate("Hello World in ByteBuffer".getBytes().length + 1); - - private static StringBuffer receivedMessageString = new StringBuffer(); - - static volatile CountDownLatch messageLatch; - - public static void main(String[] args) { - new WSClient().run(args); - } - - public WSClient() { - setContextRoot("websocket_servercontainer_addendpoint_web"); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; - */ - /* Run test */ - /* - * @testName: addMessageHandlerBasicStringTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; WebSocket:JAVADOC:184; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void addMessageHandlerBasicStringTest() throws Exception { - boolean passed = true; - String search = "Expected IllegalStateException thrown by Second TextMessageHandler|" - + "First TextMessageHander received|" + "TCKTestServerString opened|" - + "First TextMessageHander received|" - + "TCKTestServerString received String: Hello World in String|" - + "First TextMessageHander received|" + "TCKTestServerString responds"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(3); - final Session session = clientContainer.connectToServer( - TCKBasicStringEndpoint.class, config, new URI("ws://" + _hostname - + ":" + _port + CONTEXT_ROOT + "/TCKTestServerString")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings(search, - receivedMessageString.toString()); - session.close(); - - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: addMessageHandlerBasicByteBufferTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:105; - * WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; WebSocket:JAVADOC:184; - * WebSocket:SPEC:WSC-2.1.3-1; WebSocket:SPEC:WSC-2.1.3-2; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void addMessageHandlerBasicByteBufferTest() throws Exception { - boolean passed = true; - String search = "Expected IllegalStateException thrown by Second ByteBuffer MessageHandler|" - + "First Basic ByteBuffer MessageHander received|" - + "TCKTestServerByte opened|" - + "First Basic ByteBuffer MessageHander received|" - + "TCKTestServerByte received ByteBuffer: Hello World in ByteBuffer|" - + "TCKTestServerByte responds: Message in bytes"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(1); - final Session session = clientContainer - .connectToServer(TCKBasicByteEndpoint.class, config, new URI("ws://" - + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServerByte")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - SENT_BYTE_MESSAGE.put("Hello World in ByteBuffer".getBytes()); - SENT_BYTE_MESSAGE.flip(); - try { - session.getBasicRemote().sendBinary(SENT_BYTE_MESSAGE); - } catch (IOException e) { - e.printStackTrace(); - } - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings(search, - receivedMessageString.toString()); - session.close(); - - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: addMessageHandlersTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:105; - * WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; - * WebSocket:JAVADOC:134; WebSocket:JAVADOC:147; WebSocket:JAVADOC:184; - * WebSocket:SPEC:WSC-2.1.3-1; WebSocket:SPEC:WSC-2.1.3-2; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * WebSocket:SPEC:WSC-4.4-1; WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void addMessageHandlersTest() throws Exception { - boolean passed = true; - String message_sent_bytebuffer = "BasicByteBufferMessageHandler added"; - String message_sent_string = "BasicStringMessageHandler added"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - final Session session = clientContainer - .connectToServer(TCKBasicEndpoint.class, config, new URI("ws://" - + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - Set msgHanders = session.getMessageHandlers(); - receivedMessageString - .append("Start with MessageHandler=" + msgHanders.size()); - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText(message_sent_string); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - ByteBuffer data = ByteBuffer - .allocate(message_sent_bytebuffer.getBytes().length); - data.put(message_sent_bytebuffer.getBytes()); - data.flip(); - messageLatch = new CountDownLatch(3); - session.getBasicRemote().sendBinary(data); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - for (MessageHandler msgHander : msgHanders) { - session.removeMessageHandler(msgHander); - receivedMessageString - .append("MessageHandler=" + session.getMessageHandlers().size()); - } - - passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" - + "TCKTestServer opened|" + "Start with MessageHandler=2|" - + "TCKTestServer received String:|" + message_sent_string + "|" - + "TCKTestServer responds, please close your session|" - + "Basic ByteBuffer MessageHander received|" - + "TCKTestServer received ByteBuffer:|" - + "Basic ByteBuffer MessageHander received|" + message_sent_bytebuffer - + "|" + "Basic ByteBuffer MessageHander received|" - + "TCKTestServer responds: Message in bytes|" + "MessageHandler=1|" - + "MessageHandler=0", receivedMessageString.toString()); - session.close(); - - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: addMessageHandlersTest1 - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:103; - * WebSocket:JAVADOC:105; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; - * WebSocket:JAVADOC:122; WebSocket:JAVADOC:134; WebSocket:JAVADOC:147; - * WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.1.3-1; - * WebSocket:SPEC:WSC-2.1.3-2; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void addMessageHandlersTest1() throws Exception { - boolean passed = true; - final String message_sent_bytebuffer = "BasicByteBufferMessageHandler added"; - final String message_sent_reader = "BasicTextReaderMessageHandler added"; - final String message_reader_msghandler = "BasicReaderMessageHander received="; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - // No message handlers to receive messages server sends in @OnOpen - final Session session = clientContainer - .connectToServer(TCKBasicEndpoint1.class, config, new URI("ws://" - + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); - - Set msgHanders_1 = session.getMessageHandlers(); - receivedMessageString - .append("Start with MessageHandler=" + msgHanders_1.size()); - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(Reader r) { - char[] buffer = new char[128]; - try { - int i = r.read(buffer); - receivedMessageString.append("========" + message_reader_msghandler - + new String(buffer, 0, i)); - messageLatch.countDown(); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - - messageLatch = new CountDownLatch(4); - Writer writer = session.getBasicRemote().getSendWriter(); - writer.append(message_sent_reader); - writer.close(); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - Set msgHanders_2 = session.getMessageHandlers(); - receivedMessageString - .append("Now we Have MessageHandler=" + msgHanders_2.size()); - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(ByteBuffer data) { - byte[] data1 = new byte[data.remaining()]; - data.get(data1); - receivedMessageString.append(new String(data1)); - messageLatch.countDown(); - } - }); - - ByteBuffer data = ByteBuffer - .allocate((message_sent_bytebuffer).getBytes().length); - data.put((message_sent_bytebuffer).getBytes()); - data.flip(); - messageLatch = new CountDownLatch(3); - session.getBasicRemote().sendBinary(data); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - Set msgHanders_3 = session.getMessageHandlers(); - receivedMessageString - .append("Now it is MessageHandler=" + msgHanders_3.size()); - - for (MessageHandler msgHander : msgHanders_3) { - session.removeMessageHandler(msgHander); - receivedMessageString - .append("MessageHandler=" + session.getMessageHandlers().size()); - } - - passed = MessageValidator.checkSearchStrings( - "Start with MessageHandler=0|" + message_reader_msghandler + "|" - + "TCKTestServer received String:|" + message_sent_reader + "|" - + "TCKTestServer responds, please close your session|" - + "Now we Have MessageHandler=1|" - + "TCKTestServer received ByteBuffer:|" + message_sent_bytebuffer - + "|" + "TCKTestServer responds: Message in bytes|" - + "Now it is MessageHandler=2|" + "MessageHandler=1|" - + "MessageHandler=0", - receivedMessageString.toString()); - - session.close(); - - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - - System.out.println(receivedMessageString.toString()); - - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: closeTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void closeTest() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close()"); - } - - } catch (Exception e) { - e.printStackTrace(); - passed = false; - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close1Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close1Test() throws Exception { - String testName = "close1Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - session.getBasicRemote().sendText("testName=" + testName); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKTestServer opened|" + "session from Server is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - passed = false; - receivedMessageString.append(e.getMessage()); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close2Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; - * WebSocket:JAVADOC:20; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close2Test() throws Exception { - String testName = "close2Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - session.getBasicRemote().sendText("testName=" + testName); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" - + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close3Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close3Test() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" - + "session from WSCloseTestServer is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close()"); - } - - } catch (Exception e) { - e.printStackTrace(); - passed = false; - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close4Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close4Test() throws Exception { - String testName = "close1Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" - + "session from WSCloseTestServer is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - passed = false; - receivedMessageString.append(e.getMessage()); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close5Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; - * WebSocket:JAVADOC:20; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close5Test() throws Exception { - String testName = "close2Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" - + "session from WSCloseTestServer is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" - + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close6Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close6Test() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer1")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" - + "session from WSCloseTestServer1 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close()"); - } - - } catch (Exception e) { - e.printStackTrace(); - passed = false; - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close7Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close7Test() throws Exception { - String testName = "close1Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer1")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" - + "session from WSCloseTestServer1 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - passed = false; - receivedMessageString.append(e.getMessage()); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close8Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; - * WebSocket:JAVADOC:20; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close8Test() throws Exception { - String testName = "close2Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer1")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" - + "session from WSCloseTestServer1 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" - + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close9Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close9Test() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer2")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" - + "session from WSCloseTestServer2 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close()"); - } - - } catch (Exception e) { - e.printStackTrace(); - passed = false; - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close10Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close10Test() throws Exception { - String testName = "close1Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer2")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" - + "session from WSCloseTestServer2 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - passed = false; - receivedMessageString.append(e.getMessage()); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close11Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; - * WebSocket:JAVADOC:20; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-4.5-1; - * - * @test_Strategy: - */ - public void close11Test() throws Exception { - String testName = "close2Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/WSCloseTestServer2")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(1); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" - + "session from WSCloseTestServer2 is open=TRUE|" - + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" - + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", - receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: close12Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; - * WebSocket:JAVADOC:20; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.1.5-1; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * WebSocket:SPEC:WSC-4.5-2; - * - * @test_Strategy: - */ - public void close12Test() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKCloseEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator.checkSearchStrings("TCKCloseEndpoint OnOpen|" - + "TCKTestServer opened|" + "CKCloseEndpoint OnClose CloseCode|" - + "TCKCloseEndpoint OnError", receivedMessageString.toString()); - - if (session.isOpen()) { - passed = false; - receivedMessageString.append( - "=================Session stays open after calling close() from server side"); - session.close(); - } - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: getContainerTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:129; - * WebSocket:JAVADOC:184; - * - * @test_Strategy: - */ - public void getContainerTest() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - WebSocketContainer tmp = session.getContainer(); - - if (clientContainer != tmp) { - passed = false; - System.err.println("Incorrect return from getContainer" + tmp); - System.err.println("Expecting " + clientContainer); - } - - session.close(); - - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: getIdTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:130; WebSocket:JAVADOC:184; - * - * @test_Strategy: - */ - public void getIdTest() throws Exception { - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKGetIdEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - // No message handlers configured - - String tmp = session.getId(); - - session.getBasicRemote().sendText("testName=getId1Test"); - // No message handlers configured - - session.close(); - System.err.println("getId=" + tmp); - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - - } - - /* - * @testName: getId1Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:130; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void getId1Test() throws Exception { - boolean passed = true; - String testName = "getId1Test"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - String tmp = session.getId(); - - receivedMessageString.append("getId returned from client side" + tmp); - - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out.println(receivedMessageString.toString()); - - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKTestServer received String: testName=" + testName, - receivedMessageString.toString()); - - session.close(); - - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: setMaxBinaryMessageBufferSizeTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:131; WebSocket:JAVADOC:148; WebSocket:JAVADOC:184; - * - * @test_Strategy: - */ - public void setMaxBinaryMessageBufferSizeTest() throws Exception { - int size = 98765432; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - receivedMessageString - .append("getMaxBinaryMessageBufferSize returned default value =" - + session.getMaxBinaryMessageBufferSize()); - session.setMaxBinaryMessageBufferSize(size); - - int tmp = session.getMaxBinaryMessageBufferSize(); - if (tmp == size) { - receivedMessageString.append( - "getMaxBinaryMessageBufferSize returned expected value =" + tmp); - } else { - passed = false; - receivedMessageString.append( - "getMaxBinaryMessageBufferSize returned unexpected value =" + tmp); - receivedMessageString.append("expected value =" + size); - } - - session.close(); - - } catch (Exception e) { - passed = false; - receivedMessageString.append(e.getMessage()); - } - - System.out.println(receivedMessageString.toString()); - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: setMaxTextMessageBufferSizeTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:133; WebSocket:JAVADOC:150; WebSocket:JAVADOC:184; - * - * @test_Strategy: - */ - public void setMaxTextMessageBufferSizeTest() throws Exception { - int size = 987654321; - messageLatch = new CountDownLatch(1); // not to throw NPE in - // TCKBasicEndpoint - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out.println("getMaxTextMessageBufferSize returned default value =" - + session.getMaxTextMessageBufferSize()); - session.setMaxTextMessageBufferSize(size); - int tmp = session.getMaxTextMessageBufferSize(); - if (tmp == size) { - System.out.println( - "getMaxTextMessageBufferSize returned expected value =" + tmp); - } else { - System.out.println( - "getMaxTextMessageBufferSize returned unexpected value =" + tmp); - System.out.println("expected value =" + size); - } - - session.close(); - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: setTimeoutTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; WebSocket:JAVADOC:184; - * - * @test_Strategy: - */ - public void setTimeoutTest() throws Exception { - long tt = 9876543210L; - messageLatch = new CountDownLatch(1); // not to throw NPE in - // TCKBasicEndpoint - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - - System.out - .println("getMaxIdleTimeout returned default value on client side =" - + session.getMaxIdleTimeout()); - session.setMaxIdleTimeout(tt); - long tmp = session.getMaxIdleTimeout(); - if (tmp == tt) { - System.out.println("getMaxIdleTimeout returned expected value =" + tmp); - } else { - System.out - .println("getMaxIdleTimeout returned unexpected value =" + tmp); - System.out.println("expected value =" + tt); - } - session.close(); - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: setTimeout1Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; WebSocket:JAVADOC:140; - * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; - * WebSocket:SPEC:WSC-4.4-1; WebSocket:SPEC:WSC-4.4-2; WebSocket:JAVADOC:184; - * - * @test_Strategy: - */ - public void setTimeout1Test() throws Exception { - String testName = "setTimeout1Test"; - boolean passed = true; - long tt = _ws_wait * 4 * 1000L; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer?timeout=" + _ws_wait)); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out - .println("getMaxIdleTimeout returned default value on client side =" - + session.getMaxIdleTimeout()); - session.setMaxIdleTimeout(tt); - - // Wait for 2 messages but not third (which should be sent after timeout) - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait * 8, TimeUnit.SECONDS); - if (session.isOpen()) { - passed = false; - receivedMessageString.append("Session is still open after timeout"); - } - - System.out.println(receivedMessageString.toString()); - - boolean tmp = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKTestServer received String: testName=setTimeout1Test", - receivedMessageString.toString()); - if (!tmp) { - passed = false; - } - - if (receivedMessageString.indexOf("AnyString=") > -1 - || receivedMessageString - .indexOf("TCKTestServer second message after sleep") > -1) { - passed = false; - System.err.println( - "Test failed due to message sent and/or received after timeout from client side"); - - } - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: setTimeout2Test - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; WebSocket:JAVADOC:140; - * WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; - * WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void setTimeout2Test() throws Exception { - String testName = "setTimeout2Test"; - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer?timeout=" + _ws_wait)); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out - .println("getMaxIdleTimeout returned default value on client side =" - + session.getMaxIdleTimeout()); - - // Session timeout is set on server - // Wait for 2 messages but not third (which should be sent after timeout) - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - SessionUtil.waitUntilClosed(session, _ws_wait * 8, TimeUnit.SECONDS); - if (session.isOpen()) { - passed = false; - receivedMessageString.append("Session is still open after timeout"); - } - - System.out.println(receivedMessageString.toString()); - boolean tmp = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKTestServer received String: testName=setTimeout2Test", - receivedMessageString.toString()); - - if (!tmp) { - passed = false; - } - - if (receivedMessageString.indexOf("AnyString=") > -1 - || receivedMessageString - .indexOf("TCKTestServer second message after sleep") > -1) { - passed = false; - System.err.println( - "Test failed due to message sent and/or received after timeout from server side"); - - } - - if (!passed) { - throw new Exception("Test Failed"); - } - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: getQueryStringTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:140; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; - * WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void getQueryStringTest() throws Exception { - String testName = "getQueryStringTest"; - boolean passed = true; - String querystring = "test1=value1&test2=value2&test3=value3"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer?" + querystring)); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out.println(receivedMessageString.toString()); - passed = MessageValidator.checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" - + "session from Server is open=TRUE|" - + "TCKTestServer received String: testName=" + testName + "|" - + "TCKTestServer: expected Query String returned|" + querystring, - receivedMessageString.toString()); - - if (!passed) { - throw new Exception("Test Failed"); - } - - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - } - - /* - * @testName: getPathParametersTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; WebSocket:JAVADOC:138; - * WebSocket:SPEC:WSC-4.4-1; WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void getPathParametersTest() throws Exception { - String message = "invoke test"; - boolean passed = true; - String param1 = "test1"; - String param2 = "test2=xyz"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(1); - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServerPathParam/" + param1 + "/" + param2)); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(2); - session.getBasicRemote().sendText(message); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - passed = MessageValidator - .checkSearchStrings( - "TCKBasicEndpoint OnOpen|" + "WSTestServerPathParam opened|" - + "WSTestServerPathParam received String: " + message + "|" - + "WSTestServerPathParam: pathparams returned;param1=" - + param1 + ";param2=" + param2, - receivedMessageString.toString()); - - session.close(); - - } catch (Exception e) { - passed = false; - e.printStackTrace(); - } - - System.out.println(receivedMessageString.toString()); - - if (!passed) { - throw new Exception("Test Failed"); - } - } - - /* - * @testName: getRequestURITest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:142; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; - * WebSocket:SPEC:WSC-4.4-2; - * - * @test_Strategy: - */ - public void getRequestURITest() throws Exception { - String testName = "getRequestURITest"; - boolean passed = true; - String querystring = "test1=value1&test2=value2&test3=value3"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - - StringBuilder uriBuilder = new StringBuilder(); - uriBuilder.append("ws://"); - uriBuilder.append(_hostname); - if (_port != 80) { - uriBuilder.append(':'); - uriBuilder.append(_port); - } - uriBuilder.append(CONTEXT_ROOT); - uriBuilder.append("/TCKTestServer?"); - uriBuilder.append(querystring); - String uri = uriBuilder.toString(); - - Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, new URI(uri)); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out.println(receivedMessageString.toString()); - passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" - + "TCKTestServer opened|" + "session from Server is open=TRUE|" - + "TCKTestServer received String: testName=" + testName + "|" - + "TCKTestServer: getRequestURI returned=" + uri, - receivedMessageString.toString()); - } catch (Exception e) { - e.printStackTrace(); - passed = false; - } - if (!passed) { - throw new Exception("Test Failed"); - } - } - - /* - * @testName: getOpenSessionsTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; - * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; - * WebSocket:JAVADOC:137; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; - * WebSocket:SPEC:WSC-2.2.3-1; - * - * @test_Strategy: - */ - public void getOpenSessionsTest() throws Exception { - boolean passed = true; - String testName = "getOpenSessionsTest"; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(2); - Session session = clientContainer - .connectToServer(TCKOpenSessionEndpoint.class, config, new URI("ws://" - + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - int os = getOpenSessions(receivedMessageString.toString()); - - messageLatch = new CountDownLatch(2); - Session session1 = clientContainer - .connectToServer(TCKOpenSessionEndpoint.class, config, new URI("ws://" - + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session1.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - int os1 = getOpenSessions(receivedMessageString.toString()); - - messageLatch = new CountDownLatch(2); - Session session2 = clientContainer - .connectToServer(TCKOpenSessionEndpoint.class, config, new URI("ws://" - + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session2.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - int os2 = getOpenSessions(receivedMessageString.toString()); - - session.close(); - SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session1.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - int os3 = getOpenSessions(receivedMessageString.toString()); - - session1.close(); - SessionUtil.waitUntilClosed(session1, _ws_wait, TimeUnit.SECONDS); - - messageLatch = new CountDownLatch(4); - session2.getBasicRemote().sendText("testName=" + testName); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - int os4 = getOpenSessions(receivedMessageString.toString()); - - session2.close(); - - if (os == 1) { - if (os1 != 2 || os2 != 3) { - passed = false; - System.out.print("Not perfect 12321 pattern for open session"); - } - } - - if (os4 > os3 || os3 > os2) { - passed = false; - System.out.print("Incorrect XXX++ pattern for open session"); - } - - if (os < 1 || os1 < 2 || os2 < 3 || os3 < 2 || os4 < 1) { - passed = false; - System.out.print("Cannot have less open session than 12321"); - } - - if (os1 - os > 1 || os2 - os1 > 1) { - passed = false; - System.out.print("Too many session are open"); - } - - } catch (Exception ioe) { - passed = false; - ioe.printStackTrace(); - } - System.out.println(receivedMessageString.toString()); - - if (!passed) { - throw new Exception("Incorrect response received"); - } - } - - @Override - public void cleanup() throws Exception { - super.cleanup(); - } - - public final static class TCKBasicEndpoint extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - receivedMessageString.append("TCKBasicEndpoint OnOpen"); - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - receivedMessageString.append(message); - messageLatch.countDown(); - } - }); - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(ByteBuffer data) { - byte[] data1 = new byte[data.remaining()]; - data.get(data1); - receivedMessageString - .append("========Basic ByteBuffer MessageHander received=" - + new String(data1)); - messageLatch.countDown(); - } - }); - - } - - @Override - public void onClose(Session session, CloseReason closeReason) { - receivedMessageString.append( - "TCKBasicEndpoint OnClose CloseCode=" + closeReason.getCloseCode()); - receivedMessageString.append("TCKBasicEndpoint OnClose ReasonPhrase=" - + closeReason.getReasonPhrase()); - } - } - - public final static class TCKBasicEndpoint1 extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - } - } - - public final static class TCKGetIdEndpoint extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - receivedMessageString - .append("======Another SessionID=" + session.getId()); - System.out.println(session.getId()); - } - } - - public final static class TCKBasicStringEndpoint extends Endpoint { - - public void onMessage(String message) { - receivedMessageString.append("========First TextMessageHander received=") - .append(message); - messageLatch.countDown(); - } - - @Override - public void onOpen(Session session, EndpointConfig config) { - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - receivedMessageString - .append("========First TextMessageHander received=") - .append(message); - messageLatch.countDown(); - } - }); - try { - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - receivedMessageString - .append("========Second TextMessageHander received=") - .append(message); - messageLatch.countDown(); - } - }); - } catch (IllegalStateException ile) { - receivedMessageString.append( - "========Expected IllegalStateException thrown by Second TextMessageHandler"); - // ile.printStackTrace(); - } - try { - session.getBasicRemote().sendText(SENT_STRING_MESSAGE); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public final static class TCKBasicByteEndpoint extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(ByteBuffer message) { - String message_string = IOUtil.byteBufferToString(message); - receivedMessageString - .append("========First Basic ByteBuffer MessageHander received=") - .append(message_string); - messageLatch.countDown(); - } - }); - try { - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(ByteBuffer data) { - receivedMessageString - .append( - "========Second Basic ByteBuffer MessageHander received=") - .append(data.toString()); - messageLatch.countDown(); - } - }); - } catch (IllegalStateException ile) { - receivedMessageString.append( - "========Expected IllegalStateException thrown by Second ByteBuffer MessageHandler"); - // ile.printStackTrace(); - } - } - } - - public final static class TCKOpenSessionEndpoint extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - receivedMessageString.append(message); - messageLatch.countDown(); - } - }); - } - - @Override - public void onClose(Session session, CloseReason closeReason) { - receivedMessageString.append("onClose"); - } - } - - public final static class TCKCloseEndpoint extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - receivedMessageString.append("TCKCloseEndpoint OnOpen"); - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - receivedMessageString.append(message); - messageLatch.countDown(); - } - }); - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(ByteBuffer data) { - byte[] data1 = new byte[data.remaining()]; - data.get(data1); - receivedMessageString - .append("========Basic ByteBuffer MessageHander received=" - + new String(data1)); - messageLatch.countDown(); - } - }); - } - - @Override - public void onClose(Session session, CloseReason closeReason) { - receivedMessageString.append( - "TCKCloseEndpoint OnClose CloseCode=" + closeReason.getCloseCode()); - receivedMessageString - .append("Pass_On_To_Error=" + closeReason.getReasonPhrase()); - - @SuppressWarnings("unused") - int i = 1 / 0; - } - - @Override - public void onError(Session session, Throwable t) { - receivedMessageString.append("TCKCloseEndpoint OnError"); - receivedMessageString.append(t.getMessage()); - } - } - - @SuppressWarnings("unused") - private int getOpenSessions(String message) { - int start = receivedMessageString.lastIndexOf("getOpenSessions="); - int stop = receivedMessageString - .lastIndexOf("========TCKTestServer responded"); - int os = Integer - .parseInt(receivedMessageString.substring(start + 16, stop)); - System.out.println("open session=" + os); - return os; - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSClientIT.java new file mode 100644 index 0000000000..755351386d --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSClientIT.java @@ -0,0 +1,1869 @@ +/* + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $Id$ + */ +package com.sun.ts.tests.websocket.spec.servercontainer.addendpoint; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.io.Writer; +import java.net.URI; +import java.nio.ByteBuffer; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; +import com.sun.ts.tests.websocket.common.util.MessageValidator; +import com.sun.ts.tests.websocket.common.util.SessionUtil; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.CloseReason; +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.Endpoint; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.MessageHandler; +import jakarta.websocket.Session; +import jakarta.websocket.WebSocketContainer; + +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + WebArchive archive = ShrinkWrap.create(WebArchive.class, "websocket_servercontainer_addendpoint_web.war"); + final JavaArchive initializerJar = ShrinkWrap.create(JavaArchive.class, "initializer.jar") + .addClass(TCKWebSocketContainerInitializer.class); + InputStream inStream = WSClientIT.class.getClassLoader().getResourceAsStream("com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/jakarta.servlet.ServletContainerInitializer"); + StringAsset servletContainerInitializer = new StringAsset(toString(inStream)); + initializerJar.addAsManifestResource(servletContainerInitializer, "services/jakarta.servlet.ServletContainerInitializer"); + archive.addAsLibrary(initializerJar); + archive.addPackages(true, "com.sun.ts.tests.websocket.spec.servercontainer.addendpoint"); + archive.addClasses(IOUtil.class); + return archive; + }; + + private static final String CONTEXT_ROOT = "/websocket_servercontainer_addendpoint_web"; + + private static final String SENT_STRING_MESSAGE = "Hello World in String"; + + private static ByteBuffer SENT_BYTE_MESSAGE = ByteBuffer + .allocate("Hello World in ByteBuffer".getBytes().length + 1); + + private static StringBuffer receivedMessageString = new StringBuffer(); + + static volatile CountDownLatch messageLatch; + + public WSClientIT() throws Exception { + setup(); + setContextRoot("websocket_servercontainer_addendpoint_web"); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; + */ + /* Run test */ + /* + * @testName: addMessageHandlerBasicStringTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; WebSocket:JAVADOC:184; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void addMessageHandlerBasicStringTest() throws Exception { + boolean passed = true; + String search = "Expected IllegalStateException thrown by Second TextMessageHandler|" + + "First TextMessageHander received|" + "TCKTestServerString opened|" + + "First TextMessageHander received|" + "TCKTestServerString received String: Hello World in String|" + + "First TextMessageHander received|" + "TCKTestServerString responds"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(3); + final Session session = clientContainer.connectToServer(TCKBasicStringEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServerString")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings(search, receivedMessageString.toString()); + session.close(); + + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: addMessageHandlerBasicByteBufferTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:105; + * WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; WebSocket:JAVADOC:184; + * WebSocket:SPEC:WSC-2.1.3-1; WebSocket:SPEC:WSC-2.1.3-2; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void addMessageHandlerBasicByteBufferTest() throws Exception { + boolean passed = true; + String search = "Expected IllegalStateException thrown by Second ByteBuffer MessageHandler|" + + "First Basic ByteBuffer MessageHander received|" + "TCKTestServerByte opened|" + + "First Basic ByteBuffer MessageHander received|" + + "TCKTestServerByte received ByteBuffer: Hello World in ByteBuffer|" + + "TCKTestServerByte responds: Message in bytes"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(1); + final Session session = clientContainer.connectToServer(TCKBasicByteEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServerByte")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + SENT_BYTE_MESSAGE.put("Hello World in ByteBuffer".getBytes()); + SENT_BYTE_MESSAGE.flip(); + try { + session.getBasicRemote().sendBinary(SENT_BYTE_MESSAGE); + } catch (IOException e) { + e.printStackTrace(); + } + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings(search, receivedMessageString.toString()); + session.close(); + + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: addMessageHandlersTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:105; + * WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; WebSocket:JAVADOC:122; + * WebSocket:JAVADOC:134; WebSocket:JAVADOC:147; WebSocket:JAVADOC:184; + * WebSocket:SPEC:WSC-2.1.3-1; WebSocket:SPEC:WSC-2.1.3-2; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-4.4-1; WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void addMessageHandlersTest() throws Exception { + boolean passed = true; + String message_sent_bytebuffer = "BasicByteBufferMessageHandler added"; + String message_sent_string = "BasicStringMessageHandler added"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + final Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + Set msgHanders = session.getMessageHandlers(); + receivedMessageString.append("Start with MessageHandler=" + msgHanders.size()); + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText(message_sent_string); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + ByteBuffer data = ByteBuffer.allocate(message_sent_bytebuffer.getBytes().length); + data.put(message_sent_bytebuffer.getBytes()); + data.flip(); + messageLatch = new CountDownLatch(3); + session.getBasicRemote().sendBinary(data); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + for (MessageHandler msgHander : msgHanders) { + session.removeMessageHandler(msgHander); + receivedMessageString.append("MessageHandler=" + session.getMessageHandlers().size()); + } + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + + "Start with MessageHandler=2|" + "TCKTestServer received String:|" + message_sent_string + "|" + + "TCKTestServer responds, please close your session|" + "Basic ByteBuffer MessageHander received|" + + "TCKTestServer received ByteBuffer:|" + "Basic ByteBuffer MessageHander received|" + + message_sent_bytebuffer + "|" + "Basic ByteBuffer MessageHander received|" + + "TCKTestServer responds: Message in bytes|" + "MessageHandler=1|" + "MessageHandler=0", + receivedMessageString.toString()); + session.close(); + + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: addMessageHandlersTest1 + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:103; + * WebSocket:JAVADOC:105; WebSocket:JAVADOC:112; WebSocket:JAVADOC:121; + * WebSocket:JAVADOC:122; WebSocket:JAVADOC:134; WebSocket:JAVADOC:147; + * WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.1.3-1; + * WebSocket:SPEC:WSC-2.1.3-2; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void addMessageHandlersTest1() throws Exception { + boolean passed = true; + final String message_sent_bytebuffer = "BasicByteBufferMessageHandler added"; + final String message_sent_reader = "BasicTextReaderMessageHandler added"; + final String message_reader_msghandler = "BasicReaderMessageHander received="; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + // No message handlers to receive messages server sends in @OnOpen + final Session session = clientContainer.connectToServer(TCKBasicEndpoint1.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + + Set msgHanders_1 = session.getMessageHandlers(); + receivedMessageString.append("Start with MessageHandler=" + msgHanders_1.size()); + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(Reader r) { + char[] buffer = new char[128]; + try { + int i = r.read(buffer); + receivedMessageString.append("========" + message_reader_msghandler + new String(buffer, 0, i)); + messageLatch.countDown(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }); + + messageLatch = new CountDownLatch(4); + Writer writer = session.getBasicRemote().getSendWriter(); + writer.append(message_sent_reader); + writer.close(); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + Set msgHanders_2 = session.getMessageHandlers(); + receivedMessageString.append("Now we Have MessageHandler=" + msgHanders_2.size()); + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(ByteBuffer data) { + byte[] data1 = new byte[data.remaining()]; + data.get(data1); + receivedMessageString.append(new String(data1)); + messageLatch.countDown(); + } + }); + + ByteBuffer data = ByteBuffer.allocate((message_sent_bytebuffer).getBytes().length); + data.put((message_sent_bytebuffer).getBytes()); + data.flip(); + messageLatch = new CountDownLatch(3); + session.getBasicRemote().sendBinary(data); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + Set msgHanders_3 = session.getMessageHandlers(); + receivedMessageString.append("Now it is MessageHandler=" + msgHanders_3.size()); + + for (MessageHandler msgHander : msgHanders_3) { + session.removeMessageHandler(msgHander); + receivedMessageString.append("MessageHandler=" + session.getMessageHandlers().size()); + } + + passed = MessageValidator.checkSearchStrings( + "Start with MessageHandler=0|" + message_reader_msghandler + "|" + "TCKTestServer received String:|" + + message_sent_reader + "|" + "TCKTestServer responds, please close your session|" + + "Now we Have MessageHandler=1|" + "TCKTestServer received ByteBuffer:|" + + message_sent_bytebuffer + "|" + "TCKTestServer responds: Message in bytes|" + + "Now it is MessageHandler=2|" + "MessageHandler=1|" + "MessageHandler=0", + receivedMessageString.toString()); + + session.close(); + + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + + System.out.println(receivedMessageString.toString()); + + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: closeTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void closeTest() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator + .checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", + receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString.append("=================Session stays open after calling close()"); + } + + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close1Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close1Test() throws Exception { + String testName = "close1Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + session.getBasicRemote().sendText("testName=" + testName); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + passed = false; + receivedMessageString.append(e.getMessage()); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close2Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; + * WebSocket:JAVADOC:20; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close2Test() throws Exception { + String testName = "close2Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + session.getBasicRemote().sendText("testName=" + testName); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" + + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", + receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close3Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close3Test() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" + + "session from WSCloseTestServer is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString.append("=================Session stays open after calling close()"); + } + + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close4Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close4Test() throws Exception { + String testName = "close1Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" + + "session from WSCloseTestServer is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + passed = false; + receivedMessageString.append(e.getMessage()); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close5Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; + * WebSocket:JAVADOC:20; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close5Test() throws Exception { + String testName = "close2Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer opened|" + + "session from WSCloseTestServer is open=TRUE|" + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" + + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close6Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close6Test() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer1")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" + + "session from WSCloseTestServer1 is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString.append("=================Session stays open after calling close()"); + } + + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close7Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close7Test() throws Exception { + String testName = "close1Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer1")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" + + "session from WSCloseTestServer1 is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + passed = false; + receivedMessageString.append(e.getMessage()); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close8Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; + * WebSocket:JAVADOC:20; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close8Test() throws Exception { + String testName = "close2Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer1")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer1 opened|" + + "session from WSCloseTestServer1 is open=TRUE|" + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" + + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close9Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close9Test() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer2")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" + + "session from WSCloseTestServer2 is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString.append("=================Session stays open after calling close()"); + } + + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close10Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:123; WebSocket:JAVADOC:145; WebSocket:JAVADOC:184; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-2.1.5-1; WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close10Test() throws Exception { + String testName = "close1Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer2")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" + + "session from WSCloseTestServer2 is open=TRUE|" + + "TCKBasicEndpoint OnClose CloseCode=NORMAL_CLOSURE", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + passed = false; + receivedMessageString.append(e.getMessage()); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close11Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; + * WebSocket:JAVADOC:20; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-2.1.5-1; + * WebSocket:SPEC:WSC-4.5-1; + * + * @test_Strategy: + */ + @Test + public void close11Test() throws Exception { + String testName = "close2Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/WSCloseTestServer2")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(1); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "WSCloseTestServer2 opened|" + + "session from WSCloseTestServer2 is open=TRUE|" + "TCKBasicEndpoint OnClose CloseCode=TOO_BIG|" + + "TCKBasicEndpoint OnClose ReasonPhrase=TCKCloseNowWithReason", receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: close12Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:125; WebSocket:JAVADOC:145; WebSocket:JAVADOC:19; + * WebSocket:JAVADOC:20; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.1.5-1; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-4.5-2; + * + * @test_Strategy: + */ + @Test + public void close12Test() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKCloseEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings("TCKCloseEndpoint OnOpen|" + "TCKTestServer opened|" + + "CKCloseEndpoint OnClose CloseCode|" + "TCKCloseEndpoint OnError", + receivedMessageString.toString()); + + if (session.isOpen()) { + passed = false; + receivedMessageString + .append("=================Session stays open after calling close() from server side"); + session.close(); + } + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: getContainerTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:129; + * WebSocket:JAVADOC:184; + * + * @test_Strategy: + */ + @Test + public void getContainerTest() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + WebSocketContainer tmp = session.getContainer(); + + if (clientContainer != tmp) { + passed = false; + System.err.println("Incorrect return from getContainer" + tmp); + System.err.println("Expecting " + clientContainer); + } + + session.close(); + + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: getIdTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:130; WebSocket:JAVADOC:184; + * + * @test_Strategy: + */ + @Test + public void getIdTest() throws Exception { + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKGetIdEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + // No message handlers configured + + String tmp = session.getId(); + + session.getBasicRemote().sendText("testName=getId1Test"); + // No message handlers configured + + session.close(); + System.err.println("getId=" + tmp); + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + + } + + /* + * @testName: getId1Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:130; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void getId1Test() throws Exception { + boolean passed = true; + String testName = "getId1Test"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + String tmp = session.getId(); + + receivedMessageString.append("getId returned from client side" + tmp); + + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out.println(receivedMessageString.toString()); + + passed = MessageValidator + .checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKTestServer received String: testName=" + testName, + receivedMessageString.toString()); + + session.close(); + + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: setMaxBinaryMessageBufferSizeTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:131; WebSocket:JAVADOC:148; WebSocket:JAVADOC:184; + * + * @test_Strategy: + */ + @Test + public void setMaxBinaryMessageBufferSizeTest() throws Exception { + int size = 98765432; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + receivedMessageString.append( + "getMaxBinaryMessageBufferSize returned default value =" + session.getMaxBinaryMessageBufferSize()); + session.setMaxBinaryMessageBufferSize(size); + + int tmp = session.getMaxBinaryMessageBufferSize(); + if (tmp == size) { + receivedMessageString.append("getMaxBinaryMessageBufferSize returned expected value =" + tmp); + } else { + passed = false; + receivedMessageString.append("getMaxBinaryMessageBufferSize returned unexpected value =" + tmp); + receivedMessageString.append("expected value =" + size); + } + + session.close(); + + } catch (Exception e) { + passed = false; + receivedMessageString.append(e.getMessage()); + } + + System.out.println(receivedMessageString.toString()); + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: setMaxTextMessageBufferSizeTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:133; WebSocket:JAVADOC:150; WebSocket:JAVADOC:184; + * + * @test_Strategy: + */ + @Test + public void setMaxTextMessageBufferSizeTest() throws Exception { + int size = 987654321; + messageLatch = new CountDownLatch(1); // not to throw NPE in + // TCKBasicEndpoint + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out.println( + "getMaxTextMessageBufferSize returned default value =" + session.getMaxTextMessageBufferSize()); + session.setMaxTextMessageBufferSize(size); + int tmp = session.getMaxTextMessageBufferSize(); + if (tmp == size) { + System.out.println("getMaxTextMessageBufferSize returned expected value =" + tmp); + } else { + System.out.println("getMaxTextMessageBufferSize returned unexpected value =" + tmp); + System.out.println("expected value =" + size); + } + + session.close(); + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: setTimeoutTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; WebSocket:JAVADOC:184; + * + * @test_Strategy: + */ + @Test + public void setTimeoutTest() throws Exception { + long tt = 9876543210L; + messageLatch = new CountDownLatch(1); // not to throw NPE in + // TCKBasicEndpoint + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + + System.out + .println("getMaxIdleTimeout returned default value on client side =" + session.getMaxIdleTimeout()); + session.setMaxIdleTimeout(tt); + long tmp = session.getMaxIdleTimeout(); + if (tmp == tt) { + System.out.println("getMaxIdleTimeout returned expected value =" + tmp); + } else { + System.out.println("getMaxIdleTimeout returned unexpected value =" + tmp); + System.out.println("expected value =" + tt); + } + session.close(); + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: setTimeout1Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; WebSocket:JAVADOC:140; + * WebSocket:SPEC:WSC-2.2.2-1; WebSocket:SPEC:WSC-2.2.3-1; + * WebSocket:SPEC:WSC-4.4-1; WebSocket:SPEC:WSC-4.4-2; WebSocket:JAVADOC:184; + * + * @test_Strategy: + */ + @Test + public void setTimeout1Test() throws Exception { + String testName = "setTimeout1Test"; + boolean passed = true; + long tt = _ws_wait * 4 * 1000L; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer?timeout=" + _ws_wait)); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out + .println("getMaxIdleTimeout returned default value on client side =" + session.getMaxIdleTimeout()); + session.setMaxIdleTimeout(tt); + + // Wait for 2 messages but not third (which should be sent after timeout) + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait * 8, TimeUnit.SECONDS); + if (session.isOpen()) { + passed = false; + receivedMessageString.append("Session is still open after timeout"); + } + + System.out.println(receivedMessageString.toString()); + + boolean tmp = MessageValidator.checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKTestServer received String: testName=setTimeout1Test", + receivedMessageString.toString()); + if (!tmp) { + passed = false; + } + + if (receivedMessageString.indexOf("AnyString=") > -1 + || receivedMessageString.indexOf("TCKTestServer second message after sleep") > -1) { + passed = false; + System.err.println("Test failed due to message sent and/or received after timeout from client side"); + + } + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: setTimeout2Test + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:132; WebSocket:JAVADOC:149; WebSocket:JAVADOC:140; + * WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; + * WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void setTimeout2Test() throws Exception { + String testName = "setTimeout2Test"; + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer?timeout=" + _ws_wait)); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out + .println("getMaxIdleTimeout returned default value on client side =" + session.getMaxIdleTimeout()); + + // Session timeout is set on server + // Wait for 2 messages but not third (which should be sent after timeout) + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + SessionUtil.waitUntilClosed(session, _ws_wait * 8, TimeUnit.SECONDS); + if (session.isOpen()) { + passed = false; + receivedMessageString.append("Session is still open after timeout"); + } + + System.out.println(receivedMessageString.toString()); + boolean tmp = MessageValidator.checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKTestServer received String: testName=setTimeout2Test", + receivedMessageString.toString()); + + if (!tmp) { + passed = false; + } + + if (receivedMessageString.indexOf("AnyString=") > -1 + || receivedMessageString.indexOf("TCKTestServer second message after sleep") > -1) { + passed = false; + System.err.println("Test failed due to message sent and/or received after timeout from server side"); + + } + + if (!passed) { + throw new Exception("Test Failed"); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: getQueryStringTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:140; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; + * WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void getQueryStringTest() throws Exception { + String testName = "getQueryStringTest"; + boolean passed = true; + String querystring = "test1=value1&test2=value2&test3=value3"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer?" + querystring)); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out.println(receivedMessageString.toString()); + passed = MessageValidator.checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + "session from Server is open=TRUE|" + + "TCKTestServer received String: testName=" + testName + "|" + + "TCKTestServer: expected Query String returned|" + querystring, + receivedMessageString.toString()); + + if (!passed) { + throw new Exception("Test Failed"); + } + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + } + + /* + * @testName: getPathParametersTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; WebSocket:JAVADOC:138; + * WebSocket:SPEC:WSC-4.4-1; WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void getPathParametersTest() throws Exception { + String message = "invoke test"; + boolean passed = true; + String param1 = "test1"; + String param2 = "test2=xyz"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(1); + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, new URI("ws://" + + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServerPathParam/" + param1 + "/" + param2)); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(2); + session.getBasicRemote().sendText(message); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + passed = MessageValidator.checkSearchStrings( + "TCKBasicEndpoint OnOpen|" + "WSTestServerPathParam opened|" + + "WSTestServerPathParam received String: " + message + "|" + + "WSTestServerPathParam: pathparams returned;param1=" + param1 + ";param2=" + param2, + receivedMessageString.toString()); + + session.close(); + + } catch (Exception e) { + passed = false; + e.printStackTrace(); + } + + System.out.println(receivedMessageString.toString()); + + if (!passed) { + throw new Exception("Test Failed"); + } + } + + /* + * @testName: getRequestURITest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:142; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; WebSocket:SPEC:WSC-4.4-1; + * WebSocket:SPEC:WSC-4.4-2; + * + * @test_Strategy: + */ + @Test + public void getRequestURITest() throws Exception { + String testName = "getRequestURITest"; + boolean passed = true; + String querystring = "test1=value1&test2=value2&test3=value3"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + + StringBuilder uriBuilder = new StringBuilder(); + uriBuilder.append("ws://"); + uriBuilder.append(_hostname); + if (_port != 80) { + uriBuilder.append(':'); + uriBuilder.append(_port); + } + uriBuilder.append(CONTEXT_ROOT); + uriBuilder.append("/TCKTestServer?"); + uriBuilder.append(querystring); + String uri = uriBuilder.toString(); + + Session session = clientContainer.connectToServer(TCKBasicEndpoint.class, config, new URI(uri)); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out.println(receivedMessageString.toString()); + passed = MessageValidator.checkSearchStrings("TCKBasicEndpoint OnOpen|" + "TCKTestServer opened|" + + "session from Server is open=TRUE|" + "TCKTestServer received String: testName=" + testName + "|" + + "TCKTestServer: getRequestURI returned=" + uri, receivedMessageString.toString()); + } catch (Exception e) { + e.printStackTrace(); + passed = false; + } + if (!passed) { + throw new Exception("Test Failed"); + } + } + + /* + * @testName: getOpenSessionsTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:159; WebSocket:JAVADOC:69; + * WebSocket:JAVADOC:79; WebSocket:JAVADOC:128; WebSocket:JAVADOC:112; + * WebSocket:JAVADOC:137; WebSocket:JAVADOC:184; WebSocket:SPEC:WSC-2.2.2-1; + * WebSocket:SPEC:WSC-2.2.3-1; + * + * @test_Strategy: + */ + @Test + public void getOpenSessionsTest() throws Exception { + boolean passed = true; + String testName = "getOpenSessionsTest"; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(2); + Session session = clientContainer.connectToServer(TCKOpenSessionEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + int os = getOpenSessions(receivedMessageString.toString()); + + messageLatch = new CountDownLatch(2); + Session session1 = clientContainer.connectToServer(TCKOpenSessionEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session1.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + int os1 = getOpenSessions(receivedMessageString.toString()); + + messageLatch = new CountDownLatch(2); + Session session2 = clientContainer.connectToServer(TCKOpenSessionEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session2.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + int os2 = getOpenSessions(receivedMessageString.toString()); + + session.close(); + SessionUtil.waitUntilClosed(session, _ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session1.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + int os3 = getOpenSessions(receivedMessageString.toString()); + + session1.close(); + SessionUtil.waitUntilClosed(session1, _ws_wait, TimeUnit.SECONDS); + + messageLatch = new CountDownLatch(4); + session2.getBasicRemote().sendText("testName=" + testName); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + int os4 = getOpenSessions(receivedMessageString.toString()); + + session2.close(); + + if (os == 1) { + if (os1 != 2 || os2 != 3) { + passed = false; + System.out.print("Not perfect 12321 pattern for open session"); + } + } + + if (os4 > os3 || os3 > os2) { + passed = false; + System.out.print("Incorrect XXX++ pattern for open session"); + } + + if (os < 1 || os1 < 2 || os2 < 3 || os3 < 2 || os4 < 1) { + passed = false; + System.out.print("Cannot have less open session than 12321"); + } + + if (os1 - os > 1 || os2 - os1 > 1) { + passed = false; + System.out.print("Too many session are open"); + } + + } catch (Exception ioe) { + passed = false; + ioe.printStackTrace(); + } + System.out.println(receivedMessageString.toString()); + + if (!passed) { + throw new Exception("Incorrect response received"); + } + } + + @Override + public void cleanup() throws Exception { + super.cleanup(); + } + + public final static class TCKBasicEndpoint extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + receivedMessageString.append("TCKBasicEndpoint OnOpen"); + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append(message); + messageLatch.countDown(); + } + }); + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(ByteBuffer data) { + byte[] data1 = new byte[data.remaining()]; + data.get(data1); + receivedMessageString + .append("========Basic ByteBuffer MessageHander received=" + new String(data1)); + messageLatch.countDown(); + } + }); + + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + receivedMessageString.append("TCKBasicEndpoint OnClose CloseCode=" + closeReason.getCloseCode()); + receivedMessageString.append("TCKBasicEndpoint OnClose ReasonPhrase=" + closeReason.getReasonPhrase()); + } + } + + public final static class TCKBasicEndpoint1 extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + } + } + + public final static class TCKGetIdEndpoint extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + receivedMessageString.append("======Another SessionID=" + session.getId()); + System.out.println(session.getId()); + } + } + + public final static class TCKBasicStringEndpoint extends Endpoint { + + public void onMessage(String message) { + receivedMessageString.append("========First TextMessageHander received=").append(message); + messageLatch.countDown(); + } + + @Override + public void onOpen(Session session, EndpointConfig config) { + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append("========First TextMessageHander received=").append(message); + messageLatch.countDown(); + } + }); + try { + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append("========Second TextMessageHander received=").append(message); + messageLatch.countDown(); + } + }); + } catch (IllegalStateException ile) { + receivedMessageString + .append("========Expected IllegalStateException thrown by Second TextMessageHandler"); + // ile.printStackTrace(); + } + try { + session.getBasicRemote().sendText(SENT_STRING_MESSAGE); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + public final static class TCKBasicByteEndpoint extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(ByteBuffer message) { + String message_string = IOUtil.byteBufferToString(message); + receivedMessageString.append("========First Basic ByteBuffer MessageHander received=") + .append(message_string); + messageLatch.countDown(); + } + }); + try { + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(ByteBuffer data) { + receivedMessageString.append("========Second Basic ByteBuffer MessageHander received=") + .append(data.toString()); + messageLatch.countDown(); + } + }); + } catch (IllegalStateException ile) { + receivedMessageString + .append("========Expected IllegalStateException thrown by Second ByteBuffer MessageHandler"); + // ile.printStackTrace(); + } + } + } + + public final static class TCKOpenSessionEndpoint extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append(message); + messageLatch.countDown(); + } + }); + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + receivedMessageString.append("onClose"); + } + } + + public final static class TCKCloseEndpoint extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + receivedMessageString.append("TCKCloseEndpoint OnOpen"); + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append(message); + messageLatch.countDown(); + } + }); + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(ByteBuffer data) { + byte[] data1 = new byte[data.remaining()]; + data.get(data1); + receivedMessageString + .append("========Basic ByteBuffer MessageHander received=" + new String(data1)); + messageLatch.countDown(); + } + }); + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + receivedMessageString.append("TCKCloseEndpoint OnClose CloseCode=" + closeReason.getCloseCode()); + receivedMessageString.append("Pass_On_To_Error=" + closeReason.getReasonPhrase()); + + @SuppressWarnings("unused") + int i = 1 / 0; + } + + @Override + public void onError(Session session, Throwable t) { + receivedMessageString.append("TCKCloseEndpoint OnError"); + receivedMessageString.append(t.getMessage()); + } + } + + @SuppressWarnings("unused") + private int getOpenSessions(String message) { + int start = receivedMessageString.lastIndexOf("getOpenSessions="); + int stop = receivedMessageString.lastIndexOf("========TCKTestServer responded"); + int os = Integer.parseInt(receivedMessageString.substring(start + 16, stop)); + System.out.println("open session=" + os); + return os; + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer.java index d0f766217f..41e87d8643 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer.java @@ -35,98 +35,87 @@ @ServerEndpoint(value = "/WSCloseTestServer") public class WSCloseTestServer { - private static final Class[] TEST_ARGS = { String.class, Session.class }; + private static final Class[] TEST_ARGS = { String.class, Session.class }; - static String testName; + static String testName; - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========WSCloseTestServer opened"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer is open=FALSE"); - } - } + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========WSCloseTestServer opened"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from WSCloseTestServer is open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from WSCloseTestServer is open=FALSE"); + } + } - @OnMessage - public void respondString(String message, Session session) { - System.out.println("WSCloseTestServer got String message: " + message); - try { - if (message.startsWith("testName=") && message.endsWith("Test")) { - testName = message.substring(9); - Method method = WSCloseTestServer.class.getMethod(testName, TEST_ARGS); - method.invoke(this, new Object[] { message, session }); - } else { - session.getBasicRemote() - .sendText("========WSCloseTestServer received String:" + message); - session.getBasicRemote().sendText( - "========WSCloseTestServer responds, please close your session"); - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnMessage + public void respondString(String message, Session session) { + System.out.println("WSCloseTestServer got String message: " + message); + try { + if (message.startsWith("testName=") && message.endsWith("Test")) { + testName = message.substring(9); + Method method = WSCloseTestServer.class.getMethod(testName, TEST_ARGS); + method.invoke(this, new Object[] { message, session }); + } else { + session.getBasicRemote().sendText("========WSCloseTestServer received String:" + message); + session.getBasicRemote().sendText("========WSCloseTestServer responds, please close your session"); + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========WSCloseTestServer onError"); - if (session.isOpen()) { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer is open=TRUE"); - } else { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer is open=FALSE"); - } - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer onError"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer is open=TRUE"); + } else { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer is open=FALSE"); + } + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } - @OnClose - public void onClose() { - System.out.println("==From WSCloseTestServer onClose()=="); - } + @OnClose + public void onClose() { + System.out.println("==From WSCloseTestServer onClose()=="); + } - public void close1Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer received String: " + message); - session.close(); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close1Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer received String: " + message); + session.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close2Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close2Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close3Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close3Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer1.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer1.java index d476e2e6b5..f42cf60fbd 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer1.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer1.java @@ -35,98 +35,87 @@ @ServerEndpoint(value = "/WSCloseTestServer1") public class WSCloseTestServer1 { - private static final Class[] TEST_ARGS = { String.class, Session.class }; + private static final Class[] TEST_ARGS = { String.class, Session.class }; - static String testName; + static String testName; - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========WSCloseTestServer1 opened"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer1 is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer1 is open=FALSE"); - } - } + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========WSCloseTestServer1 opened"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from WSCloseTestServer1 is open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from WSCloseTestServer1 is open=FALSE"); + } + } - @OnMessage - public void respondString(String message, Session session) { - System.out.println("WSCloseTestServer1 got String message: " + message); - try { - if (message.startsWith("testName=") && message.endsWith("Test")) { - testName = message.substring(9); - Method method = WSCloseTestServer1.class.getMethod(testName, TEST_ARGS); - method.invoke(this, new Object[] { message, session }); - } else { - session.getBasicRemote() - .sendText("========WSCloseTestServer1 received String:" + message); - session.getBasicRemote().sendText( - "========WSCloseTestServer1 responds, please close your session"); - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnMessage + public void respondString(String message, Session session) { + System.out.println("WSCloseTestServer1 got String message: " + message); + try { + if (message.startsWith("testName=") && message.endsWith("Test")) { + testName = message.substring(9); + Method method = WSCloseTestServer1.class.getMethod(testName, TEST_ARGS); + method.invoke(this, new Object[] { message, session }); + } else { + session.getBasicRemote().sendText("========WSCloseTestServer1 received String:" + message); + session.getBasicRemote().sendText("========WSCloseTestServer1 responds, please close your session"); + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========WSCloseTestServer1 onError"); - if (session.isOpen()) { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer1 is open=TRUE"); - } else { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer1 is open=FALSE"); - } - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer1 onError"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer1 is open=TRUE"); + } else { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer1 is open=FALSE"); + } + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } - @OnClose - public void onClose3() { - System.out.println("==From WSCloseTestServer1 onClose(CloseReason)=="); - } + @OnClose + public void onClose3() { + System.out.println("==From WSCloseTestServer1 onClose(CloseReason)=="); + } - public void close1Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer1 received String: " + message); - session.close(); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close1Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer1 received String: " + message); + session.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close2Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer1 received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close2Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer1 received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close3Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer1 received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close3Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer1 received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer2.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer2.java index 213b77c1fa..267f66b201 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer2.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSCloseTestServer2.java @@ -35,105 +35,92 @@ @ServerEndpoint(value = "/WSCloseTestServer2") public class WSCloseTestServer2 { - private static final Class[] TEST_ARGS = { String.class, Session.class }; + private static final Class[] TEST_ARGS = { String.class, Session.class }; - static String testName; + static String testName; - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========WSCloseTestServer2 opened"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer2 is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from WSCloseTestServer2 is open=FALSE"); - } - } + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========WSCloseTestServer2 opened"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from WSCloseTestServer2 is open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from WSCloseTestServer2 is open=FALSE"); + } + } - @OnMessage - public void respondString(String message, Session session) { - System.out.println("WSCloseTestServer2 got String message: " + message); - try { - if (message.startsWith("testName=") && message.endsWith("Test")) { - testName = message.substring(9); - Method method = WSCloseTestServer2.class.getMethod(testName, TEST_ARGS); - method.invoke(this, new Object[] { message, session }); - } else { - session.getBasicRemote() - .sendText("========WSCloseTestServer2 received String:" + message); - session.getBasicRemote().sendText( - "========WSCloseTestServer2 responds, please close your session"); - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnMessage + public void respondString(String message, Session session) { + System.out.println("WSCloseTestServer2 got String message: " + message); + try { + if (message.startsWith("testName=") && message.endsWith("Test")) { + testName = message.substring(9); + Method method = WSCloseTestServer2.class.getMethod(testName, TEST_ARGS); + method.invoke(this, new Object[] { message, session }); + } else { + session.getBasicRemote().sendText("========WSCloseTestServer2 received String:" + message); + session.getBasicRemote().sendText("========WSCloseTestServer2 responds, please close your session"); + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========WSCloseTestServer2 onError"); - if (session.isOpen()) { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer2 is open=TRUE"); - } else { - session.getBasicRemote().sendText( - "========onError: session from WSCloseTestServer2 is open=FALSE"); - } - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer2 onError"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer2 is open=TRUE"); + } else { + session.getBasicRemote().sendText("========onError: session from WSCloseTestServer2 is open=FALSE"); + } + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } - @OnClose - public void onClose3(Session session) { - System.out - .println("==From WSCloseTestServer2 onClose(Session, CloseReason)=="); - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer2 OnClose(Session, CloseReason)"); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnClose + public void onClose3(Session session) { + System.out.println("==From WSCloseTestServer2 onClose(Session, CloseReason)=="); + try { + session.getBasicRemote().sendText("========WSCloseTestServer2 OnClose(Session, CloseReason)"); + } catch (Exception e) { + e.printStackTrace(); + } + } - public void close1Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer2 received String: " + message); - session.close(); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close1Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer2 received String: " + message); + session.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close2Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer2 received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close2Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer2 received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } - public void close3Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========WSCloseTestServer2 received String: " + message); - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + public void close3Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========WSCloseTestServer2 received String: " + message); + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServer.java index 1b7a3a48fb..5ce630ba3e 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServer.java @@ -42,298 +42,255 @@ @ServerEndpoint(value = "/TCKTestServer") public class WSTestServer { - private static final Class[] TEST_ARGS = { String.class, Session.class }; - - private static final Class[] TEST_ARGS_BYTEBUFFER = { ByteBuffer.class, - Session.class }; - - static String testName; - - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========TCKTestServer opened"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from Server is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from Server is open=FALSE"); - } - } - - @OnMessage - public void respondString(String message, Session session) { - System.out.println("TCKTestServer got String message: " + message); - try { - if (message.startsWith("testName=") && message.endsWith("Test")) { - testName = message.substring(9); - Method method = WSTestServer.class.getMethod(testName, TEST_ARGS); - method.invoke(this, new Object[] { message, session }); - } else { - session.getBasicRemote() - .sendText("========TCKTestServer received String:" + message); - session.getBasicRemote().sendText( - "========TCKTestServer responds, please close your session"); - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @OnMessage - public void respondByte(ByteBuffer message, Session session) { - String message_string = IOUtil.byteBufferToString(message); - - System.out - .println("TCKTestServer got ByteBuffer message: " + message_string); - - try { - if (message_string.startsWith("testName=")) { - testName = message_string.substring(9); - Method method = WSTestServer.class.getMethod(testName, - TEST_ARGS_BYTEBUFFER); - method.invoke(this, new Object[] { message, session }); - } else { - ByteBuffer data = ByteBuffer - .wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); - ByteBuffer data1 = ByteBuffer.wrap( - ("========TCKTestServer responds: Message in bytes").getBytes()); - ByteBuffer dataOrig = ByteBuffer.wrap(message_string.getBytes()); - try { - session.getBasicRemote().sendBinary(data); - session.getBasicRemote().sendBinary(dataOrig); - session.getBasicRemote().sendBinary(data1); - } catch (Exception e) { - e.printStackTrace(); - } - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @OnError - public void onError(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========TCKTestServer onError"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========onError: session from Server is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========onError: session from Server is open=FALSE"); - } - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } - - @OnClose - public void onClose(Session session) { - System.out.println("==From WSTestServer onClose(Session)=="); - try { - session.getBasicRemote() - .sendText("========WSTestServer OnClose(Session)"); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void getId1Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - session.getBasicRemote().sendText( - "========TCKTestServer responds: default getId=" + session.getId()); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - @SuppressWarnings("unused") - public void close1Test(String message, Session session) { - try { - session.close(); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - @SuppressWarnings("unused") - public void close2Test(String message, Session session) { - try { - session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, - "TCKCloseNowWithReason")); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - public void setTimeout1Test(String message, Session session) { - System.out.println( - "========In setMaxIdleTimeout1Test: TCKTestServer received String:" - + message); - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - session.getBasicRemote() - .sendText("========TCKTestServer default timeout: " - + session.getMaxIdleTimeout()); - String query_string = session.getQueryString(); - int timeout = 0; - if (query_string.startsWith("timeout")) { - timeout = Integer.parseInt(query_string.substring(8)); - Thread.sleep(timeout * 8000); - session.getBasicRemote() - .sendText("========TCKTestServer second message after sleep " - + timeout * 8 + " second"); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void setTimeout2Test(String message, Session session) { - System.out.println("========TCKTestServer received String:" + message); - CountDownLatch messageLatch = new CountDownLatch(1); - - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - session.getBasicRemote() - .sendText("========TCKTestServer default timeout: " - + session.getMaxIdleTimeout()); - - String query_string = session.getQueryString(); - int timeout = 0; - if (query_string.startsWith("timeout")) { - timeout = Integer.parseInt(query_string.substring(8)); - session.setMaxIdleTimeout(timeout * 4000); - session.getBasicRemote().sendText( - "========TCKTestServer set timeout to " + timeout * 4 + " second"); - session.getBasicRemote() - .sendText("========TCKTestServer getTimeout return " - + session.getMaxIdleTimeout() + " milliseconds"); - messageLatch.await(timeout * 6, TimeUnit.SECONDS); - session.getBasicRemote() - .sendText("========TCKTestServer second message after sleep " - + timeout * 6 + " second"); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void getQueryStringTest(String message, Session session) { - System.out.println("========TCKTestServer received String:" + message); - String expected_querystring = "test1=value1&test2=value2&test3=value3"; - - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - String query_string = session.getQueryString(); - if (expected_querystring.equals(query_string)) { - session.getBasicRemote() - .sendText("========TCKTestServer: expected Query String returned" - + query_string); - } else { - session.getBasicRemote() - .sendText("========TCKTestServer: unexpected Query String returned" - + query_string); - session.getBasicRemote().sendText( - "========TCKTestServer: expecting " + expected_querystring); - } - - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void getRequestURITest(String message, Session session) { - System.out.println("========TCKTestServer received String:" + message); - - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - URI requestURI = session.getRequestURI(); - session.getBasicRemote() - .sendText("========TCKTestServer: getRequestURI returned=" - + requestURI.toString()); - session.getBasicRemote() - .sendText("========TCKTestServer: getRequestURI returned queryString=" - + requestURI.getQuery()); - session.getBasicRemote() - .sendText("========TCKTestServer: getRequestURI returned scheme=" - + requestURI.getScheme()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void setMaxBinaryMessageBufferSizeTest2(ByteBuffer message_b, - Session session) { - System.out.println("In setMaxBinaryMessageBufferSizeTest2"); - String message = "Binary Message over size 64=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - ByteBuffer data = ByteBuffer - .wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); - ByteBuffer data1 = ByteBuffer - .wrap(("========TCKTestServer responds:").getBytes()); - ByteBuffer data2 = ByteBuffer.wrap(message.getBytes()); - - try { - session.getBasicRemote().sendBinary(data); - session.getBasicRemote().sendBinary(message_b); - session.getBasicRemote().sendBinary(data1); - session.getBasicRemote().sendBinary(data2); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - @SuppressWarnings("unused") - public void setMaxTextMessageBufferSize2Test(String message_r, - Session session) { - System.out.println("In setMaxTextMessageBufferSize2Test"); - String message = "String Message over size 64=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String Message: "); - session.getBasicRemote().sendText(message); - session.getBasicRemote().sendText("========TCKTestServer responded"); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - - public void getOpenSessionsTest(String message, Session session) { - System.out.println("In getOpenSessionsTest"); - - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String Message: "); - session.getBasicRemote().sendText(message); - Set tmp = session.getOpenSessions(); - session.getBasicRemote() - .sendText("========getOpenSessions=" + tmp.size()); - session.getBasicRemote().sendText("========TCKTestServer responded"); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + private static final Class[] TEST_ARGS = { String.class, Session.class }; + + private static final Class[] TEST_ARGS_BYTEBUFFER = { ByteBuffer.class, Session.class }; + + static String testName; + + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========TCKTestServer opened"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from Server is open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from Server is open=FALSE"); + } + } + + @OnMessage + public void respondString(String message, Session session) { + System.out.println("TCKTestServer got String message: " + message); + try { + if (message.startsWith("testName=") && message.endsWith("Test")) { + testName = message.substring(9); + Method method = WSTestServer.class.getMethod(testName, TEST_ARGS); + method.invoke(this, new Object[] { message, session }); + } else { + session.getBasicRemote().sendText("========TCKTestServer received String:" + message); + session.getBasicRemote().sendText("========TCKTestServer responds, please close your session"); + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @OnMessage + public void respondByte(ByteBuffer message, Session session) { + String message_string = IOUtil.byteBufferToString(message); + + System.out.println("TCKTestServer got ByteBuffer message: " + message_string); + + try { + if (message_string.startsWith("testName=")) { + testName = message_string.substring(9); + Method method = WSTestServer.class.getMethod(testName, TEST_ARGS_BYTEBUFFER); + method.invoke(this, new Object[] { message, session }); + } else { + ByteBuffer data = ByteBuffer.wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); + ByteBuffer data1 = ByteBuffer.wrap(("========TCKTestServer responds: Message in bytes").getBytes()); + ByteBuffer dataOrig = ByteBuffer.wrap(message_string.getBytes()); + try { + session.getBasicRemote().sendBinary(data); + session.getBasicRemote().sendBinary(dataOrig); + session.getBasicRemote().sendBinary(data1); + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @OnError + public void onError(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========TCKTestServer onError"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========onError: session from Server is open=TRUE"); + } else { + session.getBasicRemote().sendText("========onError: session from Server is open=FALSE"); + } + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } + + @OnClose + public void onClose(Session session) { + System.out.println("==From WSTestServer onClose(Session)=="); + try { + session.getBasicRemote().sendText("========WSTestServer OnClose(Session)"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void getId1Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + session.getBasicRemote().sendText("========TCKTestServer responds: default getId=" + session.getId()); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + @SuppressWarnings("unused") + public void close1Test(String message, Session session) { + try { + session.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + @SuppressWarnings("unused") + public void close2Test(String message, Session session) { + try { + session.close(new CloseReason(CloseReason.CloseCodes.TOO_BIG, "TCKCloseNowWithReason")); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public void setTimeout1Test(String message, Session session) { + System.out.println("========In setMaxIdleTimeout1Test: TCKTestServer received String:" + message); + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + session.getBasicRemote().sendText("========TCKTestServer default timeout: " + session.getMaxIdleTimeout()); + String query_string = session.getQueryString(); + int timeout = 0; + if (query_string.startsWith("timeout")) { + timeout = Integer.parseInt(query_string.substring(8)); + Thread.sleep(timeout * 8000); + session.getBasicRemote() + .sendText("========TCKTestServer second message after sleep " + timeout * 8 + " second"); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void setTimeout2Test(String message, Session session) { + System.out.println("========TCKTestServer received String:" + message); + CountDownLatch messageLatch = new CountDownLatch(1); + + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + session.getBasicRemote().sendText("========TCKTestServer default timeout: " + session.getMaxIdleTimeout()); + + String query_string = session.getQueryString(); + int timeout = 0; + if (query_string.startsWith("timeout")) { + timeout = Integer.parseInt(query_string.substring(8)); + session.setMaxIdleTimeout(timeout * 4000); + session.getBasicRemote().sendText("========TCKTestServer set timeout to " + timeout * 4 + " second"); + session.getBasicRemote().sendText( + "========TCKTestServer getTimeout return " + session.getMaxIdleTimeout() + " milliseconds"); + messageLatch.await(timeout * 6, TimeUnit.SECONDS); + session.getBasicRemote() + .sendText("========TCKTestServer second message after sleep " + timeout * 6 + " second"); + } + + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void getQueryStringTest(String message, Session session) { + System.out.println("========TCKTestServer received String:" + message); + String expected_querystring = "test1=value1&test2=value2&test3=value3"; + + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + String query_string = session.getQueryString(); + if (expected_querystring.equals(query_string)) { + session.getBasicRemote() + .sendText("========TCKTestServer: expected Query String returned" + query_string); + } else { + session.getBasicRemote() + .sendText("========TCKTestServer: unexpected Query String returned" + query_string); + session.getBasicRemote().sendText("========TCKTestServer: expecting " + expected_querystring); + } + + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void getRequestURITest(String message, Session session) { + System.out.println("========TCKTestServer received String:" + message); + + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + URI requestURI = session.getRequestURI(); + session.getBasicRemote().sendText("========TCKTestServer: getRequestURI returned=" + requestURI.toString()); + session.getBasicRemote() + .sendText("========TCKTestServer: getRequestURI returned queryString=" + requestURI.getQuery()); + session.getBasicRemote() + .sendText("========TCKTestServer: getRequestURI returned scheme=" + requestURI.getScheme()); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void setMaxBinaryMessageBufferSizeTest2(ByteBuffer message_b, Session session) { + System.out.println("In setMaxBinaryMessageBufferSizeTest2"); + String message = "Binary Message over size 64=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + ByteBuffer data = ByteBuffer.wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); + ByteBuffer data1 = ByteBuffer.wrap(("========TCKTestServer responds:").getBytes()); + ByteBuffer data2 = ByteBuffer.wrap(message.getBytes()); + + try { + session.getBasicRemote().sendBinary(data); + session.getBasicRemote().sendBinary(message_b); + session.getBasicRemote().sendBinary(data1); + session.getBasicRemote().sendBinary(data2); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + @SuppressWarnings("unused") + public void setMaxTextMessageBufferSize2Test(String message_r, Session session) { + System.out.println("In setMaxTextMessageBufferSize2Test"); + String message = "String Message over size 64=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + try { + session.getBasicRemote().sendText("========TCKTestServer received String Message: "); + session.getBasicRemote().sendText(message); + session.getBasicRemote().sendText("========TCKTestServer responded"); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public void getOpenSessionsTest(String message, Session session) { + System.out.println("In getOpenSessionsTest"); + + try { + session.getBasicRemote().sendText("========TCKTestServer received String Message: "); + session.getBasicRemote().sendText(message); + Set tmp = session.getOpenSessions(); + session.getBasicRemote().sendText("========getOpenSessions=" + tmp.size()); + session.getBasicRemote().sendText("========TCKTestServer responded"); + } catch (IOException ex) { + ex.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerByte.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerByte.java index 2bd6c779f7..e705021a8b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerByte.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerByte.java @@ -34,45 +34,41 @@ @ServerEndpoint(value = "/TCKTestServerByte") public class WSTestServerByte { - @OnOpen - public void init(Session session) throws IOException { - String message = "========TCKTestServerByte opened"; - ByteBuffer data = ByteBuffer.allocate(message.getBytes().length); - data.put(message.getBytes()); - data.flip(); - session.getBasicRemote().sendBinary(data); - } + @OnOpen + public void init(Session session) throws IOException { + String message = "========TCKTestServerByte opened"; + ByteBuffer data = ByteBuffer.allocate(message.getBytes().length); + data.put(message.getBytes()); + data.flip(); + session.getBasicRemote().sendBinary(data); + } - @OnMessage - public void respond(ByteBuffer message, Session session) { - String message_string = IOUtil.byteBufferToString(message); - System.out.println("TCKTestServerByte got Direct ByteBuffer message: " - + message_string + " from session " + session); - try { - ByteBuffer data = ByteBuffer - .allocate(("========TCKTestServerByte received ByteBuffer: " - + "========TCKTestServerByte responds: Message in bytes") - .getBytes().length - + message.capacity()); - data.put(("========TCKTestServerByte received ByteBuffer: ").getBytes()); - data.put(message_string.getBytes()); - data.put( - ("========TCKTestServerByte responds: Message in bytes").getBytes()); - data.flip(); - session.getBasicRemote().sendBinary(data); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnMessage + public void respond(ByteBuffer message, Session session) { + String message_string = IOUtil.byteBufferToString(message); + System.out.println( + "TCKTestServerByte got Direct ByteBuffer message: " + message_string + " from session " + session); + try { + ByteBuffer data = ByteBuffer.allocate(("========TCKTestServerByte received ByteBuffer: " + + "========TCKTestServerByte responds: Message in bytes").getBytes().length + message.capacity()); + data.put(("========TCKTestServerByte received ByteBuffer: ").getBytes()); + data.put(message_string.getBytes()); + data.put(("========TCKTestServerByte responds: Message in bytes").getBytes()); + data.flip(); + session.getBasicRemote().sendBinary(data); + } catch (Exception e) { + e.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - System.out.println("TCKTestServerByte onError"); - try { - session.getBasicRemote().sendText("========TCKTestServerByte onError"); - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + System.out.println("TCKTestServerByte onError"); + try { + session.getBasicRemote().sendText("========TCKTestServerByte onError"); + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerPathParam.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerPathParam.java index 459909c626..60b50370da 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerPathParam.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerPathParam.java @@ -33,44 +33,39 @@ @ServerEndpoint(value = "/TCKTestServerPathParam/{param1}/{param2}") public class WSTestServerPathParam { - @OnOpen - public void init(Session session) throws IOException { - String message = "========WSTestServerPathParam opened"; - session.getBasicRemote().sendText(message); - } + @OnOpen + public void init(Session session) throws IOException { + String message = "========WSTestServerPathParam opened"; + session.getBasicRemote().sendText(message); + } - @OnMessage - public void respond(String message, Session session) { - System.out - .println("========WSTestServerPathParam received String:" + message); - StringBuffer sb = new StringBuffer(); + @OnMessage + public void respond(String message, Session session) { + System.out.println("========WSTestServerPathParam received String:" + message); + StringBuffer sb = new StringBuffer(); - try { - session.getBasicRemote().sendText( - "========WSTestServerPathParam received String: " + message); - Map pathparams = session.getPathParameters(); - Set keys = pathparams.keySet(); - for (Object key : keys) { - System.out.println( - ";" + key.toString() + "=" + pathparams.get(key.toString())); - sb.append(";" + key.toString() + "=" + pathparams.get(key.toString())); - } - session.getBasicRemote().sendText( - "========WSTestServerPathParam: pathparams returned" + sb.toString()); - } catch (Exception ex) { - ex.printStackTrace(); - } - } + try { + session.getBasicRemote().sendText("========WSTestServerPathParam received String: " + message); + Map pathparams = session.getPathParameters(); + Set keys = pathparams.keySet(); + for (Object key : keys) { + System.out.println(";" + key.toString() + "=" + pathparams.get(key.toString())); + sb.append(";" + key.toString() + "=" + pathparams.get(key.toString())); + } + session.getBasicRemote().sendText("========WSTestServerPathParam: pathparams returned" + sb.toString()); + } catch (Exception ex) { + ex.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - System.out.println("WSTestServerPathParam onError"); - try { - session.getBasicRemote() - .sendText("========WSTestServerPathParam onError"); - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + System.out.println("WSTestServerPathParam onError"); + try { + session.getBasicRemote().sendText("========WSTestServerPathParam onError"); + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerString.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerString.java index bf6fc4e4a0..c8c9e700b7 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerString.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/WSTestServerString.java @@ -31,29 +31,28 @@ @ServerEndpoint(value = "/TCKTestServerString") public class WSTestServerString { - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========TCKTestServerString opened"); - } + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========TCKTestServerString opened"); + } - @OnMessage - public void respond(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========TCKTestServerString received String: " + message); - session.getBasicRemote().sendText("========TCKTestServerString responds"); - } catch (Exception e) { - e.printStackTrace(); - } - } + @OnMessage + public void respond(String message, Session session) { + try { + session.getBasicRemote().sendText("========TCKTestServerString received String: " + message); + session.getBasicRemote().sendText("========TCKTestServerString responds"); + } catch (Exception e) { + e.printStackTrace(); + } + } - @OnError - public void onError(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========TCKTestServerString onError"); - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } + @OnError + public void onError(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========TCKTestServerString onError"); + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/WSClientIT.java new file mode 100644 index 0000000000..bf32ac2ea3 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/WSClientIT.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation. + * + * 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 com.sun.ts.tests.websocket.spec.servercontainer.upgradehttptowebsocket; + +import java.io.IOException; +import java.net.URI; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.Filters; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.Endpoint; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.MessageHandler; +import jakarta.websocket.Session; +import jakarta.websocket.WebSocketContainer; + +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 1L; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_spec_upgradehttp_web.war"); + archive.addPackages(false, Filters.exclude(WSClientIT.class), + "com.sun.ts.tests.websocket.spec.servercontainer.upgradehttptowebsocket"); + return archive; + }; + + + private static final String MESSAGE_TEXT = "TCK upgrade test message"; + + public WSClientIT() throws Exception { + super.setup(); + setContextRoot("ws_spec_upgradehttp_web"); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; + */ + /* Run test */ + + /* + * @testName: upgradeHttpToWebSocketTest + * + * @assertion_ids: + * + * @test_Strategy: Make a WebSocket client connection request to the path + * mapped to WSTestServlet. Confirm that a WebSocket connection is + * established. Send a message. Confirm the message is echoed back. + */ + @Test + public void upgradeHttpToWebSocketTest() throws Exception { + boolean passed = false; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + CountDownLatch messageLatch = new CountDownLatch(1); + StringBuffer receivedMessageString = new StringBuffer(); + + config.getUserProperties().put("messageLatch", messageLatch); + config.getUserProperties().put("receivedMessageString", receivedMessageString); + + Session session = clientContainer.connectToServer( + TCKUpgradeEndpoint.class, + config, new URI("ws://" + _hostname + ":" + _port + "/" + getContextRoot() + "/TCKTestServlet")); + + session.getBasicRemote().sendText(MESSAGE_TEXT); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session.close(); + + if (!receivedMessageString.toString().equals(MESSAGE_TEXT)) { + throw new Exception("Received: [" + receivedMessageString.toString() + + "] but should have been [" + MESSAGE_TEXT + "]"); + } + + passed = true; + + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + public final static class TCKUpgradeEndpoint extends Endpoint { + + private CountDownLatch messageLatch; + private StringBuffer receivedMessageString; + + @Override + public void onOpen(Session session, EndpointConfig config) { + + messageLatch = (CountDownLatch)config.getUserProperties().get("messageLatch"); + receivedMessageString = (StringBuffer)config.getUserProperties().get("receivedMessageString"); + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append(message); + messageLatch.countDown(); + } + }); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/WSTestServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/WSTestServer.java new file mode 100644 index 0000000000..2cfd067fc8 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/WSTestServer.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation. + * + * 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 com.sun.ts.tests.websocket.spec.servercontainer.upgradehttptowebsocket; + +import jakarta.websocket.OnError; +import jakarta.websocket.OnMessage; +import jakarta.websocket.server.ServerEndpoint; + +@ServerEndpoint(value = "/TCKTestServer") +public class WSTestServer { + + @OnMessage + public String echo(String message) { + System.out.println("TCKTestServer got String message: " + message); + return message; + } + + @OnError + public void onError(Throwable t) { + t.printStackTrace(); + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/WSTestServlet.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/WSTestServlet.java new file mode 100644 index 0000000000..ac5be4ea8a --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/WSTestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation. + * + * 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 com.sun.ts.tests.websocket.spec.servercontainer.upgradehttptowebsocket; + +import java.io.IOException; +import java.util.Collections; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.websocket.DeploymentException; +import jakarta.websocket.server.ServerContainer; +import jakarta.websocket.server.ServerEndpointConfig; + +@WebServlet("/TCKTestServlet") +public class WSTestServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + ServerContainer sc = (ServerContainer) getServletContext().getAttribute("jakarta.websocket.server.ServerContainer"); + ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(WSTestServer.class, "/TCKTestServer").build(); + try { + sc.upgradeHttpToWebSocket(req, resp, sec, Collections.emptyMap()); + } catch (DeploymentException e) { + throw new ServletException(e); + } + } + + private static final long serialVersionUID = 1L; + +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/build.xml b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/build.xml new file mode 100644 index 0000000000..0c0017f379 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/upgradehttptowebsocket/build.xml @@ -0,0 +1,29 @@ + + + + + + + + + + diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/WSClient.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/WSClient.java deleted file mode 100644 index 4c56587271..0000000000 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/WSClient.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. - * 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 - */ - -/* - * $Id$ - */ -package com.sun.ts.tests.websocket.spec.session.sessionid; - -import java.net.URI; -import java.nio.ByteBuffer; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; -import com.sun.ts.tests.websocket.common.util.IOUtil; - -import jakarta.websocket.ClientEndpointConfig; -import jakarta.websocket.CloseReason; -import jakarta.websocket.ContainerProvider; -import jakarta.websocket.Endpoint; -import jakarta.websocket.EndpointConfig; -import jakarta.websocket.MessageHandler; -import jakarta.websocket.Session; -import jakarta.websocket.WebSocketContainer; - -public class WSClient extends WebSocketCommonClient { - - private static final long serialVersionUID = 10L; - - private static final String CONTEXT_ROOT = "/ws_spec_sessionid_web"; - - private static StringBuffer receivedMessageString = new StringBuffer(); - - static CountDownLatch messageLatch, onCloseLatch; - - static volatile String session_id, session_id_endpoint_onOpen, - session_id_endpoint_onClose; - - static volatile Session session, session_endpoint_onOpen, - session_endpoint_onClose; - - public static void main(String[] args) { - new WSClient().run(args); - } - - public WSClient() { - setContextRoot("ws_session_web"); - } - - /* - * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; - */ - /* Run test */ - - /* - * @testName: getIdTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:162; WebSocket:JAVADOC:67; - * WebSocket:JAVADOC:69; WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.1.2-1; - * - * @test_Strategy: - */ - public void getIdTest() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(1); - session = clientContainer.connectToServer( - com.sun.ts.tests.websocket.spec.session.sessionid.WSClient.TCKGetIdEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - session_id = session.getId(); - - onCloseLatch = new CountDownLatch(1); - session.close(); - onCloseLatch.await(_ws_wait, TimeUnit.SECONDS); - - if (session_id != session_id_endpoint_onOpen - || session_id != session_id_endpoint_onClose) { - passed = false; - System.out.print("Session IDs are not the same."); - } - System.out.println("session_id =" + session_id); - System.out.println( - "session_id_endpoint_onClose=" + session_id_endpoint_onClose); - System.out - .println("session_id_endpoint_onOpen =" + session_id_endpoint_onOpen); - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: instanceTest - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:162; WebSocket:JAVADOC:67; - * WebSocket:JAVADOC:69; WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.1.2-1; - * - * @test_Strategy: - */ - public void instanceTest() throws Exception { - boolean passed = true; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - messageLatch = new CountDownLatch(1); - session = clientContainer.connectToServer( - com.sun.ts.tests.websocket.spec.session.sessionid.WSClient.TCKGetIdEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - onCloseLatch = new CountDownLatch(1); - session.close(); - onCloseLatch.await(_ws_wait, TimeUnit.SECONDS); - - if (session != session_endpoint_onOpen - || session != session_endpoint_onClose) { - passed = false; - System.out.print("Sessions are not the same."); - } - System.out.println("session =" + session); - System.out - .println("session_endpoint_onClose=" + session_endpoint_onClose); - System.out.println("session_endpoint_onOpen =" + session_endpoint_onOpen); - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - /* - * @testName: unique - * - * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; - * WebSocket:JAVADOC:10; WebSocket:JAVADOC:162; WebSocket:JAVADOC:67; - * WebSocket:JAVADOC:69; WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.1.2-1; - * - * @test_Strategy: - */ - public void unique() throws Exception { - int size = 5; - boolean passed = true; - Session[] sessions = new Session[size]; - - try { - WebSocketContainer clientContainer = ContainerProvider - .getWebSocketContainer(); - ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .build(); - - for (int i = 0; i < size; i++) { - messageLatch = new CountDownLatch(1); - session = clientContainer.connectToServer( - com.sun.ts.tests.websocket.spec.session.sessionid.WSClient.TCKGetIdEndpoint.class, - config, new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT - + "/TCKTestServer")); - sessions[i] = session; - messageLatch.await(_ws_wait, TimeUnit.SECONDS); - - onCloseLatch = new CountDownLatch(1); - session.close(); - onCloseLatch.await(_ws_wait, TimeUnit.SECONDS); - - System.out.println("Session " + i); - - if (session != session_endpoint_onOpen - || session != session_endpoint_onClose) { - passed = false; - System.out.print("Sessions are not the same."); - } - - System.out.println("session =" + session); - System.out - .println("session_endpoint_onClose=" + session_endpoint_onClose); - System.out - .println("session_endpoint_onOpen =" + session_endpoint_onOpen); - } - - for (int i = 0; i < size; i++) { - for (int j = i + 1; j < size; j++) { - if (sessions[i] == sessions[j]) { - passed = false; - System.out.println("two sessions are the same: "); - System.out.println("session " + i + " " + sessions[i]); - System.out.println("session " + j + " " + sessions[j]); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - throw new Exception(e); - } - if (!passed) { - throw new Exception("Test failed with incorrect response"); - } - } - - @Override - public void cleanup() throws Exception { - super.cleanup(); - } - - public final static class TCKGetIdEndpoint extends Endpoint { - - @Override - public void onOpen(Session session, EndpointConfig config) { - session_id_endpoint_onOpen = session.getId(); - session_endpoint_onOpen = session; - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(String message) { - receivedMessageString.append(message); - messageLatch.countDown(); - } - }); - - session.addMessageHandler(new MessageHandler.Whole() { - - @Override - public void onMessage(ByteBuffer data) { - String message_string = IOUtil.byteBufferToString(data); - - receivedMessageString - .append("========Basic ByteBuffer MessageHander received=" - + message_string); - messageLatch.countDown(); - } - }); - } - - @Override - public void onClose(Session session, CloseReason closeReason) { - session_id_endpoint_onClose = session.getId(); - session_endpoint_onClose = session; - - receivedMessageString.append("CloseCode=" + closeReason.getCloseCode()); - receivedMessageString - .append("ReasonPhrase=" + closeReason.getReasonPhrase()); - onCloseLatch.countDown(); - } - } -} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/WSClientIT.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/WSClientIT.java new file mode 100644 index 0000000000..f31948d645 --- /dev/null +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/WSClientIT.java @@ -0,0 +1,277 @@ +/* + * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $Id$ + */ +package com.sun.ts.tests.websocket.spec.session.sessionid; + +import java.io.IOException; +import java.net.URI; +import java.nio.ByteBuffer; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import com.sun.ts.tests.websocket.common.client.WebSocketCommonClient; +import com.sun.ts.tests.websocket.common.util.IOUtil; + +import jakarta.websocket.ClientEndpointConfig; +import jakarta.websocket.CloseReason; +import jakarta.websocket.ContainerProvider; +import jakarta.websocket.Endpoint; +import jakarta.websocket.EndpointConfig; +import jakarta.websocket.MessageHandler; +import jakarta.websocket.Session; +import jakarta.websocket.WebSocketContainer; + +@ExtendWith(ArquillianExtension.class) +public class WSClientIT extends WebSocketCommonClient { + + private static final long serialVersionUID = 10L; + + private static final String CONTEXT_ROOT = "/ws_spec_sessionid_web"; + + private static StringBuffer receivedMessageString = new StringBuffer(); + + static CountDownLatch messageLatch, onCloseLatch; + + static volatile String session_id, session_id_endpoint_onOpen, session_id_endpoint_onClose; + + static volatile Session session, session_endpoint_onOpen, session_endpoint_onClose; + + @Deployment(testable = false) + public static WebArchive createDeployment() throws IOException { + + WebArchive archive = ShrinkWrap.create(WebArchive.class, "ws_spec_sessionid_web.war"); + archive.addClasses(WSTestServer.class); + archive.addClasses(IOUtil.class); + archive.addAsWebInfResource(WSClientIT.class.getPackage(), "web.xml", "web.xml"); + + return archive; + }; + + public WSClientIT() throws Exception { + setup(); + setContextRoot("ws_spec_sessionid_web"); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ws_wait; ts_home; + */ + /* Run test */ + + /* + * @testName: getIdTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:162; WebSocket:JAVADOC:67; + * WebSocket:JAVADOC:69; WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.1.2-1; + * + * @test_Strategy: + */ + @Test + public void getIdTest() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(1); + session = clientContainer.connectToServer( + com.sun.ts.tests.websocket.spec.session.sessionid.WSClientIT.TCKGetIdEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + session_id = session.getId(); + + onCloseLatch = new CountDownLatch(1); + session.close(); + onCloseLatch.await(_ws_wait, TimeUnit.SECONDS); + + if (session_id != session_id_endpoint_onOpen || session_id != session_id_endpoint_onClose) { + passed = false; + System.out.print("Session IDs are not the same."); + } + System.out.println("session_id =" + session_id); + System.out.println("session_id_endpoint_onClose=" + session_id_endpoint_onClose); + System.out.println("session_id_endpoint_onOpen =" + session_id_endpoint_onOpen); + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: instanceTest + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:162; WebSocket:JAVADOC:67; + * WebSocket:JAVADOC:69; WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.1.2-1; + * + * @test_Strategy: + */ + @Test + public void instanceTest() throws Exception { + boolean passed = true; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + messageLatch = new CountDownLatch(1); + session = clientContainer.connectToServer( + com.sun.ts.tests.websocket.spec.session.sessionid.WSClientIT.TCKGetIdEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + onCloseLatch = new CountDownLatch(1); + session.close(); + onCloseLatch.await(_ws_wait, TimeUnit.SECONDS); + + if (session != session_endpoint_onOpen || session != session_endpoint_onClose) { + passed = false; + System.out.print("Sessions are not the same."); + } + System.out.println("session =" + session); + System.out.println("session_endpoint_onClose=" + session_endpoint_onClose); + System.out.println("session_endpoint_onOpen =" + session_endpoint_onOpen); + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + /* + * @testName: unique + * + * @assertion_ids: WebSocket:JAVADOC:28; WebSocket:JAVADOC:8; + * WebSocket:JAVADOC:10; WebSocket:JAVADOC:162; WebSocket:JAVADOC:67; + * WebSocket:JAVADOC:69; WebSocket:JAVADOC:130; WebSocket:SPEC:WSC-2.1.2-1; + * + * @test_Strategy: + */ + @Test + public void unique() throws Exception { + int size = 5; + boolean passed = true; + Session[] sessions = new Session[size]; + + try { + WebSocketContainer clientContainer = ContainerProvider.getWebSocketContainer(); + ClientEndpointConfig config = ClientEndpointConfig.Builder.create().build(); + + for (int i = 0; i < size; i++) { + messageLatch = new CountDownLatch(1); + session = clientContainer.connectToServer( + com.sun.ts.tests.websocket.spec.session.sessionid.WSClientIT.TCKGetIdEndpoint.class, config, + new URI("ws://" + _hostname + ":" + _port + CONTEXT_ROOT + "/TCKTestServer")); + sessions[i] = session; + messageLatch.await(_ws_wait, TimeUnit.SECONDS); + + onCloseLatch = new CountDownLatch(1); + session.close(); + onCloseLatch.await(_ws_wait, TimeUnit.SECONDS); + + System.out.println("Session " + i); + + if (session != session_endpoint_onOpen || session != session_endpoint_onClose) { + passed = false; + System.out.print("Sessions are not the same."); + } + + System.out.println("session =" + session); + System.out.println("session_endpoint_onClose=" + session_endpoint_onClose); + System.out.println("session_endpoint_onOpen =" + session_endpoint_onOpen); + } + + for (int i = 0; i < size; i++) { + for (int j = i + 1; j < size; j++) { + if (sessions[i] == sessions[j]) { + passed = false; + System.out.println("two sessions are the same: "); + System.out.println("session " + i + " " + sessions[i]); + System.out.println("session " + j + " " + sessions[j]); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e); + } + if (!passed) { + throw new Exception("Test failed with incorrect response"); + } + } + + @Override + public void cleanup() throws Exception { + super.cleanup(); + } + + public final static class TCKGetIdEndpoint extends Endpoint { + + @Override + public void onOpen(Session session, EndpointConfig config) { + session_id_endpoint_onOpen = session.getId(); + session_endpoint_onOpen = session; + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(String message) { + receivedMessageString.append(message); + messageLatch.countDown(); + } + }); + + session.addMessageHandler(new MessageHandler.Whole() { + + @Override + public void onMessage(ByteBuffer data) { + String message_string = IOUtil.byteBufferToString(data); + + receivedMessageString.append("========Basic ByteBuffer MessageHander received=" + message_string); + messageLatch.countDown(); + } + }); + } + + @Override + public void onClose(Session session, CloseReason closeReason) { + session_id_endpoint_onClose = session.getId(); + session_endpoint_onClose = session; + + receivedMessageString.append("CloseCode=" + closeReason.getCloseCode()); + receivedMessageString.append("ReasonPhrase=" + closeReason.getReasonPhrase()); + onCloseLatch.countDown(); + } + } +} diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/WSTestServer.java b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/WSTestServer.java index dc4a5e5df4..2690cbb26b 100644 --- a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/WSTestServer.java +++ b/websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/WSTestServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates and others. * All rights reserved. * * This program and the accompanying materials are made available under the @@ -37,119 +37,106 @@ @ServerEndpoint(value = "/TCKTestServer") public class WSTestServer { - private static final Class[] TEST_ARGS = { String.class, Session.class }; - - private static final Class[] TEST_ARGS_BYTEBUFFER = { ByteBuffer.class, - Session.class }; - - static String testName; - - @OnOpen - public void init(Session session) throws IOException { - session.getBasicRemote().sendText("========TCKTestServer opened"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========session from Server is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========session from Server is open=FALSE"); - } - } - - @OnMessage - public void respondString(String message, Session session) { - System.out.println("TCKTestServer got String message: " + message); - try { - if (message.startsWith("testName=") && message.endsWith("Test")) { - testName = message.substring(9); - Method method = WSTestServer.class.getMethod(testName, TEST_ARGS); - method.invoke(this, new Object[] { message, session }); - } else { - session.getBasicRemote() - .sendText("========TCKTestServer received String:" + message); - session.getBasicRemote().sendText( - "========TCKTestServer responds, please close your session"); - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @OnMessage - public void respondByte(ByteBuffer message, Session session) { - String message_string = IOUtil.byteBufferToString(message); - - System.out - .println("TCKTestServer got ByteBuffer message: " + message_string); - - try { - if (message_string.startsWith("testName=")) { - testName = message_string.substring(9); - Method method = WSTestServer.class.getMethod(testName, - TEST_ARGS_BYTEBUFFER); - method.invoke(this, new Object[] { message, session }); - } else { - ByteBuffer data = ByteBuffer - .wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); - ByteBuffer data1 = ByteBuffer.wrap( - ("========TCKTestServer responds: Message in bytes").getBytes()); - - try { - session.getBasicRemote().sendBinary(data); - session.getBasicRemote().sendBinary(message); - session.getBasicRemote().sendBinary(data1); - } catch (Exception e) { - e.printStackTrace(); - } - } - } catch (InvocationTargetException ite) { - System.err.println("Cannot run method " + testName); - ite.printStackTrace(); - } catch (NoSuchMethodException nsme) { - System.err.println("Test: " + testName + " does not exist"); - nsme.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @OnError - public void onError(Session session, Throwable t) { - try { - session.getBasicRemote().sendText("========TCKTestServer onError"); - if (session.isOpen()) { - session.getBasicRemote() - .sendText("========onError: session from Server is open=TRUE"); - } else { - session.getBasicRemote() - .sendText("========onError: session from Server is open=FALSE"); - } - } catch (Exception e) { - e.printStackTrace(); - } - t.printStackTrace(); - } - - @OnClose - public void onClose() { - System.out.println("==From onClose=="); - } - - public void getId1Test(String message, Session session) { - try { - session.getBasicRemote() - .sendText("========TCKTestServer received String: " + message); - session.getBasicRemote().sendText( - "========TCKTestServer responds: default getId=" + session.getId()); - } catch (IOException ex) { - ex.printStackTrace(); - } - } + private static final Class[] TEST_ARGS = { String.class, Session.class }; + + private static final Class[] TEST_ARGS_BYTEBUFFER = { ByteBuffer.class, Session.class }; + + static String testName; + + @OnOpen + public void init(Session session) throws IOException { + session.getBasicRemote().sendText("========TCKTestServer opened"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========session from Server is open=TRUE"); + } else { + session.getBasicRemote().sendText("========session from Server is open=FALSE"); + } + } + + @OnMessage + public void respondString(String message, Session session) { + System.out.println("TCKTestServer got String message: " + message); + try { + if (message.startsWith("testName=") && message.endsWith("Test")) { + testName = message.substring(9); + Method method = WSTestServer.class.getMethod(testName, TEST_ARGS); + method.invoke(this, new Object[] { message, session }); + } else { + session.getBasicRemote().sendText("========TCKTestServer received String:" + message); + session.getBasicRemote().sendText("========TCKTestServer responds, please close your session"); + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @OnMessage + public void respondByte(ByteBuffer message, Session session) { + String message_string = IOUtil.byteBufferToString(message); + + System.out.println("TCKTestServer got ByteBuffer message: " + message_string); + + try { + if (message_string.startsWith("testName=")) { + testName = message_string.substring(9); + Method method = WSTestServer.class.getMethod(testName, TEST_ARGS_BYTEBUFFER); + method.invoke(this, new Object[] { message, session }); + } else { + ByteBuffer data = ByteBuffer.wrap(("========TCKTestServer received ByteBuffer: ").getBytes()); + ByteBuffer data1 = ByteBuffer.wrap(("========TCKTestServer responds: Message in bytes").getBytes()); + + try { + session.getBasicRemote().sendBinary(data); + session.getBasicRemote().sendBinary(message); + session.getBasicRemote().sendBinary(data1); + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (InvocationTargetException ite) { + System.err.println("Cannot run method " + testName); + ite.printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("Test: " + testName + " does not exist"); + nsme.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @OnError + public void onError(Session session, Throwable t) { + try { + session.getBasicRemote().sendText("========TCKTestServer onError"); + if (session.isOpen()) { + session.getBasicRemote().sendText("========onError: session from Server is open=TRUE"); + } else { + session.getBasicRemote().sendText("========onError: session from Server is open=FALSE"); + } + } catch (Exception e) { + e.printStackTrace(); + } + t.printStackTrace(); + } + + @OnClose + public void onClose() { + System.out.println("==From onClose=="); + } + + public void getId1Test(String message, Session session) { + try { + session.getBasicRemote().sendText("========TCKTestServer received String: " + message); + session.getBasicRemote().sendText("========TCKTestServer responds: default getId=" + session.getId()); + } catch (IOException ex) { + ex.printStackTrace(); + } + } } diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/web.xml b/websocket/src/main/resources/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/web.xml similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/web.xml rename to websocket/src/main/resources/com/sun/ts/tests/websocket/ee/jakarta/websocket/clientendpointconfig/web.xml diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/web.xml b/websocket/src/main/resources/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/web.xml similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/web.xml rename to websocket/src/main/resources/com/sun/ts/tests/websocket/ee/jakarta/websocket/session/web.xml diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/web.xml b/websocket/src/main/resources/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/web.xml similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/web.xml rename to websocket/src/main/resources/com/sun/ts/tests/websocket/ee/jakarta/websocket/sessionexception/web.xml diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/web.xml b/websocket/src/main/resources/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/web.xml similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/web.xml rename to websocket/src/main/resources/com/sun/ts/tests/websocket/ee/jakarta/websocket/websocketcontainer/web.xml diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/web.xml b/websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/web.xml similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/web.xml rename to websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/web.xml diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/wsc_platform_jakarta_websocket_handshakeresponse_authenticated_web.war.sun-web.xml b/websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/wsc_platform_jakarta_websocket_handshakeresponse_authenticated_web.war.sun-web.xml similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/wsc_platform_jakarta_websocket_handshakeresponse_authenticated_web.war.sun-web.xml rename to websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticated/wsc_platform_jakarta_websocket_handshakeresponse_authenticated_web.war.sun-web.xml diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/web.xml b/websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/web.xml similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/web.xml rename to websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/web.xml diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/wsc_platform_jakarta_websocket_handshakeresponse_authenticated_logoff_web.war.sun-web.xml b/websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/wsc_platform_jakarta_websocket_handshakeresponse_authenticated_logoff_web.war.sun-web.xml similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/wsc_platform_jakarta_websocket_handshakeresponse_authenticated_logoff_web.war.sun-web.xml rename to websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedlogoff/wsc_platform_jakarta_websocket_handshakeresponse_authenticated_logoff_web.war.sun-web.xml diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/web.xml b/websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/web.xml similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/web.xml rename to websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/web.xml diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/wsc_platform_jakarta_websocket_handshakeresponse_ssl_web.war.sun-web.xml b/websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/wsc_platform_jakarta_websocket_handshakeresponse_ssl_web.war.sun-web.xml similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/wsc_platform_jakarta_websocket_handshakeresponse_ssl_web.war.sun-web.xml rename to websocket/src/main/resources/com/sun/ts/tests/websocket/platform/jakarta/websocket/server/handshakerequest/authenticatedssl/wsc_platform_jakarta_websocket_handshakeresponse_ssl_web.war.sun-web.xml diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/jakarta.servlet.ServletContainerInitializer b/websocket/src/main/resources/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/jakarta.servlet.ServletContainerInitializer similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/jakarta.servlet.ServletContainerInitializer rename to websocket/src/main/resources/com/sun/ts/tests/websocket/spec/servercontainer/addendpoint/jakarta.servlet.ServletContainerInitializer diff --git a/websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/web.xml b/websocket/src/main/resources/com/sun/ts/tests/websocket/spec/session/sessionid/web.xml similarity index 100% rename from websocket/src/main/java/com/sun/ts/tests/websocket/spec/session/sessionid/web.xml rename to websocket/src/main/resources/com/sun/ts/tests/websocket/spec/session/sessionid/web.xml