org.xlightweb
Interface IHttpRequest

Package class diagram package IHttpRequest
All Superinterfaces:
IHeader, IHttpMessage, IPart
All Known Implementing Classes:
DeleteRequest, FormURLEncodedRequest, GetRequest, HeadRequest, HttpRequest, HttpRequestWrapper, MultipartFormDataRequest, MultipartRequest, OptionsRequest, PostRequest, PutRequest

public interface IHttpRequest
extends IHttpMessage

Http Request


Field Summary
 
Fields inherited from interface org.xlightweb.IHttpMessage
CONNECT_METHOD, DEFAULT_ENCODING, DEFAULT_ENCODING_KEY, DELETE_METHOD, GET_METHOD, HEAD_METHOD, OPTIONS_METHOD, POST_METHOD, PUT_METHOD, TRACE_METHOD
 
Method Summary
 void addMatrixParameter(String parameterName, String parameterValue)
          adds a matrix parameter
 void addParameter(String parameterName, String parameterValue)
          adds a parameter
 List<ContentType> getAccept()
          returns the list of the accepted content types, ordered by the quality factory
 Boolean getBooleanParameter(String name)
          Get an Boolean parameter, or null if not present.
 boolean getBooleanParameter(String name, boolean defaultVal)
          Get an boolean parameter, with a fallback value.
 String getContextPath()
          Returns the portion of the request URI that indicates the context of the request.
 Double getDoubleParameter(String name)
          Get an Double parameter, or null if not present.
 double getDoubleParameter(String name, double defaultVal)
          Get an double parameter, with a fallback value.
 Float getFloatParameter(String name)
          Get an Float parameter, or null if not present.
 float getFloatParameter(String name, float defaultVal)
          Get an float parameter, with a fallback value.
 String getHost()
          returns the Host header parameter or null if the header is not set
 Integer getIntParameter(String name)
          Get an Integer parameter, or null if not present.
 int getIntParameter(String name, int defaultVal)
          Get an int parameter, with a fallback value.
 Long getLongParameter(String name)
          Get an Long parameter, or null if not present.
 long getLongParameter(String name, long defaultVal)
          Get an long parameter, with a fallback value.
 String getMatrixParameter(String name)
          Returns the value of a request matrix parameter as a String, or null if the parameter does not exist.
 Set<String> getMatrixParameterNameSet()
          returns the matrix parameter name set
 String[] getMatrixParameterValues(String name)
          Returns an array of String objects containing all of the values the given request matrix parameter has, or null if the parameter does not exist.
 String getMethod()
          Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
 String getParameter(String name)
          Returns the value of a request parameter as a String, or null if the parameter does not exist.
 String getParameter(String name, String defaultVal)
          Get an String parameter, with a fallback value.
 Enumeration getParameterNames()
          Returns an Enumeration of String objects containing the names of the parameters contained in this request.
 Set<String> getParameterNameSet()
          returns the parameter name set
 String[] getParameterValues(String name)
          Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.
 String getPathInfo()
          Returns any extra path information associated with the URL.
 String getPathInfo(boolean removeSurroundingSlashs)
          Returns any extra path information associated with the URL.
 String getQueryString()
          Returns the query string that is contained in the request URL after the path.
 String getRemoteAddr()
          Returns the Internet Protocol (IP) address of the client or last proxy that sent the message.
 String getRemoteHost()
          Returns the fully qualified name of the client or the last proxy that sent the request.
 int getRemotePort()
          Returns the Internet Protocol (IP) source port of the client or last proxy that sent the message.
 String getRequestHandlerPath()
          returns the request handler path.
 IHttpRequestHeader getRequestHeader()
          returns the request header
 String getRequestURI()
          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.
 URL getRequestUrl()
          Reconstructs the URL the client used to make the request.
 boolean getRequiredBooleanParameter(String name)
          Get an boolean parameter or throws an exception if parameter is not present
 double getRequiredDoubleParameter(String name)
          Get an double parameter or throws an exception if parameter is not present
 float getRequiredFloatParameter(String name)
          Get an float parameter or throws an exception if parameter is not present
 int getRequiredIntParameter(String name)
          Get an int parameter or throws an exception if parameter is not present
 long getRequiredLongParameter(String name)
          Get an long parameter or throws an exception if parameter is not present
 String getRequiredStringParameter(String name)
          Get an string parameter or throws an exception if parameter is not present
 String getScheme()
          Returns the name of the scheme used to make this request, for example, http or https.
 String getServerName()
          Returns the host name of the server to which the request was sent.
 int getServerPort()
          Returns the port number to which the request was sent.
 String getUserAgent()
          returns the User-Agent header parameter or null if the header is not set
 boolean isSecure()
          Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
 void removeMatrixParameter(String parameterName)
          removes a matrix parameter
 void removeParameter(String parameterName)
          remove a parameter
 void setContextPath(String contextPath)
          sets the context path.
 void setHost(String host)
          sets the Host header
 void setMatrixParameter(String parameterName, String parameterValue)
          sets a matrix parameter
 void setMethod(String method)
          Sets the name of the HTTP method
 void setParameter(String parameterName, String parameterValue)
          sets a parameter
 void setRequestHandlerPath(String requestHandlerPath)
          sets the request handler path
 void setRequestURI(String requestUri)
          set the request uri part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
 void setRequestUrl(URL url)
          set the request url
 void setUserAgent(String userAgent)
          sets the User-Agent header
 
Methods inherited from interface org.xlightweb.IHttpMessage
getAttribute, getAttributeNames, getAttributeNameSet, getCharacterEncoding, getContentLength, getContentType, getMessageHeader, getProtocol, getProtocolVersion, getTransferEncoding, removeHopByHopHeaders, setAttribute, setContentLength, setContentType, setTransferEncoding
 
Methods inherited from interface org.xlightweb.IPart
getBlockingBody, getBody, getNonBlockingBody, getPartHeader, hasBody
 
Methods inherited from interface org.xlightweb.IHeader
addHeader, addHeaderLine, addHeaderlines, containsHeader, getDisposition, getDispositionParam, getDispositionType, getHeader, getHeaderList, getHeaderNames, getHeaderNameSet, getHeaders, removeHeader, setHeader
 

Method Detail

getRequestHeader

IHttpRequestHeader getRequestHeader()
returns the request header

Returns:
the request header

getRequestHandlerPath

String getRequestHandlerPath()
returns the request handler path. By default this method returns "".

Example:

 class MyHandler implements IHttpRequestHandler {
 
    public void onRequest(IHttpExchange exchange) throws IOException,BadMessageException {
       IHttpRequest req = exchange.getRequest();
       
       StringBuilder sb = new StringBuilder();
       sb.append("path=" + req.getRequestHandlerPath() + "\r\n");
       sb.append("ctx=" + req.getContextPath() + "\r\n");
       sb.append("uri=" + req.getRequestURI() + "\r\n");
       
       exchange.send(new HttpResponse(200, "text/plain", sb.toString()));
    }
 }

 
  ...
  Context ctx = new Context("/ctx/subctx");
  ctx.addHandler("/hdlPath/*", new MyHandler());
  HttpServer server = new HttpServer(ctx);
  server.start();
  
  HttpClient httpClient = new HttpClient();
  IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/ctx/subctx/hdlPath/test?param=value"));
  
  System.out.println(response.getBlockingBody().readString());
  // prints out:
  // >path=/hdlPath
  // >ctx=/ctx/subctx
  // >uri=/ctx/subctx/hdlPath/test

  ...
 
 

Returns:
the request handler path

setRequestHandlerPath

void setRequestHandlerPath(String requestHandlerPath)
sets the request handler path

Parameters:
requestHandlerPath - the request handler path

getContextPath

String getContextPath()
Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. For the default (root) context, this method returns "".

Returns:
the context path
See Also:
getRequestHandlerPath()

setContextPath

void setContextPath(String contextPath)
sets the context path.

Parameters:
contextPath - the context path

setMethod

void setMethod(String method)
Sets the name of the HTTP method

Parameters:
method - a String specifying the name of the method

getMethod

String getMethod()
Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.

Returns:
a String specifying the name of the method

getServerName

String getServerName()
Returns the host name of the server to which the request was sent. It is the value of the part before ":" in the Host header value, if any, or the resolved server name, or the server IP address.

Returns:
the server name

getServerPort

int getServerPort()
Returns the port number to which the request was sent. It is the value of the part after ":" in the Host header value, if any, or the server port where the client connection was accepted on.

Returns:
the server port

getRequestUrl

URL getRequestUrl()
Reconstructs the URL the client used to make the request.

Returns:
the URL

setRequestUrl

void setRequestUrl(URL url)
set the request url

Parameters:
url - the request url

setHost

void setHost(String host)
sets the Host header

Parameters:
host - the Host header

getHost

String getHost()
returns the Host header parameter or null if the header is not set

Returns:
the Host header parameter or null if the header is not set

getUserAgent

String getUserAgent()
returns the User-Agent header parameter or null if the header is not set

Returns:
the User-Agent header parameter or null if the header is not set

setUserAgent

void setUserAgent(String userAgent)
sets the User-Agent header

Parameters:
userAgent - the User-Agent header

getAccept

List<ContentType> getAccept()
returns the list of the accepted content types, ordered by the quality factory

Returns:
the accepted content types

getScheme

String getScheme()
Returns the name of the scheme used to make this request, for example, http or https.

Returns:
a String containing the name of the scheme

getRemoteHost

String getRemoteHost()
Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address.

Returns:
a String containing the fully qualified name of the client

getRemotePort

int getRemotePort()
Returns the Internet Protocol (IP) source port of the client or last proxy that sent the message.

Returns:
an integer specifying the port number

getRemoteAddr

String getRemoteAddr()
Returns the Internet Protocol (IP) address of the client or last proxy that sent the message.

Returns:
a String containing the IP address of the client that sent the request

getRequestURI

String getRequestURI()
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.

Returns:
a String containing the part of the URL from the protocol name up to the query string

setRequestURI

void setRequestURI(String requestUri)
set the request uri part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.

Parameters:
requestUri - the request uri

getPathInfo

String getPathInfo()
Returns any extra path information associated with the URL. The extra path information follows the servlet path but precedes the query string and will start with a "/" character.

Returns:
a String specifying extra path information that comes after the request handler and context path but before the query string in the request URL; or null if the URL does not have any extra path information

getPathInfo

String getPathInfo(boolean removeSurroundingSlashs)
Returns any extra path information associated with the URL. The extra path information follows the servlet path but precedes the query string

Parameters:
removeSurroundingSlashs - true, if surrounding slashs wil lbe removed
Returns:
a String specifying extra path information that comes after the request handler and context path but before the query string in the request URL; or null if the URL does not have any extra path information

getQueryString

String getQueryString()
Returns the query string that is contained in the request URL after the path. This method returns null if the URL does not have a query string.

Returns:
a String containing the query string or null if the URL contains no query string.

isSecure

boolean isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

Returns:
a boolean indicating if the request was made using a secure channel

getMatrixParameterNameSet

Set<String> getMatrixParameterNameSet()
returns the matrix parameter name set

Returns:
the matrix parameter name set

getMatrixParameter

String getMatrixParameter(String name)
Returns the value of a request matrix parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request.

Parameters:
name - a String specifying the name of the matrix parameter
Returns:
a String representing the single value of the matrix parameter

getMatrixParameterValues

String[] getMatrixParameterValues(String name)
Returns an array of String objects containing all of the values the given request matrix parameter has, or null if the parameter does not exist. If the natrix parameter has a single value, the array has a length of 1.

Parameters:
name - a String specifying the name of the matrix parameter
Returns:
an array of String objects containing the matrix parameter's values

setMatrixParameter

void setMatrixParameter(String parameterName,
                        String parameterValue)
sets a matrix parameter

Parameters:
parameterName - the parameter name
parameterValue - the parameter value

addMatrixParameter

void addMatrixParameter(String parameterName,
                        String parameterValue)
adds a matrix parameter

Parameters:
parameterName - the parameter name
parameterValue - the parameter value

removeMatrixParameter

void removeMatrixParameter(String parameterName)
removes a matrix parameter

Parameters:
parameterName - the parameter name

getParameterNameSet

Set<String> getParameterNameSet()
returns the parameter name set

Returns:
the parameter name set

getParameterNames

Enumeration getParameterNames()
Returns an Enumeration of String objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an empty Enumeration.

Returns:
an Enumeration of String objects, each String containing the name of a request parameter; or an empty Enumeration if the request has no parameters

getParameter

String getParameter(String name)
Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request.

Parameters:
name - a String specifying the name of the parameter
Returns:
a String representing the single value of the parameter

getParameter

String getParameter(String name,
                    String defaultVal)
Get an String parameter, with a fallback value.

Parameters:
name - the name of the parameter
defaultVal - the default value to use as fallback
Returns:
the value

getParameterValues

String[] getParameterValues(String name)
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist. If the parameter has a single value, the array has a length of 1.

Parameters:
name - a String specifying the name of the parameter
Returns:
an array of String objects containing the parameter's values

getRequiredStringParameter

String getRequiredStringParameter(String name)
                                  throws BadMessageException
Get an string parameter or throws an exception if parameter is not present

Parameters:
name - the parameter name
Returns:
the value
Throws:
BadMessageException - if the parameter is not present

getIntParameter

Integer getIntParameter(String name)
                        throws BadMessageException
Get an Integer parameter, or null if not present.

Parameters:
name - the name of the parameter
Returns:
the value, or null
Throws:
BadMessageException - if the parameter value is not a number

getRequiredIntParameter

int getRequiredIntParameter(String name)
                            throws BadMessageException
Get an int parameter or throws an exception if parameter is not present

Parameters:
name - the parameter name
Returns:
the value
Throws:
BadMessageException - if the parameter is not present or the parameter is not a number

getIntParameter

int getIntParameter(String name,
                    int defaultVal)
Get an int parameter, with a fallback value.

Parameters:
name - the name of the parameter
defaultVal - the default value to use as fallback
Returns:
the value, or null

getLongParameter

Long getLongParameter(String name)
                      throws BadMessageException
Get an Long parameter, or null if not present.

Parameters:
name - the name of the parameter
Returns:
the value, or null
Throws:
BadMessageException - if the parameter value is not a number

getRequiredLongParameter

long getRequiredLongParameter(String name)
                              throws BadMessageException
Get an long parameter or throws an exception if parameter is not present

Parameters:
name - the parameter name
Returns:
the value
Throws:
BadMessageException - if the parameter is not present or the parameter is not a number

getLongParameter

long getLongParameter(String name,
                      long defaultVal)
Get an long parameter, with a fallback value.

Parameters:
name - the name of the parameter
defaultVal - the default value to use as fallback
Returns:
the value

getDoubleParameter

Double getDoubleParameter(String name)
                          throws BadMessageException
Get an Double parameter, or null if not present.

Parameters:
name - the name of the parameter
Returns:
the value, or null
Throws:
BadMessageException - if the parameter is not a number

getRequiredDoubleParameter

double getRequiredDoubleParameter(String name)
                                  throws BadMessageException
Get an double parameter or throws an exception if parameter is not present

Parameters:
name - the parameter name
Returns:
the value
Throws:
BadMessageException - if the parameter is not present or the parameter value is not a number

getDoubleParameter

double getDoubleParameter(String name,
                          double defaultVal)
Get an double parameter, with a fallback value.

Parameters:
name - the name of the parameter
defaultVal - the default value to use as fallback
Returns:
the value

getFloatParameter

Float getFloatParameter(String name)
                        throws BadMessageException
Get an Float parameter, or null if not present.

Parameters:
name - the name of the parameter
Returns:
the value, or null
Throws:
BadMessageException - if the parameter value is not a number

getRequiredFloatParameter

float getRequiredFloatParameter(String name)
                                throws BadMessageException
Get an float parameter or throws an exception if parameter is not present

Parameters:
name - the parameter name
Returns:
the value
Throws:
BadMessageException - if the parameter is not present or the parameter value is not a number

getFloatParameter

float getFloatParameter(String name,
                        float defaultVal)
Get an float parameter, with a fallback value.

Parameters:
name - the name of the parameter
defaultVal - the default value to use as fallback
Returns:
the value

getBooleanParameter

Boolean getBooleanParameter(String name)
Get an Boolean parameter, or null if not present.

Parameters:
name - the name of the parameter
Returns:
the value, or null

getRequiredBooleanParameter

boolean getRequiredBooleanParameter(String name)
                                    throws BadMessageException
Get an boolean parameter or throws an exception if parameter is not present

Parameters:
name - the parameter name
Returns:
the value
Throws:
BadMessageException - if the parameter is not present

getBooleanParameter

boolean getBooleanParameter(String name,
                            boolean defaultVal)
Get an boolean parameter, with a fallback value.

Parameters:
name - the name of the parameter
defaultVal - the default value to use as fallback
Returns:
the value

setParameter

void setParameter(String parameterName,
                  String parameterValue)
sets a parameter

Parameters:
parameterName - the parameter name
parameterValue - the parameter value

removeParameter

void removeParameter(String parameterName)
remove a parameter

Parameters:
parameterName - the parameter name
parameterValue - the parameter value

addParameter

void addParameter(String parameterName,
                  String parameterValue)
adds a parameter

Parameters:
parameterName - the parameter name
parameterValue - the parameter value