Can I use org.apache.http.client.HttpClient in the google engine?

I read that this buzz just allowed only sampling. Does this mean that it is not possible to integrate org.apache.http.client.HttpClient into the google engine?

If not, is there an alternative to using existing librairies using org.apache.http.client.HttpClient in the google engine?

+5
java google-app-engine
source share
2 answers

So there is no answer. You need to use google fetch library.

From the Google App Engine wiki page in Google Code in the Wayback Machine archive:

The only supported HTTP transport is UrlFetchTransport, based on the URL API in the Google App Engine SDK

Do not try ApacheHttpTransport , because it will certainly fail in the Google App Engine.

0
source

Update 2019

Yes, you really can. I just tried it; it definitely works with the Java 8 environment.

Steps:

  1. Enable billing , otherwise native HttpURLConnection will not work (which is also the basis of Apache HttpClient). Without billing, you can only use the deprecated urlfetch as described in a previous post from 2016.

  2. Optional in the Java 8 environment as default is native

appengine-web.xml :

 <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <url-stream-handler>native</url-stream-handler> </appengine-web-app> 
  1. Write your code, for example:
 try (CloseableHttpClient httpclient = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost("http://myservice.com"); httpPost.setEntity(new StringEntity(objectMapper.writeValueAsString(input), ContentType.APPLICATION_JSON)); CloseableHttpResponse response = httpclient.execute(httpPost); return objectMapper.readValue(response.getEntity().getContent(), new TypeReference<MyReturnType>() { }); } catch (IOException e) { throw new RuntimeException(e); } 
0
source

All Articles