org.eclipse.jetty.server.Response.getReason()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(156)

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

Response.getReason介绍

暂无

代码示例

代码示例来源:origin: rnewson/couchdb-lucene

public void handle(String target,
          Request baseRequest,
          HttpServletRequest request,
          HttpServletResponse response) throws IOException {
  final String reason = baseRequest.getResponse().getReason();
  try {
    if (reason != null && reason.startsWith("{")) {
      ServletUtils.sendJsonError(request, response, baseRequest.getResponse().getStatus(),
          new JSONObject(reason));
    } else {
      ServletUtils.sendJsonError(request, response, baseRequest.getResponse().getStatus(),
          reason);
    }
  } catch (final JSONException e) {
    response.sendError(500);
  }
}

代码示例来源:origin: apache/jena

@Override
  public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
  {
    String method = request.getMethod();
    if ( !method.equals(HttpMethod.GET.asString())
       && !method.equals(HttpMethod.POST.asString())
       && !method.equals(HttpMethod.HEAD.asString()) )
      return ;
    response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ;
    response.setHeader(HttpNames.hCacheControl, "must-revalidate,no-cache,no-store");
    response.setHeader(HttpNames.hPragma, "no-cache");
    int code = response.getStatus() ;
    String message=(response instanceof Response)?((Response)response).getReason(): HttpSC.getMessage(code) ;
    response.getOutputStream().print(format("Error %d: %s\n", code, message)) ;
  }
}

代码示例来源:origin: org.apache.jena/jena-fuseki-main

@Override
  public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
  {
    String method = request.getMethod();
    if ( !method.equals(HttpMethod.GET.asString())
       && !method.equals(HttpMethod.POST.asString())
       && !method.equals(HttpMethod.HEAD.asString()) )
      return ;
    response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ;
    response.setHeader(HttpNames.hCacheControl, "must-revalidate,no-cache,no-store");
    response.setHeader(HttpNames.hPragma, "no-cache");
    int code = response.getStatus() ;
    String message=(response instanceof Response)?((Response)response).getReason(): HttpSC.getMessage(code) ;
    response.getOutputStream().print(format("Error %d: %s\n", code, message)) ;
  }
}

代码示例来源:origin: apache/jena

@Override
  public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
  {
    String method = request.getMethod();
       if ( !method.equals(HttpMethod.GET.asString())
       && !method.equals(HttpMethod.POST.asString())
       && !method.equals(HttpMethod.HEAD.asString()) )
      return ;
    
    response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ;
    ServletOps.setNoCache(response) ;
    int code = response.getStatus() ;
    String message=(response instanceof Response)?((Response)response).getReason(): HttpSC.getMessage(code) ;
    response.getOutputStream().print(format("Error %d: %s\n", code, message)) ;
  }
}

代码示例来源:origin: org.seaborne.rdf-delta/rdf-delta-fuseki-server

@Override
  public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
  {
    String method = request.getMethod();
    if ( !method.equals(HttpMethod.GET.asString())
       && !method.equals(HttpMethod.POST.asString())
       && !method.equals(HttpMethod.HEAD.asString()) )
      return ;
    response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ;
    response.setHeader(HttpNames.hCacheControl, "must-revalidate,no-cache,no-store");
    response.setHeader(HttpNames.hPragma, "no-cache");
    int code = response.getStatus() ;
    String message=(response instanceof Response)?((Response)response).getReason(): HttpSC.getMessage(code) ;
    response.getOutputStream().print(format("Error %d: %s\n", code, message)) ;
  }
}

代码示例来源:origin: org.apache.jena/jena-fuseki-core

@Override
  public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
  {
    String method = request.getMethod();
       if ( !method.equals(HttpMethod.GET.asString())
       && !method.equals(HttpMethod.POST.asString())
       && !method.equals(HttpMethod.HEAD.asString()) )
      return ;
    
    response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ;
    ServletOps.setNoCache(response) ;
    int code = response.getStatus() ;
    String message=(response instanceof Response)?((Response)response).getReason(): HttpSC.getMessage(code) ;
    response.getOutputStream().print(format("Error %d: %s\n", code, message)) ;
  }
}

代码示例来源:origin: org.apache.jena/jena-fuseki-core

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
{
  String method = request.getMethod();
   if ( !method.equals(HttpMethod.GET.asString())
     && !method.equals(HttpMethod.POST.asString())
     && !method.equals(HttpMethod.HEAD.asString()) )
    return ;
  
  response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ;
  ServletOps.setNoCache(response) ;
  
  ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024) ;
  try ( Writer writer = IO.asUTF8(bytes) ) {
    String reason = (response instanceof Response) ? ((Response)response).getReason() : null;
    handleErrorPage(request, writer, response.getStatus(), reason) ;
    writer.flush();
    response.setContentLength(bytes.size()) ;
    response.getOutputStream().write(bytes.toByteArray()) ;
  }
}

代码示例来源:origin: apache/jena

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
{
  String method = request.getMethod();
   if ( !method.equals(HttpMethod.GET.asString())
     && !method.equals(HttpMethod.POST.asString())
     && !method.equals(HttpMethod.HEAD.asString()) )
    return ;
  
  response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ;
  ServletOps.setNoCache(response) ;
  
  ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024) ;
  try ( Writer writer = IO.asUTF8(bytes) ) {
    String reason = (response instanceof Response) ? ((Response)response).getReason() : null;
    handleErrorPage(request, writer, response.getStatus(), reason) ;
    writer.flush();
    response.setContentLength(bytes.size()) ;
    response.getOutputStream().write(bytes.toByteArray()) ;
  }
}

代码示例来源:origin: org.leapframework/leap-webunit

@Override
  public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
    String method = request.getMethod();
    if (!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method))
    {
      baseRequest.setHandled(true);
      return;
    }
    
    baseRequest.setHandled(true);
    response.setContentType(MimeTypes.Type.TEXT_HTML_UTF_8.asString());    
    response.setHeader(HttpHeader.CACHE_CONTROL.asString(), "must-revalidate,no-cache,no-store");
    
    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    OutputStreamWriter writer = new OutputStreamWriter(out, Charsets.UTF_8);
    String reason=(response instanceof Response)?((Response)response).getReason():null;
    handleErrorPage(request, writer, response.getStatus(), reason);
    writer.flush();
    response.setContentLength(out.size());
    response.getOutputStream().write(out.toByteArray(), 0, out.size());
    writer.close();
  }
}

代码示例来源:origin: org.eclipse.jetty/server

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
{
  AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
  connection.getRequest().setHandled(true);
  String method = request.getMethod();
  if(!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(HttpMethods.HEAD))
    return;
  response.setContentType(MimeTypes.TEXT_HTML_8859_1);    
  if (_cacheControl!=null)
    response.setHeader(HttpHeaders.CACHE_CONTROL, _cacheControl);
  ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
  handleErrorPage(request, writer, connection.getResponse().getStatus(), connection.getResponse().getReason());
  writer.flush();
  response.setContentLength(writer.size());
  writer.writeTo(response.getOutputStream());
  writer.destroy();
}

代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
{
  baseRequest.setHandled(true);
  String method = request.getMethod();
  if(!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method))
    return;
  response.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.asString());
  if (_cacheControl!=null)
    response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl);
  ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
  String reason=(response instanceof Response)?((Response)response).getReason():null;
  handleErrorPage(request, writer, response.getStatus(), reason);
  writer.flush();
  response.setContentLength(writer.size());
  writer.writeTo(response.getOutputStream());
  writer.destroy();
}

代码示例来源:origin: bozaro/git-as-svn

public WebServer(@NotNull SharedContext context, @Nullable Server server, @NotNull WebServerConfig config, @NotNull EncryptionFactory tokenFactory) {
 this.context = context;
 this.server = server;
 this.config = config;
 this.tokenFactory = tokenFactory;
 if (server != null) {
  final ServletContextHandler contextHandler = new ServletContextHandler();
  contextHandler.setContextPath("/");
  handler = contextHandler.getServletHandler();
  final RequestLogHandler logHandler = new RequestLogHandler();
  logHandler.setRequestLog((request, response) -> {
   final User user = (User) request.getAttribute(User.class.getName());
   final String userName = (user == null || user.isAnonymous()) ? "" : user.getUserName();
   log.info("{}:{} - {} - \"{} {}\" {} {}", request.getRemoteHost(), request.getRemotePort(), userName, request.getMethod(), request.getHttpURI(), response.getStatus(), response.getReason());
  });
  final HandlerCollection handlers = new HandlerCollection();
  handlers.addHandler(contextHandler);
  handlers.addHandler(logHandler);
  server.setHandler(handlers);
 } else {
  handler = null;
 }
}

代码示例来源:origin: com.ovea.tajin.server/tajin-server-jetty9

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
{
  baseRequest.setHandled(true);
  String method = request.getMethod();
  if(!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method))
    return;
  response.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.asString());
  if (_cacheControl!=null)
    response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl);
  ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
  String reason=(response instanceof Response)?((Response)response).getReason():null;
  handleErrorPage(request, writer, response.getStatus(), reason);
  writer.flush();
  response.setContentLength(writer.size());
  writer.writeTo(response.getOutputStream());
  writer.destroy();
}

代码示例来源:origin: theonedev/onedev

protected MetaData.Response newResponseMetaData()
{
  return new MetaData.Response(_channel.getRequest().getHttpVersion(), getStatus(), getReason(), _fields, getLongContentLength());
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.jetty.server

protected MetaData.Response newResponseMetaData()
{
  return new MetaData.Response(_channel.getRequest().getHttpVersion(), getStatus(), getReason(), _fields, getLongContentLength());
}

代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9

protected ResponseInfo newResponseInfo()
{
  if (_status == HttpStatus.NOT_SET_000)
    _status = HttpStatus.OK_200;
  return new ResponseInfo(_channel.getRequest().getHttpVersion(), _fields, getLongContentLength(), getStatus(), getReason(), _channel.getRequest().isHead());
}

代码示例来源:origin: jenkinsci/winstone

protected MetaData.Response newResponseMetaData()
{
  MetaData.Response info = new MetaData.Response(_channel.getRequest().getHttpVersion(), getStatus(), getReason(), _fields, getLongContentLength());
  info.setTrailerSupplier(getTrailers());
  return info;
}

代码示例来源:origin: com.ovea.tajin.server/tajin-server-jetty9

protected ResponseInfo newResponseInfo()
{
  if (_status == HttpStatus.NOT_SET_000)
    _status = HttpStatus.OK_200;
  return new ResponseInfo(_channel.getRequest().getHttpVersion(), _fields, getLongContentLength(), getStatus(), getReason(), _channel.getRequest().isHead());
}

代码示例来源:origin: Nextdoor/bender

protected ResponseInfo newResponseInfo()
{
  return new ResponseInfo(_channel.getRequest().getHttpVersion(), _fields, getLongContentLength(), getStatus(), getReason(), _channel.getRequest().isHead());
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.jetty.server

public void handle(HttpChannel connection) throws IOException, ServletException
{
  final String target=connection.getRequest().getPathInfo();
  final Request request=connection.getRequest();
  final Response response=connection.getResponse();
  if (LOG.isDebugEnabled())
    LOG.debug("{} on {}{}{} {} {}{}{}", request.getDispatcherType(), connection, System.lineSeparator(),
        request.getMethod(), target, request.getProtocol(), System.lineSeparator(), request.getHttpFields());
  if (HttpMethod.OPTIONS.is(request.getMethod()) || "*".equals(target))
  {
    if (!HttpMethod.OPTIONS.is(request.getMethod()))
      response.sendError(HttpStatus.BAD_REQUEST_400);
    handleOptions(request,response);
    if (!request.isHandled())
      handle(target, request, request, response);
  }
  else
    handle(target, request, request, response);
  if (LOG.isDebugEnabled())
    LOG.debug("RESPONSE for {} h={}{}{} {}{}{}", target, request.isHandled(), System.lineSeparator(),
        response.getStatus(), response.getReason(), System.lineSeparator(), response.getHttpFields());
}

相关文章