cn.dreampie.common
接口 Request

所有已知实现类:
AbstractRequest, HttpRequest

public interface Request

Date: 1/22/13 Time: 2:49 PM


方法摘要
 String getBaseNetworkPath()
          Returns the base network path of this request (ie baseUri without the protocol).
 String getBaseUri()
          Returns the base URI of this request.
 String getCharacterEncoding()
           
 String getClientAddress()
          The address (IP) of the client.
 int getContentLength()
           
 InputStream getContentStream()
           
 String getContentType()
           
 Map<String,String> getCookiesMap()
           
 String getCookieValue(String cookieName)
           
 String getHeader(String headerName)
           
 Map<String,String> getHeaders()
           
 Enumeration<String> getHeaders(String headerName)
           
 String getHttpMethod()
          HTTP METHOD, eg GET, POST, ...
 Locale getLocale()
          Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.
 List<Locale> getLocales()
          Returns an ImmutableList of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header.
 String getQueryParam(String param)
           
 Map<String,List<String>> getQueryParams()
           
 List<String> getQueryParams(String param)
           
 String getRealPath(String path)
          Returns the resty portion of the webRoot physical path.
 String getRestPath()
          Returns the resty portion of the request path.
 String getRestUri()
          Returns the resty portion of the full request uri.
 boolean isPersistentCookie(String cookie)
           
 boolean isSecured()
          Is this request performed through a secured connection or not.
 void setCharacterEncoding(String var1)
           
<T> T
unwrap(Class<T> clazz)
          Unwraps the underlying native implementation of given class.
 

方法详细信息

getBaseUri

String getBaseUri()
Returns the base URI of this request. Eg http://mydomain.com/api or http://mydomain.com:8080

When used behind a proxy, this will try to return the client facing URI, by using: - X-Forwarded-Host for the host - X-Forwarded-Proto for the scheme - checking first Via to know if request was made in HTTPS

see http://en.wikipedia.org/wiki/X-Forwarded-For see http://en.wikipedia.org/wiki/List_of_HTTP_header_fields see http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxyvia

返回:
the base URI of this request.

getBaseNetworkPath

String getBaseNetworkPath()
Returns the base network path of this request (ie baseUri without the protocol). Eg //mydomain.com/api or //mydomain.com:8080

This is useful to create paths using the same protocol as the one seen by the client, as opposed to the protocol seen by the server (server can see http if you have a front http server like Apache doing https and reverse proxy).

See also this discussion: http://stackoverflow.com/questions/5799577/does-using-www-example-com-in-javascript-chose-http-https-protocol-automatical

Note that if Via headers are set getBaseUri should be fine too.

返回:
the base network path of this request.

getRestPath

String getRestPath()
Returns the resty portion of the request path.

If incoming request is http://mydomain.com/api/myresource/test?q=test and baseUri is http://mydomain.com/api, then resty path will be /myresource/test

返回:
the resty portion of the request path.

getRealPath

String getRealPath(String path)
Returns the resty portion of the webRoot physical path.

参数:
path - webRoot relative path
返回:
the resty portion of the webRoot physical path.

getRestUri

String getRestUri()
Returns the resty portion of the full request uri.

If incoming request is http://mydomain.com/api/myresource/test?q=test and baseUri is http://mydomain.com/api, then resty uri will be /myresource/test?q=test

返回:
the resty portion of the full request uri.

isSecured

boolean isSecured()
Is this request performed through a secured connection or not.

This will return true if: - the HttpSettings proto() is set to 'https' - the request has a 'X-Forwarded-Proto' header with value 'https', and comes from an authorized proxy as defined by HttpSettings.forwardedSupport() - the request was performed in HTTPS on this server

返回:
true if this request is performed through a secured (HTTPS) connection.

getHttpMethod

String getHttpMethod()
HTTP METHOD, eg GET, POST, ...

返回:
the request HTTP method

getQueryParam

String getQueryParam(String param)

getQueryParams

List<String> getQueryParams(String param)

getQueryParams

Map<String,List<String>> getQueryParams()

getHeader

String getHeader(String headerName)

getHeaders

Enumeration<String> getHeaders(String headerName)

getHeaders

Map<String,String> getHeaders()

getContentType

String getContentType()

getCookieValue

String getCookieValue(String cookieName)

isPersistentCookie

boolean isPersistentCookie(String cookie)

getCookiesMap

Map<String,String> getCookiesMap()

getClientAddress

String getClientAddress()
The address (IP) of the client.

If X-Forwarded-For header is present, it will return its value, otherwise it returns the remote client address.

see http://httpd.apache.org/docs/current/mod/mod_proxy.html#x-headers for details on this header.

返回:
IP address of the client.

getContentLength

int getContentLength()

getContentStream

InputStream getContentStream()
                             throws IOException
抛出:
IOException

unwrap

<T> T unwrap(Class<T> clazz)
Unwraps the underlying native implementation of given class.

Examnple: This is a HttpServletRequest in a servlet container.

类型参数:
T - unwrapped class
参数:
clazz - the class of the underlying implementation
返回:
the unwrapped implementation.
抛出:
IllegalArgumentException - if the underlying implementation is not of given type.

getLocale

Locale getLocale()
Returns the preferred Locale that the client will accept content in, based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server.

返回:
the preferred Locale for the client

getLocales

List<Locale> getLocales()
Returns an ImmutableList of Locale objects 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 ImmutableList containing one Locale, the default locale for the server.

返回:
an ImmutableList of preferred Locale objects for the client

getCharacterEncoding

String getCharacterEncoding()

setCharacterEncoding

void setCharacterEncoding(String var1)
                          throws UnsupportedEncodingException
抛出:
UnsupportedEncodingException


Copyright © 2015. All rights reserved.