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


Java Response.setStatus方法代码示例

本文整理汇总了Java中org.simpleframework.http.Response.setStatus方法的典型用法代码示例。如果您正苦于以下问题:Java Response.setStatus方法的具体用法?Java Response.setStatus怎么用?Java Response.setStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.simpleframework.http.Response的用法示例。


在下文中一共展示了Response.setStatus方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handle

import org.simpleframework.http.Response; //导入方法依赖的package包/类
@Override
public void handle(Request req, Response resp) {
  final String requestUrl = req.getAddress().toString();
  // Ignore favicon requests.
  if ("/favicon.ico".equals(requestUrl)) {
    resp.setStatus(Status.NOT_FOUND);
    return;
  }
  LOG.info("Request: " + requestUrl);

  Optional<String> returnValue = Optional.empty();
  if (requestUrl.startsWith(IO_PREFIX)) {
    returnValue = handleIoRequest(requestUrl.substring(IO_PREFIX.length()));
  }

  try {
    resp.setStatus(returnValue.isPresent() ? Status.OK : Status.NOT_FOUND);
    resp.getPrintStream().append(returnValue.isPresent() ? returnValue.get() : "");
    resp.close();
  } catch (final IOException e) {
    LOG.warn("Could not deliver response");
  }
  LOG.debug("Request handled");
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:25,代码来源:NodeContainer.java

示例2: serveError

import org.simpleframework.http.Response; //导入方法依赖的package包/类
/**
 * Write a {@link HTTPTrackerErrorMessage} to the response with the given
 * HTTP status code.
 *
 * @param response The HTTP response object.
 * @param body The response output stream to write to.
 * @param status The HTTP status code to return.
 * @param error The error reported by the tracker.
 */
private void serveError(Response response, OutputStream body,
        Status status, HTTPTrackerErrorMessage error) throws IOException {
    response.setStatus(status);
    LOG.warn("Could not process announce request ({}) !",
            error.getReason());
    BytesBEncoder encoder = new BytesBEncoder();
    encoder.bencode(error.toBEValue());
    body.write(encoder.toByteArray());  // This is the raw network stream.
}
 
开发者ID:letroll,项目名称:TtorrentAndroid,代码行数:19,代码来源:TrackerService.java

示例3: serveMotionJpegAsync

import org.simpleframework.http.Response; //导入方法依赖的package包/类
void serveMotionJpegAsync(final Response response) throws IOException {
  LOG.info("Serving MJPEG...");
  response.setContentType("multipart/x-mixed-replace;boundary=ipcamera");
  response.setStatus(Status.OK);

  OutputStream outputStream = response.getOutputStream();
  Executor mMjpegExecutor = Executors.newSingleThreadExecutor();
  mMjpegExecutor.execute(() -> {
    byte[] jpegData = null;
    try {
      // Immediately serve most recent frame.
      synchronized (mBytesLock) {
        serveMotionJpegFrame(mCurrentImageBytes, outputStream);
      }

      // Skip the first frame, since it's old. Then continue to read updated frames.
      mmJpegQueue.take();
      while ((jpegData = mmJpegQueue.take()) != null) {
        serveMotionJpegFrame(jpegData, outputStream);
      }
    } catch (IOException | InterruptedException e) {
      LOG.warn("Interrupted while serving MJPEG data. Exiting MJPEG loop.");
      try {
        response.close();
      } catch (IOException ignore) {
      }
    }
  });
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:30,代码来源:ImageServer.java

示例4: serveData

import org.simpleframework.http.Response; //导入方法依赖的package包/类
/** Serves the given data and content type to the given response. */
private void serveData(String contentType, byte[] data, Response response) throws IOException {
  response.setStatus(Status.OK);
  response.setContentType(contentType);
  response.getOutputStream().write(data);
  response.getOutputStream().close();
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:8,代码来源:ImageServer.java

示例5: handleUnsupportedMethod

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void handleUnsupportedMethod(Request request, Response response) {
    int index = this.requestIndex;
    ++this.requestIndex; // Increment before any possible exception.
    response.setStatus(Status.METHOD_NOT_ALLOWED);
    String responseBody = "UNSUPPORTED_METHOD " + index;
    this.respond(response, responseBody);
}
 
开发者ID:coil-lighting,项目名称:udder,代码行数:8,代码来源:HttpServiceContainer.java

示例6: handleGet

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void handleGet(Request request, Response response) {
    int index = this.requestIndex;
    ++this.requestIndex; // Increment before any possible exception.
    response.setStatus(Status.OK);
    String responseBody = "TODO GET " + index;
    this.respond(response, responseBody);
}
 
开发者ID:coil-lighting,项目名称:udder,代码行数:8,代码来源:HttpServiceContainer.java

示例7: handleMethodNotAllowed

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void handleMethodNotAllowed(Response resp){
	resp.setStatus(Status.METHOD_NOT_ALLOWED);
	resp.setValue("Content-Type", "text/plain");
	PrintStream body;
	try {
		body = resp.getPrintStream();
		body.println("METHOD_NOT_ALLOWED");	
		body.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:ael-code,项目名称:preston,代码行数:13,代码来源:RequestHandler.java

示例8: handleInternalServerError

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void handleInternalServerError(Response resp){
	resp.setStatus(Status.INTERNAL_SERVER_ERROR);
	resp.setValue("Content-Type", "text/plain");
	PrintStream body;
	try {
		body = resp.getPrintStream();
		body.println("INTERNAL_SERVER_ERROR");	
		body.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:ael-code,项目名称:preston,代码行数:13,代码来源:RequestHandler.java

示例9: print

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void print(Status status, Response response, String str) throws Exception {
	PrintStream body = response.getPrintStream();
	response.setStatus(status);
	response.setValue("Content-Type", "application/json");
	if (str != null)
		body.println(str);
	body.close();
}
 
开发者ID:vdurmont,项目名称:apipixie,代码行数:9,代码来源:DistantAPISimulator.java

示例10: serveData

import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void serveData(String contentType, byte[] data, Response response) throws IOException {
  response.setStatus(Status.OK);
  response.setContentType(contentType);
  response.getOutputStream().write(data);
  response.getOutputStream().close();
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:7,代码来源:WebRequestContainer.java


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