Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In OSGi + H2 environment java service HpackFieldPreEncoder can't load from org.eclipse.jetty.http #262

Closed
jmcc0nn3ll opened this issue Feb 16, 2016 · 7 comments
Assignees
Labels
Bug For general bugs on Jetty side

Comments

@jmcc0nn3ll
Copy link
Contributor

migrated from Bugzilla #483324
status NEW severity blocker in component http2 for 9.3.x
Reported in version 9.3.6 on platform PC
Assigned to: Simone Bordet

On 2015-11-30 12:51:47 -0500, hiep lq wrote:

I setup to use http2 in OSGi project. when i run it, non error message in console.
alpn selected correct h2 as protocol, but webpage is blank.
after debug i see:
line ServiceLoader.load(HttpFieldPreEncoder.class,PreEncodedHttpField.class.getClassLoader())
class org.eclipse.jetty.http.PreEncodedHttpField
only load Http1FieldPreEncoder, can't load HpackFieldPreEncoder

so it make NPE in next step and after that java.nio.channels.ClosedChannelException

detail log at:
http://0bin.net/paste/pXcVNVcvc1-52MbS#

i don't see any error log because this log just a warning, and visible when set log level to debug.

my work-around: i merged code of org.eclipse.jetty.http and org.eclipse.jetty.http2.hpack and i get http2 in my server.

@jmcc0nn3ll jmcc0nn3ll added the Bug For general bugs on Jetty side label Feb 16, 2016
@cffan
Copy link

cffan commented May 6, 2016

I had the same issue and after some digging, I found out that it is because HpackFieldPreEncoder is not included in META-INF/services. And the solution is to add
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>

to maven-shade-plugin's config.

@hieplq
Copy link

hieplq commented Nov 2, 2016

hi @janbartel, can you help me at this issue?
i believe ServiceLoader Mediator can resolve this issue.

i try to add Capability header by osgi syntax direct to MANIFEST.MF file of org.eclipse.jetty.http and org.eclipse.jetty.http2.hpack
but not yet success, service isn't registry (i guess i do some wrong about space, case, or coma).

spi fly syntax is more easy, so i try to use it, i got success.
add below head to org.eclipse.jetty.http2.hpack
SPI-Provider: org.eclipse.jetty.http.HttpFieldPreEncoder

add bellow header to org.eclipse.jetty.http
SPI-Provider: org.eclipse.jetty.http.HttpFieldPreEncoder SPI-Consumer: java.util.ServiceLoader#load(java.lang.Class[org.eclipse.jetty.http.HttpFieldPreEncoder])

class PreEncodedHttpField change bellow line
Iterator<HttpFieldPreEncoder> iter = ServiceLoader.load(HttpFieldPreEncoder.class,PreEncodedHttpField.class.getClassLoader()).iterator();

to

Iterator<HttpFieldPreEncoder> iter = ServiceLoader.load(HttpFieldPreEncoder.class).iterator();

@joakime
Copy link
Contributor

joakime commented Nov 2, 2016

Changing the ServiceLoader to use the Thread local classloader isn't correct, it would need to use the same classloader that that interface (PreEncodedHttpField) was created from.

@joakime
Copy link
Contributor

joakime commented Nov 2, 2016

Some background on OSGi + ServiceLoader + 2 param version of .load() method

http://blog.osgi.org/2013/02/javautilserviceloader-in-osgi.html

@hieplq
Copy link

hieplq commented Nov 2, 2016

seem spi fly just work with ServiceLoader.load (Class)
i don't see any document or sample about ServiceLoader.load (Class, ClassLoad)

so we can change this line to

ClassLoader saveCl = Thread.currentThread().getContextClassLoader(); Iterator<HttpFieldPreEncoder> iter = null; try { Thread.currentThread().setContextClassLoader (PreEncodedHttpField.class.getClassLoader()); iter = ServiceLoader.load(HttpFieldPreEncoder.class).iterator(); }finally{ Thread.currentThread().setContextClassLoader(saveCl); }

@joakime
Copy link
Contributor

joakime commented Feb 12, 2017

See Issue #705 for the general solution to this class of issue.

@hieplq
Copy link

hieplq commented Feb 25, 2017

resolved on #1290

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
None yet
Development

No branches or pull requests

5 participants