Search in sources :

Example 16 with Server

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server in project webtools.servertools by eclipse.

the class Tomcat80Configuration method load.

/**
 * @see TomcatConfiguration#load(IFolder, IProgressMonitor)
 */
public void load(IFolder folder, IProgressMonitor monitor) throws CoreException {
    try {
        monitor = ProgressUtil.getMonitorFor(monitor);
        monitor.beginTask(Messages.loadingTask, 1200);
        // check for catalina.policy to verify that this is a v4.0 config
        IFile file = folder.getFile("catalina.policy");
        if (!file.exists())
            throw new CoreException(new Status(IStatus.WARNING, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadConfiguration, folder.getFullPath().toOSString()), null));
        // load server.xml
        file = folder.getFile("server.xml");
        InputStream in = file.getContents();
        serverFactory = new Factory();
        serverFactory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
        server = (Server) serverFactory.loadDocument(in);
        serverInstance = new ServerInstance(server, null, null);
        monitor.worked(200);
        // load web.xml
        file = folder.getFile("web.xml");
        webAppDocument = new WebAppDocument(file);
        monitor.worked(200);
        // load context.xml
        file = folder.getFile("context.xml");
        if (file.exists()) {
            in = file.getContents();
            contextDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(in));
        } else
            contextDocument = null;
        monitor.worked(200);
        // load tomcat-users.xml
        file = folder.getFile("tomcat-users.xml");
        in = file.getContents();
        tomcatUsersDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(in));
        monitor.worked(200);
        // load catalina.policy
        file = folder.getFile("catalina.policy");
        in = file.getContents();
        policyFile = TomcatVersionHelper.getFileContents(in);
        monitor.worked(200);
        // load catalina.properties
        file = folder.getFile("catalina.properties");
        if (file.exists()) {
            in = file.getContents();
            propertiesFile = TomcatVersionHelper.getFileContents(in);
        } else
            propertiesFile = null;
        monitor.worked(200);
        if (monitor.isCanceled())
            throw new Exception("Cancelled");
        monitor.done();
    } catch (Exception e) {
        Trace.trace(Trace.WARNING, "Could not reload Tomcat v8.0 configuration from: " + folder.getFullPath() + ": " + e.getMessage());
        throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadConfiguration, folder.getFullPath().toOSString()), e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InputSource(org.xml.sax.InputSource) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) CoreException(org.eclipse.core.runtime.CoreException)

Example 17 with Server

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server in project webtools.servertools by eclipse.

the class Tomcat80Configuration method getServerPorts.

/**
 * Returns a list of ServerPorts that this configuration uses.
 *
 * @return java.util.List
 */
public List getServerPorts() {
    List<ServerPort> ports = new ArrayList<ServerPort>();
    // first add server port
    try {
        int port = Integer.parseInt(server.getPort());
        ports.add(new ServerPort("server", Messages.portServer, port, "TCPIP"));
    } catch (Exception e) {
    // ignore
    }
    // add connectors
    try {
        String instanceServiceName = serverInstance.getService().getName();
        int size = server.getServiceCount();
        for (int i = 0; i < size; i++) {
            Service service = server.getService(i);
            int size2 = service.getConnectorCount();
            for (int j = 0; j < size2; j++) {
                Connector connector = service.getConnector(j);
                String name = "HTTP/1.1";
                String protocol2 = "HTTP";
                boolean advanced = true;
                String[] contentTypes = null;
                int port = -1;
                try {
                    port = Integer.parseInt(connector.getPort());
                } catch (Exception e) {
                // ignore
                }
                String protocol = connector.getProtocol();
                if (protocol != null && protocol.length() > 0) {
                    if (protocol.startsWith("HTTP")) {
                        name = protocol;
                    } else if (protocol.startsWith("AJP")) {
                        name = protocol;
                        protocol2 = "AJP";
                    } else {
                        // Get Tomcat equivalent name if protocol handler class specified
                        name = protocolHandlerMap.get(protocol);
                        if (name != null) {
                            // Prepare simple protocol string for ServerPort protocol
                            int index = name.indexOf('/');
                            if (index > 0)
                                protocol2 = name.substring(0, index);
                            else
                                protocol2 = name;
                        } else // Specified protocol is unknown, just use as is
                        {
                            name = protocol;
                            protocol2 = protocol;
                        }
                    }
                }
                if (protocol2.toLowerCase().equals("http"))
                    contentTypes = new String[] { "web", "webservices" };
                String secure = connector.getSecure();
                if (secure != null && secure.length() > 0) {
                    name = "SSL";
                    protocol2 = "SSL";
                } else
                    advanced = false;
                String portId;
                if (instanceServiceName != null && instanceServiceName.equals(service.getName()))
                    portId = Integer.toString(j);
                else
                    portId = i + "/" + j;
                ports.add(new ServerPort(portId, name, port, protocol2, contentTypes, advanced));
            }
        }
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Error getting server ports", e);
    }
    return ports;
}
Also used : Connector(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector) ArrayList(java.util.ArrayList) Service(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service) ServerPort(org.eclipse.wst.server.core.ServerPort) CoreException(org.eclipse.core.runtime.CoreException)

Example 18 with Server

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server in project webtools.servertools by eclipse.

the class Tomcat80Configuration method load.

/**
 * @see TomcatConfiguration#load(IPath, IProgressMonitor)
 */
public void load(IPath path, IProgressMonitor monitor) throws CoreException {
    try {
        monitor = ProgressUtil.getMonitorFor(monitor);
        monitor.beginTask(Messages.loadingTask, 7);
        // check for catalina.policy to verify that this is a v8.0 config
        InputStream in = new FileInputStream(path.append("catalina.policy").toFile());
        in.read();
        in.close();
        monitor.worked(1);
        serverFactory = new Factory();
        serverFactory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
        server = (Server) serverFactory.loadDocument(new FileInputStream(path.append("server.xml").toFile()));
        serverInstance = new ServerInstance(server, null, null);
        monitor.worked(1);
        webAppDocument = new WebAppDocument(path.append("web.xml"));
        monitor.worked(1);
        File file = path.append("context.xml").toFile();
        if (file.exists())
            contextDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(new FileInputStream(file)));
        monitor.worked(1);
        tomcatUsersDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(new FileInputStream(path.append("tomcat-users.xml").toFile())));
        monitor.worked(1);
        // load policy file
        policyFile = TomcatVersionHelper.getFileContents(new FileInputStream(path.append("catalina.policy").toFile()));
        monitor.worked(1);
        // load properties file
        file = path.append("catalina.properties").toFile();
        if (file.exists())
            propertiesFile = TomcatVersionHelper.getFileContents(new FileInputStream(file));
        else
            propertiesFile = null;
        monitor.worked(1);
        if (monitor.isCanceled())
            return;
        monitor.done();
    } catch (Exception e) {
        Trace.trace(Trace.WARNING, "Could not load Tomcat v8.0 configuration from " + path.toOSString() + ": " + e.getMessage());
        throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadConfiguration, path.toOSString()), e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InputSource(org.xml.sax.InputSource) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileInputStream(java.io.FileInputStream) CoreException(org.eclipse.core.runtime.CoreException)

Example 19 with Server

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server in project webtools.servertools by eclipse.

the class Tomcat90Configuration method load.

/**
 * @see TomcatConfiguration#load(IFolder, IProgressMonitor)
 */
public void load(IFolder folder, IProgressMonitor monitor) throws CoreException {
    try {
        monitor = ProgressUtil.getMonitorFor(monitor);
        monitor.beginTask(Messages.loadingTask, 1200);
        // check for catalina.policy to verify that this is a v4.0 config
        IFile file = folder.getFile("catalina.policy");
        if (!file.exists())
            throw new CoreException(new Status(IStatus.WARNING, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadConfiguration, folder.getFullPath().toOSString()), null));
        // load server.xml
        file = folder.getFile("server.xml");
        InputStream in = file.getContents();
        serverFactory = new Factory();
        serverFactory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
        server = (Server) serverFactory.loadDocument(in);
        serverInstance = new ServerInstance(server, null, null);
        monitor.worked(200);
        // load web.xml
        file = folder.getFile("web.xml");
        webAppDocument = new WebAppDocument(file);
        monitor.worked(200);
        // load context.xml
        file = folder.getFile("context.xml");
        if (file.exists()) {
            in = file.getContents();
            contextDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(in));
        } else
            contextDocument = null;
        monitor.worked(200);
        // load tomcat-users.xml
        file = folder.getFile("tomcat-users.xml");
        in = file.getContents();
        tomcatUsersDocument = XMLUtil.getDocumentBuilder().parse(new InputSource(in));
        monitor.worked(200);
        // load catalina.policy
        file = folder.getFile("catalina.policy");
        in = file.getContents();
        policyFile = TomcatVersionHelper.getFileContents(in);
        monitor.worked(200);
        // load catalina.properties
        file = folder.getFile("catalina.properties");
        if (file.exists()) {
            in = file.getContents();
            propertiesFile = TomcatVersionHelper.getFileContents(in);
        } else
            propertiesFile = null;
        monitor.worked(200);
        if (monitor.isCanceled())
            throw new Exception("Cancelled");
        monitor.done();
    } catch (Exception e) {
        Trace.trace(Trace.WARNING, "Could not reload Tomcat v9.0 configuration from: " + folder.getFullPath() + ": " + e.getMessage());
        throw new CoreException(new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCouldNotLoadConfiguration, folder.getFullPath().toOSString()), e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) InputSource(org.xml.sax.InputSource) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) CoreException(org.eclipse.core.runtime.CoreException)

Example 20 with Server

use of org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server in project webtools.servertools by eclipse.

the class Tomcat90Configuration method getWebModules.

/**
 * Return a list of the web modules in this server.
 * @return java.util.List
 */
public List getWebModules() {
    List<WebModule> list = new ArrayList<WebModule>();
    try {
        Context[] contexts = serverInstance.getContexts();
        if (contexts != null) {
            for (int i = 0; i < contexts.length; i++) {
                Context context = contexts[i];
                String reload = context.getReloadable();
                if (reload == null)
                    reload = "false";
                WebModule module = new WebModule(context.getPath(), context.getDocBase(), context.getSource(), reload.equalsIgnoreCase("true") ? true : false);
                list.add(module);
            }
        }
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Error getting project refs", e);
    }
    return list;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)48 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)32 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)26 IStatus (org.eclipse.core.runtime.IStatus)25 Status (org.eclipse.core.runtime.Status)24 FileInputStream (java.io.FileInputStream)23 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)23 Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)22 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)22 InputStream (java.io.InputStream)19 ByteArrayInputStream (java.io.ByteArrayInputStream)18 ArrayList (java.util.ArrayList)18 InputSource (org.xml.sax.InputSource)18 IFile (org.eclipse.core.resources.IFile)17 Server (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server)15 File (java.io.File)13 IPath (org.eclipse.core.runtime.IPath)9 ServerPort (org.eclipse.wst.server.core.ServerPort)9 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6