Created
April 27, 2015 22:00
-
-
Save pumpkincouture/480da6abab565f45bf3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connection Manager with DataOutPutStream injected | |
public class ConnectionManager { | |
private DataOutputStream out; | |
private BufferedReader in; | |
private Socket socket; | |
private String directory; | |
private DataManager dataManager; | |
private Logger logger; | |
public ConnectionManager(BufferedReader in, Socket socket, String directory, DataManager dataManager, DataOutputStream out, Logger logger) { | |
this.out = out; | |
this.in = in; | |
this.socket = socket; | |
this.directory = directory; | |
this.dataManager = dataManager; | |
this.logger = logger; | |
} | |
public void executeRequest() throws IOException { | |
try { | |
String requestLines = ""; | |
do { | |
requestLines += (char) in.read(); | |
} while (in.ready()); | |
Router router = new Router(requestLines, directory, out, dataManager, logger); | |
router.createHandlers(); | |
out.flush(); | |
out.writeBytes(router.getResponse()); | |
out.flush(); | |
out.writeBytes(router.getBody()); | |
out.flush(); | |
in.close(); | |
out.close(); | |
socket.close(); | |
} | |
catch (Error err) { | |
System.out.println("Something went wrong!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment