Class UriContext

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

@Marshalled 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.

  • Field Details

    • DEFAULT

      public static final UriContext DEFAULT
      Default URI context.

      No information about authority, servlet-root, context-root, or path-info is known.

    • authority

      public final String authority
      The URI authority (host and port).
    • contextRoot

      public final String contextRoot
      The context root path (typically the servlet context path).
    • servletPath

      public final String servletPath
      The servlet path.
    • pathInfo

      public final String pathInfo
      The path info portion of the URI.
    • parentPath

      public final String parentPath
      The parent path (path excluding the last segment).
  • Constructor Details

    • 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'}
      Can be null (equivalent to the default context).
      Throws:
      ParseException - If input string is not a valid JSON object.
    • UriContext

      @BeanCtor 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")
  • Method Details

    • 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'}
      Can be null (equivalent to the default context).
      Returns:
      A new UriContext object.
    • 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")
      Can be null (treated the same as blank).
      contextRoot - The context root of the application (e.g. "/context-root", or "context-root")
      Can be null (treated the same as blank).
      servletPath - The servlet path (e.g. "/servlet-path", or "servlet-path")
      Can be null (treated the same as blank).
      pathInfo - The path info (e.g. "/path-info", or "path-info")
      Can be null (treated the same as blank).
      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.
    • 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.
    • getAbsolutePathInfoParent

      Returns the parent of the URL returned by getAbsolutePathInfo().
      Returns:
      The parent of the URL returned by getAbsolutePathInfo().
    • 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.
    • getAbsoluteServletPathParent

      Returns the parent of the URL returned by getAbsoluteServletPath().
      Returns:
      The parent of the URL returned by getAbsoluteServletPath().
    • 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.
    • 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.
    • getRootRelativePathInfoParent

      Returns the parent of the URL returned by getRootRelativePathInfo().
      Returns:
      The parent of the URL returned by getRootRelativePathInfo().
    • 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.
    • getRootRelativeServletPathParent

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

    • toString

      public String toString()
      Overrides:
      toString in class Object