use of com.koushikdutta.async.http.server.AsyncHttpServer in project cw-omnibus by commonsguy.
the class WebServerService method onCreate.
@Override
public void onCreate() {
super.onCreate();
server = new AsyncHttpServer();
server.websocket("/ss", new WebSocketClientCallback());
server.get("/.*", new AssetRequestCallback());
server.listen(4999);
raiseStartedEvent();
foregroundify();
timer.scheduleAtFixedRate(this, 3000, 3000, TimeUnit.MILLISECONDS);
}
use of com.koushikdutta.async.http.server.AsyncHttpServer in project cw-omnibus by commonsguy.
the class WebServerService method onCreate.
@Override
public void onCreate() {
super.onCreate();
ConnectivityManager mgr = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo ni = mgr.getActiveNetworkInfo();
if (ni == null || ni.getType() == ConnectivityManager.TYPE_MOBILE) {
EventBus.getDefault().post(new ServerStartRejectedEvent());
stopSelf();
} else {
handlebars = new Handlebars(new AssetTemplateLoader(getAssets()));
rootPath = "/" + new BigInteger(20, rng).toString(24).toUpperCase();
server = new AsyncHttpServer();
if (configureRoutes(server)) {
server.get("/.*", new AssetRequestCallback());
}
server.listen(getPort());
raiseReadyEvent();
foregroundify();
timeoutFuture = timer.schedule(onTimeout, getMaxIdleTimeSeconds(), TimeUnit.SECONDS);
}
}
use of com.koushikdutta.async.http.server.AsyncHttpServer in project ion by koush.
the class Issues method testIssue146.
public void testIssue146() throws Exception {
AsyncHttpServer httpServer = new AsyncHttpServer();
httpServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.getHeaders().set("Cache-Control", "max-age=300");
response.send(request.getQuery().size() + "");
}
});
AsyncServer asyncServer = new AsyncServer();
try {
int localPort = httpServer.listen(asyncServer, 0).getLocalPort();
String s1 = Ion.with(getContext()).load("http://localhost:" + localPort).addQuery("query1", "q").asString().get();
String s2 = Ion.with(getContext()).load("http://localhost:" + localPort).addQuery("query1", "q").addQuery("query2", "qq").asString().get();
String s3 = Ion.with(getContext()).load("http://localhost:" + localPort).addQuery("query1", "q").asString().get();
assertEquals(s1, "1");
assertEquals(s2, "2");
assertEquals(s3, "1");
} finally {
asyncServer.stop();
}
}
use of com.koushikdutta.async.http.server.AsyncHttpServer in project ion by koush.
the class Issues method testIssue329.
public void testIssue329() throws Exception {
AsyncHttpServer httpServer = new AsyncHttpServer();
httpServer.post("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
UrlEncodedFormBody body = (UrlEncodedFormBody) request.getBody();
response.send(body.get().getString("電"));
}
});
AsyncServer asyncServer = new AsyncServer();
try {
int localPort = httpServer.listen(asyncServer, 0).getLocalPort();
String s1 = Ion.with(getContext()).load("http://localhost:" + localPort).setBodyParameter("電", "電").asString().get();
assertEquals(s1, "電");
} finally {
asyncServer.stop();
}
}
use of com.koushikdutta.async.http.server.AsyncHttpServer in project ion by koush.
the class RedirectTests method testFinalLocation.
public void testFinalLocation() throws Exception {
try {
AsyncHttpServer server = new AsyncHttpServer();
server.listen(Ion.getDefault(getContext()).getServer(), 5555);
server.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.redirect("/foo");
}
});
server.get("/foo", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.send("bar");
}
});
Response<String> response = Ion.with(getContext()).load("http://localhost:5555").asString().withResponse().get();
assertEquals(response.getResult(), "bar");
assertEquals(response.getRequest().getUri().toString(), "http://localhost:5555/foo");
} finally {
Ion.getDefault(getContext()).getServer().stop();
}
}
Aggregations