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

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

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

Response.send介绍

[英]Writes the string content directly to the response.

This method commits the response.
[中]将字符串内容直接写入响应。
此方法提交响应。

代码示例

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

/**
 * Serializes the object as XML using the registered <code>application/xml</code>
 * ContentTypeEngine and writes it to the response.
 * <p>This method commits the response.</p>
 *
 * @param object
 */
public void xml(Object object) {
  send(object, HttpConstants.ContentType.APPLICATION_XML);
}

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

/**
 * Serializes the object as YAML using the registered <code>application/x-yaml</code>
 * ContentTypeEngine and writes it to the response.
 * <p>This method commits the response.</p>
 *
 * @param object
 */
public void yaml(Object object) {
  send(object, HttpConstants.ContentType.APPLICATION_X_YAML);
}

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

/**
 * Serializes the object as JSON using the registered <code>application/json</code>
 * ContentTypeEngine and writes it to the response.
 * <p>This method commits the response.</p>
 *
 * @param object
 */
public void json(Object object) {
  send(object, HttpConstants.ContentType.APPLICATION_JSON);
}

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

/**
 * Serializes the object as plain text using the registered <code>text/plain</code>
 * ContentTypeEngine and writes it to the response.
 * <p>This method commits the response.</p>
 *
 * @param object
 */
public void text(Object object) {
  send(object, HttpConstants.ContentType.TEXT_PLAIN);
}

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

@Override
public void send(CharSequence content) {
  response.send(content);
}

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

@Override
public void send(Object object) {
  response.send(object);
}

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

/**
 * Renders a template and writes the output directly to the response.
 * <p>This method commits the response.</p>
 *
 * @param templateName
 * @param model
 */
public void render(String templateName, Map<String, Object> model) {
  send(renderToString(templateName, model));
}

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

/**
 * Serializes the object using the registered ContentTypeEngine matching
 * the pre-specified content-type.
 * <p>This method commits the response.</p>
 *
 * @param object
 */
public void send(Object object) {
  if (object instanceof File) {
    file((File) object);
  } else {
    send(object, getContentType());
  }
}

代码示例来源: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
public void handle(RouteContext routeContext) {
  routeContext.getResponse().noCache().text().send("pong");
}

代码示例来源: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
public void handle(RouteContext routeContext) {
  Response response = routeContext.getResponse().noCache().text();
  if (threadDump != null) {
    threadDump.dump(response.getOutputStream());
  } else {
    response.internalError().send("Sorry your runtime environment does not allow to dump threads");
  }
}

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

/**
 * Copies the input stream to the response output stream and closes the input stream upon completion.
 * <p>This method commits the response.</p>
 *
 * @param input
 */
public void resource(InputStream input) {
  checkCommitted();
  finalizeResponse();
  // content type to OCTET_STREAM if it's not set
  if (getContentType() == null) {
    contentType(HttpConstants.ContentType.APPLICATION_OCTET_STREAM);
  }
  try {
    send(input);
  } catch (IOException e) {
    throw new PippoRuntimeException(e);
  }
}

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

private void send(Object object, String contentType) {
  if (StringUtils.isNullOrEmpty(contentType)) {
    throw new PippoRuntimeException("You must specify a content type!");
  }
  ContentTypeEngine contentTypeEngine = contentTypeEngines.getContentTypeEngine(contentType);
  if (contentTypeEngine == null) {
    throw new PippoRuntimeException("You must set a content type engine for '{}'", contentType);
  }
  header(HttpConstants.Header.CONTENT_TYPE, contentTypeEngine.getContentType());
  send(contentTypeEngine.toString(object));
}

代码示例来源: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: pippo-java/pippo

/**
 * Copies the input stream to the response output stream as a download and closes the input stream upon completion.
 * <p>This method commits the response.</p>
 *
 * @param filename
 * @param input
 */
public void file(String filename, InputStream input) {
  checkCommitted();
  // content type to OCTET_STREAM if it's not set
  if (getContentType() == null) {
    contentType(mimeTypes.getContentType(filename, HttpConstants.ContentType.APPLICATION_OCTET_STREAM));
  }
  if (isHeaderEmpty(HttpConstants.Header.CONTENT_DISPOSITION)) {
    filenameHeader(filename);
  }
  finalizeResponse();
  try {
    send(input);
  } catch (IOException e) {
    throw new PippoRuntimeException(e);
  }
}

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

Error error = prepareError(statusCode, routeContext);
try {
  routeContext.getResponse().contentType(contentType).send(error);
} catch (Exception e) {
  log.error("Unexpected error generating '{}' as '{}'", Error.class.getName(), contentType, 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-metrics

@Override
public void handle(RouteContext routeContext) {
  Response response = routeContext.getResponse().noCache().text();
  if (threadDump != null) {
    threadDump.dump(response.getOutputStream());
  } else {
    response.internalError().send("Sorry your runtime environment does not allow to dump threads");
  }
}

相关文章