Tag: interceptor

自动连接到hibernate拦截器

我正在扩展hibernate.EmptyInterceptor,在我的实现中,我希望自动连接到某些服务,但它们返回null。 我在类上添加了@Component注释。 我的代码: 和class级: @SuppressWarnings(“serial”) @Component public class AuditInterceptor extends EmptyInterceptor { @Autowired private IUserSessionService userSessionService;

当向其他人重定向(带拦截器)动作时,Struts2动作无法执行

我向ActLand发送请求,然后intercept() ,如果没有登录,则重定向到Login.jsp 。 struts.xml : /login.jsp /index.jsp /index.jsp /login.jsp 拦截器: public class LoginInterceptor extends AbstractInterceptor { @Override public String intercept(final ActionInvocation invocation) throws Exception { Map session = ActionContext.getContext().getSession(); int userId = -1; if (session.get(“userId”) != null) { userId = Integer.parseInt(session.get(“userId”).toString()); } Object action = invocation.getAction(); if (userId < 0) { return "loginRedirect"; } else […]

OSGi容器中的Camel:将InterceptStrategy应用于所有驼峰上下文

我有几个软件包(A,B和C)部署到OSGi容器,每个包含一个CamelContext和一些路由。 我有另一个包(M),带有一个CamelContext ,一个路由(用于收集监控数据)和一个InterceptStrategy bean。 我希望M中的InterceptStrategy bean能够自动应用于容器中的所有其他CamelContext (即A,B和C中的那些),而不必修改其他bundle。 最终,目标是将每个CamelContext数据窃听到M中的路由,而无需对A,B或C进行任何更改以显式路由Exchange 。 这种方法或类似的方法是否可行? 所有CamelContext都是使用Spring XML配置的。 更新:附加上下文 捆绑包A,B和C包含负责处理数据的核心产品。 Bundle M包含一个可选的监控工具,用于测量流经A,B和C的数据的某些参数。目前,添加可选工具需要更改A,B和C中的路由以添加额外的Processor以丰富Exchange与监控数据并在端点之前读取监控数据。 目标是能够将Bundle M放入已经过validation的A,B和C系统; 并使其自动应用于现有路由,而无需修改现有工作包的配置。 只要更改不会导致A,B和C依赖于M来运行(即,ABC必须仍然在没有M的情况下运行),对A,B和C进行修改以支持这一点是可以接受的。 如果有比使用拦截器更好的方法,我对此持开放态度。 主要目标是: 保持A,B和C与M分离(特别是在开发期间) 确保将M与A,B和C集成在一起尽可能简单 允许集成M而无需手动更改A,B或C.

在自定义拦截器中捕获SOAP Fault错误(Soap12FaultOutInterceptor)

我编写了一个自定义CXF拦截器来将所有SOAP请求和响应记录到数据库中,它似乎与正面测试用例和服务器错误一起正常工作。 但是当发生SOAP Fault时,它只是忽略了我的拦截器而没有记录任何内容。 自定义CXF拦截器。 public class DbLogOutInterceptor extends AbstractSoapInterceptor { public void handleMessage(SoapMessage message) { logger.info(“Handling outbound request”); String transaction = MDC.get(mdcKey); logger.info(“OutBound Transaction ID : {} “, transaction); //code to log the SOAP message in database ……. } } 我没有看到这种方法的日志语句 11:56:34,102 INFO [Soap12FaultOutInterceptor] class org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptor$Soap12FaultOutInterceptor Internalapplication/soap+xml 11:56:34,103 INFO [EligibilityInfo] Outbound Message ————————— ID: 2 […]

如何在jersey WriterInterceptor实现中获取@interface参数

我有一个界面,例如 @NameBinding @Retention(RetentionPolicy.RUNTIME) public @interface AutoLogged { boolean query() default false; } 如何在拦截器实现中获取query参数? @Provider @AutoLogged public class AutoLoggedInterceptor implements WriterInterceptor { @Context private ResourceInfo resourceInfo; @Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { try { final String methodName = this.resourceInfo.getResourceMethod().getName(); BasicAutoLoggedProducer.makeCall(methodName); } catch (final Exception e) { e.printStackTrace(System.err); } finally { context.proceed(); } […]

在Struts 2中获取拦截器参数

我有以下动作映射 … one two … nth-number … 我可以在Interceptor中使用以下行获取参数映射 Map params = ActionContext.getContext().getParameters(); 如上所述, 有没有办法获得下面的映射中定义的拦截器参数 。 … one two … nth-number … 并且动作参数以下面的方式定义,动作参数和拦截器参数应该可以单独访问。 … one two … nth-number …. one two … nth-number … 请注意,我不想在拦截器中声明参数字段 //all fields with their getters and setters private String param1; private String param2; … private String paramN; 在Dev Blanked’s asnwer之后,我实施了他的技术。 它没有用,所以我在这里分享我的代码。 […]

在Struts 2中使用拦截器时出现NullPointerException

这是我的WelcomeAction类 package com.codinghazard.actions; public class WelcomeAction { private String operandA; private String operandB; private Character operator; private int sum; public String execute() { if ((operandA!=””) && (operandB!=””)) { int a=Integer.parseInt(operandA); int b=Integer.parseInt(operandB); switch (operator) { case ‘1’: sum=a+b; break; case ‘2’: sum=ab; break; case ‘3’: sum=a*b; break; case ‘4’: try { sum=a/b; } catch(ArithmeticException ae) […]

Interceptor无法访问Action Parameters

我正在为struts2拦截器创建一个示例。 我创建了一个简单的登录页面,并使用自定义拦截器类来加密输入。 但是拦截器正在将ValueStack的输入值读为null 。 我不明白我做错了什么。 我想struts.xml和拦截器类就足够了。 如果您需要更多我的代码,请告诉我们。 在struts.xml /success.jsp /index.jsp 拦截器.java文件 package com.keyur.struts2.interceptors; import com.keyur.struts2.ActionClasses.validatorClass; import com.keyur.struts2.beans.EncryptorDecryptor; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; import com.opensymphony.xwork2.util.ValueStack; public class EncryptDecryptInterceptor implements Interceptor { EncryptorDecryptor encdec = new EncryptorDecryptor(); @Override public void destroy() { // TODO Auto-generated method stub } @Override public void init() { // TODO Auto-generated method stub […]

自定义注释作为方法记录的拦截器

Java大师, 我是一个很新的annotations ,并没有搜索过这么多,所以请忍受我… 我想实现一个Custom Annotation ,它将intercept一个方法调用; 从非常基本的东西开始,它可以只打印方法名称和参数,以便我可以避免使用logger语句。 像这样的示例调用: public MyAppObject findMyAppObjectById(Long id) throws MyCustomException { log.debug(“in findMyAppObjectById(” + id + “)”); //…. } 可以转换成: @LogMethodCall(Logger.DEBUG) public MyAppObject findMyAppObjectById(Long id) throws MyCustomException { //…. } 我可以得到一些关于此的提示吗?