Incomplete Sample Code


//SMSClient.java

import.java.net.*;
import.java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import com.objectxp.msg.*;

/*SMSClient is the client interface for SMS mode
of notification module for sending SMS message to
the end users using SMTP & IMAP server*/

public class SmsClient extends Thread
{
static ClientLogFile clientlogfile = new clientLogFile();
static String clientproperties[]=null;
String strTo="";
String strFrom="";
String attach;
int alertno=0;
String filename;
File foldername=null;
String username="";
String password="";
String SMS;
ArrayList readmsg=null;
static ArrayList writemessage=new ArrayList();
ObjectOutputStream oos= null;
ObjectInputStream ois= null;
OutputStream os= null;
InputStream is= null;
String strMsgText="";
static Session session = null;
Message msg=null;
static Properties props=new Properties();
ServerSocket serversock=null;
Socket sock=null;
boolean flag=true;

public SmsClient()
{}

public SmsClient(String smtp)
{
try
{
props.put("sms.gsm.connector","SERIAL");
props.put("connector.serial.port","COM1");
props.put("connector.serial.bps","19200");
props.put("objectXP.licence.company","your company");
props.put("objectXP.licence.user","user_name");
props.put("objectXP.licence.key","your_key");

session=Session.getDefaultInstance(props,null);
session.setDebug(false);

msg=newMimeMessage(session);
host=Sms;
}
catch(Exception e)
{}
}

//main method
public static void main(String clientproperties[])
{
SmsClient ob=null;
try
{
if(clientproperties[14].equalsIgnoreCase("company_name"))
{
if(clientproperties[15]==null || clientproperties[15].equals(""))
{
if(clientproperties[16]==null || clientproperties[16].equals(""))
{
throw new Exception("NO SMS is mapped in property file");
}
}
}

if(clientproperties[14].equalsIgnoreCase("user_name"))
{
if(clientproperties[17]==null || clientproperties[17].equals(""))
{
if(clientproperties[18]==null || clientproperties[18].equals(""))
{
throw new Exception("NO USER NAME IS MAPPED IN PROPERTY FILE");
}
}
}

if(clientproperties[12]!=null && !(clientproperties[12].equals("")))
{
System.out.println("SMS ADDRESS");
String ss = clientproperties[12];
ob = new SmsClient(ss);
ob.clientproperties=clientproperties;

ob.serversock = new ServerSocket(3005);
SmsClient thr=new SmsClient();
thr.start();
while(true)
{
ob.send();
}

}
if(clientproperties[12].equals(""))
{
if(clientproperties[13]!=null && !(clientproperties[13].equals("")))
{
System.out.println("SECONDARY ADDRESS");
String ss = clientproperties[13];
ob=new SmsClient(ss);
ob.clientproperties=clientproperties;
ob.serversock=new ServerSocket(3500);
SmsClient thr=new SmsClient();
thr.start();
while(true)
{
ob.send();
}

else
{
clientlogfile.writeLogMessage(
"SMS IS NOT AVAILABLE");
}
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
clientlogfile.writeLogMessage(e.getMessage());
}
}

public void send()
{
try
{
sock = serversock.accept();
is = sock.getInputStream();
os=sock.getOutputStream();
ois=new ObjectInputStream(is);
oos = new ObjectOutputStream(os);
readmsg = (ArrayList)ois.readObject();

for(int p=0; p<readmsg.size(); p +=5)
{
try
{
alertno=Integer.parseInt((String)readmsg.get(p));
strMsgText = (String)readmsg.get(p+1);
strTo = (String)readmsg.get(p+2);
strFrom = (String)readmsg.get(p+3);
attach = (String)readmsg.get(p+4);
foldername=new File(""+clientproperties[9]+attach);
try
{
if(!attach.equals("0"));
{
filename=clientproperties[9]+attach+"\\"+
(foldername.listFiles())[0].getName();
System.out.println("" + foldername+" " + filename);
File f = new File(filename);
if(!f.exists())
{
throw new FileNotFoundException();
}
}
System.out.println("RECEIVED "+alertno+" " +
strMsgText+" " + strTo+ " "+strFrom+" " + attach);

SmsService service = null;
try
{
File config = new File("/path/to/your/jsms.conf");

//create service object
service = new GSMSmsService();
service.init(config);
//create a new message
Message msg = new Message(service);
msg.setRecipient("host");
msg.setMessage("msg!");
//connect to devices
service.connect();
//send the message
service.sendMessage(msg);
System.out.println("Messages sent sucessfully, ID is "
+ msg.getMessageId());
}
catch(Exception e)
{
System.err.println("MESSAGE COULD NO BE SENT");
}
finally
{
if(servive!=null)
{
service.disconnect();
service.destroy();
}
}
}
}

System.out.println("SMS SENT " + alertno);
}catch(FileNotFoundException e)
{
writemessage.add(""+alertno);
writemessage.add("failure");
System.out.println("ATTACHMENT FILE NOT FOUND");
}
catch(MessagingException me)
{
writemessage.add(""+alertno);
writemessage.add("failure");
clientlogfile.writeLogMessage("CONNECTION NOT" +
"ESTABLISHED WITH SMCS");
}
catch(Exception ee)
{
writemessage.add(""+alertno);
writemessage.add("failure");
clientlogfile.writeLogMessage(ee.getMessage());
}
}catch(Exception e)
{
}
}
}


 

  Java Alert Notification System Home Page

   Previous    Next  
 

UNIVERSAL TEACHER PUBLICATIONS
Web: universalteacherpublications.com, universalteacher.com, universalteacher4u.com