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

6th
Nov 2015
ccit-spence
@ccit-spence
Nov 06 2015 00:44
@spencergibb One thing I notice is that ribbon and DevTools do not seem to like each other
Spencer Gibb
@spencergibb
Nov 06 2015 00:47
That may be, never tried. Open an issue on that one if you don’t mind.
ccit-spence
@ccit-spence
Nov 06 2015 00:47
sure, just noticing adding simple println to a controller and will get a 500 on refresh
ccit-spence
@ccit-spence
Nov 06 2015 01:51
@spencergibb In finally got a resttemplate version working. I need to override the Eureka Aware RestTemplate to make it SDR friendly.
This is what I had to do to a RestTemplate to get it to work
 private RestTemplate restTemplate() {
  ObjectMapper mapper = new ObjectMapper();
  mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  mapper.registerModule(new Jackson2HalModule());

  MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
  converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
  converter.setObjectMapper(mapper);
  return new RestTemplate(Arrays.asList(converter));
 }
How would I apply that to the eureka version
ccit-spence
@ccit-spence
Nov 06 2015 04:26
@spencergibb Can I override this class? RibbonAutoConfiguration looking mainly at the RestTemplateCustomizer
Is that where the Eureka aware RestTemplate is coming from?
Simon
@sbuettner
Nov 06 2015 09:22
hi guys
i am currently struggling with the feign configuration.
Is there a way to configure hystrix to pass exceptions returned by the error encoder and avoid fallback logic. It seems like all exceptions are catched by hystrix which doesnt make much sense for things like Bad requests or authentication issues.
Simon
@sbuettner
Nov 06 2015 10:38
Without subclassing HystrixBadRequestException ?
Marcin Grzejszczak
@marcingrzejszczak
Nov 06 2015 10:54
@sbuettner doesn't this solve your issue: Netflix/Hystrix#241 ?
I guess this is pretty up to date
Simon
@sbuettner
Nov 06 2015 12:50
@marcingrzejszczak but that relies on inheriting HystrixBadRequestException
Simon
@sbuettner
Nov 06 2015 13:07
@marcingrzejszczak thanks
Petar Tahchiev
@ptahchiev
Nov 06 2015 13:18
Hello, I want my spring boot app to be deployed on cloudfoundry and I want to use elasticsearch.. however this doesn't seem to be possible
says you have to create a JestClient which does not extend from elasticsearch's Client
so spring-boot will try to create one client for me
and it will fail with exception because it cannot parse the url:
2015-11-06T15:06:45.95+0200 [APP/0]      ERR Caused by: java.lang.NumberFormatException: For input string: "XXXXXXX@fili-us-east-1.searchly.com:80"
2015-11-06T15:06:45.95+0200 [APP/0]      ERR     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
2015-11-06T15:06:45.95+0200 [APP/0]      ERR     at java.lang.Integer.parseInt(Integer.java:580)
I made a pull request that there was a missing @ConditionalOnMissingBean for the elasticsearch client
spring-projects/spring-boot#4143
and it was merged... however the problem still stays because JestClient is not a org.elasticsearch.client.Client
any thoughts?
Simon
@sbuettner
Nov 06 2015 14:17
anyone using Feign inside a Project that uses SpringFox Swagger?
There seems to be an issue when using the @FeignClient annotation due to its context refreshes.
Spencer Gibb
@spencergibb
Nov 06 2015 16:35
@sbuettner not that I know of.
@ptahchiev not sure this is the right channel for your elastic search question
@ccit-spence you just need to create a @Bean of type RestTemplate. It should get load balanced.
Petar Tahchiev
@ptahchiev
Nov 06 2015 18:41
@spencergibb ok I'll ask it to the boot guys
ccit-spence
@ccit-spence
Nov 06 2015 21:35
@spencergibb I am not sure how to create the bean for the RestTemplate. If I just add a @Bean to the above example it does not work. I tried extending RestTemplate and using @Component and still it uses the default RestTemplate. I can’t seem to target the Eureka aware version of RestTemplate.
Spencer Gibb
@spencergibb
Nov 06 2015 21:37
an @Bean should be all that is needed.
ccit-spence
@ccit-spence
Nov 06 2015 21:44
This should work? I had it in a @Configuration file. Tried moving to the Application.java as well. I end up with java.net.UnknownHostException: test-service
    @Bean
    RestTemplate restTemplate() {

        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.registerModule(new Jackson2HalModule());

        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
        converter.setObjectMapper(mapper);
        return new RestTemplate(Arrays.asList(converter));

    }
Spencer Gibb
@spencergibb
Nov 06 2015 21:54
should
ccit-spence
@ccit-spence
Nov 06 2015 21:56
If I use the correct hostname it will work. If I use the ServiceID it will not work
If I remove any mods to RestTemplate the ServiceID will work. Then the object will not deserialize.
ccit-spence
@ccit-spence
Nov 06 2015 22:06
I actually tried that as well. I only used the converters and dropped the requestFactory.
Spencer Gibb
@spencergibb
Nov 06 2015 22:06
the requestFactory is what puts ribbon into the RestTemplate
ccit-spence
@ccit-spence
Nov 06 2015 22:30
In your example you are modifying it for async capabilities. For my purpose I don’t need the async stuff correct? “I have nothing using async at this time"
Spencer Gibb
@spencergibb
Nov 06 2015 22:30
right, you need the requestFactory
ccit-spence
@ccit-spence
Nov 06 2015 22:31
so this is all that is needed?
Spencer Gibb
@spencergibb
Nov 06 2015 22:31
for the non async, RibbonClientHttpRequestFactory requestFactory
ccit-spence
@ccit-spence
Nov 06 2015 22:31
    @Bean
    public RestTemplateCustomizer restTemplateCustomizer(final RibbonClientHttpRequestFactory requestFactory) {
        return restTemplate -> {
            restTemplate.setRequestFactory(requestFactory);
            addConverters(restTemplate);
        };
    }

    private void addConverters(RestTemplate restTemplate) {
        List<HttpMessageConverter<?>> converters = getHttpMessageConverters();
        restTemplate.setMessageConverters(converters);
    }

    private List<HttpMessageConverter<?>> getHttpMessageConverters() {
        List<HttpMessageConverter<?>> converters = new ArrayList<>();
        converters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));

        ObjectMapper mapper = new ObjectMapper();
        mapper.registerModule(new Jackson2HalModule());
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();

        converter.setObjectMapper(mapper);
        converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
        //converter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));

        converters.add(converter);
        return converters;
    }
Spencer Gibb
@spencergibb
Nov 06 2015 22:31
looks right
ccit-spence
@ccit-spence
Nov 06 2015 22:33
Then in my controller
    @Autowired
    RestTemplate restTemplate;
Spencer Gibb
@spencergibb
Nov 06 2015 22:33
Yes, adding @LoadBalanced would clarify
ccit-spence
@ccit-spence
Nov 06 2015 22:36
It works for using the serviceID but fails to deserialize the object
ccit-spence
@ccit-spence
Nov 06 2015 22:51
Something else I noticed is having that config broke actuator
I was wrong about the config causing it. Something about ribbon is breaking actuator endpoints for me