public class ResourceUtil extends Object
TemplateListOfResource
and
TemplateRestResource
Modifier and Type | Method and Description |
---|---|
static void |
addCommandLog(RestActionReporter ar,
String commandName,
ParameterMap parameters) |
static void |
addMethodMetaData(ActionReport ar,
Map<String,MethodMetaData> mmd) |
static void |
addQueryString(javax.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 void |
addQueryString(javax.ws.rs.core.MultivaluedMap<String,String> qs,
Properties data) |
static void |
adjustParameters(Map<String,String> data)
Adjust the input parameters.
|
static Subject |
authenticateViaAdminRealm(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 Map |
buildMethodMetadataMap(MethodMetaData mmd) |
static boolean |
canShowDeprecatedItems(org.glassfish.hk2.api.ServiceLocator habitat) |
static boolean |
commandIsPresent(org.glassfish.hk2.api.ServiceLocator habitat,
String commandName) |
static String |
convertToXMLName(String name) |
protected static void |
copyParameterMetaDataAttribute(ParameterMetaData from,
ParameterMetaData to,
String key) |
static void |
defineDefaultParameters(Map<String,String> data)
Adjust the input parameters.
|
static String |
encodeString(String text) |
static ActionReportResult |
getActionReportResult(ActionReport.ExitCode status,
String message,
javax.ws.rs.core.HttpHeaders requestHeaders,
javax.ws.rs.core.UriInfo uriInfo) |
static ActionReportResult |
getActionReportResult(RestActionReporter ar,
String message,
javax.ws.rs.core.HttpHeaders requestHeaders,
javax.ws.rs.core.UriInfo uriInfo) |
static String |
getAttributeBooleanMethodName(String attributeName) |
static String |
getAttributeMethodName(String attributeName) |
protected static byte[] |
getBytesFromStream(InputStream is) |
static String |
getCommand(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 javax.ws.rs.core.Response |
getDeleteResponse(int status,
String message,
javax.ws.rs.core.HttpHeaders requestHeaders,
javax.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
|
protected static void |
getInterfaces(Class<?> clazz,
List<Class<?>> interfaces) |
static MethodMetaData |
getMethodMetaData(ConfigModel configBeanModel)
Constructs and returns the resource method meta-data.
|
static MethodMetaData |
getMethodMetaData(String command,
Map<String,String> commandParamsToSkip,
org.glassfish.hk2.api.ServiceLocator habitat)
Constructs and returns the resource method meta-data.
|
static MethodMetaData |
getMethodMetaData(String command,
org.glassfish.hk2.api.ServiceLocator habitat)
Constructs and returns the resource method meta-data.
|
static MethodMetaData |
getMethodMetaData2(Dom parent,
ConfigModel childModel,
int parameterType) |
static String |
getParameterList(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(Dom dom,
javax.ws.rs.core.UriInfo uriInfo,
boolean canShowDeprecated) |
static Map<String,String> |
getResourceLinks(List<Dom> proxyList,
javax.ws.rs.core.UriInfo uriInfo) |
static javax.ws.rs.core.Response |
getResponse(int status,
String message,
javax.ws.rs.core.HttpHeaders requestHeaders,
javax.ws.rs.core.UriInfo uriInfo)
Constructs and returns the appropriate response object based on the
client.
|
static RestConfig |
getRestConfig(org.glassfish.hk2.api.ServiceLocator habitat) |
static String |
getResultType(javax.ws.rs.core.HttpHeaders requestHeaders) |
static String |
getUnqualifiedTypeName(String qualifiedTypeName) |
static boolean |
isAuthorized(org.glassfish.hk2.api.ServiceLocator habitat,
Subject subject,
String resource,
String action)
Indicates whether the subject can perform the action on the resource.
|
static boolean |
isDeprecated(ConfigModel model) |
static boolean |
isOnlyATag(ConfigModel model) |
static Map<String,String> |
processJvmOptions(Map<String,String> jvmOptions,
boolean removeVersioning)
Creates a new rearranged map of JVM options.
|
static void |
purgeEmptyEntries(Map<String,String> data)
Removes entries with empty value from the given Map
|
static void |
resolveParamValues(Map<String,String> commandParams,
javax.ws.rs.core.UriInfo uriInfo) |
static RestActionReporter |
runCommand(String commandName,
Map<String,String> parameters,
Subject subject)
Executes the specified __asadmin command.
|
static RestActionReporter |
runCommand(String commandName,
ParameterMap parameters,
Subject subject)
Executes the specified __asadmin command.
|
static RestActionReporter |
runCommand(String commandName,
ParameterMap parameters,
Subject subject,
boolean managedJob)
Executes the specified __asadmin command.
|
static org.glassfish.jersey.media.sse.EventOutput |
runCommandWithSse(String commandName,
ParameterMap parameters,
Subject subject,
SseCommandHelper.ActionReportProcessor processor) |
static Map<String,String> |
translateCamelCasedNamesToXMLNames(Map<String,String> sourceData) |
protected static byte[] getBytesFromStream(InputStream is)
public static void adjustParameters(Map<String,String> data)
public static void defineDefaultParameters(Map<String,String> data)
public static String getCommand(RestRedirect.OpType type, ConfigModel model)
type
- the given resource operationpublic static RestActionReporter runCommand(String commandName, ParameterMap parameters, Subject subject)
commandName
- parameters
- subject
- public static RestActionReporter runCommand(String commandName, ParameterMap parameters, Subject subject, boolean managedJob)
commandName
- parameters
- subject
- managedJob
- public static RestActionReporter runCommand(String commandName, Map<String,String> parameters, Subject subject)
commandName
- the command to executeparameters
- the command parameterssubject
- Subjectpublic static org.glassfish.jersey.media.sse.EventOutput runCommandWithSse(String commandName, ParameterMap parameters, Subject subject, SseCommandHelper.ActionReportProcessor processor)
public static void addCommandLog(RestActionReporter ar, String commandName, ParameterMap parameters)
public static String getParameterList(ParameterMap parameters)
public static MethodMetaData getMethodMetaData(String command, org.glassfish.hk2.api.ServiceLocator habitat)
command
- the command associated with the resource methodhabitat
- the habitatpublic static MethodMetaData getMethodMetaData(String command, Map<String,String> commandParamsToSkip, org.glassfish.hk2.api.ServiceLocator habitat)
command
- the command associated with the resource methodcommandParamsToSkip
- the command parameters for which not to
include the meta-data.habitat
- the habitatpublic static void resolveParamValues(Map<String,String> commandParams, javax.ws.rs.core.UriInfo uriInfo)
public static MethodMetaData getMethodMetaData(ConfigModel configBeanModel)
configBeanModel
- the config bean associated with the resource.public static MethodMetaData getMethodMetaData2(Dom parent, ConfigModel childModel, int parameterType)
protected static void copyParameterMetaDataAttribute(ParameterMetaData from, ParameterMetaData to, String key)
public static boolean commandIsPresent(org.glassfish.hk2.api.ServiceLocator habitat, String commandName)
public static Collection<CommandModel.ParamModel> getParamMetaData(String commandName, org.glassfish.hk2.api.ServiceLocator habitat)
commandName
- the command associated with the resource methodhabitat
- the habitatpublic static Collection<CommandModel.ParamModel> getParamMetaData(String commandName, Collection<String> commandParamsToSkip, org.glassfish.hk2.api.ServiceLocator habitat)
commandName
- the command associated with the resource methodcommandParamsToSkip
- the command parameters for which not to
include the meta-data.habitat
- the habitatpublic static void purgeEmptyEntries(Map<String,String> data)
data
- data to remove empty entries frompublic static javax.ws.rs.core.Response getResponse(int status, String message, javax.ws.rs.core.HttpHeaders requestHeaders, javax.ws.rs.core.UriInfo uriInfo)
status
- the http status code for the responsemessage
- message for the responserequestHeaders
- request headers of the requestpublic static ActionReportResult getActionReportResult(ActionReport.ExitCode status, String message, javax.ws.rs.core.HttpHeaders requestHeaders, javax.ws.rs.core.UriInfo uriInfo)
public static ActionReportResult getActionReportResult(RestActionReporter ar, String message, javax.ws.rs.core.HttpHeaders requestHeaders, javax.ws.rs.core.UriInfo uriInfo)
public static javax.ws.rs.core.Response getDeleteResponse(int status, String message, javax.ws.rs.core.HttpHeaders requestHeaders, javax.ws.rs.core.UriInfo uriInfo)
status
- message
- requestHeaders
- uriInfo
- public static void addQueryString(javax.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=true
The reason we need to use query parameters versus "body" variables is the limitation that HttpURLConnection has in this regard.
data
- public static void addQueryString(javax.ws.rs.core.MultivaluedMap<String,String> qs, Properties data)
public static String getAttributeBooleanMethodName(String attributeName)
public static Map<String,String> translateCamelCasedNamesToXMLNames(Map<String,String> sourceData)
sourceData
where key of each entry from it is converted to
xml namepublic static String getResultType(javax.ws.rs.core.HttpHeaders requestHeaders)
public static Map buildMethodMetadataMap(MethodMetaData mmd)
public static boolean isDeprecated(ConfigModel model)
public static Map<String,String> getResourceLinks(Dom dom, javax.ws.rs.core.UriInfo uriInfo, boolean canShowDeprecated)
public static String getUnqualifiedTypeName(String qualifiedTypeName)
qualifiedTypeName
- public static boolean isOnlyATag(ConfigModel model)
public static List<ConfigModel> getRealChildConfigModels(ConfigModel childModel, DomDocument domDocument)
public static Map<String,String> getResourceLinks(List<Dom> proxyList, javax.ws.rs.core.UriInfo uriInfo)
public static List<Map<String,String>> getCommandLinks(String[][] commandResourcesPaths)
public static void addMethodMetaData(ActionReport ar, Map<String,MethodMetaData> mmd)
public static RestConfig getRestConfig(org.glassfish.hk2.api.ServiceLocator habitat)
public static boolean canShowDeprecatedItems(org.glassfish.hk2.api.ServiceLocator habitat)
public static Subject authenticateViaAdminRealm(org.glassfish.hk2.api.ServiceLocator habitat, org.glassfish.grizzly.http.server.Request req, String remoteHost) throws LoginException, IOException
LoginException
IOException
public static boolean isAuthorized(org.glassfish.hk2.api.ServiceLocator habitat, Subject subject, String resource, String action) throws URISyntaxException
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 resourceURISyntaxException
public static Map<String,String> processJvmOptions(Map<String,String> jvmOptions, boolean removeVersioning)
target
and profiler
are forwarded 1:1. All
other options are joined in the result map for key id
and 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 or null
. 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.jvmOptions
- a set of jvm options given as key-value pairs, keys are allowed to contain values tooremoveVersioning
- set true
to erase any JVM version prefix from the keys, false
to keep
keys as they are.id
. If existing target
and profiler
keys are kept same as in input map.Copyright © 2019. All rights reserved.