Changed http codes (404 vs 501) + generic fixes
This commit is contained in:
parent
28eb5cf44d
commit
8170a24eec
@ -33,8 +33,8 @@ public class Main {
|
|||||||
/* trading */
|
/* trading */
|
||||||
router.addRoute(HttpMethod.GET, "/tradings", new TestService(), new int[]{});
|
router.addRoute(HttpMethod.GET, "/tradings", new TestService(), new int[]{});
|
||||||
router.addRoute(HttpMethod.POST, "/tradings", new TestService(), new int[]{});
|
router.addRoute(HttpMethod.POST, "/tradings", new TestService(), new int[]{});
|
||||||
router.addRoute(HttpMethod.DELETE, "/tradings/{tradingdealid}", new TestService(), new int[]{2});
|
router.addRoute(HttpMethod.DELETE, "/tradings/{tradingDealId}", new TestService(), new int[]{2});
|
||||||
router.addRoute(HttpMethod.POST, "/tradings/{tradingdealid}", new TestService(), new int[]{2});
|
router.addRoute(HttpMethod.POST, "/tradings/{tradingDealId}", new TestService(), new int[]{2});
|
||||||
|
|
||||||
Server server = new Server(10001, 10, router);
|
Server server = new Server(10001, 10, router);
|
||||||
server.start();
|
server.start();
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import at.nanopenguin.mtcg.http.HttpRequest;
|
|||||||
import at.nanopenguin.mtcg.http.Response;
|
import at.nanopenguin.mtcg.http.Response;
|
||||||
|
|
||||||
public class InternalErrorService implements Service {
|
public class InternalErrorService implements Service {
|
||||||
|
/* For error in http server */
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response handleRequest(HttpRequest request) {
|
public Response handleRequest(HttpRequest request) {
|
||||||
|
|||||||
@ -8,6 +8,6 @@ public class TestService implements Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response handleRequest(HttpRequest request) {
|
public Response handleRequest(HttpRequest request) {
|
||||||
return new Response(HttpStatus.OK, "application/json", "");
|
return new Response(HttpStatus.NOT_IMPLEMENTED, "application/json", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ public class HttpRequest {
|
|||||||
private final HttpMethod method;
|
private final HttpMethod method;
|
||||||
private final String path;
|
private final String path;
|
||||||
private final String version;
|
private final String version;
|
||||||
private Map<String, String> httpHeaders = new HashMap<String, String>();
|
private final Map<String, String> httpHeaders = new HashMap<>();
|
||||||
private final String body;
|
private final String body;
|
||||||
|
|
||||||
public HttpRequest(BufferedReader br) throws IOException {
|
public HttpRequest(BufferedReader br) throws IOException {
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public class RequestHandler implements Runnable {
|
|||||||
|
|
||||||
if (service == null) {
|
if (service == null) {
|
||||||
System.out.println("service does not exist");
|
System.out.println("service does not exist");
|
||||||
response = new Response(HttpStatus.NOT_IMPLEMENTED, "text/plain", "");
|
response = new Response(HttpStatus.NOT_FOUND, "text/plain", "");
|
||||||
break responseBuilder;
|
break responseBuilder;
|
||||||
}
|
}
|
||||||
System.out.println("creating response");
|
System.out.println("creating response");
|
||||||
|
|||||||
@ -19,10 +19,8 @@ public class Response {
|
|||||||
|
|
||||||
String localDatetime = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("UTC")));
|
String localDatetime = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneId.of("UTC")));
|
||||||
return "HTTP/1.1 " + this.httpStatus.statusCode + " " + this.httpStatus.statusMessage + "\r\n" +
|
return "HTTP/1.1 " + this.httpStatus.statusCode + " " + this.httpStatus.statusMessage + "\r\n" +
|
||||||
"Cache-Control: max-age=0\r\n" +
|
|
||||||
"Connection: close\r\n" +
|
"Connection: close\r\n" +
|
||||||
"Date: " + localDatetime + "\r\n" +
|
"Date: " + localDatetime + "\r\n" +
|
||||||
"Expires: " + localDatetime + "\r\n" +
|
|
||||||
"Content-Type: " + this.contentType + "\r\n" +
|
"Content-Type: " + this.contentType + "\r\n" +
|
||||||
"Content-Length: " + this.content.length() + "\r\n" +
|
"Content-Length: " + this.content.length() + "\r\n" +
|
||||||
"\r\n" +
|
"\r\n" +
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package at.nanopenguin.mtcg.http;
|
package at.nanopenguin.mtcg.http;
|
||||||
|
|
||||||
import at.nanopenguin.mtcg.application.InternalErrorService;
|
|
||||||
import at.nanopenguin.mtcg.application.Service;
|
import at.nanopenguin.mtcg.application.Service;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -34,7 +33,7 @@ public class Router {
|
|||||||
System.out.println("resolving route " + route);
|
System.out.println("resolving route " + route);
|
||||||
String[] routeComponents = route.split("/");
|
String[] routeComponents = route.split("/");
|
||||||
|
|
||||||
String pathVariable = null;
|
String pathVariable = null; // might be useful later, idk how services
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user