Saturday, 15 September 2012

java - Can I run a JAX-RS web service on com.sun.net.httpserver.HttpServer? -



java - Can I run a JAX-RS web service on com.sun.net.httpserver.HttpServer? -

can run simple webservice this:

@path("/rs/hello") public class helloworldprogram { //path default @get @produces(mediatype.text_html) public string sayhello() { homecoming "hello, world!"; } @get @produces(mediatype.text_xml) @path("/xml") public string sayxmlhello() { homecoming "<?xml version=\"1.0\"?>" + "<hello> hello" + "</hello>"; } }

on bundled jdk simple web server com.sun.net.httpserver.httpserver ?

no, can't utilize com.sun.net.httpserver.httpserver. need server compliant servlet api. instead can utilize illustration org.glassfish.grizzly.http.server.httpserver:

import java.net.uri; import javax.ws.rs.core.uribuilder; import org.glassfish.grizzly.http.server.httpserver; import org.glassfish.jersey.grizzly2.httpserver.grizzlyhttpserverfactory; import org.glassfish.jersey.server.resourceconfig; public class server { public static void main(string[] args) throws interruptedexception { uri uri = uribuilder.fromuri("http://localhost/").port(8888).build(); resourceconfig rc = new resourceconfig(helloworldprogram.class); httpserver server = grizzlyhttpserverfactory.createhttpserver(uri, rc); thread.currentthread().join(); // maintain running } }

you need dependency jersey container grizzly2 servlet.

java jax-rs

No comments:

Post a Comment