Is MVC working with sub-resources locators?

23 views
Skip to first unread message

Xavier Dury

unread,
May 6, 2020, 6:54:26 AM5/6/20
to MVC 1.0 Users Mailing List
Hi,

I was trying to use MVC with sub-resources locators but it does not seem to work.

Here is a simplified example of what I am trying to do:

@RequestScoped
@Path("/my")
public class MyResource {

@Inject
private Models models;

@Path("/path")
public Object locate() {
return new Object() {

@GET
@View("/myview.jsp")
@Produces(MediaType.TEXT_HTML)
@Controller
public void process() {
models.put("answer", 42);
}
};
}
}

For now, a 204 (no content) is returned as it seems that the @View was not processed.

Is there a way to make it work or are sub-resources not supported?

Thanks,

kr,
Xavier

Ivar Grimstad

unread,
May 6, 2020, 7:01:57 AM5/6/20
to MVC 1.0 Users
Hi Xavier,

You're right. Sub-resource locators are not supported by MVC 1.0. The controller methods must handle the HTTP request directly. See section 2.1 in the specification [1].

Ivar


--
You received this message because you are subscribed to the Google Groups "MVC 1.0 Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsr371-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsr371-users/052c5965-d6bb-4eaa-adef-793230e742ad%40googlegroups.com.

Xavier Dury

unread,
May 6, 2020, 7:09:51 AM5/6/20
to MVC 1.0 Users Mailing List
Ok, thank you for the quick response!

Next time I have a question, I'll check the spec first! ;-)
To unsubscribe from this group and stop receiving emails from it, send an email to jsr371...@googlegroups.com.

Xavier Dury

unread,
May 27, 2020, 4:17:49 AM5/27/20
to MVC 1.0 Users Mailing List
If someone is interested, I found a way to make MVC work with sub-resources locators with the help of a CDI InterceptionFactory.

Here's a simplified example:

public class AroundControllerLiteral extends AnnotationLiteral<AroundController> implements AroundController {}

public class ValidationInterceptorBindingLiteral extends AnnotationLiteral<ValidationInterceptorBinding> implements ValidationInterceptorBinding {}

@Path("foo")
public class MyResource {

    @Inject
    private BeanManager beanManager;

    @Path("{bar}")
    public Object bar(@PathParam("bar") String bar) {
        return wrap(MySubResource.class, new MySubResource(...));
    }

    private <T> T wrap(Class<T> resourceClass, T resourceInstance) {
        InterceptionFactory<T> interceptionFactory = beanManager.createInterceptionFactory(null, resourceClass);
        interceptionFactory.configure()
                .filterMethods(m -> m.isAnnotationPresent(Controller.class))
                .forEach(m -> m.add(new AroundControllerLiteral()).add(new ValidationInterceptorBindingLiteral()));
        return interceptionFactory.createInterceptedInstance(resourceInstance);
    }
}

public class MySubResource {

    MySubResource() {
        /* for proxies */
    }

    public MySubResource(...) {
        // initialize dependencies
    }

    @Controller
    @GET
    @View(...)
    public void get() { ... }
}

The only downside is that I now have a direct dependency on krazo (AroundController and ValidationInterceptorBinding).

The MVC spec could maybe provide a programmatic way to wrap the subresource or obtain a specialized/pre-configured InterceptionFactory.

Another way could be to have an interceptor applied on the main resource that automatically decorate the returned subresource.

WDYT?

Xavier

Xavier Dury

unread,
May 27, 2020, 6:18:39 AM5/27/20
to MVC 1.0 Users Mailing List
One way to remove the direct dependency on krazo could be to completely remove AroundController and ValidationInterceptorBinding classes and only keep Controller that could be turned into an InterceptorBinding with BeforeBeanDiscovery.addInterceptorBinding().

Christian Kaltepoth

unread,
May 31, 2020, 6:42:39 AM5/31/20
to MVC 1.0 Users
Hi Xavier,

if you are interested in sub-resource locators for MVC, feel free to file an issue here:


However, please note that we are currently migrating the spec to the Eclipse Foundation. So the issues will be migrated to a different repository soon.

Christian

To unsubscribe from this group and stop receiving emails from it, send an email to jsr371-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsr371-users/c6abd981-b82b-4fc7-a663-635127d13453%40googlegroups.com.


--
Reply all
Reply to author
Forward
0 new messages