ro.pippo.core.Response.ok()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(182)

本文整理了Java中ro.pippo.core.Response.ok方法的一些代码示例,展示了Response.ok的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.ok方法的具体详情如下:
包路径:ro.pippo.core.Response
类名称:Response
方法名:ok

Response.ok介绍

[英]Set the response status to OK (200).

Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request the response will contain an entity describing or containing the result of the action.
[中]将响应状态设置为OK(200)。
成功HTTP请求的标准响应。实际响应将取决于所使用的请求方法。在GET请求中,响应将包含与请求的资源相对应的实体。在POST请求中,响应将包含一个描述或包含操作结果的实体。

代码示例

代码示例来源:origin: pippo-java/pippo

protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException {
  String filename = resourceUrl.getFile();
  String mimeType = routeContext.getApplication().getMimeTypes().getContentType(filename);
  if (!StringUtils.isNullOrEmpty(mimeType)) {
    // stream the resource
    log.debug("Streaming as resource '{}'", resourceUrl);
    routeContext.getResponse().contentType(mimeType);
    routeContext.getResponse().ok().resource(resourceUrl.openStream());
  } else {
    // stream the file
    log.debug("Streaming as file '{}'", resourceUrl);
    routeContext.getResponse().ok().file(filename, resourceUrl.openStream());
  }
}

代码示例来源:origin: pippo-java/pippo

private void finalizeResponse() {
  // add headers
  for (Map.Entry<String, String> header : getHeaderMap().entrySet()) {
    httpServletResponse.setHeader(header.getKey(), header.getValue());
  }
  // add cookies
  for (Cookie cookie : getCookies()) {
    httpServletResponse.addCookie(cookie);
  }
  // set status to OK if it's not set
  if (getStatus() == 0 || getStatus() == Integer.MAX_VALUE) {
    ok();
  }
  // call finalize listeners
  if ((finalizeListeners != null) && !finalizeListeners.isEmpty()) {
    finalizeListeners.onFinalize(this);
  }
}

代码示例来源:origin: pippo-java/pippo

protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException {
  String filename = resourceUrl.getFile();
  String mimeType = routeContext.getApplication().getMimeTypes().getContentType(filename);
  if (!StringUtils.isNullOrEmpty(mimeType)) {
    // stream the resource
    log.debug("Streaming as resource '{}'", resourceUrl);
    routeContext.getResponse().ok().chunked(chunked).resource(resourceUrl.openStream());
  } else {
    // stream the file
    log.debug("Streaming as file '{}'", resourceUrl);
    routeContext.getResponse().ok().chunked(chunked).file(filename, resourceUrl.openStream());
  }
}

代码示例来源:origin: pippo-java/pippo

@Override
public void handle(RouteContext routeContext) {
  Response response = routeContext.getResponse().noCache().text();
  SortedMap<String, HealthCheck.Result> healthChecks = healthCheckRegistry.runHealthChecks();
  if (healthChecks.isEmpty()) {
    response.notImplemented().send("The health checks are empty");
  } else {
    boolean notHealthy = healthChecks.values().stream().anyMatch(hc -> !hc.isHealthy());
    if (notHealthy) {
      response.internalError().send("The health is bad");
    } else {
      response.ok().send("The health is good");
    }
  }
}

代码示例来源:origin: pippo-java/pippo

@Override
protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException {
  try {
    // compile sass to css
    log.trace("Send css for '{}'", resourceUrl);
    ScssContext.UrlMode urlMode = ScssContext.UrlMode.ABSOLUTE;
    String identifier = resourceUrl.getFile();
    ScssStylesheet scssStylesheet = ScssStylesheet.get(identifier);
    if (scssStylesheet == null) {
      throw new Exception("ScssStylesheet is null for '" + identifier + "'");
    }
    String content = scssStylesheet.toString();
    String result = sourceMap.get(content);
    if (result == null) {
      scssStylesheet.compile(urlMode);
      Writer writer = new StringWriter();
      scssStylesheet.write(writer, minify);
      result = writer.toString();
      if (routeContext.getApplication().getPippoSettings().isProd()) {
        sourceMap.put(content, result);
      }
    }
    // send css
    routeContext.getResponse().contentType("text/css");
    routeContext.getResponse().ok().send(result);
  }  catch (Exception e) {
    throw new PippoRuntimeException(e);
  }
}

代码示例来源:origin: pippo-java/pippo

@Override
protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException {
  try {
    // compile less to css
    log.trace("Send css for '{}'", resourceUrl);
    LessSource.URLSource source = new LessSource.URLSource(resourceUrl);
    String content = source.getContent();
    String result = sourceMap.get(content);
    if (result == null) {
      ThreadUnsafeLessCompiler compiler = new ThreadUnsafeLessCompiler();
      LessCompiler.Configuration configuration = new LessCompiler.Configuration();
      configuration.setCompressing(minify);
      LessCompiler.CompilationResult compilationResult = compiler.compile(resourceUrl, configuration);
      for (LessCompiler.Problem warning : compilationResult.getWarnings()) {
        log.warn("Line: {}, Character: {}, Message: {} ", warning.getLine(), warning.getCharacter(), warning.getMessage());
      }
      result = compilationResult.getCss();
      if (routeContext.getApplication().getPippoSettings().isProd()) {
        sourceMap.put(content, result);
      }
    }
    // send css
    routeContext.getResponse().contentType("text/css");
    routeContext.getResponse().ok().send(result);
  } catch (Exception e) {
    throw new PippoRuntimeException(e);
  }
}

代码示例来源:origin: ro.pippo/pippo-metrics

@Override
public void handle(RouteContext routeContext) {
  Response response = routeContext.getResponse().noCache().text();
  SortedMap<String, HealthCheck.Result> healthChecks = healthCheckRegistry.runHealthChecks();
  if (healthChecks.isEmpty()) {
    response.notImplemented().send("The health checks are empty");
  } else {
    boolean notHealthy = healthChecks.values().stream().anyMatch(hc -> !hc.isHealthy());
    if (notHealthy) {
      response.internalError().send("The health is bad");
    } else {
      response.ok().send("The health is good");
    }
  }
}

代码示例来源:origin: gitblit/fathom

protected void serveSpecification(RouteContext ctx, String specificationName) {
  String extension = Files.getFileExtension(specificationName);
  if (extension.isEmpty()) {
    // default to json
    specificationName += ".json";
  }
  final String finalDocumentName = specificationName;
  final String finalExtension = Files.getFileExtension(finalDocumentName);
  String document = specifications.get(finalDocumentName.toLowerCase());
  if (document == null) {
    ctx.getResponse().notFound();
  } else {
    ctx.getResponse().ok();
    httpCacheToolkit.addEtag(ctx, startTime);
    if ("json".equals(finalExtension)) {
      ctx.json();
    } else if ("yaml".equals(finalExtension)) {
      ctx.yaml();
    } else {
      ctx.text();
    }
    if (HttpMethod.GET.equals(ctx.getRequestMethod())) {
      ctx.getResponse().send(document);
    }
  }
}

代码示例来源:origin: ro.pippo/pippo-sasscompiler

@Override
protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException {
  try {
    // compile sass to css
    log.trace("Send css for '{}'", resourceUrl);
    ScssContext.UrlMode urlMode = ScssContext.UrlMode.ABSOLUTE;
    String identifier = resourceUrl.getFile();
    ScssStylesheet scssStylesheet = ScssStylesheet.get(identifier);
    if (scssStylesheet == null) {
      throw new Exception("ScssStylesheet is null for '" + identifier + "'");
    }
    String content = scssStylesheet.toString();
    String result = sourceMap.get(content);
    if (result == null) {
      scssStylesheet.compile(urlMode);
      Writer writer = new StringWriter();
      scssStylesheet.write(writer, minify);
      result = writer.toString();
      if (routeContext.getApplication().getPippoSettings().isProd()) {
        sourceMap.put(content, result);
      }
    }
    // send css
    routeContext.getResponse().contentType("text/css");
    routeContext.getResponse().ok().send(result);
  }  catch (Exception e) {
    throw new PippoRuntimeException(e);
  }
}

代码示例来源:origin: com.gitblit.fathom/fathom-rest-swagger

protected void serveSpecification(RouteContext ctx, String specificationName) {
  String extension = Files.getFileExtension(specificationName);
  if (extension.isEmpty()) {
    // default to json
    specificationName += ".json";
  }
  final String finalDocumentName = specificationName;
  final String finalExtension = Files.getFileExtension(finalDocumentName);
  String document = specifications.get(finalDocumentName.toLowerCase());
  if (document == null) {
    ctx.getResponse().notFound();
  } else {
    ctx.getResponse().ok();
    httpCacheToolkit.addEtag(ctx, startTime);
    if ("json".equals(finalExtension)) {
      ctx.json();
    } else if ("yaml".equals(finalExtension)) {
      ctx.yaml();
    } else {
      ctx.text();
    }
    if (HttpMethod.GET.equals(ctx.getRequestMethod())) {
      ctx.getResponse().send(document);
    }
  }
}

代码示例来源:origin: gitblit/fathom

@POST
@ApiSummary("Add a new pet to the store")
@RequirePermission("add:pet")
@Return(code = 405, description = "Invalid input", onResult = ValidationException.class)
public void addPet(@Desc("Pet object that needs to be added to the store") @Body Pet pet) {
  getResponse().ok();
}

代码示例来源:origin: gitblit/fathom

context.getResponse().ok().contentType(TEXT_XML).contentLength(result.length);
try (OutputStream output = context.getResponse().getOutputStream()) {
  output.write(result);

代码示例来源:origin: com.gitblit.fathom/fathom-xmlrpc

context.getResponse().ok().contentType(TEXT_XML).contentLength(result.length);
try (OutputStream output = context.getResponse().getOutputStream()) {
  output.write(result);

代码示例来源:origin: ro.pippo/pippo-less4j

@Override
protected void sendResource(URL resourceUrl, RouteContext routeContext) throws IOException {
  try {
    // compile less to css
    log.trace("Send css for '{}'", resourceUrl);
    LessSource.URLSource source = new LessSource.URLSource(resourceUrl);
    String content = source.getContent();
    String result = sourceMap.get(content);
    if (result == null) {
      ThreadUnsafeLessCompiler compiler = new ThreadUnsafeLessCompiler();
      LessCompiler.Configuration configuration = new LessCompiler.Configuration();
      configuration.setCompressing(minify);
      LessCompiler.CompilationResult compilationResult = compiler.compile(resourceUrl, configuration);
      for (LessCompiler.Problem warning : compilationResult.getWarnings()) {
        log.warn("Line: {}, Character: {}, Message: {} ", warning.getLine(), warning.getCharacter(), warning.getMessage());
      }
      result = compilationResult.getCss();
      if (routeContext.getApplication().getPippoSettings().isProd()) {
        sourceMap.put(content, result);
      }
    }
    // send css
    routeContext.getResponse().contentType("text/css");
    routeContext.getResponse().ok().send(result);
  } catch (Exception e) {
    throw new PippoRuntimeException(e);
  }
}

代码示例来源:origin: gitblit/fathom

@POST("/{petId}/uploadImage")
@ApiSummary("uploads an image")
@RequirePermission("update:pet")
@Produces(Produces.JSON)
@Return(code = 200, description = "Successful operation")
public void uploadFile(
    @Desc("ID of pet to update") long petId,
    @Desc("Additional data to pass to server") @Form String additionalMetadata,
    @Desc("file to upload") @Form FileItem file) {
  getResponse().ok();
}

相关文章