-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
org.ocpsoft.rewrite.servlet.config.Resource.java is not resolving resources properly in a Spring-boot application #206
Comments
Thanks for reporting this. Could you perhaps use your debugger to check if the rewrite/config-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/Resource.java Line 62 in a39a2d1
And could you post the value of the |
The value is |
Yeah, your are correct. I just checked the javadocs: http://docs.oracle.com/javaee/7/api/javax/servlet/ServletContext.html#getResource(java.lang.String) However, from my understanding |
I have cross-posted that to stackoverflow http://stackoverflow.com/questions/29512824/ocpsoft-rewrite-is-not-able-to-detect-a-class-path-resource-in-a-spring-boot-app. For now I have found a workaround: class Resource extends HttpCondition implements Parameterized {
private final ParameterizedPatternParser resource;
public Resource(final String resource) {
this.resource = new RegexParameterizedPatternParser(resource);
}
@Override
public boolean evaluateHttp(HttpServletRewrite event, EvaluationContext context) {
if (resource != null) {
ParameterizedPatternBuilder builder = resource.getBuilder();
if (builder.isParameterComplete(event, context)) {
String file = builder.build(event, context, Transpositions.encodePath());
try {
return new ClassPathResource("META-INF/resources" + file).exists();
} catch (Exception e) {
log.debug("Invalid file format [{}]", file);
}
}
// the default implementation does handle the !builder.isParameterComplete(event, context) here
}
return false;
}
@Override
public Set<String> getRequiredParameterNames() {
return resource.getRequiredParameterNames();
}
@Override
public void setParameterStore(ParameterStore store) {
resource.setParameterStore(store);
}
} |
Sure. Of cause you can create your own condition and implement it like this. That's fine. However, I really think the default Resource class should work fine. Perhaps a Spring Boot / Jetty issue? |
I know for sure that my classic WAR deployment works with that Resource class. It was only required within the Spring Boot environment- |
So a Spring Boot issue... |
I have a working web application with the ocpsoft rewrite filter installed.
It is trying to detect the existence of an asset deployed with the application (as a webjar). For example the resource path (file name) might be
/webjars/web-client/6.1.31.LOCAL/js/app.c0344c23.js
.However when executed within the same Spring-boot(-ified) application the rewrite filter is not able to load such resources and fails with rewriting. It is the
org.ocpsoft.rewrite.servlet.config.Resource#evaluateHttp
that fails withreturn (event.getServletContext().getResource(file) != null)
.When executing
new ClassPathResource("META-INF/resources/webjars/web-client/6.1.31.LOCAL/js/app.c0344c23.js").getInputStream()
at the same location, Spring's ClassPathResource is able to load the resource - so it is there at the right location. It just can't be loaded using the servlet context object used by the rewriteResource
class.The Spring-boot setup for the filter is
The rewrite configuration provider is registered through a
/META-INF/services/org.ocpsoft.rewrite.config.ConfigurationProvider
file located in the classpath.The text was updated successfully, but these errors were encountered: