Popular Posts

Monday, February 20, 2017

Introduction to Voice Over Internet Protocol (VOIP)


What is VOIP:


VOIP stands for Voice Over Internet Protocol. It’s a great new way from to use the power of internet to make and receive phone calls. If you have a high speed internet connection then you can use VOIP and begin making phone calls using your regular touch tone phone. Just like sending an e-mail through the internet VOIP service provider does the same thing with voice and the best part is that you will be able to call anywhere at anytime and save money too. VOIP is also called broadband phone as it uses high speed internet connection which is also called broadband connection.

History:

The concept of VOIP comes from the concept of text chatting. In earlier days when internet was invented there was big problem for the general users that how they can get access to it because to get an access to internet there is need for a physical connection between the user and the internet. It is not possible to cover million and billions of users around the world through means of physical connection. But there exists a physical connection around the world that is already in use by billions of people to connect anywhere in is world with their friends and relatives and that physical connection is our local phone cable. By using this cable they can overcome the physical connection problem but then another comes up and that is local phone signals are analog and the computer sends and receive digital signals from the internet. They over come this problem by inventing modem whose function is to convert digital signals into analog and analog signals into digital. So users are connected to internet and using it for different purposes including chatting. Most of the users around the world were using internet because of chatting. They progress further in increasing the speed of internet and then were able to transfer voice over internet which was popular all around the world as voice chatting and is still in use as VOIP service is not that much cheaper for every user. From voice chatting they get this concept of making and receiving phone calls by means of internet as they are already using the resources of the telephone. Now a day we are still connecting to the internet by means of telephone cable but there is tremendous improvement in its speed and its facilities. VOIP is one of the most important facilities of the internet.

Requirements for VOIP:

In order to get a VOIP connection following are the requirements:
                 
  • Broadband Internet connection (DSL or Cable).
  • A regular touch tone telephone.
  • A VOIP phone adapter.
  • A VOIP service provider account.

How VOIP works:

You connect your telephone to your high-speed Internet connection using the VOIP phone adapter. Pick up the phone, and use it just like you do today. When you pick up the phone, the VOIP phone adapter converts your voice into data and sends it through the Internet like an email. The VOIP service provider’s network sends the call where you want it and translates it back into voice. When the person you're calling picks up the phone, it sounds just the same as any other call. When someone calls you, they dial your number, your phone rings, and all you have to do is pick up and answer it. Once you connected a VOIP adapter with your cable or DSL modem then your phone calls are routing through the internet. Below is a diagram that how its works and general procedure:

http://wakasmalik.blogspot.com/2017/02/introduction-to-voice-over-internet.html
VOIP Setup

  • VOIP adapter sends your phone call across the Internet.
  • Your calls go through your modem.
  • Your VOIP phone adaptor splits your high-speed broadband Internet connection.
  • Your Internet connection should work as it did before you installed the VOIP phone adaptor sending emails and other web data to your personal computer.
  • Your phone calls are sent through your VOIP phone adaptor to your regular or cordless phone.


Advantages of VOIP Service:



·         First and one of the important advantages is that it will lower your phone bills and especially if you have an international connection or you are using calling cards.

·         Secondly wherever you live in this world you can get a local telephone number of your choice of country regardless of the geographical difference of both the countries. Let’s take an example if you live here in USA but still you can own a UK number. In this way you and your UK friends save a lot of money on phone calls as both you have the same area code that’s possible now with the power of internet and VOIP service.

·         You can get all great features like Caller ID with Name, Call Waiting Voicemail and Conference Calling included at no additional cost.

·         There are number of additional features that you can get like: 911 Dialing Call transfer, In-Network calls, area code selection, Click 2 Call, Call Return, Caller ID block, International Call Block and Ring List.

·         Soft Phone: Whether you're traveling across the globe or just into the next room, carrying on a conversation doesn't have to mean carrying extra equipment. Download Soft Phone software and you can turn any PC or laptop into a full-functioning telephone. Soft Phone is a screen-based interface that works just like your telephone keypad. You can make a call, receive a call, and pick up your voicemails too.


Disadvantages of VOIP Connection:
  • One major disadvantage of VOIP is the quality of the sound which can be uneven, and phone calls often have lot of delay with lot of echo. It makes conversation difficult .To get lower bandwidth, the voice compression algorithms and echo cancellation requires additional processing power that makes digital phones more expensive than analog phones.
  • If your cable, DSL or electric power goes out so does your phone line. 
  • No emergency reliability. Maybe you will never need it but if you have to use 911 you have to give exact address and name, they have a hard time tracking where you are and this could cost you valuable seconds.


Please comment if you have any questions or concerns.

Thursday, February 16, 2017

Calculate Time Difference Between Two Clocks in String Format

The other day I was looking for calculating the time difference between two clocks in String format. I could find a better solution, so I wrote a custom one. Take a look at the Java Code below:

   1:  public static String calTimeDifference(String startHour, 
       String startMin, String endHour, String endMin){
   2:   
   3:  String total = "0";     
   4:   
   5:  if (!StringUtils.isEmpty(startHour) && 
       !StringUtils.isEmpty(startMin) && 
       !StringUtils.isEmpty(endHour) && 
       !StringUtils.isEmpty(endMin){
   6:   
   7:   int stHr = Integer.parseInt(startHour) * 60 ;
   8:   
   9:   int stMn = Integer.parseInt(startMin);
  10:   
  11:   int enHr = Integer.parseInt(endHour) * 60 ;
  12:   
  13:   int enMn = Integer.parseInt(endMin);
  14:   
  15:   int startTime = stHr + stMn;
  16:   
  17:   int endTime = enHr + enMn;
  18:   
  19:    if (endTime > startTime){
  20:   
  21:     int durationHr = (endTime - startTime)/60;
  22:   
  23:     int durationMn = (endTime - startTime)%60;
  24:   
  25:     total = Integer.toString(durationHr) + " Hr and "
         + Integer.toString(durationMn) + " Min" ;
  26:   
  27:      }
  28:   
  29:     else{
  30:   
  31:      total = "Ending Time cannot be before Starting Time";
  32:   
  33:      }
  34:   
  35:    }       
  36:   
  37:   return total;
  38:   
  39:  }


The above code should work as long as you keep in mind the pre and post conditions.

Pre-Condition:
This function assumes that all four parameters are present so if even one of them is missing it will return zero.

Post-Condition:
This function will also make sure that the ending time cannot be before the starting time if it is it will return the error message.

Thursday, March 3, 2016

Disabling Default Spring File Extension Response Mapper


The other day I was trying to implement a file download functionality, which takes the filename as a path variable and returns you the uploaded file metadata. In my case file extension was not matching the response type and Spring was throwing this exception below:

 org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation  

The problem was that Spring treats the part after the dot in the url as a file extension and was trying to determine the matching response type and didn't find any matching converter, which result in throwing the above exception.

To solve we can simply disabled the default suffix-based content negotiation and can use the produce annotation to tell Spring what response type should be used.

Code:

1:  @Configuration  
2:  public class ContentNegotiationConfig extends WebMvcConfigurerAdapter {  
3:    @Override  
4:    public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {  
5:      // Turn off suffix-based content negotiation  
6:      configurer.favorPathExtension(false);  
7:    }  
8:  }  

Note: It is important to use the configuration annotation so this property can be set before starting the spring container.

Saturday, February 6, 2016

Unauthorized Entry Point with Spring Security


Let's say you already have secured your app with spring security but now every time a request comes in and you are not able to authenticate the user and the web server returns a 403 Forbidden exception instead of 401 Unauthorized exception, weird right! Well that's the default behaviour which is not correct logically because:

HTTP 401 Unauthorized Exception is for authentication, means the user is not authenticated by the app, the app doesn't know who the user is, it might be because of bad/missing credentials or wrong username or whatever else but in short the user is not authenticated, so please try again.

HTTP 403 Forbidden Exception is for the protected resource, means the user is authenticated user but he doesn't have the right privileges to access the resource so either ask your administrator to give you the privileges or forget about it simple.

Summarizing above, a 401 Unauthorized response should be used for missing or bad authentication, and a 403 Forbidden response should be used after authenticating the user, so the user is authenticated but isn’t authorized to perform the requested operation on a given resource.

Code:

1:  public class UnauthorizedEntryPoint implements AuthenticationEntryPoint {  
2:    
3:    @Override  
4:    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {  
5:    
6:      //log statement if you want to log it to server logs.  
7:      response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "User Authentication cannot be verified, Please log in again with your credentials");  
8:    
9:    }  
10:  }  

Now you need to register this entry point in your spring security web configurer class, like this :

1:  http.exceptionHandling().authenticationEntryPoint(new UnauthorizedEntryPoint());  

Please comment, if you have any questions or concerns.