Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
659 views
in Technique[技术] by (71.8m points)

servlets - java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64

Here I'm passing three parameters to this sign method. In this line

signature = new String(Base64.encodeBase64(mac.doFinal(data.getBytes(UTF_8_Encoding))));

I'm getting error:

SEVERE: Servlet.service() for servlet [com.asp.amz.amzServlet] in context with path [/amazon] threw exception [Servlet execution threw an exception] with root cause java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64

String Key = "z/0qfiE+ScjxHy2gSwmHqP0rZ6fT9zhVgsNt";
String signatureMethod = "HmacSHA256";
String data = "sandbox.amazon.com/cobranded-ui/actions/start?callerKey=AKIAJZOKEUCXF7RKSCNA&callerReference=callerReferenceSingleUse&currencyCode=USD&paymentReason=HarryPotter%201-5%20DVD%20set&pipelineName=SingleUse&returnURL=http%3A%2F%2Flocalhost%3A8888%2Famazon&signatureMethod=HmacSHA256&signatureVersion=2&transactionAmount=5&version=2009-01-09";

    private static String sign(String data, String key, String signatureMethod) throws SignatureException
    {
        System.out.println(" In sign block ");
        String signature = "";
        try {
            System.out.println(" In sign Try block ");
            Mac mac = Mac.getInstance(signatureMethod);
            mac.init(new SecretKeySpec(key.getBytes(), signatureMethod));
            signature = new String(Base64.encodeBase64(mac.doFinal(data.getBytes(UTF_8_Encoding))));
            System.out.println(" In sign Try block ");
        } catch (Exception e) {
            System.out.println(" In sign catch block ");
            throw new SignatureException("Failed to generate signature: " + e.getMessage(), e);         
        }
        System.out.println(" End sign block " + signature);
        return signature;
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

just add commons-codec.jar into your classpath


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...