From 127a37b097f5467da454f774b87940b0d26596f5 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 19 Jul 2016 15:27:57 +0200 Subject: [PATCH] Changed back to user, test circular reference --- src/io/github/norbipeti/chat/server/IOHelper.java | 12 ++++++++++++ src/io/github/norbipeti/chat/server/Main.java | 4 ++-- .../github/norbipeti/chat/server/db/domain/User.java | 6 +++--- .../norbipeti/chat/server/page/RegisterPage.java | 3 ++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/io/github/norbipeti/chat/server/IOHelper.java b/src/io/github/norbipeti/chat/server/IOHelper.java index 282e92a..4f4964e 100644 --- a/src/io/github/norbipeti/chat/server/IOHelper.java +++ b/src/io/github/norbipeti/chat/server/IOHelper.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.List; import org.apache.commons.io.IOUtils; import com.sun.net.httpserver.HttpExchange; @@ -35,4 +37,14 @@ public class IOHelper { String content = IOUtils.toString(inputStream, StandardCharsets.UTF_8); return content; } + + public static String GetPOST(HttpExchange exchange) throws IOException { + String[] content = IOUtils.toString(exchange.getRequestBody(), StandardCharsets.ISO_8859_1).split("\\&"); + HashMap vars = new HashMap<>(); + for (String var : content) { + String[] spl = var.split("\\="); + vars.put(spl[0], spl[1]); + } + return null; + } } diff --git a/src/io/github/norbipeti/chat/server/Main.java b/src/io/github/norbipeti/chat/server/Main.java index f7de172..b0eb1d6 100644 --- a/src/io/github/norbipeti/chat/server/Main.java +++ b/src/io/github/norbipeti/chat/server/Main.java @@ -30,10 +30,10 @@ public class Main { provider.addUser(user); User user2 = new User(); user2.setName("Teszt"); - user2.getContacts().add(user.getId()); + user2.getContacts().add(user); provider.addUser(user2); System.out.println(provider.getUsers()); - System.out.println("Contact: " + provider.getUser(user2.getContacts().get(0))); + System.out.println("Contact: " + user2.getContacts().get(0)); } System.out.println("Starting webserver..."); HttpServer server = HttpServer.create(new InetSocketAddress(InetAddress.getLocalHost(), 8080), 10); diff --git a/src/io/github/norbipeti/chat/server/db/domain/User.java b/src/io/github/norbipeti/chat/server/db/domain/User.java index 1848284..8294f5d 100644 --- a/src/io/github/norbipeti/chat/server/db/domain/User.java +++ b/src/io/github/norbipeti/chat/server/db/domain/User.java @@ -16,15 +16,15 @@ public class User { private String email; private String password; @ElementCollection(fetch = FetchType.EAGER) - private List contacts; + private List contacts; - public List getContacts() { + public List getContacts() { if (contacts == null) contacts = new ArrayList<>(); return contacts; } - public void setContacts(List contacts) { + public void setContacts(List contacts) { this.contacts = contacts; } diff --git a/src/io/github/norbipeti/chat/server/page/RegisterPage.java b/src/io/github/norbipeti/chat/server/page/RegisterPage.java index d1fc90e..e52af95 100644 --- a/src/io/github/norbipeti/chat/server/page/RegisterPage.java +++ b/src/io/github/norbipeti/chat/server/page/RegisterPage.java @@ -1,7 +1,6 @@ package io.github.norbipeti.chat.server.page; import java.io.IOException; - import com.sun.net.httpserver.HttpExchange; import io.github.norbipeti.chat.server.IOHelper; @@ -9,6 +8,8 @@ import io.github.norbipeti.chat.server.IOHelper; public class RegisterPage extends Page { @Override public void handlePage(HttpExchange exchange) throws IOException { + /*for(String line : IOHelper.GetPOST(exchange)) + System.out.println(line);*/ IOHelper.SendPage(200, this, exchange); }