public boolean shouldSkipExecution(HttpServletRequest request) throws ServletRequestBindingException { if (useSku) { return true; } if (allowCategoryResolutionUsingIdParam() && ServletRequestUtils.getLongParameter(request, "categoryId") != null) { return true; } return false; }
protected Category findCategoryUsingIdParam(HttpServletRequest request) throws ServletRequestBindingException { Long categoryId = ServletRequestUtils.getLongParameter(request, "categoryId"); if (categoryId != null) { Category category = catalogService.findCategoryById(categoryId); if (category != null && LOG.isDebugEnabled()) { LOG.debug("Obtained the category using ID=" + categoryId); } return category; } return null; }
protected Product findProductUsingIdParam(HttpServletRequest request) throws ServletRequestBindingException { Long productId = ServletRequestUtils.getLongParameter(request, "productId"); if (productId != null) { Product product = catalogService.findProductById(productId); if (product != null && LOG.isDebugEnabled()) { LOG.debug("Obtained the product using id=" + productId); } return product; } return null; }
request.addParameter("paramEmpty", ""); assertEquals(ServletRequestUtils.getLongParameter(request, "param1"), new Long(5L)); assertEquals(ServletRequestUtils.getLongParameter(request, "param1", 6L), 5L); assertEquals(ServletRequestUtils.getRequiredIntParameter(request, "param1"), 5L); assertEquals(ServletRequestUtils.getLongParameter(request, "param2", 6L), 6L); try { ServletRequestUtils.getRequiredLongParameter(request, "param2"); assertEquals(ServletRequestUtils.getLongParameter(request, "param3"), null); assertEquals(ServletRequestUtils.getLongParameter(request, "param3", 6L), 6L); try { ServletRequestUtils.getRequiredLongParameter(request, "param3");
@Test public void testGetLongParameterWithDefaultValueHandlingIsFastEnough() { Assume.group(TestGroup.PERFORMANCE); MockHttpServletRequest request = new MockHttpServletRequest(); StopWatch sw = new StopWatch(); sw.start(); for (int i = 0; i < 1000000; i++) { ServletRequestUtils.getLongParameter(request, "nonExistingParam", 0); } sw.stop(); System.out.println(sw.getTotalTimeMillis()); assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250); }
LinkedList<String> lines = new LinkedList<>(); long actualLength = file.length(); long lastKnownLength = ServletRequestUtils.getLongParameter(request, "lastKnownLength", 0); long currentLength = ServletRequestUtils.getLongParameter(request, "currentLength", actualLength); long maxReadLines = ServletRequestUtils.getLongParameter(request, "maxReadLines", 0);
HttpServletResponse response) throws Exception { long threadId = ServletRequestUtils.getLongParameter(request, "id", -1); String threadName = ServletRequestUtils.getStringParameter(request, "name", null);
/** * Get a long parameter, with a fallback value. Never throws an exception. * Can pass a distinguished value as default to enable checks of whether it was supplied. * @param request current HTTP request * @param name the name of the parameter * @param defaultVal the default value to use as fallback */ public static long getLongParameter(ServletRequest request, String name, long defaultVal) { return org.springframework.web.bind.ServletRequestUtils.getLongParameter(request, name, defaultVal); }
/** * Get a Long parameter, or {@code null} if not present. * Throws an exception if it the parameter value isn't a number. * @param request current HTTP request * @param name the name of the parameter * @return the Long value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static Long getLongParameter(ServletRequest request, String name) throws ServletRequestBindingException { return org.springframework.web.bind.ServletRequestUtils.getLongParameter(request, name); }