Reputation: 31
I have set up static resource serving with SpringBoot like so:
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/data/**")
.addResourceLocations("file:data/");
}
}
And when I'm trying to fetch the resource on the /data
endpoint, I get the file I requested, but the headers Date
and Last-Modified
seem to be in UTC time zone format. I tried manually setting the default time zone to Europe/Zagreb
and doing:
System.out.println(LocalDateTime.now());
Prints the expected result, but if I do:
System.out.println(Files.getLastModifiedTime(Paths.get(lastProcessedPath)));
I get the time in UTC, the same thing with fetching files on the configured resource endpoint, as mentioned earlier.
I tried using Filters but unsuccessfully, because if I call doFilter()
before I do any logic to setting the custom Headers, the response is returned and then modified, but if I try doing any logic before doFilter()
I don't know what resource is in question and can't know last modified
data.
I'm not sure whether something like that can be achieved using ResourceResolver interface - documentation is quite confusing on that one.
Upvotes: 1
Views: 61
Reputation: 1
I may be misinterpreting the case here, if the issue is about setting the zone to use and mapping it you could send your local date time to a ZonedDateTime then use that to print using a formatter
ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, "Europe/Zagreb")
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
return zonedDateTime.format(formatter);
Upvotes: 0