use of com.sun.net.httpserver.HttpContext in project spring-framework by spring-projects.
the class SimpleHttpServerJaxWsServiceExporter method buildHttpContext.
/**
* Build the HttpContext for the given endpoint.
* @param endpoint the JAX-WS Provider Endpoint object
* @param serviceName the given service name
* @return the fully populated HttpContext
*/
protected HttpContext buildHttpContext(Endpoint endpoint, String serviceName) {
String fullPath = calculateEndpointPath(endpoint, serviceName);
HttpContext httpContext = this.server.createContext(fullPath);
if (this.filters != null) {
httpContext.getFilters().addAll(this.filters);
}
if (this.authenticator != null) {
httpContext.setAuthenticator(this.authenticator);
}
return httpContext;
}
use of com.sun.net.httpserver.HttpContext in project jdk8u_jdk by JetBrains.
the class HeadTest method server.
static void server() throws Exception {
InetSocketAddress inetAddress = new InetSocketAddress(0);
HttpServer server = HttpServer.create(inetAddress, 5);
try {
server.setExecutor(Executors.newFixedThreadPool(5));
HttpContext chunkedContext = server.createContext("/chunked");
chunkedContext.setHandler(new HttpHandler() {
@Override
public void handle(HttpExchange msg) {
try {
try {
if (msg.getRequestMethod().equals("HEAD")) {
msg.getRequestBody().close();
msg.getResponseHeaders().add("Transfer-encoding", "chunked");
msg.sendResponseHeaders(200, -1);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
} finally {
msg.close();
}
}
});
HttpContext clContext = server.createContext("/content");
clContext.setHandler(new HttpHandler() {
@Override
public void handle(HttpExchange msg) {
try {
try {
if (msg.getRequestMethod().equals("HEAD")) {
msg.getRequestBody().close();
msg.getResponseHeaders().add("Content-length", "1024");
msg.sendResponseHeaders(200, -1);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
} finally {
msg.close();
}
}
});
server.start();
String urlStr = "http://localhost:" + server.getAddress().getPort() + "/";
System.out.println("Server is at " + urlStr);
// Run the chunked client
for (int i = 0; i < 10; i++) {
runClient(urlStr + "chunked/");
}
// Run the content length client
for (int i = 0; i < 10; i++) {
runClient(urlStr + "content/");
}
} finally {
// Stop the server
((ExecutorService) server.getExecutor()).shutdown();
server.stop(0);
}
}
use of com.sun.net.httpserver.HttpContext in project jdk8u_jdk by JetBrains.
the class Deadlock method main.
public static void main(String[] args) throws Exception {
Handler handler = new Handler();
InetSocketAddress addr = new InetSocketAddress(0);
HttpServer server = HttpServer.create(addr, 0);
HttpContext ctx = server.createContext("/test", handler);
BasicAuthenticator a = new BasicAuthenticator("foobar@test.realm") {
@Override
public boolean checkCredentials(String username, String pw) {
return "fred".equals(username) && pw.charAt(0) == 'x';
}
};
ctx.setAuthenticator(a);
ExecutorService executor = Executors.newCachedThreadPool();
server.setExecutor(executor);
server.start();
java.net.Authenticator.setDefault(new MyAuthenticator());
System.out.print("Deadlock: ");
for (int i = 0; i < 2; i++) {
Runner t = new Runner(server, i);
t.start();
t.join();
}
server.stop(2);
executor.shutdown();
if (error) {
throw new RuntimeException("test failed error");
}
if (count != 2) {
throw new RuntimeException("test failed count = " + count);
}
System.out.println("OK");
}
Aggregations