Changed back to user, test circular reference

This commit is contained in:
Norbi Peti 2016-07-19 15:27:57 +02:00
parent ddbcc536a7
commit 127a37b097
4 changed files with 19 additions and 6 deletions

View file

@ -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<String, String> vars = new HashMap<>();
for (String var : content) {
String[] spl = var.split("\\=");
vars.put(spl[0], spl[1]);
}
return null;
}
}

View file

@ -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);

View file

@ -16,15 +16,15 @@ public class User {
private String email;
private String password;
@ElementCollection(fetch = FetchType.EAGER)
private List<Long> contacts;
private List<User> contacts;
public List<Long> getContacts() {
public List<User> getContacts() {
if (contacts == null)
contacts = new ArrayList<>();
return contacts;
}
public void setContacts(List<Long> contacts) {
public void setContacts(List<User> contacts) {
this.contacts = contacts;
}

View file

@ -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);
}