JavaXT
|
|||||||||||||||||||||||
ServiceRequest ClassUsed to encapsulate an HttpServletRequest and simplify the parsing/extracting of parameters from the raw HTTP request.
ConstructorsPublic MethodsgetService( ) returns String Returns the service name from the http request. Service requests follow the convention: "http://localhost/servlet/service/path". For example "http://localhost/myapp/admin/user". In this example, the servlet path is "myapp" and the service name is "admin". Note that the servlet path is optional and may include multiple "directories". This method makes it easier to find the service name from the url. getMethod( ) returns String Returns a method name for the HTTP request. Examples:
If the URL contains a "servlet" path or a "service" path, will return the first object in the path after the servlet and/or service. Consider this example: "http://localhost/myapp/admin/user" In this example, the servlet path is "myapp" and the service path is "admin" and and so the method name is derived from "user". Note that this method is used by the WebService class to map service requests to REST service endpoints and execute CRUD operations.setReadOnly( boolean readOnly ) returns void Used to disable insert, update, and delete operations. "POST", "PUT", and "DELETE" requests are remapped to "GET". See getMethod() for more information on how requests are mapped. isReadOnly( ) returns boolean Returns true if insert, update, and delete operations have been disabled. See setReadOnly() for more information. Default is false. getPath( int i ) returns javaxt.utils.Value Returns a part of the url path at a given index AFTER the service name. For example, index 0 for "http://localhost/servlet/service/a/b/c" would yield "a". getPath( ) returns String Returns a part of the url path AFTER the service name. For example, "http://localhost/servlet/service/a/b/c" would yield "/a/b/c". setPath( String path ) returns void Used to update the path of the current URL. This method can be used to coerce a request to route to different web methods (see getMethod).
getID( ) returns Long Returns the ID associated with the request. Assuming the service request follows the convention "http://localhost/servlet/service/object", the ID for the "http://localhost/photos/config/user/54" is 54. If an ID is not found in the path or is invalid, then the id parameter in the query string is returned. Example: "http://localhost/photos/config/user?id=54" getParameter( String key ) returns javaxt.utils.Value Returns the value associated with a parameter in the request. Performs a case insensitive search for the keyword in the query string. In addition, will search the JSON payload of the request if parseJson is set to true. If the value is an empty string or "null" then a null value is returned.
hasParameter( String key ) returns boolean Returns true if the request contains a given parameter in the request. Performs a case insensitive search for the keyword in the query string. In addition, will search the JSON payload of the request if parseJson is set to true. setParameter( String key, String val ) returns void Used to update a parameter extracted from the original request. Performs a case insensitive search for the keyword in the query string. getParameterNames( ) returns String[] Returns a list of all the parameter keywords found in this request. getOffset( ) returns Long Returns the value of the "offset" parameter in the request as a number. This parameter is used by the WebService class to paginate through list requests. getLimit( ) returns Long Returns the value of the "limit" parameter in the request as a number. This parameter is used by the WebService class to paginate through list requests. getRequest( ) returns HttpServletRequest Returns the original, unmodified HTTP request used to instantiate this class. setPayload( byte[] payload ) returns void Used to update the raw bytes representing the payload of the request parseJson( ) returns void Calling this method will expand parameter searches into the payload of the request. See getParameter() for more info. getCredentials( ) returns String[] Returns the credentials associated with an HTTP request. The credentials will vary based on the security authentication scheme used to authenticate clients (e.g. "BASIC", "DIGEST", "NTLM", etc). In the case of "BASIC" authentication, the credentials typically include a username and password. In the case of "NTLM" authentication, the credentials may only contain a username. What is actually returned is up to the javaxt.http.servlet.Authenticator used to authenticate the request. authenticate( ) returns void Used to authenticate a client request. Authentication is performed by a javaxt.http.servlet.Authenticator. If no Authenticator is defined or if the Authenticator fails to authenticate the client, this method throws a ServletException. isCacheable( String eTag, String date ) returns boolean Returns true if a given eTag matches the "if-none-match" request header. Additional checks are performed against other cache related headers (e.g. "cache-control" and "if-modified-since"). If true is returned, the corresponding HTTP response can be set to a 304 "Not Modified".
getFields( ) returns Field[] Returns an array of ServiceRequest.Fields by parsing the "fields" parameter in the HTTP request (e.g. "?fields=id,firstName,lastName"). getFields( String fields ) returns Field[] Used to parse a given String into an array of Fields.
getFilter( ) returns Filter Returns a ServiceRequest.Filter by parsing the query string associated this request. Examples:
getWhere( ) returns String Returns the value for the "where" parameter in the HTTP request. getSort( ) returns Sort Returns an order by statement found in the request (e.g. "orderby" query string). The order by statement may be given as a comma delimited list of fields with optional sort direction for each field. Alternatively, the order by statement can be specified as a JSON array with a "property" and "direction" for each entry in the array. The order by statement is encapsulated as an instance of the Sort class. getKeywords( ) returns HashSet<String> Returns a copy of all the keywords used to identify parameters (e.g. "fields", "orderby", "offset", "limit", etc) setKeyword( String keyword, String type ) returns void Used to add or update an entry in the keyword map. For example, the default keyword used to identify fields in the getFields() method is "fields" and the default keyword used to identify sorting in getSort() if "orderby". This method provides a mechanism for overridding these defaults. For example, suppose in your application you wish to use "columns" instead of "fields" for the getFields() method. You would set the keyword to "columns" and type to "fields".
getKeyword( String type ) returns String Returns a keyword for a given type (see setKeyword for more information) getSelectStatement( String tableName ) returns String Returns a SQL "select" statement for the current request. Compiles the select statement using an array of Fields returned by the getFields() method. Prepends a table name to each field, if given. If no fields are found in the request, a "select *" statement is returned. Otherwise, a select statement is returned, starting with "select ".
getSelectStatement( Class... model ) returns String Returns a SQL "select" statement for the current request. Compiles the "select" statement using using an array of Fields returned by the getFields() method. Prepends a table name to each field by mapping fields to models.
getWhereStatement( Class... c ) returns String Returns a SQL "where" statement for the current request. Compiles the "where" statement using Filter class returned by the getFilter() method. If the Filter is empty, will use raw value for the "where" parameter returned by the getWhere() method instead. Returns an empty string if the Filter is empty and the "where" parameter is not defined. Otherwise, a where statement is returned, starting with a white space " " for convenience.
getOrderByStatement( ) returns String Returns a SQL order by statement for the current request. Compiles the order by statement using Sort class returned by the getSort() method. Returns an empty string if a sort was not defined. Otherwise, the order by statement returned, starting with a white space " " for convenience. getOffsetLimitStatement( javaxt.sql.Driver driver ) returns String Returns a SQL offset and limit statement for the current request. These statements are used for pagination. Note that different database vendors use different keywords to specify offset and limit. The given Driver is used to determine which keywords to use. Returns an empty string if limit and is offset are not defined. Otherwise, the limit and/or offset statement is returned, starting with a white space " " for convenience.
Public Classes |