Hello!
I have spent some days trying to figure out how to get sub-resources working
as I want them to to no avail. I want every resource, including
sub-resources, to contain an attribute which value is the URI of the
resource.

I have an example program where a User can be associated (one-way) to zero
or more Roles.
Consequently, I have an UserResource and a RoleResource.
To retrieve the data of a specific user, I use
http://localhost:8080/CXF_REST_Webservice/users/2/
To list the roles of the same user, I would use
http://localhost:8080/GWT_REST_Webservice/users/2/roles/
So, in my UserResource class, I have a method that is to retrieve the roles
of a user:
(annotations copied from the interface to condense things)

@WebService
@Path("/users/")
@ProduceMime({"application/xml", "application/json"})
public class UserResourceImpl implements UserResource
{
    // A lot of other stuff...

    @Path("{id}/roles/")
    public RoleResource getUserRoles(
        @PathParam("id") final Long inUserId,
        @QueryParam("expandLevel") @DefaultValue("1") final int
inExpandLevel)
        throws UserNotFoundFault
    {
        /* The RoleResource is injected into the UserResource by Spring. */
        return mRoleResource;
    }
}

Both the UserResource and the RoleResource have an instance variable of the
type UriInfo, which is annotated with the @Context annotation. The problem
that occurs is that the UriInfo in the RoleResource returned from the above
method is empty, that is, calling getAbsolutePath() on the UriInfo fails
with a NullPointerException.
When retrieving role resources directly, using an URI like
http://localhost:8080/CXF_REST_Webservice/roles/2, the UriInfo object is not
empty and the call to getAbsolutePath() causes no problems.

One place I suspect I have made a mistake is in the application context file
for the services:
...
    <jaxrs:server id="CXF_REST_Service" address="/">
        <jaxrs:serviceBeans>
            <ref bean="userServiceBean" />
            <ref bean="roleServiceBean" />
        </jaxrs:serviceBeans>
    </jaxrs:server>
...

I tried to run the code on Jersey, the reference implementation of JSR-311,
and there, the UriInfo objects in the UserResource and the RoleResource were
correctly set. There were, however, other problems with Jersey that makes me
prefer CXF, if I only can get the above problem solved.
Many thanks for all the effort people put into CXF and for any help I might
receive!

-- 
View this message in context: 
http://www.nabble.com/UriInfo-object-in-Sub-Resource-tp19533573p19533573.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to