当前位置: 首页>>代码示例>>Java>>正文


Java AsyncHttpServerResponse类代码示例

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


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

示例1: WebSocketImpl

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的package包/类
public WebSocketImpl(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
        this(request.getSocket());
        
        String key = request.getHeaders().get("Sec-WebSocket-Key");
        String concat = key + MAGIC;
        String sha1 = SHA1(concat);
        String origin = request.getHeaders().get("Origin");
        
        response.code(101);
        response.getHeaders().set("Upgrade", "WebSocket");
        response.getHeaders().set("Connection", "Upgrade");
        response.getHeaders().set("Sec-WebSocket-Accept", sha1);
        String protocol = request.getHeaders().get("Sec-WebSocket-Protocol");
        // match the protocol (sanity checking and enforcement is done in the caller)
        if (!TextUtils.isEmpty(protocol))
            response.getHeaders().set("Sec-WebSocket-Protocol", protocol);
//        if (origin != null)
//            response.getHeaders().getHeaders().set("Access-Control-Allow-Origin", "http://" + origin);
        response.writeHead();
        
        setupParser(false, false);
    }
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:23,代码来源:WebSocketImpl.java

示例2: testMaxAgePrivate

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的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

示例3: onRequest

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的package包/类
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
    if (true) {
        Log.i(Main.TAG, "screenshot authentication success");
        try {
            Bitmap bitmap = EncoderFeeder.screenshot(this.val$wm);
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bout);
            bout.flush();
            response.send("image/jpeg", bout.toByteArray());
            return;
        } catch (Exception e) {
            response.code(500);
            response.send(e.toString());
            return;
        }
    }
    Log.i(Main.TAG, "screenshot authentication failed");
    response.code(401);
    response.send("Not Authorized.");
}
 
开发者ID:lifengsofts,项目名称:AndroidRemoteScreen,代码行数:21,代码来源:AnonymousClass5.java

示例4: startServer

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的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

示例5: onRequest

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的package包/类
@Override public void onRequest(final AsyncHttpServerRequest req, final AsyncHttpServerResponse res) {
    if (!shouldPass(req, res)) {
        return;
    }
    Timber.v("[+] Received connection from: %s", req.getHeaders().get("User-Agent"));
    final String path = remapPath(req.getPath());
    res.getHeaders().set("Content-Type", ContentTypes.getInstance().getContentType(path));

    final InputStream is = HtmlHelper.loadPath(path);
    if (is != null) {
        try {
            res.sendStream(is, is.available());
            return;
        } catch (IOException ioe) {
            Timber.e(ioe, "Error!");
        } finally {
            HwIoUtils.closeQuietly(is);
        }
    }
    res.send(HtmlHelper.loadPathAsString(path));
}
 
开发者ID:amartinz,项目名称:DeviceControl,代码行数:22,代码来源:ServerWrapper.java

示例6: onRequest

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的package包/类
@Override
public void onRequest(AsyncHttpServerRequest request,
		AsyncHttpServerResponse response) {

	try {
		int index = Integer
				.parseInt(request.getPath().replace("/", ""));
		String filePath = mFiles.get(index);
		// Only serve the file set during in sendMediaRequest().
		File f = new File(filePath);

		String mimeType = getMimeType(filePath);
		response.setContentType(mimeType);

		response.sendFile(f);
	} catch (Exception ex) {
		response.send(ex.getMessage());
	}

}
 
开发者ID:dougnlamb,项目名称:FireCast,代码行数:21,代码来源:FireCastService.java

示例7: WebSocketImpl

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的package包/类
public WebSocketImpl(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
        this(request.getSocket());
        
        String key = request.getHeaders().getHeaders().get("Sec-WebSocket-Key");
        String concat = key + MAGIC;
        String sha1 = SHA1(concat);
        String origin = request.getHeaders().getHeaders().get("Origin");
        
        response.responseCode(101);
        response.getHeaders().getHeaders().set("Upgrade", "WebSocket");
        response.getHeaders().getHeaders().set("Connection", "Upgrade");
        response.getHeaders().getHeaders().set("Sec-WebSocket-Accept", sha1);
        String protocol = request.getHeaders().getHeaders().get("Sec-WebSocket-Protocol");
        // match the protocol (sanity checking and enforcement is done in the caller)
        if (!TextUtils.isEmpty(protocol))
            response.getHeaders().getHeaders().set("Sec-WebSocket-Protocol", protocol);
//        if (origin != null)
//            response.getHeaders().getHeaders().set("Access-Control-Allow-Origin", "http://" + origin);
        response.writeHead();
        
        setupParser(false, false);
    }
 
开发者ID:xiaoshutong,项目名称:AndroidNio,代码行数:23,代码来源:WebSocketImpl.java

示例8: testProxy

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的package包/类
public void testProxy() throws Exception {
        wasProxied = false;
        final AsyncServer proxyServer = new AsyncServer();
        try {
            AsyncProxyServer httpServer = new AsyncProxyServer(proxyServer) {
                @Override
                protected boolean onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
                    wasProxied = true;
                    return super.onRequest(request, response);
                }
            };

            AsyncServerSocket socket = httpServer.listen(proxyServer, 0);

//            client.getSocketMiddleware().enableProxy("localhost", 5555);

            AsyncHttpGet get = new AsyncHttpGet("http://www.clockworkmod.com");
            get.enableProxy("localhost", socket.getLocalPort());

            Future<String> ret = client.executeString(get, null);
            String data;
            assertNotNull(data = ret.get(TIMEOUT, TimeUnit.MILLISECONDS));
            assertTrue(data.contains("ClockworkMod"));
            assertTrue(wasProxied);
        }
        finally {
            proxyServer.stop();
        }
    }
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:30,代码来源:HttpClientTests.java

示例9: testKeys

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的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

示例10: BeamServer

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的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

示例11: onRequest

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的package包/类
public void onRequest(AsyncHttpServerRequest asyncHttpServerRequest, AsyncHttpServerResponse httpServerResponse) {
    if (sCurrentVideo != null && sCurrentVideo.exists()) {
        mFileType.setHeaders(httpServerResponse);
        httpServerResponse.sendFile(sCurrentVideo);
    } else {
        httpServerResponse.send("Not found");
        httpServerResponse.code(404);
    }

    Timber.i(httpServerResponse.toString());
}
 
开发者ID:PTCE,项目名称:popcorn-android,代码行数:12,代码来源:BeamServer.java

示例12: shouldPass

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的package包/类
private boolean shouldPass(final AsyncHttpServerRequest req, final AsyncHttpServerResponse res) {
    if (isStopped) {
        res.code(404);
        res.end();
        return false;
    }
    if (!isAuthenticated(req)) {
        res.getHeaders().add("WWW-Authenticate", "Basic realm=\"DeviceControl\"");
        res.code(401);
        res.end();
        return false;
    }
    return true;
}
 
开发者ID:amartinz,项目名称:DeviceControl,代码行数:15,代码来源:ServerWrapper.java

示例13: setHeaders

import com.koushikdutta.async.http.server.AsyncHttpServerResponse; //导入依赖的package包/类
public void setHeaders(AsyncHttpServerResponse httpServerResponse) {
    setHeaders(httpServerResponse.getHeaders());
}
 
开发者ID:PTCE,项目名称:popcorn-android,代码行数:4,代码来源:BeamServer.java


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