myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Juan Fernandez Corugedo (JIRA)" <>
Subject [jira] [Created] (MYFACES-3128) Problems with a custom Resource Resolver
Date Fri, 06 May 2011 13:18:03 GMT
Problems with a custom Resource Resolver

                 Key: MYFACES-3128
             Project: MyFaces Core
          Issue Type: Bug
    Affects Versions: 2.0.5
         Environment: GlassFish 3.0 with Oracle JVM 1.6  and Websphere with IBM JVM
            Reporter: Juan Fernandez Corugedo


I'm working in a project with Myfaces 2.0.5 and I have had a problem with a custom ResourceResolver.

I have coded a ResourceResolver that dynamically builds an XHTML file when the engine asks
him to resolve a certain URL.

To achieve this, I have update the web.xml as follows:


My CustomResourceResolver is very simple:

package com.test.view.facelets;


import javax.faces.view.facelets.ResourceResolver;

public class CustomResourceResolver extends ResourceResolver {

    private ResourceResolver innerResourceResolver;
    private String viewSource = ".... xhtml of the test page ....";
    public CustomResourceResolver(ResourceResolver resourceResolver){
        this.innerResourceResolver = resourceResolver;
    public URL resolveUrl(String path) {
        System.out.println("Buscando la URL del recurso: " + path);
        URL result = null;
                result = getUrlForResourceAsStream(path);
            }catch(Exception e){
                System.out.println("Unexpected error while obtaining the URL from resource
" + path);
            result = this.innerResourceResolver.resolveUrl(path);
        return result;

    private URL getUrlForResourceAsStream(String path) throws MalformedURLException {
        URLStreamHandler handler = new URLStreamHandler() {
            protected URLConnection openConnection(URL u) throws IOException {
                final String file = u.getFile();
                return new URLConnection(u) {
                    public void connect() throws IOException {

                    public InputStream getInputStream() throws IOException {
                        System.out.println("Opening internal url to " + file);
                            System.out.println("Generando el InputStream de la pagina:\n"
+ viewSource);
                            return new ByteArrayInputStream(viewSource.getBytes("UTF-8"));
                        }catch (Exception e) {
                            throw new RuntimeException("Unexpected error while obtaining the
view", e);
        return new URL("internal", null, 0, path, handler);

As you can see, the code is very simple. When the suffix matches the pattern ".test", the
Resolver creates a mock URL with a backing ByteArrayInputStream. If the suffix does not matches
the pattern, the normal ResourceResolver is invoked.

With this configuration and code, when I request the URL: http://xxxxxx:yyyy/zzzzz/anything.test
 the application fails with error:

The problem is this:

    at java.lang.StringBuilder.<init>(
    at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.getRenderedViewId(
    at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.buildView(

The executes the viewHandler.createView("xxxx.test") method. It internally calls the getViewHandlerSupport().calculateViewId(context,
viewId); method to obtain the viewId, and this method calls DefaultViewHandlerSupport.checkResourceExists(FacesContext
context, String viewId), that checks the physical file of this resource, but there are not
any file for this resource!!!! so it return false, and the viewId of the resulting ViewRoot
is assigned to null.

This causes a NullPointerException later, when the code executes the ViewDeclarationLanguage.buildView(FacesContext
context, ViewRoot viewRoot).

If I change the Myfaces implementation with Mojarra 2.0.4, it works perfectly, so I think
that the problem is in the implementation.

I can't extend any class of interface of Myfaces, because my application must not be coupled
to a specific implementation.

This message is automatically generated by JIRA.
For more information on JIRA, see:

View raw message