Search in sources :

Example 26 with ServerPort

use of org.eclipse.wst.server.core.ServerPort in project webtools.servertools by eclipse.

the class PreviewServerBehaviour method setupLaunch.

/**
 * Setup for starting the server.
 *
 * @param launch ILaunch
 * @param launchMode String
 * @param monitor IProgressMonitor
 * @throws CoreException if anything goes wrong
 */
protected void setupLaunch(ILaunch launch, String launchMode, IProgressMonitor monitor) throws CoreException {
    // check that ports are free
    ServerPort[] ports = getPreviewServer().getServerPorts();
    int port = ports[0].getPort();
    if (SocketUtil.isPortInUse(port, 5))
        throw new CoreException(new Status(IStatus.ERROR, PreviewPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPortInUse, new String[] { port + "", getServer().getName() }), null));
    // generate preview config file
    XMLMemento memento = XMLMemento.createWriteRoot("server");
    memento.putInteger("port", port);
    IModule[] modules = getServer().getModules();
    for (IModule module : modules) {
        IMemento mod = memento.createChild("module");
        mod.putString("name", module.getName());
        String type = module.getModuleType().getId();
        if ("wst.web".equals(type)) {
            IStaticWeb staticWeb = (IStaticWeb) module.loadAdapter(IStaticWeb.class, null);
            if (staticWeb != null)
                mod.putString("context", staticWeb.getContextRoot());
            mod.putString("type", "static");
        } else if ("jst.web".equals(type)) {
            IWebModule webModule = (IWebModule) module.loadAdapter(IWebModule.class, null);
            if (webModule != null)
                mod.putString("context", webModule.getContextRoot());
            mod.putString("type", "j2ee");
        }
        mod.putString("path", getModulePublishDirectory(module).toPortableString());
    }
    try {
        memento.saveToFile(getTempDirectory().append("preview.xml").toOSString());
    } catch (IOException e) {
        Trace.trace(Trace.SEVERE, "Could not write preview config", e);
        throw new CoreException(new Status(IStatus.ERROR, PreviewPlugin.PLUGIN_ID, 0, "Could not write preview configuration", null));
    }
    setServerRestartState(false);
    setServerState(IServer.STATE_STARTING);
    setMode(launchMode);
    // ping server to check for startup
    try {
        String url = "http://localhost";
        if (port != 80)
            url += ":" + port;
        ping = new PingThread(getServer(), url, this);
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Can't ping for Tomcat startup.");
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IModule(org.eclipse.wst.server.core.IModule) IWebModule(org.eclipse.jst.server.core.IWebModule) IOException(java.io.IOException) IMemento(org.eclipse.jst.server.preview.adapter.internal.IMemento) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IStaticWeb(org.eclipse.wst.server.core.util.IStaticWeb) CoreException(org.eclipse.core.runtime.CoreException) XMLMemento(org.eclipse.jst.server.preview.adapter.internal.XMLMemento) ServerPort(org.eclipse.wst.server.core.ServerPort)

Aggregations

ServerPort (org.eclipse.wst.server.core.ServerPort)26 CoreException (org.eclipse.core.runtime.CoreException)14 ArrayList (java.util.ArrayList)10 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)9 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)9 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 Iterator (java.util.Iterator)3 TableItem (org.eclipse.swt.widgets.TableItem)3 IOException (java.io.IOException)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 IModule (org.eclipse.wst.server.core.IModule)2 IStaticWeb (org.eclipse.wst.server.core.util.IStaticWeb)2 Element (org.w3c.dom.Element)2 List (java.util.List)1 IWebModule (org.eclipse.jst.server.core.IWebModule)1 Port (org.eclipse.jst.server.generic.servertype.definition.Port)1 IMemento (org.eclipse.jst.server.preview.adapter.internal.IMemento)1 XMLMemento (org.eclipse.jst.server.preview.adapter.internal.XMLMemento)1 ITomcatConfigurationWorkingCopy (org.eclipse.jst.server.tomcat.core.internal.ITomcatConfigurationWorkingCopy)1