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 に答える