HtmlController { @RequestMapping( value = "/rel/**", method = RequestMethod.GET, produces = "text/html" ) public ModelAndView getRelationshipType(final HttpServletRequest request) { final URI relationTypeURI = URI.create(request.getRequestURL().toString()); final Map<String,Object> model = new HashMap<>(); model.put("contextpath", request.getContextPath()); final JsonHome jsonHome = jsonHomeSource.getJsonHome(); if (jsonHome.hasResourceFor(relationTypeURI)) { final ResourceLink resourceLink = jsonHome.getResourceFor(relationTypeURI); model.put("resource", resourceLink); if (resourceLink.isDirectLink()) { return new ModelAndView("directresource", model); } else { return new ModelAndView("templatedresource", model); } } else { throw new IllegalArgumentException("Unknown relation type " + relationTypeURI); } }  @Autowired void setJsonHomeSource(final JsonHomeSource jsonHomeSource); @Value("${jsonhome.relationTypeBaseUri}") void setRelationTypeBaseUri(String relationTypeBaseUri); void setMaxAgeSeconds(int maxAge); URI relationTypeBaseUri(); @RequestMapping( value = "/json-home", method = RequestMethod.GET, produces = "text/html") @ResponseBody ModelAndView getHtmlHomeDocument(final HttpServletRequest request,
                                            final HttpServletResponse response); @RequestMapping( value = "/rel/**", method = RequestMethod.GET, produces = "text/html" ) ModelAndView getRelationshipType(final HttpServletRequest request); @ResponseStatus(value = NOT_FOUND) @ExceptionHandler({IllegalArgumentException.class}) void handleNotFound(final HttpServletResponse response);  }
@Test public void testGetRel() throws Exception { final HtmlController controller = relController(ControllerWithRequestMappingAndLinkRelationTypeAtClassLevel.class); final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/rel/foo"); request.setServerName("rel.example.org"); request.setScheme("http"); final ModelAndView resourcesMap = controller.getRelationshipType(request); assertEquals(resourcesMap.getViewName(), "directresource"); assertNotNull(resourcesMap.getModel().get("resource")); @SuppressWarnings("unchecked") final DirectLink model = (DirectLink) resourcesMap.getModel().get("resource"); assertEquals(model.getHref(), URI.create("http: }