use of com.reprezen.kaizen.oasparser.model3.RequestBody in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class OkHttp3ClientHttpRequestFactory method buildRequest.
static Request buildRequest(HttpHeaders headers, byte[] content, URI uri, HttpMethod method) throws MalformedURLException {
okhttp3.MediaType contentType = getContentType(headers);
RequestBody body = (content.length > 0 || okhttp3.internal.http.HttpMethod.requiresRequestBody(method.name()) ? RequestBody.create(contentType, content) : null);
Request.Builder builder = new Request.Builder().url(uri.toURL()).method(method.name(), body);
headers.forEach((headerName, headerValues) -> {
for (String headerValue : headerValues) {
builder.addHeader(headerName, headerValue);
}
});
return builder.build();
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project AnkiChinaAndroid by ankichinateam.
the class AnkiChinaSyncer method uploadLocalMediaFileInfo.
/**
* 上传媒体文件信息给服务端,服务端比对完后下发文件的同步结果
*/
private void uploadLocalMediaFileInfo(String token) {
// 获取本地media文件夹的目录
updateDialogProgress(SYNCING_MEDIA, "", 1);
File mediaDir = new File(Media.getCollectionMediaPath(CollectionHelper.getInstance().getColSafe(AnkiDroidApp.getInstance()).getPath()));
// if (!mediaDir.exists()) {
// return;
// }
File[] files = mediaDir.listFiles();
// if (files.length == 0) {
// return;
// }
String[] localFiles = new String[files.length];
for (int i = 0; i < files.length; i++) {
localFiles[i] = files[i].getName();
}
JSONArray filesJson = new JSONArray(localFiles);
// Timber.i("local file list:%s", filesJson);
RequestBody formBody = new FormBody.Builder().add("file_list", filesJson.toString()).build();
updateDialogProgress(SYNCING_MEDIA, "", 5);
if (mCancel) {
return;
}
OKHttpUtil.post(Consts.ANKI_CHINA_BASE + Consts.API_VERSION + "napi/sync/postFileInfo", formBody, token, "", new OKHttpUtil.MyCallBack() {
@Override
public void onFailure(Call call, IOException e) {
updateDialogMessage(SYNCING_ERROR, ERROR_NETWORK);
}
@Override
public void onResponse(Call call, String token, Object arg1, Response response) throws IOException {
if (response.isSuccessful()) {
Timber.e("upload media file info succeed!");
try {
final JSONObject object = new JSONObject(response.body().string());
Timber.e("fetch media sync info from server:%s", object.toString());
if (object.getInt("status_code") != 0) {
updateDialogMessage(SYNCING_ERROR, object.getString("message"));
return;
}
final JSONObject item = object.getJSONObject("data");
updateDialogProgress(SYNCING_MEDIA, "", 10);
handleMediaSync(item, token);
} catch (Exception e) {
e.printStackTrace();
}
} else {
Timber.e("upload media file info error, code %d", response.code());
}
}
});
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project incubator-inlong by apache.
the class InnerInlongManagerClient method operateInlongGroup.
public boolean operateInlongGroup(String groupId, InlongGroupState status) {
String path = HTTP_PATH;
if (status == InlongGroupState.STOPPED) {
path += "/group/suspendProcess/";
} else if (status == InlongGroupState.STARTED) {
path += "/group/restartProcess/";
} else {
throw new IllegalArgumentException(String.format("Unsupported state: %s", status));
}
path += groupId;
final String url = formatUrl(path);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), "");
Request request = new Request.Builder().url(url).method("POST", requestBody).build();
Call call = httpClient.newCall(request);
try {
Response response = call.execute();
assert response.body() != null;
String body = response.body().string();
AssertUtil.isTrue(response.isSuccessful(), String.format("Inlong request failed: %s", body));
org.apache.inlong.manager.common.beans.Response responseBody = InlongParser.parseResponse(body);
String errMsg = responseBody.getErrMsg();
return errMsg == null || !errMsg.contains("current status was not allowed");
} catch (Exception e) {
throw new RuntimeException(String.format("Inlong group operate: %s failed with ex: %s", status, e.getMessage()), e);
}
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project incubator-inlong by apache.
the class InnerInlongManagerClient method createStreamInfo.
public String createStreamInfo(InlongStreamInfo streamInfo) {
String path = HTTP_PATH + "/stream/save";
final String stream = GsonUtil.toJson(streamInfo);
final RequestBody streamBody = RequestBody.create(MediaType.parse("application/json"), stream);
final String url = formatUrl(path);
Request request = new Request.Builder().url(url).method("POST", streamBody).build();
Call call = httpClient.newCall(request);
try {
Response response = call.execute();
assert response.body() != null;
String body = response.body().string();
AssertUtil.isTrue(response.isSuccessful(), String.format("Inlong request failed: %s", body));
org.apache.inlong.manager.common.beans.Response responseBody = InlongParser.parseResponse(body);
AssertUtil.isTrue(responseBody.getErrMsg() == null, String.format("Inlong request failed: %s", responseBody.getErrMsg()));
return responseBody.getData().toString();
} catch (Exception e) {
throw new RuntimeException(String.format("Inlong stream save failed: %s", e.getMessage()), e);
}
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project incubator-inlong by apache.
the class InnerInlongManagerClient method startInlongGroup.
public WorkflowResult startInlongGroup(int taskId, Pair<InlongGroupApproveRequest, List<InlongStreamApproveRequest>> initMsg) {
JSONObject workflowTaskOperation = new JSONObject();
workflowTaskOperation.put("transferTo", Lists.newArrayList());
workflowTaskOperation.put("remark", "approved by system");
JSONObject inlongGroupApproveForm = new JSONObject();
inlongGroupApproveForm.put("groupApproveInfo", initMsg.getKey());
inlongGroupApproveForm.put("streamApproveInfoList", initMsg.getValue());
inlongGroupApproveForm.put("formName", "InlongGroupApproveForm");
workflowTaskOperation.put("form", inlongGroupApproveForm);
String operationData = GsonUtil.toJson(workflowTaskOperation);
final String path = HTTP_PATH + "/workflow/approve/" + taskId;
final String url = formatUrl(path);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), operationData);
Request request = new Request.Builder().url(url).method("POST", requestBody).build();
Call call = httpClient.newCall(request);
try {
Response response = call.execute();
assert response.body() != null;
String body = response.body().string();
AssertUtil.isTrue(response.isSuccessful(), String.format("Inlong request failed: %s", body));
org.apache.inlong.manager.common.beans.Response responseBody = InlongParser.parseResponse(body);
AssertUtil.isTrue(responseBody.getErrMsg() == null, String.format("Inlong request failed: %s", responseBody.getErrMsg()));
return InlongParser.parseWorkflowResult(responseBody);
} catch (Exception e) {
throw new RuntimeException(String.format("Inlong group start failed: %s", e.getMessage()), e);
}
}
Aggregations