DATAREST-217 - Significant overhaul of HTTP method support detection.

Refactored the way the general support for an HTTP method for the resource exported. The decision is implemented in RootResourceInformation (formerly RepositoryRestRequest). Removed request specific information from that class and introduced a HandlerMethodArgumentResolver to be able to inject HttpMethod instance into controller methods (filed https://jira.springsource.org/browse/SPR-11425 to get that support into Spring Framework itself).

Generally moved away from throwing NoSuchMethodExceptions and correctly expose HttpRequestMethodNotSupportedException instead to make sure Spring MVC renders the appropriate allowed methods if possible.

Removed RepositoryInvokerHandlerMethodArgumentResolver as a RepositoryInvoker can be obtained from the RootResourceInformation where necessary.

Related pull request: #125.
This commit is contained in:
Oliver Gierke
2014-02-14 10:09:45 +01:00
parent ef1ee10940
commit 922827fe56
24 changed files with 815 additions and 253 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -72,6 +72,15 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
this.conversionService = conversionService;
}
/*
* (non-Javadoc)
* @see org.springframework.data.rest.core.invoke.RepositoryInvocationInformation#hasFindAllMethod()
*/
@Override
public boolean hasFindAllMethod() {
return methods.hasFindAllMethod();
}
/*
* (non-Javadoc)
* @see org.springframework.data.rest.core.invoke.RepositoryInvocationInformation#exposesFindAll()
@@ -115,6 +124,15 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
return invoke(method, pageable);
}
/*
* (non-Javadoc)
* @see org.springframework.data.rest.core.invoke.RepositoryInvocationInformation#hasSaveMethod()
*/
@Override
public boolean hasSaveMethod() {
return methods.hasSaveMethod();
}
/*
* (non-Javadoc)
* @see org.springframework.data.rest.core.invoke.RepositoryInvocationInformation#exposesSave()
@@ -132,6 +150,15 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
return invoke(methods.getSaveMethod(), object);
}
/*
* (non-Javadoc)
* @see org.springframework.data.rest.core.invoke.RepositoryInvocationInformation#hasFindOneMethod()
*/
@Override
public boolean hasFindOneMethod() {
return methods.hasFindOneMethod();
}
/*
* (non-Javadoc)
* @see org.springframework.data.rest.core.invoke.RepositoryInvocationInformation#exposesFindOne()
@@ -150,6 +177,15 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
return invoke(methods.getFindOneMethod(), convertId(id));
}
/*
* (non-Javadoc)
* @see org.springframework.data.rest.core.invoke.RepositoryInvocationInformation#hasDeleteMethod()
*/
@Override
public boolean hasDeleteMethod() {
return methods.hasDelete();
}
/*
* (non-Javadoc)
* @see org.springframework.data.rest.core.invoke.RepositoryInvocationInformation#exposesDelete()

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,11 +22,59 @@ package org.springframework.data.rest.core.invoke;
*/
public interface RepositoryInvocationInformation {
/**
* Returns whether the repository has a method to save objects.
*
* @return
*/
boolean hasSaveMethod();
/**
* Returns whether the repository exposes the save method.
*
* @return
*/
boolean exposesSave();
/**
* Returns whether the repository has a method to delete objects.
*
* @return
*/
boolean hasDeleteMethod();
/**
* Returns whether the repository exposes the delete method.
*
* @return
*/
boolean exposesDelete();
/**
* Returns whether the repository has a method to find a single object.
*
* @return
*/
boolean hasFindOneMethod();
/**
* Returns whether the repository exposes the method to find a single object.
*
* @return
*/
boolean exposesFindOne();
/**
* Returns whether the repository has a method to find all objects.
*
* @return
*/
boolean hasFindAllMethod();
/**
* Returns whether the repository exposes the method to find all objects.
*
* @return
*/
boolean exposesFindAll();
}