Package org.glassfish.admin.rest.utils
Class ResourceUtil
- java.lang.Object
-
- org.glassfish.admin.rest.utils.ResourceUtil
-
public class ResourceUtil extends Object
Resource utilities class. Used by resource templates,TemplateListOfResourceandTemplateRestResource- Author:
- Rajeshwar Patil
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddCommandLog(RestActionReporter ar, String commandName, ParameterMap parameters)static voidaddMethodMetaData(ActionReport ar, Map<String,MethodMetaData> mmd)static voidaddQueryString(jakarta.ws.rs.core.MultivaluedMap<String,String> qs, Map<String,String> data)This method takes any query string parameters and adds them to the specified map.static voidaddQueryString(jakarta.ws.rs.core.MultivaluedMap<String,String> qs, Properties data)static voidadjustParameters(Map<String,String> data)Adjust the input parameters.static SubjectauthenticateViaAdminRealm(org.glassfish.hk2.api.ServiceLocator habitat, org.glassfish.grizzly.http.server.Request req, String remoteHost)Authenticate the given req as originated from given remoteHost against admin realm.static MapbuildMethodMetadataMap(MethodMetaData mmd)static booleancanShowDeprecatedItems(org.glassfish.hk2.api.ServiceLocator habitat)static booleancommandIsPresent(org.glassfish.hk2.api.ServiceLocator habitat, String commandName)static StringconvertToXMLName(String name)protected static voidcopyParameterMetaDataAttribute(ParameterMetaData from, ParameterMetaData to, String key)static voiddefineDefaultParameters(Map<String,String> data)Adjust the input parameters.static StringencodeString(String text)static ActionReportResultgetActionReportResult(RestActionReporter ar, String message, jakarta.ws.rs.core.HttpHeaders requestHeaders, jakarta.ws.rs.core.UriInfo uriInfo)static ActionReportResultgetActionReportResult(ActionReport.ExitCode status, String message, jakarta.ws.rs.core.HttpHeaders requestHeaders, jakarta.ws.rs.core.UriInfo uriInfo)static StringgetAttributeBooleanMethodName(String attributeName)static StringgetAttributeMethodName(String attributeName)protected static byte[]getBytesFromStream(InputStream is)static StringgetCommand(RestRedirect.OpType type, ConfigModel model)Returns the name of the command associated with this resource,if any, for the given operation.static List<Map<String,String>>getCommandLinks(String[][] commandResourcesPaths)static jakarta.ws.rs.core.ResponsegetDeleteResponse(int status, String message, jakarta.ws.rs.core.HttpHeaders requestHeaders, jakarta.ws.rs.core.UriInfo uriInfo)special case for the delete operation: we need to give back the URI of the parent since the resource we are on is deletedprotected static voidgetInterfaces(Class<?> clazz, List<Class<?>> interfaces)static MethodMetaDatagetMethodMetaData(String command, Map<String,String> commandParamsToSkip, org.glassfish.hk2.api.ServiceLocator habitat)Constructs and returns the resource method meta-data.static MethodMetaDatagetMethodMetaData(String command, org.glassfish.hk2.api.ServiceLocator habitat)Constructs and returns the resource method meta-data.static MethodMetaDatagetMethodMetaData(ConfigModel configBeanModel)Constructs and returns the resource method meta-data.static MethodMetaDatagetMethodMetaData2(Dom parent, ConfigModel childModel, int parameterType)static StringgetParameterList(ParameterMap parameters)static Collection<CommandModel.ParamModel>getParamMetaData(String commandName, Collection<String> commandParamsToSkip, org.glassfish.hk2.api.ServiceLocator habitat)Constructs and returns the parameter meta-data.static Collection<CommandModel.ParamModel>getParamMetaData(String commandName, org.glassfish.hk2.api.ServiceLocator habitat)Constructs and returns the parameter meta-data.static List<ConfigModel>getRealChildConfigModels(ConfigModel childModel, DomDocument domDocument)static Map<String,String>getResourceLinks(List<Dom> proxyList, jakarta.ws.rs.core.UriInfo uriInfo)static Map<String,String>getResourceLinks(Dom dom, jakarta.ws.rs.core.UriInfo uriInfo, boolean canShowDeprecated)static jakarta.ws.rs.core.ResponsegetResponse(int status, String message, jakarta.ws.rs.core.HttpHeaders requestHeaders, jakarta.ws.rs.core.UriInfo uriInfo)Constructs and returns the appropriate response object based on the client.static RestConfiggetRestConfig(org.glassfish.hk2.api.ServiceLocator habitat)static StringgetResultType(jakarta.ws.rs.core.HttpHeaders requestHeaders)static StringgetUnqualifiedTypeName(String qualifiedTypeName)static booleanisAuthorized(org.glassfish.hk2.api.ServiceLocator habitat, Subject subject, String resource, String action)Indicates whether the subject can perform the action on the resource.static booleanisDeprecated(ConfigModel model)static booleanisOnlyATag(ConfigModel model)static Map<String,String>processJvmOptions(Map<String,String> jvmOptions, boolean removeVersioning)Creates a new rearranged map of JVM options.static voidpurgeEmptyEntries(Map<String,String> data)Removes entries with empty value from the given Mapstatic voidresolveParamValues(Map<String,String> commandParams, jakarta.ws.rs.core.UriInfo uriInfo)static RestActionReporterrunCommand(String commandName, Map<String,String> parameters, Subject subject)Executes the specified __asadmin command.static RestActionReporterrunCommand(String commandName, ParameterMap parameters, Subject subject)Executes the specified __asadmin command.static RestActionReporterrunCommand(String commandName, ParameterMap parameters, Subject subject, boolean managedJob)Executes the specified __asadmin command.static org.glassfish.jersey.media.sse.EventOutputrunCommandWithSse(String commandName, ParameterMap parameters, Subject subject, SseCommandHelper.ActionReportProcessor processor)static Map<String,String>translateCamelCasedNamesToXMLNames(Map<String,String> sourceData)
-
-
-
Method Detail
-
getBytesFromStream
protected static byte[] getBytesFromStream(InputStream is)
-
adjustParameters
public static void adjustParameters(Map<String,String> data)
Adjust the input parameters. In case of POST and DELETE methods, user can provide name, id or DEFAULT parameter for primary parameter(i.e the object to create or delete). This method is used to rename primary parameter name to DEFAULT irrespective of what user provides.
-
defineDefaultParameters
public static void defineDefaultParameters(Map<String,String> data)
Adjust the input parameters. In case of POST and DELETE methods, user can provide id or DEFAULT parameter for primary parameter(i.e the object to create or delete). This method is used to rename primary parameter name to DEFAULT irrespective of what user provides.
-
getCommand
public static String getCommand(RestRedirect.OpType type, ConfigModel model)
Returns the name of the command associated with this resource,if any, for the given operation.- Parameters:
type- the given resource operation- Returns:
- String the associated command name for the given operation.
-
runCommand
public static RestActionReporter runCommand(String commandName, ParameterMap parameters, Subject subject)
Executes the specified __asadmin command.- Parameters:
commandName-parameters-subject-- Returns:
-
runCommand
public static RestActionReporter runCommand(String commandName, ParameterMap parameters, Subject subject, boolean managedJob)
Executes the specified __asadmin command.- Parameters:
commandName-parameters-subject-managedJob-- Returns:
-
runCommand
public static RestActionReporter runCommand(String commandName, Map<String,String> parameters, Subject subject)
Executes the specified __asadmin command.- Parameters:
commandName- the command to executeparameters- the command parameterssubject- Subject- Returns:
- ActionReport object with command execute status details.
-
runCommandWithSse
public static org.glassfish.jersey.media.sse.EventOutput runCommandWithSse(String commandName, ParameterMap parameters, Subject subject, SseCommandHelper.ActionReportProcessor processor)
-
addCommandLog
public static void addCommandLog(RestActionReporter ar, String commandName, ParameterMap parameters)
-
getParameterList
public static String getParameterList(ParameterMap parameters)
-
getMethodMetaData
public static MethodMetaData getMethodMetaData(String command, org.glassfish.hk2.api.ServiceLocator habitat)
Constructs and returns the resource method meta-data.- Parameters:
command- the command associated with the resource methodhabitat- the habitat- Returns:
- MethodMetaData the meta-data store for the resource method.
-
getMethodMetaData
public static MethodMetaData getMethodMetaData(String command, Map<String,String> commandParamsToSkip, org.glassfish.hk2.api.ServiceLocator habitat)
Constructs and returns the resource method meta-data.- Parameters:
command- the command associated with the resource methodcommandParamsToSkip- the command parameters for which not to include the meta-data.habitat- the habitat- Returns:
- MethodMetaData the meta-data store for the resource method.
-
resolveParamValues
public static void resolveParamValues(Map<String,String> commandParams, jakarta.ws.rs.core.UriInfo uriInfo)
-
getMethodMetaData
public static MethodMetaData getMethodMetaData(ConfigModel configBeanModel)
Constructs and returns the resource method meta-data. This method is called to get meta-data in case of update method (POST).- Parameters:
configBeanModel- the config bean associated with the resource.- Returns:
- MethodMetaData the meta-data store for the resource method.
-
getMethodMetaData2
public static MethodMetaData getMethodMetaData2(Dom parent, ConfigModel childModel, int parameterType)
-
copyParameterMetaDataAttribute
protected static void copyParameterMetaDataAttribute(ParameterMetaData from, ParameterMetaData to, String key)
-
commandIsPresent
public static boolean commandIsPresent(org.glassfish.hk2.api.ServiceLocator habitat, String commandName)
-
getParamMetaData
public static Collection<CommandModel.ParamModel> getParamMetaData(String commandName, org.glassfish.hk2.api.ServiceLocator habitat)
Constructs and returns the parameter meta-data.- Parameters:
commandName- the command associated with the resource methodhabitat- the habitat- Returns:
- Collection the meta-data for the parameter of the resource method.
-
getParamMetaData
public static Collection<CommandModel.ParamModel> getParamMetaData(String commandName, Collection<String> commandParamsToSkip, org.glassfish.hk2.api.ServiceLocator habitat)
Constructs and returns the parameter meta-data.- Parameters:
commandName- the command associated with the resource methodcommandParamsToSkip- the command parameters for which not to include the meta-data.habitat- the habitat- Returns:
- Collection the meta-data for the parameter of the resource method.
-
purgeEmptyEntries
public static void purgeEmptyEntries(Map<String,String> data)
Removes entries with empty value from the given Map- Parameters:
data- data to remove empty entries from
-
getResponse
public static jakarta.ws.rs.core.Response getResponse(int status, String message, jakarta.ws.rs.core.HttpHeaders requestHeaders, jakarta.ws.rs.core.UriInfo uriInfo)Constructs and returns the appropriate response object based on the client.- Parameters:
status- the http status code for the responsemessage- message for the responserequestHeaders- request headers of the request- Returns:
- Response the response object to be returned to the client
-
getActionReportResult
public static ActionReportResult getActionReportResult(ActionReport.ExitCode status, String message, jakarta.ws.rs.core.HttpHeaders requestHeaders, jakarta.ws.rs.core.UriInfo uriInfo)
-
getActionReportResult
public static ActionReportResult getActionReportResult(RestActionReporter ar, String message, jakarta.ws.rs.core.HttpHeaders requestHeaders, jakarta.ws.rs.core.UriInfo uriInfo)
-
getDeleteResponse
public static jakarta.ws.rs.core.Response getDeleteResponse(int status, String message, jakarta.ws.rs.core.HttpHeaders requestHeaders, jakarta.ws.rs.core.UriInfo uriInfo)special case for the delete operation: we need to give back the URI of the parent since the resource we are on is deleted- Parameters:
status-message-requestHeaders-uriInfo-- Returns:
-
addQueryString
public static void addQueryString(jakarta.ws.rs.core.MultivaluedMap<String,String> qs, Map<String,String> data)
This method takes any query string parameters and adds them to the specified map. This is used, for example, with the delete operation when cascading deletes are required:
DELETE http://localhost:4848/.../foo?cascade=trueThe reason we need to use query parameters versus "body" variables is the limitation that HttpURLConnection has in this regard.
- Parameters:
data-
-
addQueryString
public static void addQueryString(jakarta.ws.rs.core.MultivaluedMap<String,String> qs, Properties data)
-
getAttributeBooleanMethodName
public static String getAttributeBooleanMethodName(String attributeName)
-
translateCamelCasedNamesToXMLNames
public static Map<String,String> translateCamelCasedNamesToXMLNames(Map<String,String> sourceData)
- Returns:
- A copy of given
sourceDatawhere key of each entry from it is converted to xml name
-
getResultType
public static String getResultType(jakarta.ws.rs.core.HttpHeaders requestHeaders)
-
buildMethodMetadataMap
public static Map buildMethodMetadataMap(MethodMetaData mmd)
-
isDeprecated
public static boolean isDeprecated(ConfigModel model)
-
getResourceLinks
public static Map<String,String> getResourceLinks(Dom dom, jakarta.ws.rs.core.UriInfo uriInfo, boolean canShowDeprecated)
-
getUnqualifiedTypeName
public static String getUnqualifiedTypeName(String qualifiedTypeName)
- Parameters:
qualifiedTypeName-- Returns:
- unqualified type name for given qualified type name. This is a substring of qualifiedTypeName after last "."
-
isOnlyATag
public static boolean isOnlyATag(ConfigModel model)
-
getRealChildConfigModels
public static List<ConfigModel> getRealChildConfigModels(ConfigModel childModel, DomDocument domDocument)
-
getResourceLinks
public static Map<String,String> getResourceLinks(List<Dom> proxyList, jakarta.ws.rs.core.UriInfo uriInfo)
-
getCommandLinks
public static List<Map<String,String>> getCommandLinks(String[][] commandResourcesPaths)
-
addMethodMetaData
public static void addMethodMetaData(ActionReport ar, Map<String,MethodMetaData> mmd)
-
getRestConfig
public static RestConfig getRestConfig(org.glassfish.hk2.api.ServiceLocator habitat)
-
canShowDeprecatedItems
public static boolean canShowDeprecatedItems(org.glassfish.hk2.api.ServiceLocator habitat)
-
authenticateViaAdminRealm
public static Subject authenticateViaAdminRealm(org.glassfish.hk2.api.ServiceLocator habitat, org.glassfish.grizzly.http.server.Request req, String remoteHost) throws LoginException, IOException
Authenticate the given req as originated from given remoteHost against admin realm.- Returns:
- subject identifying the user/client
- Throws:
LoginExceptionIOException
-
isAuthorized
public static boolean isAuthorized(org.glassfish.hk2.api.ServiceLocator habitat, Subject subject, String resource, String action) throws URISyntaxExceptionIndicates whether the subject can perform the action on the resource.- Parameters:
habitat- ServiceLocator for finding servicessubject- the Subject to be qualifiedresource- the resource affected by the actionaction- the action being attempted by the subject on the resource- Returns:
- true if the subject is allowed to perform the action, false otherwise
- Throws:
URISyntaxException
-
processJvmOptions
public static Map<String,String> processJvmOptions(Map<String,String> jvmOptions, boolean removeVersioning)
Creates a new rearranged map of JVM options. Optionstargetandprofilerare forwarded 1:1. All other options are joined in the result map for keyidand are separated by semi-colon. An input key may include a value. In such case key and value are divided by an equals sign:key=value. In case of an empty value the key may end with an equals sign:key=. If the value is given as part of the key the input value should be empty ornull. A value may itself contain equals signs. Keys ending with a backslash the backslash is stripped away. This is a backwards compatibility behaviour addressing remains of escaped equals sign that isn't properly unescaped prior to splitting in all path. The resulting option only uses an equals sign between key and value in case the value is non-empty. This is independent of whether the value was extracted from the input key or input value.- Parameters:
jvmOptions- a set of jvm options given as key-value pairs, keys are allowed to contain values tooremoveVersioning- settrueto erase any JVM version prefix from the keys,falseto keep keys as they are.- Returns:
- a map where most options are joined into one expression for key
id. If existingtargetandprofilerkeys are kept same as in input map.
-
-