package org.camunda.bpm.example.twitter;

import javax.inject.Named;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;

import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;

/**
 * Publish content on Twitter. It really goes live! Watch out http://twitter.com/#!/camunda_demo for your postings.
 */
@Named("tweetAdapter")
public class TweetContentDelegate implements JavaDelegate {

  public void execute(DelegateExecution execution) throws Exception {      
    String content = (String) execution.getVariable("content");
      
    AccessToken accessToken = new AccessToken("220324559-jet1dkzhSOeDWdaclI48z5txJRFLCnLOK45qStvo", "B28Ze8VDucBdiE38aVQqTxOyPc7eHunxBVv7XgGim4say");
    Twitter twitter = new TwitterFactory().getInstance();
    twitter.setOAuthConsumer("lRhS80iIXXQtm6LM03awjvrvk", "gabtxwW8lnSL9yQUNdzAfgBOgIMSRqh7MegQs79GlKVWF36qLS");
    twitter.setOAuthAccessToken(accessToken);    

    twitter.updateStatus(content);
  }

}

@@ -63,16 +63,66 @@
 Named;%0A%0A
+import org.camunda.bpm.engine.delegate.BpmnError;%0A
 import o
@@ -171,16 +171,16 @@
 cution;%0A
-
 import o
@@ -251,16 +251,51 @@
 witter;%0A
+import twitter4j.TwitterException;%0A
 import t
@@ -632,23 +632,25 @@
 eption %7B
-      %0A
+%0A%09try %7B%0A%09
     Stri
@@ -709,15 +709,17 @@
 %22);%0A
+%09
       %0A
+%09
     
@@ -860,24 +860,25 @@
 gGim4say%22);%0A
+%09
     Twitter 
@@ -923,16 +923,17 @@
 ance();%0A
+%09
     twit
@@ -1037,16 +1037,17 @@
 6qLS%22);%0A
+%09
     twit
@@ -1088,17 +1088,19 @@
 n);    %0A
-%0A
+%09%0A%09
     twit
@@ -1126,15 +1126,153 @@
 ntent);%0A
+%09%7D catch (TwitterException e) %7B%0A//%09%09if (e.getErrorCode() == 187) %7B%0A//%09%09%09throw new BpmnError(%22duplicateMessage%22);%0A//%09%09%7D%0A%09%09throw e;%0A%09%7D%0A    %0A
   %7D%0A%0A%7D%0A

add comment on how to throw BPMN Error