public class RestApiUtil extends Object
| Constructor and Description |
|---|
RestApiUtil() |
| Modifier and Type | Method and Description |
|---|---|
static ForbiddenException |
buildAuthorizationFailedException(String description)
Returns a new ForbiddenException
|
static BadRequestException |
buildBadRequestException(String description)
Returns a new BadRequestException
|
static ConflictException |
buildConflictException(String description)
Returns a new ConflictException
|
static ForbiddenException |
buildForbiddenException(String description)
Returns a new ConflictException
|
static InternalServerErrorException |
buildInternalServerErrorException()
Returns a new InternalServerErrorException
|
static NotFoundException |
buildNotFoundException(String resource,
String id)
Returns a new NotFoundException
|
static PreconditionFailedException |
buildPreconditionFailedRequestException(String description)
Returns a new BadRequestException
|
static String |
getAPIPaginatedURL(Integer offset,
Integer limit)
Returns the paginated url for APIs API
|
static String |
getAPIPaginatedURL(Integer offset,
Integer limit,
String query)
Returns the paginated url for APIs API
|
static String |
getAppRatingPaginatedURL(Integer offset,
Integer limit)
Returns the paginated url for APIs API
|
static <T> ErrorDTO |
getConstraintViolationErrorDTO(Set<javax.validation.ConstraintViolation<T>> violations) |
static org.wso2.carbon.appmgt.api.APIConsumer |
getConsumer(String subscriberName) |
static ErrorDTO |
getErrorDTO(String message,
Long code,
String description)
Returns a generic errorDTO
|
static org.wso2.carbon.appmgt.api.APIConsumer |
getLoggedInUserConsumer()
Returns an APIConsumer which is corresponding to the current logged in user taken from the carbon context
|
static String |
getLoggedInUsername() |
static org.wso2.carbon.appmgt.api.APIProvider |
getLoggedInUserProvider() |
static String |
getLoggedInUserTenantDomain() |
static Map<String,Integer> |
getPaginationParams(Integer offset,
Integer limit,
Integer size)
Returns the next/previous offset/limit parameters properly when current offset, limit and size parameters are
specified
|
static org.wso2.carbon.appmgt.api.APIProvider |
getProvider(String username) |
static Map<String,String> |
getSearchTerms(String query)
Returns the seach terms of the given query string.
|
static String |
getStoreRESTAPIContextPath()
Get Store REST API context path
|
static Dictionary<org.wso2.uri.template.URITemplate,List<String>> |
getWhiteListedURIsToMethodsMap()
Returns the white-listed URIs and associated HTTP methods for REST API.
|
static void |
handleAuthorizationFailedError(String description,
Throwable t,
org.apache.commons.logging.Log log)
Logs the error, builds a NotFoundException with specified details and throws it
|
static void |
handleBadRequest(String msg,
org.apache.commons.logging.Log log)
Logs the error, builds a BadRequestException with specified details and throws it
|
static void |
handleConflictException(String msg,
org.apache.commons.logging.Log log)
Logs the error, builds a BadRequestException with specified details and throws it
|
static void |
handleForbiddenRequest(String msg,
org.apache.commons.logging.Log log)
Logs the error, builds a BadRequestException with specified details and throws it
|
static void |
handleInternalServerError(String msg,
org.apache.commons.logging.Log log)
Logs the error, builds a internalServerErrorException with specified details and throws it
|
static void |
handleInternalServerError(String msg,
Throwable t,
org.apache.commons.logging.Log log)
Logs the error, builds a internalServerErrorException with specified details and throws it
|
static void |
handlePreconditionFailedRequest(String msg,
org.apache.commons.logging.Log log)
Logs the error, builds a BadRequestException with specified details and throws it
|
static void |
handleResourceNotFoundError(String resource,
String id,
org.apache.commons.logging.Log log)
Logs the error, builds a NotFoundException with specified details and throws it
|
static void |
handleResourceNotFoundError(String resource,
String id,
Throwable t,
org.apache.commons.logging.Log log)
Logs the error, builds a NotFoundException with specified details and throws it
|
static boolean |
isDueToAuthorizationFailure(Throwable e)
Check if the specified throwable e is due to an authorization failure
|
static boolean |
isDueToResourceAlreadyExisting(Throwable e)
Check if the specified throwable e is happened as the required resource cannot be found
|
static boolean |
isDueToResourceNotFound(Throwable e)
Check if the specified throwable e is happened as the required resource cannot be found
|
static boolean |
isExistingRole(String roleName) |
static boolean |
isExistingUser(String username) |
static boolean |
isSubscriptionEnable() |
static boolean |
isURL(String url)
Url validator, Allow any url with https and http.
|
static boolean |
isUUID(String apiId)
Check whether the specified apiId is of type UUID
|
static boolean |
isValidFileName(String fileName) |
static String |
readFileContentType(String filePath) |
static File |
readFileFromStorage(String fileName) |
static void |
transferFile(InputStream uploadedInputStream,
String newFileName,
String storageLocation)
This method uploads a given file to specified location
|
public static <T> ErrorDTO getConstraintViolationErrorDTO(Set<javax.validation.ConstraintViolation<T>> violations)
public static org.wso2.carbon.appmgt.api.APIProvider getLoggedInUserProvider()
throws org.wso2.carbon.appmgt.api.AppManagementException
org.wso2.carbon.appmgt.api.AppManagementExceptionpublic static String getLoggedInUsername()
public static org.wso2.carbon.appmgt.api.APIProvider getProvider(String username) throws org.wso2.carbon.appmgt.api.AppManagementException
org.wso2.carbon.appmgt.api.AppManagementExceptionpublic static org.wso2.carbon.appmgt.api.APIConsumer getConsumer(String subscriberName) throws org.wso2.carbon.appmgt.api.AppManagementException
org.wso2.carbon.appmgt.api.AppManagementExceptionpublic static org.wso2.carbon.appmgt.api.APIConsumer getLoggedInUserConsumer()
throws org.wso2.carbon.appmgt.api.AppManagementException
org.wso2.carbon.appmgt.api.AppManagementExceptionpublic static boolean isURL(String url)
url - Url as stringpublic static void handleBadRequest(String msg, org.apache.commons.logging.Log log) throws BadRequestException
msg - error messagelog - Log instanceBadRequestExceptionpublic static void handleConflictException(String msg, org.apache.commons.logging.Log log) throws ConflictException
msg - error messagelog - Log instanceBadRequestExceptionConflictExceptionpublic static void handleForbiddenRequest(String msg, org.apache.commons.logging.Log log) throws ForbiddenException
msg - error messagelog - Log instanceBadRequestExceptionForbiddenExceptionpublic static void handlePreconditionFailedRequest(String msg, org.apache.commons.logging.Log log) throws BadRequestException
msg - error messagelog - Log instanceBadRequestExceptionpublic static BadRequestException buildBadRequestException(String description)
description - description of the exceptionpublic static ConflictException buildConflictException(String description)
description - description of the exceptionpublic static ForbiddenException buildForbiddenException(String description)
description - description of the exceptionpublic static PreconditionFailedException buildPreconditionFailedRequestException(String description)
description - description of the exceptionpublic static ErrorDTO getErrorDTO(String message, Long code, String description)
message - specifies the error messagepublic static String getAPIPaginatedURL(Integer offset, Integer limit, String query)
offset - starting indexlimit - max number of objects returnedquery - search query valuepublic static String getAPIPaginatedURL(Integer offset, Integer limit)
offset - starting indexlimit - max number of objects returnedpublic static String getAppRatingPaginatedURL(Integer offset, Integer limit)
offset - starting indexlimit - max number of objects returnedpublic static Map<String,Integer> getPaginationParams(Integer offset, Integer limit, Integer size)
offset - current starting indexlimit - current max recordssize - maximum index possiblepublic static void handleInternalServerError(String msg, Throwable t, org.apache.commons.logging.Log log) throws InternalServerErrorException
msg - error messaget - Throwable instancelog - Log instanceInternalServerErrorExceptionpublic static void handleInternalServerError(String msg, org.apache.commons.logging.Log log) throws InternalServerErrorException
msg - error messagelog - Log instanceInternalServerErrorExceptionpublic static InternalServerErrorException buildInternalServerErrorException()
public static String getLoggedInUserTenantDomain()
public static boolean isDueToResourceNotFound(Throwable e)
e - throwable to checkpublic static boolean isDueToResourceAlreadyExisting(Throwable e)
e - throwable to checkpublic static boolean isDueToAuthorizationFailure(Throwable e)
e - throwable to checkpublic static void handleResourceNotFoundError(String resource, String id, Throwable t, org.apache.commons.logging.Log log) throws NotFoundException
resource - requested resourceid - id of resourcet - Throwable instancelog - Log instanceNotFoundExceptionpublic static void handleResourceNotFoundError(String resource, String id, org.apache.commons.logging.Log log) throws NotFoundException
resource - requested resourceid - id of resourcelog - Log instanceNotFoundExceptionpublic static void handleAuthorizationFailedError(String description, Throwable t, org.apache.commons.logging.Log log) throws ForbiddenException
description - error descriptiont - Throwable instancelog - Log instanceNotFoundExceptionForbiddenExceptionpublic static NotFoundException buildNotFoundException(String resource, String id)
resource - Resource typeid - identifier of the resourcepublic static ForbiddenException buildAuthorizationFailedException(String description)
description - Error descriptionpublic static boolean isUUID(String apiId)
apiId - api identifierpublic static void transferFile(InputStream uploadedInputStream, String newFileName, String storageLocation) throws org.wso2.carbon.appmgt.api.AppManagementException
uploadedInputStream - input stream of the filenewFileName - name of the file to be createdstorageLocation - destination of the new fileorg.wso2.carbon.appmgt.api.AppManagementException - if the file transfer failspublic static File readFileFromStorage(String fileName) throws org.wso2.carbon.appmgt.api.AppManagementException
org.wso2.carbon.appmgt.api.AppManagementExceptionpublic static boolean isValidFileName(String fileName)
public static String readFileContentType(String filePath) throws org.wso2.carbon.appmgt.api.AppManagementException
org.wso2.carbon.appmgt.api.AppManagementExceptionpublic static boolean isExistingUser(String username)
public static boolean isExistingRole(String roleName)
public static boolean isSubscriptionEnable()
public static Map<String,String> getSearchTerms(String query)
query - public static Dictionary<org.wso2.uri.template.URITemplate,List<String>> getWhiteListedURIsToMethodsMap() throws org.wso2.carbon.appmgt.api.AppManagementException
org.wso2.carbon.appmgt.api.AppManagementExceptionpublic static String getStoreRESTAPIContextPath()
Copyright © 2017 WSO2. All rights reserved.