newHelpline: +91-22-26201606 Ext.325/315. +91-22-26201604 Ext.633.
Mobile Seva

Java Client for accessing Mobile Seva IVRS Push Call API ?


Note: IVRS Push Call API will be accessible with TLSv1.2 protocol. Kindly upgrade to latest Java versions for TLSv1.2 support.


Java Version TLS Protocol Supported
Java 7 Supports TLSv1.2. But by default TLS1.0 is used. So, kindly specify TLSv1.2 in code.
Java 8 & above Supports TLSv1.2. By default TLSv1.2 is used.

Steps to import certificate in Java Keystore required for JAVA version 7

1) Click to download the https://services.mgov.gov.in webservice certificate(Size:1,950B)
Note: Import the certificate into the Java Store if you are using JAVA version 7.
2) Make sure you have write access to your JRE and use the keytool utility to import it:
keytool -import -alias alias -keystore path-to-jre/lib/security/cacerts -file path-to-certificate-file
Example:
keytool -import -alias sunas -keystore /opt/jdk1.7/jre/lib/security/cacerts -file /home/gugrim/tmp/msdgwebmgov.crt
3) You will be prompted for the keystore password, which is by default changeit.
4) Also, when you connect to the server make sure you use the same name as the one set as the Subject in the certificate. You may need to add it to your host file if the server isn't reachable using this name, which may be the case for a development/production server.

Note: No need to import certificate for java version 8 and above

Click to download the Java code file(Size:3KB)
Click to download the Required Jars for below code(Size:2.5MB)
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();
		}
		    
	}

}