का उपयोग कर जर्सी में विधि अवरोध क्या जर्सी संसाधन पर एक एनोटेटेड विधि को रोकने के लिए गुइस एओपी का उपयोग करना संभव है?जूस एओपी
मैंने किसी भी समस्या के बिना निर्भरता इंजेक्शन के संबंध में जर्सी के साथ काम कर सफलतापूर्वक कॉन्फ़िगर किया है, हालांकि मेरा कॉन्फ़िगर किया गया इंटरसेप्टर मेरी एनोटेटेड विधि को रोक नहीं रहा है।
web.xml
<listener>
<listener-class>my.package.GuiceConfig</listener-class>
</listener>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
GuiceConfig विन्यास मॉड्यूल
public class GuiceConfig extends GuiceServletContextListener {
@Override
protected Injector getInjector() {
return Guice.createInjector(new JerseyServletModule() {
@Override
protected void configureServlets() {
bindInterceptor(Matchers.any(),
Matchers.annotatedWith(RequiredAuthority.class),
new AuthorisationInterceptor());
Map<String, String> params = new HashMap<String, String>();
params.put(JSP_TEMPLATES_BASE_PATH, "/WEB-INF/jsp");
params.put(FEATURE_FILTER_FORWARD_ON_404, "true");
params.put(PROPERTY_PACKAGES, "my.service.package");
filter("/*").through(GuiceContainer.class, params);
}
});
}
}
RequiredAuthority एनोटेशन
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface RequiredAuthority {
String value();
}
AuthorisationInterceptor पहलू
public class AuthorisationInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
// Allow invocation to process or throw an appropriate exception
}
}
TempResource JAX-आरएस संसाधन वर्ग
@Path("/temp")
public class TempResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
@RequiredAuthority("PERMISSION")
public String getTemp() {
// Return resource normally
}
}
, लेकिन यह ऐसा लगता है ['@ बाध्यकारीअनोटेशन'] (http://google-guice.googlecode.com/git/javadoc/com/google/inject/BindingAnnotation। एचटीएमएल) 'आवश्यक प्राधिकारी' से भी गायब है। –
धन्यवाद, हाँ, इस समय भी एक समस्या हुई। यहां ध्यान देने योग्य है। – Kynth