<repo_name>adamkowal001/hackathonWebServerMail<file_sep>/WebMail/Server/src/main/java/http/Request.java
package http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.json.JSONObject;

import DB.DBsupport;
import DB.User;
import email.Email;

public class Request {
	
	private InputStream is;
	private BufferedReader br; 
	private String method;
	private String author;
	
	public String getMethod() {
		return method;
	}

	public String getAuthor() {
		return author;
	}

	public Email getEmail() {
		return email;
	}

	public User getUser() {
		return user;
	}

	private JSONObject data; 
	private Email email;
	private User user;
	private JSONObject json;
	
	public Request(InputStream is) {
		this.is = is;
		br = new BufferedReader(new InputStreamReader(is));
		
		try {
			System.out.println("przed readline");
			
			this.json = new JSONObject(br.readLine());
			System.out.println(this.json.toString());
			this.method = json.getString("method");
			if (this.method.equals("read")) {
				author = json.getString("author");								
			}else if(this.method.equals("write")) {
				JsonToEmail();
				
			}else if(this.method.equals("login")) {
				JsonToUser();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void JsonToEmail(){
		this.data = json.getJSONObject("data");	
		email = new Email(json.getString("author"), json.getString("to"), json.getString("text"));
	}
	
	public void JsonToUser(){
		this.data = json.getJSONObject("data");	
		user = new User(json.getString("author"), data.getString("password"));		
	}
	
}<file_sep>/WebMail/Client/src/main/java/email/Email.java
package email;

import org.json.JSONObject;

public class Email {
	private String from;
	private String to;
	private String content;
	
	public Email(String from, String to, String content){
		this.from = from;
		this.to = to;
		this.content = content;
	}
	
	public Email(JSONObject obj){
		this.from = obj.getString("from");
		this.to = obj.getString("to");
		this.content = obj.getString("content");
	}
	
	public String getFrom() {
		return from;
	}
	public void setFrom(String from) {
		this.from = from;
	}
	public String getTo() {
		return to;
	}
	public void setTo(String to) {
		this.to = to;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}

}
<file_sep>/WebMail/Server/src/main/java/Server.java
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import http.RequestHandler;

public class Server {
	
	public static void main(String[] args){
		ExecutorService es = Executors.newFixedThreadPool(5);
		
		try{
			ServerSocket ss = new ServerSocket(3000);
			boolean finish = false;
			while(!finish) {
				System.out.println("Server start");
				Socket s = ss.accept();
				System.out.println("someone connect");
				Future<Boolean> val = es.submit(new RequestHandler(s));

				System.out.println(val.get());
			}
			ss.close();
		} catch(Exception e){
			e.printStackTrace();
		}
	}
}
<file_sep>/WebMail/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>hackathon</groupId>
  <artifactId>WebMail</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <jdk.version>1.8</jdk.version>
  </properties>
  
  
  
  <dependencies>
  	<dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20171018</version>
    </dependency>
	<dependency>
	    <groupId>org.xerial</groupId>
	    <artifactId>sqlite-jdbc</artifactId>
	    <version>3.21.0.1</version>
	</dependency>

   </dependencies>
  
  
  
  <modules>
  	<module>Server</module>
  	<module>Client</module>
  </modules>
</project>
