Skip to content

Commit

Permalink
Formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
srimanachanta committed Oct 5, 2023
1 parent a207ed5 commit d3024c2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.javalin.websocket.WsConnectContext;
import io.javalin.websocket.WsContext;
import io.javalin.websocket.WsMessageContext;

import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.HashMap;
Expand Down Expand Up @@ -59,7 +58,8 @@ private CameraSocketHandler() {
}

public void onConnect(WsConnectContext context) {
context.session.setIdleTimeout(Duration.ofMillis(Long.MAX_VALUE)); // TODO: determine better value
context.session.setIdleTimeout(
Duration.ofMillis(Long.MAX_VALUE)); // TODO: determine better value
var remote = (InetSocketAddress) context.session.getRemoteAddress();
var host = remote.getAddress().toString() + ":" + remote.getPort();
logger.info("New camera websocket connection from " + host);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ private DataSocketHandler() {
}

public void onConnect(WsConnectContext context) {
context.session.setIdleTimeout(Duration.ofMillis(Long.MAX_VALUE)); // TODO: determine better value
context.session.setIdleTimeout(
Duration.ofMillis(Long.MAX_VALUE)); // TODO: determine better value
var remote = (InetSocketAddress) context.session.getRemoteAddress();
var host = remote.getAddress().toString() + ":" + remote.getPort();
logger.info("New websocket connection from " + host);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public static void onSettingsImportRequest(Context ctx) {
return;
}


if (!file.extension().contains("zip")) {
ctx.status(400);
ctx.result(
Expand Down Expand Up @@ -496,7 +495,7 @@ private static Optional<File> handleTempFileCreation(UploadedFile file) {
new File(Path.of(System.getProperty("java.io.tmpdir"), file.filename()).toString());
boolean makeDirsRes = tempFilePath.getParentFile().mkdirs();

if(!makeDirsRes) {
if (!makeDirsRes) {
logger.error(
"There was an error while uploading " + file.filename() + " to the temp folder!");
return Optional.empty();
Expand Down
72 changes: 39 additions & 33 deletions photon-server/src/main/java/org/photonvision/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,56 @@
package org.photonvision.server;

import io.javalin.Javalin;
import io.javalin.http.staticfiles.Location;

import io.javalin.plugin.bundled.CorsPluginConfig;
import java.net.InetSocketAddress;
import java.util.StringJoiner;

import io.javalin.plugin.bundled.CorsPluginConfig;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;

public class Server {
private static final Logger logger = new Logger(Server.class, LogGroup.WebServer);

public static void start(int port) {
var app = Javalin.create(javalinConfig -> {
javalinConfig.showJavalinBanner = false;
javalinConfig.staticFiles.add("web");
javalinConfig.plugins.enableCors(corsContainer -> {
corsContainer.add(CorsPluginConfig::anyHost);
});
var app =
Javalin.create(
javalinConfig -> {
javalinConfig.showJavalinBanner = false;
javalinConfig.staticFiles.add("web");
javalinConfig.plugins.enableCors(
corsContainer -> {
corsContainer.add(CorsPluginConfig::anyHost);
});

javalinConfig.requestLogger.http((ctx, ms) -> {
StringJoiner joiner =
new StringJoiner(" ")
.add("Handled HTTP request of type")
.add(ctx.req().getMethod())
.add("from endpoint")
.add(ctx.path())
.add("for host")
.add(ctx.req().getRemoteHost())
.add("in")
.add(ms.toString())
.add("ms");
javalinConfig.requestLogger.http(
(ctx, ms) -> {
StringJoiner joiner =
new StringJoiner(" ")
.add("Handled HTTP request of type")
.add(ctx.req().getMethod())
.add("from endpoint")
.add(ctx.path())
.add("for host")
.add(ctx.req().getRemoteHost())
.add("in")
.add(ms.toString())
.add("ms");

logger.debug(joiner.toString());
});
javalinConfig.requestLogger.ws(ws -> {
ws.onMessage(ctx -> logger.debug("Got WebSockets message: " + ctx.message()));
ws.onBinaryMessage(ctx -> logger.trace(() -> {
var remote = (InetSocketAddress) ctx.session.getRemoteAddress();
var host = remote.getAddress().toString() + ":" + remote.getPort();
return "Got WebSockets binary message from host: " + host;
}));
});
});
logger.debug(joiner.toString());
});
javalinConfig.requestLogger.ws(
ws -> {
ws.onMessage(ctx -> logger.debug("Got WebSockets message: " + ctx.message()));
ws.onBinaryMessage(
ctx ->
logger.trace(
() -> {
var remote = (InetSocketAddress) ctx.session.getRemoteAddress();
var host =
remote.getAddress().toString() + ":" + remote.getPort();
return "Got WebSockets binary message from host: " + host;
}));
});
});

/*Web Socket Events for Data Exchange */
var dsHandler = DataSocketHandler.getInstance();
Expand Down

0 comments on commit d3024c2

Please sign in to comment.