Created
February 23, 2016 20:33
-
-
Save leonmaia/19cdc5f894348f0a9c38 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package com.leon.dogs; | |
| import com.twitter.finagle.ListeningServer; | |
| import com.twitter.finagle.Service; | |
| import com.twitter.finagle.http.HttpMuxer; | |
| import com.twitter.finagle.http.Request; | |
| import com.twitter.finagle.http.Response; | |
| import com.twitter.util.Await; | |
| import com.twitter.util.Future; | |
| import org.jboss.netty.buffer.ChannelBuffers; | |
| import java.net.InetAddress; | |
| import java.net.InetSocketAddress; | |
| public class SimpleHttpServer { | |
| public static void main(String[] args) throws Exception { | |
| runServer(); | |
| } | |
| private static HttpMuxer router() { | |
| return new HttpMuxer() | |
| .withHandler("/echo", echoService()); | |
| } | |
| private static Service<Request, Response> echoService() { | |
| return new Service<Request, Response>() { | |
| public Future<Response> apply(Request request) { | |
| Response response = Response.apply(); | |
| response.setContent(ChannelBuffers.wrappedBuffer("WORKING".getBytes())); | |
| return Future.value(response); | |
| } | |
| }; | |
| } | |
| private static void runServer() throws InterruptedException, com.twitter.util.TimeoutException { | |
| ListeningServer server = com.twitter.finagle.Http.server() | |
| .serve(new InetSocketAddress(InetAddress.getLoopbackAddress(), 8888), router()); | |
| Await.ready(server); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment