.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Make and receive VoIP phone calls through HTTP requests using your Java application

Posted By:Simon Robert VoIP       Posted Date: July 11, 2014    Points: 200    Category: General    URL: http://www.dotnetspark.com  

I have created an application that can be used to make and receive phone calls through your VoIP network by using a Java program. I have implemented this solution using HTTP requests and responses.

Hello Everyone,

I'm working on a huge VoIP telephony project using Java and HTTP and I learned something cool today that I think would be useful for you. Let me share my project in the hope that I can help anyone who wants to improve her/his communication system - and I also hope you will contribute to my solution by providing any further useful development suggestion.

Introduction to the problem

It was often such that I needed a separate application to be able to manage my telephone system. The most common case: I was on a conference, but I suddenly needed to notify my colleagues related to some issue. Since I couldn't start a phone conversation there, I could rely on my laptop solely. However, most of my colleagues are usually out of the office, so the only way for reaching them immediately is a phone call or an SMS. Instead of typing and sending dozens of SMSs, I thought it would be more effective (and more personal) to use an application that allows me to make phone calls and plays a specified message.

Background of development

Concerning to the fact that HTTP requests and responses can be used for this purpose, I started to build a HTTP-based solution. The following figure illustrates how it works:

As I'm a passionate Java developer, I used this programming language. For implementing my VoIP telephony solution I have used the HTTP API provided by Ozeki Phone System along with NetBeans. The Java Development Kit (JDK) is essentially needed, so if you install the NetBeans IDE, please install the JDK as well (see below). To be able to make (and receive) phone calls, a softphone is also required. Therefore I downloaded and installed CounterPath X-Lite softphone.

Code explanation

Having done with the introduction section, I'm going to explain what you need to do if you are interested in my solution.

After you have installed all the necessary software, you need to start a new Java project in NetBeans (or Eclipse, or any other Java IDE). For this purpose, in NetBeans, click on File then select the New Project menu item.

To make my project complete, I will present two-way communication. That is, I will not explain only how to make a phone but also how to receive a phone call by using your Java application.

First of all you need to select which port receives the incoming calls. For this purpose, click on the Productivity menu item in the Ozeki PBX then choose the HTTP API item from the dropdown menu. Here, you need to add a new API extension notification, then you can set the address of incoming calls by using the URL field of Incoming call. In this example, this is the 7778 port of localhost. Now, make a Java application that checks this port and gives a HTTP response if a call arrives.

public static Initialize() {
	ServerSocket listener = new ServerSocket(7778));
	while (true){
		Socket socket = listener.accept();
		String responde = "HTTP/1.1 200 OKrn"
						+ "Content-Type: text/xmlrn"
						+ "Connection: Keep-Alivern"
						+ "Keep-Alive: timeout=15, max=100rnrn"
						+ "<?xml version=1.0" encoding="UTF-8"?>rn"
						+ "<Response>rn"
						+ "<Delay>1</Delay>rn"
						+ "<Speak>Congratulations, this is your first OZML Response command.</Speak>rn"
						+ "<Delay>1</Delay>rn"
						+ "<Speak>For more information on OZML syntax, visit www.ozekiphone.com </Speak>rn"
						+ "</Response>";
		OutputStream outputStream = socket.getOutputStream();


Make a ServerSocket object and add the port number in its constuctor. You can accept an incoming request by calling the accept() method. After the invitation, you will get back a Socket object. Call the getOutputStream method of socket, in order to give a response back. This leads to an OutputStream. You can send back the appropriate response through this by calling the write method of outputstream. It waits for a byte array. As a result the String typed response message needs to be converted to a byte typed array. You can manage to do it if you use the getBytes method(). Finally, with the help of the outputStream flush() method, you can send the answer.

To make an outgoing call, make a sample by a URL class. Then connect to the URL, which was given in the construstor of the URL object. To do this, invite the openConnection() method of the object which sends back an URLConnection typed object. Then convert it to HttpURLConnection format. In this file, set the method of the request and send it, using the connect() method.

private static void Initialize {
	URL url = new URL("http://ozekixepbx.ip:7780/?command=Call&"
					+ "Dialed=100&"
					+ "ApiExtension=9997&"
					+ "CallerId=1000&"
					+ "CallerDisplayName=John+Smith&"
					+ "Url=http://yoursite.com/callconnected.php&"
					+ "ErrorUrl=http://yoursite.com/error.php");
	HttpURLConnection connection = (HttpURLConnection) url.openConnection();

Furher development opportunities

I'm thinking srongly about some additional enhancements, such as call recording to be able to record an important one calling. Do you have any idea regarding with my VoIP application?


To sum it up I have created a really simple application that can be used to make and receive phone calls through your VoIP network by using your Java program. I have implemented this solution using HTTP requests and responses. 

References and the availability of programs used

If you want to try out my solution, you may need some software. The following collection contains all the necessary application and information you need to know.

You can find out more about the used HTTP API commands using this page: http://www.ozekiphone.com/voip-http-api-commands-in-ozeki-phone-system-xe-pbx-231.html

You can download the necessary software from the following pages:

Thank you for your attention!

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend