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


Java HttpResponseStatus类代码示例

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


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

示例1: handleVersion

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
/**
 * Prints Version information for the various components.
 * @param query A non-null HTTP query to parse and respond to.
 */
private void handleVersion(final HttpRpcPluginQuery query) {
  final Map<String, Map<String, String>> versions = Maps.newHashMap();
  
  Map<String, String> version = Maps.newHashMap();
  version.put("version", BuildData.version);
  version.put("short_revision", BuildData.short_revision);
  version.put("full_revision", BuildData.full_revision);
  version.put("timestamp", Long.toString(BuildData.timestamp));
  version.put("repo_status", BuildData.repo_status.toString());
  version.put("user", BuildData.user);
  version.put("host", BuildData.host);
  version.put("repo", BuildData.repo);
  versions.put("tsdb", version);

  // TODO - plugin version
  
  query.sendBuffer(HttpResponseStatus.OK,
      ChannelBuffers.wrappedBuffer(JSON.serializeToBytes(versions)),
      "application/json");
}
 
开发者ID:OpenTSDB,项目名称:opentsdb-rpc-kafka,代码行数:25,代码来源:KafkaHttpRpcPlugin.java

示例2: handleRate

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
/**
 * Handles calls to print and/or adjust the rate per group
 * @param query The HTTP query to parse and respond to.
 */
private void handleRate(final HttpRpcPluginQuery query) {
  synchronized (tsdb) {
    if (KafkaRpcPlugin.KAFKA_RPC_REFERENCE == null) {
      throw new BadRequestException(HttpResponseStatus.CONFLICT, 
          "Consumers have not started yet");
    }
    // for now we'll just parse URI params to cheat
    final String group_id = query.getQueryStringParam("group");
    final double rate;
    if (group_id != null && !group_id.isEmpty()) {
      rate = Double.parseDouble(query.getRequiredQueryStringParam("rate"));
      KafkaRpcPlugin.KAFKA_RPC_REFERENCE.setRate(group_id, rate);
    } else {
      rate = 0;
    }
    
    final Map<String, Double> rates = 
        KafkaRpcPlugin.KAFKA_RPC_REFERENCE.getRates();
    query.sendBuffer(HttpResponseStatus.OK,
        ChannelBuffers.wrappedBuffer(JSON.serializeToBytes(rates)),
        "application/json");
  }
}
 
开发者ID:OpenTSDB,项目名称:opentsdb-rpc-kafka,代码行数:28,代码来源:KafkaHttpRpcPlugin.java

示例3: decode

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
@Override
protected Object decode(
        Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    HttpRequest request = (HttpRequest) msg;
    QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());

    DeviceSession deviceSession = getDeviceSession(
            channel, remoteAddress, decoder.getParameters().get("UserName").get(0));
    if (deviceSession == null) {
        return null;
    }

    Parser parser = new Parser(PATTERN, decoder.getParameters().get("LOC").get(0));
    if (!parser.matches()) {
        return null;
    }

    Position position = new Position();
    position.setProtocol(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());

    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));

    position.setValid(true);
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setAltitude(parser.nextDouble(0));
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));

    if (channel != null) {
        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
        channel.write(response).addListener(ChannelFutureListener.CLOSE);
    }

    return position;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:39,代码来源:PathAwayProtocolDecoder.java

示例4: doAuthAction

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
@Override
public void doAuthAction(ActionRequest request, ActionResponse response)
		throws Exception {
	BackupDictionaryJob job = new BackupDictionaryJob();
	job.setArgs(request.getParameter("pluginId"));
	
	writeHeader(response);
	response.setStatus(HttpResponseStatus.OK);
	ResponseWriter resultWriter = getDefaultResponseWriter(response.getWriter());
	resultWriter.object().key("success");
	//job을 바로실행.
	try{
		JobResult jobResult = job.doRun();
		if(jobResult != null){
			resultWriter.value(jobResult.isSuccess());
		}else{
			resultWriter.value(false);
		}
	}catch(Throwable e){
		resultWriter.value(false);
	}
	
	resultWriter.endObject();
	resultWriter.done();
}
 
开发者ID:gncloud,项目名称:fastcatsearch3,代码行数:26,代码来源:BackupDictionaryAction.java

示例5: writeHeader

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
protected void writeHeader(ActionResponse response, String responseCharset) {
        if(response.status() == null) {
            response.setStatus(HttpResponseStatus.OK);
        }
//		logger.debug("resultType > {}", resultType);
		if (resultType == Type.json) {
			response.setContentType("application/json; charset=" + responseCharset);
		} else if (resultType == Type.jsonp) {
			response.setContentType("application/json; charset=" + responseCharset);
		} else if (resultType == Type.xml) {
			response.setContentType("text/xml; charset=" + responseCharset);
		} else if (resultType == Type.html) {
			response.setContentType("text/html; charset=" + responseCharset);
		} else if (resultType == Type.text) {
			response.setContentType("text/plain; charset=" + responseCharset);
		} else {
			response.setContentType("application/json; charset=" + responseCharset);
		}
	}
 
开发者ID:gncloud,项目名称:fastcatsearch3,代码行数:20,代码来源:ServiceAction.java

示例6: messageReceived

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
  try {
    final HttpRequest req = (HttpRequest) e.getMessage();
    if (req.getMethod().equals(HttpMethod.POST)) {
      doPost(ctx, e, req);
    } else if (req.getMethod().equals(HttpMethod.GET)) {
      doGet(ctx, e, req);
    } else {
      writeResponseAndClose(e, new DefaultHttpResponse(
              HttpVersion.HTTP_1_1,
              HttpResponseStatus.BAD_REQUEST));
    }
  } catch (Exception ex) {
    if (logger.isDebugEnabled())
      logger.debug("Failed to process message", ex);
    HttpResponse response = new DefaultHttpResponse(
            HttpVersion.HTTP_1_1,
            HttpResponseStatus.INTERNAL_SERVER_ERROR);
    response.setContent(
            ChannelBuffers.copiedBuffer(ex.getMessage().getBytes()));
    writeResponseAndClose(e, response);
  }
}
 
开发者ID:yandex,项目名称:opentsdb-flume,代码行数:25,代码来源:LegacyHttpSource.java

示例7: doPost

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
private void doPost(ChannelHandlerContext ctx, MessageEvent e, HttpRequest req)
        throws IOException {

  final QueryStringDecoder decoded = new QueryStringDecoder(req.getUri());
  if (!decoded.getPath().equalsIgnoreCase("/write")) {
    writeResponseAndClose(e,
            new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND));
    return;
  }

  try {
    metricParser.parse(req);
  } catch (IllegalArgumentException iae) {
    logger.warn("Metric parser failed: " + iae.getMessage());
  }

  HttpResponse response = new DefaultHttpResponse(
          HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
  response.setContent(ChannelBuffers.copiedBuffer(
          ("Seen events").getBytes()
  ));
  writeResponseAndClose(e, response);
}
 
开发者ID:yandex,项目名称:opentsdb-flume,代码行数:24,代码来源:LegacyHttpSource.java

示例8: prepareAsyncResponse

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
/**
 * Prepares an asynchronous rest response. It submits the {@linkplain}
 * @param request
 * @param response
 * @throws IOException 
 */
private void prepareAsyncResponse(HttpRequest request, HttpResponse response) throws IOException 
{
  HazelcastClusterServiceBean hzService = SpringContext.getBean(HazelcastClusterServiceBean.class);
  
  SerializableHttpRequest serReq = new SerializableHttpRequest();
  
  serReq.getArgs().addAll(extractArguments(request, true));
  serReq.setRequestMethod(request.method());
  serReq.setRequestUri(request.uri());
  
  Event<SerializableHttpRequest> event = new Event<>(serReq);
  String requestKey = makeAsyncRequestKey(event);
      
  String redirectUrl = WebbitRestServerBean.ASYNC_REST_RESPONSE_URI+requestKey;
   
  hzService.set(requestKey, event, WebbitRestServerBean.ASYNC_REST_EVENT_MAP);
  response.header("Location", redirectUrl).status(HttpResponseStatus.ACCEPTED.getCode()).end();
  
  log.info("[Async rest] Request submitted with redirect url: "+redirectUrl);
}
 
开发者ID:javanotes,项目名称:reactive-data,代码行数:27,代码来源:MethodInvocationHandler.java

示例9: createRouteBuilder

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("netty-http:http://0.0.0.0:{{port}}/foo")
                .to("mock:input")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
                        response.setContent(ChannelBuffers.copiedBuffer("Bye World".getBytes()));
                        response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 9);

                        exchange.getOut().setBody(response);
                    }
                });
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:NettyUseRawHttpResponseTest.java

示例10: decode

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg)
        throws Exception
{
  HttpResponse nettyResponse = (HttpResponse) msg;

  RestResponseBuilder builder = new RestResponseBuilder();

  HttpResponseStatus status = nettyResponse.getStatus();
  builder.setStatus(status.getCode());

  for (Map.Entry<String, String> e : nettyResponse.getHeaders())
  {
    builder.unsafeAddHeaderValue(e.getKey(), e.getValue());
  }

  ChannelBuffer buf = nettyResponse.getContent();
  byte[] array = new byte[buf.readableBytes()];
  buf.readBytes(array);
  builder.setEntity(array);

  return builder.build();
}
 
开发者ID:ppdai,项目名称:rest4j,代码行数:24,代码来源:RAPClientCodec.java

示例11: encode

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg)
        throws Exception
{
  RestResponse response = (RestResponse) msg;

  HttpResponse nettyResponse =
      new DefaultHttpResponse(HttpVersion.HTTP_1_1,
                              HttpResponseStatus.valueOf(response.getStatus()));

  for (Map.Entry<String, String> e : response.getHeaders().entrySet())
  {
    nettyResponse.setHeader(e.getKey(), e.getValue());
  }
  final ByteString entity = response.getEntity();
  ChannelBuffer buf = ChannelBuffers.wrappedBuffer(entity.asByteBuffer());
  nettyResponse.setContent(buf);
  nettyResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, entity.length());

  return nettyResponse;
}
 
开发者ID:ppdai,项目名称:rest4j,代码行数:22,代码来源:RAPServerCodec.java

示例12: writeResponse

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
private void writeResponse(MessageEvent e) {
  HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
  response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");

  ChannelBuffer content = ChannelBuffers.dynamicBuffer();
  Writer writer = new OutputStreamWriter(new ChannelBufferOutputStream(content), CharsetUtil.UTF_8);
  reportAdapter.toJson(report.get(), writer);
  try {
    writer.close();
  } catch (IOException e1) {
    LOG.error("error writing resource report", e1);
  }
  response.setContent(content);
  ChannelFuture future = e.getChannel().write(response);
  future.addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:17,代码来源:TrackerService.java

示例13: messageReceived

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
        throws Exception {
    HttpRequest request = (HttpRequest) e.getMessage();
    String uri = request.getUri();
    
    System.out.println("uri:" + uri);
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    ChannelBuffer buffer = new DynamicChannelBuffer(2048);
    buffer.writeBytes("hello!! 你好".getBytes("UTF-8"));
    response.setContent(buffer);
    response.setHeader("Content-Type", "text/html; charset=UTF-8");
    response.setHeader("Content-Length", response.getContent().writerIndex());
    Channel ch = e.getChannel();
    // Write the initial line and the header.
    ch.write(response);
    ch.disconnect();
    ch.close();

}
 
开发者ID:laizhihuan,项目名称:java-test-demo,代码行数:21,代码来源:HttpServerHandler.java

示例14: getStatus

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
/**
 * Returns the {@link HttpResponseStatus} represented by the HTTP response status header.
 */
public static HttpResponseStatus getStatus(int spdyVersion, SpdyHeaderBlock block) {
    try {
        String status;
        if (spdyVersion < 3) {
            status = block.getHeader(Spdy2HttpNames.STATUS);
        } else {
            status = block.getHeader(HttpNames.STATUS);
        }
        int space = status.indexOf(' ');
        if (space == -1) {
            return HttpResponseStatus.valueOf(Integer.parseInt(status));
        } else {
            int code = Integer.parseInt(status.substring(0, space));
            String reasonPhrase = status.substring(space + 1);
            HttpResponseStatus responseStatus = HttpResponseStatus.valueOf(code);
            if (responseStatus.getReasonPhrase().equals(reasonPhrase)) {
                return responseStatus;
            } else {
                return new HttpResponseStatus(code, reasonPhrase);
            }
        }
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:jle,项目名称:andy,代码行数:29,代码来源:SpdyHeaders.java

示例15: handleInfoRequest

import org.jboss.netty.handler.codec.http.HttpResponseStatus; //导入依赖的package包/类
private void handleInfoRequest(NettyHttpRequest req, DefaultHttpResponse resp){
	String numJobs = req.param("last", "5"); //default 5
	String jobType = req.param("isLocal", "true");
	String jobName = req.param("jobName");
	LeaderModule m = ((LeaderModule)module);
	if (!jobType.equalsIgnoreCase("true") && !jobType.equalsIgnoreCase("false")){
		HttpResponseUtil.setResponse(resp, "info action", "require 'isLocal' == 'true' OR 'false'");
		resp.setStatus(HttpResponseStatus.BAD_REQUEST);
	}else{
		boolean isLocal = new Boolean(jobType.toLowerCase());
		if (jobName != null){
			JSONObject searchJobInfo = m.searchJobInfo(jobName, isLocal);
			if (searchJobInfo == null){
				HttpResponseUtil.setResponse(resp, " query job :" + jobName, "null");
			}else{
				HttpResponseUtil.setResponse(resp, " query job :" + jobName, searchJobInfo);
			}
		}else if (numJobs != null){
			int num = new Integer(numJobs);
			HttpResponseUtil.setResponse(resp, "latest jobs", m.getLatestJobStates(num,isLocal));
		}else{
			HttpResponseUtil.setResponse(resp, "feluca job status", m.getLatestJobStates(1,isLocal));
		}
	}
}
 
开发者ID:lgnlgn,项目名称:feluca,代码行数:26,代码来源:LeaderJobRequest.java


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