Skip to content
This repository was archived by the owner on Mar 21, 2022. It is now read-only.

Adding ClientFactory abstraction to allow alternate JAXRS implementations to be used#340

Open
jskjons wants to merge 7 commits intospotify:masterfrom
rei:master
Open

Adding ClientFactory abstraction to allow alternate JAXRS implementations to be used#340
jskjons wants to merge 7 commits intospotify:masterfrom
rei:master

Conversation

@jskjons
Copy link
Copy Markdown

@jskjons jskjons commented Feb 4, 2016

We use RESTEasy in most of our applications/tooling and because the docker client currently uses the standard JAXRS client api it's hard to control which implementation gets used and it's impossible to customize the client if Resteasy gets picked. This abstractions allows us to just create RESTEasy clients and then only have 1 JAXRS implementation on our classpath. I've tested it with both Jersey and RESTEasy (not included) implementations and everything seems to work.

I also switched the JerseyClientFactory to directly use the JerseyClientBuilder so that it'll still use Jersey even if there's an alternate JAXRS implementation on the classpath.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Feb 5, 2016

Current coverage is 62.78% (diff: 75.78%)

Merging #340 into master will increase coverage by 16.44%

@@             master       #340   diff @@
==========================================
  Files           130         81     -49   
  Lines          4331       2940   -1391   
  Methods           0          0           
  Messages          0          0           
  Branches        635        403    -232   
==========================================
- Hits           2007       1846    -161   
+ Misses         2134       1094   -1040   
+ Partials        190          0    -190   

Powered by Codecov. Last update cbdd93b...128c40f

@@ -57,11 +57,7 @@
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.glassfish.hk2.api.MultiException;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this code is still dependent on org.glassfish.hk2.api.MultiException and org.glassfish.jersey.internal.util.Base64. Are you sure that this client still works when glassfish has completely vanished from the classpath? And that the exception handling works well if glassfish is replaced with resteasy?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MultiException is in hk2-api which doesn't seem to conflict with RESTEasy anyways so I don't think I need to worry about getting rid of the reference, although explicitly adding the maven dependency rather than using it transitively would be good. I'll make that change.

Base64 I didn't notice and I assume would've failed if I tried to use it with registry authentication. Any objections to switching that to commons-codec?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also switch to Java8 and use Base64.getEncoder()

On Mon, 2 May 2016 at 18:19 Jeff Skjonsby notifications@github.com wrote:

In src/main/java/com/spotify/docker/client/DefaultDockerClient.java
#340 (comment):

@@ -57,11 +57,7 @@
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.glassfish.hk2.api.MultiException;

MultiException is in hk2-api which doesn't seem to conflict with RESTEasy
anyways so I don't think I need to worry about getting rid of the
reference, although explicitly adding the maven dependency rather than
using it transitively would be good. I'll make that change.

Base64 I didn't notice and I assume would've failed if I tried to use it
with registry authentication. Any objections to switching that to
commons-codec?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/spotify/docker-client/pull/340/files/f540f50f336c198eca7ea006a9f59e5a5f0f0e30#r61761412

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that was the first thing I thought of but thought it might be a bit presumptuous to update the jdk version in this PR :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But resteasy does not throw hk2-exceptions, but jax-rs exceptions, so that is different right?

Copy link
Copy Markdown
Author

@jskjons jskjons May 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only place the MultiException is used is in an multi-catch with ExecutionException which is what gets thrown by either implementation from what I can tell in the .get() call because it's async. In my tests it seems to propagate exceptions just fine. They get dealt with by the line
} else if (cause instanceof WebApplicationException) {...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, missed that statement. Exception handlig should be fine then! 👍

@jwgmeligmeyling
Copy link
Copy Markdown
Contributor

jwgmeligmeyling commented Apr 30, 2016

Great work! The PR looks quite good. There are a few remarks from my side (as a contributor, not maintainer).

It seems the code is still dependent on org.glassfish.hk2.api.MultiException and org.glassfish.jersey.internal.util.Base64. Besides that this implies that (at least some) glassfish dependencies are still required on the classpath, I think that exceptions may not be handled properly when another HttpClient implementation is used.

I would love to see a few additions:

  • Add resteasy-client (and its Jackson companion) as an optional and provided dependency:
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.0.16.Final</version>
    <scope>provided</scope>
    <optional>true</optional>
</dependency>

(In fact, this should also be done with the glassfish dependencies in my opinion, but that would be a breaking change for existing users, so lets stick to adding that as <exclusion> for now)

  • Alter the intergration tests in such as way (either through test class inheritance or for example JUnit theories or parameterized) that the same tests are ran for both the glassfish and resteasy-client. This would address my concern that some exception handling (or for example any timeout vs. non-timeout issues) are not working properly.
  • Some example usage of how to use another HttpClient can be used and specifically how the resteasy-client should be configured in practice would be nice!
  • The PR should be up to date with master, so it can be merged :)

@jwgmeligmeyling
Copy link
Copy Markdown
Contributor

ping @grexe

@jskjons jskjons force-pushed the master branch 2 times, most recently from eddee9f to 4d878f6 Compare May 2, 2016 21:47
@jskjons
Copy link
Copy Markdown
Author

jskjons commented May 3, 2016

I can add the optional dependencies but I'm not sure if it really adds much value since the user still has to add those dependencies themselves anyway. Unless you're going to fully support multiple JAXRS implementations I'm not sure how much value there is in kinda-sorta supporting it. I mainly wanted to clear the roadblock preventing usage of anything else.

If you want to full on support multiple implementations I think ideally there should be a few more breaking changes like extracting the dependencies and factories into separate modules.

I'm happy to add an example usage of using RESTEasy with this, should that go in user_manual.md?

@jwgmeligmeyling
Copy link
Copy Markdown
Contributor

The dependencies should be included anyway in order to be able to test the Resteasy client. My opinion is still that this should be tested properly, including timeout and exception behaviour. So I would like to see the integration tests to be ran on both client implementations.

The optional inclusion would mostly be a cosmetic feature indicating it can be used with other clients.

@jskjons
Copy link
Copy Markdown
Author

jskjons commented May 3, 2016

fair enough, I'll make that change today.

@jwgmeligmeyling
Copy link
Copy Markdown
Contributor

Allright. I can have a look on Thursday to maybe add some tests if you'd like :)

@jskjons
Copy link
Copy Markdown
Author

jskjons commented May 4, 2016

I added the ResteasyClientFactory implementation as well as deps + docs. It turned out there was a few of the features that we were using (streaming stuff in particular) that was a bit of a pain to get working in RESTEasy but the integration tests are passing now. The Events stuff currently directly relies on jersey so it would be more difficult to get working so I just left it for now and documented that fact.

@jwgmeligmeyling
Copy link
Copy Markdown
Contributor

Whoa, great work! Will defenitely start using our fork 😄 Any idea on the last failing test case?

Tests in error:
testEventStreamWithUntilTimeresteasy: The supplied component "org.jboss.resteasy.client.jaxrs.ResteasyClient" is not assignable from JerseyClient or JerseyWebTarget.

Comment thread docs/user_manual.md Outdated
* [Exec Resize](#exec-resize)
* [Exec Inspect](#exec-inspect)
* [Mounting volumes in a container](#mounting-volumes-in-a-container)
* [Using RESTEasy instead of Jersey]#(resteasy)
Copy link
Copy Markdown
Contributor

@jwgmeligmeyling jwgmeligmeyling May 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that the #( should be flipped to (# (preview)

@jskjons
Copy link
Copy Markdown
Author

jskjons commented May 4, 2016

that last test was failing because the events stuff doesn't work with resteasy so I needed to add

assumeThat(sut.getClient(), not(instanceOf(ResteasyClient.class)));

to all of those tests and missed one. Should be good now.

@jwgmeligmeyling
Copy link
Copy Markdown
Contributor

Great! Waiting on response from the maintainers then.

@johnflavin
Copy link
Copy Markdown
Contributor

That test failure on 1.10.3 is caused by the same problem as #412. That issue (or at least the test that failed because of the issue) was fixed in #415. Rebase this PR on master and that issue should go away.

jskjons and others added 4 commits May 6, 2016 08:42
This required:
  - adding a few annotations
  - adding resteasy dependencies
  - adding hackery to make streaming work with RESTEasy
  - switching to Parameterized JUnit tests
  - documentation for how to use it
@bitsofinfo
Copy link
Copy Markdown

+1

@mydeadlyvenoms
Copy link
Copy Markdown

Any updates on this?

@jskjons
Copy link
Copy Markdown
Author

jskjons commented Oct 27, 2017

I haven't had time to keep the branch up to date with master and I haven't heard anything from the maintainers so it appears this isn't a priority or not a direction the maintainers want to go it. We're still internally using this branch so it still works.

@mydeadlyvenoms
Copy link
Copy Markdown

I am having trouble to use the library under Glassfish / Payara due to Jersey conflicts - this might be the solution.

leachad and others added 3 commits June 14, 2018 12:28
Rebasing the existing fork from current master branch proved too tedious for the purpose of this pull request. I need to test that the addition of the Ulimit builder will work with tenzing scripts and shipyard client. If this proves to be successful perhaps I can revisit merging all components of the master branch into this fork, but as this work is blocking another teammate, I want to free them up ASAP.
Adding Ulimit Builder object in HostConfig Builder.
@rmannibucau
Copy link
Copy Markdown

+1, i'd like to use CXF and JSONB instead of jackson, using portable API is really important

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants