in jelly-tags/jetty/src/main/java/org/apache/commons/jelly/tags/jetty/JettyHttpServerTag.java [109:177]
public void doTag(XMLOutput xmlOutput) throws JellyTagException {
try {
URL logFileURL = getContext().getResource(getLogFileName());
_logSink.setFilename(logFileURL.getPath());
_logSink.start();
} catch (Exception ex ) {
log.error(ex.getLocalizedMessage());
}
// allow nested tags first, e.g body
invokeBody(xmlOutput);
try {
// if no listeners create a default port listener
if (_server.getListeners().length == 0) {
SocketListener listener=new SocketListener();
listener.setPort(DEFAULT_PORT);
listener.setHost(DEFAULT_HOST);
_server.addListener(listener);
}
// if no context/s create a default context
if (_server.getContexts().length == 0) {
log.info("Creating a default context");
// Create a context
HttpContext context = _server.getContext(DEFAULT_HOST,
DEFAULT_CONTEXT_PATH);
// Serve static content from the context
URL baseResourceURL = getContext().getResource(DEFAULT_RESOURCE_BASE);
Resource resource = Resource.newResource(baseResourceURL);
context.setBaseResource(resource);
_server.addContext(context);
}
}
catch (UnknownHostException e) {
throw new JellyTagException(e);
}
catch (IOException e) {
throw new JellyTagException(e);
}
// check that all the contexts have at least one handler
// if not then add a default resource handler and a not found handler
HttpContext[] allContexts = _server.getContexts();
for (int i = 0; i < allContexts.length; i++) {
HttpContext currContext = allContexts[i];
if (currContext.getHandlers().length == 0) {
log.info("Adding resource and not found handlers to context:" +
currContext.getContextPath());
currContext.addHandler(new ResourceHandler());
currContext.addHandler(new NotFoundHandler());
}
}
// Start the http server
try {
_server.start();
}
catch (MultiException e) {
throw new JellyTagException(e);
}
// set variable to value if required
if (getVar() != null) {
getContext().setVariable(getVar(), _server);
}
}