-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from gprodriguez/master
Merge
- Loading branch information
Showing
5 changed files
with
96 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package es.uvigo.ei.sing.dummyserver; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
public class Functions { | ||
public static String parseRequest(BufferedReader in) { | ||
StringBuilder requestJson = new StringBuilder(); | ||
|
||
try { | ||
// Read the headers | ||
String headerLine; | ||
while (!(headerLine = in.readLine()).isEmpty()) { | ||
// TODO: Do something with the headers... | ||
} | ||
|
||
// Read the body (JSON) | ||
while (in.ready()) { | ||
// TODO: Do some content validations... | ||
requestJson.append((char) in.read()); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return requestJson.toString(); | ||
} | ||
|
||
public static void writeHeadersAndMessage(PrintWriter out, String message) { | ||
// TODO: Add the desired headers... | ||
out.println("POST HTTP/1.1"); | ||
out.println("Content-Length:" + message.length()); | ||
out.println("Content-Type: application/json; charset=utf-8"); | ||
out.println(""); | ||
out.println(message); | ||
out.flush(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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