0

我有以下课程运行

@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.
            }
        }
    }
}
}

现在我想@PathParam("idSubsidiary") Integer idSubsidiary从发出请求的 url 中检索 idSubsidiary 设置的值。

在这个阶段有可能知道吗?

是否有一种策略可以让我在流程的这一点获得这些数据?

我尝试使用 MessageBodyWriterInterceptor,但无法成功。也尝试过使用@Context HttpServletRequest req但没有成功。

4

1 回答 1

1

我找到了,

刚注入

@Context
private UriInfo uri;

并在我的 postProcess 方法中使用:

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

如果有更好的方法,请随时提供帮助。

于 2013-11-19T16:41:57.407 回答