Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interceptors mechanism (fixes #6) #17

Merged
merged 1 commit into from
Nov 15, 2014

Conversation

nurkiewicz
Copy link
Contributor

Changes REST invocation flow from simple RestClientMethodInterceptor -> RestTemplateInvoker to much more flexible and extensible interceptor/handler architecture. Basically each REST call is wrapped in RestInvocation value object and passed to first RestInvocationHandler (with highest priority). Each handler can either process invocation or pass is further (invocation.proceed(), see LoggingHandler). Last handler must handle the request, typically this will be RestTemplateInvoker (added automatically to the end of handlers chain).

Handlers are auto-discovered in application context and sorted using Ordered interface. This architecture makes it very easy to implement a lot of custom functionality:

And a lot more. It's basically specialized AOP inside the library.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 977f854 on nurkiewicz:interceptors into * on Codearte:master*.

@@ -138,7 +140,8 @@ private boolean checkQualifier(BeanDefinition endpointBeanDefinition, Annotation
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
RestTemplate restTemplate = provideRestTemplate(this.beanFactory);
beanProxyCreator = new BeanProxyCreator(restTemplate);
final Collection<RestInvocationHandler> handlers = ((ConfigurableListableBeanFactory) beanFactory).getBeansOfType(RestInvocationHandler.class).values();
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure all RestInvocationHandlers are available at this point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, this can be an issue. I'll try to make it lazier.

Copy link
Member

Choose a reason for hiding this comment

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

I think we have to look at @DependsOn internals :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not very helpful: AbstractBeanFactory#L286.

Copy link
Member

Choose a reason for hiding this comment

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

@coveralls
Copy link

Coverage Status

Coverage increased (+0.76%) when pulling e59eb57 on nurkiewicz:interceptors into 0ed3f15 on Codearte:master.

<artifactId>objenesis</artifactId>
<version>2.1</version>
<scope>test</scope>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need those dependencies defined explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mocking of some classes wasn't working without it. Try removing these dependencies, maybe it became obsolete in the meantime.

… handlers

Implements chain-of-responsibility pattern
@coveralls
Copy link

Coverage Status

Coverage increased (+0.57%) when pulling 1fee956 on nurkiewicz:interceptors into 5dfcf0d on Codearte:master.

@jkubrynski jkubrynski merged commit 1fee956 into Codearte:master Nov 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants