Skip to content

Commit

Permalink
modifying the compiler running servlet so it knows to deal with 503s …
Browse files Browse the repository at this point in the history
…too.
  • Loading branch information
dyoo committed Apr 11, 2013
1 parent 7385d8d commit dc834f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
45 changes: 26 additions & 19 deletions src/org/wescheme/project/Compiler.java
Expand Up @@ -90,32 +90,39 @@ public static ObjectCode compileObjectCode(ServletContext ctx, SourceCode src) t
*/
public static CompilationResult compile(ServletContext ctx, String programName, String programSource){
try {
URL url = new URL(new WeSchemeProperties(ctx).getCompilationServerUrl());
URL url = new URL(new WeSchemeProperties(ctx).getCompilationServerUrl());
String data = "name=" + URLEncoder.encode(programName, "UTF-8") +
"&format=json" +
"&program=" + URLEncoder.encode(programSource, "UTF-8");


HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();

if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
while (true) {
try {
JSONObject obj = (JSONObject) jsonParser.parse(readStream(conn.getInputStream()));
String compiledCode = (String) obj.get("bytecode");
Set<String> perms = jsonStringArrayToSet((JSONArray) obj.get("permissions"));
Set<String> provides = jsonStringArrayToSet((JSONArray) obj.get("provides"));
return new GoodCompilationResult(compiledCode, perms, provides);
} catch (ParseException e) {
return new BadCompilationResult(e.toString());
conn.setRequestMethod("POST");
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
try {
JSONObject obj = (JSONObject) jsonParser.parse(readStream(conn.getInputStream()));
String compiledCode = (String) obj.get("bytecode");
Set<String> perms = jsonStringArrayToSet((JSONArray) obj.get("permissions"));
Set<String> provides = jsonStringArrayToSet((JSONArray) obj.get("provides"));
return new GoodCompilationResult(compiledCode, perms, provides);
} catch (ParseException e) {
return new BadCompilationResult(e.toString());
}
} else if (conn.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE) {
// Retry if the compiler server fails due to being temporarily overloaded.
continue;
} else {
String errorMessage = readStream(conn.getErrorStream());
return new BadCompilationResult(errorMessage);
}
} finally {
conn.disconnect();
}
} else {
String errorMessage = readStream(conn.getErrorStream());
return new BadCompilationResult(errorMessage);
}
} catch (MalformedURLException e) {
return new BadCompilationResult(e.getMessage());
Expand Down
4 changes: 2 additions & 2 deletions war/WEB-INF/appengine-web.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>dyoo-test</application>
<version>15</version>
<application>wescheme</application>
<version>68</version>

<!-- Configure java.util.logging -->
<system-properties>
Expand Down

0 comments on commit dc834f8

Please sign in to comment.