Java Code Examples for org.eclipse.jetty.server.ServerConnector#getHost()

The following examples show how to use org.eclipse.jetty.server.ServerConnector#getHost() . 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: BadBackendTest.java    From knox with Apache License 2.0 6 votes vote down vote up
private static void startProxy() throws Exception {
  GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
  proxy = new Server();
  proxyConnector = new ServerConnector(proxy);
  proxy.addConnector(proxyConnector);

  /* start Knox with WebsocketAdapter to test */
  final BigEchoSocketHandler wsHandler = new BigEchoSocketHandler(
      new ProxyWebSocketAdapter(new URI(BAD_BACKEND), Executors.newFixedThreadPool(10), gatewayConfig));

  ContextHandler context = new ContextHandler();
  context.setContextPath("/");
  context.setHandler(wsHandler);
  proxy.setHandler(context);

  // Start Server
  proxy.start();

  String host = proxyConnector.getHost();
  if (host == null) {
    host = "localhost";
  }
  int port = proxyConnector.getLocalPort();
  proxyUri = new URI(String.format(Locale.ROOT, "ws://%s:%d/", host, port));
}
 
Example 2
Source File: MessageFailureTest.java    From knox with Apache License 2.0 6 votes vote down vote up
private static void startProxy() throws Exception {
  GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
  proxy = new Server();
  proxyConnector = new ServerConnector(proxy);
  proxy.addConnector(proxyConnector);

  /* start Knox with WebsocketAdapter to test */
  final BigEchoSocketHandler wsHandler = new BigEchoSocketHandler(
      new ProxyWebSocketAdapter(serverUri, Executors.newFixedThreadPool(10), gatewayConfig));

  ContextHandler context = new ContextHandler();
  context.setContextPath("/");
  context.setHandler(wsHandler);
  proxy.setHandler(context);

  // Start Server
  proxy.start();

  String host = proxyConnector.getHost();
  if (host == null) {
    host = "localhost";
  }
  int port = proxyConnector.getLocalPort();
  proxyUri = new URI(String.format(Locale.ROOT, "ws://%s:%d/", host, port));
}
 
Example 3
Source File: MessageFailureTest.java    From knox with Apache License 2.0 6 votes vote down vote up
private static void startBackend() throws Exception {
  backend = new Server();
  connector = new ServerConnector(backend);
  backend.addConnector(connector);

  /* start backend with Echo socket */
  final BigEchoSocketHandler wsHandler = new BigEchoSocketHandler(
      new EchoSocket());

  ContextHandler context = new ContextHandler();
  context.setContextPath("/");
  context.setHandler(wsHandler);
  backend.setHandler(context);

  // Start Server
  backend.start();

  String host = connector.getHost();
  if (host == null) {
    host = "localhost";
  }
  int port = connector.getLocalPort();
  serverUri = new URI(String.format(Locale.ROOT, "ws://%s:%d/", host, port));
}
 
Example 4
Source File: ProxyInboundClientTest.java    From knox with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  server = new Server();
  ServerConnector connector = new ServerConnector(server);
  server.addConnector(connector);

  Handler handler = new WebsocketEchoHandler();

  ContextHandler context = new ContextHandler();
  context.setContextPath("/");
  context.setHandler(handler);
  server.setHandler(context);

  server.start();

  String host = connector.getHost();
  if (host == null) {
    host = "localhost";
  }
  int port = connector.getLocalPort();
  serverUri = new URI(String.format(Locale.ROOT, "ws://%s:%d/",host,port));
}
 
Example 5
Source File: ConnectionDroppedTest.java    From knox with Apache License 2.0 6 votes vote down vote up
private static void startProxy() throws Exception {
  GatewayConfig gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class);
  proxy = new Server();
  proxyConnector = new ServerConnector(proxy);
  proxy.addConnector(proxyConnector);

  /* start Knox with WebsocketAdapter to test */
  final BigEchoSocketHandler wsHandler = new BigEchoSocketHandler(
      new ProxyWebSocketAdapter(serverUri, Executors.newFixedThreadPool(10), gatewayConfig));

  ContextHandler context = new ContextHandler();
  context.setContextPath("/");
  context.setHandler(wsHandler);
  proxy.setHandler(context);

  // Start Server
  proxy.start();

  String host = proxyConnector.getHost();
  if (host == null) {
    host = "localhost";
  }
  int port = proxyConnector.getLocalPort();
  proxyUri = new URI(String.format(Locale.ROOT, "ws://%s:%d/", host, port));
}
 
Example 6
Source File: App.java    From mysql_perf_analyzer with Apache License 2.0 6 votes vote down vote up
private URI getServerUri(ServerConnector connector)
		throws URISyntaxException {
	String scheme = "http";
	for (ConnectionFactory connectFactory : connector
			.getConnectionFactories()) {
		if (connectFactory.getProtocol().startsWith("SSL-http")) {
			scheme = "https";
		}
	}
	String host = connector.getHost();
	if (host == null) {
		try{
			host = InetAddress.getLocalHost().getHostName();
		}catch(Exception ex){}
	}
	if (host == null){
		host = "localhost";			
	}
	int myport = connector.getLocalPort();
	serverURI = new URI(String.format("%s://%s:%d", scheme, host, myport));
	System.out.println(new Date() + " Server URI: " + serverURI + this.contextPath);
	return serverURI;
}
 
Example 7
Source File: ConnectionDroppedTest.java    From knox with Apache License 2.0 6 votes vote down vote up
private static void startBackend() throws Exception {
  backend = new Server();
  connector = new ServerConnector(backend);
  backend.addConnector(connector);

  /* start backend with Echo socket */
  final BigEchoSocketHandler wsHandler = new BigEchoSocketHandler(
      new BadSocket());

  ContextHandler context = new ContextHandler();
  context.setContextPath("/");
  context.setHandler(wsHandler);
  backend.setHandler(context);

  // Start Server
  backend.start();

  String host = connector.getHost();
  if (host == null) {
    host = "localhost";
  }
  int port = connector.getLocalPort();
  serverUri = new URI(String.format(Locale.ROOT, "ws://%s:%d/", host, port));
}
 
Example 8
Source File: HttpServer.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Get the address that corresponds to a particular connector.
 *
 * @return the corresponding address for the connector, or null if there's no
 *         such connector or the connector is not bounded.
 */
public InetSocketAddress getConnectorAddress(int index) {
  Preconditions.checkArgument(index >= 0);

  if (index > webServer.getConnectors().length) {
    return null;
  }

  ServerConnector c = (ServerConnector)webServer.getConnectors()[index];
  if (c.getLocalPort() == -1 || c.getLocalPort() == -2) {
    // -1 if the connector has not been opened
    // -2 if it has been closed
    return null;
  }

  return new InetSocketAddress(c.getHost(), c.getLocalPort());
}
 
Example 9
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Get the address that corresponds to a particular connector.
 *
 * @param index index of the connector
 * @return the corresponding address for the connector, or null if there's no
 *         such connector or the connector is not bounded or was closed.
 */
public InetSocketAddress getConnectorAddress(int index) {
  Preconditions.checkArgument(index >= 0);
  if (index > webServer.getConnectors().length) {
    return null;
  }

  ServerConnector c = (ServerConnector)webServer.getConnectors()[index];
  if (c.getLocalPort() == -1 || c.getLocalPort() == -2) {
    // The connector is not bounded or was closed
    return null;
  }

  return new InetSocketAddress(c.getHost(), c.getLocalPort());
}
 
Example 10
Source File: WebsocketEchoTestBase.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Start Gateway Server.
 * @throws Exception exception on server start
 */
private static void startGatewayServer() throws Exception {
  gatewayServer = new Server();
  final ServerConnector connector = new ServerConnector(gatewayServer);
  gatewayServer.addConnector(connector);

  /* workaround so we can add our handler later at runtime */
  HandlerCollection handlers = new HandlerCollection(true);

  /* add some initial handlers */
  ContextHandler context = new ContextHandler();
  context.setContextPath("/");
  handlers.addHandler(context);

  gatewayServer.setHandler(handlers);

  // Start Server
  gatewayServer.start();

  String host = connector.getHost();
  if (host == null) {
    host = "localhost";
  }
  int port = connector.getLocalPort();
  serverUri = new URI(String.format(Locale.ROOT, "ws://%s:%d/", host, port));

  /* Setup websocket handler */
  setupGatewayConfig(backendServerUri.toString());

  final GatewayWebsocketHandler gatewayWebsocketHandler = new GatewayWebsocketHandler(
      gatewayConfig, services);
  handlers.addHandler(gatewayWebsocketHandler);
  gatewayWebsocketHandler.start();
}
 
Example 11
Source File: WebsocketMultipleConnectionTest.java    From knox with Apache License 2.0 5 votes vote down vote up
private static void startGatewayServer() throws Exception {
  /* use default Max threads */
  gatewayServer = new Server(new QueuedThreadPool(254));
  final ServerConnector connector = new ServerConnector(gatewayServer);
  gatewayServer.addConnector(connector);

  /* workaround so we can add our handler later at runtime */
  HandlerCollection handlers = new HandlerCollection(true);

  /* add some initial handlers */
  ContextHandler context = new ContextHandler();
  context.setContextPath("/");
  handlers.addHandler(context);

  gatewayServer.setHandler(handlers);

  // Start Server
  gatewayServer.start();

  String host = connector.getHost();
  if (host == null) {
    host = "localhost";
  }
  int port = connector.getLocalPort();
  serverUri = new URI(String.format(Locale.ROOT, "ws://%s:%d/", host, port));

  /* Setup websocket handler */
  setupGatewayConfig(backendServerUri.toString());

  final GatewayWebsocketHandler gatewayWebsocketHandler = new GatewayWebsocketHandler(
      gatewayConfig, services);
  handlers.addHandler(gatewayWebsocketHandler);
  gatewayWebsocketHandler.start();
}
 
Example 12
Source File: ServerRpcProvider.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the socket the WebSocket server is listening on.
 */
public SocketAddress getWebSocketAddress() {
  if (httpServer == null) {
    return null;
  } else {
    ServerConnector c = (ServerConnector)httpServer.getConnectors()[0];
    return new InetSocketAddress(c.getHost(), c.getLocalPort());
  }
}
 
Example 13
Source File: BadUrlTest.java    From knox with Apache License 2.0 5 votes vote down vote up
private static void startGatewayServer() throws Exception {
  gatewayServer = new Server();
  final ServerConnector connector = new ServerConnector(gatewayServer);
  gatewayServer.addConnector(connector);

  /* workaround so we can add our handler later at runtime */
  HandlerCollection handlers = new HandlerCollection(true);

  /* add some initial handlers */
  ContextHandler context = new ContextHandler();
  context.setContextPath("/");
  handlers.addHandler(context);

  gatewayServer.setHandler(handlers);

  // Start Server
  gatewayServer.start();

  String host = connector.getHost();
  if (host == null) {
    host = "localhost";
  }
  int port = connector.getLocalPort();
  serverUri = new URI(String.format(Locale.ROOT, "ws://%s:%d/", host, port));

  /* Setup websocket handler */
  setupGatewayConfig(BACKEND);

  final GatewayWebsocketHandler gatewayWebsocketHandler = new GatewayWebsocketHandler(
      gatewayConfig, services);
  handlers.addHandler(gatewayWebsocketHandler);
  gatewayWebsocketHandler.start();
}
 
Example 14
Source File: JettyHTTPServerEngine.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static void logConnector(ServerConnector connector) {
    try {
        String h = connector.getHost();
        int port = connector.getPort();
        LOG.finer("connector.host: " + (h == null ? "null" : "\"" + h + "\""));
        LOG.finer("connector.port: " + port);
    } catch (Throwable t) {
        //ignore
    }
}
 
Example 15
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Get the address that corresponds to a particular connector.
 *
 * @param index index of the connector
 * @return the corresponding address for the connector, or null if there's no
 *         such connector or the connector is not bounded or was closed.
 */
public InetSocketAddress getConnectorAddress(int index) {
  Preconditions.checkArgument(index >= 0);
  if (index > webServer.getConnectors().length) {
    return null;
  }

  ServerConnector c = (ServerConnector)webServer.getConnectors()[index];
  if (c.getLocalPort() == -1 || c.getLocalPort() == -2) {
    // The connector is not bounded or was closed
    return null;
  }

  return new InetSocketAddress(c.getHost(), c.getLocalPort());
}
 
Example 16
Source File: HttpServer2.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Create bind exception by wrapping the bind exception thrown.
 * @param listener listener to check
 * @param ex exception to check
 * @return returns the exception
 */
private static BindException constructBindException(ServerConnector listener,
                                                    BindException ex) {
  BindException be = new BindException("Port in use: "
      + listener.getHost() + ":" + listener.getPort());
  if (ex != null) {
    be.initCause(ex);
  }
  return be;
}
 
Example 17
Source File: HttpServer2.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Get the address that corresponds to a particular connector.
 *
 * @return the corresponding address for the connector, or null if there's no
 *         such connector or the connector is not bounded or was closed.
 */
public InetSocketAddress getConnectorAddress(int index) {
  Preconditions.checkArgument(index >= 0);
  if (index > webServer.getConnectors().length)
    return null;

  ServerConnector c = (ServerConnector)webServer.getConnectors()[index];
  if (c.getLocalPort() == -1 || c.getLocalPort() == -2) {
    // The connector is not bounded or was closed
    return null;
  }

  return new InetSocketAddress(c.getHost(), c.getLocalPort());
}
 
Example 18
Source File: HttpServer.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
private RpcMetadataResponse createRpcServerMetadata(ServerConnector connector) throws
    UnknownHostException {
  String host = connector.getHost();
  if (null == host) {
    // "null" means binding to all interfaces, we need to pick one so the client gets a real
    // address and not "0.0.0.0" or similar.
    host = InetAddress.getLocalHost().getHostName();
  }

  final int port = connector.getLocalPort();

  return new RpcMetadataResponse(
      String.format(Locale.ROOT, "%s:%d", host, port));
}
 
Example 19
Source File: HostedRepositoryIntegrationTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
private URI toServerURI(ServerConnector connector) throws URISyntaxException {
    String host = connector.getHost();
    if (host == null) {
        host = DEFAULT_HOST;
    }
    int port = connector.getLocalPort();
    return new URI(String.format("http://%s:%d",
                                 host,
                                 port));
}
 
Example 20
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Create bind exception by wrapping the bind exception thrown.
 * @param listener listener to check
 * @param ex exception to check
 * @return returns the exception
 */
private static BindException constructBindException(ServerConnector listener,
                                                    BindException ex) {
  BindException be = new BindException("Port in use: "
                                           + listener.getHost() + ":" + listener.getPort());
  if (ex != null) {
    be.initCause(ex);
  }
  return be;
}