Class NetworkRequest
- java.lang.Object
-
- com.microstrategy.web.app.utils.usher.NetworkRequest
-
- All Implemented Interfaces:
EnumUsherRequest
- Direct Known Subclasses:
UsherAuthenticationRequest,UsherGetBadgeInfoRequest,UsherGetScanStatusRequest,UsherLogoutRequest,UsherNotifyMeRequest,UsherQRCodeRequest,UsherRememberMeRequest,UsherUserRequest,UsherUserSearchRequest
public abstract class NetworkRequest extends java.lang.Object implements EnumUsherRequest
Generic network request. It allows a subclass to add parameters in the url and read the response.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFORMAT_JSONstatic java.lang.StringFORMAT_XMLstatic java.lang.StringHTTP_USHER_HEADER_ERRORprotected booleanisPostprotected java.lang.StringjsonDataParamprotected java.util.Map<java.lang.String,java.lang.String>requestParamsprotected java.util.Map<java.lang.String,java.lang.String>requestPropsprotected java.util.Map<java.lang.String,java.util.List<java.lang.String>>responseHeaderFields-
Fields inherited from interface com.microstrategy.web.app.utils.usher.EnumUsherRequest
BAD_CONFIG, CUSTOMER_USHER_APP_ID, GENERIC_ERROR_CODE_FOR_USHER_AUTH, HANDLE_INPUT_STREAM, HANDLE_STRING, INVALID_RESPONSE_FROM_USHER, INVALID_TOKEN, ORG_ID, SESSION_ID, TIME_TO_LIVE, USER_ALREADY_EXISTS, USHER_ACCESS_TOKEN
-
-
Constructor Summary
Constructors Constructor Description NetworkRequest(java.lang.String baseURLIn, int whichHandle, boolean isPost)NetworkRequest(java.lang.String baseURL, java.lang.String extraPath, int whichHandle, boolean isPost)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddBody(java.io.OutputStream out)protected voidaddJsonDataParam()protected abstract voidaddRequestParameters()protected abstract voidaddRequestProperties()protected java.net.URLbuildURL(java.util.Map<java.lang.String,java.lang.String> params, boolean isPost, boolean sanitize)builds up the query to be executed with any additional parameters specified by the child requestjava.lang.StringexecuteStringContentType()static java.lang.StringgetCookieFromResponseHeader(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, java.lang.String cookieName)static java.lang.StringgetErrorDetails(java.net.HttpURLConnection urlConn)In case of error gets error detailsprotected java.lang.StringgetJsonStringIfExists(JSONObject json, java.lang.String key)java.lang.StringgetResponseFromRequest()static voidhandleErrorCodes(int responseCode, java.lang.String errorDetails)Throws the appropriate Usher Error code depending on type of errorprotected abstract voidhandleResponse(java.io.InputStream imageStream, java.lang.String contentType, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)protected abstract voidhandleResponse(java.lang.String result)static java.lang.StringmakePath(java.lang.String url, java.lang.String params)Helper function to generate new URL by connecting a path with a given URL.voidsetResponseFromRequest(java.lang.String responseFromRequest)
-
-
-
Field Detail
-
HTTP_USHER_HEADER_ERROR
public static final java.lang.String HTTP_USHER_HEADER_ERROR
- See Also:
- Constant Field Values
-
FORMAT_XML
public static final java.lang.String FORMAT_XML
- See Also:
- Constant Field Values
-
FORMAT_JSON
public static final java.lang.String FORMAT_JSON
- See Also:
- Constant Field Values
-
requestParams
protected java.util.Map<java.lang.String,java.lang.String> requestParams
-
jsonDataParam
protected java.lang.String jsonDataParam
-
requestProps
protected java.util.Map<java.lang.String,java.lang.String> requestProps
-
responseHeaderFields
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseHeaderFields
-
isPost
protected boolean isPost
-
-
Method Detail
-
addBody
protected void addBody(java.io.OutputStream out) throws TaskException- Throws:
TaskException
-
addJsonDataParam
protected void addJsonDataParam() throws TaskException- Throws:
TaskException
-
addRequestParameters
protected abstract void addRequestParameters() throws TaskException- Throws:
TaskException
-
addRequestProperties
protected abstract void addRequestProperties() throws TaskException- Throws:
TaskException
-
handleResponse
protected abstract void handleResponse(java.lang.String result) throws TaskException- Throws:
TaskException
-
handleResponse
protected abstract void handleResponse(java.io.InputStream imageStream, java.lang.String contentType, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers) throws TaskException- Throws:
TaskException
-
getJsonStringIfExists
protected java.lang.String getJsonStringIfExists(JSONObject json, java.lang.String key)
- Parameters:
json-key-- Returns:
-
executeStringContentType
public java.lang.String executeStringContentType() throws TaskException- Returns:
- Throws:
TaskInternalExceptionTaskException
-
handleErrorCodes
public static void handleErrorCodes(int responseCode, java.lang.String errorDetails) throws TaskInternalExceptionThrows the appropriate Usher Error code depending on type of error- Parameters:
responseCode-response-- Throws:
TaskInternalException
-
buildURL
protected java.net.URL buildURL(java.util.Map<java.lang.String,java.lang.String> params, boolean isPost, boolean sanitize) throws java.io.UnsupportedEncodingException, java.net.MalformedURLExceptionbuilds up the query to be executed with any additional parameters specified by the child request- Parameters:
params-- Returns:
- Throws:
java.io.UnsupportedEncodingExceptionjava.net.MalformedURLException
-
getResponseFromRequest
public java.lang.String getResponseFromRequest()
-
setResponseFromRequest
public void setResponseFromRequest(java.lang.String responseFromRequest)
-
getCookieFromResponseHeader
public static java.lang.String getCookieFromResponseHeader(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, java.lang.String cookieName)
-
getErrorDetails
public static java.lang.String getErrorDetails(java.net.HttpURLConnection urlConn)
In case of error gets error details- Parameters:
urlConn-- Returns:
- StringBuilder with error details
-
makePath
public static java.lang.String makePath(java.lang.String url, java.lang.String params)Helper function to generate new URL by connecting a path with a given URL. If the given URL does not have "/" at the then, it will append "/" at the end of the URL.- Parameters:
url- The URL link stringparams- The second part of the link- Returns:
- A full URL constructed with given url and the second part path
-
-