1

I would like to trap the file upload event in IBM Connections, and take some actions. If a particular criteria gets satisfied, the file should be stored within the system, or else should be rejected with a message.

For this, I was exploring the IBM Connections SPI ( Pre-Event Handler hooks ). I have followed the necessary steps required as per the document to create the jar, deploy and change the configurations, but it seems that my code doesn't get called, when a file is uploaded into Connections.

Not sure, where lies the issue, as I don't get any errors too.

PS: I tried the Post Event handler hook and it worked successfully.

Following are the snippets

public class PreHandlerEvents implements PreEventHandler{
    @Override
    public void destroy() {
        // TODO Auto-generated method stub

    }

    @Override
    public void handleEvent(MutableEvent arg0) throws EventHandlerException {

        String content = "This is the content to write into file";
        File file = new File("filenamePre.txt");

        // if file doesnt exists, then create it
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        FileWriter fw;
        try {
            fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);
            bw.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

events-config.xml


<preHandler enabled="true" name="PreHandlerEvents" class="com.connections.PreHandlerEvents">
        <subscriptions>
            <subscription source="*" type="*" eventName="*"/>
        </subscriptions>
    </preHandler>
</preHandlers>
bukubapi
  • 497
  • 2
  • 5
  • 13
  • 1
    Same for me. Both I and a customer of ours independentely tried to get the preeventhandler to work, but neither of us managed. The Posteventhandler did work completely fine. – subrunner Sep 28 '16 at 06:03

1 Answers1

0

Perhaps rather than a PreEventHandler, you could use an EventHandler instead in your <preHandler .../>?

Example code:

public class CustomEventHandler implements EventHandler {

    public void init() throws EventHandlerInitException {}

    public void destroy() {}

    @Override
    public void handleEvent(Event event) throws EventHandlerException {
        System.out.println(" +++ Event: " + event.getName());
    }
}
dvdsmpsn
  • 2,839
  • 1
  • 26
  • 40