(858) 586 7777 | About | Testimonials | Contact
vteams vteams vteams vteams
  • How does it work?
    • Startup Process
    • Your First Day
  • Technologies
    • Hire PHP Developer
    • Hire App Developer
    • Hire JavaScript Developer
    • Hire ROR Developer
    • Hire IOS Developer
    • Hire .NET Developer
    • Hire AI Developer
    • Hire Robotics Engineer
  • Sample Budgets
  • Meet The Team
  • Experiments
  • Captain’s Log
  • Blog
vteams vteams
  • How does it work?
    • Startup Process
    • Your First Day
  • Technologies
    • Hire PHP Developer
    • Hire App Developer
    • Hire JavaScript Developer
    • Hire ROR Developer
    • Hire IOS Developer
    • Hire .NET Developer
    • Hire AI Developer
    • Hire Robotics Engineer
  • Sample Budgets
  • Meet The Team
  • Experiments
  • Captain’s Log
  • Blog
Blog
  1. vteams
  2. Blog
  3. Developing a Java Application to Fetch the Data from Untangle Server
Dec 30
developing-a-java-application-to-fetch-the-data-from-untangle-server

Developing a Java Application to Fetch the Data from Untangle Server

  • December 30, 2016

vteams helped out a client to fetch the data from Untangle Server through PHP. The client wanted to achieve this by creating a crawler which could gather the data from the server. However, vteams engineer knew that this is not a viable solution and hence an alternative solution was proposed.

Solution

The first step was to analyze the PSQL database structure to figure out how Untangle Server saves its data. To do this, vteams engineer enabled a port in Untangle unit to access the database remotely (Read the reference link to learn how to enable ports in Untangle unit).

Enabled port allowed PSQL database to connect remotely with pgAdmin. PSQL database was then installed in the system using SSH tunnel. Example given below:

developing-a-java-application-to-fetch-the-data-from-untangle-server-1

In order to fetch the data from PSQL and push it to the web server, vteams engineers created the application in Java. Java was the preferred choice for this because Java JRE (Java Runtime Environment) already comes with Untangle unit which meant that no further installations were required on the system.

Timer functionality was then implemented in Java application so that the data could be pushed to the web service according to the configurable time.  Once the data was received by the web service, it was then saved in the client’s database for future processing.

Following are the sample codes:

1- For Connecting Database

1
connection = DriverManager.getConnection("jdbc:postgresql://"+hostname+"/"+db, user,pass);

2- For Fetching the Data from Table

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
ResultSet rs = st.executeQuery("SELECT * FROM reports.http_events where time_stamp between '"+previousTime+"' and  '"+currentTime+"' ");
                
Statement stCount = (Statement) connection.createStatement();
ResultSet countQuery = stCount.executeQuery("SELECT count(*) FROM reports.http_events where  time_stamp between '"+previousTime+".0' and  '"+currentTime+".0' ");
countQuery.next();
int totalRows = countQuery.getInt(1);
System.out.println("Total Rcords = "+totalRows+" Application Running Last update on "+currentTime);
String data = "";                
WebEvents events = new WebEvents();
while ( rs.next() ){
events.setuserID(userID);
      events.setTimeStamp(rs.getTimestamp("time_stamp"));
      events.setCClientAddr(rs.getString("c_client_addr"));
      events.setUsername(rs.getString("username"));
      events.setHost(rs.getString("host"));
      events.setHostName(rs.getString("hostname"));
      events.setRequestID(rs.getLong("request_id"));
      events.setUri(rs.getString("uri"));
      Gson gson = new Gson();  
      data+= gson.toJson(events)+",,";
}

3- For Sending Data to Web Services

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
private void sendPost(String data) throws Exception {
        
        
        String url = webUrl;
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
 
        //add reuqest header
        con.setRequestMethod("POST");
        con.setRequestProperty("User-Agent", USER_AGENT);
        con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
 
        String urlParameters = "data="+data;
 
        // Send post request
        con.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(urlParameters);
        wr.flush();
        wr.close();
 
        int responseCode = con.getResponseCode();
        
        if(responseCode == 404){
            System.out.println("Web Url is not correct");
        }
 
        BufferedReader in = new BufferedReader(
                new InputStreamReader(con.getInputStream()));
        String inputLine = "";
        String result = "";
        StringBuffer response = new StringBuffer();
 
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        result = response.toString().trim();
        
        if(!result.equals("ok")){
            System.out.println("Web Url is not correct");
            
        }
        in.close();
 
    }

  • Facebook
  • Twitter
  • Tumblr
  • Pinterest
  • Google+
  • LinkedIn
  • E-Mail

Comments are closed.

SEARCH BLOG

Categories

  • Blog (492)
  • Captain's Log (1)
  • Closure Reports (45)
  • Experiments (7)
  • How-To (57)
  • Implementation Notes (148)
  • Learn More (158)
  • LMS (8)
  • Look Inside (10)
  • Operations Log (12)
  • Programmer Notes (20)
  • R&D (14)
  • Rescue Log (4)
  • Testimonials (25)
  • Uncategorized (4)

RECENT STORIES

  • Ultimate Django: Become a Skilled Developer in 5 minutes
  • Create your 1st workflow with GitHub Actions within 5 Minutes
  • GitHub Actions- Automate your software workflows with excellence
  • Yii Framework – Accomplish Repetitive & Iterative Projects with Ease
  • A Recipe for CRM Software Development

ARCHIVES

In Short

With the vteams model, you bypass the middleman and hire your own offshore engineers - they work exclusively for you. You pay a reasonable monthly wage and get the job done without hassles, re-negotiations, feature counts or budget overruns.

Goals for 2020

  • Open development center in Australia
  • Complete and Launch the Robot
  • Structural changes to better address Clients' needs

Contact Us

Address: NEXTWERK INC.
6790 Embarcadero Ln, Ste 100,
Carlsbad, CA 92011, USA

Tel: (858) 586 7777
Email: fahad@nextwerk.com
Web: www.vteams.com

© 2020 vteams. All Rights Reserved.

Content Protection by DMCA.com