use of com.reprezen.kaizen.oasparser.model3.RequestBody in project Manhua by ag2s20150909.
the class GzipRequestInterceptor method gzip.
private RequestBody gzip(final RequestBody body) {
return new RequestBody() {
@Override
public MediaType contentType() {
return body.contentType();
}
@Override
public long contentLength() {
// 无法知道压缩后的数据大小
return -1;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
body.writeTo(gzipSink);
gzipSink.close();
}
};
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project lzc_app_lib by httplzc.
the class OkHttpCallFactory method transToBody.
private RequestBody transToBody(MultipartFormParams params) {
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
for (Map.Entry<String, String> entry : params.getUrlParams().entrySet()) {
multipartBuilder.addFormDataPart(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, MultipleData[]> entry : params.getMultipartDatas().entrySet()) {
if (entry.getValue() != null) {
for (MultipleData multipleData : entry.getValue()) {
RequestBody requestBody = transToBody(multipleData.binaryData);
if (requestBody != null)
multipartBuilder.addFormDataPart(entry.getKey(), multipleData.name, requestBody);
}
}
}
return multipartBuilder.build();
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project lzc_app_lib by httplzc.
the class OkHttpCallFactory method transToRequest.
private Request transToRequest(RequestData requestData) {
String url = requestData.url;
BaseParams params = requestData.params;
HttpMethod method = requestData.method;
HttpUrl httpUrl = HttpUrl.parse(url);
Objects.requireNonNull(httpUrl);
Request.Builder requestBuilder = new Request.Builder();
requestBuilder.headers(Headers.of(params.getHeads()));
RequestBody body = null;
if (method == HttpMethod.GET || method == HttpMethod.HEAD) {
if (!(params instanceof FormParams))
throw new IllegalArgumentException(method.name() + "只能为表单数据");
httpUrl = paramsToHttpUrl(httpUrl, (FormParams) params);
} else {
if (params instanceof RawParams) {
body = transToBody(((RawParams) params).getBinaryData());
} else if (params instanceof MultipartFormParams) {
body = transToBody((MultipartFormParams) params);
} else if (params instanceof FormParams) {
body = transToBody((FormParams) params);
}
}
if (body != null)
body = new ProxyRequestBody(body, requestData.uploadProgress);
return requestBuilder.url(httpUrl).method(method.name(), body).build();
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project fineract by apache.
the class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl method okHttpConnectionMethod.
@Transactional
@Override
@SuppressWarnings("deprecation")
public String okHttpConnectionMethod(String userName, String password, String subscriptionKey, String subscriptionId, String url, String token, File file, FormDataContentDisposition fileData, Long uniqueId, String nrcId, String process) {
String reponseMessage = null;
RequestBody requestBody = null;
OkHttpClient client = new OkHttpClient();
if (process.equals("UploadCreditReport")) {
String fileName = fileData.getFileName();
requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("file", fileName, requestBody).addFormDataPart("BODY", "formdata").addFormDataPart("userName", userName).build();
} else if (process.equals("token")) {
final MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
String jsonBody = "" + "BODY=x-www-form-urlencoded&\r" + "grant_type=password&\r" + "userName=" + userName + "&\r" + "password=" + password + "&\r";
requestBody = RequestBody.create(jsonBody, mediaType);
} else if (process.equals("NRC")) {
final MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
String jsonBody = "BODY=x-www-form-urlencoded&nrc=" + nrcId + "&";
requestBody = RequestBody.create(jsonBody, mediaType);
}
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
String urlokhttp = urlBuilder.build().toString();
Request request = null;
if (token == null) {
request = new Request.Builder().header("mcix-subscription-key", subscriptionKey).header("mcix-subscription-id", subscriptionId).header("Content-Type", "application/x-www-form-urlencoded").url(urlokhttp).post(requestBody).build();
}
if (token != null) {
if (process.equals("CreditReport")) {
// GET method for fetching credit report
request = new Request.Builder().header("mcix-subscription-key", subscriptionKey).header("mcix-subscription-id", subscriptionId).header("Content-Type", "application/x-www-form-urlencoded").header("Authorization", "Bearer " + token).url(urlokhttp).get().build();
} else if (process.equals("UploadCreditReport")) {
// POST for uploading Credit-Report(multipart/form-data)
// To ThitsaWork
request = new Request.Builder().header("mcix-subscription-key", subscriptionKey).header("mcix-subscription-id", subscriptionId).header("Content-Type", "multipart/form-data").header("Authorization", "Bearer " + token).url(urlokhttp).post(requestBody).build();
} else {
// POST method for application/x-www-form-urlencoded
request = new Request.Builder().header("mcix-subscription-key", subscriptionKey).header("mcix-subscription-id", subscriptionId).header("Content-Type", "application/x-www-form-urlencoded").header("Authorization", "Bearer " + token).url(urlokhttp).post(requestBody).build();
}
}
Response response;
Integer responseCode = 0;
try {
response = client.newCall(request).execute();
responseCode = response.code();
reponseMessage = response.body().string();
} catch (IOException e) {
LOG.error("error occured in HTTP request-response method.", e);
}
if (responseCode != HttpURLConnection.HTTP_OK) {
this.httpResponse(responseCode, reponseMessage);
}
if (process.equals("UploadCreditReport")) {
// to show the Response on frontEnd
JsonObject reportObject = JsonParser.parseString(reponseMessage).getAsJsonObject();
String ResponseMessageJson = reportObject.get("ResponseMessage").getAsString();
this.handleAPIIntegrityIssues(ResponseMessageJson);
}
return reponseMessage;
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project gim-plugin by davidvorona.
the class HttpClient method broadcast.
/**
* Makes an HTTP POST request to the broadcast endpoint at the
* URL injected from the plugin config. The JSON data is sent
* in the request body. Times out after 5 seconds.
*
* @param dataJson request data in JSON
* @throws IOException if request fails
*/
public void broadcast(String dataJson) throws IOException {
RequestBody body = RequestBody.create(JSON, dataJson);
Request request = new Request.Builder().url(getBaseUrl() + "/broadcast/" + namespace).post(body).build();
Response response = client.newCall(request).execute();
ResponseBody bodyJson = response.body();
if (bodyJson != null) {
logHttpResponse(response.code(), bodyJson.string());
}
}
Aggregations