static { $SwitchMap$io$fabric$sdk$android$services$network$HttpMethod = new int[HttpMethod.values().length]; try { $SwitchMap$io$fabric$sdk$android$services$network$HttpMethod[HttpMethod.GET.ordinal()] = 1; } catch (NoSuchFieldError nosuchfielderror3) { } try { $SwitchMap$io$fabric$sdk$android$services$network$HttpMethod[HttpMethod.POST.ordinal()] = 2; } catch (NoSuchFieldError nosuchfielderror2) { } try { $SwitchMap$io$fabric$sdk$android$services$network$HttpMethod[HttpMethod.PUT.ordinal()] = 3; } catch (NoSuchFieldError nosuchfielderror1) { } try { $SwitchMap$io$fabric$sdk$android$services$network$HttpMethod[HttpMethod.DELETE.ordinal()] = 4; } catch (NoSuchFieldError nosuchfielderror) { return; } }
static { HttpMethod[] methods = HttpMethod.values(); for (int i = 0; i < methods.length; i++) { HttpMethod method = methods[i]; _methods[i] = method.toString(); } }
private void initHttpMethodValidityVerification() { assert (null == allowedUnknownHttpMethods); assert (null != defaultAllowedHttpMethods); assert (null == allHttpMethods); allHttpMethods = EnumSet.allOf(HttpMethod.class); // Configure our permitted HTTP methods allowedUnknownHttpMethods = Collections.emptySet(); allowedKnownHttpMethods = defaultAllowedHttpMethods; String[] methods; String allowedHttpMethodsString = servletConfig.getServletContext().getInitParameter(ALLOWED_HTTP_METHODS_ATTR); if (null != allowedHttpMethodsString) { methods = allowedHttpMethodsString.split("\\s+"); assert (null != methods); // assuming split always returns a non-null array result allowedUnknownHttpMethods = new HashSet(methods.length); List<String> allowedKnownHttpMethodsStringList = new ArrayList<String>(); // validate input against allHttpMethods data structure for (String cur : methods) { if (cur.equals("*")) { allowAllMethods = true; allowedUnknownHttpMethods = Collections.emptySet(); return; } boolean isKnownHttpMethod; try { HttpMethod.valueOf(cur); isKnownHttpMethod = true; } catch (IllegalArgumentException e) { isKnownHttpMethod = false; } if (!isKnownHttpMethod) { if (LOGGER.isLoggable(Level.WARNING)) { HttpMethod[] values = HttpMethod.values(); Object[] arg = new Object[values.length + 1]; arg[0] = cur; System.arraycopy(values, HttpMethod.OPTIONS.ordinal(), arg, 1, values.length); LOGGER.log(Level.WARNING, "warning.webapp.facesservlet.init_invalid_http_method", arg); } // prevent duplicates if (!allowedUnknownHttpMethods.contains(cur)) { allowedUnknownHttpMethods.add(cur); } } else { // prevent duplicates if (!allowedKnownHttpMethodsStringList.contains(cur)) { allowedKnownHttpMethodsStringList.add(cur); } } } // Optimally initialize allowedKnownHttpMethods if (5 == allowedKnownHttpMethodsStringList.size()) { allowedKnownHttpMethods = EnumSet.of( HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(0)), HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(1)), HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(2)), HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(3)), HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(4))); } else if (4 == allowedKnownHttpMethodsStringList.size()) { allowedKnownHttpMethods = EnumSet.of( HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(0)), HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(1)), HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(2)), HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(3))); } else if (3 == allowedKnownHttpMethodsStringList.size()) { allowedKnownHttpMethods = EnumSet.of( HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(0)), HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(1)), HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(2))); } else if (2 == allowedKnownHttpMethodsStringList.size()) { allowedKnownHttpMethods = EnumSet.of( HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(0)), HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(1))); } else if (1 == allowedKnownHttpMethodsStringList.size()) { allowedKnownHttpMethods = EnumSet.of(HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(0))); } else { List<HttpMethod> restList = new ArrayList<HttpMethod>(allowedKnownHttpMethodsStringList.size() - 1); for (int i = 1; i < allowedKnownHttpMethodsStringList.size() - 1; i++) { restList.add(HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(i))); } HttpMethod first = HttpMethod.valueOf(allowedKnownHttpMethodsStringList.get(0)); HttpMethod[] rest = new HttpMethod[restList.size()]; restList.toArray(rest); allowedKnownHttpMethods = EnumSet.of(first, rest); } } }
/** Configuration for the web-resource-collection. */ public class WebResourceCollection { static L10N L = new L10N(WebResourceCollection.class); public enum HttpMethod { GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE }; public static final String[] _methods = new String[HttpMethod.values().length]; private String _webResourceName; private String _description; private ArrayList<String> _methodList; private Set<String> _methodOmitList; private ArrayList<Pattern> _urlPatternList = new ArrayList<Pattern>(); /** Sets the web-resource-name. */ public void setWebResourceName(String name) { _webResourceName = name; } /** Sets the description */ public void setDescription(String name) { _description = name; } /** Adds a url-pattern */ public void addURLPattern(String pattern) throws PatternSyntaxException { String regexpPattern = UrlMap.urlPatternToRegexpPattern(pattern); int flags = (CauchoSystem.isCaseInsensitive() ? Pattern.CASE_INSENSITIVE : 0); Pattern regexp = Pattern.compile(regexpPattern, flags); _urlPatternList.add(regexp); } /** Gets the pattern list */ public ArrayList getURLPatternList() { return _urlPatternList; } /** Adds a method */ public void addMethod(String method) { if (_methodList == null) _methodList = new ArrayList<String>(); _methodList.add(method); } /** Adds a method */ public void addHttpMethod(String method) { if (!Pattern.matches("[a-zA-Z]+", method)) { throw new ConfigException(L.l("'{0}' is not a valid http-method.", method)); } /* try { HttpMethod.valueOf(method.toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { StringBuilder builder = new StringBuilder(); for (HttpMethod validHttpMethod : EnumSet.allOf(HttpMethod.class)) { if (builder.length() != 0) builder.append(", "); builder.append(validHttpMethod.name()); } throw new ConfigException(L.l("'{0}' is not a valid value for '{1}', valid values are {2}", method, "http-method", builder)); } */ if (_methodList == null) _methodList = new ArrayList<String>(); _methodList.add(method); } public void addHttpMethodOmission(String method) { if (!Pattern.matches("[a-zA-Z]+", method)) { throw new ConfigException(L.l("'{0}' is not a valid http-method.", method)); } if (_methodOmitList == null) _methodOmitList = new HashSet<String>(); _methodOmitList.add(method); } /** Returns the methods. */ public ArrayList<String> getMethods() { if (_methodOmitList == null) return _methodList; if (_methodList == null) { _methodList = new ArrayList<String>(_methods.length - _methodOmitList.size()); for (String method : _methods) { if (!_methodOmitList.contains(method)) _methodList.add(method); } } return _methodList; } /** Returns true if there's a pattern match. */ public boolean isMatch(String url) { if (_urlPatternList.size() == 0) return true; for (int i = 0; i < _urlPatternList.size(); i++) { Pattern pattern = _urlPatternList.get(i); if (pattern.matcher(url).find()) return true; } return false; } static { HttpMethod[] methods = HttpMethod.values(); for (int i = 0; i < methods.length; i++) { HttpMethod method = methods[i]; _methods[i] = method.toString(); } } }