diff --git a/plugin/src/software/aws/toolkits/eclipse/amazonq/views/AmazonQView.java b/plugin/src/software/aws/toolkits/eclipse/amazonq/views/AmazonQView.java index 2736481e..a134eea4 100644 --- a/plugin/src/software/aws/toolkits/eclipse/amazonq/views/AmazonQView.java +++ b/plugin/src/software/aws/toolkits/eclipse/amazonq/views/AmazonQView.java @@ -110,52 +110,53 @@ private void setupAuthStatusListeners() { AuthUtils.addAuthStatusChangeListener(amazonQCommonActions.getFeedbackDialogContributionAction()); } - /** - * Sets up virtual host mapping for the given path using jetty server - * @param jsPath - * @return server launched - */ - protected Server setupVirtualServer(String jsPath) { - Server server = null; - try { - server = new Server(0); - var servletContext = new ContextHandler(); - servletContext.setContextPath("/"); - servletContext.addVirtualHosts(new String[]{"localhost"}); - - var handler = new ResourceHandler(); - - ResourceFactory resourceFactory = ResourceFactory.of(server); - handler.setBaseResource(resourceFactory.newResource(jsPath)); - handler.setDirAllowed(true); - servletContext.setHandler(handler); - - server.setHandler(servletContext); + /** + * Sets up virtual host mapping for the given path using jetty server + * + * @param jsPath + * @return server launched + */ + protected Server setupVirtualServer(String jsPath) { + Server server = null; + try { + server = new Server(0); + var servletContext = new ContextHandler(); + servletContext.setContextPath("/"); + servletContext.addVirtualHosts(new String[] { "localhost" }); + + var handler = new ResourceHandler(); + + ResourceFactory resourceFactory = ResourceFactory.of(server); + handler.setBaseResource(resourceFactory.newResource(jsPath)); + handler.setDirAllowed(true); + servletContext.setHandler(handler); + + server.setHandler(servletContext); server.start(); - + return server; - + } catch (Exception e) { stopVirtualServer(server); PluginLogger.error("Error occurred while attempting to start a virtual server for " + jsPath, e); return null; } - } + } - protected void stopVirtualServer(Server server) { - if(server != null) { - try { + protected void stopVirtualServer(Server server) { + if (server != null) { + try { server.stop(); - } catch (Exception e) { + } catch (Exception e) { PluginLogger.error("Error occurred when attempting to stop the virtual server", e); } - } + } } @Override - public final void setFocus() { + public final void setFocus() { browser.setFocus(); - } + } /** * Disposes of the resources associated with this view.