These are chat archives for spring-cloud/spring-cloud

9th
Dec 2015
Dominik Bartholdi
@imod
Dec 09 2015 12:28
what is the easiest way to access the credentials of a serviceinfo from VCAP_SERVICES? I know I could do something like this: List<ServiceInfo> serviceInfos = cloud.getServiceInfos(RelationalServiceInfo.class) - but the problem is that I need to access some service info which does not directly correspond to a ServiceInfo class, in particular I need to access the NewRelic licensekey (http://docs.run.pivotal.io/marketplace/services/newrelic/#vcap-services). In this case the service info is usually only used by the buildpack (but still available in VCAP_SERVICES). So in other words: is there a generic way to access this info via spring cloud? (not having to parse the Json myself).
Dave Syer
@dsyer
Dec 09 2015 15:45
You should find all the vcap properties in the environment
Eg ${vcap.services.newrelic.credentials.licenseKey} might be there (depending on the format of the Json)
Joao Duraes
@joaoduraes
Dec 09 2015 17:29
hey guys.. I’m using feign with spring cloud and I am wondering how’s the support for Pageable objects?
there is a PageableHandlerMethodArgumentResolver that resolves the parameters in the request to build the Pageable object
can I just declare a method in the feign client without parameters and it will work?
Dave Syer
@dsyer
Dec 09 2015 17:34
The method needs parameters if you want to get all the pages, right?
Otherwise you are just going to get the default page
E.g.
    @RequestMapping(value = "/messages", method=RequestMethod.GET)
    PagedResources<Message> messages(@RequestParam("page") int page);
That works for me with a Spring Data repository backend
Joao Duraes
@joaoduraes
Dec 09 2015 17:37
so we should declare all the page related parameters in the methods?
and not rely on the PageableHandlerMethodArgumentResolver ?
this is what we have now: Page<WebsiteDTO> findAllByAccountId(Long accountId, Pageable pageable);
Dave Syer
@dsyer
Dec 09 2015 17:39
That should work too
But it's not "without parameters" is it?
Joao Duraes
@joaoduraes
Dec 09 2015 17:40
but when creating the feign client, if I have parameters on a GET method, we get this exception, which makes sense
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'websiteFeignClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Method has too many Body parameters: public abstract org.springframework.data.domain.Page com.clipkit.plankton.api.WebsiteApi.getMyWebsites(org.springframework.data.domain.Pageable,java.security.Principal)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1585) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    ... 45 common frames omitted
Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract org.springframework.data.domain.Page com.clipkit.plankton.api.WebsiteApi.getMyWebsites(org.springframework.data.domain.Pageable,java.security.Principal)
    at feign.Util.checkState(Util.java:112) ~[feign-core-8.11.0.jar:8.11.0]
    at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:111) ~[feign-core-8.11.0.jar:8.11.0]
    at org.springframework.cloud.netflix.feign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:71) ~[spring-cloud-netflix-core-1.1.0.M3.jar:1.1.0.M3]
    at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:61) ~[feign-core-8.11.0.jar:8.11.0]
    at feign.hystrix.HystrixDelegatingContract.parseAndValidatateMetadata(HystrixDelegatingContract.java:24) ~[feign-hystrix-8.11.0.jar:8.11.0]
    at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:137) ~[feign-core-8.11.0.jar:8.11.0]
    at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:55) ~[feign-core-8.11.0.jar:8.11.0]
    at feign.Feign$Builder.target(Feign.java:179) ~[feign-core-8.11.0.jar:8.11.0]
    at feign.Feign$Builder.target(Feign.java:175) ~[feign-core-8.11.0.jar:8.11.0]
    at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:148) ~[spring-cloud-netflix-core-1.1.0.M3.jar:1.1.0.M3]
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    ... 53 common frames omitted
Dave Syer
@dsyer
Dec 09 2015 17:40
Don't you need an annotation somewhere?
Joao Duraes
@joaoduraes
Dec 09 2015 17:40
for the Pageable?
Dave Syer
@dsyer
Dec 09 2015 17:41
Don't know. I never saw this feature.
PageableHandlerMethodArgumentResolver is a server side feature
Did anyone write a Feign processor that goes with it?
Joao Duraes
@joaoduraes
Dec 09 2015 17:42
I was not able to find it, but I guess that probably not
Dave Syer
@dsyer
Dec 09 2015 17:42
I guess not too
Seems like a useful addition
But the workaround is easy as well
Send a PR if you get one that works
Joao Duraes
@joaoduraes
Dec 09 2015 17:43
could you give me a hint on how to start to write a feign processor?
Dave Syer
@dsyer
Dec 09 2015 17:46
Look at the existing ones I guess.
Joao Duraes
@joaoduraes
Dec 09 2015 17:47
ok, I’ll try to take a look
:)
thank you
Dave Syer
@dsyer
Dec 09 2015 17:47
e.g. PathVariableParameterProcessor