use of org.mortbay.jetty.Connector in project maven-plugins by apache.
the class ProjectInfoReportUtilsTest method startJetty.
private void startJetty(boolean isSSL, boolean withAuth) throws Exception {
jettyServer = new Server();
jettyServer.setStopAtShutdown(true);
Connector connector = (isSSL ? getSSLConnector() : getDefaultConnector());
jettyServer.setConnectors(new Connector[] { connector });
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setResourceBase(getBasedir() + "/target/classes/");
webapp.setServer(jettyServer);
if (withAuth) {
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "user", "admin" });
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
SecurityHandler sh = new SecurityHandler();
sh.setUserRealm(new HashUserRealm("MyRealm", getBasedir() + "/src/test/resources/realm.properties"));
sh.setConstraintMappings(new ConstraintMapping[] { cm });
webapp.addHandler(sh);
}
DefaultHandler defaultHandler = new DefaultHandler();
defaultHandler.setServer(jettyServer);
Handler[] handlers = new Handler[2];
handlers[0] = webapp;
handlers[1] = defaultHandler;
jettyServer.setHandlers(handlers);
jettyServer.start();
port = connector.getLocalPort();
}
use of org.mortbay.jetty.Connector in project voldemort by voldemort.
the class HttpService method stopInner.
@Override
public void stopInner() {
try {
if (httpServer != null) {
httpServer.stop();
for (Connector c : httpServer.getConnectors()) {
c.close();
}
}
if (context != null)
context.destroy();
} catch (Exception e) {
throw new VoldemortException(e);
}
this.httpServer = null;
this.context = null;
}
use of org.mortbay.jetty.Connector in project tomee by apache.
the class JettyHttpServer method init.
@Override
public void init(final Properties props) throws Exception {
final Options options = new Options(props);
port = options.get("port", 8080);
// Create all the Jetty objects but dont' start them
server = new Server();
final Connector connector = new SelectChannelConnector();
connector.setPort(port);
server.setConnectors(new Connector[] { connector });
final ContextHandler context = new ContextHandler();
context.setContextPath("/");
final ServletContext servletContext = context.getServletContext();
server.setHandler(context);
final Handler handler = new AbstractHandler() {
@Override
public void handle(final String target, final HttpServletRequest req, final HttpServletResponse res, final int dispatch) throws IOException, ServletException {
try {
((Request) req).setHandled(true);
final HttpRequest httpRequest = new ServletRequestAdapter(req, res, servletContext);
final HttpResponse httpResponse = new ServletResponseAdapter(res);
JettyHttpServer.this.listener.onMessage(httpRequest, httpResponse);
} catch (IOException | ServletException e) {
throw e;
} catch (Exception e) {
throw new ServletException(e);
}
}
};
final SessionHandler sessionHandler = new SessionHandler();
final SessionManager sessionManager = new HashSessionManager();
sessionManager.setIdManager(new HashSessionIdManager());
sessionHandler.setSessionManager(sessionManager);
sessionHandler.setHandler(handler);
context.setHandler(sessionHandler);
}
use of org.mortbay.jetty.Connector in project gradle by gradle.
the class Jetty6PluginServer method setConnectors.
/**
* @see Jetty6PluginServer#setConnectors(Object[])
*/
public void setConnectors(Object[] connectors) {
if (connectors == null || connectors.length == 0) {
return;
}
for (int i = 0; i < connectors.length; i++) {
Connector connector = (Connector) connectors[i];
LOGGER.debug("Setting Connector: {} on port {}", connector.getClass().getName(), connector.getPort());
this.server.addConnector(connector);
}
}
use of org.mortbay.jetty.Connector 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();
}
Aggregations