SocketAddress address = socketConnection.connect(new InetSocketAddress("localhost", 0));
SocketConnection ssl = new SocketConnection(secure); InetSocketAddress address = new InetSocketAddress( port ); ssl.connect( address, sslc );
@Override public int start(int port, SSLContext context, boolean authReq) throws IOException { DirectRouter router = new DirectRouter(this); RouterContainer routerContainer = new RouterContainer(this, router, webSocketThreads); ContainerSocketProcessor processor = new ContainerSocketProcessor(routerContainer, threadCount, selectThreads); socketConnection = new SocketConnection(authReq ? new AuthRequiredServer(processor) : processor); InetSocketAddress actualAddress = (InetSocketAddress) socketConnection.connect(new InetSocketAddress(port), context); return actualAddress.getPort(); }
@Test public void test503ResponseHandling() throws IOException { // https://bugzilla.redhat.com/show_bug.cgi?id=874983 HTTPMockContainer mockContainer = HTTPMockContainer.notOkResponse(Status.SERVICE_UNAVAILABLE); ContainerServer server = new ContainerServer(mockContainer); try (SocketConnection connection = new SocketConnection(server)) { InetSocketAddress address = (InetSocketAddress) connection .connect(new InetSocketAddress(0)); int port = address.getPort(); String command = "stats"; String url = "http://localhost:" + port + "/"; String project = "iok"; String version = "6.4"; // client.setErrors(true); client.processArgs(command, "--url", url, "--project", project, "--project-version", version, "--username", "admin", "--key", "abcdeabcdeabcdeabcdeabcdeabcde12"); server.stop(); Mockito.verify(mockAbortStrategy).abort(throwableCapture.capture()); assertThat("Client will display meaningful message for 503", throwableCapture.getValue().getMessage() .contains("unavailable")); } } }