當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpRequest.getContent方法代碼示例

本文整理匯總了Java中org.jboss.netty.handler.codec.http.HttpRequest.getContent方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequest.getContent方法的具體用法?Java HttpRequest.getContent怎麽用?Java HttpRequest.getContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jboss.netty.handler.codec.http.HttpRequest的用法示例。


在下文中一共展示了HttpRequest.getContent方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toCamelMessage

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
public Message toCamelMessage(HttpRequest request, Exchange exchange, NettyHttpConfiguration configuration) throws Exception {
    LOG.trace("toCamelMessage: {}", request);

    NettyHttpMessage answer = new NettyHttpMessage(request, null);
    answer.setExchange(exchange);
    if (configuration.isMapHeaders()) {
        populateCamelHeaders(request, answer.getHeaders(), exchange, configuration);
    }

    if (configuration.isDisableStreamCache()) {
        // keep the body as is, and use type converters
        answer.setBody(request.getContent());
    } else {
        // turn the body into stream cached
        NettyChannelBufferStreamCache cache = new NettyChannelBufferStreamCache(request.getContent());
        answer.setBody(cache);
    }
    return answer;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:21,代碼來源:DefaultNettyHttpBinding.java

示例2: decode

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
        throws Exception
{
  HttpRequest nettyRequest = (HttpRequest) msg;
  URI uri = new URI(nettyRequest.getUri());
  RestRequestBuilder builder = new RestRequestBuilder(uri);
  builder.setMethod(nettyRequest.getMethod().getName());
  for (Map.Entry<String, String> e : nettyRequest.getHeaders())
  {
    builder.unsafeAddHeaderValue(e.getKey(), e.getValue());
  }
  ChannelBuffer buf = nettyRequest.getContent();
  if (buf != null)
  {
    if (buf.hasArray())
    {
      // TODO make a copy?
      builder.setEntity(buf.array());
    }
  }

  return builder.build();
}
 
開發者ID:ppdai,項目名稱:rest4j,代碼行數:25,代碼來源:RAPServerCodec.java

示例3: handleSendData

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private void handleSendData(ChannelHandlerContext ctx, HttpRequest request) {
	final HttpTunnelAcceptedChannel tunnel = parent.getTunnel(HttpTunnelMessageUtils.extractTunnelId(request));
	if (tunnel == null) {
		// If the tunnel doesn't exist then close it on the other end
		this.respondWith(ctx, HttpTunnelMessageUtils.createTunnelCloseResponse()).addListener(ChannelFutureListener.CLOSE);
		return;
	}

	tunnel.ping();

	if (LOG.isDebugEnabled())
		LOG.debug("send data request received for tunnel " + tunnel.getTunnelId());

	if (HttpHeaders.getContentLength(request, 0) == 0 || request.getContent() == null || request.getContent().readableBytes() == 0) {
		this.respondWithRejection(ctx, request, "Send data requests must contain data");
		return;
	}

	tunnel.internalReceiveMessage(request.getContent());
	this.respondWith(ctx, HttpTunnelMessageUtils.createSendDataResponse());
}
 
開發者ID:reines,項目名稱:httptunnel,代碼行數:22,代碼來源:HttpTunnelAcceptedChannelHandler.java

示例4: decode

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
protected Object decode(
        Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    HttpRequest request = (HttpRequest) msg;
    ChannelBuffer buf = request.getContent();

    buf.skipBytes("id=".length());
    int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '&');
    String uniqueId = buf.toString(buf.readerIndex(), index - buf.readerIndex(), StandardCharsets.US_ASCII);
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, uniqueId);
    if (deviceSession == null) {
        return null;
    }
    buf.skipBytes(uniqueId.length());
    buf.skipBytes("&bin=".length());

    short packetId = buf.readUnsignedByte();
    short offset = buf.readUnsignedByte(); // dataOffset
    short packetCount = buf.readUnsignedByte();
    buf.readUnsignedByte(); // reserved
    buf.readUnsignedByte(); // timezone
    buf.skipBytes(offset - 5);

    if (channel != null) {
        sendContinue(channel);
        sendResponse(channel, packetId, packetCount);
    }

    if (packetId == 0x31 || packetId == 0x32 || packetId == 0x36) {
        if (simple) {
            return parseFormatA1(deviceSession, buf);
        } else {
            return parseFormatA(deviceSession, buf);
        }
    } //else if (0x34 0x38 0x4F 0x59)

    return null;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:40,代碼來源:Mta6ProtocolDecoder.java

示例5: ActionRequest

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public ActionRequest(String uri, HttpRequest request) {
	this.uri = uri;
	this.request = request;

	if (request != null) {
		if (request.getMethod() == HttpMethod.GET) {
			// logger.debug("URI:{} , {}, {}", request.getUri(), request.getUri().length(), uri.length());
			if (request.getUri().length() > uri.length()) {
				queryString = request.getUri().substring(uri.length() + 1); // 맨앞의 ?를 제거하기 위해 +1
			}
		} else if (request.getMethod() == HttpMethod.POST) {
			long len = HttpHeaders.getContentLength(request);
			ChannelBuffer buffer = request.getContent();
			queryString = new String(buffer.toByteBuffer().array(), 0, (int) len);
		} else {

		}
		if(logger.isDebugEnabled()) {
			String debugQueryString = null;
			if(queryString != null) {
				debugQueryString = queryString.length() > 100 ? queryString.substring(0, 100) + "..." : queryString;
			}
			logger.debug("action {}, param={}", uri, debugQueryString);
		}

		parameterMap = new HashMap<String, String>();
		if (queryString != null) {
			parse();
		}
	}
}
 
開發者ID:gncloud,項目名稱:fastcatsearch,代碼行數:32,代碼來源:ActionRequest.java

示例6: checkIsSendDataRequestWithData

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
private void checkIsSendDataRequestWithData(ChannelEvent event,
		ChannelBuffer data) {
	assertTrue(event instanceof DownstreamMessageEvent);
	DownstreamMessageEvent messageEvent = (DownstreamMessageEvent) event;
	assertTrue(messageEvent.getMessage() instanceof HttpRequest);
	HttpRequest request = (HttpRequest) messageEvent.getMessage();
	assertTrue(HttpTunnelMessageUtils.isSendDataRequest(request, USER_AGENT));
	assertEquals(data.readableBytes(),
			HttpHeaders.getContentLength(request));

	ChannelBuffer content = request.getContent();
	NettyTestUtils.assertEquals(data, content);
}
 
開發者ID:reines,項目名稱:httptunnel,代碼行數:14,代碼來源:HttpTunnelClientSendHandlerTest.java

示例7: ActionRequest

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public ActionRequest(String uri, HttpRequest request) {
		this.uri = uri;
		this.request = request;
        String contentType = request.getHeader("Content-Type");
		if (request != null) {
            parameterMap = new HashMap<String, String>();
			if (request.getMethod() == HttpMethod.GET) {
				// logger.debug("URI:{} , {}, {}", request.getUri(), request.getUri().length(), uri.length());
				if (request.getUri().length() > uri.length()) {
					queryString = request.getUri().substring(uri.length() + 1); // 맨앞의 ?를 제거하기 위해 +1
                    if (queryString != null) {
                        parse();
                    }
				}
			} else if (request.getMethod() == HttpMethod.POST || request.getMethod() == HttpMethod.PUT || request.getMethod() == HttpMethod.DELETE ) {
                if (request.getUri().length() > uri.length()) {
                    queryString = request.getUri().substring(uri.length() + 1); // 맨앞의 ?를 제거하기 위해 +1
                    if (queryString != null) {
                        parse();
                    }
                }
				long len = HttpHeaders.getContentLength(request);
				ChannelBuffer buffer = request.getContent();
				requestBody = new String(buffer.toByteBuffer().array(), 0, (int) len);
                if(contentType == null || !contentType.startsWith("text/plain")) {
                    if (requestBody != null) {
                        parse(requestBody);
                    }
                }
			} else {

			}
			if(logger.isDebugEnabled()) {
				String debugQueryString = null;
				if(queryString != null) {
					debugQueryString = queryString.length() > 100 ? queryString.substring(0, 100) + "..." : queryString;
				}
				logger.debug("action {}, param={}", uri, debugQueryString);
			}

//            parameterMap = new HashMap<String, String>();
//			if (queryString != null) {
//				parse();
//			}
		}
	}
 
開發者ID:gncloud,項目名稱:fastcatsearch3,代碼行數:47,代碼來源:ActionRequest.java

示例8: main

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
public static void main(String[] args) {
    
    Service<HttpRequest, HttpResponse> service = new Service<HttpRequest, HttpResponse>() {
        @Override
        public Future<HttpResponse> apply(HttpRequest request) {
            String reqContent = request.getContent().toString(CharsetUtil.UTF_8);
            System.out.println("[Main] Request received: " + reqContent);
            
            // Parsing JSON request
            JSONObject mainReq;
            try {
                mainReq = (JSONObject) jsonParser.parse(reqContent);
                System.out.println("[Main] Param received - pname:" + mainReq.get("pname"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            
            // Initiate request to Helper
            Service<HttpRequest, HttpResponse> client = ClientBuilder
                    .safeBuild(ClientBuilder.get().codec(Http.get())
                            .hosts("localhost:9004").hostConnectionLimit(1));
            
            HttpRequest helperRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
            ChannelBuffer buffer;
            buffer = request.getContent();
            //buffer = ChannelBuffers.copiedBuffer("{\"dummy\":1}", CharsetUtil.UTF_8);
            helperRequest.setContent(buffer);
            helperRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
            helperRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
            
            Future<HttpResponse> helperResponse = client.apply(helperRequest);
            client.close();
            
            // TODO Understand how Future exceptions are handled. Eg: Connection Error
            /* helperResponse.addEventListener( 
                    new FutureEventListener<HttpResponse>() {
                        public void onSuccess(HttpResponse helperResponse) {
                            System.out.print("[Main] Received helper response: ");
                            System.out.println(helperResponse.getContent().toString(CharsetUtil.UTF_8));
                        }
                        public void onFailure(Throwable cause) {
                            System.out.println("[Main] Helper failed with cause: " + cause);
                        }
                    }); */
            
            Future <HttpResponse> mainResponse = helperResponse.flatMap(new GetBid());
            return mainResponse;
        }
    };
    
    ServerBuilder.safeBuild(service,
            ServerBuilder.get().codec(Http.get()).name("HttpServer")
            .bindTo(new InetSocketAddress("localhost", 9001)));
}
 
開發者ID:eternalthinker,項目名稱:finagle-6.x-java-example,代碼行數:55,代碼來源:MainServer.java

示例9: decode

import org.jboss.netty.handler.codec.http.HttpRequest; //導入方法依賴的package包/類
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, Object msg)
        throws Exception {
    
    HttpRequest request = (HttpRequest) msg;

    ChannelBuffer buf = request.getContent();
    int length = buf.readableBytes();

    // Read identifier
    buf.skipBytes("id=".length());
    int index = ChannelBufferTools.find(buf, buf.readerIndex(), length, "&");
    String uniqueId = buf.toString(buf.readerIndex(), index - buf.readerIndex(), Charset.defaultCharset());
    long deviceId;
    try {
        deviceId = getDataManager().getDeviceByImei(uniqueId).getId();
    } catch(Exception error) {
        Log.warning("Unknown device - " + uniqueId);
        return null;
    }
    buf.skipBytes(uniqueId.length());
    buf.skipBytes("&bin=".length());
    
    // Read header
    short packetId = buf.readUnsignedByte();
    short offset = buf.readUnsignedByte(); // dataOffset
    short packetCount = buf.readUnsignedByte();
    buf.readUnsignedByte(); // reserved
    short parameters = buf.readUnsignedByte(); // TODO: handle timezone
    buf.skipBytes(offset - 5);
    
    // Send response
    if (channel != null) {
        sendContinue(channel);
        sendResponse(channel, packetId, packetCount);
    }
    
    // Parse data
    if (packetId == 0x31 || packetId == 0x32 || packetId == 0x36) {
        if (simple) {
            return parseFormatA1(buf, deviceId);
        } else {
            return parseFormatA(buf, deviceId);
        }
    } //else if (0x34 0x38 0x4F 0x59)

    return null;
}
 
開發者ID:michaelloliveira,項目名稱:traccar-mongodb,代碼行數:50,代碼來源:Mta6ProtocolDecoder.java


注:本文中的org.jboss.netty.handler.codec.http.HttpRequest.getContent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。