Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void enclosingElementHasOneOfAnnotations(Element element, List<Class<? ex
hasOneOfAnnotations(element, element.getEnclosingElement(), validAnnotations, validation);
}

private void hasOneOfAnnotations(Element reportElement, Element element, List<Class<? extends Annotation>> validAnnotations, ElementValidation validation) {
public void hasOneOfAnnotations(Element reportElement, Element element, List<Class<? extends Annotation>> validAnnotations, ElementValidation validation) {
checkAnnotations(reportElement, element, validAnnotations, true, validation);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (C) 2010-2015 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.spring.annotations;

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 classes to add headers to a
* particular method.
*
* <blockquote>
*
* <b>Example :</b>
*
* <pre>
* &#064;Rest(converters = MappingJacksonHttpMessageConverter.class)
* public interface MyRestClient {
*
* &#064;Header(name = &quot;keep-alive&quot;, name = &quot;300&quot;)
* &#064;Post(&quot;/test&quot;)
* void testRoute();
* }
* </pre>
*
* </blockquote>
*
* @see Headers
*/
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
public @interface Header {
String name();

String value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (C) 2010-2015 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.spring.annotations;

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 classes to add multiple headers to a
* given method.
*
* <blockquote>
*
* <b>Example :</b>
*
* <pre>
* &#064;Rest(converters = MappingJacksonHttpMessageConverter.class)
* public interface MyRestClient {
*
* &#064;Headers({
* &#064;Header(name = &quot;keep-alive&quot;, value = &quot;300&quot;),
* &#064;Header(name = &quot;cache-control&quot;, value = &quot;64000&quot;)})
* &#064;Post(&quot;/test&quot;)
* void testRoute();
* }
* </pre>
*
* </blockquote>
*
* @see Header
*/
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
public @interface Headers {
Header[] value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
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;
Expand Down Expand Up @@ -172,6 +174,19 @@ public interface MyService {
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithPathParameters(@Path("date") String pathParam, @Field String parameter);

@Post("/events/{date}")
@RequiresHeader("SomeFancyHeader")
@Header(name = "SomeFancyHeader", value = "fancy")
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithHeaders(String date, String parameter);

@Post("/events/{date}")
@Headers(@Header(name = "SomeFancyHeader", value = "fancy"))
@RequiresCookie("myCookie")
@RequiresCookieInUrl("myCookieInUrl")
void addEventWithHeadersHeadersAnnotation(String date, String parameter);

/**
* Output different then input
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,49 @@ public void execute(MyService myService) {
});
}

@Test
public void addEventWithHeadersOverriden() {
RequestTestBuilder.build() //
.requestCookie("myCookie", "myCookieValue") //
.requestHeader("SomeFancyHeader", "aFancyHeader") //
.responseContent("{'id':1,'name':'event1'}") //
.hasUrlVariables(true) //
.asserts(new RequestTestBuilder.RequestTestBuilderExecutor() {
@Override
public void execute(MyService myService) {
myService.addEventWithHeaders("now", "event");
}
});
}

@Test
public void addEventWithHeaders() {
RequestTestBuilder.build() //
.requestCookie("myCookie", "myCookieValue") //
.expectedHeader("SomeFancyHeader", "fancy") //
.responseContent("{'id':1,'name':'event1'}") //
.hasUrlVariables(true) //
.asserts(new RequestTestBuilder.RequestTestBuilderExecutor() {
@Override
public void execute(MyService myService) {
myService.addEventWithHeaders("now", "event");
}
});
}

@Test
public void addEventWithHeadersHeadersAnnotation() {
RequestTestBuilder.build() //
.requestCookie("myCookie", "myCookieValue") //
.expectedHeader("SomeFancyHeader", "fancy") //
.responseContent("{'id':1,'name':'event1'}") //
.hasUrlVariables(true) //
.asserts(new RequestTestBuilder.RequestTestBuilderExecutor() {
@Override
public void execute(MyService myService) {
myService.addEventWithHeadersHeadersAnnotation("now", "event");
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.androidannotations.rest.spring.handler.DeleteHandler;
import org.androidannotations.rest.spring.handler.GetHandler;
import org.androidannotations.rest.spring.handler.HeadHandler;
import org.androidannotations.rest.spring.handler.HeaderHandler;
import org.androidannotations.rest.spring.handler.HeadersHandler;
import org.androidannotations.rest.spring.handler.OptionsHandler;
import org.androidannotations.rest.spring.handler.PathHandler;
import org.androidannotations.rest.spring.handler.PostHandler;
Expand Down Expand Up @@ -51,6 +53,8 @@ public List<AnnotationHandler<?>> getHandlers(AndroidAnnotationsEnvironment andr
annotationHandlers.add(new HeadHandler(androidAnnotationEnv));
annotationHandlers.add(new OptionsHandler(androidAnnotationEnv));
annotationHandlers.add(new PathHandler(androidAnnotationEnv));
annotationHandlers.add(new HeaderHandler(androidAnnotationEnv));
annotationHandlers.add(new HeadersHandler(androidAnnotationEnv));
annotationHandlers.add(new RestServiceHandler(androidAnnotationEnv));
return annotationHandlers;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (C) 2010-2015 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.spring.handler;

import javax.lang.model.element.Element;

import org.androidannotations.AndroidAnnotationsEnvironment;
import org.androidannotations.ElementValidation;
import org.androidannotations.handler.BaseAnnotationHandler;
import org.androidannotations.rest.spring.annotations.Header;
import org.androidannotations.rest.spring.annotations.Headers;
import org.androidannotations.rest.spring.helper.RestSpringValidatorHelper;
import org.androidannotations.rest.spring.holder.RestHolder;

public class HeaderHandler extends BaseAnnotationHandler<RestHolder> {

private RestSpringValidatorHelper restValidatorHelper;

public HeaderHandler(AndroidAnnotationsEnvironment environment) {
super(Header.class, environment);
restValidatorHelper = new RestSpringValidatorHelper(environment, getTarget());
}

@Override
protected void validate(Element element, ElementValidation validation) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You put validate after process again...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it was a messy rebase.

restValidatorHelper.elementHasOneOfRestMethodAnnotations(element, validation);

validatorHelper.doesNotHaveAnnotation(element, Headers.class, validation);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must define a precedence of Header and Headers and also write it in the doc if we remove this. Do we want to do that?

}

@Override
public void process(Element element, RestHolder holder) throws Exception {
// empty
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (C) 2010-2015 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.spring.handler;

import javax.lang.model.element.Element;

import org.androidannotations.AndroidAnnotationsEnvironment;
import org.androidannotations.ElementValidation;
import org.androidannotations.handler.BaseAnnotationHandler;
import org.androidannotations.rest.spring.annotations.Header;
import org.androidannotations.rest.spring.annotations.Headers;
import org.androidannotations.rest.spring.helper.RestSpringValidatorHelper;
import org.androidannotations.rest.spring.holder.RestHolder;

public class HeadersHandler extends BaseAnnotationHandler<RestHolder> {

private RestSpringValidatorHelper restValidatorHelper;

public HeadersHandler(AndroidAnnotationsEnvironment environment) {
super(Headers.class, environment);
restValidatorHelper = new RestSpringValidatorHelper(environment, getTarget());
}

@Override
protected void validate(Element element, ElementValidation validation) {
restValidatorHelper.elementHasOneOfRestMethodAnnotations(element, validation);

validatorHelper.doesNotHaveAnnotation(element, Header.class, validation);
}

@Override
public void process(Element element, RestHolder holder) throws Exception {
// empty
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.