protected boolean acceptsGZipEncoding(HttpServletRequest httpServletRequest) { String acceptEncoding = httpServletRequest.getHeader("accept-encoding"); return !StringUtils.isNullOrEmpty(acceptEncoding) && ( acceptEncoding.contains("gzip") || acceptEncoding.contains("*") ); }
protected boolean acceptsGZipEncoding(HttpServletRequest request) { String acceptEncoding = request.getHeader("accept-encoding"); return !StringUtils.isNullOrEmpty(acceptEncoding) && ( acceptEncoding.contains("gzip") || acceptEncoding.contains("*") ); }
public int toInt(int defaultValue) { if (isNull() || StringUtils.isNullOrEmpty(values[0])) { return defaultValue; } return Integer.parseInt(values[0]); }
public short toShort(short defaultValue) { if (isNull() || StringUtils.isNullOrEmpty(values[0])) { return defaultValue; } return Short.parseShort(values[0]); }
public java.sql.Date toSqlDate(java.sql.Date defaultValue) { if (isNull() || StringUtils.isNullOrEmpty(values[0])) { return defaultValue; } return java.sql.Date.valueOf(values[0]); }
public long toLong(long defaultValue) { if (isNull() || StringUtils.isNullOrEmpty(values[0])) { return defaultValue; } return Long.parseLong(values[0]); }
public Time toSqlTime(Time defaultValue) { if (isNull() || StringUtils.isNullOrEmpty(values[0])) { return defaultValue; } return Time.valueOf(values[0]); }
private String getMetricName(Route route, Method method) { String metricName = route.getName(); if (StringUtils.isNullOrEmpty(metricName)) { metricName = MetricRegistry.name(method.getDeclaringClass(), method.getName()); } return metricName; }
public Timestamp toSqlTimestamp(Timestamp defaultValue) { if (isNull() || StringUtils.isNullOrEmpty(values[0])) { return defaultValue; } return Timestamp.valueOf(values[0]); }
public Date toDate(Date defaultValue, String pattern) { if (isNull() || StringUtils.isNullOrEmpty(values[0])) { return defaultValue; } SimpleDateFormat dateFormat = new SimpleDateFormat(pattern); try { return dateFormat.parse(values[0]); } catch (ParseException e) { throw new PippoRuntimeException(e); } }
@Override public void setApplicationPath(String applicationPath) { if (StringUtils.isNullOrEmpty(applicationPath) || "/".equals(applicationPath.trim())) { this.applicationPath = ""; } else { this.applicationPath = StringUtils.removeEnd(StringUtils.addStart(applicationPath, "/"), "/"); } }
protected void validateRoute(Route route) { // validate the request method if (StringUtils.isNullOrEmpty(route.getRequestMethod())) { throw new PippoRuntimeException("Unspecified request method!"); } // validate the uri pattern String uriPattern = route.getUriPattern(); if (StringUtils.isNullOrEmpty(uriPattern)) { throw new PippoRuntimeException("The uri pattern cannot be null or empty"); } }
public float toFloat(float defaultValue) { if (isNull() || StringUtils.isNullOrEmpty(values[0])) { return defaultValue; } try { Number number = getDecimalFormat().parse(values[0]); return number.floatValue(); } catch (ParseException e) { throw new PippoRuntimeException(e, "Failed to parse '{}'", values[0]); } }
public double toDouble(double defaultValue) { if (isNull() || StringUtils.isNullOrEmpty(values[0])) { return defaultValue; } try { Number number = getDecimalFormat().parse(values[0]); return number.doubleValue(); } catch (ParseException e) { throw new PippoRuntimeException(e, "Failed to parse '{}'", values[0]); } }
public BigDecimal toBigDecimal(BigDecimal defaultValue) { if (isNull() || StringUtils.isNullOrEmpty(values[0])) { return defaultValue; } DecimalFormat formatter = getDecimalFormat(); formatter.setParseBigDecimal(true); try { return (BigDecimal) formatter.parse(values[0]); } catch (ParseException e) { throw new PippoRuntimeException(e, "Failed to parse '{}'", values[0]); } }
protected WebSocketRouter.WebSocketMatch findWebSocketRoute(String requestUri) { String applicationPath = getApplication().getRouter().getContextPath(); String path = applicationPath.isEmpty() ? requestUri : requestUri.substring(applicationPath.length()); if (StringUtils.isNullOrEmpty(path)) { path = "/"; } return getApplication().getWebSocketRouter().match(path); }
@SuppressWarnings("unchecked") protected void handleRoute(Route route) { if (StringUtils.isNullOrEmpty(route.getName())) { log.debug("Executing handler for {} '{}'", route.getRequestMethod(), route.getUriPattern()); } else { log.debug("Executing '{}' for {} '{}'", route.getName(), route.getRequestMethod(), route.getUriPattern()); } this.route = route; route.getRouteHandler().handle(this); }
private String getParameterName(MethodParameter parameter, Header annotation) { String name = annotation.value(); if (StringUtils.isNullOrEmpty(name)) { name = parameter.getParameterName(); } if (name == null) { throw new PippoRuntimeException( "Method '{}' parameter {} does not specify a name!", LangUtils.toString(parameter.getMethod()), parameter.getParameterIndex()); } return name; }
private String getParameterName(MethodParameter parameter, Param annotation) { String name = annotation.value(); if (StringUtils.isNullOrEmpty(name)) { name = parameter.getParameterName(); } if (name == null) { throw new PippoRuntimeException( "Method '{}' parameter {} does not specify a name!", LangUtils.toString(parameter.getMethod()), parameter.getParameterIndex()); } return name; }
private String getParameterName(MethodParameter parameter, Session annotation) { String name = annotation.value(); if (StringUtils.isNullOrEmpty(name)) { name = parameter.getParameterName(); } if (name == null) { throw new PippoRuntimeException( "Method '{}' parameter {} does not specify a name!", LangUtils.toString(parameter.getMethod()), parameter.getParameterIndex()); } return name; }