* @return a URL for the given JSON string, and the required OAuth parameters.
*/
public static String createOAuthUrlString(
String jsonBody, String rpcServerUrl, OAuthAccessor accessor)
throws IOException, URISyntaxException, OAuthException {
OAuthMessage message =
new OAuthMessage(POST, rpcServerUrl, Collections.<SimpleEntry<String, String>>emptyList());
// Compute the hash of the body.
byte[] rawBody = jsonBody.getBytes(UTF_8);
byte[] hash = DigestUtils.sha(rawBody);
byte[] encodedHash = Base64.encodeBase64(hash);
message.addParameter(OAUTH_BODY_HASH, new String(encodedHash, UTF_8));
// Add other parameters.
message.addRequiredParameters(accessor);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Signature base string: " + OAuthSignatureMethod.getBaseString(message));
}
// Construct the resulting URL.
StringBuilder sb = new StringBuilder(rpcServerUrl);
char connector = '?';
for (Map.Entry<String, String> p : message.getParameters()) {
if (!p.getKey().equals(jsonBody)) {
sb.append(connector);
sb.append(URLEncoder.encode(p.getKey(), UTF_8));
sb.append('=');
sb.append(URLEncoder.encode(p.getValue(), UTF_8));