Java Code Examples for org.mortbay.jetty.bio.SocketConnector#setPort()

The following examples show how to use org.mortbay.jetty.bio.SocketConnector#setPort() . 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: 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 2
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 3
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 4
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 5
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 6
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;
}