Search in sources :

Example 11 with WebAppContext

use of org.mortbay.jetty.webapp.WebAppContext in project nhin-d by DirectProject.

the class ServiceRunner method startServices.

public static synchronized void startServices() throws Exception {
    if (server == null) {
        /*
			 * Setup the configuration service server
			 */
        server = new Server();
        SocketConnector connector = new SocketConnector();
        HTTPPort = AvailablePortFinder.getNextAvailable(1024);
        connector.setPort(HTTPPort);
        WebAppContext context = new WebAppContext("src/test/resources/webapp", "/");
        server.setSendServerVersion(false);
        server.addConnector(connector);
        server.addHandler(context);
        server.start();
        txsServiceURL = "http://localhost:" + HTTPPort + "/";
    }
}
Also used : WebAppContext(org.mortbay.jetty.webapp.WebAppContext) Server(org.mortbay.jetty.Server) SocketConnector(org.mortbay.jetty.bio.SocketConnector)

Example 12 with WebAppContext

use of org.mortbay.jetty.webapp.WebAppContext in project nhin-d by DirectProject.

the class MonitorServiceRunner method startMonitorService.

public static synchronized void startMonitorService() throws Exception {
    if (server == null) {
        /*
			 * Setup the configuration service server
			 */
        server = new Server();
        SocketConnector connector = new SocketConnector();
        HTTPPort = AvailablePortFinder.getNextAvailable(8090);
        connector.setPort(HTTPPort);
        // certificate service
        WebAppContext context = new WebAppContext("src/test/resources/webapp-liverun", "/");
        server.setSendServerVersion(false);
        server.addConnector(connector);
        server.addHandler(context);
        server.start();
        serviceURL = "http://localhost:" + HTTPPort + "/";
    }
}
Also used : WebAppContext(org.mortbay.jetty.webapp.WebAppContext) Server(org.mortbay.jetty.Server) SocketConnector(org.mortbay.jetty.bio.SocketConnector)

Example 13 with WebAppContext

use of org.mortbay.jetty.webapp.WebAppContext in project roboguice by roboguice.

the class Main method main.

public static void main(String[] args) throws Exception {
    Server server = new Server();
    Connector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.setConnectors(new Connector[] { connector });
    WebAppContext webapp = new WebAppContext("./root", "/example");
    server.addHandler(webapp);
    server.start();
    server.join();
}
Also used : Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) Server(org.mortbay.jetty.Server)

Example 14 with WebAppContext

use of org.mortbay.jetty.webapp.WebAppContext in project maven-plugins by apache.

the class SiteRunMojo method createWebApplication.

private WebAppContext createWebApplication() throws MojoExecutionException {
    File webXml = new File(tempWebappDirectory, "WEB-INF/web.xml");
    webXml.getParentFile().mkdirs();
    InputStream inStream = null;
    FileOutputStream outStream = null;
    try {
        inStream = getClass().getResourceAsStream("/run/web.xml");
        outStream = new FileOutputStream(webXml);
        IOUtil.copy(inStream, outStream);
        outStream.close();
        outStream = null;
        inStream.close();
        inStream = null;
    } catch (FileNotFoundException e) {
        throw new MojoExecutionException("Unable to construct temporary webapp for running site", e);
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to construct temporary webapp for running site", e);
    } finally {
        IOUtil.close(outStream);
        IOUtil.close(inStream);
    }
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setResourceBase(tempWebappDirectory.getAbsolutePath());
    webapp.setAttribute(DoxiaFilter.SITE_RENDERER_KEY, siteRenderer);
    webapp.getInitParams().put("org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false");
    // For external reports
    project.getReporting().setOutputDirectory(tempWebappDirectory.getAbsolutePath());
    for (MavenReportExecution mavenReportExecution : getReports()) {
        mavenReportExecution.getMavenReport().setReportOutputDirectory(tempWebappDirectory);
    }
    // TODO: is it sane to call getReports() method a second time?
    List<MavenReportExecution> reports = getReports();
    List<Locale> localesList = getLocales();
    webapp.setAttribute(DoxiaFilter.LOCALES_LIST_KEY, localesList);
    // Default is first in the list
    Locale defaultLocale = localesList.get(0);
    Locale.setDefault(defaultLocale);
    try {
        Map<String, DoxiaBean> i18nDoxiaContexts = new HashMap<String, DoxiaBean>();
        for (Locale locale : localesList) {
            SiteRenderingContext i18nContext = createSiteRenderingContext(locale);
            i18nContext.setInputEncoding(getInputEncoding());
            i18nContext.setOutputEncoding(getOutputEncoding());
            SiteRenderingContext i18nGeneratedSiteContext = createSiteRenderingContext(locale);
            i18nGeneratedSiteContext.setInputEncoding(getInputEncoding());
            i18nGeneratedSiteContext.setOutputEncoding(getOutputEncoding());
            i18nGeneratedSiteContext.getSiteDirectories().clear();
            Map<String, DocumentRenderer> i18nDocuments = locateDocuments(i18nContext, reports, locale);
            DoxiaBean doxiaBean;
            if (defaultLocale.equals(locale)) {
                i18nGeneratedSiteContext.addSiteDirectory(generatedSiteDirectory);
                doxiaBean = new DoxiaBean(i18nContext, i18nDocuments, i18nGeneratedSiteContext);
            } else {
                i18nGeneratedSiteContext.addSiteDirectory(new File(generatedSiteDirectory, locale.getLanguage()));
                doxiaBean = new DoxiaBean(i18nContext, i18nDocuments, i18nGeneratedSiteContext);
            }
            i18nDoxiaContexts.put(locale.getLanguage(), doxiaBean);
            if (defaultLocale.equals(locale)) {
                i18nDoxiaContexts.put("default", doxiaBean);
            }
            if (defaultLocale.equals(locale)) {
                siteRenderer.copyResources(i18nContext, tempWebappDirectory);
            } else {
                siteRenderer.copyResources(i18nContext, new File(tempWebappDirectory, locale.getLanguage()));
            }
        }
        webapp.setAttribute(DoxiaFilter.I18N_DOXIA_CONTEXTS_KEY, i18nDoxiaContexts);
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to set up webapp", e);
    }
    return webapp;
}
Also used : Locale(java.util.Locale) MavenReportExecution(org.apache.maven.reporting.exec.MavenReportExecution) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) DocumentRenderer(org.apache.maven.doxia.siterenderer.DocumentRenderer) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) SiteRenderingContext(org.apache.maven.doxia.siterenderer.SiteRenderingContext) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 15 with WebAppContext

use of org.mortbay.jetty.webapp.WebAppContext in project maven-plugins by apache.

the class SiteRunMojo method execute.

/**
     * @see org.apache.maven.plugin.AbstractMojo#execute()
     */
public void execute() throws MojoExecutionException, MojoFailureException {
    checkInputEncoding();
    Server server = new Server();
    server.setStopAtShutdown(true);
    Connector defaultConnector = getDefaultConnector();
    server.setConnectors(new Connector[] { defaultConnector });
    WebAppContext webapp = createWebApplication();
    webapp.setServer(server);
    DefaultHandler defaultHandler = new DefaultHandler();
    defaultHandler.setServer(server);
    Handler[] handlers = new Handler[2];
    handlers[0] = webapp;
    handlers[1] = defaultHandler;
    server.setHandlers(handlers);
    getLog().info("Starting Jetty on http://localhost:" + port + "/");
    try {
        server.start();
    } catch (Exception e) {
        throw new MojoExecutionException("Error executing Jetty: " + e.getMessage(), e);
    }
    // Watch it
    try {
        server.getThreadPool().join();
    } catch (InterruptedException e) {
        getLog().warn("Jetty was interrupted", e);
    }
}
Also used : Connector(org.mortbay.jetty.Connector) SelectChannelConnector(org.mortbay.jetty.nio.SelectChannelConnector) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) Server(org.mortbay.jetty.Server) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Handler(org.mortbay.jetty.Handler) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DefaultHandler(org.mortbay.jetty.handler.DefaultHandler)

Aggregations

WebAppContext (org.mortbay.jetty.webapp.WebAppContext)17 Server (org.mortbay.jetty.Server)14 SocketConnector (org.mortbay.jetty.bio.SocketConnector)11 Connector (org.mortbay.jetty.Connector)5 SelectChannelConnector (org.mortbay.jetty.nio.SelectChannelConnector)4 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Handler (org.mortbay.jetty.Handler)2 DefaultHandler (org.mortbay.jetty.handler.DefaultHandler)2 SecurityHandler (org.mortbay.jetty.security.SecurityHandler)2 WebXmlConfiguration (org.mortbay.jetty.webapp.WebXmlConfiguration)2 ThreadPoolExecutorAdapter (com.google.util.threads.ThreadPoolExecutorAdapter)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 BindException (java.net.BindException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1