org.mortbay.jetty.bio.SocketConnector Java Examples

The following examples show how to use org.mortbay.jetty.bio.SocketConnector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpServerImpl.java    From reef with Apache License 2.0 6 votes vote down vote up
private Server tryPort(final int portNumber) throws Exception {
  Server srv = new Server();
  final Connector connector = new SocketConnector();
  connector.setHost(this.hostAddress);
  connector.setPort(portNumber);
  srv.addConnector(connector);
  try {
    srv.start();
    LOG.log(Level.INFO, "Jetty Server started with port: {0}", portNumber);
  } catch (final BindException ex) {
    srv = null;
    LOG.log(Level.FINEST, "Cannot use host: {0},port: {1}. Will try another",
        new Object[] {this.hostAddress, portNumber});
  }
  return srv;
}
 
Example #2
Source File: LocalServerWebDriverContainerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Before
public void setupLocalServer() throws Exception {

    // Set up a local Jetty HTTP server
    Server server = new Server();
    server.addConnector(new SocketConnector());
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase("src/test/resources/server");
    server.addHandler(resourceHandler);
    server.start();

    // The server will have a random port assigned, so capture that
    localPort = server.getConnectors()[0].getLocalPort();
}
 
Example #3
Source File: TestProtocolHttpClient.java    From anthelion with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the Jetty server at a specified port.
 *
 * @param  portno     Port number.
 * @throws Exception  When an error occurs.
 */
private void startServer(int portno) throws Exception {
  port = portno;
  SocketConnector listener = new SocketConnector();
  listener.setHost("127.0.0.1");
  listener.setPort(port);
  server.addConnector(listener);
  server.start();
}
 
Example #4
Source File: CrawlDBTestUtil.java    From anthelion with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new JettyServer with one static root context
 * 
 * @param port port to listen to
 * @param staticContent folder where static content lives
 * @throws UnknownHostException 
 */
public static Server getServer(int port, String staticContent) throws UnknownHostException{
  Server webServer = new org.mortbay.jetty.Server();
  SocketConnector listener = new SocketConnector();
  listener.setPort(port);
  listener.setHost("127.0.0.1");
  webServer.addConnector(listener);
  ContextHandler staticContext = new ContextHandler();
  staticContext.setContextPath("/");
  staticContext.setResourceBase(staticContent);
  staticContext.addHandler(new ResourceHandler());
  webServer.addHandler(staticContext);
  return webServer;
}
 
Example #5
Source File: ServletTestContext.java    From oink with Apache License 2.0 5 votes vote down vote up
/**
 * Start embedded server.
 * @throws Exception
 */
public void startServer() throws Exception {
    SocketConnector connector = new SocketConnector();
    connector.setPort(0);
    connector.setHost("127.0.0.1");
    webServer.addConnector(connector);

    webServer.start();
    port = connector.getLocalPort();
    host = connector.getHost();
}
 
Example #6
Source File: TestProtocolHttpClient.java    From nutch-htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the Jetty server at a specified port.
 *
 * @param  portno     Port number.
 * @throws Exception  When an error occurs.
 */
private void startServer(int portno) throws Exception {
  port = portno;
  SocketConnector listener = new SocketConnector();
  listener.setHost("127.0.0.1");
  listener.setPort(port);
  server.addConnector(listener);
  server.start();
}
 
Example #7
Source File: CrawlDBTestUtil.java    From nutch-htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new JettyServer with one static root context
 * 
 * @param port port to listen to
 * @param staticContent folder where static content lives
 * @throws UnknownHostException 
 */
public static Server getServer(int port, String staticContent) throws UnknownHostException{
  Server webServer = new org.mortbay.jetty.Server();
  SocketConnector listener = new SocketConnector();
  listener.setPort(port);
  listener.setHost("127.0.0.1");
  webServer.addConnector(listener);
  ContextHandler staticContext = new ContextHandler();
  staticContext.setContextPath("/");
  staticContext.setResourceBase(staticContent);
  staticContext.addHandler(new ResourceHandler());
  webServer.addHandler(staticContext);
  return webServer;
}
 
Example #8
Source File: TestServer.java    From nomulus with Apache License 2.0 4 votes vote down vote up
private static Connector createConnector(HostAndPort address) {
  SocketConnector connector = new SocketConnector();
  connector.setHost(address.getHost());
  connector.setPort(address.getPortOrDefault(DEFAULT_PORT));
  return connector;
}