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, Option<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.MediaTypegetResponseFormat(String format) Deprecated.static javax.ws.rs.core.MediaTypegetResponseType(String type) Return JSON iftype== json, XML else.static javax.ws.rs.core.Response.ResponseBuildercreate a partial file responsestatic Monadics.ListMonadic<String> splitCommaSeparatedParam(Option<String> param) Split a comma separated request param into a list of trimmed strings discarding any blank parts.static javax.ws.rs.core.Response.ResponseBuilderstreamResponse(InputStream in, String contentType, Option<Long> streamLength, Option<String> fileName)
-
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, Option<String> fileName) Create a file response. -
partialFileResponse
public static javax.ws.rs.core.Response.ResponseBuilder partialFileResponse(File f, String contentType, Option<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
-
streamResponse
@Deprecated public static javax.ws.rs.core.Response.ResponseBuilder streamResponse(InputStream in, String contentType, Option<Long> streamLength, Option<String> fileName) Deprecated.Create a stream response. -
getResponseFormat
Deprecated.Return JSON ifformat== json, XML else. -
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
-
getResponseType(String)