public static String getServerURI() { return server.getURI().toASCIIString(); }
private Response call(String path) throws Exception { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url(jetty.getURI().resolve(path).toString()) .build(); return client.newCall(request).execute(); }
@Test public void testBindOnHost() throws Exception { Assert.assertEquals("localhost", server.getURI().getHost()); final URL url = new URL("http://localhost:" + port + "/default"); final HttpURLConnection get = (HttpURLConnection) url.openConnection(); Assert.assertEquals(DEFAULT_RESPONSE_CONTENT, IOUtils.toString(get.getInputStream(), StandardCharsets.UTF_8)); final HttpURLConnection post = (HttpURLConnection) url.openConnection(); post.setRequestMethod("POST"); Assert.assertEquals(DEFAULT_RESPONSE_CONTENT, IOUtils.toString(post.getInputStream(), StandardCharsets.UTF_8)); } }
@Override protected void runUnsafe() throws Exception { Path reportDirectory = getReportDirectoryPath(); if (Files.notExists(reportDirectory)) { throw new AllureCommandException(String.format( "Can't open report: directory <%s> doesn't exist.", reportDirectory )); } LOGGER.info("Starting web server for report directory <{}>", reportDirectory); Server server = setUpServer(); server.start(); openBrowser(server.getURI()); LOGGER.info("Server started at <{}>. Press <Ctrl+C> to exit ...", server.getURI()); server.join(); }
@SuppressWarnings("unchecked") @Override public void start(final String bootstrapServers, final String stateDir) { jettyServer = startJetty(port, this); port = jettyServer.getURI().getPort(); // update port, in case port was zero producer = startProducer(bootstrapServers, ORDERS); streams = startKStreams(bootstrapServers); log.info("Started Service " + getClass().getSimpleName()); }
public static Server startJetty(int port, Object binding) { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); Server jettyServer = new Server(port); jettyServer.setHandler(context); ResourceConfig rc = new ResourceConfig(); rc.register(binding); rc.register(JacksonFeature.class); ServletContainer sc = new ServletContainer(rc); ServletHolder holder = new ServletHolder(sc); context.addServlet(holder, "/*"); try { jettyServer.start(); } catch (Exception e) { throw new RuntimeException(e); } log.info("Listening on " + jettyServer.getURI()); return jettyServer; }
public URI getServiceUri() { return this.server.getURI(); }
public URI getURI() { return jetty.getURI(); }
public URI getUri() { return server.getURI(); }
public URI getServerBaseUri() { return server.getURI(); } }
public URI getURI() { return jetty.getURI(); }
public URI getUri() { return server.getURI(); }
public String getLocalURL() { return registryApplication.localServer.getURI().toString(); }
public int getPort() { return jetty.getURI().getPort(); }
/** * Returns the server endpoint. Mainly used for testing. * * @throws IllegalStateException if the server is not running */ @VisibleForTesting URI getURI() { if (!server.isRunning()) { throw new IllegalStateException("Server is not running"); } return server.getURI(); }
@Override public String getScheme() { return isStarted() ? server.getURI().getScheme() : super.getScheme(); }
private String startHttpServer() throws Exception { Server server = new Server(0); ((QueuedThreadPool)server.getThreadPool()).setMaxThreads(10); ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/foo"); server.setHandler(context); String servletPath = "/bar"; context.addServlet(new ServletHolder(TestHttpServer.EchoServlet.class), servletPath); ((ServerConnector)server.getConnectors()[0]).setHost("localhost"); server.start(); System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); return server.getURI().toString() + servletPath; }
@BeforeAll public static void init() throws Exception { server = new Server(new InetSocketAddress("localhost", 0)); ServletContextHandler handler = new ServletContextHandler(server, "/"); handler.addEventListener(new TestListener()); handler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class)); server.setHandler(handler); server.start(); baseUri = server.getURI(); }
@Override public void afterEach(Method testMethod, ExtensionContext context) throws Exception { cleanUpPort(context); cleanUpIP(context); store().apply(context).get(TSERVER_SERVER, Result.class) .flatMap((CheckedFunction<Server, String>) server -> { URI serverURI = server.getURI(); server.stop(); return serverURI.toASCIIString(); }).ifPresentOrElse(serverURI -> logger().info("Stopped server on : " + serverURI), failed -> logger().warning("no active server available to stop " + failed)); store().apply(context).remove(TSERVER_SERVER); }
private void deployAndconfigureRESTService(String warFileName) throws Exception { jmsServer.createTopic(false, "ordersTopic", (String[]) null); File warFile = getResourceFile("/rest/" + warFileName, warFileName); deployWebApp("/restapp", warFile); server.start(); String uri = server.getURI().toASCIIString(); System.out.println("Sever started with uri: " + uri); restConnection = new RestAMQConnection(uri); }