Abdul Basit
Abdul Basit

Reputation: 189

Get fullpath from requestContext RESTEasy3.0.7 PreRequestFilter for Security in JAVA

I am working on RESTEasy3.0.7 PreRequestFilter to make my REST API secure. Here I am trying to get fullpath as mentioned in screen short which is available in methodInvoker. There is no direct method to get this value.. I have tried using getProperty but it also not worked.

@Provider
public class PreRequestFilter implements javax.ws.rs.container.ContainerRequestFilter
{
    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException 
    {
        ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) requestContext.getProperty("org.jboss.resteasy.core.ResourceMethodInvoker");
        Method method = methodInvoker.getMethod();

enter image description here

I just need methodInvoker -> method -> fullpath value.. can anyone help in this regard like how can get this value if there is no method available directly..

Upvotes: 0

Views: 603

Answers (1)

lefloh
lefloh

Reputation: 10961

Obtaining the requested path can be done easily:

String path = requestContext.getUriInfo().getPath();

But I don't know a standard-way to get the URI-Template without substituted path parameters. The ResourceMethodInvoker is only exposing the java.lang.reflect.Method of the org.jboss.resteasy.spi.metadata.ResourceMethod but not the org.jboss.resteasy.spi.metadata.ResourceMethod itself which you need to access.

You could get the template per reflection:

Field field = ResourceMethodInvoker.class.getDeclaredField("method");
field.setAccessible(true);
ResourceMethod method = (ResourceMethod) field.get(methodInvoker);
String path = method.getFullpath();

Upvotes: 3

Related Questions