Java servlet used to parse phone numbers using google's libphonenumber library.
This is a Java servlet created with Eclipse Java EE IDE for Web Developers version Oxygen. 2 Release (4.7.2). The servlet's main page contains 2 web forms to receive input either as a string or a file. Once the input is received, the servlet will output a JSON string containing all Canadian phone numbers found from the input.
- The libphonenumber library
- Quick guide on how to create a servlet
- Quick guide to JUnit tests in mockito
What you will need:
- Eclipse Java EE IDE for Web Developers
- Apache Tomcat 7 - choose the appropriate link for the OS you are using
- WAR file for project
Instructions for Windows deployment:
- Install the eclipse IDE into any folder
- Install the Apache Tomcat into any folder
- Start the eclipse IDE.
- Select a workspace.
- Once inside eclipse, choose File -> Import -> Web -> WAR file
- Import the WAR file you downloaded from "How to deploy?" Link Here to WAR file
- Use "ParsePNum" as name of the web project and set Target Runtime to Apache Tomcat v7.0. Choose Finish.
To create a new Apache Server:
- Go to Server window with Window -> Show View -> Server
- Click on link to create a new server
- Choose Tomcat v7.0 Server, and set host name as localhost. Select Next.
- Note: If this is your first time, you may need to tell the IDE where the Tomcat installation directory is.
Use Browse button and search for your Apache Tomcat installation folder.
- Right click the newly created server, choose "Add and Remove..."
- Add the servlet ParsePNum from "Available" to "Configured".
- The server is ready to be deployed. Read below for usage.
The first thing to do is to start the apache server.
Simply go to Window -> Show View -> Server
Next start the server from the server menu. Here's a screenshot:
After the server is running, to access the servlet's main page, go to http://localhost:8080/ParsePNum/phonenumberparse.jsp. This assumes you started server on port 8080.
Here's a screenshot of the main page:
Currently, there are 3 ways to use ParsePNum.
-
GET from servlet page
- Simply type text into the GET textbox and click submit.
-
POST from servlet page
- Select a file to upload and click submit.
-
GET by editting URL on address bar
- Edit the address bar as per screenshot below.
The tests are in src/PhonenumbersTest.java. They are written using JUnit and Mockito libraries. Currently, the only method being tested is doGet() method.
To start a unit test:
- Open PhonenumbersTest.java
- Select Run from main menu -> Run As -> JUnit Test
To add more test cases, simply create a new test# method, and add that test method onto the main method.
- Unit testing for doPost()
- Ideally using Spring Test Framework or JUnit with Mockito
- Include more test cases
- Automated testing using Travis CI
- Parsing PDF or MS Word files
- Add instructions to deploy in other OS (linux, macOS)
This license is under BSD-2 clause. You can find out more at BSD
Also, IANAL.