T5 + Tynamo RESTEasy + UriInfo

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

T5 + Tynamo RESTEasy + UriInfo

Michael Gentry
This is an FYI in case it helps others.

Converting a non-T5 REST-based application into a T5 + Tynamo RESTEasy
version.  The original application used:

  private UriInfo uriinfo;

to inject UriInfo to construct URLs to other REST services. but this
didin't work with Tynamo's RESTEasy.  You *can* add "@Context UriInfo
uriInfo" to your method's parameters, but that ended up kind of ugly
passing it around all over the place.  Since you couldn't @Inject the
UriInfo without some work, I came up with this to make it possible (add to

    public static UriInfo build(HttpServletRequest request,
String restEasyPackage)
        throws URISyntaxException
        // Glue the container's context path to the T5 RESTEasy path so the
        // URLs are constructed correctly.
        String webServicePath = request.getContextPath() + restEasyPackage;

        // Create the injectable and session-scoped UriInfo for this
        return new ResteasyUriInfo(request.getRequestURL().toString(),
request.getQueryString(), webServicePath);

With that added, you can put this in your web services implementation:

    private UriInfo uriInfo;

It works just like the @Context version, but is injected by T5.  Hopefully
that will save someone some effort in the future if they need this feature.