Search in sources :

Example 1 with IStaticWeb

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

the class PreviewServer method getModuleRootURL.

/**
 * Return the root URL of this module.
 *
 * @param module a module
 * @return java.net.URL
 */
public URL getModuleRootURL(IModule module) {
    try {
        String base = "http://localhost";
        int port = getPort();
        URL url = null;
        if (port == 80)
            url = new URL(base + "/");
        else
            url = new URL(base + ":" + port + "/");
        String type = module.getModuleType().getId();
        if ("wst.web".equals(type)) {
            IStaticWeb staticWeb = (IStaticWeb) module.loadAdapter(IStaticWeb.class, null);
            return new URL(url, staticWeb.getContextRoot());
        } else if ("jst.web".equals(type)) {
            IWebModule webModule = (IWebModule) module.loadAdapter(IWebModule.class, null);
            return new URL(url, webModule.getContextRoot());
        }
        return url;
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Could not get root URL", e);
        return null;
    }
}
Also used : IStaticWeb(org.eclipse.wst.server.core.util.IStaticWeb) IWebModule(org.eclipse.jst.server.core.IWebModule) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with IStaticWeb

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

the class PreviewServer method getModuleRootURL.

/**
 * Return the root URL of this module.
 *
 * @param module a module
 * @return java.net.URL
 */
public URL getModuleRootURL(IModule module) {
    try {
        String base = "http://localhost";
        int port = getPort();
        URL url = null;
        if (port == 80)
            url = new URL(base + "/");
        else
            url = new URL(base + ":" + port + "/");
        String type = module.getModuleType().getId();
        if ("wst.web".equals(type)) {
            IStaticWeb staticWeb = (IStaticWeb) module.loadAdapter(IStaticWeb.class, null);
            return new URL(url, staticWeb.getContextRoot());
        }
        return url;
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Could not get root URL", e);
        return null;
    }
}
Also used : IStaticWeb(org.eclipse.wst.server.core.util.IStaticWeb) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException)

Example 3 with IStaticWeb

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

the class HttpServer method getModuleRootURL.

/**
 * Return the root URL of this module.
 *
 * @param module a module
 * @return the root URL
 */
public URL getModuleRootURL(IModule module) {
    try {
        String base = "http://" + getURLHost(getServer().getHost());
        if (base.equals(""))
            base = "http://" + getURLHost(getServer().getHost());
        int port = getPort();
        URL url = null;
        if (port == 80)
            url = new URL(base + "/");
        else
            url = new URL(base + ":" + port + "/");
        String prefix = getURLPrefix();
        if (prefix != null && prefix.length() > 0)
            url = new URL(url, prefix + "/");
        IStaticWeb staticWeb = (IStaticWeb) module.loadAdapter(IStaticWeb.class, null);
        return new URL(url, staticWeb.getContextRoot());
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Could not get root URL", e);
        return null;
    }
}
Also used : IStaticWeb(org.eclipse.wst.server.core.util.IStaticWeb) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException)

Example 4 with IStaticWeb

use of org.eclipse.wst.server.core.util.IStaticWeb 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");
        }
        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) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IModule(org.eclipse.wst.server.core.IModule) IOException(java.io.IOException) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) IStaticWeb(org.eclipse.wst.server.core.util.IStaticWeb) CoreException(org.eclipse.core.runtime.CoreException) ServerPort(org.eclipse.wst.server.core.ServerPort)

Example 5 with IStaticWeb

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

the class HttpServerBehaviour method publishModule.

/*
	 * Publishes the given module to the server.
	 */
protected void publishModule(int kind, int deltaKind, IModule[] moduleTree, IProgressMonitor monitor) throws CoreException {
    if (!getHttpServer().isPublishing())
        return;
    String contextRoot = null;
    IModule module = moduleTree[moduleTree.length - 1];
    IStaticWeb sw = (IStaticWeb) module.loadAdapter(IStaticWeb.class, monitor);
    if (sw != null)
        contextRoot = sw.getContextRoot();
    else
        contextRoot = module.getName();
    IPath to = getServer().getRuntime().getLocation();
    File temp = null;
    try {
        if (to.removeLastSegments(1).toFile().exists())
            temp = to.removeLastSegments(1).append("temp").toFile();
    } catch (Exception e) {
    // ignore - use null temp folder
    }
    if (contextRoot != null && !contextRoot.equals(""))
        to = to.append(contextRoot);
    IModuleResource[] res = getResources(moduleTree);
    PublishHelper pubHelper = new PublishHelper(temp);
    IStatus[] status = pubHelper.publishSmart(res, to, monitor);
    if (temp.exists())
        temp.delete();
    throwException(status);
    setModulePublishState(moduleTree, IServer.PUBLISH_STATE_NONE);
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModule(org.eclipse.wst.server.core.IModule) IStatus(org.eclipse.core.runtime.IStatus) IStaticWeb(org.eclipse.wst.server.core.util.IStaticWeb) IPath(org.eclipse.core.runtime.IPath) PublishHelper(org.eclipse.wst.server.core.util.PublishHelper) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)6 IStaticWeb (org.eclipse.wst.server.core.util.IStaticWeb)6 URL (java.net.URL)3 IStatus (org.eclipse.core.runtime.IStatus)3 IModule (org.eclipse.wst.server.core.IModule)3 IOException (java.io.IOException)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 Status (org.eclipse.core.runtime.Status)2 IWebModule (org.eclipse.jst.server.core.IWebModule)2 ServerPort (org.eclipse.wst.server.core.ServerPort)2 File (java.io.File)1 IPath (org.eclipse.core.runtime.IPath)1 IMemento (org.eclipse.jst.server.preview.adapter.internal.IMemento)1 XMLMemento (org.eclipse.jst.server.preview.adapter.internal.XMLMemento)1 IModuleResource (org.eclipse.wst.server.core.model.IModuleResource)1 PublishHelper (org.eclipse.wst.server.core.util.PublishHelper)1