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

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

本文整理了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

  1. @Override
  2. public String getRootURL() {
  3. return request.getRootURL().toString();
  4. }
  5. }

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

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

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

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

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

  1. public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  2. {
  3. if (_newContextURL==null)
  4. return;
  5. String path=_newContextURL;
  6. if (!_discardPathInfo && request.getPathInfo()!=null)
  7. path=URIUtil.addPaths(path, request.getPathInfo());
  8. StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  9. location.append(path);
  10. if (!_discardQuery && request.getQueryString()!=null)
  11. {
  12. location.append('?');
  13. String q=request.getQueryString();
  14. q=q.replaceAll("\r\n?&=","!");
  15. location.append(q);
  16. }
  17. response.setHeader(HttpHeaders.LOCATION,location.toString());
  18. if (_expires!=null)
  19. response.setHeader(HttpHeaders.EXPIRES,_expires);
  20. response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  21. response.setContentLength(0);
  22. baseRequest.setHandled(true);
  23. }

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

  1. public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  2. {
  3. if (_newContextURL==null)
  4. return;
  5. String path=_newContextURL;
  6. if (!_discardPathInfo && request.getPathInfo()!=null)
  7. path=URIUtil.addPaths(path, request.getPathInfo());
  8. StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  9. location.append(path);
  10. if (!_discardQuery && request.getQueryString()!=null)
  11. {
  12. location.append('?');
  13. String q=request.getQueryString();
  14. q=q.replaceAll("\r\n?&=","!");
  15. location.append(q);
  16. }
  17. response.setHeader(HttpHeaders.LOCATION,location.toString());
  18. if (_expires!=null)
  19. response.setHeader(HttpHeaders.EXPIRES,_expires);
  20. response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  21. response.setContentLength(0);
  22. baseRequest.setHandled(true);
  23. }

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

  1. public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  2. {
  3. if (_newContextURL==null)
  4. return;
  5. String path=_newContextURL;
  6. if (!_discardPathInfo && request.getPathInfo()!=null)
  7. path=URIUtil.addPaths(path, request.getPathInfo());
  8. StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  9. location.append(path);
  10. if (!_discardQuery && request.getQueryString()!=null)
  11. {
  12. location.append('?');
  13. String q=request.getQueryString();
  14. q=q.replaceAll("\r\n?&=","!");
  15. location.append(q);
  16. }
  17. response.setHeader(HttpHeaders.LOCATION,location.toString());
  18. if (_expires!=null)
  19. response.setHeader(HttpHeaders.EXPIRES,_expires);
  20. response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  21. response.setContentLength(0);
  22. baseRequest.setHandled(true);
  23. }

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

  1. public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  2. {
  3. if (_newContextURL==null)
  4. return;
  5. String path=_newContextURL;
  6. if (!_discardPathInfo && request.getPathInfo()!=null)
  7. path=URIUtil.addPaths(path, request.getPathInfo());
  8. StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  9. location.append(path);
  10. if (!_discardQuery && request.getQueryString()!=null)
  11. {
  12. location.append('?');
  13. String q=request.getQueryString();
  14. q=q.replaceAll("\r\n?&=","!");
  15. location.append(q);
  16. }
  17. response.setHeader(HttpHeaders.LOCATION,location.toString());
  18. if (_expires!=null)
  19. response.setHeader(HttpHeaders.EXPIRES,_expires);
  20. response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  21. response.setContentLength(0);
  22. baseRequest.setHandled(true);
  23. }

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

  1. public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  2. {
  3. if (_newContextURL==null)
  4. return;
  5. String path=_newContextURL;
  6. if (!_discardPathInfo && request.getPathInfo()!=null)
  7. path=URIUtil.addPaths(path, request.getPathInfo());
  8. StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  9. location.append(path);
  10. if (!_discardQuery && request.getQueryString()!=null)
  11. {
  12. location.append('?');
  13. String q=request.getQueryString();
  14. q=q.replaceAll("\r\n?&=","!");
  15. location.append(q);
  16. }
  17. response.setHeader(HttpHeaders.LOCATION,location.toString());
  18. if (_expires!=null)
  19. response.setHeader(HttpHeaders.EXPIRES,_expires);
  20. response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  21. response.setContentLength(0);
  22. baseRequest.setHandled(true);
  23. }

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

  1. public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  2. {
  3. if (_newContextURL==null)
  4. return;
  5. String path=_newContextURL;
  6. if (!_discardPathInfo && request.getPathInfo()!=null)
  7. path=URIUtil.addPaths(path, request.getPathInfo());
  8. StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  9. location.append(path);
  10. if (!_discardQuery && request.getQueryString()!=null)
  11. {
  12. location.append('?');
  13. String q=request.getQueryString();
  14. q=q.replaceAll("\r\n?&=","!");
  15. location.append(q);
  16. }
  17. response.setHeader(HttpHeader.LOCATION.asString(),location.toString());
  18. if (_expires!=null)
  19. response.setHeader(HttpHeader.EXPIRES.asString(),_expires);
  20. response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  21. response.setContentLength(0);
  22. baseRequest.setHandled(true);
  23. }

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

  1. public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  2. {
  3. if (_newContextURL==null)
  4. return;
  5. String path=_newContextURL;
  6. if (!_discardPathInfo && request.getPathInfo()!=null)
  7. path=URIUtil.addPaths(path, request.getPathInfo());
  8. StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  9. location.append(path);
  10. if (!_discardQuery && request.getQueryString()!=null)
  11. {
  12. location.append('?');
  13. String q=request.getQueryString();
  14. q=q.replaceAll("\r\n?&=","!");
  15. location.append(q);
  16. }
  17. response.setHeader(HttpHeader.LOCATION.asString(),location.toString());
  18. if (_expires!=null)
  19. response.setHeader(HttpHeader.EXPIRES.asString(),_expires);
  20. response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  21. response.setContentLength(0);
  22. baseRequest.setHandled(true);
  23. }

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

  1. public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  2. {
  3. if (_newContextURL==null)
  4. return;
  5. String path=_newContextURL;
  6. if (!_discardPathInfo && request.getPathInfo()!=null)
  7. path=URIUtil.addPaths(path, request.getPathInfo());
  8. StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  9. location.append(path);
  10. if (!_discardQuery && request.getQueryString()!=null)
  11. {
  12. location.append('?');
  13. String q=request.getQueryString();
  14. q=q.replaceAll("\r\n?&=","!");
  15. location.append(q);
  16. }
  17. response.setHeader(HttpHeader.LOCATION.asString(),location.toString());
  18. if (_expires!=null)
  19. response.setHeader(HttpHeader.EXPIRES.asString(),_expires);
  20. response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  21. response.setContentLength(0);
  22. baseRequest.setHandled(true);
  23. }

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

  1. public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  2. {
  3. if (_newContextURL==null)
  4. return;
  5. String path=_newContextURL;
  6. if (!_discardPathInfo && request.getPathInfo()!=null)
  7. path=URIUtil.addPaths(path, request.getPathInfo());
  8. StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  9. location.append(path);
  10. if (!_discardQuery && request.getQueryString()!=null)
  11. {
  12. location.append('?');
  13. String q=request.getQueryString();
  14. q=q.replaceAll("\r\n?&=","!");
  15. location.append(q);
  16. }
  17. response.setHeader(HttpHeader.LOCATION.asString(),location.toString());
  18. if (_expires!=null)
  19. response.setHeader(HttpHeader.EXPIRES.asString(),_expires);
  20. response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  21. response.setContentLength(0);
  22. baseRequest.setHandled(true);
  23. }

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

  1. @Override
  2. public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  3. {
  4. if (_newContextURL==null)
  5. return;
  6. String path=_newContextURL;
  7. if (!_discardPathInfo && request.getPathInfo()!=null)
  8. path=URIUtil.addPaths(path, request.getPathInfo());
  9. StringBuilder location = URIUtil.hasScheme(path)?new StringBuilder():baseRequest.getRootURL();
  10. location.append(path);
  11. if (!_discardQuery && request.getQueryString()!=null)
  12. {
  13. location.append('?');
  14. String q=request.getQueryString();
  15. q=q.replaceAll("\r\n?&=","!");
  16. location.append(q);
  17. }
  18. response.setHeader(HttpHeader.LOCATION.asString(),location.toString());
  19. if (_expires!=null)
  20. response.setHeader(HttpHeader.EXPIRES.asString(),_expires);
  21. response.setStatus(_permanent?HttpServletResponse.SC_MOVED_PERMANENTLY:HttpServletResponse.SC_FOUND);
  22. response.setContentLength(0);
  23. baseRequest.setHandled(true);
  24. }

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

  1. @Override
  2. protected String filterResponseHeaderValue(String headerName, String headerValue, HttpServletRequest request)
  3. {
  4. if (_proxyPassReverse && REVERSE_PROXY_HEADERS.contains(headerName))
  5. {
  6. HttpURI locationURI = new HttpURI(headerValue);
  7. if (isAbsoluteLocation(locationURI) && isBackendLocation(locationURI))
  8. {
  9. Request jettyRequest = (Request)request;
  10. URI reverseUri;
  11. try
  12. {
  13. reverseUri = new URI(jettyRequest.getRootURL().append(locationURI.getCompletePath()).toString()).normalize();
  14. return reverseUri.toURL().toString();
  15. }
  16. catch (Exception e)
  17. {
  18. _log.warn("Not filtering header response",e);
  19. return headerValue;
  20. }
  21. }
  22. }
  23. return headerValue;
  24. }

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

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

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

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

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

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

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

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

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

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

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

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

相关文章

Request类方法