forked from johnament/getting-started-microprofile
-
Notifications
You must be signed in to change notification settings - Fork 3
/
runMockAuthorService.groovy
36 lines (30 loc) · 1.05 KB
/
runMockAuthorService.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
class AuthorServlet extends AbstractHandler
{
public void handle(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
response.getWriter().println("\"This is a mock author\"");
}
}
def startJetty() {
int port = Integer.parseInt(properties.getProperty("port", "8080"))
def server = new Server(port)
server.handler = new AuthorServlet()
server.start()
server.join()
}
println "Starting Jetty, press Ctrl+C to stop."
startJetty()