• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java HttpServerRequestCallback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.koushikdutta.async.http.server.HttpServerRequestCallback的典型用法代码示例。如果您正苦于以下问题:Java HttpServerRequestCallback类的具体用法?Java HttpServerRequestCallback怎么用?Java HttpServerRequestCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HttpServerRequestCallback类属于com.koushikdutta.async.http.server包,在下文中一共展示了HttpServerRequestCallback类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testMaxAgePrivate

import com.koushikdutta.async.http.server.HttpServerRequestCallback; //导入依赖的package包/类
public void testMaxAgePrivate() throws Exception {
    AsyncHttpClient client = new AsyncHttpClient(AsyncServer.getDefault());
    ResponseCacheMiddleware cache = ResponseCacheMiddleware.addCache(client, new File(getContext().getFilesDir(), "AndroidAsyncTest"), 1024 * 1024 * 10);
    AsyncHttpServer httpServer = new AsyncHttpServer();
    try {
        httpServer.get("/uname/(.*)", new HttpServerRequestCallback() {
            @Override
            public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
                response.getHeaders().set("Date", HttpDate.format(new Date()));
                response.getHeaders().set("Cache-Control", "private, max-age=10000");
                response.send(request.getMatcher().group(1));
            }
        });

        AsyncServerSocket socket = httpServer.listen(AsyncServer.getDefault(), 0);
        int port = socket.getLocalPort();
        // clear the old cache
        cache.clear();

        client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();

        client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();


        assertEquals(cache.getCacheHitCount(), 1);
        assertEquals(cache.getNetworkCount(), 1);
    }
    finally {
        AsyncServer.getDefault().stop();
        client.getMiddleware().remove(cache);
    }
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:33,代码来源:CacheTests.java


示例2: startServer

import com.koushikdutta.async.http.server.HttpServerRequestCallback; //导入依赖的package包/类
private void startServer() {
    server.get("/", new HttpServerRequestCallback() {
        @Override
        public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
            response.send("Hello!!!");
        }
    });

    server.post("/testJson", new HttpServerRequestCallback() {
        @Override
        public void onRequest(AsyncHttpServerRequest asyncHttpServerRequest, AsyncHttpServerResponse asyncHttpServerResponse) {
            AsyncHttpRequestBody requestBody = asyncHttpServerRequest.getBody();
            try {
                asyncHttpServerResponse.code(200);
                asyncHttpServerResponse.send(new JSONObject(requestBody.toString()).getJSONObject("menu").getString("value"));
            } catch (JSONException e) {
                Log.e("MainActivity", e.getMessage(), e);
            }
        }
    });
    server.listen(mAsyncServer, 8080);
}
 
开发者ID:andreivisan,项目名称:AndroidAsyncHttpServer,代码行数:23,代码来源:MainActivity.java


示例3: testKeys

import com.koushikdutta.async.http.server.HttpServerRequestCallback; //导入依赖的package包/类
public void testKeys() throws Exception {
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

    ks.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
    kmf.init(ks, "storepass".toCharArray());


    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    KeyStore ts = KeyStore.getInstance(KeyStore.getDefaultType());
    ts.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
    tmf.init(ts);

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

    AsyncHttpServer httpServer = new AsyncHttpServer();
    httpServer.listenSecure(8888, sslContext);
    httpServer.get("/", new HttpServerRequestCallback() {
        @Override
        public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
            response.send("hello");
        }
    });

    Thread.sleep(1000);

    AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setSSLContext(sslContext);
    AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setTrustManagers(tmf.getTrustManagers());
    AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet("https://localhost:8888/"), null).get();
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:32,代码来源:SSLTests.java


示例4: BeamServer

import com.koushikdutta.async.http.server.HttpServerRequestCallback; //导入依赖的package包/类
public BeamServer(String host, int port) {
    mHttpServer = new AsyncHttpServer() {
        protected boolean onRequest(AsyncHttpServerRequest httpServerRequest, AsyncHttpServerResponse httpServerResponse) {
            Timber.d(httpServerRequest.toString());
            httpServerResponse.getHeaders().set("Access-Control-Allow-Origin", "*");
            return super.onRequest(httpServerRequest, httpServerResponse);
        }
    };

    sHost = host;
    sPort = port;

    for (FileType localFileType : FILE_TYPES) {
        VideoFileReponse localVideoFileReponse = new VideoFileReponse(localFileType);
        mHttpServer.get("/video." + localFileType.extension, localVideoFileReponse);
        mHttpServer.addAction("HEAD", "/video." + localFileType.extension, localVideoFileReponse);
    }

    for(FileType localSubsFileType : SUB_TYPES) {
        SubtitleFileResponse localSubsFileReponse = new SubtitleFileResponse(localSubsFileType);
        mHttpServer.get("/video." + localSubsFileType.extension, localSubsFileReponse);
        mHttpServer.addAction("HEAD", "/video." + localSubsFileType.extension, localSubsFileReponse);
    }

    mHttpServer.get("/(.*?)", new HttpServerRequestCallback() {
        @Override
        public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
            response.send("Not found");
            response.code(404);
        }
    });
}
 
开发者ID:PTCE,项目名称:popcorn-android,代码行数:33,代码来源:BeamServer.java



注:本文中的com.koushikdutta.async.http.server.HttpServerRequestCallback类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RMWebApp类代码示例发布时间:2022-05-22
下一篇:
Java ApplicationBundle类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap