use of com.reprezen.kaizen.oasparser.model3.MediaType in project CipherTrust_Application_Protection by thalescpl-io.
the class CipherTrustManagerHelper method getTokenFromRefresh.
/**
* Returns an String that will be a JWT token to be used for REST calls
* based on the refresh token.
* <p>
* Note: This is using a Java KeyStore for authentication.
*
* @param keystorepwd
* password to the java keystore
* @param keystorelocation
* location of javakeystore that contains certificates
* @return string JWT token
*/
public String getTokenFromRefresh(String keystorepwd, String keystorelocation) throws IOException {
OkHttpClient client = getOkHttpClient(keystorepwd, this.cmipaddress, keystorelocation);
MediaType mediaType = MediaType.parse("application/json");
String grant_typetag = "{\"grant_type\":";
String grant_type = "refresh_token";
String refreshtokentag = "\"refresh_token\":";
String authcall = grant_typetag + quote + grant_type + quote + comma + refreshtokentag + quote + this.refreshtoken + quote + " }";
RequestBody body = RequestBody.create(authcall, mediaType);
Request request = new Request.Builder().url("https://" + this.cmipaddress + "/api/v1/auth/tokens").method("POST", body).addHeader("Content-Type", "application/json").build();
Response response = client.newCall(request).execute();
String returnvalue = response.body().string();
String jwt = JsonPath.read(returnvalue.toString(), "$.jwt").toString();
return jwt;
}
use of com.reprezen.kaizen.oasparser.model3.MediaType in project CipherTrust_Application_Protection by thalescpl-io.
the class CipherTrustManagerHelper method getTokenFromRefresh.
/**
* Returns an String that will be a JWT token to be used for REST calls
* based on the refresh token.
* <p>
* Note: This is not using a Java KeyStore for authentication.
*
* @return string JWT token
*/
public String getTokenFromRefresh() throws IOException {
OkHttpClient client = getUnsafeOkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
String grant_typetag = "{\"grant_type\":";
String grant_type = "refresh_token";
String refreshtokentag = "\"refresh_token\":";
String authcall = grant_typetag + quote + grant_type + quote + comma + refreshtokentag + quote + this.refreshtoken + quote + " }";
RequestBody body = RequestBody.create(authcall, mediaType);
Request request = new Request.Builder().url("https://" + this.cmipaddress + "/api/v1/auth/tokens").method("POST", body).addHeader("Content-Type", "application/json").build();
Response response = client.newCall(request).execute();
String returnvalue = response.body().string();
String jwt = JsonPath.read(returnvalue.toString(), "$.jwt").toString();
return jwt;
}
use of com.reprezen.kaizen.oasparser.model3.MediaType in project CipherTrust_Application_Protection by thalescpl-io.
the class CipherTrustManagerHelper method getToken.
/**
* Returns an String that will be a JWT token to be used for REST calls.
* <p>
* Note: This is using a Java KeyStore for authentication.
*
* @param keystorepwd
* password to the java keystore
* @param keystorelocation
* location of javakeystore that contains certificates
* @return string JWT token
*/
public String getToken(String keystorepwd, String keystorelocation) throws IOException {
this.keystorepwd = keystorepwd;
OkHttpClient client = getOkHttpClient(keystorepwd, this.cmipaddress, keystorelocation);
MediaType mediaType = MediaType.parse("application/json");
String grant_typetag = "{\"grant_type\":";
String grant_type = "password";
String passwordtag = "\"password\":";
String usernametag = "\"username\":";
String labels = "\"labels\": [\"myapp\",\"cli\"]}";
String authcall = grant_typetag + quote + grant_type + quote + comma + usernametag + quote + this.username + quote + comma + passwordtag + quote + this.password + quote + comma + labels;
RequestBody body = RequestBody.create(authcall, mediaType);
Request request = new Request.Builder().url("https://" + this.cmipaddress + "/api/v1/auth/tokens").method("POST", body).addHeader("Content-Type", "application/json").build();
Response response = client.newCall(request).execute();
String returnvalue = response.body().string();
String jwt = JsonPath.read(returnvalue.toString(), "$.jwt").toString();
this.refreshtoken = JsonPath.read(returnvalue.toString(), "$.refresh_token").toString();
this.token = jwt;
return jwt;
}
use of com.reprezen.kaizen.oasparser.model3.MediaType in project spacecraft-android by JamesfChen.
the class ResponseTest method error.
@Test
public void error() {
MediaType plainText = MediaType.get("text/plain; charset=utf-8");
ResponseBody errorBody = ResponseBody.create(plainText, "Broken!");
Response<?> response = Response.error(400, errorBody);
assertThat(response.raw()).isNotNull();
assertThat(response.raw().body().contentType()).isEqualTo(plainText);
assertThat(response.raw().body().contentLength()).isEqualTo(7);
try {
response.raw().body().source();
fail();
} catch (IllegalStateException expected) {
}
assertThat(response.code()).isEqualTo(400);
assertThat(response.message()).isEqualTo("Response.error()");
assertThat(response.headers().size()).isZero();
assertThat(response.isSuccessful()).isFalse();
assertThat(response.body()).isNull();
assertThat(response.errorBody()).isSameAs(errorBody);
}
use of com.reprezen.kaizen.oasparser.model3.MediaType in project nylas-java by nylas.
the class HttpLoggingInterceptor method logRequest.
private void logRequest(Request request) throws IOException {
RequestBody requestBody = request.body();
boolean hasBody = requestBody != null;
// Summary
if (requestLogs.isDebugEnabled()) {
requestLogs.debug("=> " + request.method() + " " + request.url() + " reqBodySize=" + (hasBody ? requestBody.contentLength() : 0));
}
logHeaders("=>", request.headers());
if (bodyLogs.isDebugEnabled()) {
String message;
if (!hasBody) {
message = " No request body";
} else {
MediaType contentType = requestBody.contentType();
if (!isPrintableMediaType(contentType)) {
message = " Skipped logging request body of type that may not be printable: " + contentType;
} else {
Buffer buf = new Buffer();
requestBody.writeTo(buf);
message = bodyBufferToString("", buf, contentType);
}
}
bodyLogs.debug("=>" + message);
}
}
Aggregations