@Test public void shouldMatchEndpointWithNoQueryParams() throws NotFoundException { HttpServletRequest request = mock(HttpServletRequest.class); given(request.getContextPath()).willReturn("/openam"); given(request.getRequestURI()).willReturn("/openam/URI_A"); given(request.getMethod()).willReturn("GET"); Map<String, String> details = new HashMap<String, String>(); details.put("resourceName", "/URI_A"); given(restDispatcher.getRequestDetails("/URI_A")).willReturn(details); boolean matches = endpointMatcher.match(request); assertTrue(matches); }
public boolean match(HttpServletRequest request) { String path = getRequestPath(request); try { Map<String, String> details = restDispatcher.getRequestDetails(path); if (details.get("resourceId") != null) { path = details.get("resourceName") + "/" + details.get("resourceId"); } else { path = details.get("resourceName"); } } catch (NotFoundException e) { DEBUG.message("Resource " + request.getPathInfo() + " not found."); return false; } Endpoint requestEndpoint = new Endpoint(path, request.getMethod()); if (endpoints.contains(requestEndpoint)) { int index = endpoints.indexOf(requestEndpoint); Endpoint endpoint = endpoints.get(index); return matchQueryParameters(request, endpoint); } return false; }
EndpointMatcher { public boolean match(HttpServletRequest request) { String path = getRequestPath(request); try { Map<String, String> details = restDispatcher.getRequestDetails(path); if (details.get("resourceId") != null) { path = details.get("resourceName") + "/" + details.get("resourceId"); } else { path = details.get("resourceName"); } } catch (NotFoundException e) { DEBUG.message("Resource " + request.getPathInfo() + " not found."); return false; } Endpoint requestEndpoint = new Endpoint(path, request.getMethod()); if (endpoints.contains(requestEndpoint)) { int index = endpoints.indexOf(requestEndpoint); Endpoint endpoint = endpoints.get(index); return matchQueryParameters(request, endpoint); } return false; } }
EndpointMatcher { public boolean match(HttpServletRequest request) { String path = getRequestPath(request); try { Map<String, String> details = restDispatcher.getRequestDetails(path); if (details.get("resourceId") != null) { path = details.get("resourceName") + "/" + details.get("resourceId"); } else { path = details.get("resourceName"); } } catch (NotFoundException e) { DEBUG.message("Resource " + request.getPathInfo() + " not found."); return false; } Endpoint requestEndpoint = new Endpoint(path, request.getMethod()); if (endpoints.contains(requestEndpoint)) { int index = endpoints.indexOf(requestEndpoint); Endpoint endpoint = endpoints.get(index); return matchQueryParameters(request, endpoint); } return false; } EndpointMatcher(String rootPath, RestDispatcher restDispatcher); }
EndpointMatcher { public boolean match(HttpServletRequest request) { String path = getRequestPath(request); try { Map<String, String> details = restDispatcher.getRequestDetails(path); if (details.get("resourceId") != null) { path = details.get("resourceName") + "/" + details.get("resourceId"); } else { path = details.get("resourceName"); } } catch (NotFoundException e) { DEBUG.message("Resource " + request.getPathInfo() + " not found."); return false; } Endpoint requestEndpoint = new Endpoint(path, request.getMethod()); if (endpoints.contains(requestEndpoint)) { int index = endpoints.indexOf(requestEndpoint); Endpoint endpoint = endpoints.get(index); return matchQueryParameters(request, endpoint); } return false; } EndpointMatcher(String rootPath, RestDispatcher restDispatcher); boolean match(HttpServletRequest request); void endpoint(String uri, String httpMethod); void endpoint(String uri, String httpMethod, String queryParam, String... queryParamValues); }
EndpointMatcher { public boolean match(HttpServletRequest request) { String path = getRequestPath(request); try { Map<String, String> details = restDispatcher.getRequestDetails(path); if (details.get("resourceId") != null) { path = details.get("resourceName") + "/" + details.get("resourceId"); } else { path = details.get("resourceName"); } } catch (NotFoundException e) { DEBUG.message("Resource " + request.getPathInfo() + " not found."); return false; } Endpoint requestEndpoint = new Endpoint(path, request.getMethod()); if (endpoints.contains(requestEndpoint)) { int index = endpoints.indexOf(requestEndpoint); Endpoint endpoint = endpoints.get(index); return matchQueryParameters(request, endpoint); } return false; } EndpointMatcher(String rootPath, RestDispatcher restDispatcher); boolean match(HttpServletRequest request); void endpoint(String uri, String httpMethod); void endpoint(String uri, String httpMethod, String queryParam, String... queryParamValues);  }