// Path: server/src/main/java/com/amplify/honeydew_server/ActionsExecutor.java
// public class ActionsExecutor {
// 
//     protected final UiDevice uiDevice;
//     private final Map<String, Action> actions;
//     private static final String TAG = ActionsExecutor.class.getName();
// 
//     public ActionsExecutor(UiDevice uiDevice) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
//         this.uiDevice = uiDevice;
//         actions = newHashMap();
//         for (Class<? extends Action> actionClass : allActionClasses()) {
//             Constructor<? extends Action> constructor = actionClass.getConstructor(UiDevice.class);
//             Action action = constructor.newInstance(this.uiDevice);
//             Log.d(TAG, String.format("Registering action: %s", action.name()));
//             actions.put(action.name(), action);
//         }
//     }
// 
//     public Result execute(Command command) {
//         String actionName = command.getAction();
//         try {
//             Action action = actions.get(actionName);
//             if (action == null) {
//                 return new Result("Action: " + actionName + " does not exist");
//             }
//             return executeWithStopwatch(command, action);
//         } catch (Exception e) {
//             return new Result("Exception, on calling " + actionName, e);
//         }
//     }
// 
//     private Result executeWithStopwatch(Command command, Action action) throws UiObjectNotFoundException {
//         Stopwatch timer = new Stopwatch().start();
// 
//         Result result = action.execute(command.getArguments());
// 
//         timer.stop();
//         Log.i(TAG, String.format("action '%s' took %d ms to execute on the tablet",
//                 command.getAction(), timer.elapsed(MILLISECONDS)));
//         return result;
//     }
// 
//     private static Set<Class<? extends Action>> allActionClasses() {
//         Set<Class<? extends Action>> actionClasses = newHashSet();
//         actionClasses.add(LaunchApp.class);
//         actionClasses.add(LaunchHome.class);
//         actionClasses.add(PressBack.class);
//         actionClasses.add(PressEnter.class);
//         actionClasses.add(WakeUp.class);
//         actionClasses.add(Sleep.class);
//         actionClasses.add(IsTextPresent.class);
//         actionClasses.add(IsTextGone.class);
//         actionClasses.add(IsRegexMatchPresent.class);
//         actionClasses.add(IsButtonPresent.class);
//         actionClasses.add(IsElementWithNestedTextPresent.class);
//         actionClasses.add(IsChildCountEqualTo.class);
//         actionClasses.add(IsChildCountGreaterThan.class);
//         actionClasses.add(Click.class);
//         actionClasses.add(ClickAndWaitForNewWindow.class);
//         actionClasses.add(LongClick.class);
//         actionClasses.add(SetText.class);
//         actionClasses.add(SetTextByLabel.class);
//         actionClasses.add(SetTextByIndex.class);
//         actionClasses.add(DumpWindowHierarchy.class);
//         actionClasses.add(SelectMenuInSettings.class);
//         actionClasses.add(IsOptionInSettingsMenuEnabled.class);
//         actionClasses.add(IsOptionInSettingsMenuDisabled.class);
//         actionClasses.add(HasSettingsMenuItem.class);
//         actionClasses.add(SelectFromAppsList.class);
//         actionClasses.add(Unlock.class);
//         actionClasses.add(ScrollToTextByIndex.class);
//         return actionClasses;
//     }
// }
// 
// Path: server/src/main/java/com/amplify/honeydew_server/Command.java
// public class Command {
//     private String action;
//     private Map<String, Object> arguments;
// 
//     public Command(String action, Map<String, Object> arguments) {
//         this.action = action;
//         this.arguments = arguments;
//     }
// 
//     public String getAction() {
//         return action;
//     }
// 
//     public Map<String, Object> getArguments() {
//         return arguments;
//     }
// }
// 
// Path: server/src/main/java/com/amplify/honeydew_server/Result.java
// public class Result {
//     public final boolean success;
//     public String description;
//     public String errorMessage;
//     public String stackTrace;
// 
//     public static Result OK = new Result();
//     public static Result FAILURE = new Result(false);
// 
//     public Result() {
//         this(true);
//     }
// 
//     public Result(boolean success) {
//         this(success, success ? "Success!" : "Failure.");
//     }
// 
//     public Result(boolean success, String description) {
//         this.success = success;
//         this.description = description;
//     }
// 
//     public Result(String errorMessage, Throwable exception) {
//         this(errorMessage);
//         this.stackTrace = ExceptionUtils.getFullStackTrace(exception);
//     }
// 
//     public Result(String errorMessage) {
//         this.success = false;
//         this.errorMessage = errorMessage;
//     }
// }


import android.util.Log;
import com.amplify.honeydew_server.ActionsExecutor;
import com.amplify.honeydew_server.Command;
import com.amplify.honeydew_server.Result;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import fi.iki.elonen.NanoHTTPD;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;
import static java.lang.String.format;
package com.amplify.honeydew_server.httpd;




public class RemoteCommandReceiver extends NanoHTTPD {

    private static final String PLAIN_TEXT = "plain/text";
    public static final Type ARGUMENTS_COLLECTION_TYPE = new TypeToken<Map<String, Object>>() {
    }.getType();
// Path: server/src/main/java/com/amplify/honeydew_server/ActionsExecutor.java
// public class ActionsExecutor {
// 
//     protected final UiDevice uiDevice;
//     private final Map<String, Action> actions;
//     private static final String TAG = ActionsExecutor.class.getName();
// 
//     public ActionsExecutor(UiDevice uiDevice) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
//         this.uiDevice = uiDevice;
//         actions = newHashMap();
//         for (Class<? extends Action> actionClass : allActionClasses()) {
//             Constructor<? extends Action> constructor = actionClass.getConstructor(UiDevice.class);
//             Action action = constructor.newInstance(this.uiDevice);
//             Log.d(TAG, String.format("Registering action: %s", action.name()));
//             actions.put(action.name(), action);
//         }
//     }
// 
//     public Result execute(Command command) {
//         String actionName = command.getAction();
//         try {
//             Action action = actions.get(actionName);
//             if (action == null) {
//                 return new Result("Action: " + actionName + " does not exist");
//             }
//             return executeWithStopwatch(command, action);
//         } catch (Exception e) {
//             return new Result("Exception, on calling " + actionName, e);
//         }
//     }
// 
//     private Result executeWithStopwatch(Command command, Action action) throws UiObjectNotFoundException {
//         Stopwatch timer = new Stopwatch().start();
// 
//         Result result = action.execute(command.getArguments());
// 
//         timer.stop();
//         Log.i(TAG, String.format("action '%s' took %d ms to execute on the tablet",
//                 command.getAction(), timer.elapsed(MILLISECONDS)));
//         return result;
//     }
// 
//     private static Set<Class<? extends Action>> allActionClasses() {
//         Set<Class<? extends Action>> actionClasses = newHashSet();
//         actionClasses.add(LaunchApp.class);
//         actionClasses.add(LaunchHome.class);
//         actionClasses.add(PressBack.class);
//         actionClasses.add(PressEnter.class);
//         actionClasses.add(WakeUp.class);
//         actionClasses.add(Sleep.class);
//         actionClasses.add(IsTextPresent.class);
//         actionClasses.add(IsTextGone.class);
//         actionClasses.add(IsRegexMatchPresent.class);
//         actionClasses.add(IsButtonPresent.class);
//         actionClasses.add(IsElementWithNestedTextPresent.class);
//         actionClasses.add(IsChildCountEqualTo.class);
//         actionClasses.add(IsChildCountGreaterThan.class);
//         actionClasses.add(Click.class);
//         actionClasses.add(ClickAndWaitForNewWindow.class);
//         actionClasses.add(LongClick.class);
//         actionClasses.add(SetText.class);
//         actionClasses.add(SetTextByLabel.class);
//         actionClasses.add(SetTextByIndex.class);
//         actionClasses.add(DumpWindowHierarchy.class);
//         actionClasses.add(SelectMenuInSettings.class);
//         actionClasses.add(IsOptionInSettingsMenuEnabled.class);
//         actionClasses.add(IsOptionInSettingsMenuDisabled.class);
//         actionClasses.add(HasSettingsMenuItem.class);
//         actionClasses.add(SelectFromAppsList.class);
//         actionClasses.add(Unlock.class);
//         actionClasses.add(ScrollToTextByIndex.class);
//         return actionClasses;
//     }
// }
// 
// Path: server/src/main/java/com/amplify/honeydew_server/Command.java
// public class Command {
//     private String action;
//     private Map<String, Object> arguments;
// 
//     public Command(String action, Map<String, Object> arguments) {
//         this.action = action;
//         this.arguments = arguments;
//     }
// 
//     public String getAction() {
//         return action;
//     }
// 
//     public Map<String, Object> getArguments() {
//         return arguments;
//     }
// }
// 
// Path: server/src/main/java/com/amplify/honeydew_server/Result.java
// public class Result {
//     public final boolean success;
//     public String description;
//     public String errorMessage;
//     public String stackTrace;
// 
//     public static Result OK = new Result();
//     public static Result FAILURE = new Result(false);
// 
//     public Result() {
//         this(true);
//     }
// 
//     public Result(boolean success) {
//         this(success, success ? "Success!" : "Failure.");
//     }
// 
//     public Result(boolean success, String description) {
//         this.success = success;
//         this.description = description;
//     }
// 
//     public Result(String errorMessage, Throwable exception) {
//         this(errorMessage);
//         this.stackTrace = ExceptionUtils.getFullStackTrace(exception);
//     }
// 
//     public Result(String errorMessage) {
//         this.success = false;
//         this.errorMessage = errorMessage;
//     }
// }


// Path: server/src/main/java/com/amplify/honeydew_server/httpd/RemoteCommandReceiver.java
import android.util.Log;
import com.amplify.honeydew_server.ActionsExecutor;
import com.amplify.honeydew_server.Command;
import com.amplify.honeydew_server.Result;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import fi.iki.elonen.NanoHTTPD;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;
import static java.lang.String.format;

package com.amplify.honeydew_server.httpd;




public class RemoteCommandReceiver extends NanoHTTPD {

    private static final String PLAIN_TEXT = "plain/text";
    public static final Type ARGUMENTS_COLLECTION_TYPE = new TypeToken<Map<String, Object>>() {
    }.getType();
    private final ActionsExecutor actionsExecutor;