package ru.mail.teamcity.ssh.controller;

import com.google.gson.Gson;
import com.intellij.openapi.util.text.StringUtil;
import jetbrains.buildServer.users.SUser;
import jetbrains.buildServer.web.openapi.WebControllerManager;
import jetbrains.buildServer.web.util.SessionUser;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import ru.mail.teamcity.ssh.config.PresetBean;
import ru.mail.teamcity.ssh.config.PresetManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Author: g.chernyshev
 * Date: 04.06.15
 */
public class WebSshPresetResourceController extends AbstractController {


    public WebSshPresetResourceController(
            @NotNull WebControllerManager webControllerManager
    ) {
        webControllerManager.registerController("/webSshPresetResource.html", this);
    }

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String id = request.getParameter("id");
        if (null == id || StringUtil.isEmpty(id)) {
            return null; // TODO error here
        }

        SUser user = SessionUser.getUser(request);
        PresetBean bean = PresetManager.load(user, id);
        if (null != bean) {
            bean.setPassword(""); // because view is read-only - remove password at all
            response.setContentType("application/json");
            response.getOutputStream().write(new Gson().toJson(bean).getBytes());
        }

        return null;
    }
}

@@ -31,24 +31,64 @@
 ontroller;%0A%0A
+import com.google.common.collect.Lists;%0A
 import com.g
@@ -464,24 +464,69 @@
 Controller;%0A
+import ru.mail.teamcity.ssh.config.HostBean;%0A
 import ru.ma
@@ -1554,16 +1554,130 @@
  at all%0A
+            bean.setHosts(Lists.%3CHostBean%3EnewArrayList()); // prevent stack overflow during serialization to json%0A
         

Clear hosts to prevent stack overflow