use of net.cryptonomica.returns.StringWrapperObject in project cryptonomica by Cryptonomica.
the class EthNodeAPI method requestTestingServlet.
@ApiMethod(name = "requestTestingServlet", path = "requestTestingServlet", httpMethod = ApiMethod.HttpMethod.POST)
@SuppressWarnings("unused")
public StringWrapperObject requestTestingServlet(final User googleUser) throws IllegalArgumentException, UnauthorizedException {
// (!) for Cryptonomica officers only:
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaOfficer(googleUser);
String urlHost = "https://tomcatweb3j.cryptonomica.net";
String urlPath = "/TestingServlet";
String urlAddress = urlHost + urlPath;
String postRequestBody = "testBodyParameterName=" + "testBodyParameterValue";
String headerName = "testHeaderName";
String heaserValue = "testHeaderValue";
// (!!!!) DO NOT USE API KEY IN TEST REQUEST
HTTPResponse httpResponse = HttpService.postRequestWithCustomHeader(urlAddress, postRequestBody, headerName, heaserValue);
// LOG.warning("httpResponse: " + new Gson().toJson(httpResponse));
byte[] httpResponseContentBytes = httpResponse.getContent();
String httpResponseContentString = new String(httpResponseContentBytes, StandardCharsets.UTF_8);
// Test:
// Object resObj = new Gson().fromJson(httpResponseContentString, Object.class); // --- exception
// --- works
TestEntity testEntity = new Gson().fromJson(httpResponseContentString, TestEntity.class);
LOG.warning("testEntity: " + new Gson().toJson(testEntity));
// testEntity: {"string":"some string","integer":33,"aBoolean":true,"object":{}} (EthNodeAPI.java:309)
LOG.warning("testEntity.string: " + testEntity.string);
LOG.warning("testEntity.integer: " + testEntity.integer);
LOG.warning("testEntity.aBoolean: " + testEntity.aBoolean);
LOG.warning("testEntity.object: " + testEntity.object);
LOG.warning("httpResponseContentString: ");
LOG.warning(httpResponseContentString);
// return resObj;
return new StringWrapperObject(httpResponseContentString);
}
use of net.cryptonomica.returns.StringWrapperObject in project cryptonomica by Cryptonomica.
the class EthNodeAPI method getVerificationDataFromSmartContractByFingerprint.
@ApiMethod(name = "getVerificationFromSCbyFingerprint", path = "getVerificationFromSCbyFingerprint", httpMethod = ApiMethod.HttpMethod.GET)
@SuppressWarnings("unused")
public StringWrapperObject getVerificationDataFromSmartContractByFingerprint(// final HttpServletRequest httpServletRequest,
final User googleUser, @Named("fingerprint") final String fingerprint) throws IllegalArgumentException, UnauthorizedException {
// ensure registered user ( - may be later only for verified):
CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaRegisteredUser(googleUser);
// check form:
LOG.warning("fingerprint" + fingerprint);
if (fingerprint == null || fingerprint.equals("") || fingerprint.length() != 40) {
throw new IllegalArgumentException("Provided fingerprint is not valid");
}
String tomcatWeb3jAPIkey = ofy().load().key(Key.create(AppSettings.class, "tomcatweb3jAPIkey")).now().getValue();
String urlHost = "https://tomcatweb3j.cryptonomica.net";
String urlPath = "/getVerification";
String urlAddress = urlHost + urlPath;
// HashMap<String, String> queryMap = new HashMap<>();
// queryMap.put("address", ethereumAcc);
String postRequestBody = "fingerprint=" + fingerprint;
HTTPResponse httpResponse = HttpService.postRequestWithAPIkey(urlAddress, postRequestBody, tomcatWeb3jAPIkey);
byte[] httpResponseContentBytes = httpResponse.getContent();
String httpResponseContentString = new String(httpResponseContentBytes, StandardCharsets.UTF_8);
LOG.warning("httpResponseContentString: " + httpResponseContentString);
return new StringWrapperObject(httpResponseContentString);
}
Aggregations