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;
}
}
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;
}
}
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;
}
}
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.");
}
}
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);
}
Aggregations