Package org.opencastproject.util
Class RestUtil
java.lang.Object
org.opencastproject.util.RestUtil
Utility functions for REST endpoints.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic javax.ws.rs.core.Response.ResponseBuilderfileResponse(File f, String contentType, Optional<String> fileName) Create a file response.static StringgetEndpointUrl(org.osgi.service.component.ComponentContext cc) Return the endpoint's server URL and the service path by extracting the relevant parameters from the ComponentContext.getEndpointUrl(org.osgi.service.component.ComponentContext cc, String serverUrlKey, String servicePathKey) Return the endpoint's server URL and the service path by extracting the relevant parameters from the ComponentContext.static javax.ws.rs.core.MediaTypegetResponseType(String type) Return JSON iftype== json, XML else.static javax.ws.rs.core.Response.ResponseBuildercreate a partial file responsesplitCommaSeparatedParam(Optional<String> param) Split a comma separated request param into a list of trimmed strings discarding any blank parts.
-
Method Details
-
getEndpointUrl
Return the endpoint's server URL and the service path by extracting the relevant parameters from the ComponentContext.- Parameters:
cc- ComponentContext to get configuration from- Returns:
- (serverUrl, servicePath)
- Throws:
Error- if the service path is not configured for this component
-
getEndpointUrl
public static Tuple<String,String> getEndpointUrl(org.osgi.service.component.ComponentContext cc, String serverUrlKey, String servicePathKey) Return the endpoint's server URL and the service path by extracting the relevant parameters from the ComponentContext.- Parameters:
cc- ComponentContext to get configuration fromserverUrlKey- Configuration key for the server URLservicePathKey- Configuration key for the service path- Returns:
- (serverUrl, servicePath)
- Throws:
Error- if the service path is not configured for this component
-
fileResponse
public static javax.ws.rs.core.Response.ResponseBuilder fileResponse(File f, String contentType, Optional<String> fileName) Create a file response. -
partialFileResponse
public static javax.ws.rs.core.Response.ResponseBuilder partialFileResponse(File f, String contentType, Optional<String> fileName, String rangeHeader) throws IOException create a partial file response- Parameters:
f- the requested filecontentType- the contentType to sendfileName- the filename to sendrangeHeader- the range header- Returns:
- the Responsebuilder
- Throws:
IOException- if something goes wrong
-
getResponseType
Return JSON iftype== json, XML else. -
splitCommaSeparatedParam
Split a comma separated request param into a list of trimmed strings discarding any blank parts.x=comma,separated,,%20value -> ["comma", "separated", "value"]
-
generateErrorResponse
-