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


Java Status类代码示例

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


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

示例1: handleRequestTrusted

import org.simpleframework.http.Status; //导入依赖的package包/类
/** Call this for requests that are already trusted and don't need an auth token check. */
public void handleRequestTrusted(String requestUrl, OutputStream response) throws
    RequestHandlingException {
  synchronized (mLock) {
    // TODO: This should be done on a background thread, with a proper queue, de-duping per
    // command/node etc.
    for (RequestHandler handler : mRequestHandlers) {
      if (handler.canHandle(requestUrl)) {
        handler.doHandle(requestUrl, response);
        return;
      }
    }
    throw new RequestHandlingException("No request handler found. " + requestUrl,
        Status.NOT_FOUND);
  }
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:17,代码来源:RequestHandlers.java

示例2: handle

import org.simpleframework.http.Status; //导入依赖的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

示例3: testServingIndexHtml

import org.simpleframework.http.Status; //导入依赖的package包/类
@Test
public void testServingIndexHtml() throws IOException {
  WebRequestContainer container =
      new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
  when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
  container.start();

  ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
  verify(mMockServer).startServing(containerCaptor.capture());

  OutputStream mockOutputStream = mock(OutputStream.class);
  Response mockResponse = mock(Response.class);
  when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);

  // Simulate request to unavailable address.
  containerCaptor.getValue().handle(createMockRequestForUrl("/"), mockResponse);
  verify(mockResponse).setStatus(Status.OK);
  verify(mockResponse).setContentType("text/html");
  verify(mockResponse).close();
  verify(mockOutputStream).write(eq(new byte[]{1, 2, 23, 42}));
  verify(mockOutputStream).close();
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:23,代码来源:WebRequestContainerTest.java

示例4: testServingImageFileNotSet

import org.simpleframework.http.Status; //导入依赖的package包/类
@Test
public void testServingImageFileNotSet() throws IOException {
  WebRequestContainer container =
      new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
  when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
  container.start();

  ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
  verify(mMockServer).startServing(containerCaptor.capture());

  OutputStream mockOutputStream = mock(OutputStream.class);
  Response mockResponse = mock(Response.class);
  when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);

  // Simulate request to image URL..
  containerCaptor.getValue().handle(createMockRequestForUrl("/now.jpg"), mockResponse);
  verify(mockResponse).setStatus(Status.OK);
  verify(mockResponse).setContentType("image/jpeg");
  verify(mockResponse).close();

  // We never set the image
  verify(mockOutputStream).write(eq(new byte[0]));
  verify(mockOutputStream).close();
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:25,代码来源:WebRequestContainerTest.java

示例5: testServingImageFileSet

import org.simpleframework.http.Status; //导入依赖的package包/类
@Test
public void testServingImageFileSet() throws IOException {
  WebRequestContainer container =
      new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
  when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
  container.start();
  mImageServer.updateCurrentFile(() -> Optional.of(new byte[]{1, 2, 3, 5, 8, 13, 21}));

  ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
  verify(mMockServer).startServing(containerCaptor.capture());

  OutputStream mockOutputStream = mock(OutputStream.class);
  Response mockResponse = mock(Response.class);
  when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);

  // Simulate request to image URL..
  containerCaptor.getValue().handle(createMockRequestForUrl("/now.jpg"), mockResponse);
  verify(mockResponse).setStatus(Status.OK);
  verify(mockResponse).setContentType("image/jpeg");
  verify(mockResponse).close();

  // We never set the image
  verify(mockOutputStream).write(eq(new byte[]{1, 2, 3, 5, 8, 13, 21}));
  verify(mockOutputStream).close();
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:26,代码来源:WebRequestContainerTest.java

示例6: serveError

import org.simpleframework.http.Status; //导入依赖的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.setCode(status.getCode());
	response.setText(status.getDescription());
	logger.warn("Could not process announce request ({}) !",
		error.getReason());

	WritableByteChannel channel = Channels.newChannel(body);
	channel.write(error.getData());
}
 
开发者ID:KingJoker,项目名称:PiratePlayar,代码行数:20,代码来源:TrackerService.java

示例7: serveError

import org.simpleframework.http.Status; //导入依赖的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

示例8: doHandle

import org.simpleframework.http.Status; //导入依赖的package包/类
@Override
public void doHandle(String request, OutputStream response) throws RequestHandlingException {
  try (OutputStreamWriter writer = new OutputStreamWriter(response)) {
    writer.write(handle(request));
  } catch (IOException e) {
    LOG.error("Cannot write response", e);
    throw new RequestHandlingException("Cannot write response.", Status.INTERNAL_SERVER_ERROR);
  }
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:10,代码来源:MasterModuleHandler.java

示例9: dataToText

import org.simpleframework.http.Status; //导入依赖的package包/类
private String dataToText() throws RequestHandlingException {
  StringWriter result = new StringWriter();
  try {
    TextFormat.print(mChannelData, result);
    return result.toString();
  } catch (IOException e) {
    LOG.error("Cannot turn protocol buffer into text.", e);
    throw new RequestHandlingException("Cannot produce output", Status.INTERNAL_SERVER_ERROR);
  }
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:11,代码来源:ChannelDataHandler.java

示例10: serveMotionJpegAsync

import org.simpleframework.http.Status; //导入依赖的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

示例11: serveData

import org.simpleframework.http.Status; //导入依赖的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

示例12: testServingUnmappedUrl

import org.simpleframework.http.Status; //导入依赖的package包/类
@Test
public void testServingUnmappedUrl() throws IOException {
  WebRequestContainer container =
      new WebRequestContainer(123, mMockServerCreator, mImageServer, mMockResourceLoader);
  when(mMockResourceLoader.load(anyString())).thenReturn(new byte[]{1, 2, 23, 42});
  container.start();

  ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
  verify(mMockServer).startServing(containerCaptor.capture());

  Response mockResponse = mock(Response.class);
  // Simulate request to unavailable address.
  containerCaptor.getValue().handle(createMockRequestForUrl("doesNotExist"), mockResponse);
  verify(mockResponse).setStatus(Status.NOT_FOUND);
}
 
开发者ID:shaeberling,项目名称:winston,代码行数:16,代码来源:WebRequestContainerTest.java

示例13: handleUnsupportedMethod

import org.simpleframework.http.Status; //导入依赖的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

示例14: handleGet

import org.simpleframework.http.Status; //导入依赖的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

示例15: handleMethodNotAllowed

import org.simpleframework.http.Status; //导入依赖的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


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