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.String
FORMAT_JSON
static java.lang.String
FORMAT_XML
static java.lang.String
HTTP_USHER_HEADER_ERROR
protected boolean
isPost
protected java.lang.String
jsonDataParam
protected java.util.Map<java.lang.String,java.lang.String>
requestParams
protected java.util.Map<java.lang.String,java.lang.String>
requestProps
protected 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 void
addBody(java.io.OutputStream out)
protected void
addJsonDataParam()
protected abstract void
addRequestParameters()
protected abstract void
addRequestProperties()
protected java.net.URL
buildURL(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.String
executeStringContentType()
static java.lang.String
getCookieFromResponseHeader(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, java.lang.String cookieName)
static java.lang.String
getErrorDetails(java.net.HttpURLConnection urlConn)
In case of error gets error detailsprotected java.lang.String
getJsonStringIfExists(JSONObject json, java.lang.String key)
java.lang.String
getResponseFromRequest()
static void
handleErrorCodes(int responseCode, java.lang.String errorDetails)
Throws the appropriate Usher Error code depending on type of errorprotected abstract void
handleResponse(java.io.InputStream imageStream, java.lang.String contentType, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
protected abstract void
handleResponse(java.lang.String result)
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.void
setResponseFromRequest(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:
TaskInternalException
TaskException
-
handleErrorCodes
public static void handleErrorCodes(int responseCode, java.lang.String errorDetails) throws TaskInternalException
Throws 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.MalformedURLException
builds up the query to be executed with any additional parameters specified by the child request- Parameters:
params
-- Returns:
- Throws:
java.io.UnsupportedEncodingException
java.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
-
-