Hi,
I have created a custom action to send jms message to destination server while any content is updated in the folder.The code is posted below
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.content.ContentServicePolicies;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
public class JMSMessageSender extends ActionExecuterAbstractBase implements ContentServicePolicies.OnContentUpdatePolicy{
private static final String PROP_KEY_DOCUMENT_ID = null;
private static final String PROP_KEY_DOCUMENT_NAME = null;
private static final String PROP_KEY_DOCUMENT_CREATOR = null;
public final static String PARAM_ACTIVE = "active";
// @Resource(mappedName = "jms/GlassFishBookConnetcionFactory")
private ConnectionFactory connectionFactory;
// @Resource(mappedName = "jms/GlassFishBookQueue") ;
private Behaviour onContentUpdate;
private PolicyComponent policyComponent;
MessageProducer messageProducer;
private NodeService nodeService;
private ContentService contentService;
private Session session;
public NodeService getNodeService() {
return nodeService;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public ContentService getContentService() {
return contentService;
}
public void setContentService(ContentService contentService) {
this.contentService = contentService;
}
public PolicyComponent getPolicyComponent() {
return policyComponent;
}
public void setPolicyComponent(PolicyComponent policyComponent) {
this.policyComponent = policyComponent;
}
public void init(String fileName,String connectionFactoryJNDI,String destinationJNDI)throws NamingException, JMSException, FileNotFoundException, IOException
{
// Create behaviours
this.onContentUpdate = new JavaBehaviour(this, "onContentUpdate", NotificationFrequency.TRANSACTION_COMMIT);
// Bind behaviours to policies
this.policyComponent.bindClassBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onContentUpdate"),
ContentModel.TYPE_CONTENT, this.onContentUpdate);
Properties properties = new Properties();
properties.load(new FileInputStream(fileName));
Context ctx = new InitialContext(properties);
Object objHandler = ctx.lookup(connectionFactoryJNDI);
this.connectionFactory = (ConnectionFactory)objHandler;
objHandler = ctx.lookup(destinationJNDI);
Destination destination = (Destination)objHandler;
Connection connection = connectionFactory.createConnection();
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
messageProducer = session.createProducer(destination);
}
private void sendJMSEvent(String documentId, String documentName, String user, byte[] documentContent) throws JMSException{
}
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
Boolean flag=true;
onContentUpdate(actionedUponNodeRef,flag);
}
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList){
}
public void onContentUpdate(NodeRef updatedNodeRef, boolean flag) {
}
}
and the bean is
<bean id="messageSender" class="com.custom.MessageSender" parent="action-executer" init-method="init">
<property name="nodeService">
<ref bean="NodeService" />
</property>
<property name="contentService" >
<ref bean="ContentService" />
</property>
<property name="policyComponent">
<ref bean="PolicyComponent"/>
</property>
</bean>
But I am getting error as
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'PolicyComponent' is defined
Can anyboby tell me where I am wrong? Please help.It is urgent.