OAF SMS SENDING FEATURE
Fron Controller Call xxx_SendSMS class.
Controller Code:
Controller Code:
xxx_SendSMS oSendSMS = new
xxx_SendSMS();
String balance =
oSendSMS.checkBalance("MobileNumber", "Password");
oSendSMS.sendMessage("MobileNumber",
"Password", "Sender", " Message","Number");
xxx_SendSMS Class File:===>
package xxx.oracle.apps.per.selfservice.user.webui;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
public class xxx_SendSMS
{
private String msg = "";
private String balance = "";
static char[] hexDigit = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
public void sendMessage(String userName, String password, String sender, String message, String numbers)
{
System.out.println("Inside the method to send the message");
try
{
String para = "mobile=" + userName + "&password=" + password + "&numbers=" + numbers + "&sender=" + sender + "&msg=" + convertUnicode(message) + "&applicationType=24";
sendURL("http://ip address/sms/api/msgSend.php", para, 1);
System.out.println(getMessage());
}
catch(Exception e)
{
System.out.println("Exception cought====>>>>>>>" + e);
}
}
public String checkBalance(String userName, String password)
{
String para = "mobile=" + userName + "&password=" + password;
sendURL("http://ip address/sms/api/balance.php", para, 5);
return this.balance;
}
public void checkSender(String userName, String password, String senderID)
{
String para = "mobile=" + userName + "&password=" + password + "&senderId=" + senderID;
sendURL("http://ip address/sms/api/checkSender.php", para, 7); }
public String getMessage() {
return this.msg; }
public static String convertUnicode(String a) {
int bufSize = 16;
byte[] buffer = new byte[bufSize];
String s = null;
try {
buffer = a.getBytes();
s = bytesToHex(buffer, 0, buffer.length);
System.out.println("Hex: " + s);
} catch (Exception e) {
System.out.println(e.toString());
}
return s; }
public static String bytesToHex(byte[] b, int off, int len) {
StringBuffer buf = new StringBuffer();
for (int j = 0; j < len; ++j)
buf.append(byteToHex(b[(off + j)]));
return buf.toString(); }
public static String byteToHex(byte b) {
char[] a = { hexDigit[(b >> 4 & 0xF)], hexDigit[(b & 0xF)] };
return forDigits(new String(a)); }
public static String forDigits(String val) {
switch (val.length())
{
case 1:
return "000" + val;
case 2:
return "00" + val;
case 3:
return "0" + val;
case 4:
return val; }
return val;
}
public void selectedMessage(int value, int operationNumber)
{
switch (operationNumber)
{
case 1:
System.out.println(value);
switch (value)
{
case 1:
this.msg = "MESSAGE SENT"; break;
case 2:
this.msg = "BALANCE=0"; break;
case 3:
this.msg = "BALANCE IS NOT ENOUGH"; break;
case 4:
this.msg = "MESSAGE NOT AVAILABLE)."; break;
case 5:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 6:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 12:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 13:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 14:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 15:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 16:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 17:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case -1:
this.msg = "MESSAGE NOT AVAILABLE)"; break;
case -2:
this.msg = "MESSAGE NOT AVAILABLE)"; break;
case 0:
case 7:
case 8:
case 9:
case 10:
case 11:
default:
this.msg = "FAILED"; }
break;
case 2:
switch (value)
{
case 1:
this.msg = "MESSAGE NOT AVAILABLE."; break;
default:
this.msg = "MESSAGE NOT AVAILABLE."; }
break;
case 3:
switch (value)
{
case 1:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 2:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 3:
this.msg = "MESSAGE NOT AVAILABLE"; break;
default:
this.msg = ""; }
break;
case 4:
switch (value)
{
case 1:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 2:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 3:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 4:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 5:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 6:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 7:
this.msg = "MESSAGE NOT AVAILABLE."; break;
default:
this.msg = ""; }
break;
case 5:
switch (value)
{
case 1:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 2:
this.msg = "MESSAGE NOT AVAILABLE."; break;
default:
this.msg = this.balance; }
break;
case 7:
switch (value)
{
case 0:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 1:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 2:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 3:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 4:
this.msg = "MESSAGE NOT AVAILABLE"; break;
default:
this.msg = "";
}
case 6:
}
}
public void sendURL(String URL, String parameters, int operationNumber)
{
try
{
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.1.100.15", 8080));
URLConnection urlConnection=null;
MyAuthenticator myAuthenticator=new MyAuthenticator("FARISPRO","N3wRudr");
Authenticator.setDefault(myAuthenticator);
URL url = new URL(URL);
urlConnection = url.openConnection(proxy);
((HttpURLConnection)urlConnection).setRequestMethod("POST");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//urlConnection.setRequestProperty("Content-Length", parameters.length());
urlConnection.setRequestProperty("Content-Length", ""+ parameters.length());
urlConnection.setRequestProperty("User-agent", "Mozilla/4.0");
urlConnection.connect();
DataOutputStream outStream = new DataOutputStream(urlConnection.getOutputStream());
outStream.writeBytes(parameters);
outStream.flush();
outStream.close();
BufferedReader rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String buffer;
while ((buffer = rd.readLine()) != null) {
try {
selectedMessage(Integer.parseInt(buffer), operationNumber);
} catch (Exception ex) {
this.balance = buffer;
}
}
rd.close();
outStream.close();
}
catch (Exception ex) {
System.out.println("Exception cought:\n" + ex.toString());
}
}
}
xxx_SendSMS Class File:===>
package xxx.oracle.apps.per.selfservice.user.webui;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import
java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import
java.net.URLEncoder;
import
oracle.apps.fnd.framework.webui.OAPageContext;
public class xxx_SendSMS
{
private String msg = "";
private String balance = "";
static char[] hexDigit = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
public void sendMessage(String userName, String password, String sender, String message, String numbers)
{
System.out.println("Inside the method to send the message");
try
{
String para = "mobile=" + userName + "&password=" + password + "&numbers=" + numbers + "&sender=" + sender + "&msg=" + convertUnicode(message) + "&applicationType=24";
sendURL("http://ip address/sms/api/msgSend.php", para, 1);
System.out.println(getMessage());
}
catch(Exception e)
{
System.out.println("Exception cought====>>>>>>>" + e);
}
}
public String checkBalance(String userName, String password)
{
String para = "mobile=" + userName + "&password=" + password;
sendURL("http://ip address/sms/api/balance.php", para, 5);
return this.balance;
}
public void checkSender(String userName, String password, String senderID)
{
String para = "mobile=" + userName + "&password=" + password + "&senderId=" + senderID;
sendURL("http://ip address/sms/api/checkSender.php", para, 7); }
public String getMessage() {
return this.msg; }
public static String convertUnicode(String a) {
int bufSize = 16;
byte[] buffer = new byte[bufSize];
String s = null;
try {
buffer = a.getBytes();
s = bytesToHex(buffer, 0, buffer.length);
System.out.println("Hex: " + s);
} catch (Exception e) {
System.out.println(e.toString());
}
return s; }
public static String bytesToHex(byte[] b, int off, int len) {
StringBuffer buf = new StringBuffer();
for (int j = 0; j < len; ++j)
buf.append(byteToHex(b[(off + j)]));
return buf.toString(); }
public static String byteToHex(byte b) {
char[] a = { hexDigit[(b >> 4 & 0xF)], hexDigit[(b & 0xF)] };
return forDigits(new String(a)); }
public static String forDigits(String val) {
switch (val.length())
{
case 1:
return "000" + val;
case 2:
return "00" + val;
case 3:
return "0" + val;
case 4:
return val; }
return val;
}
public void selectedMessage(int value, int operationNumber)
{
switch (operationNumber)
{
case 1:
System.out.println(value);
switch (value)
{
case 1:
this.msg = "MESSAGE SENT"; break;
case 2:
this.msg = "BALANCE=0"; break;
case 3:
this.msg = "BALANCE IS NOT ENOUGH"; break;
case 4:
this.msg = "MESSAGE NOT AVAILABLE)."; break;
case 5:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 6:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 12:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 13:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 14:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 15:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 16:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 17:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case -1:
this.msg = "MESSAGE NOT AVAILABLE)"; break;
case -2:
this.msg = "MESSAGE NOT AVAILABLE)"; break;
case 0:
case 7:
case 8:
case 9:
case 10:
case 11:
default:
this.msg = "FAILED"; }
break;
case 2:
switch (value)
{
case 1:
this.msg = "MESSAGE NOT AVAILABLE."; break;
default:
this.msg = "MESSAGE NOT AVAILABLE."; }
break;
case 3:
switch (value)
{
case 1:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 2:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 3:
this.msg = "MESSAGE NOT AVAILABLE"; break;
default:
this.msg = ""; }
break;
case 4:
switch (value)
{
case 1:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 2:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 3:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 4:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 5:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 6:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 7:
this.msg = "MESSAGE NOT AVAILABLE."; break;
default:
this.msg = ""; }
break;
case 5:
switch (value)
{
case 1:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 2:
this.msg = "MESSAGE NOT AVAILABLE."; break;
default:
this.msg = this.balance; }
break;
case 7:
switch (value)
{
case 0:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 1:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 2:
this.msg = "MESSAGE NOT AVAILABLE"; break;
case 3:
this.msg = "MESSAGE NOT AVAILABLE."; break;
case 4:
this.msg = "MESSAGE NOT AVAILABLE"; break;
default:
this.msg = "";
}
case 6:
}
}
public void sendURL(String URL, String parameters, int operationNumber)
{
try
{
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.1.100.15", 8080));
URLConnection urlConnection=null;
MyAuthenticator myAuthenticator=new MyAuthenticator("FARISPRO","N3wRudr");
Authenticator.setDefault(myAuthenticator);
URL url = new URL(URL);
urlConnection = url.openConnection(proxy);
((HttpURLConnection)urlConnection).setRequestMethod("POST");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//urlConnection.setRequestProperty("Content-Length", parameters.length());
urlConnection.setRequestProperty("Content-Length", ""+ parameters.length());
urlConnection.setRequestProperty("User-agent", "Mozilla/4.0");
urlConnection.connect();
DataOutputStream outStream = new DataOutputStream(urlConnection.getOutputStream());
outStream.writeBytes(parameters);
outStream.flush();
outStream.close();
BufferedReader rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String buffer;
while ((buffer = rd.readLine()) != null) {
try {
selectedMessage(Integer.parseInt(buffer), operationNumber);
} catch (Exception ex) {
this.balance = buffer;
}
}
rd.close();
outStream.close();
}
catch (Exception ex) {
System.out.println("Exception cought:\n" + ex.toString());
}
}
}
Comments
Post a Comment