Announcement Announcement Module
Collapse
No announcement yet.
Problem with @Publisher annotation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with @Publisher annotation

    Hi,

    I am using the @Publisher annotation on a method in a bean to create a heartbeat message. The method is executed every 30 seconds by a Quartz trigger. My issue is that when the method is called and returns a string nothing happens to the message. Is is not placed on the channel and not sent out my socket.

    Here is the config and code:
    Code:
    <int:channel id="tcpSNRSend">
    	</int:channel>
    	
    <int-ip:tcp-connection-factory id="cfSNRClient"
    		type="client" 
    		host="10.100.211.80"
    		port="10854"  
    		deserializer="connectionSerializeDeserialize" 
    	/>
    
    <bean id="heartbeatJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
      		<property name="targetObject" ref="heartbeatMaintenanceCycle" />
      		<property name="targetMethod" value="heartbeat" />
    	</bean>
    	
    	<bean id="heartbeatTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        	<property name="jobDetail" ref="heartbeatJobDetail" />
        	<!-- 10 seconds -->
        	<property name="startDelay" value="10000" />
        	<!-- repeat every 30 seconds -->
        	<property name="repeatInterval" value="30000" />
    	</bean>
    	
    	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
       		<property name="triggers">
            	<list>
                	<ref bean="heartbeatTrigger" />
            	</list>
        	</property>
    	</bean>
    
    
    
    /**
    	 * Heartbeat 
    	 */
    	@Publisher(channel="tcpSNRSend")
    	@Payload
    	public String heartbeat() {
    		//Create Heartbeat message
    
    		TimeZone tz = TimeZone.getTimeZone("UTC");
    		GregorianCalendar date = new GregorianCalendar(tz);	
    		java.util.UUID uuid = UUID.randomUUID();
    
    		String request = "ESTP/1.0\r\n" + 
    				ISG2Constants.CONTENT_LENGTH + ": 0\r\n" +
    				ISG2Constants.DATE + ": " + DateUtil.formatDate(date.getTime()) + "\r\n" + 
    				ISG2Constants.TRANS_ID + ": " + uuid.toString() + "\r\n" +
    				ISG2Constants.CONTENT_TYPE + ": application/bems-healthrequest" + "\r\n";
    
    		return request;
    	}
    Please advise.

  • #2
    Do you have <int:annotation-config> defined? (it's needed to enable the @Publisher annotations)

    Comment


    • #3
      Thanks Mark,

      When I add that I got the error:

      10:51:44,337 ERROR [ContextLoader] Context initialization failed
      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'heartbeatMaintenanceCycle' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigExcepti on: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.

      When I add CGLIB 2.2 I get more errors:

      10:57:29,385 ERROR [ContextLoader] Context initialization failed
      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'heartbeatMaintenanceCycle' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigExcepti on: Could not generate CGLIB subclass of class [class com.intrado.isg2.bl.HeartbeatMaintenanceCycle]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null

      and the class
      Code:
      class HeartbeatMaintenanceCycle
      {
      	
      	public HeartbeatMaintenanceCycle() {}
      	
      	/**
      	 * Heartbeat 
      	 */
      	@Publisher(channel="tcpSNRSend")
      	@Payload
      	public String heartbeat() {
      		//Create Heartbeat message
      
      		TimeZone tz = TimeZone.getTimeZone("UTC");
      		GregorianCalendar date = new GregorianCalendar(tz);	
      		java.util.UUID uuid = UUID.randomUUID();
      
      		String request = "ESTP/1.0\r\n" + 
      				ISG2Constants.CONTENT_LENGTH + ": 0\r\n" +
      				ISG2Constants.DATE + ": " + DateUtil.formatDate(date.getTime()) + "\r\n" + 
      				ISG2Constants.TRANS_ID + ": " + uuid.toString() + "\r\n" +
      				ISG2Constants.CONTENT_TYPE + ": application/bems-healthrequest" + "\r\n";
      
      		return request;
      	}
      }
      Last edited by Frank DiMauro; Dec 7th, 2012, 12:59 PM.

      Comment


      • #4
        You have 2 options: 1) have your HeartbeatMaintenanceCycle class implement an interface (with the annotated-method being defined by that interface) or 2) add CGLIB to the classpath. Interfaces can be proxied via standard JDK dynamic proxies, but for proxying classes, you need CGLIB.

        Hope that helps.
        -Mark

        Comment


        • #5
          Mark,

          That did it. Created a interface and it works great!

          Thanks again.

          Comment

          Working...
          X