IVRS Push Call Java Code



package in.cdac;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

import javax.net.ssl.SSLContext;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLContexts;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

public class IVRSPushCall {




public static void main(String[] args) {
// TODO Auto-generated method stub
String userName="";//Your username of services portal
String password="";//Your Password
String mobileNumber="";//If more than 1 then seprated by comma(,)
String voiceCode="";//as uploaded on website( give only nuber of voicecode)
makePushCall(userName,password,mobileNumber,voiceCode);

}


private static void makePushCall( String userName,String password,String mobileNumbers,String voiceCode){

SSLSocketFactory sf=null;
SSLContext context=null;
try {
context=SSLContext.getInstance("TLSv1.2"); //This line is required only for Java 7. No need for java 8 and above.
context.init(null, null, null);
sf=new SSLSocketFactory(context, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme scheme=new Scheme("https",443,sf);
@SuppressWarnings("resource")
HttpClient client=new DefaultHttpClient();
client.getConnectionManager().getSchemeRegistry().register(scheme);
HttpPost post=new HttpPost("https://services.mgov.gov.in/PushCallAPI/MakePushCall");
List nameValuePairs=new ArrayList(1);
nameValuePairs.add(new BasicNameValuePair("username", userName));
nameValuePairs.add(new BasicNameValuePair("password", password));
nameValuePairs.add(new BasicNameValuePair("MobileNumbers", mobileNumbers));
nameValuePairs.add(new BasicNameValuePair("voiceCode", voiceCode));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=client.execute(post);
BufferedReader bf=new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line="";
while((line=bf.readLine())!=null){
System.out.println("response==>"+line);
}

} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeyManagementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}