org.jboss.netty.handler.codec.http.DefaultHttpRequest Java Examples
The following examples show how to use
org.jboss.netty.handler.codec.http.DefaultHttpRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HlsTrafficFilter.java From feeyo-hlsserver with Apache License 2.0 | 5 votes |
@Override public boolean doFilter(ChannelHandlerContext ctx, MessageEvent e) { boolean isPassed = false; HttpRequest request = (DefaultHttpRequest) e.getMessage(); String[] path = request.getUri().split("/"); String requestFile = path[3]; if (requestFile.endsWith(".ts")) { isPassed = true; } else { isPassed = true; } return isPassed; }
Example #2
Source File: WrapFileClientHandler.java From netty-file-parent with Apache License 2.0 | 5 votes |
public WrapFileClientHandler(String host, URI uri, String userName, String pwd) { this.host = host; this.uri = uri; this.userName = userName; this.pwd = pwd; this.request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri.toASCIIString()); setHeaderDatas(); }
Example #3
Source File: HttpAction.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
protected HttpRequest newRequest(HttpMethod method, URL url, String path, ChannelBuffer buffer) { HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, method, path); request.headers().add(HttpHeaders.Names.HOST, url.getHost()); request.headers().add(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE); request.headers().add(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP); if (buffer != null) { request.setContent(buffer); int length = request.getContent().readableBytes(); request.headers().add(HttpHeaders.Names.CONTENT_TYPE, "application/json"); request.headers().add(HttpHeaders.Names.CONTENT_LENGTH, length); } return request; }
Example #4
Source File: HlsVodHandler.java From feeyo-hlsserver with Apache License 2.0 | 4 votes |
@Override public void execute(ChannelHandlerContext ctx, MessageEvent e) throws Exception { HttpRequest request = (DefaultHttpRequest) e.getMessage(); if ( !request.getUri().matches(regex) ) { LOGGER.warn("bad request: " + request.getUri()); HttpUtil.sendError(ctx, HttpResponseStatus.NOT_FOUND); return; } String[] path = request.getUri().split("/"); String alias = path[3]; final String reqFileName = path[4]; Long streamId = HlsLiveStreamMagr.INSTANCE().getStreamIdByAlias(alias); if( streamId == null ) { LOGGER.warn(" aac vod, lookup alias failed: " + alias); HttpUtil.sendError(ctx, HttpResponseStatus.NOT_FOUND); return; } OssUtil ossOperation = new OssUtil(); byte[] content = null; if (reqFileName.endsWith(".m3u8")) { if ( !ossOperation.doesObjectExist(reqFileName, streamId) ) { boolean needWaite = false; // the very first listener of a specific m3u8 will create the m3u8 file and the ts file // the reset will be in a waiter set synchronized (m3u8WaiteSet) { if (!m3u8WaiteSet.add(reqFileName)) { needWaite = true; } } if (needWaite) { synchronized (m3u8WaiteSet) { while (m3u8WaiteSet.contains(reqFileName)) { m3u8WaiteSet.wait(1000); } } } else { content = generateTsFiles(reqFileName, streamId); } } } if (content == null) { content = cachedVodTsFiles.get(reqFileName); if (content == null) { if (ossOperation.doesObjectExist(reqFileName, streamId)){ InputStream inputStream = ossOperation.readObject(reqFileName, streamId); ObjectMetadata objectMetadata = ossOperation.getObjectMetadata(reqFileName,streamId); int len = (int)objectMetadata.getContentLength(); content = new byte[len]; int writePtr = 0; for (;;) { int ret = inputStream.read(content, writePtr,len-writePtr); if ((ret == -1) || (writePtr += ret) >= len) break; } } else { LOGGER.warn("request file not on OSS: " + request.getUri()); HttpUtil.sendError(ctx, HttpResponseStatus.NOT_FOUND); return; } } } ossOperation.closeOSSClient(); long timeMillis = System.currentTimeMillis(); DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); response.headers().set(HttpHeaders.Names.DATE, HttpUtil.getDateString(timeMillis)); response.headers().set(HttpHeaders.Names.CONTENT_TYPE, HttpUtil.getMimeType(reqFileName)); response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, content.length); response.headers().set(HttpHeaders.Names.LAST_MODIFIED, HttpUtil.getDateString(timeMillis)); response.headers().set(HttpHeaders.Names.EXPIRES, HttpUtil.getDateString(timeMillis + VOD_CACHE_TIME)); response.headers().set(HttpHeaders.Names.CACHE_CONTROL, "max-age=" + (VOD_CACHE_TIME/1000)); response.setContent(ChannelBuffers.copiedBuffer(content)); e.getChannel().write(response); }
Example #5
Source File: AuthCheckFilter.java From feeyo-hlsserver with Apache License 2.0 | 4 votes |
@Override public boolean doFilter(ChannelHandlerContext ctx, MessageEvent messageEvent) { boolean isPass = true; HttpRequest request = (DefaultHttpRequest) messageEvent.getMessage(); String access_string = request.headers().get(Token.ACCESS_STRING); if ( access_string == null ) { // 解析 Cookie String value = request.headers().get( HttpHeaders.Names.COOKIE ); Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode(value != null ? value : ""); Iterator<Cookie> it = cookies.iterator(); while( it.hasNext() ) { Cookie c = it.next(); if ( Token.ACCESS_STRING.equals( c.name() ) ) { access_string = c.value(); break; } } } if (access_string != null) { try { Token token = TokenMagr.getInstance().getToken(access_string); if (token != null) { int now = (int) (System.currentTimeMillis() / 1000L); int expires = token.getCreateAt() + (token.getExpiresIn() * 60 * 60 * 24); if (expires < now) { TokenMagr.getInstance().deleteToken(access_string); isPass = false; } } else { isPass = false; } } catch (Exception e) { LOGGER.error("filter error -- > " + request.getUri(), e); } } else { isPass = false; } return isPass; }