< prev index next >

test/jdk/java/net/httpclient/websocket/WSHandshakeExceptionTest.java

Print this page

  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /*
 25  * @test
 26  * @bug 8240666
 27  * @summary Basic test for WebSocketHandshakeException
 28  * @library /test/lib
 29  * @build jdk.test.lib.net.SimpleSSLContext
 30  * @modules java.net.http
 31  *          jdk.httpserver
 32  * @run testng/othervm -Djdk.internal.httpclient.debug=true WSHandshakeExceptionTest
 33  */
 34 
 35 import com.sun.net.httpserver.HttpHandler;
 36 import com.sun.net.httpserver.HttpServer;
 37 import com.sun.net.httpserver.HttpsConfigurator;
 38 import com.sun.net.httpserver.HttpsServer;
 39 import com.sun.net.httpserver.HttpExchange;
 40 
 41 
 42 
 43 import java.io.IOException;
 44 import java.io.InputStream;
 45 import java.io.OutputStream;
 46 import java.net.InetAddress;
 47 import java.net.http.HttpClient;
 48 import java.net.http.WebSocket;
 49 import java.net.http.WebSocketHandshakeException;


 50 import jdk.test.lib.net.SimpleSSLContext;
 51 import org.testng.annotations.AfterTest;
 52 import org.testng.annotations.BeforeTest;
 53 import org.testng.annotations.DataProvider;
 54 import org.testng.annotations.Test;
 55 import javax.net.ssl.SSLContext;
 56 import java.net.InetSocketAddress;
 57 import java.net.URI;
 58 import java.util.concurrent.CompletionException;
 59 import java.util.concurrent.ExecutionException;
 60 import java.util.concurrent.ExecutorService;
 61 import java.util.concurrent.Executors;
 62 
 63 import static java.net.http.HttpClient.Builder.NO_PROXY;
 64 import static org.testng.Assert.assertEquals;
 65 import static org.testng.Assert.assertNotNull;
 66 import static org.testng.Assert.assertTrue;
 67 import static org.testng.Assert.fail;
 68 import static java.lang.System.out;
 69 

155             Thread.sleep(ms);
156         } catch (InterruptedException x) {
157             // OK
158         }
159     }
160 
161     @BeforeTest
162     public void setup() throws Exception {
163         sslContext = new SimpleSSLContext().get();
164         if (sslContext == null)
165             throw new AssertionError("Unexpected null sslContext");
166 
167         // HTTP/1.1
168         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
169         httpTestServer = HttpServer.create(sa, 0);
170         httpURI = "ws://localhost:" + httpTestServer.getAddress().getPort() + "/";
171         httpNonUtf8URI = "ws://localhost:" + httpTestServer.getAddress().getPort() + "/nonutf8body";
172         httpTestServer.createContext("/nonutf8body", new BodyHandler());
173 
174         httpsTestServer = HttpsServer.create(sa, 0);
175         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
176         httpsURI = "wss://localhost:" + httpsTestServer.getAddress().getPort() + "/";
177         httpsNonUtf8URI = "wss://localhost:" + httpsTestServer.getAddress().getPort() + "/nonutf8body";
178         httpsTestServer.createContext("/nonutf8body", new BodyHandler());
179 
180         httpTestServer.start();
181         httpsTestServer.start();
182     }
183 
184     @AfterTest
185     public void teardown() {
186         sharedClient = null;
187         gc(100);
188         httpTestServer.stop(0);
189         httpsTestServer.stop(0);
190         executor.shutdownNow();
191     }
192 
193     private static Throwable getCompletionCause(Throwable x) {
194         if (!(x instanceof CompletionException)
195                 && !(x instanceof ExecutionException)) return x;

  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 /*
 25  * @test
 26  * @bug 8240666
 27  * @summary Basic test for WebSocketHandshakeException
 28  * @library /test/lib /test/jdk/java/net/httpclient/lib
 29  * @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.common.TestServerConfigurator
 30  * @modules java.net.http/jdk.internal.net.http.common
 31  *          jdk.httpserver
 32  * @run testng/othervm -Djdk.internal.httpclient.debug=true WSHandshakeExceptionTest
 33  */
 34 
 35 import com.sun.net.httpserver.HttpHandler;
 36 import com.sun.net.httpserver.HttpServer;

 37 import com.sun.net.httpserver.HttpsServer;
 38 import com.sun.net.httpserver.HttpExchange;
 39 
 40 
 41 
 42 import java.io.IOException;
 43 import java.io.InputStream;
 44 import java.io.OutputStream;
 45 import java.net.InetAddress;
 46 import java.net.http.HttpClient;
 47 import java.net.http.WebSocket;
 48 import java.net.http.WebSocketHandshakeException;
 49 
 50 import jdk.httpclient.test.lib.common.TestServerConfigurator;
 51 import jdk.test.lib.net.SimpleSSLContext;
 52 import org.testng.annotations.AfterTest;
 53 import org.testng.annotations.BeforeTest;
 54 import org.testng.annotations.DataProvider;
 55 import org.testng.annotations.Test;
 56 import javax.net.ssl.SSLContext;
 57 import java.net.InetSocketAddress;
 58 import java.net.URI;
 59 import java.util.concurrent.CompletionException;
 60 import java.util.concurrent.ExecutionException;
 61 import java.util.concurrent.ExecutorService;
 62 import java.util.concurrent.Executors;
 63 
 64 import static java.net.http.HttpClient.Builder.NO_PROXY;
 65 import static org.testng.Assert.assertEquals;
 66 import static org.testng.Assert.assertNotNull;
 67 import static org.testng.Assert.assertTrue;
 68 import static org.testng.Assert.fail;
 69 import static java.lang.System.out;
 70 

156             Thread.sleep(ms);
157         } catch (InterruptedException x) {
158             // OK
159         }
160     }
161 
162     @BeforeTest
163     public void setup() throws Exception {
164         sslContext = new SimpleSSLContext().get();
165         if (sslContext == null)
166             throw new AssertionError("Unexpected null sslContext");
167 
168         // HTTP/1.1
169         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
170         httpTestServer = HttpServer.create(sa, 0);
171         httpURI = "ws://localhost:" + httpTestServer.getAddress().getPort() + "/";
172         httpNonUtf8URI = "ws://localhost:" + httpTestServer.getAddress().getPort() + "/nonutf8body";
173         httpTestServer.createContext("/nonutf8body", new BodyHandler());
174 
175         httpsTestServer = HttpsServer.create(sa, 0);
176         httpsTestServer.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), sslContext));
177         httpsURI = "wss://localhost:" + httpsTestServer.getAddress().getPort() + "/";
178         httpsNonUtf8URI = "wss://localhost:" + httpsTestServer.getAddress().getPort() + "/nonutf8body";
179         httpsTestServer.createContext("/nonutf8body", new BodyHandler());
180 
181         httpTestServer.start();
182         httpsTestServer.start();
183     }
184 
185     @AfterTest
186     public void teardown() {
187         sharedClient = null;
188         gc(100);
189         httpTestServer.stop(0);
190         httpsTestServer.stop(0);
191         executor.shutdownNow();
192     }
193 
194     private static Throwable getCompletionCause(Throwable x) {
195         if (!(x instanceof CompletionException)
196                 && !(x instanceof ExecutionException)) return x;
< prev index next >