Class RestUtil
- java.lang.Object
-
- org.glassfish.admingui.common.util.RestUtil
-
public class RestUtil extends Object
Utilities for processing REST requests in the admin console- Author:
- anilam
-
-
Field Summary
Fields Modifier and Type Field Description static String
FORM_ENCODING
static String
GUI_TOKEN_FOR_EMPTY_PROPERTY_VALUE
static String
RESPONSE_TYPE
static String
REST_TOKEN_COOKIE
-
Constructor Summary
Constructors Constructor Description RestUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
appendEncodedSegment(String base, String segment)
This method will encode append segment to base, encoding it so that a correct URL is returned.static List<Map<String,Object>>
buildChildEntityList(String parent, String childType, List<?> skipList, List<?> includeList, String id)
Given the parent URL and the desired childType, this method will build a List of Maps that contains each child entities values.static Map<String,String>
buildDefaultValueMap(String endpoint)
protected static jakarta.ws.rs.core.MultivaluedMap<String,Object>
buildMultivalueMap(Map<String,Object> payload)
protected static Map<String,Object>
buildUseOnlyAttrMap(Map<String,Object> attrs, List<String> onlyUseAttrs)
static void
checkStatusForSuccess(jakarta.ws.rs.core.Response cr)
protected static Map<String,Object>
convertNullValuesToFalse(Map<String,Object> attrs, List<String> convertToFalse)
static RestResponse
delete(String address, Map<String,Object> payload)
static Boolean
doesProxyExist(String endpoint)
protected static Map<String,Object>
fixKeyNames(Map<String,Object> map)
static RestResponse
get(String address)
static RestResponse
get(String address, Map<String,Object> payload)
static Map<String,Object>
getAttributesMap(String endpoint)
static List<String>
getChildList(String endpoint)
Given the parent URL and the desired childType, this method will build a List of Strings that contains child entity names.static Map<String,String>
getChildMap(String endpoint)
static Map<String,String>
getChildMap(String endpoint, Map<String,Object> attrs)
static List<String>
getChildResourceList(String document)
static Map<String,Object>
getEntityAttrs(String endpoint, String key)
static jakarta.ws.rs.client.Client
getJerseyClient()
static String
getPropValue(String endpoint, String propName, com.sun.jsftemplating.layout.descriptors.handler.HandlerContext handlerCtx)
static jakarta.ws.rs.core.Response
getRequestFromServlet(jakarta.servlet.http.HttpServletRequest request, String endpoint, Map<String,Object> attrs)
static void
getRestRequestFromServlet(jakarta.servlet.http.HttpServletRequest request, String endpoint, Map<String,Object> attrs, boolean quiet, boolean throwException)
static String
getRestToken()
This method returns the value of the REST token if it is successfully set in session scope.static boolean
hasWarning(Map responseMap)
static jakarta.ws.rs.client.ClientBuilder
initialize(jakarta.ws.rs.client.ClientBuilder clientBuilder)
static Map<String,Object>
maskOffPassword(Map<String,Object> attrs)
static RestResponse
options(String address, String responseType)
static Map<String,Object>
parseResponse(RestResponse response, com.sun.jsftemplating.layout.descriptors.handler.HandlerContext handlerCtx, String endpoint, Object attrs, boolean quiet, boolean throwException)
static RestResponse
post(String address, Object payload, String contentType)
static RestResponse
post(String address, Map<String,Object> payload)
static void
postRestRequestFromServlet(jakarta.servlet.http.HttpServletRequest request, String endpoint, Map<String,Object> attrs, boolean quiet, boolean throwException)
static RestResponse
put(String address, Object payload, String contentType)
static RestResponse
put(String address, Map<String,Object> payload)
protected static void
removeSpecifiedAttrs(Map<String,Object> attrs, List<String> removeList)
static String
resolveToken(String endpoint, String token)
static Map<String,Object>
restRequest(String endpoint, Map<String,Object> attrs, String method, com.sun.jsftemplating.layout.descriptors.handler.HandlerContext handlerCtx, boolean quiet)
static Map<String,Object>
restRequest(String endpoint, Map<String,Object> attrs, String method, com.sun.jsftemplating.layout.descriptors.handler.HandlerContext handlerCtx, boolean quiet, boolean throwException)
static RestResponse
sendCreateRequest(String endpoint, Map<String,Object> attrs, List<String> skipAttrs, List<String> onlyUseAttrs, List<String> convertToFalse)
static RestResponse
sendUpdateRequest(String endpoint, Map<String,Object> attrs, List<String> skipAttrs, List<String> onlyUseAttrs, List<String> convertToFalse)
static jakarta.ws.rs.client.WebTarget
targetWithQueryParams(jakarta.ws.rs.client.WebTarget target, Map<String,?> paramMap)
static String
upperCaseFirstLetter(String string)
Converts the first letter of the given string to Uppercase.
-
-
-
Field Detail
-
FORM_ENCODING
public static final String FORM_ENCODING
- See Also:
- Constant Field Values
-
RESPONSE_TYPE
public static final String RESPONSE_TYPE
- See Also:
- Constant Field Values
-
GUI_TOKEN_FOR_EMPTY_PROPERTY_VALUE
public static final String GUI_TOKEN_FOR_EMPTY_PROPERTY_VALUE
- See Also:
- Constant Field Values
-
REST_TOKEN_COOKIE
public static final String REST_TOKEN_COOKIE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getJerseyClient
public static jakarta.ws.rs.client.Client getJerseyClient()
-
getPropValue
public static String getPropValue(String endpoint, String propName, com.sun.jsftemplating.layout.descriptors.handler.HandlerContext handlerCtx)
-
restRequest
public static Map<String,Object> restRequest(String endpoint, Map<String,Object> attrs, String method, com.sun.jsftemplating.layout.descriptors.handler.HandlerContext handlerCtx, boolean quiet)
-
restRequest
public static Map<String,Object> restRequest(String endpoint, Map<String,Object> attrs, String method, com.sun.jsftemplating.layout.descriptors.handler.HandlerContext handlerCtx, boolean quiet, boolean throwException)
-
buildDefaultValueMap
public static Map<String,String> buildDefaultValueMap(String endpoint) throws ParserConfigurationException, SAXException, IOException
-
parseResponse
public static Map<String,Object> parseResponse(RestResponse response, com.sun.jsftemplating.layout.descriptors.handler.HandlerContext handlerCtx, String endpoint, Object attrs, boolean quiet, boolean throwException)
-
hasWarning
public static boolean hasWarning(Map responseMap)
-
appendEncodedSegment
public static String appendEncodedSegment(String base, String segment)
This method will encode append segment to base, encoding it so that a correct URL is returned.- Parameters:
base
-segment
-- Returns:
-
buildMultivalueMap
protected static jakarta.ws.rs.core.MultivaluedMap<String,Object> buildMultivalueMap(Map<String,Object> payload)
-
sendCreateRequest
public static RestResponse sendCreateRequest(String endpoint, Map<String,Object> attrs, List<String> skipAttrs, List<String> onlyUseAttrs, List<String> convertToFalse)
-
sendUpdateRequest
public static RestResponse sendUpdateRequest(String endpoint, Map<String,Object> attrs, List<String> skipAttrs, List<String> onlyUseAttrs, List<String> convertToFalse)
-
removeSpecifiedAttrs
protected static void removeSpecifiedAttrs(Map<String,Object> attrs, List<String> removeList)
-
buildUseOnlyAttrMap
protected static Map<String,Object> buildUseOnlyAttrMap(Map<String,Object> attrs, List<String> onlyUseAttrs)
-
convertNullValuesToFalse
protected static Map<String,Object> convertNullValuesToFalse(Map<String,Object> attrs, List<String> convertToFalse)
-
upperCaseFirstLetter
public static String upperCaseFirstLetter(String string)
Converts the first letter of the given string to Uppercase.- Parameters:
string
- the input string- Returns:
- the string with the Uppercase first letter
-
getChildResourceList
public static List<String> getChildResourceList(String document) throws SAXException, IOException, ParserConfigurationException
-
buildChildEntityList
public static List<Map<String,Object>> buildChildEntityList(String parent, String childType, List<?> skipList, List<?> includeList, String id) throws Exception
Given the parent URL and the desired childType, this method will build a List of Maps that contains each child entities values. In addition to the entity values, each row will have a field, 'selected', set to false, as well as the URL encoded entity name ('encodedName').- Parameters:
parent
-childType
-skipList
-- Returns:
- Throws:
Exception
-
getChildList
public static List<String> getChildList(String endpoint) throws Exception
Given the parent URL and the desired childType, this method will build a List of Strings that contains child entity names.- Parameters:
endpoint
-- Returns:
- Throws:
Exception
-
getChildMap
public static Map<String,String> getChildMap(String endpoint) throws Exception
- Throws:
Exception
-
getChildMap
public static Map<String,String> getChildMap(String endpoint, Map<String,Object> attrs) throws Exception
- Throws:
Exception
-
getRestToken
public static String getRestToken()
This method returns the value of the REST token if it is successfully set in session scope.
- Returns:
-
getRequestFromServlet
public static jakarta.ws.rs.core.Response getRequestFromServlet(jakarta.servlet.http.HttpServletRequest request, String endpoint, Map<String,Object> attrs)
-
getRestRequestFromServlet
public static void getRestRequestFromServlet(jakarta.servlet.http.HttpServletRequest request, String endpoint, Map<String,Object> attrs, boolean quiet, boolean throwException)
-
targetWithQueryParams
public static jakarta.ws.rs.client.WebTarget targetWithQueryParams(jakarta.ws.rs.client.WebTarget target, Map<String,?> paramMap)
-
get
public static RestResponse get(String address)
-
get
public static RestResponse get(String address, Map<String,Object> payload)
-
post
public static RestResponse post(String address, Object payload, String contentType)
-
post
public static RestResponse post(String address, Map<String,Object> payload)
-
put
public static RestResponse put(String address, Object payload, String contentType)
-
put
public static RestResponse put(String address, Map<String,Object> payload)
-
delete
public static RestResponse delete(String address, Map<String,Object> payload)
-
options
public static RestResponse options(String address, String responseType)
-
checkStatusForSuccess
public static void checkStatusForSuccess(jakarta.ws.rs.core.Response cr)
-
initialize
public static jakarta.ws.rs.client.ClientBuilder initialize(jakarta.ws.rs.client.ClientBuilder clientBuilder)
-
-