com.jalios.jcms.rest
Class RestUtil

java.lang.Object
  extended by com.jalios.jcms.rest.RestUtil

public class RestUtil
extends Object

Provides utility static methods for both client and server side in REST communication.

Since:
JCMS-6.0
Author:
dissert

Field Summary
static String XML_UTF_8_STANDARD_BOM
           
 
Constructor Summary
RestUtil()
           
 
Method Summary
static void displayResponse(org.restlet.data.Response response)
          Dev method to print in syso the content of a response
static String formatMsgToXml(javax.servlet.http.HttpServletRequest request)
          Get the info, warning and error messages in the request and in the session and returns a xml with all this informations.
static String formatMsgToXml(javax.servlet.http.HttpServletRequest request, boolean displayInfo, boolean displayWarning, boolean displayError)
          Get the info, warning and error messages in the request and in the session and returns a xml with all this informations.
static String formatXmlEntityError(String code, String message)
          Print an message in the following format (without indentation) : code message
static String getExtension(org.restlet.data.MediaType mediaType)
          Gives an possible extension from a mime-type.
static org.restlet.data.Form getForm(org.restlet.resource.Representation entity)
          Gives a form representation of the parameters in the entity-body.
static org.restlet.data.Form getForm(String queryString)
          Gives a form representation of the parameters in the queryString.
static org.restlet.data.Reference getReferenceFromUriSuffix(String uriSuffix, javax.servlet.http.HttpServletRequest j2eeRequest)
          Gives the complete URL from an external point of vue, from an uri with no context-path and "rest" prefix
static boolean isRest(javax.servlet.http.HttpServletRequest request)
           
static void sendApplicationError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Get the messages in request or in session and put it formatted in the entity body of the response and set CLIENT_ERROR_BAD_REQUEST (400) HTTP error code.
static void sendDetailedError(javax.servlet.http.HttpServletResponse response, int errorCode, String applicationErrorCode, String applicationErrorMessage)
           
static void sendError(javax.servlet.http.HttpServletResponse response, int errorCode)
           
static void sendError(javax.servlet.http.HttpServletResponse response, int errorCode, String message)
           
static void sendError(javax.servlet.http.HttpServletResponse response, org.restlet.data.Status error)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_UTF_8_STANDARD_BOM

public static final String XML_UTF_8_STANDARD_BOM
See Also:
Constant Field Values
Constructor Detail

RestUtil

public RestUtil()
Method Detail

isRest

public static final boolean isRest(javax.servlet.http.HttpServletRequest request)

sendError

public static void sendError(javax.servlet.http.HttpServletResponse response,
                             org.restlet.data.Status error)
                      throws IOException
Throws:
IOException

sendError

public static void sendError(javax.servlet.http.HttpServletResponse response,
                             int errorCode,
                             String message)
                      throws IOException
Throws:
IOException

sendError

public static void sendError(javax.servlet.http.HttpServletResponse response,
                             int errorCode)
                      throws IOException
Throws:
IOException

sendDetailedError

public static void sendDetailedError(javax.servlet.http.HttpServletResponse response,
                                     int errorCode,
                                     String applicationErrorCode,
                                     String applicationErrorMessage)
                              throws IOException
Throws:
IOException

formatXmlEntityError

public static String formatXmlEntityError(String code,
                                          String message)
Print an message in the following format (without indentation) : code message

Parameters:
code -
message -
Returns:
the formatted XML String

displayResponse

public static void displayResponse(org.restlet.data.Response response)
                            throws IOException
Dev method to print in syso the content of a response

Parameters:
response - a Restlet response
Throws:
IOException - if the text content of the entity body can't be retrieved

formatMsgToXml

public static String formatMsgToXml(javax.servlet.http.HttpServletRequest request)
Get the info, warning and error messages in the request and in the session and returns a xml with all this informations. The form of the XML is as follow : message in the lang of the current logged member message in the lang of the current logged member message in the lang of the current logged member message in the lang of the current logged member message in the lang of the current logged member message in the lang of the current logged member If an XML element would be empty, it is not set.

Parameters:
request - the current request
Returns:
the formatted xml message.

formatMsgToXml

public static String formatMsgToXml(javax.servlet.http.HttpServletRequest request,
                                    boolean displayInfo,
                                    boolean displayWarning,
                                    boolean displayError)
Get the info, warning and error messages in the request and in the session and returns a xml with all this informations. But info, warning or error level messages may be skipped.

Parameters:
request - the current request
displayInfo - if false, info message is skipped
displayWarning - if false, warning message is skipped
displayError - if false, error message is skipped
Returns:
the formatted message

sendApplicationError

public static void sendApplicationError(javax.servlet.http.HttpServletRequest request,
                                        javax.servlet.http.HttpServletResponse response)
                                 throws IOException
Get the messages in request or in session and put it formatted in the entity body of the response and set CLIENT_ERROR_BAD_REQUEST (400) HTTP error code.

Parameters:
request - the current request
response - the current response
Throws:
IOException - if the printer is innaccessible

getExtension

public static String getExtension(org.restlet.data.MediaType mediaType)
Gives an possible extension from a mime-type. If present in "file-document.ext" properties

Parameters:
mediaType -
Returns:
possible extensions
Since:
JCMS-6.1

getReferenceFromUriSuffix

public static org.restlet.data.Reference getReferenceFromUriSuffix(String uriSuffix,
                                                                   javax.servlet.http.HttpServletRequest j2eeRequest)
Gives the complete URL from an external point of vue, from an uri with no context-path and "rest" prefix

Parameters:
uriSuffix - the uriSuffix with no context-path and no "rest" prefix
j2eeRequest - The current J2EE request
Returns:
the complete URL, with the base URL
Since:
JCMS-6.1

getForm

public static org.restlet.data.Form getForm(String queryString)
Gives a form representation of the parameters in the queryString. If parameter have a transformation specific format, they are transformed into the good value. Example :

Parameters:
queryString - the query string
Returns:
the form
Since:
jcms-6.1.3

getForm

public static org.restlet.data.Form getForm(org.restlet.resource.Representation entity)
Gives a form representation of the parameters in the entity-body. If parameter have a transformation specific format, they are transformed into the good value. Example :

Parameters:
entity - A representation
Returns:
the form
Since:
jcms-6.1.3


Copyright © 2001-2010 Jalios SA. All Rights Reserved.