org.eclipse.jetty.server.Server#getURI ( )源码实例Demo

下面列出了org.eclipse.jetty.server.Server#getURI ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Test
public void testBackfill() throws Exception {
    Server server = new Server(0);
    server.setHandler(new BackfillHandler());
    server.start();
    URI uri = server.getURI();
    DataPointReceiver dpr = new HttpDataPointProtobufReceiverFactory(
            new SignalFxEndpoint(uri.getScheme(), uri.getHost(), uri.getPort()))
            .createDataPointReceiver();

    ArrayList<SignalFxProtocolBuffers.PointValue> values = new ArrayList<SignalFxProtocolBuffers.PointValue>(Arrays.asList(
            SignalFxProtocolBuffers.PointValue.newBuilder().setTimestamp(System.currentTimeMillis())
                    .setValue(SignalFxProtocolBuffers.Datum.newBuilder().setDoubleValue(123.0)).build()
    ));
    HashMap<String,String> dims = new HashMap<String,String>();
    dims.put("baz", "gorch");
    dims.put("moo", "cow");

    dpr.backfillDataPoints(AUTH_TOKEN, "foo.bar.baz", "counter", "ABC123", dims, values);
    server.stop();
}
 
源代码2 项目: pulsar   文件: WorkerServer.java
private static String getErrorMessage(Server server, int port, Exception ex) {
    if (ex instanceof BindException) {
        final URI uri = server.getURI();
        return String.format("%s http://%s:%d", ex.getMessage(), uri.getHost(), port);
    }

    return ex.getMessage();
}
 
源代码3 项目: incubator-heron   文件: Runtime.java
private static String getErrorMessage(Server server, int port, Exception ex) {
  if (ex instanceof BindException) {
    final URI uri = server.getURI();
    return String.format("%s http://%s:%d", ex.getMessage(), uri.getHost(), port);
  }

  return ex.getMessage();
}
 
源代码4 项目: spectator   文件: IpcServletFilterTest.java
@BeforeAll
public static void init() throws Exception {
  server = new Server(new InetSocketAddress("localhost", 0));
  ServletHandler handler = new ServletHandler();
  handler.addServletWithMapping(OkServlet.class, "/test/foo/*");
  handler.addServletWithMapping(OkServlet.class, "/api/*");
  handler.addServletWithMapping(BadRequestServlet.class, "/bad/*");
  handler.addServletWithMapping(FailServlet.class, "/throw/*");
  handler.addServletWithMapping(CustomEndpointServlet.class, "/endpoint/*");
  handler.addServletWithMapping(OkServlet.class, "/*");
  handler.addFilterWithMapping(IpcServletFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
  server.setHandler(handler);
  server.start();
  baseUri = server.getURI();
}
 
源代码5 项目: spectator   文件: GuiceServletFilterTest.java
@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();
}
 
@Test
public void testHttpConnection() throws Exception {
    Server server = new Server(0);
    server.setHandler(new AddPointsHandler());
    server.start();
    URI uri = server.getURI();
    DataPointReceiver dpr = new HttpDataPointProtobufReceiverFactory(
            new SignalFxEndpoint(uri.getScheme(), uri.getHost(), uri.getPort()))
            .createDataPointReceiver();
    dpr.addDataPoints(AUTH_TOKEN, Collections.singletonList(
            SignalFxProtocolBuffers.DataPoint.newBuilder().setSource("source").build()));
    server.stop();
}
 
源代码7 项目: selenium   文件: HttpClientTestBase.java
@Test
public void shouldAllowUrlsWithSchemesToBeUsed() throws Exception {
  Server server = new Server(PortProber.findFreePort());
  ServletContextHandler handler = new ServletContextHandler();
  handler.setContextPath("");

  class Canned extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
      try (PrintWriter writer = resp.getWriter()) {
        writer.append("Hello, World!");
      }
    }
  }
  ServletHolder holder = new ServletHolder(new Canned());
  handler.addServlet(holder, "/*");
  server.setHandler(handler);

  server.start();
  try {
    // This is a terrible choice of URL
    HttpClient client = createFactory().createClient(new URL("http://example.com"));

    URI uri = server.getURI();
    HttpRequest request = new HttpRequest(
        GET,
        String.format("http://%s:%s/hello", uri.getHost(), uri.getPort()));

    HttpResponse response = client.execute(request);

    assertThat(string(response)).isEqualTo("Hello, World!");
  } finally {
    server.stop();
  }
}
 
源代码8 项目: bromium   文件: ServerLauncher.java
public static void main(final String[] args) {
  InetSocketAddress _inetSocketAddress = new InetSocketAddress("localhost", 8080);
  final Server server = new Server(_inetSocketAddress);
  WebAppContext _webAppContext = new WebAppContext();
  final Procedure1<WebAppContext> _function = (WebAppContext it) -> {
    it.setResourceBase("WebRoot");
    it.setWelcomeFiles(new String[] { "index.html" });
    it.setContextPath("/");
    AnnotationConfiguration _annotationConfiguration = new AnnotationConfiguration();
    WebXmlConfiguration _webXmlConfiguration = new WebXmlConfiguration();
    WebInfConfiguration _webInfConfiguration = new WebInfConfiguration();
    MetaInfConfiguration _metaInfConfiguration = new MetaInfConfiguration();
    it.setConfigurations(new Configuration[] { _annotationConfiguration, _webXmlConfiguration, _webInfConfiguration, _metaInfConfiguration });
    it.setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, ".*/com\\.hribol\\.bromium\\.dsl\\.web/.*,.*\\.jar");
    it.setInitParameter("org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false");
  };
  WebAppContext _doubleArrow = ObjectExtensions.<WebAppContext>operator_doubleArrow(_webAppContext, _function);
  server.setHandler(_doubleArrow);
  String _name = ServerLauncher.class.getName();
  final Slf4jLog log = new Slf4jLog(_name);
  try {
    server.start();
    URI _uRI = server.getURI();
    String _plus = ("Server started " + _uRI);
    String _plus_1 = (_plus + "...");
    log.info(_plus_1);
    final Runnable _function_1 = () -> {
      try {
        log.info("Press enter to stop the server...");
        final int key = System.in.read();
        if ((key != (-1))) {
          server.stop();
        } else {
          log.warn("Console input is not available. In order to stop the server, you need to cancel process manually.");
        }
      } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
      }
    };
    new Thread(_function_1).start();
    server.join();
  } catch (final Throwable _t) {
    if (_t instanceof Exception) {
      final Exception exception = (Exception)_t;
      log.warn(exception.getMessage());
      System.exit(1);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
源代码9 项目: slr-toolkit   文件: Activator.java
public void start(BundleContext context) throws Exception {
	super.start(context);

	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	String webappRoot = workspace.getRoot().getLocation().toString().concat("/webapp");
	new File(webappRoot).mkdirs();

	Activator.WEB_APP_WORKSPACE = webappRoot;

	// create the server on a free port
	Server server = new Server(0);

	// Configure the ResourceHandler. Setting the resource base indicates where the
	// files should be served out of.
	ResourceHandler resource_handler = new ResourceHandler();
	resource_handler.setDirectoriesListed(true);
	resource_handler.setResourceBase(webappRoot);

	// Add the ResourceHandler to the server.
	HandlerCollection handlers = new HandlerCollection(true);
	handlers.addHandler(resource_handler);

	server.setHandler(handlers);

	// Start server up.
	try {
		server.start();
	} catch (Exception e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	// Get the URI of the server and set it global for the
	// diagram handlers to access
	if (null != server && null != server.getURI()) {
		String localhost = server.getURI().toString();
		Activator.URL = localhost;
	}

	writeVegaFiles();

	plugin = this;
}