user134589
user134589

Reputation: 2939

Docker-client Java API : The server failed to respond with a valid HTTP response

Managed to solve an issue which I posted about yesterday where the Java client library couldn't connect to my daemon but now I have a new problem which I cant find any info about online.

I ran the Boot2Docker v1.6 Windows installer on Win7 64 bit. I can run docker commands just fine. Then I pulled the latest Docker-client master branch (v2.7.22) from https://github.com/spotify/docker-client and ran it in Eclipse Java IDE. In DefaultDockerClient I changed DEFAULT_HOST and DEFAULT_PORT to the values which Docker seemed to be using https://docs.docker.com/installation/images/windows-boot2docker-cmd.png (the default values were giving me localhost:2375 connection refused errors).

I tried running the following commands:

final DockerClient docker = DefaultDockerClient.fromEnv().build();
List results = docker.searchImages("ubuntu");

My result is an Apache error going:

 Exception in thread "main" com.spotify.docker.client.DockerException: java.util.concurrent.ExecutionException: javax.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException
at com.spotify.docker.client.DefaultDockerClient.propagate(DefaultDockerClient.java:1109)
at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:1028)
at com.spotify.docker.client.DefaultDockerClient.searchImages(DefaultDockerClient.java:653)
at com.spotify.docker.client.main.Test.main(Test.java:28)
Caused by: java.util.concurrent.ExecutionException: javax.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException
at jersey.repackaged.com.google.common.util.concurrent.AbstractFuture$Sync.getValue(AbstractFuture.java:306)
at jersey.repackaged.com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:293)
at jersey.repackaged.com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:116)
at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:1026)
... 2 more
Caused by: javax.ws.rs.ProcessingException: org.apache.http.client.ClientProtocolException
at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:517)
at org.glassfish.jersey.apache.connector.ApacheConnector$1.run(ApacheConnector.java:527)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at jersey.repackaged.com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:293)
at jersey.repackaged.com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:49)
at jersey.repackaged.com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:45)
at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:523)
at org.glassfish.jersey.client.ClientRuntime$1.run(ClientRuntime.java:169)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:320)
at org.glassfish.jersey.client.ClientRuntime$2.run(ClientRuntime.java:201)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.http.client.ClientProtocolException
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:469)
... 20 more
Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:151)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:153)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:254)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
... 22 more

Does anyone know how I can read the HTTP message/where the logs are stored by the Apache library? I also tried it using the v2.7.21 client version but I had the same errors.

Any ideas how to solve or is anyone else on here also using the same library in combination with boot2docker Windows installer? I am looking for advice from people who are using this library please

Upvotes: 4

Views: 6041

Answers (2)

Ravi Macha
Ravi Macha

Reputation: 717

Its working after setting Environment variables DOCKER_CERT_PATH and DOCKER_HOST

Upvotes: 0

palimpsestor
palimpsestor

Reputation: 1069

I'm guessing that you do not have your DOCKER_CERT_PATH environment variable set, because I was able to reproduce your exception by running those two lines after unsetting my own DOCKER_CERT_PATH.

Also the "connection refused" errors would probably have been avoided if your DOCKER_HOST environment variables were set correctly. Again, I can reproduce by unsetting my own DOCKER_HOST variable.

The values that you need to set for these environment variables are normally displayed at the end of the boot2docker init command, as described at https://docs.docker.com/installation/mac/. You can also see them again by running boot2docker shellinit.

Upvotes: 3

Related Questions