Results 1 to 10 of 10

Thread: Aspect / Advice within SI

  1. #1
    Join Date
    Jul 2009
    Location
    Charlotte, NC
    Posts
    131

    Default Aspect / Advice within SI

    In my last project, I used own coded client to make outbound webservice calls. Using Advices was easy and worked quite well around those outbound functional calls for profiling.

    Now, in my current project, SI is handling every single such call (whether its MQ or http), with minimal coding efforts.

    Can I still hook up Advices somehow in SI? Any pointers would be helpful!

    Just to add, the outbound webservice / MQ calls are included in a chain, which :
    1. Transforms the message (Transformer)
    2. Makes the outbound call (Activator)
    3. Receives the response (Activator) followed by a Router based routing.

    I need to profile the 2. above

    Why an Activator is being used for the outbound call in 2. is a different story (we can't use Milestone release, and http://jira.springframework.org/browse/INT-1056 is our issue)

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    I assume the service-activator is invoking a method on some POJO that you're injecting into it via "ref", yes? If so, then you can use standard AOP Advice on that POJO itself... or is there something else going on?

    -Mark

  3. #3
    Join Date
    Jul 2009
    Location
    Charlotte, NC
    Posts
    131

    Default

    Quote Originally Posted by Mark Fisher View Post
    I assume the service-activator is invoking a method on some POJO that you're injecting into it via "ref", yes?
    Indirectly, yes.

    Here is my code snippet:

    Code:
    <service-activator id="appPayOutBoundGatewayActivator"
    			ref="xxxxOutboundGateway" method="handleMessage" />
    This outbound gateway [your POJO above] is extending MarshallingWebServiceOutboundGateway and implementing InitializingBean :

    Code:
    <beans:bean id="xxxxOutboundGateway"
    		class="com.xxx.MarshallingWebServiceOutboundGateway">
    		<beans:constructor-arg index="0"
    			ref="xxxxDestproviderMessageSubmit" />
    		<beans:constructor-arg index="1" ref="marshallerNew" />
    		<beans:constructor-arg index="2" ref="marshallerNew" />
    
    		<beans:property name="interceptors">
    			<beans:list>
    				<beans:ref bean="wss4jInterceptor" />
    				<beans:ref bean="osaRequestHeaderInterceptor" />
    			</beans:list>
    		</beans:property>
    		<beans:property name="replyChannel"
    			ref="xxxxResponseProcessingChannel" />
    		<beans:property name="messageFactory" ref="messageFactorySoap12" />
    		<beans:property name="requestCallback" ref="wsAddressingActionCallback" />
    	</beans:bean>
    And here is the Outbound implementation:

    Code:
    public class xxxxOutboundGateway extends MarshallingWebServiceOutboundGateway implements InitializingBean {
    	
    	public MarshallingWebServiceOutboundGateway(
    			DestinationProvider destinationProvider, Marshaller marshaller,
    			Unmarshaller unmarshaller) {
    		super(destinationProvider, marshaller, unmarshaller);
    		
    	}
    
    	private ClientInterceptor[] interceptors;
    	
    	public ClientInterceptor[] getInterceptors() {
    		return interceptors;
    	}
    
    	public void setInterceptors(ClientInterceptor[] interceptors) {
    		this.interceptors = interceptors;
    	}
    
    	public void afterPropertiesSet() throws Exception {
    		getWebServiceTemplate().setInterceptors(interceptors);
    	}
    
    	@Override
    	public void setMessageFactory(
    			org.springframework.ws.WebServiceMessageFactory messageFactory) {
    		super.setMessageFactory(messageFactory);
    		getWebServiceTemplate().setMessageFactory(messageFactory);
    	}
    }
    So the "handleMessage" method (which is actually from AbstractMessageHandler), is actually whats being working behind the scenes...

    I hope this does clarify my implementation... so now how should I use advice "around" this handleMessage method?
    Last edited by GPS; Jul 11th, 2010 at 11:19 PM.

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    You should be able to use standard AOP around advice for the "xxxxOutboundGateway" bean.

  5. #5
    Join Date
    Jul 2009
    Location
    Charlotte, NC
    Posts
    131

    Default

    <beans:bean id="outboundGatewayPerformanceAdvice"
    class="xxxx.PerformanceAdvice">
    </beans:bean>
    <aop:config>
    <aop:aspect id="outboundGatewayPerformanceAdviceAspect" ref="outboundGatewayPerformanceAdvice">
    <aop:around method="logServiceStartAndEndTimes"
    pointcut="execution(* xxxxOutboundGateway.*(..))" />
    </aop:aspect>
    </aop:config>
    Please take a look at this. xxxx.PerformanceAdvice class's logServiceStartAndEndTimes method calculates the time using Stopwatch.
    Ideally this should work, however, if you look at xxxxOutboundGateway bean code above, its not implementing any custom Interface. That leaves with using CGLib proxies instead of Dynamic proxies. But again, I cannot have a default no argument constructor in the xxxxOutboundGateway, which is a requirement for using CGLib. Am I missing something here?

  6. #6
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    It does implement the MessageHandler interface, right?

  7. #7
    Join Date
    Jul 2009
    Location
    Charlotte, NC
    Posts
    131

    Default

    It extends MarshallingWebServiceOutboundGateway which implements MessageHandler.
    Well, I didn't state this that I didn't get any exception while deploying with default configuration (which is I believe is dynamic proxies), but I didn't see any logger statments from my xxxx.PerformanceAdvice class, which means it was not configured correctly.
    That is when I tried with CGLib, which didn't work either.

  8. #8
    Join Date
    Jul 2009
    Location
    Charlotte, NC
    Posts
    131

    Default

    Dont forget me, Mark!

  9. #9
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    I think you will need to provide some of your AOP configuration excerpts. Since you are trying to intercept something that implements the MessageHandler interface, it should work if configured properly.

  10. #10
    Join Date
    Jul 2009
    Location
    Charlotte, NC
    Posts
    131

    Default

    most of the things are provided in this thread itself.. I am including the xxxx.PerformanceAdvice code here too:
    public class PerformanceAdvice {

    private static final Log logger = LogFactory.getLog(PerformanceAdvice.class);

    private long totalCalls = 0;
    private long totalTimeSpent = 0;
    private long maxTimeSpent = 0;
    private long minTimeSpent = Long.MAX_VALUE;

    public Object logServiceStartAndEndTimes(ProceedingJoinPoint pjp)
    throws Throwable {

    logger.debug("Calling logServiceStartAndEndTimes");

    StopWatch clock = new StopWatch();

    try {
    clock.start(pjp.toShortString());
    return pjp.proceed();

    } finally {
    clock.stop();

    String callingMethodName = "";
    Thread currentThread = Thread.currentThread();
    StackTraceElement[] stackTrace = currentThread.getStackTrace();
    for (int i = 0; i < stackTrace.length; i++) {
    if (stackTrace[i].getClassName().contains(
    "xxxxOutboundGateway")) {
    callingMethodName = stackTrace[i].getMethodName();
    break;
    }
    }

    logger.debug("Calling " + callingMethodName + " took: "
    + clock.getTotalTimeMillis() + " ms to complete ("
    + clock.getTotalTimeSeconds() + " seconds).");
    updateCounters(clock.getTotalTimeMillis());
    }
    }

    private synchronized void updateCounters(long ms) {
    totalTimeSpent += ms;
    totalCalls++;
    if (ms > maxTimeSpent) {
    maxTimeSpent = ms;
    }
    if (ms < minTimeSpent) {
    minTimeSpent = ms;
    }
    }
    Whenever an outbound WS call is made, xxxxOutboundGateway is invoked, and I can see everything working as expected from code perspective.
    Just that, this advice doesnt work... I dont see any of the loggings provided in this class.. execution simply doesnt go there...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •