Example usage for java.security AccessControlException getMessage

List of usage examples for java.security AccessControlException getMessage

Introduction

In this page you can find the example usage for java.security AccessControlException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.jredrain.startup.Bootstrap.java

private void await() throws Exception {
    // Negative values - don't wait on port - redrain is embedded or we just don't like ports
    if (port == -2) {
        return;//from  w w  w.j  a v a2  s .c o  m
    }
    if (port == -1) {
        try {
            awaitThread = Thread.currentThread();
            while (!stopAwait) {
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException ex) {
                    // continue and check the flag
                }
            }
        } finally {
            awaitThread = null;
        }
        return;
    }

    // Set up a server socket to wait on
    try {
        awaitSocket = new ServerSocket(RedrainProperties.getInt("redrain.shutdown"));
    } catch (IOException e) {
        logger.error("[redrain] agent .await: create[{}] ", RedrainProperties.getInt("redrain.shutdown"), e);
        return;
    }

    try {
        awaitThread = Thread.currentThread();
        // Loop waiting for a connection and a valid command
        while (!stopAwait) {
            ServerSocket serverSocket = awaitSocket;
            if (serverSocket == null) {
                break;
            }
            // Wait for the next connection
            Socket socket = null;
            StringBuilder command = new StringBuilder();
            try {
                InputStream stream;
                long acceptStartTime = System.currentTimeMillis();
                try {
                    socket = serverSocket.accept();
                    socket.setSoTimeout(10 * 1000); // Ten seconds
                    stream = socket.getInputStream();
                } catch (SocketTimeoutException ste) {
                    // This should never happen but bug 56684 suggests that
                    // it does.
                    logger.warn("[redrain] agentServer accept.timeout",
                            Long.valueOf(System.currentTimeMillis() - acceptStartTime), ste);
                    continue;
                } catch (AccessControlException ace) {
                    logger.warn("[redrain] agentServer .accept security exception: {}", ace.getMessage(), ace);
                    continue;
                } catch (IOException e) {
                    if (stopAwait) {
                        break;
                    }
                    logger.error("[redrain] agent .await: accept: ", e);
                    break;
                }

                // Read a set of characters from the socket
                int expected = 1024; // Cut off to avoid DoS attack
                while (expected < shutdown.length()) {
                    if (random == null) {
                        random = new Random();
                    }
                    expected += (random.nextInt() % 1024);
                }
                while (expected > 0) {
                    int ch = -1;
                    try {
                        ch = stream.read();
                    } catch (IOException e) {
                        logger.warn("[redrain] agent .await: read: ", e);
                        ch = -1;
                    }
                    if (ch < 32) // Control character or EOF terminates loop
                        break;
                    command.append((char) ch);
                    expected--;
                }
            } finally {
                try {
                    if (socket != null) {
                        socket.close();
                    }
                } catch (IOException e) {
                }
            }
            boolean match = command.toString().equals(shutdown);
            if (match) {
                break;
            } else {
                logger.warn("[redrain] agent .await: Invalid command '" + command.toString() + "' received");
            }
        }
    } finally {
        ServerSocket serverSocket = awaitSocket;
        awaitThread = null;
        awaitSocket = null;
        // Close the server socket and return
        if (serverSocket != null) {
            try {
                serverSocket.close();
            } catch (IOException e) {
                // Ignore
            }
        }
    }

}

From source file:azkaban.webapp.servlet.ProjectManagerServlet.java

private void ajaxFetchFlowDetails(Project project, HashMap<String, Object> ret, HttpServletRequest req)
        throws ServletException {
    String flowName = getParam(req, "flow");

    Flow flow = null;//from  w  w  w.  j av  a 2  s  .  c  o m
    try {
        flow = project.getFlow(flowName);
        if (flow == null) {
            ret.put("error", "Flow " + flowName + " not found.");
            return;
        }

        ret.put("jobTypes", getFlowJobTypes(flow));
    } catch (AccessControlException e) {
        ret.put("error", e.getMessage());
    }
}

From source file:azkaban.webapp.servlet.ProjectManagerServlet.java

private void handleFlowPage(HttpServletRequest req, HttpServletResponse resp, Session session)
        throws ServletException {
    Page page = newPage(req, resp, session, "azkaban/webapp/servlet/velocity/flowpage.vm");
    String projectName = getParam(req, "project");
    String flowName = getParam(req, "flow");

    User user = session.getUser();//  ww w  . ja  v  a  2  s. com
    Project project = null;
    Flow flow = null;
    try {
        project = projectManager.getProject(projectName);
        if (project == null) {
            page.add("errorMsg", "Project " + projectName + " not found.");
            page.render();
            return;
        }

        if (!hasPermission(project, user, Type.READ)) {
            throw new AccessControlException("No permission Project " + projectName + ".");
        }

        page.add("project", project);
        flow = project.getFlow(flowName);
        if (flow == null) {
            page.add("errorMsg", "Flow " + flowName + " not found.");
        } else {
            page.add("flowid", flow.getId());
        }
    } catch (AccessControlException e) {
        page.add("errorMsg", e.getMessage());
    }

    page.render();
}

From source file:azkaban.webapp.servlet.ProjectManagerServlet.java

private void handleProjectLogsPage(HttpServletRequest req, HttpServletResponse resp, Session session)
        throws ServletException, IOException {
    Page page = newPage(req, resp, session, "azkaban/webapp/servlet/velocity/projectlogpage.vm");
    String projectName = getParam(req, "project");

    User user = session.getUser();/*from  w  w w  .java2 s .c om*/
    Project project = null;
    try {
        project = projectManager.getProject(projectName);
        if (project == null) {
            page.add("errorMsg", "Project " + projectName + " doesn't exist.");
        } else {
            if (!hasPermission(project, user, Type.READ)) {
                throw new AccessControlException("No permission to view project " + projectName + ".");
            }

            page.add("project", project);
            page.add("admins", Utils.flattenToString(project.getUsersWithPermission(Type.ADMIN), ","));
            Permission perm = this.getPermissionObject(project, user, Type.ADMIN);
            page.add("userpermission", perm);

            boolean adminPerm = perm.isPermissionSet(Type.ADMIN);
            if (adminPerm) {
                page.add("admin", true);
            }
            // Set this so we can display execute buttons only to those who have
            // access.
            if (perm.isPermissionSet(Type.EXECUTE) || adminPerm) {
                page.add("exec", true);
            } else {
                page.add("exec", false);
            }
        }
    } catch (AccessControlException e) {
        page.add("errorMsg", e.getMessage());
    }

    int numBytes = 1024;

    // Really sucks if we do a lot of these because it'll eat up memory fast.
    // But it's expected that this won't be a heavily used thing. If it is,
    // then we'll revisit it to make it more stream friendly.
    StringBuffer buffer = new StringBuffer(numBytes);
    page.add("log", buffer.toString());

    page.render();
}

From source file:azkaban.webapp.servlet.ProjectManagerServlet.java

private void handlePermissionPage(HttpServletRequest req, HttpServletResponse resp, Session session)
        throws ServletException {
    Page page = newPage(req, resp, session, "azkaban/webapp/servlet/velocity/permissionspage.vm");
    String projectName = getParam(req, "project");
    User user = session.getUser();/*  w  ww  .  j av a 2 s .c o  m*/

    Project project = null;
    try {
        project = projectManager.getProject(projectName);
        if (project == null) {
            page.add("errorMsg", "Project " + projectName + " not found.");
        } else {
            if (!hasPermission(project, user, Type.READ)) {
                throw new AccessControlException("No permission to view project " + projectName + ".");
            }

            page.add("project", project);
            page.add("username", user.getUserId());
            page.add("admins", Utils.flattenToString(project.getUsersWithPermission(Type.ADMIN), ","));
            Permission perm = this.getPermissionObject(project, user, Type.ADMIN);
            page.add("userpermission", perm);

            if (perm.isPermissionSet(Type.ADMIN)) {
                page.add("admin", true);
            }

            List<Pair<String, Permission>> userPermission = project.getUserPermissions();
            if (userPermission != null && !userPermission.isEmpty()) {
                page.add("permissions", userPermission);
            }

            List<Pair<String, Permission>> groupPermission = project.getGroupPermissions();
            if (groupPermission != null && !groupPermission.isEmpty()) {
                page.add("groupPermissions", groupPermission);
            }

            Set<String> proxyUsers = project.getProxyUsers();
            if (proxyUsers != null && !proxyUsers.isEmpty()) {
                page.add("proxyUsers", proxyUsers);
            }

            if (hasPermission(project, user, Type.ADMIN)) {
                page.add("isAdmin", true);
            }
        }
    } catch (AccessControlException e) {
        page.add("errorMsg", e.getMessage());
    }

    page.render();
}

From source file:azkaban.webapp.servlet.ProjectManagerServlet.java

private void handleProjectPage(HttpServletRequest req, HttpServletResponse resp, Session session)
        throws ServletException {
    Page page = newPage(req, resp, session, "azkaban/webapp/servlet/velocity/projectpage.vm");
    String projectName = getParam(req, "project");

    User user = session.getUser();/*  ww w .  j  a  v a 2  s. c  o m*/
    Project project = null;
    try {
        project = projectManager.getProject(projectName);
        if (project == null) {
            page.add("errorMsg", "Project " + projectName + " not found.");
        } else {
            if (!hasPermission(project, user, Type.READ)) {
                throw new AccessControlException("No permission to view project " + projectName + ".");
            }

            page.add("project", project);
            page.add("admins", Utils.flattenToString(project.getUsersWithPermission(Type.ADMIN), ","));
            Permission perm = this.getPermissionObject(project, user, Type.ADMIN);
            page.add("userpermission", perm);
            page.add("validatorFixPrompt",
                    projectManager.getProps().getBoolean(ValidatorConfigs.VALIDATOR_AUTO_FIX_PROMPT_FLAG_PARAM,
                            ValidatorConfigs.DEFAULT_VALIDATOR_AUTO_FIX_PROMPT_FLAG));
            page.add("validatorFixLabel",
                    projectManager.getProps().get(ValidatorConfigs.VALIDATOR_AUTO_FIX_PROMPT_LABEL_PARAM));
            page.add("validatorFixLink",
                    projectManager.getProps().get(ValidatorConfigs.VALIDATOR_AUTO_FIX_PROMPT_LINK_PARAM));

            boolean adminPerm = perm.isPermissionSet(Type.ADMIN);
            if (adminPerm) {
                page.add("admin", true);
            }
            // Set this so we can display execute buttons only to those who have
            // access.
            if (perm.isPermissionSet(Type.EXECUTE) || adminPerm) {
                page.add("exec", true);
            } else {
                page.add("exec", false);
            }

            List<Flow> flows = project.getFlows();
            if (!flows.isEmpty()) {
                Collections.sort(flows, FLOW_ID_COMPARATOR);
                page.add("flows", flows);
            }
        }
    } catch (AccessControlException e) {
        page.add("errorMsg", e.getMessage());
    }
    page.render();
}

From source file:azkaban.webapp.servlet.ProjectManagerServlet.java

private void handlePropertyPage(HttpServletRequest req, HttpServletResponse resp, Session session)
        throws ServletException {
    Page page = newPage(req, resp, session, "azkaban/webapp/servlet/velocity/propertypage.vm");
    String projectName = getParam(req, "project");
    String flowName = getParam(req, "flow");
    String jobName = getParam(req, "job");
    String propSource = getParam(req, "prop");

    User user = session.getUser();//from   www.  j av  a  2 s  .  c  o  m
    Project project = null;
    Flow flow = null;
    try {
        project = projectManager.getProject(projectName);
        if (project == null) {
            page.add("errorMsg", "Project " + projectName + " not found.");
            page.render();
            return;
        }

        if (!hasPermission(project, user, Type.READ)) {
            throw new AccessControlException("No permission to view project " + projectName + ".");
        }
        page.add("project", project);

        flow = project.getFlow(flowName);
        if (flow == null) {
            page.add("errorMsg", "Flow " + flowName + " not found.");
            page.render();
            return;
        }

        page.add("flowid", flow.getId());
        Node node = flow.getNode(jobName);
        if (node == null) {
            page.add("errorMsg", "Job " + jobName + " not found.");
            page.render();
            return;
        }

        Props prop = projectManager.getProperties(project, propSource);
        page.add("property", propSource);
        page.add("jobid", node.getId());

        // Resolve property dependencies
        ArrayList<String> inheritProps = new ArrayList<String>();
        FlowProps parent = flow.getFlowProps(propSource);
        while (parent.getInheritedSource() != null) {
            inheritProps.add(parent.getInheritedSource());
            parent = flow.getFlowProps(parent.getInheritedSource());
        }
        if (!inheritProps.isEmpty()) {
            page.add("inheritedproperties", inheritProps);
        }

        ArrayList<String> dependingProps = new ArrayList<String>();
        FlowProps child = flow.getFlowProps(flow.getNode(jobName).getPropsSource());
        while (!child.getSource().equals(propSource)) {
            dependingProps.add(child.getSource());
            child = flow.getFlowProps(child.getInheritedSource());
        }
        if (!dependingProps.isEmpty()) {
            page.add("dependingproperties", dependingProps);
        }

        ArrayList<Pair<String, String>> parameters = new ArrayList<Pair<String, String>>();
        // Parameter
        for (String key : prop.getKeySet()) {
            String value = prop.get(key);
            parameters.add(new Pair<String, String>(key, value));
        }

        page.add("parameters", parameters);
    } catch (AccessControlException e) {
        page.add("errorMsg", e.getMessage());
    } catch (ProjectManagerException e) {
        page.add("errorMsg", e.getMessage());
    }

    page.render();
}

From source file:azkaban.webapp.servlet.ProjectManagerServlet.java

private void handleJobPage(HttpServletRequest req, HttpServletResponse resp, Session session)
        throws ServletException {
    Page page = newPage(req, resp, session, "azkaban/webapp/servlet/velocity/jobpage.vm");
    String projectName = getParam(req, "project");
    String flowName = getParam(req, "flow");
    String jobName = getParam(req, "job");

    User user = session.getUser();// www .j  av a2 s . c om
    Project project = null;
    Flow flow = null;
    try {
        project = projectManager.getProject(projectName);
        if (project == null) {
            page.add("errorMsg", "Project " + projectName + " not found.");
            page.render();
            return;
        }
        if (!hasPermission(project, user, Type.READ)) {
            throw new AccessControlException("No permission to view project " + projectName + ".");
        }

        page.add("project", project);
        flow = project.getFlow(flowName);
        if (flow == null) {
            page.add("errorMsg", "Flow " + flowName + " not found.");
            page.render();
            return;
        }

        page.add("flowid", flow.getId());
        Node node = flow.getNode(jobName);
        if (node == null) {
            page.add("errorMsg", "Job " + jobName + " not found.");
            page.render();
            return;
        }

        Props prop = projectManager.getProperties(project, node.getJobSource());
        Props overrideProp = projectManager.getJobOverrideProperty(project, jobName);
        if (overrideProp == null) {
            overrideProp = new Props();
        }
        Props comboProp = new Props(prop);
        for (String key : overrideProp.getKeySet()) {
            comboProp.put(key, overrideProp.get(key));
        }
        page.add("jobid", node.getId());
        page.add("jobtype", node.getType());

        ArrayList<String> dependencies = new ArrayList<String>();
        Set<Edge> inEdges = flow.getInEdges(node.getId());
        if (inEdges != null) {
            for (Edge dependency : inEdges) {
                dependencies.add(dependency.getSourceId());
            }
        }
        if (!dependencies.isEmpty()) {
            page.add("dependencies", dependencies);
        }

        ArrayList<String> dependents = new ArrayList<String>();
        Set<Edge> outEdges = flow.getOutEdges(node.getId());
        if (outEdges != null) {
            for (Edge dependent : outEdges) {
                dependents.add(dependent.getTargetId());
            }
        }
        if (!dependents.isEmpty()) {
            page.add("dependents", dependents);
        }

        // Resolve property dependencies
        ArrayList<String> source = new ArrayList<String>();
        String nodeSource = node.getPropsSource();
        if (nodeSource != null) {
            source.add(nodeSource);
            FlowProps parent = flow.getFlowProps(nodeSource);
            while (parent.getInheritedSource() != null) {
                source.add(parent.getInheritedSource());
                parent = flow.getFlowProps(parent.getInheritedSource());
            }
        }
        if (!source.isEmpty()) {
            page.add("properties", source);
        }

        ArrayList<Pair<String, String>> parameters = new ArrayList<Pair<String, String>>();
        // Parameter
        for (String key : comboProp.getKeySet()) {
            String value = comboProp.get(key);
            parameters.add(new Pair<String, String>(key, value));
        }

        page.add("parameters", parameters);
    } catch (AccessControlException e) {
        page.add("errorMsg", e.getMessage());
    } catch (ProjectManagerException e) {
        page.add("errorMsg", e.getMessage());
    }
    page.render();
}

From source file:catalina.core.StandardServer.java

/**
 * Wait until a proper shutdown command is received, then return.
 *///from   w  ww. j  av a2  s.  co  m
public void await() {

    // Set up a server socket to wait on
    ServerSocket serverSocket = null;
    try {
        serverSocket = new ServerSocket(port, 1, InetAddress.getByName("127.0.0.1"));
    } catch (IOException e) {
        System.err.println("StandardServer.await: create[" + port + "]: " + e);
        e.printStackTrace();
        System.exit(1);
    }

    // Loop waiting for a connection and a valid command
    while (true) {

        // Wait for the next connection
        Socket socket = null;
        InputStream stream = null;
        try {
            socket = serverSocket.accept();
            socket.setSoTimeout(10 * 1000); // Ten seconds
            stream = socket.getInputStream();
        } catch (AccessControlException ace) {
            System.err.println("StandardServer.accept security exception: " + ace.getMessage());
            continue;
        } catch (IOException e) {
            System.err.println("StandardServer.await: accept: " + e);
            e.printStackTrace();
            System.exit(1);
        }

        // Read a set of characters from the socket
        StringBuffer command = new StringBuffer();
        int expected = 1024; // Cut off to avoid DoS attack
        while (expected < shutdown.length()) {
            if (random == null)
                random = new Random(System.currentTimeMillis());
            expected += (random.nextInt() % 1024);
        }
        while (expected > 0) {
            int ch = -1;
            try {
                ch = stream.read();
            } catch (IOException e) {
                System.err.println("StandardServer.await: read: " + e);
                e.printStackTrace();
                ch = -1;
            }
            if (ch < 32) // Control character or EOF terminates loop
                break;
            command.append((char) ch);
            expected--;
        }

        // Close the socket now that we are done with it
        try {
            socket.close();
        } catch (IOException e) {
            ;
        }

        // Match against our command string
        boolean match = command.toString().equals(shutdown);
        if (match) {
            break;
        } else
            System.err.println("StandardServer.await: Invalid command '" + command.toString() + "' received");

    }

    // Close the server socket and return
    try {
        serverSocket.close();
    } catch (IOException e) {
        ;
    }

}

From source file:org.infoglue.igide.helper.http.HTTPTextDocumentListenerEngine.java

private void listen() {
    String errorMessage;//  w w w. j av a2  s  . c  o  m
    boolean error;
    errorMessage = "";
    error = false;
    try {
        Logger.logConsole("Starting listen thread");
        URLConnection urlConn = url.openConnection();
        urlConn.setConnectTimeout(3000);
        urlConn.setRequestProperty("Connection", "Keep-Alive");
        urlConn.setReadTimeout(0);
        urlConn.setDoInput(true);
        urlConn.setDoOutput(true);
        urlConn.setUseCaches(false);
        urlConn.setAllowUserInteraction(false);
        if (urlConn.getHeaderFields().toString().indexOf("401 Unauthorized") > -1) {
            Logger.logConsole("User has no access to the CMS - closing connection");
            throw new AccessControlException("User has no access to the CMS - closing connection");
        }
        String boundary = urlConn.getHeaderField("boundary");
        DataInputStream input = new DataInputStream(urlConn.getInputStream());
        StringBuffer buf = new StringBuffer();
        if (listener != null)
            listener.onConnection(url);
        String str = null;
        while ((str = input.readLine()) != null) {
            if (str.indexOf("XMLNotificationWriter.ping") == -1) {
                if (str.equals(boundary)) {
                    String message = buf.toString();

                    // By checking there is more in the String than the XML declaration we assume the message is valid
                    if (message != null
                            && !message.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").equals("")) {
                        if (listener != null)
                            listener.recieveDocument(buf.toString());
                        else
                            Logger.logConsole((new StringBuilder("NEW DOCUMENT!!\r\n")).append(buf.toString())
                                    .append("\r\n").toString());
                    }
                    buf = new StringBuffer();
                } else {
                    buf.append(str);
                }
            }
        }
        input.close();
    } catch (MalformedURLException me) {
        error = true;
        errorMessage = (new StringBuilder("Faulty CMS-url:")).append(url).toString();
        if (listener != null)
            listener.onException(me);
        else
            System.err.println((new StringBuilder("MalformedURLException: ")).append(me).toString());
        final String errorMessageFinal = errorMessage;
        Logger.logConsole(
                (new StringBuilder("The connection was shut. Was it an error:")).append(error).toString());
        if (!error) {
            if (System.currentTimeMillis() - lastRetry > 20000L) {
                Logger.logConsole("Trying to restart the listener as it was a while since last...");
                lastRetry = System.currentTimeMillis();
                listen();
            }
        } else {
            try {
                if (listener != null)
                    listener.onEndConnection(url);
            } catch (Exception e) {
                Logger.logConsole(
                        (new StringBuilder("Error ending connection:")).append(e.getMessage()).toString());
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    MessageDialog.openError(viewer.getControl().getShell(), "Error",
                            (new StringBuilder()).append(errorMessageFinal).toString());
                }
            });
        }
    } catch (IOException ioe) {
        error = true;
        errorMessage = "Got an I/O-Exception talking to the CMS. Check that it is started and in valid state.";
        Logger.logConsole((new StringBuilder("ioe: ")).append(ioe.getMessage()).toString());
        if (listener != null)
            listener.onException(ioe);
        else
            Logger.logConsole((new StringBuilder("TextDocumentListener cannot connect to: "))
                    .append(url.toExternalForm()).toString());
        final String errorMessageFinal = errorMessage;
        Logger.logConsole(
                (new StringBuilder("The connection was shut. Was it an error:")).append(error).toString());
        if (!error) {
            if (System.currentTimeMillis() - lastRetry > 20000L) {
                Logger.logConsole("Trying to restart the listener as it was a while since last...");
                lastRetry = System.currentTimeMillis();
                listen();
            }
        } else {
            try {
                if (listener != null)
                    listener.onEndConnection(url);
            } catch (Exception e) {
                Logger.logConsole(
                        (new StringBuilder("Error ending connection:")).append(e.getMessage()).toString());
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    MessageDialog.openError(viewer.getControl().getShell(), "Error",
                            (new StringBuilder()).append(errorMessageFinal).toString());
                }
            });
        }
    } catch (AccessControlException ace) {
        error = true;
        errorMessage = "The user you tried to connect with did not have the correct access rights. Check that he/she has roles etc enough to access the CMS";
        Logger.logConsole((new StringBuilder("ioe: ")).append(ace.getMessage()).toString());
        if (listener != null)
            listener.onException(ace);
        else
            Logger.logConsole((new StringBuilder()).append(ace.getMessage()).toString());
        final String errorMessageFinal = errorMessage;
        Logger.logConsole(
                (new StringBuilder("The connection was shut. Was it an error:")).append(error).toString());
        if (!error) {
            if (System.currentTimeMillis() - lastRetry > 20000L) {
                Logger.logConsole("Trying to restart the listener as it was a while since last...");
                lastRetry = System.currentTimeMillis();
                listen();
            }
        } else {
            try {
                if (listener != null)
                    listener.onEndConnection(url);
            } catch (Exception e) {
                Logger.logConsole(
                        (new StringBuilder("Error ending connection:")).append(e.getMessage()).toString());
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    MessageDialog.openError(viewer.getControl().getShell(), "Error",
                            (new StringBuilder()).append(errorMessageFinal).toString());
                }
            });
        }
    } catch (Exception exception) {
        final String errorMessageFinal = errorMessage;
        Logger.logConsole(
                (new StringBuilder("The connection was shut. Was it an error:")).append(error).toString());
        if (!error) {
            if (System.currentTimeMillis() - lastRetry > 20000L) {
                Logger.logConsole("Trying to restart the listener as it was a while since last...");
                lastRetry = System.currentTimeMillis();
                listen();
            }
        } else {
            try {
                if (listener != null)
                    listener.onEndConnection(url);
            } catch (Exception e) {
                Logger.logConsole(
                        (new StringBuilder("Error ending connection:")).append(e.getMessage()).toString());
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    MessageDialog.openError(viewer.getControl().getShell(), "Error",
                            (new StringBuilder()).append(errorMessageFinal).toString());
                }
            });
        }
    } catch (Throwable e) {
        final String errorMessageFinal = errorMessage;
        Logger.logConsole(
                (new StringBuilder("The connection was shut. Was it an error:")).append(error).toString());
        if (!error) {
            if (System.currentTimeMillis() - lastRetry > 20000L) {
                Logger.logConsole("Trying to restart the listener as it was a while since last...");
                lastRetry = System.currentTimeMillis();
                listen();
            }
        } else {
            try {
                if (listener != null)
                    listener.onEndConnection(url);
            } catch (Exception e2) {
                Logger.logConsole(
                        (new StringBuilder("Error ending connection:")).append(e2.getMessage()).toString());
            }
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    MessageDialog.openError(viewer.getControl().getShell(), "Error",
                            (new StringBuilder()).append(errorMessageFinal).toString());
                }
            });
        }
    }
}