Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2010 JBoss Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.jbpm.process.workitem.jabber;
 import java.util.List;
 import  org.jivesoftware.smack.Chat;
 import  org.jivesoftware.smack.ChatManager;
 import  org.jivesoftware.smack.ConnectionConfiguration;
 import  org.jivesoftware.smack.XMPPConnection;
 import  org.jivesoftware.smack.XMPPException;
 import  org.jivesoftware.smack.packet.Message;
 import  org.jivesoftware.smack.packet.Presence;

 public class JabberWorkItemHandler implements WorkItemHandler {
     private String user;
     private String password;
     private String server;
     private int port;
     private String service;
     private String text;
     private List<StringtoUsers = new ArrayList<String>();
     public void executeWorkItem(WorkItem workItemWorkItemManager manager) {
         this. = (StringworkItem.getParameter("User");
         this. = (StringworkItem.getParameter("Password");
         this. = (StringworkItem.getParameter("Server");
         String portString = (StringworkItem.getParameter("Port");
         if(portString != null && !portString.equals("")){
             this. = Integer.valueOf((StringworkItem.getParameter("Port"));
         this. = (StringworkItem.getParameter("Service");
         this. = (StringworkItem.getParameter("Text");
         String to = (StringworkItem.getParameter("To");
 		if ( to == null || to.trim().length() == 0 ) {
 		    throw new RuntimeException"IM must have one or more to adresses" );
 		for (String sto.split(";")) {
 			if (s != null && !"".equals(s)) {
         ConnectionConfiguration conf = new ConnectionConfiguration( , );
         XMPPConnection connection = null;
         try {
            if( !=null && !.equals("") &&  != 0){
              connection = new XMPPConnection(conf);
            } else {
              connection = new XMPPConnection();
            ..println("Connected to " + connection.getHost());
         } catch (XMPPException ex) {
             ..println("Failed to connect to " + connection.getHost());
             ..println("Logged in as " + connection.getUser());
             Presence presence = new Presence(Presence.Type.available);
        } catch (XMPPException ex){
            ..println("Failed to log in as " + connection.getUser());
        for(String toUser : ){
            ChatManager chatmanager = connection.getChatManager();
            Chat chat = chatmanager.createChat(toUsernull);
            try {
                // google bounces back the default message types, you must use chat
                Message msg = new Message(toUser,;
                ..println("Message Sended");
            } catch (XMPPException e) {
                ..println("Failed to send message");
                // handle this how?
        manager.completeWorkItem(workItem.getId(), null);
    public void abortWorkItem(WorkItem workItemWorkItemManager manager) {
        throw new UnsupportedOperationException("Not supported yet.");
New to GrepCode? Check out our FAQ X