< prev index next >

test/jdk/java/net/httpclient/ExpectContinue.java

Print this page

  7  * published by the Free Software Foundation.
  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  * @summary Basic test for Expect 100-Continue ( HTTP/1.1 only )
 27  * @modules java.net.http


 28  *          jdk.httpserver
 29  * @library /test/lib
 30  * @build jdk.test.lib.net.SimpleSSLContext
 31  * @run testng/othervm ExpectContinue
 32  */
 33 
 34 import com.sun.net.httpserver.HttpExchange;
 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 java.io.IOException;
 40 import java.io.InputStream;
 41 import java.io.OutputStream;
 42 import java.net.InetAddress;
 43 import java.net.InetSocketAddress;
 44 import java.net.URI;
 45 import java.net.http.HttpClient;
 46 import java.net.http.HttpRequest;
 47 import java.net.http.HttpRequest.BodyPublishers;
 48 import java.net.http.HttpResponse;
 49 import java.net.http.HttpResponse.BodyHandlers;
 50 import java.util.List;
 51 import javax.net.ssl.SSLContext;


 52 import jdk.test.lib.net.SimpleSSLContext;
 53 import org.testng.annotations.AfterTest;
 54 import org.testng.annotations.BeforeTest;
 55 import org.testng.annotations.DataProvider;
 56 import org.testng.annotations.Test;
 57 import static java.lang.System.out;
 58 import static org.testng.Assert.assertEquals;
 59 
 60 public class ExpectContinue {
 61 
 62     SSLContext sslContext;
 63     HttpServer httpTestServer;         // HTTP/1.1    [ 2 servers ]
 64     HttpsServer httpsTestServer;       // HTTPS/1.1
 65     String httpURI;
 66     String httpsURI;
 67 
 68     @DataProvider(name = "positive")
 69     public Object[][] positive() {
 70         return new Object[][] {
 71                 { httpURI,  false, "Billy" },

131 
132     // -- Infrastructure
133 
134     static String serverAuthority(HttpServer server) {
135         return InetAddress.getLoopbackAddress().getHostName() + ":"
136                 + server.getAddress().getPort();
137     }
138 
139     @BeforeTest
140     public void setup() throws Exception {
141         sslContext = new SimpleSSLContext().get();
142         if (sslContext == null)
143             throw new AssertionError("Unexpected null sslContext");
144 
145         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
146         httpTestServer = HttpServer.create(sa, 0);
147         httpTestServer.createContext("/http1/ec", new Http1ExpectContinueHandler());
148         httpURI = "http://" + serverAuthority(httpTestServer) + "/http1/ec";
149 
150         httpsTestServer = HttpsServer.create(sa, 0);
151         httpsTestServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
152         httpsTestServer.createContext("/https1/ec", new Http1ExpectContinueHandler());
153         httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1/ec";
154 
155         httpTestServer.start();
156         httpsTestServer.start();
157     }
158 
159     @AfterTest
160     public void teardown() throws Exception {
161         httpTestServer.stop(0);
162         httpsTestServer.stop(0);
163     }
164 
165     static class Http1ExpectContinueHandler implements HttpHandler {
166         @Override
167         public void handle(HttpExchange t) throws IOException {
168             try (InputStream is = t.getRequestBody();
169                  OutputStream os = t.getResponseBody()) {
170                 byte[] bytes = is.readAllBytes();
171 

  7  * published by the Free Software Foundation.
  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  * @summary Basic test for Expect 100-Continue ( HTTP/1.1 only )
 27  * @library /test/lib /test/jdk/java/net/httpclient/lib
 28  * @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.common.TestServerConfigurator
 29  * @modules java.net.http/jdk.internal.net.http.common
 30  *          jdk.httpserver


 31  * @run testng/othervm ExpectContinue
 32  */
 33 
 34 import com.sun.net.httpserver.HttpExchange;
 35 import com.sun.net.httpserver.HttpHandler;
 36 import com.sun.net.httpserver.HttpServer;

 37 import com.sun.net.httpserver.HttpsServer;
 38 import java.io.IOException;
 39 import java.io.InputStream;
 40 import java.io.OutputStream;
 41 import java.net.InetAddress;
 42 import java.net.InetSocketAddress;
 43 import java.net.URI;
 44 import java.net.http.HttpClient;
 45 import java.net.http.HttpRequest;
 46 import java.net.http.HttpRequest.BodyPublishers;
 47 import java.net.http.HttpResponse;
 48 import java.net.http.HttpResponse.BodyHandlers;
 49 import java.util.List;
 50 import javax.net.ssl.SSLContext;
 51 
 52 import jdk.httpclient.test.lib.common.TestServerConfigurator;
 53 import jdk.test.lib.net.SimpleSSLContext;
 54 import org.testng.annotations.AfterTest;
 55 import org.testng.annotations.BeforeTest;
 56 import org.testng.annotations.DataProvider;
 57 import org.testng.annotations.Test;
 58 import static java.lang.System.out;
 59 import static org.testng.Assert.assertEquals;
 60 
 61 public class ExpectContinue {
 62 
 63     SSLContext sslContext;
 64     HttpServer httpTestServer;         // HTTP/1.1    [ 2 servers ]
 65     HttpsServer httpsTestServer;       // HTTPS/1.1
 66     String httpURI;
 67     String httpsURI;
 68 
 69     @DataProvider(name = "positive")
 70     public Object[][] positive() {
 71         return new Object[][] {
 72                 { httpURI,  false, "Billy" },

132 
133     // -- Infrastructure
134 
135     static String serverAuthority(HttpServer server) {
136         return InetAddress.getLoopbackAddress().getHostName() + ":"
137                 + server.getAddress().getPort();
138     }
139 
140     @BeforeTest
141     public void setup() throws Exception {
142         sslContext = new SimpleSSLContext().get();
143         if (sslContext == null)
144             throw new AssertionError("Unexpected null sslContext");
145 
146         InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
147         httpTestServer = HttpServer.create(sa, 0);
148         httpTestServer.createContext("/http1/ec", new Http1ExpectContinueHandler());
149         httpURI = "http://" + serverAuthority(httpTestServer) + "/http1/ec";
150 
151         httpsTestServer = HttpsServer.create(sa, 0);
152         httpsTestServer.setHttpsConfigurator(new TestServerConfigurator(sa.getAddress(), sslContext));
153         httpsTestServer.createContext("/https1/ec", new Http1ExpectContinueHandler());
154         httpsURI = "https://" + serverAuthority(httpsTestServer) + "/https1/ec";
155 
156         httpTestServer.start();
157         httpsTestServer.start();
158     }
159 
160     @AfterTest
161     public void teardown() throws Exception {
162         httpTestServer.stop(0);
163         httpsTestServer.stop(0);
164     }
165 
166     static class Http1ExpectContinueHandler implements HttpHandler {
167         @Override
168         public void handle(HttpExchange t) throws IOException {
169             try (InputStream is = t.getRequestBody();
170                  OutputStream os = t.getResponseBody()) {
171                 byte[] bytes = is.readAllBytes();
172 
< prev index next >