This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathMyService.java
More file actions
322 lines (245 loc) · 11.4 KB
/
Copy pathMyService.java
File metadata and controls
322 lines (245 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
* Copyright (C) 2016-2020 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.rest.spring.test;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.androidannotations.rest.spring.annotations.Accept;
import org.androidannotations.rest.spring.annotations.Body;
import org.androidannotations.rest.spring.annotations.Delete;
import org.androidannotations.rest.spring.annotations.Field;
import org.androidannotations.rest.spring.annotations.Get;
import org.androidannotations.rest.spring.annotations.Head;
import org.androidannotations.rest.spring.annotations.Header;
import org.androidannotations.rest.spring.annotations.Headers;
import org.androidannotations.rest.spring.annotations.Options;
import org.androidannotations.rest.spring.annotations.Part;
import org.androidannotations.rest.spring.annotations.Path;
import org.androidannotations.rest.spring.annotations.Post;
import org.androidannotations.rest.spring.annotations.Put;
import org.androidannotations.rest.spring.annotations.RequiresAuthentication;
import org.androidannotations.rest.spring.annotations.RequiresCookie;
import org.androidannotations.rest.spring.annotations.RequiresCookieInUrl;
import org.androidannotations.rest.spring.annotations.RequiresHeader;
import org.androidannotations.rest.spring.annotations.Rest;
import org.androidannotations.rest.spring.annotations.SetsCookie;
import org.androidannotations.rest.spring.api.MediaType;
import org.springframework.http.HttpAuthentication;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
// if defined, the rootUrl will be added as a prefix to every request
@Rest(rootUrl = "http://company.com/ajax/services", converters = { MappingJacksonHttpMessageConverter.class, EBeanConverter.class, FormHttpMessageConverter.class }, //
interceptors = { RequestInterceptor.class, EBeanInterceptor.class }, //
requestFactory = MyRequestFactory.class)
public interface MyService {
// *** GET ***
// url variables are mapped to method parameter names.
@RequiresCookie("xt")
@Get("/events/{year}/{location}")
@Accept(MediaType.APPLICATION_JSON)
EventList getEvents(@Path String location, @Path int year);
@Get("/events/{year}/{location}")
@Accept("application/json")
Event[] getEventsArray(@Path String location, @Path int year);
@Get("/events/{year}/{year}")
@Accept(MediaType.APPLICATION_JSON)
Event[][] urlWithAParameterDeclaredTwice(@Path int year);
@Get("/events/{year}/{location}")
@Accept(MediaType.APPLICATION_JSON)
Event[][] getEventsArrayOfArrays(@Path String location, @Path int year);
// The response can be a ResponseEntity<T>
@Get("/events/{year}/{location}")
/*
* You may (or may not) declare throwing RestClientException (as a reminder,
* since it's a RuntimeException), but nothing else.
*/
ResponseEntity<EventList> getEvents2(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
ResponseEntity<Event[]> getEventsArray2(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
ResponseEntity<Event[][]> getEventsArrayOfArrays2(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
List<Event> getEventsGenericsList(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
List<Event>[] getEventsGenericsArrayList(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
List<Event>[][] getEventsGenericsArrayList2(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
List<List<Event>> getEventsGenericsListListEvent(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
List<List<Event[]>> getEventsGenericsListListEvents(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
List<Event[]> getEventsGenericsListArray(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
List<Event[][]> getEventsGenericsListArrayArray(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
Set<Event> getEventsGenericsSet(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
GenericEvent<String> getEventsGenericString(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
GenericEvent<Integer> getEventsGenericInteger(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
GenericEvent<List<Event>> getEventsGenericListEvent(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
GenericEvent<GenericEvent<GenericEvent<String>>> getEventsGenericsInception(@Path String location, @Path int year) throws RestClientException;
@Get("/events/{year}/{location}")
@SetsCookie({ "xt", "sjsaid" })
Map<String, Event> getEventsGenericsMap(@Path String location, @Path int year) throws RestClientException;
@RequiresCookie("sjsaid")
@RequiresCookieInUrl("xt")
@Get("/events/{year}/{location}?xt={xt}")
void getEventsVoid(@Path String location, @Path int year) throws RestClientException;
// *** POST ***
@RequiresHeader("SomeFancyHeader")
@Post("/login")
@SetsCookie({ "xt", "sjsaid" })
void authenticate();
@RequiresAuthentication
@Post("http://company.com/client/ping")
void ping();
@Post("/events/")
@Accept(MediaType.APPLICATION_JSON)
Event addEvent(@Body String event);
@Post("/events/{year}/")
Event addEvent(@Body Event event, @Path int year);
@Post("/events/{year}/")
Event addEvent(@Path int year);
@Post("/events/")
ResponseEntity<Event> addEvent2(@Body Event event);
@Post("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithParameters(@Path String date, @Field String parameter, @Field String otherParameter);
@Post("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithParts(@Path String date, @Part String parameter, @Part String otherParameter);
@Post("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithPathParameters(@Path("date") String pathParam, @Field String parameter);
@Post("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@Header(name = "SomeFancyHeader", value = "fancy")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithHeaders(@Path String date, @Body String parameter);
@Post("/events/{date}?myCookieInUrl={myCookieInUrl}")
@Headers(@Header(name = "SomeFancyHeader", value = "fancy"))
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithHeadersHeadersAnnotation(@Path String date, @Body String parameter);
/**
* Output different then input
*/
@Post("/events/")
ResponseEntity<String> addEvent3(@Body Event event);
@Post("/events/")
List<? extends Event> addEventGenericsListWildcardExtends(@Body Event event);
@Post("/events/")
List<Event> addEventGenericsList(@Body Event event);
// TODO: Handle generics in params
// @Post("/events/")
// List<Event> addEventGenericsList(List<Event> events);
@Post("/events/")
Set<Event> addEventGenericsSet(@Body Event event);
@Post("/events/")
GenericEvent<GenericEvent<GenericEvent<String>>> addEventGenericsInception(@Body Event event);
@Post("/events/")
Map<String, Event> addEventGenericsMap(@Body Event event);
/**
* Output different then input
*/
@Post("/events/")
String addEvent4(@Body Event event);
@Post("/events/")
void addEvent5(@Body Event event);
@Post("/events/{year}/")
@Accept(MediaType.APPLICATION_JSON)
ResponseEntity<Event> addEvent2(@Body Event event, @Path int year);
// *** PUT ***
@Put("/events/{id}")
void updateEvent(@Body Event event, @Path int id);
@Put("/events/{date}")
void updateEvent(@Path long date);
@Put("/events/{date}")
Event updateEventWithResponse(@Path long date);
@Put("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
Event updateEventWithRequires(@Path long date);
// *** DELETE ***
@Delete("/events/{id}")
void removeEvent(@Path long id);
@Delete("/events/{id}")
Event removeEventWithResponse(@Path long id);
@Delete("/events/{id}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void removeEventWithRequires(@Path long id);
@Delete("/events/{id}")
@RequiresAuthentication
void removeEventWithAuthentication(@Path long id);
// *** HEAD ***
@Head("/events/{year}/{location}")
HttpHeaders getEventHeaders(@Path String location, @Path int year);
@Head("/events/{date}")
HttpHeaders getEventheaders(@Path long date);
@Head("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
HttpHeaders getEventheadersWithRequires(@Path long date);
@Head("/events/{date}")
@RequiresAuthentication
HttpHeaders getEventheadersWithAuthentication(@Path long date);
// *** OPTIONS ***
@Options("/events/{year}/{location}")
Set<HttpMethod> getEventOptions(@Path String location, @Path int year);
@Options("/events/{date}")
Set<HttpMethod> getEventOptions(@Path long date);
@Options("/events/{date}?myCookieInUrl={myCookieInUrl}")
@RequiresHeader("SomeFancyHeader")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
Set<HttpMethod> getEventOptionsWithRequires(@Path long date);
@Options("/events/{date}")
@RequiresAuthentication
Set<HttpMethod> getEventOptionsWithAuthentication(@Path long date);
// if you need to add some configuration to the Spring RestTemplate.
RestTemplate getRestTemplate();
void setRestTemplate(RestTemplate restTemplate);
void setRootUrl(String test);
String getRootUrl();
void setCookie(String cookieName, String value);
String getCookie(String cookieName);
void setHeader(String headerName, String value);
String getHeader(String headerName);
void setAuthentication(HttpAuthentication auth);
void setHttpBasicAuth(String username, String password);
void setBearerAuth(String token);
}