< prev index next >
test/java/net/HttpURLConnection/UnmodifiableMaps.java
Print this page
*** 22,36 ****
*/
/**
* @test
* @bug 7128648
* @summary HttpURLConnection.getHeaderFields should return an unmodifiable Map
*/
import java.io.IOException;
- import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.HttpURLConnection;
import java.util.Collection;
import java.util.ArrayList;
--- 22,36 ----
*/
/**
* @test
* @bug 7128648
+ * @modules jdk.httpserver
* @summary HttpURLConnection.getHeaderFields should return an unmodifiable Map
*/
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.HttpURLConnection;
import java.util.Collection;
import java.util.ArrayList;
*** 38,64 ****
import java.util.Map;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.Headers;
public class UnmodifiableMaps {
void test(String[] args) throws Exception {
HttpServer server = startHttpServer();
try {
InetSocketAddress address = server.getAddress();
! URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress()
! + ":" + address.getPort() + "/foo");
doClient(uri);
} finally {
server.stop(0);
}
}
void doClient(URI uri) throws Exception {
! HttpURLConnection uc = (HttpURLConnection) uri.toURL().openConnection();
// Test1: getRequestProperties is unmodifiable
System.out.println("Check getRequestProperties");
checkUnmodifiable(uc.getRequestProperties());
uc.addRequestProperty("X", "V");
--- 38,64 ----
import java.util.Map;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.Headers;
+ import static java.net.Proxy.NO_PROXY;
public class UnmodifiableMaps {
void test(String[] args) throws Exception {
HttpServer server = startHttpServer();
try {
InetSocketAddress address = server.getAddress();
! URI uri = new URI("http://localhost:" + address.getPort() + "/foo");
doClient(uri);
} finally {
server.stop(0);
}
}
void doClient(URI uri) throws Exception {
! HttpURLConnection uc = (HttpURLConnection) uri.toURL().openConnection(NO_PROXY);
// Test1: getRequestProperties is unmodifiable
System.out.println("Check getRequestProperties");
checkUnmodifiable(uc.getRequestProperties());
uc.addRequestProperty("X", "V");
< prev index next >