public class RestUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CSRF_HEADER_NAME |
static java.lang.String |
FAILED_CONTROLLER_STATUS |
static java.lang.String |
RESPONSE_CONTENT_TYPE_NAME_ATTRIBUTE |
static java.lang.String |
XML_UTF_8_STANDARD_BOM |
Constructor and Description |
---|
RestUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
displayResponse(org.restlet.data.Response response)
Dev method to print in syso the content of a response
|
static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> |
formatMsgToJson(javax.servlet.http.HttpServletRequest request)
Get the info, warning and error messages in the request and in the session and
returns a json with all this informations.
|
static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> |
formatMsgToJson(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 Map with all this informations.
|
static java.lang.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 java.lang.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 java.lang.String |
formatXmlEntityError(java.lang.String code,
java.lang.String message)
Print an message in the following format (without indentation) :
|
static Data |
getData(java.lang.String dataId,
Member mbr,
boolean throwExceptionOnInvalidData)
Retrieve Data instance (if mbr can read it)
|
static java.util.Date |
getDate(java.lang.String date) |
static java.lang.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(java.lang.String queryString)
Gives a form representation of the parameters in the queryString.
|
static java.util.LinkedHashMap<java.lang.String,java.util.List<java.lang.String>> |
getFormParameters(org.restlet.resource.Representation entity,
javax.servlet.http.HttpServletRequest j2eeRequest)
Read form parameters from a rest entity (as json entity, application/x-www-form-urlencoded or multipart-formdata entity)
|
static Group |
getGroup(java.lang.String grpStr,
Member mbr,
boolean throwExceptionOnInvalidData)
Retrieve
Group from a string (by testing id, ldap dn and name) |
static Member |
getMember(java.lang.String mbrStr,
boolean throwExceptionOnInvalidData)
Retrieve
Member from a string (by testing id, login and email) |
static org.restlet.data.Reference |
getReferenceFromUriSuffix(java.lang.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 org.restlet.data.MediaType |
getRestContentType(javax.servlet.http.HttpServletRequest request)
Simple implementation of the feature : is application/json in accept headers ? application_JSON : application_XML
|
static Workspace |
getWorkspace(java.lang.String wkStr,
boolean throwExceptionOnInvalidData)
Retrieve
Workspace from a string (by testing id and title) |
static boolean |
isRest(javax.servlet.http.HttpServletRequest request) |
static void |
sendApplicationError(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.restlet.data.MediaType contentType)
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 |
sendApplicationError(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String contentType)
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,
java.lang.String applicationErrorCode,
java.lang.String applicationErrorMessage)
Deprecated.
use
sendDetailedError(HttpServletResponse, int, String, String, MediaType) which allows the correct media type to be
specified |
static void |
sendDetailedError(javax.servlet.http.HttpServletResponse response,
int errorCode,
java.lang.String applicationErrorCode,
java.lang.String applicationErrorMessage,
org.restlet.data.MediaType contentType)
This method send an error stream
|
static void |
sendDetailedError(javax.servlet.http.HttpServletResponse response,
int errorCode,
java.lang.String applicationErrorCode,
java.lang.String applicationErrorMessage,
java.lang.String contentType)
This method is here for ascendant compatibility, please use the method with MediaType parameter instead.
|
static void |
sendDetailedError(javax.servlet.http.HttpServletResponse response,
RestException exception,
org.restlet.data.MediaType contentType)
This method send an error stream
|
static void |
sendDetailedError(org.restlet.data.Response response,
RestException exception,
org.restlet.data.MediaType contentType)
This method send an error stream from restlet scope)
|
static void |
sendDetailedError(org.restlet.data.Response response,
org.restlet.data.Status httpStatus,
java.lang.String applicationErrorCode,
java.lang.String applicationErrorMessage,
org.restlet.data.MediaType contentType)
This method send an error stream (from restlet scope)
|
static void |
sendError(javax.servlet.http.HttpServletResponse response,
int errorCode) |
static void |
sendError(javax.servlet.http.HttpServletResponse response,
int errorCode,
java.lang.String message) |
static void |
sendError(javax.servlet.http.HttpServletResponse response,
org.restlet.data.Status error) |
static void |
setUserLang(JcmsContext jcmsContext,
java.lang.String userLang)
Force the update of the user lang in jcmsContext (must be only used in Rest environment to avoid not wanted side effects)
|
public static final java.lang.String XML_UTF_8_STANDARD_BOM
public static final java.lang.String CSRF_HEADER_NAME
public static final java.lang.String RESPONSE_CONTENT_TYPE_NAME_ATTRIBUTE
public static final java.lang.String FAILED_CONTROLLER_STATUS
public static final boolean isRest(javax.servlet.http.HttpServletRequest request)
public static void sendError(javax.servlet.http.HttpServletResponse response, org.restlet.data.Status error) throws java.io.IOException
java.io.IOException
public static void sendError(javax.servlet.http.HttpServletResponse response, int errorCode, java.lang.String message) throws java.io.IOException
java.io.IOException
public static void sendError(javax.servlet.http.HttpServletResponse response, int errorCode) throws java.io.IOException
java.io.IOException
@Deprecated public static void sendDetailedError(javax.servlet.http.HttpServletResponse response, int errorCode, java.lang.String applicationErrorCode, java.lang.String applicationErrorMessage) throws java.io.IOException
sendDetailedError(HttpServletResponse, int, String, String, MediaType)
which allows the correct media type to be
specifiedresponse
- the Response
objecterrorCode
- the error codeapplicationErrorCode
- the application error codeapplicationErrorMessage
- the application error messagejava.io.IOException
- Exception thrown when the content is written to the responsepublic static void sendDetailedError(javax.servlet.http.HttpServletResponse response, int errorCode, java.lang.String applicationErrorCode, java.lang.String applicationErrorMessage, java.lang.String contentType) throws java.io.IOException
response
- the Response
objecterrorCode
- the error codeapplicationErrorCode
- the application error codeapplicationErrorMessage
- the application error messagecontentType
- the content type name used to create response contentjava.io.IOException
- Exception thrown when the content is written to the responsepublic static void sendDetailedError(javax.servlet.http.HttpServletResponse response, int errorCode, java.lang.String applicationErrorCode, java.lang.String applicationErrorMessage, org.restlet.data.MediaType contentType) throws java.io.IOException
response
- the HttpServletResponse
objecterrorCode
- the error codeapplicationErrorCode
- the application error codeapplicationErrorMessage
- the application error messagecontentType
- the content type used to create response contentjava.io.IOException
- Exception thrown when the content is written to the responsepublic static void sendDetailedError(javax.servlet.http.HttpServletResponse response, RestException exception, org.restlet.data.MediaType contentType) throws java.io.IOException
response
- the HttpServletResponse
objectexception
- the RestException
contentType
- the content type used to create response contentjava.io.IOException
- Exception thrown when the cntent is written to the responsepublic static void sendDetailedError(org.restlet.data.Response response, org.restlet.data.Status httpStatus, java.lang.String applicationErrorCode, java.lang.String applicationErrorMessage, org.restlet.data.MediaType contentType)
response
- the Response
objecthttpStatus
- the Status
applicationErrorCode
- the application error codeapplicationErrorMessage
- the application error messagecontentType
- the content type used to create response contentpublic static void sendDetailedError(org.restlet.data.Response response, RestException exception, org.restlet.data.MediaType contentType)
response
- the Response
objectexception
- the RestException
contentType
- the content type used to create response contentpublic static java.lang.String formatXmlEntityError(java.lang.String code, java.lang.String message)
<error> <code>code</code> <message>message</message> </error>
code
- the error codemessage
- the messagepublic static void displayResponse(org.restlet.data.Response response) throws java.io.IOException
response
- a Restlet responsejava.io.IOException
- if the text content of the entity body can't be retrievedpublic static java.lang.String formatMsgToXml(javax.servlet.http.HttpServletRequest request)
<msg> <info> <session>message in the lang of the current logged member</session> <request>message in the lang of the current logged member</request> </info> <warning> <session>message in the lang of the current logged member</session> <request>message in the lang of the current logged member</request> </warning> <error> <session>message in the lang of the current logged member</session> <request>message in the lang of the current logged member</request> </error> </msg>If an XML element would be empty, it is not set.
request
- the current requestpublic static java.lang.String formatMsgToXml(javax.servlet.http.HttpServletRequest request, boolean displayInfo, boolean displayWarning, boolean displayError)
request
- the current requestdisplayInfo
- if false, info message is skippeddisplayWarning
- if false, warning message is skippeddisplayError
- if false, error message is skippedpublic static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> formatMsgToJson(javax.servlet.http.HttpServletRequest request)
{ "info": { "session" : "message in the lang of the current logged member", "request" : "message in the lang of the current logged member" }, "warning: { "session" : "message in the lang of the current logged member", "request" : "message in the lang of the current logged member" }, "error: { "session" : "message in the lang of the current logged member", "request" : "message in the lang of the current logged member" } }If an JSon element would be empty, it is not set.
request
- the current requestpublic static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> formatMsgToJson(javax.servlet.http.HttpServletRequest request, boolean displayInfo, boolean displayWarning, boolean displayError)
{ "info": { "session" : "message in the lang of the current logged member", "request" : "message in the lang of the current logged member" }, "warning: { "session" : "message in the lang of the current logged member", "request" : "message in the lang of the current logged member" }, "error: { "session" : "message in the lang of the current logged member", "request" : "message in the lang of the current logged member" } }If an JSon element would be empty, it is not set.
request
- the current requestdisplayInfo
- if false, info message is skippeddisplayWarning
- if false, warning message is skippeddisplayError
- if false, error message is skippedpublic static void sendApplicationError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String contentType) throws java.io.IOException
request
- the current requestresponse
- the current responsecontentType
- the content type name used to format responsejava.io.IOException
- if the printer is not availablepublic static void sendApplicationError(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.restlet.data.MediaType contentType) throws java.io.IOException
request
- the current requestresponse
- the current responsecontentType
- the content type used to format responsejava.io.IOException
- if the printer is not availablepublic static java.lang.String getExtension(org.restlet.data.MediaType mediaType)
mediaType
- the MediaType
public static org.restlet.data.Reference getReferenceFromUriSuffix(java.lang.String uriSuffix, javax.servlet.http.HttpServletRequest j2eeRequest)
uriSuffix
- the uriSuffix with no context-path and no "rest" prefixj2eeRequest
- The current J2EE requestpublic static org.restlet.data.Form getForm(java.lang.String queryString)
queryString
- the query stringpublic static org.restlet.data.Form getForm(org.restlet.resource.Representation entity)
entity
- A representationpublic static org.restlet.data.MediaType getRestContentType(javax.servlet.http.HttpServletRequest request)
request
- the HttpServletRequest
MediaType
public static Workspace getWorkspace(java.lang.String wkStr, boolean throwExceptionOnInvalidData) throws java.lang.Exception
Workspace
from a string (by testing id and title)wkStr
- the workspace stringthrowExceptionOnInvalidData
- the an Exception if the id is not empty and not a valid dataWorkspace
java.lang.Exception
- thrown if the string is not empty and if workspace cannot be foundpublic static Group getGroup(java.lang.String grpStr, Member mbr, boolean throwExceptionOnInvalidData) throws java.lang.Exception
Group
from a string (by testing id, ldap dn and name)grpStr
- the group stringmbr
- the Member
used to check read rightsthrowExceptionOnInvalidData
- the an Exception if the id is not empty and not a valid dataGroup
java.lang.Exception
- thrown if the string is not empty and if group cannot be found, is multiple, or cannot be read by memberpublic static Member getMember(java.lang.String mbrStr, boolean throwExceptionOnInvalidData) throws java.lang.Exception
Member
from a string (by testing id, login and email)mbrStr
- the member stringthrowExceptionOnInvalidData
- the an Exception if the data id is not empty and not a valid dataMember
java.lang.Exception
- thrown if the string is not empty and if member cannot be found, is multiple, or cannot be read by memberpublic static Data getData(java.lang.String dataId, Member mbr, boolean throwExceptionOnInvalidData) throws java.lang.Exception
dataId
- the data Id (can be nullmbr
- the Member
used to ckeck read rightsthrowExceptionOnInvalidData
- the an Exception if the data id is not empty and not a valid dataData
if it can be found and if user can read it.java.lang.Exception
- throw if the dataId is not empty and if data cannot be found, or cannot be read by memberpublic static java.util.Date getDate(java.lang.String date)
public static java.util.LinkedHashMap<java.lang.String,java.util.List<java.lang.String>> getFormParameters(org.restlet.resource.Representation entity, javax.servlet.http.HttpServletRequest j2eeRequest) throws RestException
entity
- the body entityj2eeRequest
- the HttpServletRequest
(used to read multipart-formdata)RestException
- a RestException
if any problem occurspublic static void setUserLang(JcmsContext jcmsContext, java.lang.String userLang)
jcmsContext
- the current JcmsContext
to updateuserLang
- the User lang (of not null).Copyright © 2001-2021 Jalios SA. All Rights Reserved.