@Test public void returnsResponseWithStatus_NOT_FOUND_WhenResourceMethodNotFound() throws Exception { when(applicationContext.getPathSegments(false)).thenReturn(createPathSegments("a", "b;x=y")); Resource resource = new Resource(); ObjectFactory resourceFactory = mockResourceFactory(resource, newArrayList(), newArrayList(), newArrayList()); matchRequestPath(); when(resources.getMatchedResource(eq("/a/b"), anyList())).thenReturn(resourceFactory); requestDispatcher.dispatch(request, response); ArgumentCaptor<Response> argumentCaptor = ArgumentCaptor.forClass(Response.class); verify(response).setResponse(argumentCaptor.capture()); assertEquals(NOT_FOUND, argumentCaptor.getValue().getStatusInfo()); }
public void dispatch(GenericContainerRequest request, GenericContainerResponse response) { ApplicationContext context = ApplicationContext.getCurrent(); String requestPath = getRequestPathWithoutMatrixParameters(context); List<String> parameterValues = context.getParameterValues(); ObjectFactory<ResourceDescriptor> resourceFactory = getRootResource(parameterValues, requestPath); if (resourceFactory == null) { LOG.debug("Root resource not found for {}", requestPath); response.setResponse(Response.status(NOT_FOUND) .entity(String.format("There is no any resources matched to request path %s", requestPath)) .type(TEXT_PLAIN) .build()); return; } String newRequestPath = getPathTail(parameterValues); context.addMatchedURI(requestPath.substring(0, requestPath.lastIndexOf(newRequestPath))); context.setParameterNames(resourceFactory.getObjectModel().getUriPattern().getParameterNames()); Object resource = resourceFactory.getInstance(context); dispatch(request, response, context, resourceFactory.getObjectModel(), resource, newRequestPath); }
RequestDispatcher { public void dispatch(GenericContainerRequest request, GenericContainerResponse response) { ApplicationContext context = ApplicationContext.getCurrent(); String requestPath = getRequestPathWithoutMatrixParameters(context); List<String> parameterValues = context.getParameterValues(); ObjectFactory<ResourceDescriptor> resourceFactory = getRootResource(parameterValues, requestPath); if (resourceFactory == null) { LOG.debug("Root resource not found for {}", requestPath); response.setResponse(Response.status(NOT_FOUND) .entity(String.format("There is no any resources matched to request path %s", requestPath)) .type(TEXT_PLAIN) .build()); return; } String newRequestPath = getPathTail(parameterValues); context.addMatchedURI(requestPath.substring(0, requestPath.lastIndexOf(newRequestPath))); context.setParameterNames(resourceFactory.getObjectModel().getUriPattern().getParameterNames()); Object resource = resourceFactory.getInstance(context); dispatch(request, response, context, resourceFactory.getObjectModel(), resource, newRequestPath); } }
RequestDispatcher { public void dispatch(GenericContainerRequest request, GenericContainerResponse response) { ApplicationContext context = ApplicationContext.getCurrent(); String requestPath = getRequestPathWithoutMatrixParameters(context); List<String> parameterValues = context.getParameterValues(); ObjectFactory<ResourceDescriptor> resourceFactory = getRootResource(parameterValues, requestPath); if (resourceFactory == null) { LOG.debug("Root resource not found for {}", requestPath); response.setResponse(Response.status(NOT_FOUND) .entity(String.format("There is no any resources matched to request path %s", requestPath)) .type(TEXT_PLAIN) .build()); return; } String newRequestPath = getPathTail(parameterValues); context.addMatchedURI(requestPath.substring(0, requestPath.lastIndexOf(newRequestPath))); context.setParameterNames(resourceFactory.getObjectModel().getUriPattern().getParameterNames()); Object resource = resourceFactory.getInstance(context); dispatch(request, response, context, resourceFactory.getObjectModel(), resource, newRequestPath); } RequestDispatcher(ResourceBinder resourceBinder); }
RequestDispatcher { public void dispatch(GenericContainerRequest request, GenericContainerResponse response) { ApplicationContext context = ApplicationContext.getCurrent(); String requestPath = getRequestPathWithoutMatrixParameters(context); List<String> parameterValues = context.getParameterValues(); ObjectFactory<ResourceDescriptor> resourceFactory = getRootResource(parameterValues, requestPath); if (resourceFactory == null) { LOG.debug("Root resource not found for {}", requestPath); response.setResponse(Response.status(NOT_FOUND) .entity(String.format("There is no any resources matched to request path %s", requestPath)) .type(TEXT_PLAIN) .build()); return; } String newRequestPath = getPathTail(parameterValues); context.addMatchedURI(requestPath.substring(0, requestPath.lastIndexOf(newRequestPath))); context.setParameterNames(resourceFactory.getObjectModel().getUriPattern().getParameterNames()); Object resource = resourceFactory.getInstance(context); dispatch(request, response, context, resourceFactory.getObjectModel(), resource, newRequestPath); } RequestDispatcher(ResourceBinder resourceBinder); void dispatch(GenericContainerRequest request, GenericContainerResponse response); ResourceBinder getResources(); }
RequestDispatcher { public void dispatch(GenericContainerRequest request, GenericContainerResponse response) { ApplicationContext context = ApplicationContext.getCurrent(); String requestPath = getRequestPathWithoutMatrixParameters(context); List<String> parameterValues = context.getParameterValues(); ObjectFactory<ResourceDescriptor> resourceFactory = getRootResource(parameterValues, requestPath); if (resourceFactory == null) { LOG.debug("Root resource not found for {}", requestPath); response.setResponse(Response.status(NOT_FOUND) .entity(String.format("There is no any resources matched to request path %s", requestPath)) .type(TEXT_PLAIN) .build()); return; } String newRequestPath = getPathTail(parameterValues); context.addMatchedURI(requestPath.substring(0, requestPath.lastIndexOf(newRequestPath))); context.setParameterNames(resourceFactory.getObjectModel().getUriPattern().getParameterNames()); Object resource = resourceFactory.getInstance(context); dispatch(request, response, context, resourceFactory.getObjectModel(), resource, newRequestPath); } RequestDispatcher(ResourceBinder resourceBinder); void dispatch(GenericContainerRequest request, GenericContainerResponse response); ResourceBinder getResources();  }