Class UriContext

java.lang.Object
org.apache.juneau.UriContext

@Bean public class UriContext extends Object
Represents a URL broken into authority/context-root/servlet-path/path-info parts.

A typical request against a URL takes the following form:

http://host:port/context-root/servlet-path/path-info | authority | context | resource | path | +--------------------------------------------------+

This class allows you to convert URL strings to absolute (e.g. "http://host:port/foo/bar") or root-relative (e.g. "/foo/bar") URLs.

See Also:
  • Field Details

  • Constructor Details

    • UriContext

      @Beanc public UriContext(@Name("authority") String authority, @Name("contextRoot") String contextRoot, @Name("servletPath") String servletPath, @Name("pathInfo") String pathInfo)
      Constructor.

      Leading and trailing slashes are trimmed of all parameters.

      Any parameter can be null. Blanks and nulls are equivalent.

      Parameters:
      authority - The authority portion of URL (e.g. "http://hostname:port")
      contextRoot - The context root of the application (e.g. "/context-root", or "context-root")
      servletPath - The servlet path (e.g. "/servlet-path", or "servlet-path")
      pathInfo - The path info (e.g. "/path-info", or "path-info")
    • UriContext

      public UriContext()
      Default constructor.

      All null values.

    • UriContext

      public UriContext(String s) throws ParseException
      String constructor.

      Input string is a JSON object with the following format: {authority:'xxx',contextRoot:'xxx',servletPath:'xxx',pathInfo:'xxx'}

      Parameters:
      s - The input string.
      Example: {authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'}
      Throws:
      ParseException - If input string is not a valid JSON object.
  • Method Details

    • of

      public static UriContext of(String authority, String contextRoot, String servletPath, String pathInfo)
      Static creator.
      Parameters:
      authority - The authority portion of URL (e.g. "http://hostname:port")
      contextRoot - The context root of the application (e.g. "/context-root", or "context-root")
      servletPath - The servlet path (e.g. "/servlet-path", or "servlet-path")
      pathInfo - The path info (e.g. "/path-info", or "path-info")
      Returns:
      A new UriContext object.
    • of

      public static UriContext of(String s)
      Static creator.
      Parameters:
      s - The input string.
      Example: {authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'}
      Returns:
      A new UriContext object.
    • getAbsoluteAuthority

      Returns the absolute URI of just the authority portion of this URI context.

      Example: "http://hostname:port"

      If the authority is null/empty, returns "/".

      Returns:
      The absolute URI of just the authority portion of this URI context. Never null.
    • getAbsoluteContextRoot

      Returns the absolute URI of the context-root portion of this URI context.

      Example: "http://hostname:port/context-root"

      Returns:
      The absolute URI of the context-root portion of this URI context. Never null.
    • getRootRelativeContextRoot

      Returns the root-relative URI of the context portion of this URI context.

      Example: "/context-root"

      Returns:
      The root-relative URI of the context portion of this URI context. Never null.
    • getAbsoluteServletPath

      Returns the absolute URI of the resource portion of this URI context.

      Example: "http://hostname:port/context-root/servlet-path"

      Returns:
      The absolute URI of the resource portion of this URI context. Never null.
    • getRootRelativeServletPath

      Returns the root-relative URI of the resource portion of this URI context.

      Example: "/context-root/servlet-path"

      Returns:
      The root-relative URI of the resource portion of this URI context. Never null.
    • getAbsoluteServletPathParent

      Returns the parent of the URL returned by getAbsoluteServletPath().
      Returns:
      The parent of the URL returned by getAbsoluteServletPath().
    • getRootRelativeServletPathParent

      Returns the parent of the URL returned by getRootRelativeServletPath().
      Returns:
      The parent of the URL returned by getRootRelativeServletPath().
    • getAbsolutePathInfo

      Returns the absolute URI of the path portion of this URI context.

      Example: "http://hostname:port/context-root/servlet-path/path-info"

      Returns:
      The absolute URI of the path portion of this URI context. Never null.
    • getRootRelativePathInfo

      Returns the root-relative URI of the path portion of this URI context.

      Example: "/context-root/servlet-path/path-info"

      Returns:
      The root-relative URI of the path portion of this URI context. Never null.
    • getAbsolutePathInfoParent

      Returns the parent of the URL returned by getAbsolutePathInfo().
      Returns:
      The parent of the URL returned by getAbsolutePathInfo().
    • getRootRelativePathInfoParent

      Returns the parent of the URL returned by getRootRelativePathInfo().
      Returns:
      The parent of the URL returned by getRootRelativePathInfo().
    • toString

      public String toString()
      Overrides:
      toString in class Object