Skip to content

Commit

Permalink
use URIBuilder, add return value
Browse files Browse the repository at this point in the history
  • Loading branch information
ry99 committed Apr 2, 2020
1 parent 00f57ba commit 8591519
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/amihaiemil/docker/Container.java
Expand Up @@ -161,7 +161,8 @@ void remove(final boolean volumes, final boolean force, final boolean link)
* Wait Container</a>.
* @throws IOException If something goes wrong.
* the expected one (200).
* @return the exit code of the container
*/
void waitOn(String state) throws IOException;
int waitOn(String state) throws IOException;

}
23 changes: 15 additions & 8 deletions src/main/java/com/amihaiemil/docker/RtContainer.java
Expand Up @@ -32,6 +32,7 @@
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicHeader;

/**
* Restful Container.
Expand Down Expand Up @@ -232,19 +233,25 @@ public void unpause() throws IOException {
}

@Override
public void waitOn(final String state) throws IOException {
String end = "";
public int waitOn(final String state) throws IOException {
UncheckedUriBuilder urib = new UncheckedUriBuilder(
this.baseUri.toString().concat("/wait")
);
if(null == state || state.isEmpty()){
end = String.format("?condition=%s", state);
urib.addParameter("condition", state);
}
final HttpPost waiter = new HttpPost(
this.baseUri.toString() + "/wait" + end
);

final HttpPost waiter = new HttpPost(urib.build());
waiter.setHeader(new BasicHeader("Content-Type", "application/json"));

try {
this.client.execute(
final JsonObject json = this.client.execute(
waiter,
new MatchStatus(waiter.getURI(), HttpStatus.SC_OK)
new ReadJsonObject(
new MatchStatus(waiter.getURI(), HttpStatus.SC_OK)
)
);
return json.getInt("StatusCode");
} finally {
waiter.releaseConnection();
}
Expand Down

0 comments on commit 8591519

Please sign in to comment.