Created
September 15, 2015 14:03
-
-
Save vkosh/f714c6acb46ba23c47c9 to your computer and use it in GitHub Desktop.
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
AsyncServer asyncServer = new AsyncServer(); | |
AsyncHttpServer httpServer = new AsyncHttpServer(); | |
AsyncHttpClient httpClient = new AsyncHttpClient(asyncServer); | |
ExecutorService executorService = Executors.newCachedThreadPool(); | |
httpServer.get(".*", new HttpServerRequestCallback() { | |
@Override | |
public void onRequest(final AsyncHttpServerRequest request, final AsyncHttpServerResponse response) { | |
executorService.execute(new Runnable() { | |
@Override | |
public void run() { | |
final AsyncHttpGet proxyRequest = new AsyncHttpGet("http://remotehost/" + request.getPath()); | |
httpClient.executeByteBufferList(proxyRequest, new AsyncHttpClient.DownloadCallback() { | |
@Override | |
public void onCompleted(Exception e, final AsyncHttpResponse proxyResponse, ByteBufferList result) { | |
if (e != null) { | |
// handle error | |
return; | |
} | |
// fill response headers | |
... | |
// response | |
int size = result.remaining(); | |
ByteArrayInputStream is = new ByteArrayInputStream(result.getAllByteArray()); | |
response.sendStream(is, result); | |
} | |
}); | |
} | |
}); | |
} | |
httpServer.listen(asyncServer, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment