Class HTTPConnection

  • All Implemented Interfaces:
    ClientInfo

    public final class HTTPConnection
    extends Object
    implements ClientInfo
    Single HTTP connection.
    Author:
    BaseX Team 2005-23, BSD License, Christian Gruen
    • Field Detail

      • request

        public final javax.servlet.http.HttpServletRequest request
        HTTP servlet request.
      • response

        public final javax.servlet.http.HttpServletResponse response
        HTTP servlet response.
      • context

        public final Context context
        Current database context.
      • requestCtx

        public final RequestContext requestCtx
        Request parameters.
      • method

        public String method
        Request method.
    • Method Detail

      • mediaType

        public MediaType mediaType()
        Returns the content type of a request as media type.
        Returns:
        content type
      • initResponse

        public void initResponse()
        Initializes the output and assigns the content type.
      • path

        public String path()
        Returns the URL path. The path always starts with a slash.
        Returns:
        path
      • dbpath

        public String dbpath()
        Returns the database path (i.e., all path entries except for the first).
        Returns:
        database path
      • db

        public String db()
        Returns the addressed database (i.e., the first path entry).
        Returns:
        database, or null if the root directory was specified
      • accepts

        public ArrayList<MediaType> accepts()
        Returns all accepted media types.
        Returns:
        accepted media types
      • error

        public void error​(int code,
                          String info)
                   throws IOException
        Handles an error with an info message.
        Parameters:
        code - status code
        info - info, will additionally be logged
        Throws:
        IOException - I/O exception
      • sopts

        public void sopts​(SerializerOptions opts)
        Assigns serialization parameters.
        Parameters:
        opts - serialization parameters
      • sopts

        public SerializerOptions sopts()
        Returns the serialization parameters.
        Returns:
        serialization parameters
      • log

        public void log​(int status,
                        String info)
        Writes a log message.
        Parameters:
        status - HTTP status code
        info - info string (can be null)
      • resolve

        public String resolve​(String location)
        Normalizes a redirection location. Prefixes absolute locations with the request URI.
        Parameters:
        location - location
        Returns:
        normalized representation
      • redirect

        public void redirect​(String location)
                      throws IOException
        Sends a redirect.
        Parameters:
        location - location
        Throws:
        IOException - I/O exception
      • forward

        public void forward​(String location)
                     throws IOException,
                            javax.servlet.ServletException
        Sends a forward.
        Parameters:
        location - location
        Throws:
        IOException - I/O exception
        javax.servlet.ServletException - servlet exception
      • status

        public void status​(int code,
                           String message,
                           String body)
                    throws IOException
        Sets a status and sends an info message.
        Parameters:
        code - status code
        message - status message (can be null)
        body - message for response body (can be null)
        Throws:
        IOException - I/O exception
      • timing

        public void timing​(QueryInfo qi)
        Sets profiling information.
        Parameters:
        qi - query info
      • mediaType

        public static MediaType mediaType​(SerializerOptions sopts)
        Returns the media type defined in the specified serialization parameters.
        Parameters:
        sopts - serialization parameters
        Returns:
        media type
      • mediaType

        public static MediaType mediaType​(javax.servlet.http.HttpServletRequest request)
        Returns the content type of a request as media type.
        Parameters:
        request - servlet request
        Returns:
        content type
      • remoteAddress

        public static String remoteAddress​(javax.servlet.http.HttpServletRequest request)
        Returns the content type of a request, or an empty string.
        Parameters:
        request - servlet request
        Returns:
        content type