use of com.reprezen.kaizen.oasparser.model3.RequestBody in project incubator-inlong by apache.
the class InnerInlongManagerClient method createSink.
public String createSink(SinkRequest sinkRequest) {
String path = HTTP_PATH + "/sink/save";
final String sink = GsonUtil.toJson(sinkRequest);
final RequestBody sinkBody = RequestBody.create(MediaType.parse("application/json"), sink);
final String url = formatUrl(path);
Request request = new Request.Builder().url(url).method("POST", sinkBody).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 sink save failed: %s", e.getMessage()), e);
}
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project incubator-inlong by apache.
the class InnerInlongManagerClient method updateSource.
public Pair<Boolean, String> updateSource(SourceRequest sourceRequest) {
final String path = HTTP_PATH + "/source/update";
final String url = formatUrl(path);
final String storage = GsonUtil.toJson(sourceRequest);
final RequestBody storageBody = RequestBody.create(MediaType.parse("application/json"), storage);
Request request = new Request.Builder().method("POST", storageBody).url(url).build();
Call call = httpClient.newCall(request);
try {
Response response = call.execute();
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);
if (responseBody.getData() != null) {
return Pair.of(Boolean.valueOf(responseBody.getData().toString()), responseBody.getErrMsg());
} else {
return Pair.of(false, responseBody.getErrMsg());
}
} catch (Exception e) {
throw new RuntimeException(String.format("Inlong source update failed with ex:%s", e.getMessage()), e);
}
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project incubator-inlong by apache.
the class InnerInlongManagerClient method listGroups.
public PageInfo<InlongGroupListResponse> listGroups(String keyword, int status, int pageNum, int pageSize) {
if (pageNum <= 0) {
pageNum = 1;
}
JSONObject groupQuery = new JSONObject();
groupQuery.put("keyWord", pageNum);
groupQuery.put("status", status);
groupQuery.put("pageNum", pageNum);
groupQuery.put("pageSize", pageSize);
String operationData = GsonUtil.toJson(groupQuery);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), operationData);
String path = HTTP_PATH + "/group/list";
final String url = formatUrl(path);
Request request = new Request.Builder().get().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);
if (responseBody.getErrMsg() != null) {
if (responseBody.getErrMsg().contains("Inlong group does not exist")) {
return null;
} else {
throw new RuntimeException(responseBody.getErrMsg());
}
} else {
return InlongParser.parseGroupList(responseBody);
}
} catch (Exception e) {
throw new RuntimeException(String.format("Inlong group get failed: %s", e.getMessage()), e);
}
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project incubator-shenyu by apache.
the class HttpTestControllerTest method testUpload.
@Test
public void testUpload() throws IOException {
File uploadFile = File.createTempFile(String.valueOf(System.currentTimeMillis()), "-uploadFile.txt");
try (FileOutputStream fos = new FileOutputStream(uploadFile)) {
fos.write("testContent".getBytes(StandardCharsets.UTF_8));
}
RequestBody requestBody = new MultipartBody.Builder().setType(MediaType.parse(MULTIPART_FORM_DATA_VALUE)).addFormDataPart("file", uploadFile.getName(), RequestBody.create(MediaType.parse(APPLICATION_OCTET_STREAM_VALUE), uploadFile)).build();
String ret = HttpHelper.INSTANCE.postGateway("/http/test/upload", requestBody, String.class);
assertEquals(ret, "OK");
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project msgraph-sdk-java-core by microsoftgraph.
the class CoreHttpProviderTests method getHttpRequestWithTextPlainBodyDoesNotSerializeAsJson.
@Test
void getHttpRequestWithTextPlainBodyDoesNotSerializeAsJson() throws IOException {
final IHttpRequest absRequest = mock(IHttpRequest.class);
when(absRequest.getRequestUrl()).thenReturn(new URL("https://graph.microsoft.com/v1.0/me"));
when(absRequest.getHttpMethod()).thenReturn(HttpMethod.POST);
final ISerializer serializer = mock(ISerializer.class);
final ILogger logger = mock(ILogger.class);
mProvider = new CoreHttpProvider(serializer, logger, new OkHttpClient.Builder().build());
// GIVEN: A "text/plain" request body
final HeaderOption option = new HeaderOption("Content-Type", "text/plain");
when(absRequest.getHeaders()).thenReturn(Arrays.asList(option));
final String expectedBody = "Plain String Body";
// WHEN: getHttpRequest is called
final Request request = mProvider.getHttpRequest(absRequest, String.class, expectedBody);
// THEN: The serializer must not be called
verify(serializer, never()).serializeObject(Mockito.any());
// AND: We expect the request body to contain the plain String, not serialized as Json
final Buffer buffer = new Buffer();
final RequestBody requestBody = request.body();
assertNotNull(requestBody);
requestBody.writeTo(buffer);
final String actualRequestBody = buffer.readUtf8();
assertEquals(expectedBody, actualRequestBody);
}
Aggregations