Announcement Announcement Module
No announcement yet.
Injection into MethodInterceptor Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Injection into MethodInterceptor

    Hi All,

    I am attempting to provide an invoker service api which will comes with a MethodInterceptor which is responsible for closing a context. The idea behind the MethodInterceptor is, I want to seamlessly perform some context operations for the invokee without them realising its happening.

    Here's what I have;

    Intended Usage:
    JbpmContext jBpmCtx = getCurrentContext();
    FooService fooSrv = (FooService) ServiceInvokerUtil.getService("FooService", jBpmCtx);
    Service Wrapper:
    public class ServiceInvokerUtil {
    	public static Object getService(String serviceName, JbpmContext jbpmContext)
    			throws ServiceInvocationException {
    		ApplicationContext ctx = new FileSystemXmlApplicationContext(
    		ctx.getBean("contextManager", new Object[] { jbpmContext });
    		Object service = ctx.getBean(serviceName);
    		return service;
    The Interceptor:
    public class ServiceInvokerInterceptor implements MethodInterceptor {
    	private boolean isAsync;
    	private ContextManager context;
    	public Object invoke(MethodInvocation m) throws Throwable {
    		// Close the JBPMContext if this is Asynchronous invocation
    		JbpmContext jBpmContext = getContext().getContext();
    	        JbpmConfiguration config = jBpmContext.getJbpmConfiguration();
    		if (isAsync()) {
    			System.out.println("Executing Async Before Advice" + jBpmContext);
    		} else {
    			System.out.println("Executing Before Advice");
    		// Invoke the 3rd party system
    		Object rspObj = m.proceed();
    		// Reload the JBPMContext
    		if (isAsync()) {
    			System.out.println("Executing Async After Advice");
    		} else {
    			System.out.println("Executing After Advice");
    		return rspObj;
    // Async  and Context setters/getters ommitted !
    The weaving config:
    	<!-- Bean configuration -->
    	    <bean id="proxyTemplate" class="org.springframework.aop.framework.ProxyFactoryBean" abstract="true">
    	    <bean id="syncInterceptor" class="com.mdsuk.bpe.extensions.invoker.ServiceInvokerInterceptor">
    	   		<property name="async"><value>false</value></property>
    	   		<property name="context"><ref local="contextManager"/></property>
    		<bean id="asyncInterceptor" class="com.mdsuk.bpe.extensions.invoker.ServiceInvokerInterceptor">
    			<property name="async"><value>true</value></property>
    	   		<property name="context"><ref local="contextManager"/></property>
    		<bean id="contextManager" scope="prototype" class="com.mdsuk.bpe.extensions.invoker.ContextBeanFactory" factory-method="createContextBean">
    	   	<!-- Bean Classes -->
    	   	<bean id="fooServiceTarget" class="com.mdsuk.bpe.extensions.invoker.test.FooServiceImpl">  	
    	   	<bean id="FooService" parent="proxyTemplate">
    			<property name="proxyInterfaces">
    	      	<property name="target">
    	         	<ref local="fooServiceTarget"/>
    	      	<property name="interceptorNames">

    The problem:

    I want to be able to set the context into the method interceptor programatically, as each context is a new instance and specific to the invokee.

    I have tried to use a factory prototype bean and
    		ctx.getBean("contextManager", new Object[] { jbpmContext });
    to pump in the context passed by the invokee, but no joy

    Can anyone point out what I'm doing wrong or if this is possible, I'm a Spring newbie so I may have made elementary mistakes here somewhere.

    Thanks in advance
    -- Pat