How to get the WRO4J generated content from a servet?

35 views
Skip to first unread message

Tekno

unread,
Nov 14, 2013, 9:01:17 AM11/14/13
to wr...@googlegroups.com
Hi,

I'd like to get the content of the generated WRO4J from a java servlet.

I need this because I want to calculate the hash of the content, and then distribute the file via an url: /hashed/$HASH/wro/style.css

The servlet that listens on /hashed/* gets the content from the original URL using a RequestDispatcher. Something like this:


        RequestDispatcher dispatcher = context.getRequestDispatcher(plainUri);
        ByteArrayResponseWrapper responseWrapper = new ByteArrayResponseWrapper(resp);
        dispatcher.include(req, responseWrapper);
        byte[] bytes = responseWrapper.getBytes();
        String hash = SHA1Digest.toSHA1(bytes);

     // if the calculated hash is the same as in the request uri then:

        resp.getWriter().println(SHA1Digest.toSHA1(bytes));
        resp.addHeader("Cache-Control", "max-age=" + SECONDS_IN_A_YEAR + ", public");
        resp.addHeader("ETAG", hash);
    
 ....

(ByteArrayResponseWrapper is a custom class that gets the written content of the response accumulated into a byte array.)

This works for any static resources and also for servlet generated resources, but does not work for WRO4j as it creates the content using a filter.

How to get around this issue?

The problem is related to this issue: https://code.google.com/p/wro4j/issues/detail?id=360
(I posted that myself, it's a different problem but both problems are caused by the same issue.)

Thanks,
T.

Alex Objelean

unread,
Nov 14, 2013, 12:31:30 PM11/14/13
to wr...@googlegroups.com
I think the reason why it doesn't work with wro filter is because you are missing the following filter-mapping configuration:

  <filter-mapping>
    <filter-name>WebResourceOptimizer</filter-name>
    <url-pattern>/wro/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>

Let me know if that works.

Thanks,
Alex


--
You received this message because you are subscribed to the Google Groups "wro4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wro4j+un...@googlegroups.com.
To post to this group, send email to wr...@googlegroups.com.
Visit this group at http://groups.google.com/group/wro4j.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages