ro.pippo.core.Response类的使用及代码示例

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

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

Response介绍

暂无

代码示例

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

@Override
public RouteContext negotiateContentType() {
  response.contentType(request);
  return this;
}

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

/**
 * Gets the character encoding of the response.
 *
 * @return the character encoding
 */
public String getCharacterEncoding() {
  return getHttpServletResponse().getCharacterEncoding();
}

代码示例来源:origin: stackoverflow.com

Connection.Response res = Jsoup.connect("http://www.example.com/login.php")
  .data("username", "myUsername", "password", "myPassword")
  .method(Method.POST)
  .execute();

Document doc = res.parse();
String sessionId = res.cookie("SESSIONID"); // you will need to check what the right cookie name is

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

/**
 * Writes the string content directly to the response.
 * <p>This method commits the response.</p>
 *
 * @param content
 */
public void send(CharSequence content) {
  checkCommitted();
  commit(content);
}

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

@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: gitblit/fathom

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

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

errorHandler.handle(HttpServletResponse.SC_NOT_FOUND, routeContext);
  ROUTE_CONTEXT_THREAD_LOCAL.remove();
  log.debug("Returned status code {} for {} '{}' (IGNORED)", response.getStatus(), requestMethod, requestPath);
  if (!response.isCommitted()) {
    if (response.getStatus() == 0) {
      log.debug("Status code not set for {} '{}'", requestMethod, requestPath);
      response.notFound();
    if (response.getStatus() >= HttpServletResponse.SC_BAD_REQUEST) {
      errorHandler.handle(response.getStatus(), routeContext);
    } else {
      response.commit();
} finally {
  routeContext.runFinallyRoutes();
  log.debug("Returned status code {} for {} '{}'", response.getStatus(), requestMethod, requestPath);
  ROUTE_CONTEXT_THREAD_LOCAL.remove();

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

protected void writeObject(Context context, Object result) {
    try {
      context.getResponse()
        .contentType(CONTENT_TYPE)
        .header(CLASS_NAME, result == null ? NULL : result.getClass().getName());

      if (result != null) {
        ObjectOutputStream replyStream = new ObjectOutputStream(context.getResponse().getOutputStream());
        replyStream.writeObject(result);
        replyStream.flush();
      }
    } catch (IOException e) {
    }
  }
}

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

public PrintWriter getWriter() {
  checkCommitted();
  finalizeResponse();
  if (getContentType() == null) {
    contentType(HttpConstants.ContentType.TEXT_HTML);
  }
  try {
    return httpServletResponse.getWriter();
  } catch (IOException 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

@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: 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: 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

@Override
public void handle(RouteContext routeContext) {
  Map<String, String> settingsMap = settingsToMap(routeContext.getSettings());
  Response response = routeContext.getResponse().noCache().text();
  try (BufferedWriter writer = new BufferedWriter(response.getWriter())) {
    writeSettings(settingsMap, writer);
    writer.flush();
  } catch (IOException e) {
    log.error(e.getMessage(), e);
  }
}

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

private void commit(CharSequence content) {
  checkCommitted();
  finalizeResponse();
  // content type to TEXT_HTML if it's not set
  if (getContentType() == null) {
    contentType(HttpConstants.ContentType.TEXT_HTML);
  }
  try {
    if (content != null) {
      contentLength(content.toString().getBytes().length);
      httpServletResponse.getWriter().append(content);
    }
    log.trace("Response committed");
    if (chunked) {
      httpServletResponse.flushBuffer();
    }
    finishGZip();
  } catch (IOException e) {
    throw new PippoRuntimeException(e);
  }
}

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

String contentType = routeContext.getResponse().getContentType();
    contentType = routeContext.getResponse().getContentType();
    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: pippo-java/pippo

@Override
public void handle(RouteContext routeContext) {
  routeContext.getResponse().noCache().text().send("pong");
}

相关文章