Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pissirSmartHome
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alfredo Chissotti
pissirSmartHome
Commits
3cb44b5a
Commit
3cb44b5a
authored
2 years ago
by
Alfredo Chissotti
Browse files
Options
Downloads
Patches
Plain Diff
rimosse classi inutilizzate dal server
parent
5550c8c1
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
WebServer/src/code/Antifurto.java
+0
-146
0 additions, 146 deletions
WebServer/src/code/Antifurto.java
WebServer/src/code/Luci.java
+0
-78
0 additions, 78 deletions
WebServer/src/code/Luci.java
with
0 additions
and
224 deletions
WebServer/src/code/Antifurto.java
deleted
100644 → 0
+
0
−
146
View file @
5550c8c1
package
code
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.List
;
import
com.sun.net.httpserver.HttpExchange
;
import
com.sun.net.httpserver.HttpHandler
;
public
class
Antifurto
implements
HttpHandler
{
private
boolean
statoAntifurto
=
true
;
private
boolean
statoAllarme
=
false
;
@Override
public
void
handle
(
HttpExchange
exchange
)
throws
IOException
{
URI
requestURI
=
exchange
.
getRequestURI
();
String
path
[]
=
requestURI
.
toString
().
split
(
"/"
);
String
lastfile
=
path
[
path
.
length
-
1
];
String
requestMethod
=
exchange
.
getRequestMethod
();
List
<
String
>
strlist
=
new
ArrayList
<>();
//serve List<String> a causa di .put("content-type", strlist);
strlist
.
add
(
"text/json"
);
exchange
.
getResponseHeaders
().
put
(
"content-type"
,
strlist
);
//opzionale, per dire cosa c'e' nel body
if
(
Helper
.
compareText
(
lastfile
,
"antifurto"
))
{
//get {stato, allarme, attenzione, soglia, sensori}
if
(
Helper
.
compareText
(
requestMethod
,
"GET"
))
{
String
response
=
"{\"stato\":true,\"soglia\":43,\"attenzione\":21,\"allarme\":false,\"sensori\":[{\"in0\":8},{\"in2\":3}]}"
;
statoAntifurto
=
true
;
statoAllarme
=
false
;
Helper
.
sendResponse
(
response
,
exchange
);
}
else
{
Helper
.
methodNotAllowed
(
exchange
);
}
return
;
}
if
(
Helper
.
compareText
(
lastfile
,
"stato"
))
{
//get, put {se l'antifurto e' attivo + aggiornamento}
if
(
Helper
.
compareText
(
requestMethod
,
"GET"
))
{
String
response
=
"{\"stato\":true}"
;
Helper
.
sendResponse
(
response
,
exchange
);
}
else
if
(
Helper
.
compareText
(
requestMethod
,
"PUT"
))
{
String
body
=
Helper
.
readBody
(
exchange
.
getRequestBody
());
if
(!
Helper
.
checkJSON
(
body
)
||
!
body
.
contains
(
"\"stato\""
))
{
Helper
.
badRequest
(
exchange
);
return
;
}
String
stato
=
body
.
split
(
"\"stato\""
,
2
)[
1
].
split
(
":"
,
2
)[
1
].
split
(
","
,
2
)[
0
].
split
(
"}"
,
2
)[
0
].
trim
();
try
{
boolean
exStato
=
statoAntifurto
;
statoAntifurto
=
Boolean
.
parseBoolean
(
stato
);
if
(
exStato
==
statoAntifurto
)
System
.
out
.
println
(
"\tRicevuto stato antifurto gia' assegnato"
);
if
(
statoAllarme
&&
!
statoAntifurto
)
{
Helper
.
badRequest
(
exchange
);
return
;
}
String
response
=
"{\"antifurto\":\"ok\",\"stato\":"
+
statoAntifurto
+
"}"
;
Helper
.
sendResponse
(
response
,
exchange
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Conversion error.\t"
+
stato
);
e
.
printStackTrace
();
Helper
.
badRequest
(
exchange
);
}
}
else
{
Helper
.
methodNotAllowed
(
exchange
);
}
return
;
}
if
(
Helper
.
compareText
(
lastfile
,
"allarme"
))
{
//get, put {se l'allarme sta suonando + aggiornamento}
if
(
Helper
.
compareText
(
requestMethod
,
"GET"
))
{
String
response
=
"{\"dati\":\"ecco l'allarme\"}"
;
Helper
.
sendResponse
(
response
,
exchange
);
}
else
if
(
Helper
.
compareText
(
requestMethod
,
"PUT"
))
{
String
body
=
Helper
.
readBody
(
exchange
.
getRequestBody
());
if
(!
Helper
.
checkJSON
(
body
)
||
!
body
.
contains
(
"\"stato\""
))
{
Helper
.
badRequest
(
exchange
);
return
;
}
String
stato
=
body
.
split
(
"\"stato\""
,
2
)[
1
].
split
(
":"
,
2
)[
1
].
split
(
","
,
2
)[
0
].
split
(
"}"
,
2
)[
0
].
trim
();
try
{
boolean
exStato
=
statoAllarme
;
statoAllarme
=
Boolean
.
parseBoolean
(
stato
);
if
(
exStato
==
statoAllarme
)
System
.
out
.
println
(
"\tRicevuto stato allarme gia' assegnato"
);
if
(
statoAllarme
&&
!
statoAntifurto
)
{
Helper
.
badRequest
(
exchange
);
return
;
}
String
response
=
"{\"allarme\":\"ok\",\"stato\":"
+
statoAllarme
+
"}"
;
Helper
.
sendResponse
(
response
,
exchange
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Conversion error.\t"
+
stato
);
e
.
printStackTrace
();
Helper
.
badRequest
(
exchange
);
}
}
else
{
Helper
.
methodNotAllowed
(
exchange
);
}
return
;
}
if
(
Helper
.
compareText
(
lastfile
,
"attenzione"
))
{
//put {valore della progress bar}
if
(
Helper
.
compareText
(
requestMethod
,
"PUT"
))
{
String
body
=
Helper
.
readBody
(
exchange
.
getRequestBody
());
if
(!
Helper
.
checkJSON
(
body
)
||
!
body
.
contains
(
"\"attenzione\""
))
{
Helper
.
badRequest
(
exchange
);
return
;
}
String
valore
=
body
.
split
(
"\"attenzione\""
,
2
)[
1
].
split
(
":"
,
2
)[
1
].
split
(
","
,
2
)[
0
].
split
(
"}"
,
2
)[
0
].
trim
();
try
{
int
val
=
Integer
.
parseInt
(
valore
);
String
response
=
"{\"attenzione\":"
+
val
+
"}"
;
Helper
.
sendResponse
(
response
,
exchange
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Conversion error.\t"
+
valore
);
e
.
printStackTrace
();
Helper
.
badRequest
(
exchange
);
}
}
else
{
Helper
.
methodNotAllowed
(
exchange
);
}
return
;
}
if
(
Helper
.
compareText
(
lastfile
,
"soglia"
))
{
//put {valore scelto dall'utente per la soglia}
if
(
Helper
.
compareText
(
requestMethod
,
"PUT"
))
{
System
.
out
.
println
(
Helper
.
readBody
(
exchange
.
getRequestBody
()));
String
response
=
"{\"dati\":\"soglia aggiornata\"}"
;
Helper
.
sendResponse
(
response
,
exchange
);
}
else
{
Helper
.
methodNotAllowed
(
exchange
);
}
return
;
}
Helper
.
pageNotFound
(
exchange
);
}
}
This diff is collapsed.
Click to expand it.
WebServer/src/code/Luci.java
deleted
100644 → 0
+
0
−
78
View file @
5550c8c1
package
code
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.List
;
import
com.sun.net.httpserver.HttpExchange
;
import
com.sun.net.httpserver.HttpHandler
;
public
class
Luci
implements
HttpHandler
{
@Override
public
void
handle
(
HttpExchange
exchange
)
throws
IOException
{
URI
requestURI
=
exchange
.
getRequestURI
();
String
path
[]
=
requestURI
.
getPath
().
split
(
"/"
);
String
lastfile
=
path
[
path
.
length
-
1
];
String
requestMethod
=
exchange
.
getRequestMethod
();
List
<
String
>
strlist
=
new
ArrayList
<>();
//serve List<String> a causa di .put("content-type", strlist);
strlist
.
add
(
"text/json"
);
exchange
.
getResponseHeaders
().
put
(
"content-type"
,
strlist
);
//opzionale, per dire cosa c'e' nel body
if
(
Helper
.
compareText
(
lastfile
,
"luci"
))
{
//post, get [put, delete] {luogo e stato di tutte luci}
if
(
Helper
.
compareText
(
requestMethod
,
"GET"
))
{
String
response
=
"[{\"luogo\":\"ingresso\",\"stato\":true,\"in\":\"in2\",\"out\":\"out2\"},{\"luogo\":\"cucina\",\"stato\":false,\"in\":\"in3\",\"out\":\"out3\"}]"
;
Helper
.
sendResponse
(
response
,
exchange
);
// Helper.methodNotAllowed(exchange);
}
else
if
(
Helper
.
compareText
(
requestMethod
,
"POST"
))
{
String
body
=
Helper
.
readBody
(
exchange
.
getRequestBody
());
//check body is json or xml
if
(!
Helper
.
checkJSON
(
body
)
||
!
body
.
contains
(
"\"luogo\""
))
{
Helper
.
badRequest
(
exchange
);
return
;
}
String
luogo
=
body
.
split
(
"\"luogo\""
,
2
)[
1
].
split
(
"\""
,
3
)[
1
].
trim
();
String
response
=
"{\"luogo\":\""
+
luogo
+
"\"}"
;
Helper
.
sendResponse
(
response
,
exchange
);
}
else
{
Helper
.
methodNotAllowed
(
exchange
);
}
return
;
}
if
(
Helper
.
compareText
(
lastfile
,
"stato"
))
{
//put {aggiorna lo stato di una luce}
if
(
Helper
.
compareText
(
requestMethod
,
"PUT"
))
{
String
body
=
Helper
.
readBody
(
exchange
.
getRequestBody
());
//check body is json or xml
if
(!
Helper
.
checkJSON
(
body
)
||
!
body
.
contains
(
"\"luogo\""
))
{
Helper
.
badRequest
(
exchange
);
return
;
}
String
stato
=
body
.
split
(
"\"stato\""
,
2
)[
1
].
split
(
":"
,
3
)[
1
].
split
(
","
,
2
)[
0
].
split
(
"}"
,
2
)[
0
].
trim
();
try
{
boolean
st
=
Boolean
.
parseBoolean
(
stato
);
String
response
=
"{\"luce\":\"ok\",\"stato\":"
+
st
+
"}"
;
Helper
.
sendResponse
(
response
,
exchange
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Conversion error.\t"
+
stato
);
e
.
printStackTrace
();
Helper
.
badRequest
(
exchange
);
}
}
else
{
Helper
.
methodNotAllowed
(
exchange
);
}
return
;
}
Helper
.
pageNotFound
(
exchange
);
}
}
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