@Test
 public void testNormalizeString() {
   assertEquals("/something", RequestUtil.normalize("//something"));
   assertEquals("/some/thing", RequestUtil.normalize("some//thing"));
   assertEquals("/something/", RequestUtil.normalize("something//"));
   assertEquals("/", RequestUtil.normalize("//"));
 }
示例#2
0
 public void sendBookingConfirmation(HttpServletRequest request, Booking booking)
     throws MailException, IOException {
   Mail mail = new Mail();
   mail.setSubject(msg.get("BookingSuccessfulMailSubject"));
   mail.setBody(
       msg.get(
           "BookingSuccessfulMailBody",
           new Object[] {
             booking.getPlayer().toString(),
             FormatUtils.DATE_MEDIUM.print(booking.getBookingDate()),
             FormatUtils.TIME_HUMAN_READABLE.print(booking.getBookingTime()),
             booking.getName(),
             msg.get(booking.getPaymentMethod().toString()),
             booking.getAmount(),
             booking.getCurrency(),
             CANCELLATION_POLICY_DEADLINE,
             RequestUtil.getBaseURL(request)
                 + "/bookings/booking/"
                 + booking.getUUID()
                 + "/cancel",
             RequestUtil.getBaseURL(request) + "/invoices/booking/" + booking.getUUID(),
             RequestUtil.getBaseURL(request)
           }));
   mail.addRecipient(booking.getPlayer());
   mailUtils.send(mail, request);
 }
示例#3
0
 private Object[] getDetailBody(HttpServletRequest request, Booking booking) {
   return new Object[] {
     booking.getPlayer().toString(),
     FormatUtils.DATE_HUMAN_READABLE.print(booking.getBookingDate()),
     FormatUtils.TIME_HUMAN_READABLE.print(booking.getBookingTime()),
     booking.getName(),
     msg.get(booking.getPaymentMethod().toString()),
     booking.getAmount(),
     booking.getCurrency(),
     RequestUtil.getBaseURL(request) + "/invoices/booking/" + booking.getUUID(),
     RequestUtil.getBaseURL(request) + "/admin/reports/booking/" + booking.getId()
   };
 }
 public HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
   ResteasyRequestWrapper requestWrapper =
       RequestUtil.getRequestWrapper(request, request.getMethod(), prefix);
   try {
     // NOTE: if invoker isn't found, RESTEasy throw NoReourceFoundFailure
     HttpRequest httpRequest = requestWrapper.getHttpRequest();
     if (!httpRequest.isInitial()) {
       String message =
           httpRequest.getUri().getPath()
               + " is not initial request.  Its suspended and retried.  Aborting.";
       logger.error(message);
       requestWrapper.setError(500, message);
     } else {
       Response response = dispatcher.preprocess(httpRequest);
       if (response != null) {
         requestWrapper.setAbortedResponse(response);
       } else {
         requestWrapper.setInvoker(getInvoker(httpRequest));
       }
     }
     return new HandlerExecutionChain(requestWrapper, interceptors);
   } catch (NotFoundException e) {
     if (throwNotFound) {
       throw e;
     }
     logger.error("Resource Not Found: " + e.getMessage(), e);
   } catch (Failure e) {
     logger.error("ResourceFailure: " + e.getMessage(), e);
     throw e;
   }
   return null;
 }
示例#5
0
 @RequestMapping(value = "/teacher/password", method = RequestMethod.PUT)
 @ResponseBody
 public JSONObject changePasswd(@RequestBody JSONObject teacher) throws SQLException {
   teacher.put("tch_passwd", MD5.string2md5(teacher.getString("tch_passwd")));
   teacherService.updatePasswd(teacher);
   return RequestUtil.make_ret();
 }
  public static <T> T process(
      RequestMethod method,
      String path,
      Class<T> clazz,
      String className,
      Resource classObj,
      GenericParams params)
      throws ZSAPIException {
    Response response = handleRequest(method, path, classObj, clazz, params);
    if (method == RequestMethod.DELETE) {
      // No body
      return null;
    }

    try {
      Object body = response.getBody();
      if (!(body instanceof String)) {
        return (T) response;
      }
      ObjectMapper mapper = RequestUtil.getMapper();
      JsonNode root = mapper.readTree((String) body);
      JsonNode dataNode =
          root.get(className != null ? className : clazz.getSimpleName().toLowerCase());
      if (dataNode == null) {
        return null;
      }
      return mapper.readValue(dataNode.toString(), clazz);
    } catch (Exception e) {
      throw new ZSAPIException(e);
    }
  }
  public static Response handleRequest(
      RequestMethod method, String path, Resource classObj, Class clazz, GenericParams params)
      throws ZSAPIException {
    Response response = RequestUtil.request(method, path, classObj, clazz, params);

    if (response.isError()) {
      // Will throw Exception
      handleError(response);
    }
    return response;
  }
  @Test
  public void testURLDecodeStringInvalid() {
    // %n rather than %nn should throw an IAE according to the Javadoc
    Exception exception = null;
    try {
      RequestUtil.URLDecode("%5xxxxx");
    } catch (Exception e) {
      exception = e;
    }
    assertTrue(exception instanceof IllegalArgumentException);

    // Edge case trying to trigger ArrayIndexOutOfBoundsException
    exception = null;
    try {
      RequestUtil.URLDecode("%5");
    } catch (Exception e) {
      exception = e;
    }
    assertTrue(exception instanceof IllegalArgumentException);
  }
 private static void handleError(Response response) throws ZSAPIException {
   ResourceUtil.Error e = null;
   try {
     ObjectMapper mapper = RequestUtil.getMapper();
     e = mapper.readValue((String) response.getBody(), ResourceUtil.Error.class);
     throw new ZSAPIException(e.code, e.message);
   } catch (JsonProcessingException jsonex) {
     throw new ZSAPIException(jsonex);
   } catch (IOException ioe) {
     throw new ZSAPIException(ioe);
   }
 }
 @GET
 @Path("/")
 @Produces(APPLICATION_JSON)
 @ApiOperation(value = "Get triggers with optional filtering")
 @ApiResponses(
     value = {
       @ApiResponse(code = 200, message = "Success"),
       @ApiResponse(code = 500, message = "Internal server error")
     })
 public Response findTriggers(
     @ApiParam(
             required = false,
             value =
                 "filter out triggers for unspecified triggerIds, "
                     + "comma separated list of trigger IDs")
         @QueryParam("triggerIds")
         final String triggerIds,
     @ApiParam(
             required = false,
             value =
                 "filter out triggers for unspecified tags, comma separated list of "
                     + "tags, each tag of format 'name|value'. Specify '*' for value to match all values.")
         @QueryParam("tags")
         final String tags,
     @ApiParam(required = false, value = "return only thin triggers. Currently Ignored")
         @QueryParam("thin")
         final Boolean thin,
     @Context final UriInfo uri) {
   Pager pager = RequestUtil.extractPaging(uri);
   try {
     TriggersCriteria criteria = buildCriteria(triggerIds, tags, thin);
     Page<Trigger> triggerPage = definitions.getTriggers(tenantId, criteria, pager);
     if (log.isDebugEnabled()) {
       log.debug("Triggers: " + triggerPage);
     }
     if (isEmpty(triggerPage)) {
       return ResponseUtil.ok(triggerPage);
     }
     return ResponseUtil.paginatedOk(triggerPage, uri);
   } catch (Exception e) {
     log.debug(e.getMessage(), e);
     return ResponseUtil.internalError(e.getMessage());
   }
 }
  @Test
  public void testURLDecodeStringValidIso88591End() {

    String result = RequestUtil.URLDecode("xxxx%41", "ISO-8859-1");
    assertEquals("xxxxA", result);
  }
  @Test
  public void testURLDecodeStringValidIso88591Start() {

    String result = RequestUtil.URLDecode("%41xxxx", "ISO-8859-1");
    assertEquals("Axxxx", result);
  }
示例#13
0
 @RequestMapping(value = "/teacher", method = RequestMethod.PUT)
 @ResponseBody
 public JSONObject updateTeacher(@RequestBody JSONObject teacher) throws SQLException {
   teacherService.update(teacher);
   return RequestUtil.make_ret();
 }
示例#14
0
 @RequestMapping(value = "/teacher/{teacher_id}", method = RequestMethod.DELETE)
 @ResponseBody
 public JSONObject delTeacher(@PathVariable("teacher_id") int teacherID) throws SQLException {
   teacherService.deleteByID(teacherID);
   return RequestUtil.make_ret();
 }
示例#15
0
 @RequestMapping(value = "/teacher", method = RequestMethod.POST)
 @ResponseBody
 public JSONObject addTeacher(@RequestBody JSONObject teacher) throws SQLException {
   Log.debug("save Teacher:" + teacher);
   return RequestUtil.make_ret(0, "", teacherService.insertTeacher(teacher));
 }
 @Test
 public void testURLDecodeStringValidUtf8Start() {
   String result = RequestUtil.URLDecode("%c3%aaxxxx", "UTF-8");
   assertEquals("\u00eaxxxx", result);
 }
示例#17
0
 @RequestMapping(value = "/teachers", method = RequestMethod.GET)
 @ResponseBody
 public JSONObject teachers() throws SQLException {
   return RequestUtil.make_ret(teacherService.selectAll());
 }
  @Test
  public void testURLDecodeStringValidUtf8End() {

    String result = RequestUtil.URLDecode("xxxx%c3%aa", "UTF-8");
    assertEquals("xxxx\u00ea", result);
  }
 @GET
 @Path("/")
 @Produces(APPLICATION_JSON)
 @ApiOperation(
     value = "Get events with optional filtering.",
     response = Event.class,
     responseContainer = "List")
 @ApiResponses(
     value = {
       @ApiResponse(code = 200, message = "Successfully fetched list of events."),
       @ApiResponse(code = 400, message = "Bad Request/Invalid Parameters."),
       @ApiResponse(code = 500, message = "Internal server error.", response = ApiError.class)
     })
 public Response findEvents(
     @ApiParam(
             required = false,
             value = "Filter out events created before this time, millisecond since epoch.")
         @QueryParam("startTime")
         final Long startTime,
     @ApiParam(
             required = false,
             value = "Filter out events created after this time, millisecond since epoch.")
         @QueryParam("endTime")
         final Long endTime,
     @ApiParam(
             required = false,
             value =
                 "Filter out events for unspecified eventIds, "
                     + "comma separated list of event IDs.")
         @QueryParam("eventIds")
         final String eventIds,
     @ApiParam(
             required = false,
             value =
                 "Filter out events for unspecified triggers, "
                     + "comma separated list of trigger IDs.")
         @QueryParam("triggerIds")
         final String triggerIds,
     @ApiParam(
             required = false,
             value =
                 "Filter out events for unspecified categories, "
                     + "comma separated list of category values.")
         @QueryParam("categories")
         final String categories,
     @ApiParam(
             required = false,
             value =
                 "Filter out events for unspecified tags, comma separated list of tags, "
                     + "each tag of format 'name|value'. Specify '*' for value to match all values.")
         @QueryParam("tags")
         final String tags,
     @ApiParam(required = false, value = "Return only thin events, do not include: evalSets.")
         @QueryParam("thin")
         final Boolean thin,
     @Context final UriInfo uri) {
   Pager pager = RequestUtil.extractPaging(uri);
   try {
     EventsCriteria criteria =
         buildCriteria(startTime, endTime, eventIds, triggerIds, categories, tags, thin);
     Page<Event> eventPage = alertsService.getEvents(tenantId, criteria, pager);
     if (log.isDebugEnabled()) {
       log.debug("Events: " + eventPage);
     }
     if (isEmpty(eventPage)) {
       return ResponseUtil.ok(eventPage);
     }
     return ResponseUtil.paginatedOk(eventPage, uri);
   } catch (Exception e) {
     log.debug(e.getMessage(), e);
     if (e.getCause() != null && e.getCause() instanceof IllegalArgumentException) {
       return ResponseUtil.badRequest("Bad arguments: " + e.getMessage());
     }
     return ResponseUtil.internalError(e);
   }
 }