test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/HttpServer.java in calabash-android-0.4.6 vs test-server/instrumentation-backend/src/sh/calaba/instrumentationbackend/actions/HttpServer.java in calabash-android-0.4.7.pre1

- old
+ new

@@ -1,11 +1,10 @@ package sh.calaba.instrumentationbackend.actions; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.List; import java.util.Map; import java.util.Properties; @@ -15,12 +14,12 @@ import sh.calaba.instrumentationbackend.Command; import sh.calaba.instrumentationbackend.FranklyResult; import sh.calaba.instrumentationbackend.InstrumentationBackend; import sh.calaba.instrumentationbackend.Result; +import sh.calaba.instrumentationbackend.json.JSONUtils; import sh.calaba.instrumentationbackend.query.Query; -import sh.calaba.instrumentationbackend.query.QueryResult; import sh.calaba.org.codehaus.jackson.map.DeserializationConfig.Feature; import sh.calaba.org.codehaus.jackson.map.ObjectMapper; import android.graphics.Bitmap; import android.util.Log; import android.view.View; @@ -59,31 +58,66 @@ private HttpServer(int testServerPort) { super(testServerPort, new File("/")); } - @SuppressWarnings("rawtypes") + @SuppressWarnings({ "rawtypes", "unchecked" }) public Response serve(String uri, String method, Properties header, Properties params, Properties files) { System.out.println("URI: " + uri); if (uri.endsWith("/ping")) { return new NanoHTTPD.Response(HTTP_OK, MIME_HTML, "pong"); - } else if (uri.endsWith("/map")) { + } + else if (uri.endsWith("/dump")) { FranklyResult errorResult = null; try { + + + String json = params.getProperty("json"); + + + if (json == null) + { + Map<?,?> dumpTree = new ViewDump().dumpWithoutElements(); + return new NanoHTTPD.Response(HTTP_OK, "application/json;charset=utf-8", JSONUtils.asJson(dumpTree)); + } + else + { + ObjectMapper mapper = new ObjectMapper(); + Map dumpSpec = mapper.readValue(json, Map.class); + + List<Integer> path = (List<Integer>) dumpSpec.get("path"); + if (path == null) + { + Map<?,?> dumpTree = new ViewDump().dumpWithoutElements(); + return new NanoHTTPD.Response(HTTP_OK, "application/json;charset=utf-8", JSONUtils.asJson(dumpTree)); + } + Map<?,?> dumpTree = new ViewDump().dumpPathWithoutElements(path); + return new NanoHTTPD.Response(HTTP_OK, "application/json;charset=utf-8", JSONUtils.asJson(dumpTree)); + } + + + } catch (Exception e ) { + e.printStackTrace(); + errorResult = FranklyResult.fromThrowable(e); + } + return new NanoHTTPD.Response(HTTP_INTERNALERROR, "application/json;charset=utf-8", errorResult.asJson()); + } + else if (uri.endsWith("/map")) { + FranklyResult errorResult = null; + try { String commandString = params.getProperty("json"); ObjectMapper mapper = new ObjectMapper(); Map command = mapper.readValue(commandString, Map.class); String uiQuery = (String) command.get("query"); Map op = (Map) command.get("operation"); + @SuppressWarnings("unused") //TODO: support other methods, e.g., flash String methodName = (String) op.get("method_name"); List arguments = (List) op.get("arguments"); - //For now we only support query and query_all - //query_all includes also invisible views, while query filters them - boolean includeInVisible = "query_all".equals(methodName); + //For now we only support query List queryResult = new Query(uiQuery,arguments).executeQuery(); return new NanoHTTPD.Response(HTTP_OK, "application/json;charset=utf-8",