Search in sources :

Example 6 with StringWrapperObject

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);
}
Also used : StringWrapperObject(net.cryptonomica.returns.StringWrapperObject) HTTPResponse(com.google.appengine.api.urlfetch.HTTPResponse) Gson(com.google.gson.Gson) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Example 7 with StringWrapperObject

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);
}
Also used : AppSettings(net.cryptonomica.entities.AppSettings) StringWrapperObject(net.cryptonomica.returns.StringWrapperObject) HTTPResponse(com.google.appengine.api.urlfetch.HTTPResponse) CryptonomicaUser(net.cryptonomica.entities.CryptonomicaUser) ApiMethod(com.google.api.server.spi.config.ApiMethod)

Aggregations

ApiMethod (com.google.api.server.spi.config.ApiMethod)7 StringWrapperObject (net.cryptonomica.returns.StringWrapperObject)7 BadRequestException (com.google.api.server.spi.response.BadRequestException)2 HTTPResponse (com.google.appengine.api.urlfetch.HTTPResponse)2 Gson (com.google.gson.Gson)2 Message (com.twilio.sdk.resource.instance.Message)2 CryptonomicaUser (net.cryptonomica.entities.CryptonomicaUser)2 NotFoundException (com.google.api.server.spi.response.NotFoundException)1 Key (com.googlecode.objectify.Key)1 Date (java.util.Date)1 AppSettings (net.cryptonomica.entities.AppSettings)1 PGPPublicKeyData (net.cryptonomica.entities.PGPPublicKeyData)1 PGPPublicKey (org.bouncycastle.openpgp.PGPPublicKey)1