< prev index next >

test/jdk/java/net/httpclient/websocket/HandshakeUrlEncodingTest.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 8245245
 27  * @summary Test for Websocket URI encoding during HandShake
 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 HandshakeUrlEncodingTest
 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 import jdk.test.lib.net.SimpleSSLContext;
 41 import jdk.test.lib.net.URIBuilder;
 42 import org.testng.annotations.AfterTest;
 43 import org.testng.annotations.BeforeTest;
 44 import org.testng.annotations.DataProvider;
 45 import org.testng.annotations.Test;
 46 
 47 import javax.net.ssl.SSLContext;
 48 import java.io.IOException;
 49 import java.io.InputStream;
 50 import java.io.OutputStream;
 51 import java.net.InetAddress;
 52 import java.net.InetSocketAddress;
 53 import java.net.URI;
 54 import java.net.http.HttpClient;
 55 import java.net.http.WebSocket;
 56 import java.net.http.WebSocketHandshakeException;
 57 import java.util.concurrent.CompletionException;
 58 import java.util.concurrent.ExecutionException;
 59 import java.util.concurrent.ExecutorService;

137     public void setup() throws Exception {
138         sslContext = new SimpleSSLContext().get();
139         if (sslContext == null)
140             throw new AssertionError("Unexpected null sslContext");
141 
142 
143         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
144         queryPart = "?&raw=abc+def/ghi=xyz&encoded=abc%2Bdef%2Fghi%3Dxyz";
145         httpTestServer = HttpServer.create(sa, 10);
146         httpURI = URIBuilder.newBuilder()
147                             .scheme("ws")
148                             .host("localhost")
149                             .port(httpTestServer.getAddress().getPort())
150                             .path("/")
151                             .build()
152                             .toString() + queryPart;
153 
154         httpTestServer.createContext("/", new UrlHandler());
155 
156         httpsTestServer = HttpsServer.create(sa, 10);
157         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
158         httpsURI = URIBuilder.newBuilder()
159                              .scheme("wss")
160                              .host("localhost")
161                              .port(httpsTestServer.getAddress().getPort())
162                              .path("/")
163                              .build()
164                              .toString() + queryPart;
165 
166         httpsTestServer.createContext("/", new UrlHandler());
167 
168         httpTestServer.start();
169         httpsTestServer.start();
170     }
171 
172     @AfterTest
173     public void teardown() {
174         httpTestServer.stop(0);
175         httpsTestServer.stop(0);
176         executor.shutdownNow();
177     }

  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 8245245
 27  * @summary Test for Websocket URI encoding during HandShake
 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 HandshakeUrlEncodingTest
 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 import jdk.httpclient.test.lib.common.TestServerConfigurator;
 40 import jdk.test.lib.net.SimpleSSLContext;
 41 import jdk.test.lib.net.URIBuilder;
 42 import org.testng.annotations.AfterTest;
 43 import org.testng.annotations.BeforeTest;
 44 import org.testng.annotations.DataProvider;
 45 import org.testng.annotations.Test;
 46 
 47 import javax.net.ssl.SSLContext;
 48 import java.io.IOException;
 49 import java.io.InputStream;
 50 import java.io.OutputStream;
 51 import java.net.InetAddress;
 52 import java.net.InetSocketAddress;
 53 import java.net.URI;
 54 import java.net.http.HttpClient;
 55 import java.net.http.WebSocket;
 56 import java.net.http.WebSocketHandshakeException;
 57 import java.util.concurrent.CompletionException;
 58 import java.util.concurrent.ExecutionException;
 59 import java.util.concurrent.ExecutorService;

137     public void setup() throws Exception {
138         sslContext = new SimpleSSLContext().get();
139         if (sslContext == null)
140             throw new AssertionError("Unexpected null sslContext");
141 
142 
143         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
144         queryPart = "?&raw=abc+def/ghi=xyz&encoded=abc%2Bdef%2Fghi%3Dxyz";
145         httpTestServer = HttpServer.create(sa, 10);
146         httpURI = URIBuilder.newBuilder()
147                             .scheme("ws")
148                             .host("localhost")
149                             .port(httpTestServer.getAddress().getPort())
150                             .path("/")
151                             .build()
152                             .toString() + queryPart;
153 
154         httpTestServer.createContext("/", new UrlHandler());
155 
156         httpsTestServer = HttpsServer.create(sa, 10);
157         httpsTestServer.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), sslContext));
158         httpsURI = URIBuilder.newBuilder()
159                              .scheme("wss")
160                              .host("localhost")
161                              .port(httpsTestServer.getAddress().getPort())
162                              .path("/")
163                              .build()
164                              .toString() + queryPart;
165 
166         httpsTestServer.createContext("/", new UrlHandler());
167 
168         httpTestServer.start();
169         httpsTestServer.start();
170     }
171 
172     @AfterTest
173     public void teardown() {
174         httpTestServer.stop(0);
175         httpsTestServer.stop(0);
176         executor.shutdownNow();
177     }
< prev index next >