mn8 Language Reference | Index    

ServletRequest

SUMMARY: NO ATTRIBUTES  NO ELEMENTS  NO CONSTRUCTORS  NO OPERATORS  METHODS SUMMARYDETAIL: NO ATTRIBUTES  NO ELEMENTS  NO CONSTRUCTORS  NO OPERATORS  METHOD DETAILS

Description

Defines an concept to provide client request information to a MN8 concept or script. The servlet container creates a ServletRequest concept and passes it as an argument to the concept's/script's main method as the first parameter.

Usage

Version: 0.1
Authors:Remus Pereni (http://neuro.nolimits.ro)
Location:
Inherits: Concept

Method List

StringgetAuthType
StringgetCharacterEncoding
IntegergetContentLength
StringgetContentType
StringgetContextPath
MapgetHeaders
SeriesgetLocales
StringgetMethod
StringgetMimeType (String $file)
MapgetParameters
StringgetPathInfo
StringgetPathTranslated
StringgetProtocol
StringgetQueryString
StringgetRealPath (String $path)
StringgetRemoteAddr
StringgetRemoteHost
StringgetRemoteUser
StringgetRequestURI
StringgetRequestedSessionId
StringgetResourceURL (String $path)
StringgetScheme
StringgetServerName
IntegergetServerPort
StringgetServletPath
ServletSessiongetSession (Logical $create)
ServletSessiongetSession
StringgetUserPrincipalName
LogicalisRequestedSessionIdFromCookie
LogicalisRequestedSessionIdFromURL
LogicalisRequestedSessionIdValid
LogicalisSecure
LogicalisUserInRole (String $role)
top
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI

Detailed Method Info

getAuthType
Returns: String

Returns the name of the authentication scheme used to protect the servlet, for example, "BASIC" or "SSL," or "" if the servlet was not protected.

Same as the value of the CGI variable AUTH_TYPE.

        $request  #the servlet request
        print $request.getAuthType
        -- the result is --
        BASIC
        

top
getCharacterEncoding
Returns: String

Returns the name of the character encoding used in the body of this request. This method returns "" if the request does not specify a character encoding.

        $request  #the servlet request
        print $request.getCharacterEncoding
        -- the result is --
        
        

top
getContentLength
Returns: Integer

Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known. For HTTP servlets, same as the value of the CGI variable CONTENT_LENGTH.

        $request  #the servlet request
        print $request.getContentLength
        -- the result is --
        -1
        

top
getContentType
Returns: String

Returns the MIME type of the body of the request, or "" if the type is not known. For HTTP servlets, same as the value of the CGI variable CONTENT_TYPE.

        $request  #the servlet request
        print $request.getContentType
        -- the result is --
        
        

top
getContextPath
Returns: String

Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "".

        $request  #the servlet request
        print $request.getContextPath
        -- the result is --
        
        

top
getHeaders
Returns: Map

Returns the request headers as a Map.

        $request  #the servlet request
        print $request.getContextPath
        -- the result is --
        Host server:8080
        User-Agent Mozilla/5.0 Galeon/1.2.0 (X11; Linux i686; U;) Gecko/20020516
        Accept  text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,
        image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1
        Accept-Language en
        Accept-Encoding gzip, deflate, compress;q=0.9
        Accept-Charset ISO-8859-1, utf-8;q=0.66, *;q=0.66
        Keep-Alive 300
        Connection keep-alive
        Referer http://server:8080/mn8/
        

top
getLocales
Returns: Series

Returns an Series of Locale instances indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns an Series containing one Locale, the default locale for the server.

        $request  #the servlet request
        $locale = $request.getLocales
        print "Prefered Languages: " + $locale.getDisplayName
        -- the result is --
        Prefered Languages: English
        

top
getMethod
Returns: String

Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. Same as the value of the CGI variable REQUEST_METHOD.

        $request  #the servlet request
        print "Method: " + $request.getMethod
        -- the result is --
        Method: GET
        

top
getMimeType (String $file)
Parameters:
$file :a String specifying the name of a file.
Returns: String

Returns the MIME type of the specified file, or "" if the MIME type is not known. The MIME type is determined by the configuration of the servlet container, and may be specified in a web application deployment descriptor. Common MIME types are "text/html" and "image/gif".

        $request  #the servlet request
        print "MIME type: " + $request.getMimeType("index.html")
        -- the result is --
        MIME type: text/html
        

top
getParameters
Returns: Map

Returns the value of the request parameters as a Map, or an empty Map if the parameters does not exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

        $request  #the servlet request
        print $request.getParameters
        -- the result is --
        
        

top
getPathInfo
Returns: String

Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string. This method returns "" if there was no extra path information.

Same as the value of the CGI variable PATH_INFO.

        $request  #the servlet request
        print "Path Info: " + $request.getPathInfo
        -- the result is --
        Path Info: /ServletTest.mn8
        

top
getPathTranslated
Returns: String

Returns any extra path information after the servlet name but before the query string, and translates it to a real path. Same as the value of the CGI variable PATH_TRANSLATED.

If the URL does not have any extra path information, this method returns "".

        $request  #the servlet request
        print "Path Translated: " + $request.getPathTranslated
        -- the result is --
        Path Translated: /var/tomcat3/webapps/mn8/ServletTest.mn8
        

top
getProtocol
Returns: String

Returns the name and version of the protocol the request uses in the form protocol/ majorVersion.minorVersion, for example, HTTP/1.1. For HTTP servlets, the value returned is the same as the value of the CGI variable SERVER_PROTOCOL.

        $request  #the servlet request
        print $request.getProtocol
        -- the result is --
        HTTP/1.1
        

top
getQueryString
Returns: String

Returns the query string that is contained in the request URL after the path. This method returns "" if the URL does not have a query string. Same as the value of the CGI variable QUERY_STRING.

        $request  #the servlet request
        print $request.getQueryString
        -- the result is --
        
        

top
getRealPath (String $path)
Parameters:
$path :a String specifying a virtual path.
Returns: String

Returns a String containing the real path for a given virtual path. For example, the virtual path "/ index.html" has a real path of whatever file on the server's filesystem would be served by a request for "/ index.html".

The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators. This method returns "" if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive).

        $request  #the servlet request
        print $request.getRealPath("/ServletTest.mn8")
        -- the result is --
        /var/tomcat3/webapps/mn8/ServletTest.mn8
        

top
getRemoteAddr
Returns: String

Returns the Internet Protocol (IP) address of the client that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR.

        $request  #the servlet request
        print "Remote Address: " + $request.getRemoteAddr
        -- the result is --
        Remote Address: 192.168.1.211
        

top
getRemoteHost
Returns: String

Returns the fully qualified name of the client that sent the request, or the IP address of the client if the name cannot be determined. For HTTP servlets, same as the value of the CGI variable REMOTE_HOST.

        $request  #the servlet request
        print "Remote Host: " + $request.getRemoteHost
        -- the result is --
        Remote Host: 192.168.1.211
        

top
getRemoteUser
Returns: String

Returns the login of the user making this request, if the user has been authenticated, or "" if the user has not been authenticated. Whether the user name is sent with each subsequent request depends on the browser and type of authentication. Same as the value of the CGI variable REMOTE_USER.

        $request  #the servlet request
        print "Remote User: " + $request.getRemoteUser
        -- the result is --
        Remote User: 
        

top
getRequestURI
Returns: String

Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. For example:

            First line of HTTP request            Returned Value
            POST /some/path.html HTTP/1.1         /some/path.html 
            GET http://foo.bar/a.html HTTP/1.0    http://foo.bar/a.html 
            HEAD /xyz?a=b HTTP/1.1                /xyz
        $request  #the servlet request
        print "Request URI: " + $request.getRequestURI
        -- the result is --
        Request URI: /mn8/ServletTest.mn8
        

top
getRequestedSessionId
Returns: String

Returns the session ID specified by the client. This may not be the same as the ID of the actual session in use. For example, if the request specified an old (expired) session ID and the server has started a new session, this method gets a new session with a new ID. If the request did not specify a session ID, this method returns "".

        $request  #the servlet request
        print "Requested Session ID: " + $request.getRequestedSessionId
        -- the result is --
        Requested Session ID: rypcqm9941
        

top
getResourceURL (String $path)
Parameters:
$path :a String specifying the path to the resource.
Returns: String

Returns a URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.

This method allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a .war file.

        $request  #the servlet request
        print "Resource URL: " + $request.getResourceURL("index.mn8")
        -- the result is --
        Resource URL: file:/var/tomcat3/webapps/mn8/index.mn8
        

top
getScheme
Returns: String

Returns the name of the scheme used to make this request, for example, http, https, or ftp. Different schemes have different rules for constructing URLs, as noted in RFC 1738.

        $request  #the servlet request
        print $request.getScheme
        -- the result is --
        http
        

top
getServerName
Returns: String

Returns the host name of the server that received the request. For HTTP servlets, same as the value of the CGI variable SERVER_NAME.

        $request  #the servlet request
        print "Server Name: " + $request.getServerName
        -- the result is --
        Server Name: server
        

top
getServerPort
Returns: Integer

Returns the port number on which this request was received. For HTTP servlets, same as the value of the CGI variable SERVER_PORT.

        $request  #the servlet request
        print "Server Port: " + $request.getServerPort
        -- the result is --
        Server Port: 8080
        

top
getServletPath
Returns: String

Returns the part of this request's URL that calls the servlet. This includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string. Same as the value of the CGI variable SCRIPT_NAME.

        $request  #the servlet request
        print "Servlet Path: " + $request.getServletPath
        -- the result is --
        Servlet Path: 
        

top
getSession (Logical $create)
Parameters:
$create : true - to create a new session for this request if necessary; false - to return null if there's no current session
Returns: ServletSession

Returns the current Session associated with this request or, if there is no current session and create is true, returns a new session.

If create is false and the request has no valid Session, this method returns null.

To make sure the session is properly maintained, you must call this method before the response is committed.

        $request  #the servlet request
        print $request.getSession(FALSE).getAttributes
        -- the result is --
        Map
        hasPrevious: false
        hasNext: true
        index: 0
        length: 1
        nr 1 
        

top
getSession
Returns: ServletSession

Returns the current session associated with this request, or if the request does not have a session, creates one.

        $request  #the servlet request
        print $request.getSession.getAttributes
        -- the result is --
        Map
        hasPrevious: false
        hasNext: true
        index: 0
        length: 1
        nr 1 
        

top
getUserPrincipalName
Returns: String

Returns a security principal name containing the name of the current authenticated user. If the user has not been authenticated, the method returns "".

        $request  #the servlet request
        print "User Principal Name: " + $request.getUserPrincipalName
        -- the result is --
        User Principal Name: 
        

top
isRequestedSessionIdFromCookie
Returns: Logical

Checks whether the requested session ID came in as a cookie.

        $request  #the servlet request
        print $request.isRequestedSessionIdFromCookie
        -- the result is --
        true
        

top
isRequestedSessionIdFromURL
Returns: Logical

Checks whether the requested session ID came in as part of the request URL.

        $request  #the servlet request
        print $request.isRequestedSessionIdFromURL
        -- the result is --
        false
        

top
isRequestedSessionIdValid
Returns: Logical

Checks whether the requested session ID is still valid.

        $request  #the servlet request
        print $request.isRequestedSessionIdValid
        -- the result is --
        true
        

top
isSecure
Returns: Logical

Returns a logical indicating whether this request was made using a secure channel, such as HTTPS.

        $request  #the servlet request
        print $request.isSecure
        -- the result is --
        false
        

top
isUserInRole (String $role)
Parameters:
$role :a String specifying the name of the role.
Returns: Logical

Returns a logical indicating whether the authenticated user is included in the specified logical "role". Roles and role membership can be defined using deployment descriptors. If the user has not been authenticated, the method returns false.

        $request  #the servlet request
        print $request.isUserInRole("admin")
        -- the result is --
        false
        

top