Skip to content
Snippets Groups Projects
Commit d7f4723d authored by root's avatar root
Browse files

Added properties file

parent 50e9b937
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>rucd.monitoring</groupId> <modelVersion>4.0.0</modelVersion>
<artifactId>client</artifactId> <groupId>rucd.monitoring</groupId>
<version>1.0-SNAPSHOT</version> <artifactId>client</artifactId>
<packaging>jar</packaging> <version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<licenses> <licenses>
<license> <license>
<name>MIT License</name> <name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url> <url>http://www.opensource.org/licenses/mit-license.php</url>
</license> </license>
</licenses> </licenses>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>exec-maven-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>1.2.1</version> <version>3.0.2</version>
<executions> <configuration>
<execution> <archive>
<goals> <manifest>
<goal>java</goal> <addClasspath>true</addClasspath>
</goals> <mainClass>rucd.monitoring.client.Main</mainClass>
</execution> </manifest>
</executions> </archive>
<configuration> </configuration>
<mainClass>rucd.monitoring.client.Main</mainClass> </plugin>
<arguments> <plugin>
</arguments> <groupId>org.codehaus.mojo</groupId>
</configuration> <artifactId>exec-maven-plugin</artifactId>
</plugin> <version>1.2.1</version>
</plugins> <executions>
</build> <execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>rucd.monitoring.client.Main</mainClass>
<arguments>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
<dependencies> <dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.2</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>httpclient</artifactId> <artifactId>jackson-databind</artifactId>
<version>4.5.4</version> <version>2.9.2</version>
</dependency> </dependency>
</dependencies> <dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.4</version>
</dependency>
</dependencies>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.target>1.7</maven.compiler.target>
</properties> </properties>
</project> </project>
\ No newline at end of file
...@@ -23,16 +23,70 @@ ...@@ -23,16 +23,70 @@
*/ */
package rucd.monitoring.client; package rucd.monitoring.client;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Scanner;
public class Main { public class Main {
public static String token;
public static void main(String[] args) { public static void main(String[] args) {
Monitor monitor = new Monitor(); Properties properties = new Properties();
if(new File("config.properties").isFile()) {
InputStream input = null;
try {
input = new FileInputStream("config.properties");
// load a properties file
properties.load(input);
// get the property value and print it out
token = properties.getProperty("token");
System.out.println(token);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}else{
System.out.println("Veuillez entrer le token fourni par l'interface d'administration");
Scanner s = new Scanner(System.in);
token = s.nextLine();
properties.setProperty("token", token);
// Save the grades properties using store() and an output stream
FileOutputStream out;
try {
out = new FileOutputStream(
"config.properties");
properties.store(out, null);
out.close();
System.out.println("Fichier de configuration créer");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Monitor monitor = new Monitor();
Map<String, Object> analyze_result = monitor.analyze(); Map<String, Object> analyze_result = monitor.analyze();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
try { try {
......
package rucd.monitoring.client; package rucd.monitoring.client;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -18,7 +17,7 @@ public class Uploader { ...@@ -18,7 +17,7 @@ public class Uploader {
private String json; private String json;
private HttpClient httpclient; private HttpClient httpclient;
private HttpPost httppost ; private HttpPost httppost ;
private String url = "http://192.168.0.70/Laravel/public/api/sensors"; private String url = "http://192.168.0.71/Laravel/public/api/sensors";
public Uploader(String json) { public Uploader(String json) {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
this.json = json; this.json = json;
...@@ -32,6 +31,7 @@ private String url = "http://192.168.0.70/Laravel/public/api/sensors"; ...@@ -32,6 +31,7 @@ private String url = "http://192.168.0.70/Laravel/public/api/sensors";
List<NameValuePair> params = new ArrayList<NameValuePair>(1); List<NameValuePair> params = new ArrayList<NameValuePair>(1);
params.add(new BasicNameValuePair("content", json)); params.add(new BasicNameValuePair("content", json));
params.add(new BasicNameValuePair("token",Main.token));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = httpclient.execute(httppost); HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment