Skip to content

Commit dfa89ef

Browse files
committed
Drop RequestParameter annotation.
1 parent 1798ed7 commit dfa89ef

File tree

6 files changed

+11
-67
lines changed

6 files changed

+11
-67
lines changed

README.md

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ The HTTP-RPC framework includes the following classes:
4242

4343
* `org.httprpc`
4444
* `RequestMethod` - associates an HTTP verb with a service method
45-
* `RequestParameter` - associates a custom request parameter name with a method argument
4645
* `ResourcePath` - associates a resource path with a service method
4746
* `WebServiceException` - thrown when a service operation returns an error
4847
* `WebServiceProxy` - web service invocation proxy
@@ -72,7 +71,7 @@ These classes are discussed in more detail in the following sections.
7271
## WebService
7372
`WebService` is an abstract base class for web services. It extends the similarly abstract `HttpServlet` class provided by the servlet API.
7473

75-
Service operations are defined by adding public methods to a concrete service implementation. Methods are invoked by submitting an HTTP request for a path associated with a servlet instance. Arguments are provided either via the query string or in the request body, like an HTML form. `WebService` converts the request parameters to the expected argument types, invokes the method, and writes the return value to the output stream as [JSON](http://json.org).
74+
Service operations are defined by adding public methods to a concrete service implementation. Methods are invoked by submitting an HTTP request for a path associated with a servlet instance. Arguments are provided either via the query string or in the request body, like an HTML form. `WebService` converts the request parameters to the expected argument types, invokes the method, and writes the return value to the output stream as [JSON](http://json.org). Service classes must be compiled with the `-parameters` flag so the names of their method parameters are available at runtime.
7675

7776
The `RequestMethod` annotation is used to associate a service method with an HTTP verb such as `GET` or `POST`. The optional `ResourcePath` annotation can be used to associate the method with a specific path relative to the servlet. If unspecified, the method is associated with the servlet itself. If no matching handler method is found for a given request, the default handler (e.g. `doGet()`) is called.
7877

@@ -173,16 +172,6 @@ The methods could be invoked using this HTML form:
173172

174173
If no method is found that matches the provided arguments, an HTTP 405 response is returned.
175174

176-
#### Parameter Names
177-
In general, service classes should be compiled with the `-parameters` flag so the names of their method parameters are available at runtime. However, the `RequestParameter` annotation can be used to customize the name of the parameter associated with a particular argument. For example:
178-
179-
```java
180-
@RequestMethod("GET")
181-
public double getTemperature(@RequestParameter("zip_code") String zipCode) {
182-
...
183-
}
184-
```
185-
186175
### Path Variables
187176
Path variables may be specified by a "?" character in the resource path. For example:
188177

@@ -1097,9 +1086,9 @@ public static <T> T adapt(URL baseURL, Class<T> type, Map<String, ?> headers) {
10971086

10981087
Both versions take a base URL and an interface type as arguments and return an instance of the given type that can be used to invoke service operations. The second version also accepts a map of HTTP header values that will be submitted with every service request.
10991088

1100-
The `RequestMethod` annotation is used to associate an HTTP verb with an interface method. The optional `ResourcePath` annotation can be used to associate the method with a specific path relative to the base URL. If unspecified, the method is associated with the base URL itself.
1089+
The `RequestMethod` annotation is used to associate an HTTP verb with an interface method. The optional `ResourcePath` annotation can be used to associate the method with a specific path relative to the base URL. If unspecified, the method is associated with the base URL itself.
11011090

1102-
In general, service adapters should be compiled with the `-parameters` flag so their method parameter names are available at runtime. However, the `RequestParameter` annotation can be used to associate a custom parameter name with a request argument.
1091+
Service adapters must be compiled with the `-parameters` flag so their method parameter names are available at runtime.
11031092

11041093
`POST` requests are always submitted using the multi-part encoding. Values are returned as described for `WebServiceProxy` and adapted as described [earlier](#beanadapter) based on the method return type.
11051094

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
subprojects {
1616
group = 'org.httprpc'
17-
version = '7.1.1'
17+
version = '7.2'
1818

1919
apply plugin: 'java-library'
2020
apply plugin: 'maven-publish'

httprpc-client/src/main/java/org/httprpc/RequestParameter.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

httprpc-client/src/main/java/org/httprpc/WebServiceProxy.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,8 @@ public static <T> T adapt(URL baseURL, Class<T> type, Map<String, ?> headers) {
667667

668668
for (int i = 0; i < parameters.length; i++) {
669669
Parameter parameter = parameters[i];
670-
RequestParameter requestParameter = parameter.getAnnotation(RequestParameter.class);
671670

672-
String name = (requestParameter == null) ? parameter.getName() : requestParameter.value();
673-
674-
argumentMap.put(name, arguments[i]);
671+
argumentMap.put(parameter.getName(), arguments[i]);
675672
}
676673

677674
webServiceProxy.setArguments(argumentMap);

httprpc-server/src/main/java/org/httprpc/WebService.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ private static Handler getHandler(List<Handler> handlerList, Map<String, List<?>
424424
int j = 0;
425425

426426
for (int k = 0; k < parameters.length; k++) {
427-
String name = getName(parameters[k]);
427+
String name = parameters[k].getName();
428428

429429
if (!(parameterMap.containsKey(name))) {
430430
j++;
@@ -450,12 +450,10 @@ private static Object[] getArguments(Method method, Map<String, List<?>> paramet
450450
for (int i = 0; i < parameters.length; i++) {
451451
Parameter parameter = parameters[i];
452452

453-
String name = getName(parameter);
453+
List<?> values = parameterMap.get(parameter.getName());
454454

455455
Class<?> type = parameter.getType();
456456

457-
List<?> values = parameterMap.get(name);
458-
459457
Object argument;
460458
if (type == List.class) {
461459
Type elementType = ((ParameterizedType)parameter.getParameterizedType()).getActualTypeArguments()[0];
@@ -493,12 +491,6 @@ private static Object[] getArguments(Method method, Map<String, List<?>> paramet
493491
return arguments;
494492
}
495493

496-
private static String getName(Parameter parameter) {
497-
RequestParameter requestParameter = parameter.getAnnotation(RequestParameter.class);
498-
499-
return (requestParameter == null) ? parameter.getName() : requestParameter.value();
500-
}
501-
502494
/**
503495
* Returns the servlet request.
504496
*
@@ -709,7 +701,7 @@ private void describeResource(String path, Resource resource, TreeMap<Class<?>,
709701
xmlStreamWriter.writeCharacters(", ");
710702
}
711703

712-
xmlStreamWriter.writeCharacters(getName(parameter) + ": ");
704+
xmlStreamWriter.writeCharacters(parameter.getName() + ": ");
713705

714706
Type type = parameter.getParameterizedType();
715707

@@ -749,7 +741,7 @@ private void describeResource(String path, Resource resource, TreeMap<Class<?>,
749741
for (int i = 0; i < parameters.length; i++) {
750742
Parameter parameter = parameters[i];
751743

752-
String parameterName = getName(parameter);
744+
String parameterName = parameter.getName();
753745

754746
xmlStreamWriter.writeStartElement("li");
755747

httprpc-test/src/main/java/org/httprpc/test/TestService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package org.httprpc.test;
1616

1717
import org.httprpc.RequestMethod;
18-
import org.httprpc.RequestParameter;
1918
import org.httprpc.ResourcePath;
2019
import org.httprpc.WebService;
2120

@@ -53,10 +52,10 @@ public class TestService extends WebService {
5352
private static final long serialVersionUID = 0;
5453

5554
@RequestMethod("GET")
56-
public Map<String, ?> testGet(@RequestParameter("string") String text, List<String> strings, int number, boolean flag,
55+
public Map<String, ?> testGet(String string, List<String> strings, int number, boolean flag,
5756
Date date, LocalDate localDate, LocalTime localTime, LocalDateTime localDateTime) {
5857
return mapOf(
59-
entry("string", text),
58+
entry("string", string),
6059
entry("strings", strings),
6160
entry("number", number),
6261
entry("flag", flag),

0 commit comments

Comments
 (0)