use of org.eclipse.jetty.server.NetworkTrafficServerConnector in project knime-core by knime.
the class HelpviewPlugin method start.
/**
* This method is called upon plug-in activation.
*
* {@inheritDoc}
*/
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
// initialize jetty's logging system
if (System.getProperty("org.mortbay.log.class") == null) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(JettyLogger.class.getClassLoader());
System.setProperty("org.mortbay.log.class", JettyLogger.class.getName());
Log.getLog();
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
// start an embedded webserver for serving bundle-local or node-local
// files in the node descriptions
m_server = new Server();
NetworkTrafficServerConnector connector = new NetworkTrafficServerConnector(m_server);
connector.setPort(PORT);
try {
connector.setHost(InetAddress.getLocalHost().getHostAddress());
} catch (UnknownHostException ex) {
// sometimes the above returns this exception; yeah, strange
try {
connector.setHost(InetAddress.getByName("localhost").getHostAddress());
} catch (UnknownHostException ex1) {
logger.error("Cannot start embedded webserver: " + ex.getMessage(), ex);
}
}
m_server.addConnector(connector);
m_server.setHandler(FileHandler.instance);
try {
m_server.start();
} catch (BindException ex) {
logger.error("Cannot start embedded webserver: " + ex.getMessage(), ex);
// ignore exception otherwise the plugin is not initialized
}
}
Aggregations