@Override public String digestParams(RestInvocation restInvocation) { Mac mac256 = getMac(); String nonce = nonceFactory.createValue().toString(); mac256.update(nonce.getBytes()); mac256.update(clientId.getBytes()); mac256.update(apiKey.getBytes()); String signature = String.format("%064x", new BigInteger(1, mac256.doFinal())).toUpperCase(); List<Object> unannanotatedParams = restInvocation.getUnannanotatedParams(); for (Object unannanotatedParam : unannanotatedParams) { // there *should* be only one if (unannanotatedParam instanceof CexIORequest) { CexIORequest request = (CexIORequest) unannanotatedParam; request.signature = signature; request.nonce = nonce; request.key = apiKey; } } return signature; } }
for (Object param : restInvocation.getUnannanotatedParams()) { if (param instanceof LakeBTCRequest) { request = (LakeBTCRequest) param;
public String writeBody(RestInvocation invocation) { //just safety checks if (!invocation.getParamsMap().get(FormParam.class).isEmpty() || invocation.getUnannanotatedParams().isEmpty()) { throw new IllegalArgumentException("No media type specified; don't know how to create request body. Please specify the body media type using @javax.ws.rs.Consumes."); } return null; } }
public String writeBody(RestInvocation invocation) { //just safety checks if (!invocation.getParamsMap().get(FormParam.class).isEmpty() || invocation.getUnannanotatedParams().isEmpty()) { throw new IllegalArgumentException("No media type specified; don't know how to create request body. Please specify the body media type using @javax.ws.rs.Consumes."); } return null; } }
public String writeBody(RestInvocation invocation) { if (!TEXT_PLAIN.equals(invocation.getMethodMetadata().getReqContentType())) { throw new IllegalArgumentException("ToStringRequestWriter supports " + TEXT_PLAIN + " content type only!"); } if (invocation.getParamsMap().get(FormParam.class) != null && !invocation.getParamsMap().get(FormParam.class).isEmpty()) { throw new IllegalArgumentException("@FormParams are not allowed with " + TEXT_PLAIN); } else if (invocation.getUnannanotatedParams().size() > 1) { throw new IllegalArgumentException("Can only have a single unannotated parameter with " + TEXT_PLAIN); } if (invocation.getUnannanotatedParams().isEmpty()) { return null; } return invocation.getUnannanotatedParams().get(0).toString(); } }
public String writeBody(RestInvocation invocation) { if (!TEXT_PLAIN.equals(invocation.getMethodMetadata().getReqContentType())) { throw new IllegalArgumentException("ToStringRequestWriter supports " + TEXT_PLAIN + " content type only!"); } if (invocation.getParamsMap().get(FormParam.class) != null && !invocation.getParamsMap().get(FormParam.class).isEmpty()) { throw new IllegalArgumentException("@FormParams are not allowed with " + TEXT_PLAIN); } else if (invocation.getUnannanotatedParams().size() > 1) { throw new IllegalArgumentException("Can only have a single unannotated parameter with " + TEXT_PLAIN); } if (invocation.getUnannanotatedParams().isEmpty()) { return null; } return invocation.getUnannanotatedParams().get(0).toString(); } }
public String writeBody(RestInvocation invocation) { if (!MediaType.APPLICATION_JSON.equals(invocation.getMethodMetadata().getReqContentType())) { throw new IllegalArgumentException("JsonRequestWriter supports application/json content type only!"); } if (invocation.getParamsMap().get(FormParam.class) != null && !invocation.getParamsMap().get(FormParam.class).isEmpty()) { throw new IllegalArgumentException("@FormParams are not allowed with " + MediaType.APPLICATION_JSON); } else if (invocation.getUnannanotatedParams().size() > 1) { throw new IllegalArgumentException("Can only have a single unannotated parameter with " + MediaType.APPLICATION_JSON); } if (invocation.getUnannanotatedParams().isEmpty()) { return null; } try { return objectMapper.writeValueAsString(invocation.getUnannanotatedParams().get(0)); } catch (JsonProcessingException e) { throw new RuntimeException("Error writing json. This could be due to an error in your Jackson mapping, or a bug in rescu.", e); } }
@Override public String digestParams(RestInvocation restInvocation) { Mac mac256 = getMac(); String nonce = nonceFactory.createValue().toString(); mac256.update(nonce.getBytes()); mac256.update(clientId.getBytes()); mac256.update(apiKey.getBytes()); String signature = String.format("%064x", new BigInteger(1, mac256.doFinal())).toUpperCase(); List<Object> unannanotatedParams = restInvocation.getUnannanotatedParams(); for (Object unannanotatedParam : unannanotatedParams) { // there *should* be only one if (unannanotatedParam instanceof CexIORequest) { CexIORequest request = (CexIORequest) unannanotatedParam; request.signature = signature; request.nonce = nonce; request.key = apiKey; } } return signature; } }
public String writeBody(RestInvocation invocation) { if (!MediaType.APPLICATION_JSON.equals(invocation.getMethodMetadata().getReqContentType())) { throw new IllegalArgumentException("JsonRequestWriter supports application/json content type only!"); } if (invocation.getParamsMap().get(FormParam.class) != null && !invocation.getParamsMap().get(FormParam.class).isEmpty()) { throw new IllegalArgumentException("@FormParams are not allowed with " + MediaType.APPLICATION_JSON); } else if (invocation.getUnannanotatedParams().size() > 1) { throw new IllegalArgumentException("Can only have a single unannotated parameter with " + MediaType.APPLICATION_JSON); } if (invocation.getUnannanotatedParams().isEmpty()) { return null; } try { return objectMapper.writeValueAsString(invocation.getUnannanotatedParams().get(0)); } catch (JsonProcessingException e) { throw new RuntimeException("Error writing json. This could be due to an error in your Jackson mapping, or a bug in rescu.", e); } }
@Override public String digestParams(RestInvocation restInvocation) { String tonce = restInvocation.getHttpHeadersFromParams().get("Json-Rpc-Tonce"); LakeBTCRequest request = null; for (Object param : restInvocation.getUnannanotatedParams()) { if (param instanceof LakeBTCRequest) { request = (LakeBTCRequest) param; } } if (request == null) { throw new IllegalArgumentException("No LakeBTCDigest found."); } final long id = request.getId(); final String method = request.getRequestMethod(); final String params = ""; //stripParams(request.getParams()); String signature = String.format("tonce=%s&accesskey=%s&requestmethod=%s&id=%d&method=%s¶ms=%s", tonce, clientId, method, id, request.getMethod(), params); log.debug("signature message: {}", signature); Mac mac = getMac(); byte[] hash = mac.doFinal(signature.getBytes()); BasicAuthCredentials auth = new BasicAuthCredentials(apiKey, LakeBTCUtil.bytesToHex(hash)); return auth.digestParams(restInvocation); }
@Override public String digestParams(RestInvocation restInvocation) { String tonce = restInvocation.getHttpHeadersFromParams().get("Json-Rpc-Tonce"); BTCChinaRequest request = null; for (Object param : restInvocation.getUnannanotatedParams()) { if (param instanceof BTCChinaRequest) { request = (BTCChinaRequest) param; } } if (request == null) { throw new IllegalArgumentException("No BTCChinaRequest found."); } final long id = request.getId(); final String method = request.getMethod(); final String params = stripParams(request.getParams()); String signature = String.format("tonce=%s&accesskey=%s&requestmethod=%s&id=%d&method=%s¶ms=%s", tonce, exchangeAccessKey, "post", id, method, params); log.debug("signature message: {}", signature); Mac mac = getMac(); byte[] hash = mac.doFinal(signature.getBytes()); BasicAuthCredentials auth = new BasicAuthCredentials(exchangeAccessKey, BTCChinaUtils.bytesToHex(hash)); return auth.digestParams(restInvocation); }