Commit 406501e0 authored by ReemyHasan's avatar ReemyHasan

add Rethink Functions

parent e0c31d51
...@@ -44,7 +44,7 @@ public class SnmpListener implements CommandResponder { ...@@ -44,7 +44,7 @@ public class SnmpListener implements CommandResponder {
} }
public void startTrapListener() { public void startTrapListener() {
try { try {
TransportMapping<?> transport = new DefaultUdpTransportMapping(new UdpAddress("192.168.26.46/1625")); TransportMapping<?> transport = new DefaultUdpTransportMapping(new UdpAddress("192.168.25.254/1625"));
System.out.println("Listening to SNMP Trap"); System.out.println("Listening to SNMP Trap");
Snmp snmp = new Snmp(transport); Snmp snmp = new Snmp(transport);
snmp.addCommandResponder(this); snmp.addCommandResponder(this);
......
...@@ -19,7 +19,7 @@ public class WebSocketConfig implements WebSocketConfigurer { ...@@ -19,7 +19,7 @@ public class WebSocketConfig implements WebSocketConfigurer {
@Override @Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
System.out.println(webSocketPath); // System.out.println(webSocketPath);
registry.addHandler(socket_server, webSocketPath).setAllowedOrigins("*"); registry.addHandler(socket_server, webSocketPath).setAllowedOrigins("*");
} }
} }
//package com.example.WebApplication.controller; package com.example.WebApplication.controller;
//
//import com.example.WebApplication.controller.SocketTextHandler; import com.example.WebApplication.controller.SocketTextHandler;
//import com.example.WebApplication.entities.RethinkChange; import com.example.WebApplication.entities.RethinkChange;
//import com.example.WebApplication.services.RethinkDBService; import com.example.WebApplication.services.RethinkDBService;
//import com.rethinkdb.net.Cursor; import com.rethinkdb.net.Cursor;
//import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
//import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.http.HttpStatus;
//import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*;
//
//import java.io.IOException; import java.io.IOException;
// import java.util.List;
//@RestController import java.util.Map;
//@RequestMapping("/api/rethink")
//public class RethinkController { @RestController
// @RequestMapping("/api/rethink")
// @Override @CrossOrigin(origins = {"http://localhost:3000"})
// public void run(String... args) throws Exception { public class RethinkController {
// Cursor<RethinkChange> changeCursor = rethinkDBService.subscribe(); @Autowired
// System.out.println("I am Subscribing"); private RethinkDBService rethinkDBService;
// //List<RethinkChange> result = new ArrayList<>(); @PostMapping("/delete")
// for (RethinkChange change : changeCursor){ public void delete(@RequestBody String id){
//// System.out.println("Something Changed "); rethinkDBService.deleteById(id);
//// System.out.println(change); }
//// result.add(change);
// try { @GetMapping("/data")
// socket_server.broadcast(change); public ResponseEntity<List<Map<String, Object>>> getData() {
// } catch (IOException e) { List<Map<String, Object>> result = rethinkDBService.getData();
// throw new RuntimeException(e); System.out.println(result);
// } if (result != null) {
// } return ResponseEntity.ok(result);
// } else {
// } return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
//} }
}
}
...@@ -25,8 +25,6 @@ import java.util.Map; ...@@ -25,8 +25,6 @@ import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@Component @Component
@RestController
@RequestMapping("/api/rethink")
public class SocketTextHandler extends TextWebSocketHandler implements CommandLineRunner { public class SocketTextHandler extends TextWebSocketHandler implements CommandLineRunner {
private List<WebSocketSession> sessions = new CopyOnWriteArrayList<>(); private List<WebSocketSession> sessions = new CopyOnWriteArrayList<>();
...@@ -98,8 +96,8 @@ public class SocketTextHandler extends TextWebSocketHandler implements CommandLi ...@@ -98,8 +96,8 @@ public class SocketTextHandler extends TextWebSocketHandler implements CommandLi
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
Cursor<RethinkChange> changeCursor = rethinkDBService.subscribe(); Cursor<RethinkChange> changeCursor = rethinkDBService.subscribe();
System.out.println("I am Subscribing"); System.out.println("I am Subscribing");
System.out.println(changeCursor.getClass()); // System.out.println(changeCursor.getClass());
System.out.println(changeCursor); // System.out.println(changeCursor);
//List<RethinkChange> result = new ArrayList<>(); //List<RethinkChange> result = new ArrayList<>();
for (RethinkChange change : changeCursor){ for (RethinkChange change : changeCursor){
System.out.println("Something Changed "); System.out.println("Something Changed ");
...@@ -112,8 +110,4 @@ public class SocketTextHandler extends TextWebSocketHandler implements CommandLi ...@@ -112,8 +110,4 @@ public class SocketTextHandler extends TextWebSocketHandler implements CommandLi
} }
} }
@PostMapping("/delete")
public void delete(@RequestBody String id){
rethinkDBService.deleteById(id);
}
} }
...@@ -34,10 +34,10 @@ public class RethinkDBService{ ...@@ -34,10 +34,10 @@ public class RethinkDBService{
String jsonString = objectMapper.writeValueAsString(rethinkTrap); String jsonString = objectMapper.writeValueAsString(rethinkTrap);
JsonNode jsonNode = objectMapper.readTree(jsonString); JsonNode jsonNode = objectMapper.readTree(jsonString);
Map<String,EnrichedTrap> document = objectMapper.convertValue(jsonNode, Map.class); Map<String,EnrichedTrap> document = objectMapper.convertValue(jsonNode, Map.class);
System.out.println(jsonString); // System.out.println(jsonString);
System.out.println(jsonNode); // System.out.println(jsonNode);
System.out.println(document); // System.out.println(document);
System.out.println("I am here reem " + connectionFactory.getDbName() + " " + connectionFactory.getDbTableName()); // System.out.println("I am here reem " + connectionFactory.getDbName() + " " + connectionFactory.getDbTableName());
r.db(connectionFactory.getDbName()).table(connectionFactory.getDbTableName()).insert(document).run(connectionFactory.getConnection()); r.db(connectionFactory.getDbName()).table(connectionFactory.getDbTableName()).insert(document).run(connectionFactory.getConnection());
System.out.println("I am here now reem"); System.out.println("I am here now reem");
} catch (Exception e) { } catch (Exception e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment