client_java: HttpServer tries and fails to create a Jetty HttpServer when defined by SPI

The HTTPServer will not start when using Jetty as HttpServerProvider. Might be as easy as to call .create(addr,..) directly, without call to bind(...).

Unless the intent is to always start a com.sun Server, then perhaps that should be done more explicitly.

Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
	at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.NullPointerException
	at org.eclipse.jetty.http.spi.JettyHttpServer.bind(JettyHttpServer.java:94)
	at org.eclipse.jetty.http.spi.JettyHttpServerProvider.createHttpServer(JettyHttpServerProvider.java:69)
	at com.sun.net.httpserver.HttpServer.create(HttpServer.java:130)
	at com.sun.net.httpserver.HttpServer.create(HttpServer.java:105)
	at io.prometheus.jmx.shaded.io.prometheus.client.exporter.HTTPServer.<init>(HTTPServer.java:144)
	at io.prometheus.jmx.shaded.io.prometheus.jmx.JavaAgent.premain(JavaAgent.java:38)
	... 6 more

Versions: jmx_exporter: 0.1.0 simpleclient_httpserver: 0.1.0 (by transitive dependency)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Ok, sorry for being unclear!

As far as I can see, jmx_exporter uses HTTPServer from simpleclient_httpserver which technically uses the JDK’s HttpServerProvider.provider() to instantiate a HttpServer. HttpServerProvider uses the Java SPI-mechanism to determine what HttpServer implementation to instantiate, and in most cases that will be the built-in sun.net.httpserver.HttpServerImpl. However, since SPI is used, if I put a jetty-http-spi dependency on the classpath, it will instead try to instantiate a Jetty-httpserver, which fails.

So it is a pretty edgy case. We are using jetty-http-spi in our application to expose RMI services over Jetty. Ultimately, we would just like to get the jmx_exporter to work in our app, but after looking at the possibilities, I am not clear on how we can achieve that in our current setup.