0

I'm trying to use the Application Security on Cloud provided by Bluemix for a Spring application.

I'm relatively new to Spring and I'm having difficulty serving the requested verification file with the requested url. Bluemix wants the html file to be available at /IBMDomainVerification.html

However, I can't figure out how to serve the html file given that exact url using Spring. I can serve it without the .html at the end of the url but that's not what it needs.

If anyone can let me know how I can serve the html file given the specified url with the .html extension on the end that'd be great!

Thanks!

Andre
  • 49
  • 1
  • 5

1 Answers1

0

Spring 4.1 introduced the ResourceResolvers, that can resolve resources, given their URL path. In particular you could use the simplest: PathResourceResolver. This is the simplest resolver and its purpose is to find a resource given a public URL pattern. In fact, if no ResourceResolver is added to the ResourceChainRegistration, this is the default resolver.

Consider the following example:

@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
  .addResourceHandler("/resources/**")
  .addResourceLocations("/resources/","/other-resources/")
  .setCachePeriod(3600)
  .resourceChain(true)
  .addResolver(new PathResourceResolver());
}

The above code serves anything in either the webapp/resources of the webapp/other-resources folder, required with URLs /resources/** (e.g. /resources/foo.js). Note the two asterisks, it means that it will match everything after resources/, even '/'.

In your case using /IBMDomainVerification.html (/**) it should work.

An alternative way could be using *<mvc:resources/>* (Spring 3) which can be used to serve static resources while still using the DispatchServlet on root. Please refer to this SO answer.

Community
  • 1
  • 1
Umberto Manganiello
  • 3,213
  • 9
  • 16