# HG changeset patch # User phrebejk # Date 1358265378 -3600 # Node ID ccc3fd318cb1debdb8c49fcc061685df1e1340ad # Parent c0f1788183ddc481ecb93b2e2d6007fa801cc3f3 Web development server initial prototype. diff -r c0f1788183dd -r ccc3fd318cb1 launcher/pom.xml --- a/launcher/pom.xml Tue Jan 15 15:56:45 2013 +0100 +++ b/launcher/pom.xml Tue Jan 15 16:56:18 2013 +0100 @@ -45,5 +45,10 @@ vm4brwsr ${project.version} + + org.json + json + 20090211 + diff -r c0f1788183dd -r ccc3fd318cb1 launcher/src/main/java/org/apidesign/bck2brwsr/dew/Dew.java --- a/launcher/src/main/java/org/apidesign/bck2brwsr/dew/Dew.java Tue Jan 15 15:56:45 2013 +0100 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/dew/Dew.java Tue Jan 15 16:56:18 2013 +0100 @@ -4,25 +4,55 @@ */ package org.apidesign.bck2brwsr.dew; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; +import java.util.logging.Logger; +import org.glassfish.grizzly.http.Method; import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; +import org.glassfish.grizzly.http.util.HttpStatus; +import org.json.JSONObject; +import org.json.JSONTokener; /** * * @author phrebejk */ public class Dew extends HttpHandler { + private static String html = "Nazdar!"; @Override public void service(Request request, Response response) throws Exception { + + if ( request.getMethod() == Method.POST ) { + InputStream is = request.getInputStream(); + JSONTokener tok = new JSONTokener(new InputStreamReader(is)); + JSONObject obj = new JSONObject(tok); + html = obj.getString("html"); + LOG.info(html); + + response.getOutputStream().write("[]".getBytes()); + response.setStatus(HttpStatus.OK_200); + + return; + } + String r = request.getHttpHandlerPath(); if (r == null || r.equals("/")) { r = "index.html"; } + if (r.equals("/result.html")) { + response.setContentType("text/html"); + response.getOutputBuffer().write(html); + response.setStatus(HttpStatus.OK_200); + return; + } + if (r.startsWith("/")) { r = r.substring(1); } @@ -38,6 +68,7 @@ response.setStatus(404); } } + private static final Logger LOG = Logger.getLogger(Dew.class.getName()); static void copyStream(InputStream is, OutputStream os, String baseURL) throws IOException { for (;;) { diff -r c0f1788183dd -r ccc3fd318cb1 launcher/src/main/resources/org/apidesign/bck2brwsr/dew/index.html --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/index.html Tue Jan 15 15:56:45 2013 +0100 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/index.html Tue Jan 15 16:56:18 2013 +0100 @@ -40,11 +40,14 @@
 
+ - diff -r c0f1788183dd -r ccc3fd318cb1 launcher/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js --- a/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js Tue Jan 15 15:56:45 2013 +0100 +++ b/launcher/src/main/resources/org/apidesign/bck2brwsr/dew/js/app.js Tue Jan 15 16:56:18 2013 +0100 @@ -70,11 +70,21 @@ }; }]); -function DevCtrl( $scope ) { +function DevCtrl( $scope, $http ) { - var htmlChange = function() { - var frame = document.getElementById("result"); - frame.contentDocument.write($scope.html); + $scope.reload= function() { + var frame = document.getElementById("result"); + frame.src = "result.html"; + frame.contentDocument.location.reload(true); + frame.contentWindow.location.reload(); + }; + + $scope.post = function(html, java) { + return $http({url: ".", + method: "POST", + //headers: this.headers, + data: { html : $scope.html, java : $scope.java} + }).success( $scope.reload ); }; $scope.tab = "html"; @@ -85,7 +95,7 @@ return tab === $scope.tab ? "active" : ""; }; - $scope.$watch( "html", htmlChange ); + // $scope.$watch( "html", htmlChange ); }