@Test public void canHandleTheCorrectMethod() { when(request.getRequestURI()).thenReturn("/url"); when(request.getMethod()).thenReturn("POST"); when(router.parse("/url", HttpMethod.POST,webRequest)).thenReturn(method); ResourceMethod resource = translator.translate(info); assertThat(resource, is(equalTo(method))); }
public ResourceMethod translate(RequestInfo info) { MutableRequest request = info.getRequest(); String resourceName = info.getRequestedUri(); logger.debug("trying to access {}", resourceName); HttpMethod method; try { method = HttpMethod.of(request); } catch (IllegalArgumentException e) { throw new MethodNotAllowedException(router.allowedMethodsFor(resourceName), request.getMethod()); } ResourceMethod resource = router.parse(resourceName, method, request); logger.debug("found resource {}", resource); return resource; }
DefaultResourceTranslator implements UrlToResourceTranslator { public ResourceMethod translate(RequestInfo info) { MutableRequest request = info.getRequest(); String resourceName = info.getRequestedUri(); logger.debug("trying to access {}", resourceName); HttpMethod method; try { method = HttpMethod.of(request); } catch (IllegalArgumentException e) { throw new MethodNotAllowedException(router.allowedMethodsFor(resourceName), request.getMethod()); } ResourceMethod resource = router.parse(resourceName, method, request); logger.debug("found resource {}", resource); return resource; } }
DefaultResourceTranslator implements UrlToResourceTranslator { public ResourceMethod translate(RequestInfo info) { MutableRequest request = info.getRequest(); String resourceName = info.getRequestedUri(); logger.debug("trying to access {}", resourceName); HttpMethod method; try { method = HttpMethod.of(request); } catch (IllegalArgumentException e) { throw new MethodNotAllowedException(router.allowedMethodsFor(resourceName), request.getMethod()); } ResourceMethod resource = router.parse(resourceName, method, request); logger.debug("found resource {}", resource); return resource; } DefaultResourceTranslator(Router router); }
DefaultResourceTranslator implements UrlToResourceTranslator { public ResourceMethod translate(RequestInfo info) { MutableRequest request = info.getRequest(); String resourceName = info.getRequestedUri(); logger.debug("trying to access {}", resourceName); HttpMethod method; try { method = HttpMethod.of(request); } catch (IllegalArgumentException e) { throw new MethodNotAllowedException(router.allowedMethodsFor(resourceName), request.getMethod()); } ResourceMethod resource = router.parse(resourceName, method, request); logger.debug("found resource {}", resource); return resource; } DefaultResourceTranslator(Router router); ResourceMethod translate(RequestInfo info); }
DefaultResourceTranslator implements UrlToResourceTranslator { public ResourceMethod translate(RequestInfo info) { MutableRequest request = info.getRequest(); String resourceName = info.getRequestedUri(); logger.debug("trying to access {}", resourceName); HttpMethod method; try { method = HttpMethod.of(request); } catch (IllegalArgumentException e) { throw new MethodNotAllowedException(router.allowedMethodsFor(resourceName), request.getMethod()); } ResourceMethod resource = router.parse(resourceName, method, request); logger.debug("found resource {}", resource); return resource; } DefaultResourceTranslator(Router router); ResourceMethod translate(RequestInfo info);  }