List of usage examples for com.squareup.okhttp RequestBody create
public static RequestBody create(final MediaType contentType, final File file)
From source file:io.fabric8.docker.client.impl.ContainerNamedOperationImpl.java
License:Apache License
@Override public ContainerExecCreateResponse exec(ExecConfig execConfig) { try {//from www . j a v a 2s . co m StringBuilder sb = new StringBuilder(); sb.append(getOperationUrl(EXEC_OPERATION)); RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, JSON_MAPPER.writeValueAsString(execConfig)); Request.Builder builder = new Request.Builder().post(body).url(sb.toString()); return handleResponse(builder, ContainerExecCreateResponse.class, 200, 201); } catch (Exception e) { throw DockerClientException.launderThrowable(e); } }
From source file:io.fabric8.docker.client.impl.ExecNamedOperationImpl.java
License:Apache License
public Boolean start(ExecStartCheck config) { try {/*from w w w .ja va 2s .com*/ StringBuilder sb = new StringBuilder(); sb.append(getResourceUrl()); RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, JSON_MAPPER.writeValueAsString(config)); Request.Builder requestBuilder = new Request.Builder().post(body) .url(URLUtils.join(getResourceUrl().toString(), START_OPERATION)); handleResponse(requestBuilder, 200); return true; } catch (Exception e) { throw DockerClientException.launderThrowable(e); } }
From source file:io.fabric8.docker.client.impl.ImageNamedOperationImpl.java
License:Apache License
public Boolean load(String path) { try {// w w w. j a v a2 s . co m StringBuilder sb = new StringBuilder() .append(URLUtils.join(getRootUrl().toString(), LOAD_OPERATION).toString()); RequestBody body = RequestBody.create(MEDIA_TYPE_TAR, new File(path)); Request request = new Request.Builder().post(body).url(sb.toString()).build(); Response response = client.newCall(request).execute(); return response.isSuccessful(); } catch (Exception e) { throw DockerClientException.launderThrowable(e); } }
From source file:io.fabric8.docker.client.impl.ImageOperationImpl.java
License:Apache License
public Boolean load(String path) { try {//from ww w . ja v a 2s.c om StringBuilder sb = new StringBuilder() .append(URLUtils.join(getRootUrl().toString(), "load").toString()); RequestBody body = RequestBody.create(MEDIA_TYPE_TAR, new File(path)); Request request = new Request.Builder().post(body).url(sb.toString()).build(); Response response = client.newCall(request).execute(); return response.isSuccessful(); } catch (Exception e) { throw DockerClientException.launderThrowable(e); } }
From source file:io.fabric8.docker.client.impl.ImportImage.java
License:Apache License
@Override public OutputHandle asRepo(String src) { try {//from w w w . ja v a 2s. c o m StringBuilder sb = new StringBuilder().append(getOperationUrl(CREATE_OPERATION)); if (Utils.isNotNullOrEmpty(tag)) { sb.append(Q).append(TAG).append(EQUALS).append(tag); } AuthConfig authConfig = RegistryUtils.getConfigForImage(name, config); Request request = new Request.Builder() .header("X-Registry-Auth", new String(Base64.encodeBase64(JSON_MAPPER .writeValueAsString(authConfig != null ? authConfig : new AuthConfig()) .getBytes("UTF-8")), "UTF-8")) .post(RequestBody.create(MEDIA_TYPE_TEXT, EMPTY)).url(sb.toString()).build(); OkHttpClient clone = client.clone(); clone.setReadTimeout(0, TimeUnit.MILLISECONDS); ImportImageHandle handle = new ImportImageHandle(out, config.getImagePushTimeout(), TimeUnit.MILLISECONDS, listener); clone.newCall(request).enqueue(handle); return handle; } catch (Exception e) { throw DockerClientException.launderThrowable(e); } }
From source file:io.fabric8.docker.client.impl.NetworkNamedOperationImpl.java
License:Apache License
private Boolean containerOp(String containerId, String opertaionType) { try {/*from w w w. j av a 2s . c o m*/ RequestBody body = RequestBody.create(MEDIA_TYPE_TEXT, EMPTY); Request.Builder requestBuilder = new Request.Builder().post(body) .url(new StringBuilder().append(getOperationUrl(opertaionType)).append(Q).append(CONTAINER) .append(EQUALS).append(containerId).toString()); handleResponse(requestBuilder, 201); return true; } catch (Exception e) { throw DockerClientException.launderThrowable(e); } }
From source file:io.fabric8.docker.client.impl.OperationSupport.java
License:Apache License
public <T> void handleCreate(T resource) throws ExecutionException, InterruptedException, DockerClientException, IOException { RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, JSON_MAPPER.writeValueAsString(resource)); Request.Builder requestBuilder = new Request.Builder().post(body).url(getResourceUrl().toString()); handleResponse(requestBuilder, 200, 201, 204); }
From source file:io.fabric8.docker.client.impl.OperationSupport.java
License:Apache License
public <T, I> T handleCreate(I resource, Class<T> outputType, String... dirs) throws ExecutionException, InterruptedException, DockerClientException, IOException { RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, JSON_MAPPER.writeValueAsString(resource)); Request.Builder requestBuilder = new Request.Builder().post(body) .url(URLUtils.join(getResourceUrl().toString(), URLUtils.join(dirs))); return handleResponse(requestBuilder, outputType, 200, 201, 204); }
From source file:io.fabric8.docker.client.impl.PullImage.java
License:Apache License
@Override public OutputHandle fromRegistry() { try {//from w w w . j a v a 2 s .com StringBuilder sb = new StringBuilder().append(getOperationUrl(CREATE_OPERATION)).append(Q) .append(FROM_IMAGE).append(EQUALS).append(name); if (Utils.isNotNullOrEmpty(tag)) { sb.append(A).append(TAG).append(EQUALS).append(tag); } AuthConfig authConfig = RegistryUtils.getConfigForImage(name, config); Request request = new Request.Builder() .header("X-Registry-Auth", new String(Base64.encodeBase64(JSON_MAPPER .writeValueAsString(authConfig != null ? authConfig : new AuthConfig()) .getBytes("UTF-8")), "UTF-8")) .post(RequestBody.create(MEDIA_TYPE_TEXT, EMPTY)).url(sb.toString()).build(); OkHttpClient clone = client.clone(); clone.setReadTimeout(config.getImagePullTimeout(), TimeUnit.MILLISECONDS); PullImageHandle handle = new PullImageHandle(out, config.getImagePushTimeout(), TimeUnit.MILLISECONDS, listener); clone.newCall(request).enqueue(handle); return handle; } catch (Exception e) { throw DockerClientException.launderThrowable(e); } }
From source file:io.fabric8.docker.client.impl.PushImage.java
License:Apache License
@Override public OutputHandle toRegistry() { try {/*from ww w . j av a 2 s. co m*/ StringBuilder sb = new StringBuilder().append(getOperationUrl(PUSH_OPERATION)); sb.append(Q).append(FORCE).append(EQUALS).append(force); if (Utils.isNotNullOrEmpty(tag)) { sb.append(A).append(TAG).append(EQUALS).append(tag); } AuthConfig authConfig = RegistryUtils.getConfigForImage(name, config); RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, "{}"); Request request = new Request.Builder() .header("X-Registry-Auth", new String(Base64.encodeBase64(JSON_MAPPER .writeValueAsString(authConfig != null ? authConfig : new AuthConfig()) .getBytes("UTF-8")), "UTF-8")) .post(body).url(sb.toString()).build(); OkHttpClient clone = client.clone(); clone.setReadTimeout(config.getImagePushTimeout(), TimeUnit.MILLISECONDS); PushImageHandle handle = new PushImageHandle(out, config.getImagePushTimeout(), TimeUnit.MILLISECONDS, listener); clone.newCall(request).enqueue(handle); return handle; } catch (Exception e) { throw DockerClientException.launderThrowable(e); } }