문제

I have the following class that runs

@Provider
@ServerInterceptor
@RedirectPrecedence
public class SubsidiaryOpenInterceptor implements PostProcessInterceptor, AcceptedByMethod {

@Override
public boolean accept(Class clazz, Method method) {
    final Annotation[][] paramAnnotations = method.getParameterAnnotations();
    for (Annotation[] paramAnnotation : paramAnnotations) {
        for (Annotation a : paramAnnotation) {
            if (a instanceof PathParam && ((PathParam) a).value().equals("idSubsidiary"))
                return true;
        }
    }
    return false;
}

@Override
public void postProcess(ServerResponse response) {
    final Annotation[][] paramAnnotations = response.getResourceMethod().getParameterAnnotations();
    for (Annotation[] paramAnnotation : paramAnnotations) {
        for (Annotation a : paramAnnotation) {
            if (a instanceof PathParam && ((PathParam) a).value().equals("idSubsidiary")) {
                // get the value of "idSubsidiary", it should be an Integer, and do something.
            }
        }
    }
}
}

Now I want to retrieve the value of the idSubsidiary set in the @PathParam("idSubsidiary") Integer idSubsidiary from the url the request was made.

Is it possible to know it at this stage?

Is there a strategy that I could use to have this data at this point of the flow?

I tried to use the MessageBodyWriterInterceptor, but could not make it. Also tried to use the @Context HttpServletRequest req but without success.

도움이 되었습니까?

해결책

I found it,

Just injected

@Context
private UriInfo uri;

and used inside my postProccess method:

MultivaluedMap<String, String> pathParameters = uri.getPathParameters();
String first = pathParameters.getFirst("idSubsidiary");

If there is a better approach, please feel free to help.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top