This repository was archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
323 custom rest headers #967
Closed
maltzj
wants to merge
13
commits into
androidannotations:develop
from
maltzj:323_custom_rest_headers
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
db0e652
added header annotation
maltzj 9c00a44
added basic docs and license to the header
maltzj 1aea6d5
renamed a variable in the RestAnnotationHelper so that it is more sen…
maltzj 3f31e6d
full implementation of restful headers (I think). Need to do lots of…
maltzj 20af46a
added the two test classes that are necessary
maltzj 33a4fd4
got the most basic test working
maltzj cf639ef
covered all the basic cases in testing, need to refactor a little
maltzj 7692b95
removed a useless test
maltzj b5d0cad
updated how the header name was specified and added some docs
maltzj c9edeaa
added whitespace
maltzj 52d791d
forgot to rename a method call
maltzj 20c8461
added licensing headers
maltzj e9946c5
renamed a the requiresHeader variable to make it even more clear
maltzj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
.../androidannotations-api/src/main/java/org/androidannotations/annotations/rest/Header.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /** | ||
| * Copyright (C) 2010-2014 eBusiness Information, Excilys Group | ||
| * | ||
| * 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.annotations.rest; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
|
|
||
| /** | ||
| * Use on methods in {@link Rest} annotated class to add headers to a particular method | ||
| * | ||
| * Example usage: | ||
| * | ||
| * @Header(headerName="keep-alive", value="300") | ||
| * @Post("/test") | ||
| * public void testRoute() | ||
| */ | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target({ElementType.METHOD}) | ||
| public @interface Header { | ||
| String headerName(); | ||
| String value(); | ||
| } |
36 changes: 36 additions & 0 deletions
36
...androidannotations-api/src/main/java/org/androidannotations/annotations/rest/Headers.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * Copyright (C) 2010-2014 eBusiness Information, Excilys Group | ||
| * | ||
| * 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.annotations.rest; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * Use on methods in {@link Rest} annotated class to add multiple headers to a given method | ||
| * | ||
| * Example usage | ||
| * @Headers({@Header(headerName="cache-control" value="64000"), | ||
| * @Header(headerName="keep-alive" value="300")}) | ||
| * @Post("/test") | ||
| * public void getTest() | ||
| */ | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target({ElementType.METHOD}) | ||
| public @interface Headers { | ||
| Header[] value(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...droidannotations/src/test/java/org/androidannotations/rest/ClientWithMultipleHeaders.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * Copyright (C) 2010-2014 eBusiness Information, Excilys Group | ||
| * | ||
| * 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; | ||
|
|
||
| import org.androidannotations.annotations.rest.Header; | ||
| import org.androidannotations.annotations.rest.Headers; | ||
| import org.androidannotations.annotations.rest.Post; | ||
| import org.androidannotations.annotations.rest.Rest; | ||
| import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter; | ||
|
|
||
| @Rest(converters = MappingJacksonHttpMessageConverter.class) | ||
| public interface ClientWithMultipleHeaders { | ||
|
|
||
| @Headers({ | ||
| @Header(headerName="testKey", value="testVal"), | ||
| @Header(headerName="testKey1", value="testVal1") | ||
| }) | ||
| @Post("/test/") | ||
| void requestWithOneHeader(); | ||
| } |
31 changes: 31 additions & 0 deletions
31
...ons/androidannotations/src/test/java/org/androidannotations/rest/ClientWithOneHeader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * Copyright (C) 2010-2014 eBusiness Information, Excilys Group | ||
| * | ||
| * 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; | ||
|
|
||
| import org.androidannotations.annotations.rest.Header; | ||
| import org.androidannotations.annotations.rest.Post; | ||
| import org.androidannotations.annotations.rest.RequiresHeader; | ||
| import org.androidannotations.annotations.rest.Rest; | ||
| import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter; | ||
|
|
||
| @Rest(converters = MappingJacksonHttpMessageConverter.class) | ||
| public interface ClientWithOneHeader { | ||
|
|
||
| @Header(headerName="testKey", value="testVal") | ||
| @Post("/test/") | ||
| void requestWithHeader(); | ||
|
|
||
| } |
32 changes: 32 additions & 0 deletions
32
...idannotations/src/test/java/org/androidannotations/rest/ClientWithOneHeaderInHeaders.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /** | ||
| * Copyright (C) 2010-2014 eBusiness Information, Excilys Group | ||
| * | ||
| * 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; | ||
|
|
||
|
|
||
| import org.androidannotations.annotations.rest.Header; | ||
| import org.androidannotations.annotations.rest.Headers; | ||
| import org.androidannotations.annotations.rest.Post; | ||
| import org.androidannotations.annotations.rest.Rest; | ||
| import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter; | ||
|
|
||
|
|
||
| @Rest(converters = MappingJacksonHttpMessageConverter.class) | ||
| public interface ClientWithOneHeaderInHeaders { | ||
|
|
||
| @Headers({@Header(headerName="testKey", value="testVal")}) | ||
| @Post("/test/") | ||
| void requestWithOneHeader(); | ||
| } |
49 changes: 49 additions & 0 deletions
49
...tations/androidannotations/src/test/java/org/androidannotations/rest/RestHeadersTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * Copyright (C) 2010-2014 eBusiness Information, Excilys Group | ||
| * | ||
| * 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; | ||
|
|
||
| import org.androidannotations.AndroidAnnotationProcessor; | ||
| import org.androidannotations.utils.AAProcessorTestHelper; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import dalvik.annotation.TestTargetClass; | ||
|
|
||
| public class RestHeadersTest extends AAProcessorTestHelper { | ||
|
|
||
| @Before | ||
| public void setup() { | ||
| addManifestProcessorParameter(RestConverterTest.class); | ||
| addProcessor(AndroidAnnotationProcessor.class); | ||
| } | ||
|
|
||
| @Test | ||
| public void client_with_one_header_compiles() { | ||
| CompileResult result = compileFiles(ClientWithOneHeader.class); | ||
| assertCompilationSuccessful(result); | ||
| } | ||
|
|
||
| @Test | ||
| public void client_with_one_header_in_multiple_annotation_compiles() { | ||
| CompileResult result = compileFiles(ClientWithOneHeaderInHeaders.class); | ||
| assertCompilationSuccessful(result); | ||
| } | ||
|
|
||
| @Test | ||
| public void client_with_multiple_headers_test() { | ||
| CompileResult result = compileFiles(ClientWithMultipleHeaders.class); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use GitHub comments instead of commenting this kind of things directly into the code...