Package org.basex.http
Class HTTPConnection
- java.lang.Object
-
- org.basex.http.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 Summary
Fields Modifier and Type Field Description ContextcontextCurrent database context.StringmethodRequest method.javax.servlet.http.HttpServletRequestrequestHTTP servlet request.RequestContextrequestCtxRequest parameters.javax.servlet.http.HttpServletResponseresponseHTTP servlet response.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ArrayList<MediaType>accepts()Returns all accepted media types.StringclientAddress()StringclientName()Stringdb()Returns the addressed database (i.e., the first path entry).Stringdbpath()Returns the database path (i.e., all path entries except for the first).voiderror(int code, String info)Handles an error with an info message.voidforward(String location)Sends a forward.voidinitResponse()Initializes the output and assigns the content type.voidlog(int status, String info)Writes a log message.MediaTypemediaType()Returns the content type of a request as media type.static MediaTypemediaType(javax.servlet.http.HttpServletRequest request)Returns the content type of a request as media type.static MediaTypemediaType(SerializerOptions sopts)Returns the media type defined in the specified serialization parameters.Stringpath()Returns the URL path.voidredirect(String location)Sends a redirect.static StringremoteAddress(javax.servlet.http.HttpServletRequest request)Returns the content type of a request, or an empty string.Stringresolve(String location)Normalizes a redirection location.SerializerOptionssopts()Returns the serialization parameters.voidsopts(SerializerOptions opts)Assigns serialization parameters.voidstatus(int code, String message, String body)Sets a status and sends an info message.voidtiming(QueryInfo qi)Sets profiling information.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.basex.server.ClientInfo
clientName
-
-
-
-
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
nullif 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 IOExceptionHandles an error with an info message.- Parameters:
code- status codeinfo- 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 codeinfo- info string (can benull)
-
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 exceptionjavax.servlet.ServletException- servlet exception
-
clientAddress
public String clientAddress()
- Specified by:
clientAddressin interfaceClientInfo
-
clientName
public String clientName()
- Specified by:
clientNamein interfaceClientInfo
-
status
public void status(int code, String message, String body) throws IOExceptionSets a status and sends an info message.- Parameters:
code- status codemessage- status message (can benull)body- message for response body (can benull)- 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
-
-