I am implementing the slideshare Connector using slideshare API.
I have to set this to the SHA1 hash of the concatenation of the shared
secret and the timestamp (ts). i.e. SHA1 (sharedsecret + timestamp).
package org.wso2.carbon.connector;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.*;
import org.apache.synapse.MessageContext;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import org.apache.synapse.SynapseException;
import org.apache.synapse.mediators.AbstractMediator;
/**
* Created by vanii on 12/9/14.
*/
public class Encoder extends AbstractMediator {
public static final String sha1Key = "uri.var.sha1Key";
public void generateHash(MessageContext msgctx) throws
UnsupportedEncodingException,NoSuchAlgorithmException, InvalidKeyException {
StringBuilder baseString = new StringBuilder();
MessageDigest md = MessageDigest.getInstance("MD5");
String timeStamp=String.valueOf(System.currentTimeMillis() / 1000);
msgctx.setProperty("uri.var.ts",timeStamp);
String input = msgctx.getProperty("uri.var.sha1Key").toString() +
timeStamp;
md.update(input.getBytes());
String hash = String.format("%032x", new BigInteger(1,
md.digest()));
msgctx.setProperty("uri.var.hash",hash);
}
public boolean mediate(MessageContext msgctx) {
try {
generateHash(msgctx);
} catch (Exception e) {
throw new SynapseException(e);
}
return true;
}
}
I am getting but the response says hashing is not correct.
[1]
[2014-12-11 20:26:01,652] DEBUG - headers http-outgoing-8 >> GET
https://www.slideshare.net/api/2/get_slideshow?api_key=4yCEGJou&ts=1418309760&hash=901c42f4bb22ee6617f2c82c81547bd3ad9b5b95&slideshow_id=124324&slideshow_url=http://www.slideshare.net/cocog520/-124324
HTTP/1.1
[2014-12-11 20:26:01,652] DEBUG - headers http-outgoing-8 >>
Accept-Language: en-US,en;q=0.8
[2014-12-11 20:26:01,652] DEBUG - headers http-outgoing-8 >> Cookie:
SERVERID=r87|VImwL|VImwJ
[2014-12-11 20:26:01,652] DEBUG - headers http-outgoing-8 >>
Accept-Encoding: gzip,deflate
[2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> Origin:
chrome-extension://
hgmloofddffdnphfgcellkdfbfbjeloo
[2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> Content-Type:
application/json
[2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> Accept: */*
[2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> Host:
www.slideshare.net:80
[2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> Connection:
Keep-Alive
[2014-12-11 20:26:01,653] DEBUG - headers http-outgoing-8 >> User-Agent:
Synapse-PT-HttpComponents-NIO
[2014-12-11 20:26:01,654] DEBUG - wire << "GET
https://www.slideshare.net/api/2/get_slideshow?api_key=4yCEGJou&ts=1418309760&hash=901c42f4bb22ee6617f2c82c81547bd3ad9b5b95&slideshow_id=124324&slideshow_url=http://www.slideshare.net/cocog520/-124324
HTTP/1.1[\r][\n]"
[2014-12-11 20:26:01,654] DEBUG - wire << "Accept-Language:
en-US,en;q=0.8[\r][\n]"
[2014-12-11 20:26:01,654] DEBUG - wire << "Cookie:
SERVERID=r87|VImwL|VImwJ[\r][\n]"
[2014-12-11 20:26:01,654] DEBUG - wire << "Accept-Encoding:
gzip,deflate[\r][\n]"
[2014-12-11 20:26:01,655] DEBUG - wire << "Origin:
chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo[\r][\n]"
[2014-12-11 20:26:01,655] DEBUG - wire << "Content-Type:
application/json[\r][\n]"
[2014-12-11 20:26:01,655] DEBUG - wire << "Accept: */*[\r][\n]"
[2014-12-11 20:26:01,655] DEBUG - wire << "Host: www.slideshare.net:80
[\r][\n]"
[2014-12-11 20:26:01,655] DEBUG - wire << "Connection: Keep-Alive[\r][\n]"
[2014-12-11 20:26:01,655] DEBUG - wire << "User-Agent:
Synapse-PT-HttpComponents-NIO[\r][\n]"
i am getting the error response in Rest Client
<?xml version="1.0" encoding="UTF-8" ?>
<SlideShareServiceError>
<Message ID="1">
Failed API validation
</Message>
</SlideShareServiceError>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev