use of com.reprezen.kaizen.oasparser.model3.MediaType 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.MediaType in project Shitter by nuclearfog.
the class Twitter method downloadImage.
/**
* download image from twitter
*
* @param link link to the image
* @return image bitmap
*/
public MediaStream downloadImage(String link) throws TwitterException {
try {
// this type of link requires authentication
if (link.startsWith(DOWNLOAD)) {
Response response = get(link, new ArrayList<>(0));
if (response.code() == 200 && response.body() != null) {
MediaType type = response.body().contentType();
if (type != null) {
String mime = type.toString();
InputStream stream = response.body().byteStream();
return new MediaStream(stream, mime);
}
}
throw new TwitterException(response);
} else // public link, no authentication required
{
Request request = new Request.Builder().url(link).get().build();
Response response = client.newCall(request).execute();
if (response.code() == 200 && response.body() != null) {
MediaType type = response.body().contentType();
if (type != null) {
String mime = type.toString();
InputStream stream = response.body().byteStream();
return new MediaStream(stream, mime);
}
}
throw new TwitterException(response);
}
} catch (IOException e) {
throw new TwitterException(e);
}
}
use of com.reprezen.kaizen.oasparser.model3.MediaType in project files-sdk-java by Files-com.
the class FilesOkHttpApi method putBufferedInputStream.
@Override
public long putBufferedInputStream(String url, HttpMethods.RequestMethods requestType, String name, BufferedInputStream inputStream) throws IOException {
String uri = ModelUtils.forceMandatoryUriEncode(url);
MediaType type = MediaType.parse("application/octet-stream");
Request.Builder request = new Request.Builder();
request.addHeader("Content-type", "application/octet-stream");
request.url(uri);
RequestBody body = create(type, inputStream);
updateRequestWithHttpMethod(request, body, requestType);
Response response = FilesHttpClient.getHttpClient().newCall(request.build()).execute();
return 0;
}
use of com.reprezen.kaizen.oasparser.model3.MediaType in project che-server by eclipse-che.
the class DirectKubernetesAPIAccessHelper method convertResponseBody.
private static void convertResponseBody(Response.ResponseBuilder responseBuilder, okhttp3.Response response) {
ResponseBody responseBody = response.body();
if (responseBody != null) {
responseBuilder.entity(responseBody.byteStream());
MediaType contentType = responseBody.contentType();
if (contentType != null) {
responseBuilder.type(contentType.toString());
}
}
}
use of com.reprezen.kaizen.oasparser.model3.MediaType in project xray-maven-plugin by Xray-App.
the class XrayResultsImporter method submitStandardCloud.
public String submitStandardCloud(String format, String reportFile) throws Exception {
OkHttpClient client = CommonUtils.getHttpClient(useInternalTestProxy, ignoreSslErrors, this.timeout);
String authenticationPayload = "{ \"client_id\": \"" + clientId + "\", \"client_secret\": \"" + clientSecret + "\" }";
RequestBody body = RequestBody.create(authenticationPayload, MEDIA_TYPE_JSON);
Request request = new Request.Builder().url(xrayCloudAuthenticateUrl).post(body).build();
Response response = null;
String authToken = null;
try {
response = client.newCall(request).execute();
String responseBody = response.body().string();
if (response.isSuccessful()) {
authToken = responseBody.replace("\"", "");
} else {
throw new IOException("failed to authenticate " + response);
}
} catch (IOException e) {
e.printStackTrace();
throw e;
}
String credentials = "Bearer " + authToken;
String[] supportedFormats = new String[] { XRAY_FORMAT, JUNIT_FORMAT, TESTNG_FORMAT, ROBOT_FORMAT, NUNIT_FORMAT, XUNIT_FORMAT, CUCUMBER_FORMAT };
if (!Arrays.asList(supportedFormats).contains(format)) {
throw new Exception("unsupported report format: " + format);
}
MediaType mediaType;
String[] xmlBasedFormats = new String[] { JUNIT_FORMAT, TESTNG_FORMAT, ROBOT_FORMAT, NUNIT_FORMAT, XUNIT_FORMAT };
if (Arrays.asList(xmlBasedFormats).contains(format)) {
mediaType = MEDIA_TYPE_XML;
} else {
mediaType = MEDIA_TYPE_JSON;
}
String endpointUrl;
if (XRAY_FORMAT.equals(format)) {
endpointUrl = xrayCloudApiBaseUrl + "/import/execution";
} else {
endpointUrl = xrayCloudApiBaseUrl + "/import/execution/" + format;
}
RequestBody requestBody = null;
try {
String reportContent = new String(Files.readAllBytes(Paths.get(reportFile)));
requestBody = RequestBody.create(reportContent, mediaType);
} catch (Exception e1) {
e1.printStackTrace();
throw e1;
}
HttpUrl url = HttpUrl.get(endpointUrl);
HttpUrl.Builder builder = url.newBuilder();
if (projectKey != null) {
builder.addQueryParameter("projectKey", this.projectKey);
}
if (fixVersion != null) {
builder.addQueryParameter("fixVersion", this.fixVersion);
}
if (revision != null) {
builder.addQueryParameter("revision", this.revision);
}
if (testPlanKey != null) {
builder.addQueryParameter("testPlanKey", this.testPlanKey);
}
if (testExecKey != null) {
builder.addQueryParameter("testExecKey", this.testExecKey);
}
if (testEnvironment != null) {
builder.addQueryParameter("testEnvironment", this.testEnvironment);
}
request = new Request.Builder().url(builder.build()).post(requestBody).addHeader("Authorization", credentials).build();
try {
response = client.newCall(request).execute();
String responseBody = response.body().string();
if (response.isSuccessful()) {
JSONObject responseObj = new JSONObject(responseBody);
// System.out.println("Test Execution: "+((JSONObject)(responseObj.get("testExecIssue"))).get("key"));
return (responseBody);
} else {
// System.err.println(responseBody);
throw new IOException("Unexpected HTTP code " + response);
}
} catch (IOException e) {
e.printStackTrace();
throw e;
}
}
Aggregations