cancel
Showing results for 
Search instead for 
Did you mean: 

how to set up an ASR callback

iguanna
Champ in-the-making
Champ in-the-making
Hi from Spain,

I've got a webscript in my alfresco. It's running perfectly. This webscript is implemented in the class named 'save.java'.

I'd like that this class sends a request to another url at the end through a callback. So my class 'save.java' implements DeploymentCallback interface and override the method: public void eventOccurred(DeploymentEvent event).

So I was supposing that at the end of the execution of save.java the DeploymentEvent is raised and thus I could do somethingh. But the problem is that the eventOcurred is never raised.

Could anyone help me out to implement my problem? thanks
9 REPLIES 9

mrogers
Star Contributor
Star Contributor
That callback is for the DeploymentService

Did you pass in your callback handler when calling  deployDifferenceFS?

iguanna
Champ in-the-making
Champ in-the-making
I am going to tell you what exactly I am doing to get run the callback just in case you can help me out:

my environment is:
Alfresco-Enterprise-tomcat-3.3 
windows7

my webscript save.java:

public class Save extends DeclarativeWebScript implements DeploymentCallback{
   
   @Setter   private RequestService requestService;
   @Setter   private UserServiceImpl userService;
   private String event_ticket;
   

   @Override
   public void eventOccurred(DeploymentEvent event) {
      System.out.println("eventOccurred");
      if (event.getType() == DeploymentEvent.Type.END) {
         if (event_ticket!=null) {
            System.out.println("callBack runs");
         }
      }
   }
   
   @Override
   protected Map<String, Object> executeImpl(WebScriptRequest req,
         Status status, Cache cache) {   
       System.out.println("req.parameter.callback:"+req.getParameter("callBack"));
       this.event_ticket = req.getParameter("callBack");
      return map;
   }

my someco-avm-context.xml is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
   <bean id="someco-deployment-save" class="com.someco.alfresco.request.Save" />
   <bean id="avm-deploy-website" class="org.alfresco.repo.avm.actions.AVMDeployWebsiteAction" parent="action-executer">
      <property name="deploymentService" ref="DeploymentService" />
      <property name="contentService" ref="ContentService" />
      <property name="nodeService" ref="NodeService" />
      <property name="publicAction">
         <value>false</value>
      </property>
      <property name="defaultRemoteUsername">
         <value>admin</value>
      </property>
      <property name="defaultRemotePassword">
         <value>admin</value>
      </property>
      <property name="defaultAlfrescoRmiPort">
         <value>${alfresco.rmi.services.port}</value>
      </property>
      <property name="defaultReceiverRmiPort">
         <value>44100</value>
      </property>
      <property name="defaultTargetName">
         <value>default</value>
      </property>
      <property name="delay">
         <value>30</value>
      </property>
      <property name="callbacks">
         <list>
            <ref bean="someco-deployment-save" />
         </list>
      </property>
   </bean>
</beans>

mrogers
Star Contributor
Star Contributor
So you have over-ridden the AVMDeployWebSiteAction to call a method on a web script handler.

The only valid reason I can think of from having a wcm deployment callback to a webscript handler would be if the implementation of that webscript asynchronously kicked off a deployment and needed to be informed as the deployment proceeded.   I don't see that in your code.    And AVMDeployWebSiteAction is already running asychronously. 

Are you using WCM deployment?   How does the deployment get triggered?

iguanna
Champ in-the-making
Champ in-the-making
I am not using WCM deployment. I don't know how the deployment gets triggered. I thought that just writing that piece of code I would have a callback running. My aim is:
At the end of the save.java I have to do something (Actually I have to send a xml file to another URL but it will be another issue later) and I have to do it by callback, that's all. I draw out from a Doc about Alfresco that piece of code and I'm not sure what I have to do else. Could you orientate to me please?

mrogers
Star Contributor
Star Contributor
Why does "save" not just "send the XML file to another URL"?   why the instantance on "callbacks"?

If you need your "send the XML file to another URL" to execute asynchronously or in a different transaction then one approach is to register an action in your "save" method.

If you don't want to inject code into your "save" handler then you need to analyse what "triggers" your "send the XML file to another URL" and possibly use a rule or a behavior to call your "sent the XML file to another URL" code.    So for example you could have a rule running on all new content items in a particular folder.

iguanna
Champ in-the-making
Champ in-the-making
hi mrogers,

I had to leave you for some days because I was attending another issue.
About our issue:
   The webscript "save.java" manages to save in Alfresco a Request that the customer can command by the interface. The point is that an external system can send a Request to save.java (withouh interface just API-REST) as well. In this case the Request  has to store an URL of callback. it means that whenever the Request is changed, Alfresco has to call to this URL of callback sending the Request into a xml file as well. This is what I have to implement. Could you help me out?

thanks

mrogers
Star Contributor
Star Contributor
So you have some sort of "Request" content type.
Call your callback URL from a policy that is triggered when a "Request" changes.

iguanna
Champ in-the-making
Champ in-the-making
my apologies, I can do that just  "send the XML file to another URL" I don't need to instance a callback.

thanks for your attention.

iguanna
Champ in-the-making
Champ in-the-making
by the way, could you tell me how to send a xml file by a post called from Alfresco?