Tag Archives: weblets

Weblets 1.1 now officially released

Weblets 1.1 has been released at weblets.dev.java.net

Weblets is a Java servlet based framework that provides an easy way of loading resources (Javascript, CSS, images, …) directly out of JAR files. For an overview of what Weblets can do for you, check our Weblets overview.

Below we’ll highlight some of the new features in Weblets v1.1:

  • Weblets 1.1 provides a stable api to build your own Weblets upon
  • Asynchronous In-server reporting of url usage is possible. (eg. for traffic analysis). In-server means that the logging is done in the same JVM server process. Asynchronous because reports that are triggered and executed can run for a longer period of time.
  • General reporting API for in server reporting instances
  • Configurable cache timeouts for better browser cache control

Weblets 1.0 only had the possibility to host resources within your classpath. It was only possible to host Weblets related resources within a jar or within your WEB-INF/classes directory!

Weblets 1.1 now enhances this with a very common usecase. expanded application hosted resources . This means you can put any resource hosted within your local web application under Weblet control. For instance if your application is hosted under /myapplication and your resource under /myapplication/images/myimage.png it until now was not possible to put this resource under Weblets control.

  • Server Mime Type overrides: some servers don’t set default mime types. (eg Weblogic 8.1). If you’re not able to edit them in the web.xml, the Weblets configuration provides another possibility.
  • Resource Whitelists: a mechanism to allow the serving of resources only for certain filetypes given in a resource whitelist (eg. only allow serving of png files)
  • Weblets 1.1 corrects Maven2.0 transitive dependencies (Maven should now pickup all needed dependencies of Weblets)

See http://weblets.dev.java.net/doc_11/longdoc/whatsnew.html for a more detailed description of the new features!

Setup Weblets 1.0 for JSF on Weblogic 8.1

This week I’ve tried to upgrade from Weblets 0.4 to 1.0 while using the following technologies: JSF1.1, JDK1.4 and Weblogic 8.1.

Here are some of my experiences:

As noted in the documentation on https://weblets.dev.java.net/doc/longdoc/setup.html, the web.xml needs the following additions:

       <servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>

This URL pattern will be used only by Weblets. The generated URLs whenever you call weblet:url / weblet:resource via EL, Javascript, CSS or Java will begin with /faces.
This in fact makes sure that the WebletsPhaseListener knows when to process a resource or not by looking at the url

For Weblogic 8.1 it also necessary to add the following listener to your web.xml:

 

 <listener>
<listener-class>net.java.dev.weblets.WebletsContextListener</listener-class>
</listener>

I couldn’t get Weblets to work without it.

Last but not least you should add mime-mappings to your web.xml for all the different types of static resources you want Weblets to serve:

<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>application/x-javascript</mime-type>
</mime-mapping>
<mime-mapping>
<extension>gif</extension>
<mime-type>image/gif</mime-type>
</mime-mapping>

<mime-mapping>
<extension>png</extension>
<mime-type>image/png</mime-type>
</mime-mapping>

<mime-mapping>
<extension>jpg</extension>
<mime-type>image/jpg</mime-type>
</mime-mapping>

If you don’t do this, then a NullPointerException is thrown internally by Weblets and gives problems serving the static resources.
I don’t know about other servers, but on Weblogic doing a servletContext.getMimeType will return null when it was not defined in the web.xml

In fact, Weblets 1.0 also supports defining a <mime-mapping> in the weblets-config.xml. But adding the mime types only there didn’t work as in the Weblets source code there are few places where servletContext.getMimeType is called directly thus ignores any configuration done in the weblets-config.xml. For the next version of Weblets it would be interesting to fix this behaviour and document eg. that mime-mappings in weblets-config.xml take precedence. And if not defined there, Weblets will try to look for mime-mappings in the web.xml via the servlet context.

Weblets 1.0 has been released

Weblets 1.0 has been released at weblets.dev.java.net

Weblets is a Java servlet based framework that provides an easy way of loading resources (Javascript, CSS, images, …) directly out of JAR files.

For us the following features were the reason to start using it:

  1. Weblets has a full frontend api for neutral resource handling. This includes
    • a JSP API
    • JSF facelet integration
    • Using weblets from CSS and Javascript files is also possible.
  2. Weblets will automatically add Expires, If-Modified-Since headers to your HTTP responses. This enhances performance and is a way to implement Rule 3: Add an Expires Header from the Yahoo Performance team (http://developer.yahoo.com/performance/rules.html#expires)
  3. Weblets can automatically version your static resources. (eg. by adding a version id into the generated URL). Doing this accomplishes two things:
    • when a new version of eg. a CSS is in your jar, the URL location where it is served from will change (version id will be different). So there will be no browser issues of people still using the old version as the new URL will not yet be in the cache of the browser.
    • the first point allows you to define much more far future Expires headers; thus the chance that browser will use a cached version will be far higher, enhancing front end performance.

In the next post we will look at using Weblets 1.0 in a Weblogic 8.1 environment.