简体   繁体   English

如何用 Spring 或 POJO 类替换 org.jboss.resteasy.core.ResourceMethodInvoker

[英]How to replace org.jboss.resteasy.core.ResourceMethodInvoker with Spring or POJO classes

We have an application developed many years back using RESTEasy.我们有一个多年前使用 RESTEasy 开发的应用程序。 The implementation uses RestEasy filters, the implementation is very close to the code shown here: RESTEasy ContainerRequestFilter – RESTEasy security filter example I am migrating that application to Spring Boot as we have all the other applications developed using Spring Boot.该实现使用 RestEasy 过滤器,该实现与此处显示的代码非常接近: RESTEasy ContainerRequestFilter – RESTEasy 安全过滤器示例我正在将该应用程序迁移到 Spring Boot,因为我们使用 Spring Boot 开发了所有其他应用程序。 I am converting the code by taking out JAX-RS and RESTEasy and replacing the RESTEasy filter by Spring Filter something similar to the code shown here: How to Define a Spring Boot Filter?我通过取出 JAX-RS 和 RESTEasy 并将 RESTEasy 过滤器替换为 Spring 过滤器来转换代码,类似于此处显示的代码:如何定义 Spring 引导过滤器? I have the code in the current implementation which checks for annotation on a method like below:我在当前实现中有代码,它检查如下方法的注释:

ResourceMethodInvoker methodInvoker = (ResourceMethodInvoker) requestContext.getProperty("org.jboss.resteasy.core.ResourceMethodInvoker");
Method method = methodInvoker.getMethod();
if(!method.isAnnotationPresent(PermitAll.class))
{
    doSomething();
}

I am looking for some way to implement the same method verification logic using POJO or Spring which I didn't seem to find so far.我正在寻找一些方法来使用 POJO 或 Spring 实现相同的方法验证逻辑,到目前为止我似乎还没有找到。 Any help would be greatly appreciated.任何帮助将不胜感激。

Thanks.谢谢。

IN spring boot you can use Interceptor for the same.在 spring 引导中,您可以使用拦截器。 In interceptor you will have access to HnadlerMethod from which you can know which service method is getting called and it is in which resource and you can get the weather annotation is present or not.在拦截器中,您将可以访问 HnadlerMethod,从中您可以知道调用了哪个服务方法以及它在哪个资源中,并且您可以获取天气注释是否存在。

Steps: create a handler interceptor and register it with spring context so that it will be called.步骤:创建一个处理程序拦截器并将其注册到 spring 上下文中,以便调用它。 Handler interceptor is getting called after Filter is called.在调用过滤器后调用处理程序拦截器。 It is similar like in rest easy containerRequestFilter.它类似于 rest easy containerRequestFilter。 Also, javax.servlet.Filter is called before containerFilter , here also it is in same way.此外, javax.servlet.FiltercontainerFilter之前被调用,这里也是同样的方式。

Link:https://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/HandlerInterceptor.html`链接:https://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/HandlerInterceptor.html`

@Configuration
public class HandlerIntercepter extends HandlerInterceptorAdapter
{
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse 
response, Object handler) throws Exception
{
    System.out.println("handler called");
    HandlerMethod handlerMethod = (HandlerMethod) handler;
    Class<?> clazz = handlerMethod.getBeanType();
    Method m = handlerMethod.getMethod();
    if (clazz != null)
    {
        boolean isClzAnnotation = 
clazz.isAnnotationPresent(RequireSignInClassLevel.class);
    }
    if (m != null)
    {
        boolean isMethondAnnotation = 
m.isAnnotationPresent(RequireSignIn.class);
    }
    return true;
}}
@Component
public class AppConfig extends WebMvcConfigurerAdapter
{
@Autowired
HandlerIntercepter HandlerIntercepter;

@Override
public void addInterceptors(InterceptorRegistry registry)
{
    registry.addInterceptor(HandlerIntercepter);
}
}`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JBoss + RestEasy + Jackson:无法将org.jboss.resteasy.core.ServerResponse强制转换为org.jboss.resteasy.specimpl.BuiltResponse - JBoss + RestEasy + Jackson : org.jboss.resteasy.core.ServerResponse cannot be cast to org.jboss.resteasy.specimpl.BuiltResponse ClassNotFoundException:org.jboss.resteasy.core.messagebody.AsyncBufferedMessageBodyWriter - ClassNotFoundException: org.jboss.resteasy.core.messagebody.AsyncBufferedMessageBodyWriter JAX-RS:“RESTEASY002005:执行 GET org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure 失败 - JAX-RS: "RESTEASY002005: Failed executing GET org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure JBOSS 7.1.0错误 - 无法找到类org.jboss.resteasy.core.AsynchronousDispatcher的公共构造函数 - JBOSS 7.1.0 error - Unable to find a public constructor for class org.jboss.resteasy.core.AsynchronousDispatcher org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure:无法找到类型的响应对象的MessageBodyWriter:媒体类型:application / xml - org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: of media type: application/xml 在JBOSS AS上将RESTEasy与Spring集成是强制性的吗? - Is it mandatory to integrate RESTEasy with Spring on JBOSS AS? org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure:无法为类型的响应对象找到MessageBodyWriter - org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type java.lang.NoSuchFieldError: INSTANCE at org.jboss.resteasy.core.providerfactory.ResteasyProviderFactoryImpl.initializeCommon - java.lang.NoSuchFieldError: INSTANCE at org.jboss.resteasy.core.providerfactory.ResteasyProviderFactoryImpl.initializeCommon Quarkus - org.jboss.resteasy.reactive.common.core.BlockingNotAllowedException:尝试在 io 线程上进行阻塞读取 - Quarkus - org.jboss.resteasy.reactive.common.core.BlockingNotAllowedException: Attempting a blocking read on io thread 与JBoss AS 7和Jetty一起部署时,使用RestEasy序列化POJO的差异 - Difference serializing POJO using RestEasy when deployed with JBoss AS 7 and Jetty
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM