Excludes issue SiteMesh in an application with JAX-RS on GlassFish

102 views
Skip to first unread message

Stephan Kliche

unread,
Dec 12, 2012, 2:58:33 PM12/12/12
to sitemes...@googlegroups.com
Hi Group,

I am using SiteMesh 3.0-alpha-2 in an application which also provides some REST endpoints using JAX-RS and it is running on GlassFish 3.1.2. In the application I defined a JAX-RS ApplicationConfig and mapped the endpoint to "/api":

@ApplicationPath("/api")
public class RestApp extends Application {
}

I also defined a REST endpoint under "/test" (method = GET)

@Path("/test")
@Stateless
public class RestEndpoint {
@GET
public String test() {
return "blah";
}

So I can access my RestEndpoint via http://host:port/MyApplication/api/test - works fine so far.

Now I added SiteMesh and defined an excludePath in my configuration. I also added a default decorator:

@WebFilter("/*")
public class SitemeshFilter extends org.sitemesh.config.ConfigurableSiteMeshFilter{
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder
.addExcludedPath("/api/*")
.addDecoratorPath("/*", "/decorators/baseDecorator.html");
}
}

 If I am accessing my API as described above, the result is also decorated and that was not my intention. 

So I downloaded the sources and tried to figure out how the excludes are mapped. As far as I understand SiteMesh the class BasicSelector and BaseSiteMeshFilterBuilder which overrides shouldBufferForRequest handles the exclusions. It uses the requestPath and does a lookup in the excludesmapper. So i did some debugging and found out, that the requestPath is not the same I entered in the browser... My expectation was, that when I enter http://host:port/MyApplication/api/test, the requestPath would be /api/test. But it's not. It is only /api.... so I changed my WebFilter the following way:
 
@WebFilter("/*")
public class SitemeshFilter extends org.sitemesh.config.ConfigurableSiteMeshFilter{
@Override
protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
builder
.addExcludedPath("/api/*")
.addExcludedPath("/api") 
.addDecoratorPath("/*", "/decorators/baseDecorator.html");
}
}

That works...

The method getRequestPath in the class WebAppContext calculates the path and for http://host:port/MyApplication/api/test it only returns /api. I am not sure if I am wrong, but shouldn't SiteMesh also evaluate the pathInfo? Right now in my case only the servletPath is evaluated.

Well... that mapping is quite complex - to me it would be useful to have more logging :)


sitemesh.png

Tin Pham

unread,
Dec 14, 2012, 8:14:48 AM12/14/12
to sitemes...@googlegroups.com, sitemes...@googlegroups.com
Hi Stephan,

That's an excellent point and well described. Let me take a look and verify that this is a bug. If so I'll get it fixed.

FYI, I never run into this kind of issue as I always define view folders ie web-view mobile-view and decorate only those. I find it easier to manage than decorating /.

Even my images and other auxiliary files sit outside of these folders.

I'm manage the docs for SiteMesh2 so I'll add a reference implementation with a structure that has worked well for me over the years.

Tin
<sitemesh.png>

Stephan Kliche

unread,
Dec 26, 2012, 5:53:51 AM12/26/12
to sitemes...@googlegroups.com
Hi Tin,

thank you for your reply. - So you suggest that in combination with spring-webmvc you would not decorate the path's I am using in the controllers, you would rather decorate the views my controllers are using? This is an interesting point. I will try that out. Thanks!
Reply all
Reply to author
Forward
0 new messages