Search in sources :

Example 1 with Servlet

use of org.eclipse.jst.server.core.Servlet in project webtools.servertools by eclipse.

the class GenericServerLaunchableAdapterDelegate method prepareHttpLaunchable.

/**
 * @param moduleObject
 * @param delegate
 * @return object
 */
private Object prepareHttpLaunchable(IModuleArtifact moduleObject, ServerDelegate delegate) {
    try {
        URL url = ((IURLProvider) delegate).getModuleRootURL(moduleObject.getModule());
        // $NON-NLS-1$
        Trace.trace("root: " + url);
        if (moduleObject instanceof Servlet) {
            Servlet servlet = (Servlet) moduleObject;
            if (servlet.getAlias() != null) {
                String path = servlet.getAlias();
                if (// $NON-NLS-1$
                path.startsWith("/"))
                    path = path.substring(1);
                url = new URL(url, path);
            } else
                // $NON-NLS-1$
                url = new URL(url, "servlet/" + servlet.getServletClassName());
        } else if (moduleObject instanceof WebResource) {
            WebResource resource = (WebResource) moduleObject;
            String path = resource.getPath().toString();
            // $NON-NLS-1$
            Trace.trace("path: " + path);
            if (// $NON-NLS-1$
            path != null && path.startsWith("/") && path.length() > 0)
                path = path.substring(1);
            if (path != null && path.length() > 0)
                url = new URL(url, path);
        }
        return new HttpLaunchable(url);
    } catch (Exception e) {
        // $NON-NLS-1$
        Trace.trace("Error getting URL for " + moduleObject, e);
        return null;
    }
}
Also used : HttpLaunchable(org.eclipse.wst.server.core.util.HttpLaunchable) Servlet(org.eclipse.jst.server.core.Servlet) WebResource(org.eclipse.wst.server.core.util.WebResource) URL(java.net.URL)

Example 2 with Servlet

use of org.eclipse.jst.server.core.Servlet in project webtools.servertools by eclipse.

the class TomcatLaunchableAdapterDelegate method getLaunchable.

/*
	 * @see LaunchableAdapterDelegate#getLaunchable(IServer, IModuleArtifact)
	 */
public Object getLaunchable(IServer server, IModuleArtifact moduleObject) {
    Trace.trace(Trace.FINER, "TomcatLaunchableAdapter " + server + "-" + moduleObject);
    if (server.getAdapter(TomcatServer.class) == null)
        return null;
    if (!(moduleObject instanceof Servlet) && !(moduleObject instanceof WebResource))
        return null;
    if (moduleObject.getModule().loadAdapter(IWebModule.class, null) == null)
        return null;
    try {
        URL url = ((IURLProvider) server.loadAdapter(IURLProvider.class, null)).getModuleRootURL(moduleObject.getModule());
        Trace.trace(Trace.FINER, "root: " + url);
        if (moduleObject instanceof Servlet) {
            Servlet servlet = (Servlet) moduleObject;
            if (servlet.getAlias() != null) {
                String path = servlet.getAlias();
                if (path.startsWith("/"))
                    path = path.substring(1);
                url = new URL(url, path);
            } else
                url = new URL(url, "servlet/" + servlet.getServletClassName());
        } else if (moduleObject instanceof WebResource) {
            WebResource resource = (WebResource) moduleObject;
            String path = resource.getPath().toString();
            Trace.trace(Trace.FINER, "path: " + path);
            if (path != null && path.startsWith("/") && path.length() > 0)
                path = path.substring(1);
            if (path != null && path.length() > 0)
                url = new URL(url, path);
        }
        return new HttpLaunchable(url);
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Error getting URL for " + moduleObject, e);
        return null;
    }
}
Also used : HttpLaunchable(org.eclipse.wst.server.core.util.HttpLaunchable) Servlet(org.eclipse.jst.server.core.Servlet) WebResource(org.eclipse.wst.server.core.util.WebResource) IWebModule(org.eclipse.jst.server.core.IWebModule) URL(java.net.URL)

Aggregations

URL (java.net.URL)2 Servlet (org.eclipse.jst.server.core.Servlet)2 HttpLaunchable (org.eclipse.wst.server.core.util.HttpLaunchable)2 WebResource (org.eclipse.wst.server.core.util.WebResource)2 IWebModule (org.eclipse.jst.server.core.IWebModule)1