I have added static resrouces to spring cloud project and noticed that static resources served incorrectly.
_Png_ resource not displayed after downloading from backend, _Jpg_ displayed wrong.
Here is my build.gradle content:
buildscript {
ext {
springBootVersion = '2.0.0.M6'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
repositories {
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
dependencies {
compile (group: 'org.springframework.cloud', name: 'spring-cloud-starter-gateway', version: '2.0.0.M5')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux'
}
Here is Application source:
import static org.springframework.web.reactive.function.server.RouterFunctions.resources;
@Configuration
@SpringBootApplication
public class GatewayApplication {
@Bean
public RouterFunction<ServerResponse> monoRouterFunction() {
return resources("/**", new ClassPathResource("public/"));
}
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
Here is how _jpg_ request/response looks like:

And here is how _png_ request/response looks like:

How is this a gateway problem? You're not going through the gateway to view the images.
Idea was that gateway is also host all static resources, and all request from browser goes to gateway(both static and REST requests, REST request routed to services). This way we escape CORS issues.
Putting the following in application.properties:
spring.webflux.static-path-pattern=/static/*
and a jpg and png in src/main/resources/static
and this bean
@Bean
public RouteLocator routes(RouteLocatorBuilder builder) {
return builder.routes()
.route(r -> r.path("/get").uri("http://httpbin.org:80"))
.build();
}
I was able to see the images at http://localhost/static/test.png and http://localhost/static/test.jpg and http://localhost/get proxied thru.
You'll need to post a minimal project that recreates the problem.
I have created simple project. However i can't found class RouteLocatorBuilder(import or version problem?) so it was little different:
https://github.com/muzuro/spring-cloud-gateway-issue184/commit/9a01d7763089ee2c825e16e50ac1501f6f1d13a4
When i made request to http://localhost:8080/static/yc.png it failed with:
2018-02-07 23:04:46.373 [reactor-http-nio-2] ERROR o.s.b.a.w.r.e.DefaultErrorWebExceptionHandler.logError:197 - Failed to handle request [GET http://localhost:8080/static/soren.jpg]
java.lang.NullPointerException: null
at org.springframework.cloud.gateway.handler.RoutePredicateHandlerMapping.lambda$lookupRoute$2(RoutePredicateHandlerMapping.java:81)
at reactor.core.publisher.FluxFilterFuseable$FilterFuseableSubscriber.tryOnNext(FluxFilterFuseable.java:122)
at reactor.core.publisher.FluxIterable$IterableSubscriptionConditional.fastPath(FluxIterable.java:485)
at reactor.core.publisher.FluxIterable$IterableSubscriptionConditional.request(FluxIterable.java:385)
at reactor.core.publisher.FluxFilterFuseable$FilterFuseableSubscriber.request(FluxFilterFuseable.java:170)
Then i added manual route: https://github.com/muzuro/spring-cloud-gateway-issue184/commit/3ee49c00f0df0b38777777f832a46f8c6c4858da
And it worked, resources served without problems. Will research what was added at main project. There is also other routes and controlles.
boot M7 and gateway M5 are the latest, that why.
OK. Feel free to reopen if you can find an issue that needs fixing.
@spencergibb Which version of spring boot and gateway you recommend to use?
the ones I mentioned. We'll have a new milestone of gateway that will go with boot RC1 soon