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

23rd
Sep 2018
Dieter Hubau
@Turbots
Sep 23 2018 13:50
@dsyer im playing around with Riff again to make a demo I told you about once (Mandelbrot visualizer of some kind)
and a lot has changed with KNative and the changes to Riff itself etc, so im struggling a bit to invoke my function:
public class MandelbrotFunction implements Function<String, Integer> {
}
when I deploy and invoke this function (implementation not relevant I think) on my brand new GKE cluster with Istio and Riff enabled, I get the following response:
[]{"timestamp":"Sep 23, 2018 1:13:51 PM","status":200,"error":"OK","exception":"java.lang.ClassCastException","message":"org.springframework.util.LinkedMultiValueMap cannot be cast to java.lang.String","path":"/"}
invoking it like this: riff service invoke mandelbrot -- -w '\n' -d ‘2.0,3.0,1'
Dieter Hubau
@Turbots
Sep 23 2018 14:40
i’ll try to upgrade to riff 0.1.3 first and try the buildpack to deploy it, it seems theres a new option —json to invoke a function with other content types
Emre
@TheCoder84
Sep 23 2018 14:48
hi all , i wonder that what is purpose of new() operator on Autowired field like below
thanks
@Autowired(required = false)
private final SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory = new SimpleMessageListenerContainerFactory();
Dieter Hubau
@Turbots
Sep 23 2018 15:04
@TheCoder84 since the @Autowired annotation states it is not required, you need to instantiate the field manually using the constructor for when Spring cannot find a suitable candidate of type SimpleMessageListenerContainerFactory
if Spring can find a bean of type SimpleMessageListenerContainerFactory, it will use that one
Emre
@TheCoder84
Sep 23 2018 15:05
waw nice. thank you @Turbots
Dieter Hubau
@Turbots
Sep 23 2018 15:06
you’re welcome :-)
Yang Yang
@reliveyy
Sep 23 2018 15:24
hi, I'm tring to implement a i18n filter in spring cloud gateway
@Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpResponse originalResponse = exchange.getResponse();
        DataBufferFactory bufferFactory = originalResponse.bufferFactory();
        ServerHttpResponseDecorator decoratedResponse = new ServerHttpResponseDecorator(originalResponse) {
            @Override
            @SuppressWarnings("unchecked")
            public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
                if (body instanceof Flux) {
                    Flux<DataBuffer> fluxBody = (Flux<DataBuffer>) body;
                    return super.writeWith(fluxBody
                            .reduce((buf1, buf2) -> bufferFactory.join(Arrays.asList(buf1, buf2)))
                            .map(buf -> {
                                byte[] data = new byte[buf.readableByteCount()];
                                buf.read(data);
                                String content = new String(data);
                                // how to get related request locale here ?
                                return bufferFactory.wrap(i18nContent("en_US", content).getBytes());
                            })
                    );
                }
                return super.writeWith(body); // if body is not a flux. never got there.
            }
        };
        return chain.filter(exchange.mutate().response(decoratedResponse).build()); // replace response with decorator
    }
But I don't know how to get the related request locale in ServerHttpResponseDecorator
public class I18nFilter implements GlobalFilter, Ordered
Can I use exchange.getRequest().getHeaders().getAcceptLanguageAsLocales() directly in filter