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

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

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

Request.getRootURL介绍

[英]Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and, but it does not include a path.

Because this method returns a StringBuffer, not a string, you can modify the URL easily, for example, to append path and query parameters. This method is useful for creating redirect messages and for reporting errors.
[中]重建客户端用于发出请求的URL。返回的URL包含协议、服务器名称、端口号和,但不包括路径。
由于此方法返回StringBuffer,而不是字符串,因此可以轻松修改URL,例如,添加路径和查询参数。此方法对于创建重定向消息和报告错误非常有用。

代码示例

代码示例来源:origin: gocd/gocd

@Override
  public String getRootURL() {
    return request.getRootURL().toString();
  }
}

代码示例来源:origin: gocd/gocd

@Override
public String getUrl() {
  return request.getRootURL().append(getUriAsString()).toString();
}

代码示例来源:origin: gocd/gocd

@Before
public void setUp() throws Exception {
  initMocks(this);
  jetty9Request = new Jetty9Request(request);
  when(request.getHttpURI()).thenReturn(new HttpURI("foo/bar/baz"));
  when(request.getRootURL()).thenReturn(new StringBuilder("http://junk/"));
}

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

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
  if (_newContextURL==null)
    return;
  String path=_newContextURL;
  if (!_discardPathInfo && request.getPathInfo()!=null)
    path=URIUtil.addPaths(path, request.getPathInfo());
  
  StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  location.append(path);
  if (!_discardQuery && request.getQueryString()!=null)
  {
    location.append('?');
    String q=request.getQueryString();
    q=q.replaceAll("\r\n?&=","!");
    location.append(q);
  }
  
  response.setHeader(HttpHeaders.LOCATION,location.toString());
  if (_expires!=null)
    response.setHeader(HttpHeaders.EXPIRES,_expires);
  
  response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  response.setContentLength(0);
  baseRequest.setHandled(true);
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-webapp

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
  if (_newContextURL==null)
    return;
  String path=_newContextURL;
  if (!_discardPathInfo && request.getPathInfo()!=null)
    path=URIUtil.addPaths(path, request.getPathInfo());
  
  StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  location.append(path);
  if (!_discardQuery && request.getQueryString()!=null)
  {
    location.append('?');
    String q=request.getQueryString();
    q=q.replaceAll("\r\n?&=","!");
    location.append(q);
  }
  
  response.setHeader(HttpHeaders.LOCATION,location.toString());
  if (_expires!=null)
    response.setHeader(HttpHeaders.EXPIRES,_expires);
  
  response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  response.setContentLength(0);
  baseRequest.setHandled(true);
}

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-plus

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
  if (_newContextURL==null)
    return;
  String path=_newContextURL;
  if (!_discardPathInfo && request.getPathInfo()!=null)
    path=URIUtil.addPaths(path, request.getPathInfo());
  
  StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  location.append(path);
  if (!_discardQuery && request.getQueryString()!=null)
  {
    location.append('?');
    String q=request.getQueryString();
    q=q.replaceAll("\r\n?&=","!");
    location.append(q);
  }
  
  response.setHeader(HttpHeaders.LOCATION,location.toString());
  if (_expires!=null)
    response.setHeader(HttpHeaders.EXPIRES,_expires);
  
  response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  response.setContentLength(0);
  baseRequest.setHandled(true);
}

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

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
  if (_newContextURL==null)
    return;
  String path=_newContextURL;
  if (!_discardPathInfo && request.getPathInfo()!=null)
    path=URIUtil.addPaths(path, request.getPathInfo());
  
  StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  location.append(path);
  if (!_discardQuery && request.getQueryString()!=null)
  {
    location.append('?');
    String q=request.getQueryString();
    q=q.replaceAll("\r\n?&=","!");
    location.append(q);
  }
  
  response.setHeader(HttpHeaders.LOCATION,location.toString());
  if (_expires!=null)
    response.setHeader(HttpHeaders.EXPIRES,_expires);
  
  response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  response.setContentLength(0);
  baseRequest.setHandled(true);
}

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

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
  if (_newContextURL==null)
    return;
  String path=_newContextURL;
  if (!_discardPathInfo && request.getPathInfo()!=null)
    path=URIUtil.addPaths(path, request.getPathInfo());
  
  StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  location.append(path);
  if (!_discardQuery && request.getQueryString()!=null)
  {
    location.append('?');
    String q=request.getQueryString();
    q=q.replaceAll("\r\n?&=","!");
    location.append(q);
  }
  
  response.setHeader(HttpHeaders.LOCATION,location.toString());
  if (_expires!=null)
    response.setHeader(HttpHeaders.EXPIRES,_expires);
  
  response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  response.setContentLength(0);
  baseRequest.setHandled(true);
}

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

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
  if (_newContextURL==null)
    return;
  String path=_newContextURL;
  if (!_discardPathInfo && request.getPathInfo()!=null)
    path=URIUtil.addPaths(path, request.getPathInfo());
  StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  location.append(path);
  if (!_discardQuery && request.getQueryString()!=null)
  {
    location.append('?');
    String q=request.getQueryString();
    q=q.replaceAll("\r\n?&=","!");
    location.append(q);
  }
  response.setHeader(HttpHeader.LOCATION.asString(),location.toString());
  if (_expires!=null)
    response.setHeader(HttpHeader.EXPIRES.asString(),_expires);
  response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  response.setContentLength(0);
  baseRequest.setHandled(true);
}

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

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
  if (_newContextURL==null)
    return;
  String path=_newContextURL;
  if (!_discardPathInfo && request.getPathInfo()!=null)
    path=URIUtil.addPaths(path, request.getPathInfo());
  StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  location.append(path);
  if (!_discardQuery && request.getQueryString()!=null)
  {
    location.append('?');
    String q=request.getQueryString();
    q=q.replaceAll("\r\n?&=","!");
    location.append(q);
  }
  response.setHeader(HttpHeader.LOCATION.asString(),location.toString());
  if (_expires!=null)
    response.setHeader(HttpHeader.EXPIRES.asString(),_expires);
  response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  response.setContentLength(0);
  baseRequest.setHandled(true);
}

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

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
  if (_newContextURL==null)
    return;
  String path=_newContextURL;
  if (!_discardPathInfo && request.getPathInfo()!=null)
    path=URIUtil.addPaths(path, request.getPathInfo());
  StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  location.append(path);
  if (!_discardQuery && request.getQueryString()!=null)
  {
    location.append('?');
    String q=request.getQueryString();
    q=q.replaceAll("\r\n?&=","!");
    location.append(q);
  }
  response.setHeader(HttpHeader.LOCATION.asString(),location.toString());
  if (_expires!=null)
    response.setHeader(HttpHeader.EXPIRES.asString(),_expires);
  response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  response.setContentLength(0);
  baseRequest.setHandled(true);
}

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

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
  if (_newContextURL==null)
    return;
  String path=_newContextURL;
  if (!_discardPathInfo && request.getPathInfo()!=null)
    path=URIUtil.addPaths(path, request.getPathInfo());
  StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  location.append(path);
  if (!_discardQuery && request.getQueryString()!=null)
  {
    location.append('?');
    String q=request.getQueryString();
    q=q.replaceAll("\r\n?&=","!");
    location.append(q);
  }
  response.setHeader(HttpHeader.LOCATION.asString(),location.toString());
  if (_expires!=null)
    response.setHeader(HttpHeader.EXPIRES.asString(),_expires);
  response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  response.setContentLength(0);
  baseRequest.setHandled(true);
}

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

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
  if (_newContextURL==null)
    return;
  String path=_newContextURL;
  if (!_discardPathInfo && request.getPathInfo()!=null)
    path=URIUtil.addPaths(path, request.getPathInfo());
  StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  location.append(path);
  if (!_discardQuery && request.getQueryString()!=null)
  {
    location.append('?');
    String q=request.getQueryString();
    q=q.replaceAll("\r\n?&=","!");
    location.append(q);
  }
  response.setHeader(HttpHeader.LOCATION.asString(),location.toString());
  if (_expires!=null)
    response.setHeader(HttpHeader.EXPIRES.asString(),_expires);
  response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  response.setContentLength(0);
  baseRequest.setHandled(true);
}

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

@Override
protected String filterResponseHeaderValue(String headerName, String headerValue, HttpServletRequest request)
{
  if (_proxyPassReverse && REVERSE_PROXY_HEADERS.contains(headerName))
  {
    HttpURI locationURI = new HttpURI(headerValue);
    if (isAbsoluteLocation(locationURI) && isBackendLocation(locationURI))
    {
      Request jettyRequest = (Request)request;
      URI reverseUri;
      try
      {
        reverseUri = new URI(jettyRequest.getRootURL().append(locationURI.getCompletePath()).toString()).normalize();
        return reverseUri.toURL().toString();
      }
      catch (Exception e)
      {
        _log.warn("Not filtering header response",e);
        return headerValue;
      }
    }
  }
  return headerValue;
}

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

StringBuilder buf = _connection.getRequest().getRootURL();
if (location.startsWith("/"))

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-webapp

StringBuilder buf = _connection.getRequest().getRootURL();
if (location.startsWith("/"))

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-plus

StringBuilder buf = _connection.getRequest().getRootURL();
if (location.startsWith("/"))

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

StringBuilder buf = _connection.getRequest().getRootURL();
if (location.startsWith("/"))

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

StringBuilder buf = _channel.getRequest().getRootURL();
if (location.startsWith("/"))

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

StringBuilder buf = _channel.getRequest().getRootURL();
if (location.startsWith("/"))

相关文章

微信公众号

最新文章

更多

Request类方法