Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
monitoring
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cylab
monitoring
Commits
967ddad3
Commit
967ddad3
authored
6 years ago
by
btalhaoui
Browse files
Options
Downloads
Patches
Plain Diff
client get the token from the api
parent
70f34e20
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/src/main/java/rucd/monitoring/client/Main.java
+18
-7
18 additions, 7 deletions
client/src/main/java/rucd/monitoring/client/Main.java
client/src/main/java/rucd/monitoring/client/Uploader.java
+28
-4
28 additions, 4 deletions
client/src/main/java/rucd/monitoring/client/Uploader.java
with
46 additions
and
11 deletions
client/src/main/java/rucd/monitoring/client/Main.java
+
18
−
7
View file @
967ddad3
...
...
@@ -38,7 +38,7 @@ import java.util.Properties;
import
java.util.Scanner
;
public
class
Main
{
public
static
String
token
;
public
static
String
token
=
""
;
public
static
void
main
(
String
[]
args
)
{
Properties
properties
=
new
Properties
();
if
(
new
File
(
"config.properties"
).
isFile
())
{
...
...
@@ -52,7 +52,8 @@ public class Main {
// get the property value and print it out
token
=
properties
.
getProperty
(
"token"
);
System
.
out
.
println
(
token
);
System
.
out
.
println
(
"Insert the following token in organization management :"
);
System
.
out
.
println
(
"\""
+
token
+
"\""
);
}
catch
(
IOException
ex
)
{
ex
.
printStackTrace
();
}
finally
{
...
...
@@ -65,11 +66,20 @@ public class Main {
}
}
}
else
{
System
.
out
.
println
(
"Veuillez entrer le token fourni par l'interface d'administration"
);
Scanner
s
=
new
Scanner
(
System
.
in
);
token
=
s
.
nextLine
();
Uploader
up
=
new
Uploader
();
up
.
initialize
();
while
(
token
==
""
)
{
try
{
token
=
up
.
register
();
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
properties
.
setProperty
(
"token"
,
token
);
System
.
out
.
println
(
"Insert the following token in organization management :"
);
System
.
out
.
println
(
"\""
+
token
+
"\""
);
// Save the grades properties using store() and an output stream
FileOutputStream
out
;
try
{
...
...
@@ -77,7 +87,7 @@ public class Main {
"config.properties"
);
properties
.
store
(
out
,
null
);
out
.
close
();
System
.
out
.
println
(
"
Fichier de
configuration
créer
"
);
System
.
out
.
println
(
"configuration
file created
"
);
}
catch
(
FileNotFoundException
e1
)
{
// TODO Auto-generated catch block
e1
.
printStackTrace
();
...
...
@@ -89,11 +99,12 @@ public class Main {
Monitor
monitor
=
new
Monitor
();
Map
<
String
,
Object
>
analyze_result
=
monitor
.
analyze
();
ObjectMapper
mapper
=
new
ObjectMapper
();
Uploader
up
;
try
{
// Convert object to JSON string and pretty print
String
json_string
=
mapper
.
writerWithDefaultPrettyPrinter
()
.
writeValueAsString
(
analyze_result
);
Uploader
up
=
new
Uploader
(
json_string
);
up
=
new
Uploader
(
json_string
);
up
.
initialize
();
try
{
up
.
post
();
...
...
This diff is collapsed.
Click to expand it.
client/src/main/java/rucd/monitoring/client/Uploader.java
+
28
−
4
View file @
967ddad3
...
...
@@ -5,30 +5,38 @@ import java.util.List;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.HttpStatus
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.impl.client.BasicResponseHandler
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.util.EntityUtils
;
public
class
Uploader
{
private
String
json
;
private
HttpClient
httpclient
;
private
HttpPost
httppost
;
private
String
u
rl
=
"http://192.168.0.71/Laravel/public/api/
sensors
"
;
private
String
baseU
rl
=
"http://192.168.0.71/Laravel/public/api/"
;
public
Uploader
(
String
json
)
{
// TODO Auto-generated constructor stub
this
.
json
=
json
;
}
public
Uploader
()
{
}
public
void
initialize
()
{
httpclient
=
HttpClients
.
createDefault
();
httppost
=
new
HttpPost
(
url
);
}
public
void
post
()
throws
Exception
{
String
url
=
"sensors/"
;
httppost
=
new
HttpPost
(
baseUrl
+
url
);
List
<
NameValuePair
>
params
=
new
ArrayList
<
NameValuePair
>(
1
);
params
.
add
(
new
BasicNameValuePair
(
"content"
,
json
));
params
.
add
(
new
BasicNameValuePair
(
"token"
,
Main
.
token
));
...
...
@@ -39,10 +47,26 @@ private String url = "http://192.168.0.71/Laravel/public/api/sensors";
if
(
entity
!=
null
)
{
InputStream
instream
=
entity
.
getContent
();
try
{
System
.
out
.
println
(
instream
.
toString
()
)
;
instream
.
toString
();
}
finally
{
instream
.
close
();
}
}
}
public
String
register
()
throws
Exception
{
String
url
=
"register"
;
HttpGet
httpget
=
new
HttpGet
(
baseUrl
+
url
);
HttpResponse
response
=
httpclient
.
execute
(
httpget
);
if
(
response
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_OK
)
{
String
result
=
null
;
HttpEntity
entity
=
response
.
getEntity
();
if
(
entity
!=
null
)
{
result
=
EntityUtils
.
toString
(
entity
);
}
return
result
;
}
else
if
(
response
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_UNAUTHORIZED
)
{
return
"401 SC_UNAUTHORIZED"
;
}
return
"UNKNOWN ERROR"
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment