You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2018/11/29 21:48:58 UTC

[09/10] tomee git commit: TOMEE-2283 - address PR feedback: * I've removed the NOTICE/LICENSE files. * Added missing headers to a few files. * I updated the package name... I had forgot to rename the package name... :) * removed value= when * correct, th

http://git-wip-us.apache.org/repos/asf/tomee/blob/d7f8b452/examples/websocket-tls-basic-auth/src/test/java/api/WebSocketResourceTest.java
----------------------------------------------------------------------
diff --git a/examples/websocket-tls-basic-auth/src/test/java/api/WebSocketResourceTest.java b/examples/websocket-tls-basic-auth/src/test/java/api/WebSocketResourceTest.java
deleted file mode 100644
index 21bf2bc..0000000
--- a/examples/websocket-tls-basic-auth/src/test/java/api/WebSocketResourceTest.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package api;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.container.test.api.RunAsClient;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.test.api.ArquillianResource;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import javax.websocket.ClientEndpointConfig;
-import javax.websocket.CloseReason;
-import javax.websocket.ContainerProvider;
-import javax.websocket.Endpoint;
-import javax.websocket.EndpointConfig;
-import javax.websocket.MessageHandler.Whole;
-import javax.websocket.Session;
-import java.io.File;
-import java.net.URI;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-
-import static java.util.Arrays.asList;
-import static javax.xml.bind.DatatypeConverter.printBase64Binary;
-import static org.junit.Assert.assertEquals;
-
-@RunAsClient
-@RunWith(Arquillian.class)
-public class WebSocketResourceTest {
-
-    private static final int PORT = 8443;
-
-    @ArquillianResource()
-    private URL url;
-
-    @Deployment(name = "cve", testable = false)
-    public static final WebArchive app() {
-        return ShrinkWrap.create(WebArchive.class, "example.war")
-                .addClasses(WebSocketResource.class)
-                .addAsWebInfResource(new File("src/main/webapp/WEB-INF/web.xml"), "web.xml");
-    }
-
-    @Test
-    public void sayHi() throws Exception {
-
-
-        final URI uri = url.toURI();
-
-        final AtomicReference<String> message = new AtomicReference<>();
-        final CountDownLatch latch = new CountDownLatch(1);
-
-        Endpoint endpoint = new Endpoint() {
-            @Override
-            public void onClose(final Session session,
-                                final CloseReason closeReason) {
-                super.onClose(session, closeReason);
-                System.out.println("onClose: " + closeReason);
-
-            }
-
-            @Override
-            public void onError(final Session session,
-                                final Throwable throwable) {
-                super.onError(session, throwable);
-                System.out.println("onError: " + throwable);
-            }
-
-            @Override
-            public void onOpen(final Session session,
-                               final EndpointConfig endpointConfig) {
-                session.addMessageHandler(new Whole<String>() {
-                    @Override
-                    public void onMessage(final String content) {
-                        message.set(content);
-                        latch.countDown();
-                    }
-                });
-            }
-        };
-
-        ClientEndpointConfig.Configurator configurator = new ClientEndpointConfig.Configurator() {
-            public void beforeRequest(Map<String, List<String>> headers) {
-                headers.put("Authorization", asList("Basic " + printBase64Binary("tomee:tomee".getBytes())));
-            }
-        };
-
-        ClientEndpointConfig authorizationConfiguration = ClientEndpointConfig.Builder.create()
-                .configurator(configurator)
-                .build();
-
-        //use same keystore as the server
-        authorizationConfiguration.getUserProperties().put("org.apache.tomcat.websocket.SSL_TRUSTSTORE",
-                "src/main/conf/keystore.jks");
-        authorizationConfiguration.getUserProperties().put("org.apache.tomcat.websocket.SSL_TRUSTSTORE_PWD",
-                "123456");
-
-        Session session = ContainerProvider.getWebSocketContainer()
-                .connectToServer(
-                        endpoint,
-                        authorizationConfiguration,
-//                      When using the keystore.jks.ca-cert certificate
-//                      new URI("wss", uri.getUserInfo(), "www.example.org", PORT, "/example/socket",
-//                              null, null)
-                        new URI("wss", uri.getUserInfo(), "localhost", PORT, "/example/socket",
-                                null, null)
-                );
-
-        latch.await(1, TimeUnit.MINUTES);
-        session.close();
-
-        assertEquals("Hello tomee", message.get());
-    }
-}

http://git-wip-us.apache.org/repos/asf/tomee/blob/d7f8b452/examples/websocket-tls-basic-auth/src/test/java/org/superbiz/websockets/WebSocketResourceTest.java
----------------------------------------------------------------------
diff --git a/examples/websocket-tls-basic-auth/src/test/java/org/superbiz/websockets/WebSocketResourceTest.java b/examples/websocket-tls-basic-auth/src/test/java/org/superbiz/websockets/WebSocketResourceTest.java
new file mode 100644
index 0000000..6f3611e
--- /dev/null
+++ b/examples/websocket-tls-basic-auth/src/test/java/org/superbiz/websockets/WebSocketResourceTest.java
@@ -0,0 +1,135 @@
+package org.superbiz.websockets;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.websocket.ClientEndpointConfig;
+import javax.websocket.CloseReason;
+import javax.websocket.ContainerProvider;
+import javax.websocket.Endpoint;
+import javax.websocket.EndpointConfig;
+import javax.websocket.MessageHandler.Whole;
+import javax.websocket.Session;
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static java.util.Arrays.asList;
+import static javax.xml.bind.DatatypeConverter.printBase64Binary;
+import static org.junit.Assert.assertEquals;
+
+@RunAsClient
+@RunWith(Arquillian.class)
+public class WebSocketResourceTest {
+
+    private static final int PORT = 8443;
+
+    @ArquillianResource()
+    private URL url;
+
+    @Deployment(testable = false)
+    public static final WebArchive app() {
+        return ShrinkWrap.create(WebArchive.class, "example.war")
+                .addClasses(WebSocketResource.class)
+                .addAsWebInfResource(new File("src/main/webapp/WEB-INF/web.xml"), "web.xml");
+    }
+
+    @Test
+    public void sayHi() throws Exception {
+
+
+        final URI uri = url.toURI();
+
+        final AtomicReference<String> message = new AtomicReference<>();
+        final CountDownLatch latch = new CountDownLatch(1);
+
+        Endpoint endpoint = new Endpoint() {
+            @Override
+            public void onClose(final Session session,
+                                final CloseReason closeReason) {
+                super.onClose(session, closeReason);
+                System.out.println("onClose: " + closeReason);
+
+            }
+
+            @Override
+            public void onError(final Session session,
+                                final Throwable throwable) {
+                super.onError(session, throwable);
+                System.out.println("onError: " + throwable);
+            }
+
+            @Override
+            public void onOpen(final Session session,
+                               final EndpointConfig endpointConfig) {
+                session.addMessageHandler(new Whole<String>() {
+                    @Override
+                    public void onMessage(final String content) {
+                        message.set(content);
+                        latch.countDown();
+                    }
+                });
+            }
+        };
+
+        ClientEndpointConfig.Configurator configurator = new ClientEndpointConfig.Configurator() {
+            public void beforeRequest(Map<String, List<String>> headers) {
+                headers.put("Authorization", asList("Basic " + printBase64Binary("tomee:tomee".getBytes())));
+            }
+        };
+
+        ClientEndpointConfig authorizationConfiguration = ClientEndpointConfig.Builder.create()
+                .configurator(configurator)
+                .build();
+
+        //use same keystore as the server
+        authorizationConfiguration.getUserProperties().put("org.apache.tomcat.websocket.SSL_TRUSTSTORE",
+                "src/main/conf/keystore.jks");
+        authorizationConfiguration.getUserProperties().put("org.apache.tomcat.websocket.SSL_TRUSTSTORE_PWD",
+                "123456");
+
+        Session session = ContainerProvider.getWebSocketContainer()
+                .connectToServer(
+                        endpoint,
+                        authorizationConfiguration,
+//                      When using the keystore.jks.ca-cert certificate
+//                      new URI("wss", uri.getUserInfo(), "www.example.org", PORT, "/example/socket",
+//                              null, null)
+                        new URI("wss", uri.getUserInfo(), "localhost", PORT, "/example/socket",
+                                null, null)
+                );
+
+        latch.await(1, TimeUnit.MINUTES);
+        session.close();
+
+        assertEquals("Hello tomee", message.get());
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/d7f8b452/examples/websocket-tls-basic-auth/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/examples/websocket-tls-basic-auth/src/test/resources/arquillian.xml b/examples/websocket-tls-basic-auth/src/test/resources/arquillian.xml
index df328c3..7b98461 100644
--- a/examples/websocket-tls-basic-auth/src/test/resources/arquillian.xml
+++ b/examples/websocket-tls-basic-auth/src/test/resources/arquillian.xml
@@ -1,3 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
 <arquillian xmlns="http://jboss.org/schema/arquillian"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="