コード例 #1
0
 /**
  * Finds and uploads interval on a channel, based on channel and interval, to the FtpServer as a
  * file with requested filename. Sends back a response with a status code based on whether or not
  * it was successful. Status codes: 200: OK. 400: Bad information in url. 404: Content not
  * available in main archive. Try again later. 409: A file with chosen filename already exists on
  * FtpServer. 410: Content not available. 500: Internal server error or unexpected status code.
  *
  * @param channel Which channel
  * @param filename Wanted filename
  * @param fromRaw from when, format: yyyy-MM-dd_HH:mm:ss
  * @param toRaw to when, format: yyyy-MM-dd_HH:mm:ss
  * @return Status code in Response and requested file on FtpServer.
  */
 @GET
 @Path("rawCut")
 @Produces("text/plain")
 public Response rawCut(
     @QueryParam("channel") String channel,
     @QueryParam("filename") String filename,
     @QueryParam("from") String fromRaw,
     @QueryParam("to") String toRaw) {
   if (channel == null
       || channel.trim().length() == 0
       || filename == null
       || filename.trim().length() == 0) {
     String text = "Bad information in url. Make sure to set channel, filename, from and to.";
     log.info("-----------rawCut first opportunity exit with 400---------------");
     return Response.status(400).entity(text).build();
   }
   Date from = null;
   Date to = null;
   if (fromRaw != null
       && fromRaw.trim().length() > 0
       && toRaw != null
       && toRaw.trim().length() > 0) {
     DateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
     try {
       from = format.parse(fromRaw);
       to = format.parse(toRaw);
     } catch (ParseException ex) {
       log.debug("Date parse error: From: " + fromRaw + " | To: " + toRaw);
       log.debug("Date parse error stacktrace: " + ex.getStackTrace());
       String text =
           "Failed to parse dates, make sure it is of following format: yyyy-MM-dd_HH:mm:ss";
       return Response.status(400).entity(text).build();
     }
   } else {
     String text = "Bad information in url. Make sure to set channel, filename, from and to.";
     log.info("-----------rawCut second opportunity exit with 400---------------");
     return Response.status(400).entity(text).build();
   }
   if (from.after(to)) {
     return Response.status(400).entity("From must be before To.").build();
   }
   try {
     int statusCode = service.getRawCut(channel, filename, from, to);
     if (statusCode == 200) {
       String text = "OK";
       log.info("-----------rawCut exit with 200---------------" + statusCode);
       return Response.status(statusCode).entity(text).build();
     }
     if (statusCode == 400) {
       String text = "Bad information in url (for instance, unknown channel id)";
       log.info("-----------rawCut exit with 400---------------" + statusCode);
       return Response.status(statusCode).entity(text).build();
     }
     if (statusCode == 404) {
       String text =
           "Content unavailable on primary archive server, but exists on secondary. Try later.";
       log.info("-----------rawCut exit with 404---------------" + statusCode);
       return Response.status(statusCode).entity(text).build();
     }
     if (statusCode == 409) {
       String text = "A file with that filename already exists.";
       log.info("-----------rawCut exit with 409---------------" + statusCode);
       return Response.status(statusCode).entity(text).build();
     }
     if (statusCode == 410) {
       String text = "Content unavailable, request cannot be fulfilled.";
       log.info("-----------rawCut exit with 410---------------" + statusCode);
       return Response.status(statusCode).entity(text).build();
     }
     log.info(
         "-----------rawCut exit with 500, unexpected status code---------------" + statusCode);
     return Response.status(500)
         .entity("Unexpected status code.")
         .build(); // Unexpected status code
   } catch (ServiceException ex) {
     log.info(
         "-----------rawCut exit with 500, internal server---------------" + ex.getMessage(), ex);
     return Response.status(500).entity("Internal server error.").build();
   }
 }
コード例 #2
0
 /**
  * Finds and uploads a program, based on id and offsets, to the FtpServer as a file with requested
  * filename, along with PBCore xml about the program. Sends back a response with a status code
  * based on whether or not it was successful. Status codes: 200: OK. 400: Bad information in url.
  * 404: Content not available in main archive. Try again later. 409: A file with chosen filename
  * already exists on FtpServer. 410: Content not available. 500: Internal server error or
  * unexpected status code.
  *
  * @param programIdRaw Id of the program.
  * @param filename Wanted filename.
  * @param offsetStartRaw Offset from start of the program in HH:mm:ss format.
  * @param offsetEndRaw Offset from end of the program in HH:mm:ss format.
  * @return Status code in Response and requested file and associated PBCore xml on FtpServer.
  */
 @GET
 @Path("programSnippet")
 @Produces("text/plain")
 public Response programSnippet(
     @QueryParam("id") String programIdRaw,
     @QueryParam("filename") String filename,
     @QueryParam("offsetStart") String offsetStartRaw,
     @QueryParam("offsetEnd") String offsetEndRaw) {
   if (programIdRaw == null
       || programIdRaw.trim().length() == 0
       || filename == null
       || filename.trim().length() == 0) {
     String text = "Bad information in url. Make sure to set id, filename and offsets.";
     log.info("-----------programSnippet first opportunity exit with 400---------------");
     return Response.status(400).entity(text).build();
   }
   Date offsetStart = null;
   Date offsetEnd = null;
   if (offsetStartRaw != null
       && offsetStartRaw.trim().length() > 0
       && offsetEndRaw != null
       && offsetEndRaw.trim().length() > 0) {
     DateFormat format = new SimpleDateFormat("HH:mm:ss");
     try {
       offsetStart = format.parse(offsetStartRaw);
       offsetEnd = format.parse(offsetEndRaw);
     } catch (ParseException ex) {
       log.debug("Date parse error: From: " + offsetStartRaw + " | To: " + offsetEndRaw);
       log.debug("Date parse error stacktrace: " + ex.getStackTrace());
       String text = "Failed to parse offsets, make sure it is of following format: HH:mm:ss";
       return Response.status(400).entity(text).build();
     }
   } else {
     String text = "Bad information in url. Make sure to set id, filename and offsets.";
     log.info("-----------programSnippet second opportunity exit with 400---------------");
     return Response.status(400).entity(text).build();
   }
   try {
     Long programId = Long.parseLong(programIdRaw);
     try {
       int statusCode = service.getProgramSnippet(programId, filename, offsetStart, offsetEnd);
       if (statusCode == 200) {
         String text = "OK";
         log.info("-----------programSnippet exit with 200---------------" + statusCode);
         return Response.status(statusCode).entity(text).build();
       }
       if (statusCode == 400) {
         String text = "Bad information in url (for instance, unknown channel id)";
         log.info("-----------programSnippet exit with 400---------------" + statusCode);
         return Response.status(statusCode).entity(text).build();
       }
       if (statusCode == 404) {
         String text =
             "Content unavailable on primary archive server, but exists on secondary. Try later.";
         log.info("-----------programSnippet exit with 404---------------" + statusCode);
         return Response.status(statusCode).entity(text).build();
       }
       if (statusCode == 409) {
         String text = "A file with that filename already exists.";
         log.info("-----------programSnippet exit with 409---------------" + statusCode);
         return Response.status(statusCode).entity(text).build();
       }
       if (statusCode == 410) {
         String text = "Content unavailable, request cannot be fulfilled.";
         log.info("-----------programSnippet exit with 410---------------" + statusCode);
         return Response.status(statusCode).entity(text).build();
       }
       if (statusCode == -0) {
         String text = "Program id not found.";
         log.info("-----------programSnippet exit with 410---------------" + statusCode);
         return Response.status(410).entity(text).build();
       }
       log.info(
           "-----------programSnippet exit with 500, unexpected status code---------------"
               + statusCode);
       return Response.status(500)
           .entity("Unexpected status code.")
           .build(); // Unexpected status code
     } catch (ServiceException ex) {
       log.info(
           "-----------programSnippet exit with 500, internal server---------------"
               + ex.getMessage(),
           ex);
       return Response.status(500).entity("Internal server error.").build();
     }
   } catch (NumberFormatException ex) {
     log.info("-----------programSnippet exit with 400, invalid program id---------------");
     return Response.status(400).entity("Invalid program id, must only contain numbers.").build();
   }
 }