Created
March 11, 2017 03:01
-
-
Save DALDEI/cb0f798898ff91fa0dade48a00ad627c to your computer and use it in GitHub Desktop.
Minimal Java Web server with no dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run with
javac Server.java
java -cp . Server
Thats ALL