Class RestUtil

java.lang.Object
org.opencastproject.util.RestUtil

public final class RestUtil extends Object
Utility functions for REST endpoints.
  • Method Details

    • getEndpointUrl

      public static Tuple<String,String> getEndpointUrl(org.osgi.service.component.ComponentContext cc)
      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 from
      serverUrlKey - Configuration key for the server URL
      servicePathKey - 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 file
      contentType - the contentType to send
      fileName - the filename to send
      rangeHeader - 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)
      Create a stream response.
    • getResponseFormat

      @Deprecated public static javax.ws.rs.core.MediaType getResponseFormat(String format)
      Deprecated.
      Return JSON if format == json, XML else.
    • getResponseType

      public static javax.ws.rs.core.MediaType getResponseType(String type)
      Return JSON if type == json, XML else.
    • splitCommaSeparatedParam

      public static Monadics.ListMonadic<String> splitCommaSeparatedParam(Option<String> param)
      Split a comma separated request param into a list of trimmed strings discarding any blank parts.

      x=comma,separated,,%20value -> ["comma", "separated", "value"]

    • generateErrorResponse

      public static String generateErrorResponse(ErrorCodeException e)