use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class ChunkedEncodingTest method startHttpServer.
/**
* Http Server
*/
static HttpServer startHttpServer() throws IOException {
HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
HttpHandler httpHandler = new SimpleHandler();
httpServer.createContext("/chunked/", httpHandler);
httpServer.start();
return httpServer;
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class SecurityPolicy method httpd.
/**
* Creates and starts an HTTP or proxy server that requires
* Negotiate authentication.
* @param scheme "Negotiate" or "Kerberos"
* @param principal the krb5 service principal the server runs with
* @return the server
*/
public static HttpServer httpd(String scheme, boolean proxy, String principal, String ktab) throws Exception {
MyHttpHandler h = new MyHttpHandler();
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
HttpContext hc = server.createContext("/", h);
hc.setAuthenticator(new MyServerAuthenticator(proxy, scheme, principal, ktab));
server.start();
return server;
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class TestWsImport method main.
public static void main(String[] args) throws IOException {
String javaHome = System.getProperty("java.home");
if (javaHome.endsWith("jre")) {
javaHome = new File(javaHome).getParent();
}
String wsimport = javaHome + File.separator + "bin" + File.separator + "wsimport";
if (System.getProperty("os.name").startsWith("Windows")) {
wsimport = wsimport.concat(".exe");
}
Endpoint endpoint = Endpoint.create(new TestService());
HttpServer httpServer = null;
try {
// Manually create HttpServer here using ephemeral address for port
// so as to not end up with attempt to bind to an in-use port
httpServer = HttpServer.create(new InetSocketAddress(0), 0);
HttpContext httpContext = httpServer.createContext("/hello");
int port = httpServer.getAddress().getPort();
System.out.println("port = " + port);
httpServer.start();
endpoint.publish(httpContext);
String address = "http://localhost:" + port + "/hello";
Service service = Service.create(new URL(address + "?wsdl"), new QName("http://test/jaxws/sample/", "TestService"));
String[] wsargs = { wsimport, "-p", "wstest", "-J-Djavax.xml.accessExternalSchema=all", "-J-Dcom.sun.tools.internal.ws.Invoker.noSystemProxies=true", address + "?wsdl", "-clientjar", "wsjar.jar" };
ProcessBuilder pb = new ProcessBuilder(wsargs);
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s = r.readLine();
while (s != null) {
System.out.println(s.trim());
s = r.readLine();
}
p.waitFor();
p.destroy();
try (JarFile jarFile = new JarFile("wsjar.jar")) {
for (Enumeration em = jarFile.entries(); em.hasMoreElements(); ) {
String fileName = em.nextElement().toString();
if (fileName.contains("\\")) {
throw new RuntimeException("\"\\\" character detected in jar file: " + fileName);
}
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
} finally {
endpoint.stop();
if (httpServer != null) {
httpServer.stop(0);
}
Path p = Paths.get("wsjar.jar");
Files.deleteIfExists(p);
p = Paths.get("wstest");
if (Files.exists(p)) {
try {
Files.walkFileTree(p, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc == null) {
Files.delete(dir);
return CONTINUE;
} else {
throw exc;
}
}
});
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class ClassLoad method main.
public static void main(String[] args) throws Exception {
boolean error = true;
// Start a dummy server to return 404
HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
HttpHandler handler = new HttpHandler() {
public void handle(HttpExchange t) throws IOException {
InputStream is = t.getRequestBody();
while (is.read() != -1) ;
t.sendResponseHeaders(404, -1);
t.close();
}
};
server.createContext("/", handler);
server.start();
// Client request
try {
URL url = new URL("http://localhost:" + server.getAddress().getPort());
String name = args.length >= 2 ? args[1] : "foo.bar.Baz";
ClassLoader loader = new URLClassLoader(new URL[] { url });
System.out.println(url);
Class c = loader.loadClass(name);
System.out.println("Loaded class \"" + c.getName() + "\".");
} catch (ClassNotFoundException ex) {
System.out.println(ex);
error = false;
} finally {
server.stop(0);
}
if (error)
throw new RuntimeException("No ClassNotFoundException generated");
}
use of com.sun.net.httpserver.HttpServer in project ignite by apache.
the class GridEmbeddedHttpServer method createAndStart.
/**
* Internal method which creates and starts the server.
*
* @param httpsMode True if the server to be started is HTTPS, false otherwise.
* @return Started server.
*/
private static GridEmbeddedHttpServer createAndStart(boolean httpsMode) throws Exception {
HttpServer httpSrv;
InetSocketAddress addrToBind = new InetSocketAddress(HOSTNAME_TO_BIND_SRV, getAvailablePort());
if (httpsMode) {
HttpsServer httpsSrv = HttpsServer.create(addrToBind, 0);
httpsSrv.setHttpsConfigurator(new HttpsConfigurator(GridTestUtils.sslContext()));
httpSrv = httpsSrv;
} else
httpSrv = HttpServer.create(addrToBind, 0);
GridEmbeddedHttpServer embeddedHttpSrv = new GridEmbeddedHttpServer();
embeddedHttpSrv.proto = httpsMode ? "https" : "http";
embeddedHttpSrv.httpSrv = httpSrv;
embeddedHttpSrv.httpSrv.start();
return embeddedHttpSrv;
}
Aggregations