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 + "/";
}
}
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 + "/";
}
}
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();
}
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;
}
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);
}
}
Aggregations