Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

## TODOs

### Apache httpd
- [ ] Enable logging to APACHE_LOG_DIR (this folder is currently being created during build process, but not used by apache server)
- [X] Redirecting from /index.html to /
### Httpd
- [ ] https support

### Java FCGI
- [ ] User input validation
- [ ] Add support of responces with information about errors
- [X] User input validation
- [X] Add support of responces with information about errors
Binary file added httpd/static/assets/img/logo.ico
Binary file not shown.
3 changes: 1 addition & 2 deletions httpd/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web lab1</title>
<script src="./js/ajax.js"></script>
<link rel="icon" href="assets/img/logo.ico" type="image/x-icon"/>
<style>
:root {
/* Цветовая палитра в OKLCH */
Expand Down Expand Up @@ -733,9 +734,7 @@ <h3 class="history-title">История введенных данных</h3>

if (X && R && Y) {

// Stub
sendAJAXGETRequest("/fcgi/", {"x": X, "y": Y, "r": R}, (data) => {FFCGIResponceHandler(data, X,Y,R)});
console.log(`Данные отправлены!\nX: ${X}\nY: ${Y}\nR: ${R}`);

// Очищаем форму
this.reset();
Expand Down
9 changes: 8 additions & 1 deletion server/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:17-jdk-slim AS build
FROM eclipse-temurin:17-jdk-alpine AS build

# copy maven confis
COPY pom.xml mvnw ./
Expand All @@ -14,7 +14,7 @@ RUN ./mvnw dependency:resolve
COPY src src
RUN ./mvnw clean package

FROM openjdk:17-jdk-slim
FROM eclipse-temurin:17-jre-alpine
WORKDIR server
COPY --from=build target/*.jar server-1.0.jar
ENTRYPOINT ["java", "-DFCGI_PORT=55555", "-jar", "server-1.0.jar"]
17 changes: 11 additions & 6 deletions server/src/main/java/org/web1/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.web1;

import com.fastcgi.*;

import java.util.HashMap;
import java.util.function.Function;

Expand All @@ -9,10 +10,11 @@
import org.web1.DTOs.RequestDTO;
import org.web1.checkers.Checker;
import org.web1.checkers.CheckerFunction;
import org.web1.netUtils.JsonBuilder;
import org.web1.netUtils.QueryStringToHashmap;
import org.web1.netUtils.ResponseFactory;
import org.web1.timer.Timer;
import org.web1.utils.mappers.JsonBuilder;
import org.web1.utils.mappers.QueryStringToHashmap;
import org.web1.utils.responce.ResponseFactory;
import org.web1.utils.responce.ResponseStatus;
import org.web1.utils.timer.Timer;

public class Main {
private static final Function<String, HashMap<String,String>> parseQuery = new QueryStringToHashmap();
Expand Down Expand Up @@ -46,13 +48,16 @@ public static void main(String[] args) {
String result = ResponseFactory.create(
new JsonBuilder()
.add("result", checkResult)
.add("elapsedTimeNs", timer.stop())
.add("elapsedTimeNs", timer.stop()),
ResponseStatus.OK
);

System.out.println(result);
} catch (ValidationException e) {
String result = ResponseFactory.create(
new JsonBuilder().add("error", '"'+e.getMessage()+'"')
new JsonBuilder()
.add("error", '"'+e.getMessage()+'"'),
ResponseStatus.BAD_REQUEST
);
System.out.println(result);
}
Expand Down
15 changes: 0 additions & 15 deletions server/src/main/java/org/web1/netUtils/ResponseFactory.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.web1.netUtils;
package org.web1.utils.mappers;

import java.util.HashMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.web1.netUtils;
package org.web1.utils.mappers;

import java.util.HashMap;
import java.util.function.Function;
Expand Down
37 changes: 37 additions & 0 deletions server/src/main/java/org/web1/utils/responce/ResponseFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.web1.utils.responce;

import org.web1.utils.mappers.JsonBuilder;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;

public class ResponseFactory {
private static final String BASE_RESPONSE = """
HTTP/2 %s\r
Status: %s\r
Access-Control-Allow-Origin: *\r
Connection: keep-alive\r
Content-Type: application/json; charset=utf-8\r
Content-Length: %d\r
\r
%s""";

private static final HashMap<ResponseStatus, String> responseStatus = new HashMap<>();

static {
responseStatus.put(ResponseStatus.BAD_REQUEST, "400");
responseStatus.put(ResponseStatus.OK, "200");
}

public static String create(JsonBuilder jsonBuilder, ResponseStatus status) {
String response = jsonBuilder.build();

return String.format(
BASE_RESPONSE,
responseStatus.get(status),
responseStatus.get(status),
response.getBytes(StandardCharsets.UTF_8).length + 1,
response
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.web1.utils.responce;

public enum ResponseStatus {
BAD_REQUEST,
OK
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.web1.timer;
package org.web1.utils.timer;

public class Timer {
long startTime;
Expand Down