java-http-client icon indicating copy to clipboard operation
java-http-client copied to clipboard

Replace Httpcore dependency

Open depsypher opened this issue 9 years ago • 25 comments

Issue Summary

Because sendgrid/java-http-client depends on org.apache.httpcomponents/httpcore, this library is necessary under google appengine in order to stay under socket connection quotas: https://github.com/sendgrid/sendgrid-google-java

But it looks like that library is soon to be very out of date with the latest sendgrid apis. It would be great if java-http-client could remove that dependency and just use the built in java http connection apis directly so that the official sendgrid-java library would work in all scenarios.

depsypher avatar May 20 '16 17:05 depsypher

Hello @depsypher,

Thanks for the issue!

The new, supported, library can be found here: https://github.com/sendgrid/sendgrid-java/tree/v3beta, it will be out of beta in a few weeks.

I did not see anything in the https://github.com/sendgrid/sendgrid-google-java library that deals with socket connection quotas, could you please elaborate?

We have the org.apache.httpcomponents/httpcore dependency because the java http connection apis do not support PATCH. Do you know of a work around to this? Is there another http library that would achieve your results?

With Best Regards,

Elmer

thinkingserious avatar May 20 '16 17:05 thinkingserious

Very interesting. I didn't know that about PATCH. I found a couple workarounds, but I'm not sure which is the better one:

https://java.net/jira/browse/JERSEY-639 http://stackoverflow.com/questions/25163131/httpurlconnection-invalid-http-method-patch

The background regarding appengine is that it's a bit of a strange beast and java code there runs on a google-modified jdk. That jdk whitelists certain classes and has custom implementations of others so that code runs safely from multiple users without interfering with each other.

Google does some special magic to HttpURLConnection so those calls run in their sandbox. That magic doesn't exist for the apache http implementation, so appengine does a socket connection instead to safely exit the sandbox. This works fine, but google imposes a limit on the number of socket connections allowed per project... so if you send a high volume of email you can blow that limit. Once you hit that quota you're pretty much SOL, as any further calls that use socket connections (be they sending emails or connections to a database) will fail until the quota resets the next day. Not fun.

Anyhow, as long as the older sendgrid-google-java code still works, it's a fine stopgap measure for us to keep using it... but if the sendgrid apis it talks to become deprecated we'll need to have an alternative that doesn't use apache httpcore at that point.

depsypher avatar May 20 '16 18:05 depsypher

@depsypher,

Thanks for the detailed response! We are not deprecating the v2 version of our mail send endpoint, so you are good there.

The first link is something I have not tried, but the second does not work in my tests.

In September, Java will get an update where the HTTP core library will support PATCH. I'm hoping this will be a solid solution. We were able to use core HTTP libraries on all the other 6 languages we support and were quite surprised to run into the PATCH issue when we tried to remove the Apache dependency on this library :(

I'll leave this issue open for further investigation, so yes, your stop gap solution should be fine. Just please be careful when making any updates.

  • Elmer

thinkingserious avatar May 20 '16 18:05 thinkingserious

For reference: http://android-developers.blogspot.be/2011/09/androids-http-clients.html

thinkingserious avatar Aug 04 '16 21:08 thinkingserious

Note:

Consider replacing with https://github.com/google/google-http-java-client

thinkingserious avatar Apr 18 '17 22:04 thinkingserious

EDIT: nvm, I see that this is an on-going issue.

The link https://github.com/sendgrid/sendgrid-java/tree/v3beta no longer works.

Is there a fix for this?

Is the fix "replacing with https://github.com/google/google-http-java-client"?

dougouk avatar May 28 '17 02:05 dougouk

Hi @dougouk,

I believe the fix is to replace the http client with the google-http-java-client. Unless the native Java client has caught up.

In any case, I've added your vote to this issue to help increase it's priority.

Thanks!

thinkingserious avatar May 28 '17 03:05 thinkingserious

@thinkingserious

I tried replacing the http client, but it didn't fix the issue.

The SendGrid API looks for the http client, not the google-http-java-client in the code, so replacing it doesn't fix the issue.

I am actually more specifically here for the following closed issue https://github.com/sendgrid/sendgrid-java/issues/127 but the issue redirects me to this thread.

All I'm trying to do is simply send an email using SendGrid on Android, but I can't due to the dependency issues

Is there a solution?

dougouk avatar May 28 '17 04:05 dougouk

I apologize for not being clear. This is an open issue. We need to actually replace the current client with the google-http-java-client. It will not be as simple as just replacing the client, I don't think. I believe the google-http-java-client probably has a different interface to the apache http client.

thinkingserious avatar May 28 '17 04:05 thinkingserious

@thinkingserious I got this one.

andy-trimble avatar Oct 12 '17 14:10 andy-trimble

@thinkingserious Replace does not work.

baignomi avatar Dec 20 '17 06:12 baignomi

@baignomi,

Yes, you are correct. This issue is yet to be resolved. You can follow this thread for progress.

Thanks!

With Best Regards,

Elmer

thinkingserious avatar Dec 20 '17 08:12 thinkingserious

Hi Elmer, do you have an ETA for this issue? This is the only thing that is blocking us from moving our mail infrastructure to SendGrid... Thanks :-)

maelcaldas avatar Jan 23 '18 17:01 maelcaldas

@andy-trimble,

Is this something you still would like to tackle? Thanks!

thinkingserious avatar Jan 23 '18 17:01 thinkingserious

Ah, yes @thinkingserious. I completely forgot about this one. I'll take a crack at it.

andy-trimble avatar Jan 23 '18 19:01 andy-trimble

Awesome!

thinkingserious avatar Jan 24 '18 22:01 thinkingserious

What is the status for this fix? I am also using App Engine and running into the same issue. I am using my own http utils in App Engine for now, but would love to use this library.

bashoogzaad avatar Dec 08 '18 15:12 bashoogzaad

I am also curious what the status of this issue is. I just tried to create a SendGrid instance in Android and got: java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier;

szeidner avatar Feb 12 '19 21:02 szeidner

Is this still being worked on? I am currently having the same issue in Android.

Glennmen avatar Mar 28 '19 15:03 Glennmen

Hi there, I was just wondering if this issue is still being worked on as I am currently experiencing the same issue, or is there even a work around for the time being to get my Android app to send an email? Thanks

walker142 avatar Apr 04 '19 07:04 walker142

What is the status of this issue? Does this completely stop the library working on Android?

johnnyzen avatar Mar 13 '20 17:03 johnnyzen

@johnnyzen As far as I know, it's not currently being worked on. The original request was to allow for better usage within Google App Engine; not Android even though a fix may impact both.

That said, interacting with SendGrid APIs that require auth is not recommended from a client/app/browser. Doing so requires potentially exposing credentials to the end user. The APIs should be invoked by a backend service which could be supporting the front-end client. What's your use case for needing this to be available on Android? There may be edge cases I'm not considering here so just trying to get some clarity.

childish-sambino avatar Mar 13 '20 18:03 childish-sambino

Is there any (simple) solution at this point?

I have already spent/wasted 2 days trying to integrate SendGrid into my app and every single time it either fails because of the: java.lang.NoSuchFieldError: No static field INSTANCE of type org/apache/http/conn/ssl/AllowAllHostnameVerifier; #588

or the duplication of libraries, or something else. This is particularly frustrating and with the issue first reported more than 3 years ago, I couldn't find a straightforward "just works" solution as of now.

vmfox avatar Apr 26 '20 18:04 vmfox

After appeasing a build exception due to More than one file was found with OS independent path 'META-INF/DEPENDENCIES' in my issue #625, I'm now also stuck with java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier

Misery loves company.

digsub avatar May 31 '20 12:05 digsub

Still the same problem in 2022 !!

yamanjain avatar Feb 22 '22 19:02 yamanjain