Skip to content

Instantly share code, notes, and snippets.

@DALDEI
Created March 11, 2017 03:01
Show Gist options
  • Save DALDEI/cb0f798898ff91fa0dade48a00ad627c to your computer and use it in GitHub Desktop.
Save DALDEI/cb0f798898ff91fa0dade48a00ad627c to your computer and use it in GitHub Desktop.
Minimal Java Web server with no dependencies
// from: http://stackoverflow.com/questions/3732109/simple-http-server-in-java-using-only-java-se-api
import java.io.*;
import javax.xml.ws.*;
import javax.xml.ws.http.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
@WebServiceProvider
@ServiceMode(value = Service.Mode.PAYLOAD)
public class Server implements Provider<Source> {
public Source invoke(Source request) {
return new StreamSource(new StringReader("<p>Hello There!</p>"));
}
public static void main(String[] args) throws InterruptedException {
String address = "http://127.0.0.1:8080/";
Endpoint.create(HTTPBinding.HTTP_BINDING, new Server()).publish(address);
System.out.println("Service running at " + address);
System.out.println("Type [CTRL]+[C] to quit!");
Thread.sleep(Long.MAX_VALUE);
}
}
@DALDEI
Copy link
Author

DALDEI commented Mar 11, 2017

run with
javac Server.java
java -cp . Server

Thats ALL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment