Skip to content

Commit ebf50a3

Browse files
committed
+ Enable concurrent HTTPS+HTTP serving
+ Code refactor. Signed-off-by: elmodo7 <elmodo7yt@gmail.com>
1 parent f81aff3 commit ebf50a3

File tree

5 files changed

+51
-15
lines changed

5 files changed

+51
-15
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>com.em7</groupId>
1212
<artifactId>wol</artifactId>
13-
<version>0.1.2</version>
13+
<version>0.1.4</version>
1414
<packaging>jar</packaging>
1515
<name>wol</name>
1616
<description>Wake on Lan</description>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.em7.wol.config;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.apache.catalina.connector.Connector;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
7+
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
8+
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
12+
@Slf4j
13+
@Configuration
14+
@ConditionalOnProperty(
15+
value="server.insecure.enabled",
16+
havingValue = "true",
17+
matchIfMissing = false)
18+
public class AppConfiguration {
19+
20+
@Value("${server.http.port}")
21+
private int httpPort;
22+
23+
@Bean
24+
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
25+
return (TomcatServletWebServerFactory factory) -> {
26+
// also listen on http
27+
final Connector connector = new Connector();
28+
log.info(String.valueOf(httpPort));
29+
30+
connector.setPort(httpPort);
31+
factory.addAdditionalTomcatConnectors(connector);
32+
};
33+
}
34+
}

src/main/java/com/em7/wol/util/RestUtils.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
@Slf4j
1515
public class RestUtils {
1616
public static String doPost(String urlString, JsonObject params) {
17-
String nombreMetodo = new Object() {
17+
String methodName = new Object() {
1818
}.getClass().getEnclosingMethod().getName();
19-
log.info(nombreMetodo + " Entrada datos: " + " - url: " + urlString + " - params: " + params.toString());
20-
String respuesta = "";
19+
log.info(methodName + " Data input: " + " - url: " + urlString + " - params: " + params.toString());
20+
String response = "";
2121
try {
2222
URL url = new URL(urlString);
2323
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
@@ -27,33 +27,33 @@ public static String doPost(String urlString, JsonObject params) {
2727
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
2828
wr.write(params.toString());
2929
wr.flush();
30-
respuesta = obtenerRespuesta(conn);
30+
response = getResponse(conn);
3131
conn.disconnect();
3232
} catch (Exception e) {
3333
log.error("", e);
3434
}
35-
log.info(nombreMetodo + " - Salida datos: " + respuesta);
36-
return respuesta;
35+
log.info(methodName + " - Data output: " + response);
36+
return response;
3737
}
3838

3939
public static String doGet(String urlString) {
40-
log.info("Entrada GET a " + urlString);
40+
log.info("GET to " + urlString);
4141
String respuesta = "";
4242
try {
4343
URL url = new URL(urlString);
4444
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
4545
conn.setRequestMethod("GET");
46-
respuesta = obtenerRespuesta(conn);
46+
respuesta = getResponse(conn);
4747
conn.disconnect();
4848
} catch (Exception e) {
4949
log.error("", e);
5050
}
5151
return respuesta;
5252
}
5353

54-
private static String obtenerRespuesta(HttpURLConnection conn) throws Exception {
54+
private static String getResponse(HttpURLConnection conn) throws Exception {
5555
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
56-
log.error("Error al conectar con el servidor");
56+
log.error("Error connecting to the server");
5757
} else {
5858
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), UTF_8));
5959
String strCurrentLine;

src/main/resources/application.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
version=0.1.2
1+
version=0.1.4
22
spring.profiles.active=default
33

44
wol.user=admin
55
wol.password=admin
66
server.port=7800
77
shutdown.port=7801
8+
server.insecure.enabled=true
9+
server.http.port=7802
810
security.require-ssl=false
911
server.ssl.enabled=false
1012
spring.thymeleaf.cache=true

src/main/resources/devices.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"status": false
99
},
1010
{
11-
"description": "8700K",
11+
"description": "Google DNS",
1212
"id": 2,
13-
"ip": "192.168.12.228",
13+
"ip": "8.8.8.8",
1414
"mac": "30:9C:23:FF:FF:FF",
15-
"name": "Desktop",
15+
"name": "Google",
1616
"status": false
1717
},
1818
{

0 commit comments

Comments
 (0)