List of usage examples for java.security SignatureException SignatureException
public SignatureException(String message, Throwable cause)
From source file:API.amazon.mws.products.MarketplaceWebServiceProductsClient.java
/** * Calculate String to Sign for SignatureVersion 2 * @param parameters request parameters/*from w w w. j a v a 2 s. co m*/ * @return String to Sign * @throws java.security.SignatureException */ private String calculateStringToSignV2(Map<String, String> parameters) throws SignatureException { StringBuilder data = new StringBuilder(); data.append("POST"); data.append("\n"); URI endpoint = null; try { endpoint = new URI(config.getServiceURL().toLowerCase()); } catch (URISyntaxException ex) { log.debug("URI Syntax Exception", ex); throw new SignatureException("URI Syntax Exception thrown " + "while constructing string to sign", ex); } data.append(endpoint.getHost()); if (!usesAStandardPort(config.getServiceURL())) { data.append(":"); data.append(endpoint.getPort()); } data.append("\n"); String uri = "/Products/2011-10-01"; data.append(urlEncode(uri, true)); data.append("\n"); Map<String, String> sorted = new TreeMap<String, String>(); sorted.putAll(parameters); Iterator<Map.Entry<String, String>> pairs = sorted.entrySet().iterator(); while (pairs.hasNext()) { Map.Entry<String, String> pair = pairs.next(); String key = pair.getKey(); data.append(urlEncode(key, false)); data.append("="); String value = pair.getValue(); data.append(urlEncode(value, false)); if (pairs.hasNext()) { data.append("&"); } } return data.toString(); }
From source file:API.amazon.mws.feeds.service.MarketplaceWebServiceClient.java
/** * Calculate String to Sign for SignatureVersion 2 * @param parameters request parameters//from w w w . j a va2s .c o m * @return String to Sign * @throws java.security.SignatureException */ private String calculateStringToSignV2(Map<String, String> parameters) throws SignatureException { StringBuilder data = new StringBuilder(); data.append("POST"); data.append("\n"); URI endpoint = null; try { endpoint = new URI(config.getServiceURL().toLowerCase()); } catch (URISyntaxException ex) { log.error("URI Syntax Exception", ex); throw new SignatureException("URI Syntax Exception thrown " + "while constructing string to sign", ex); } data.append(endpoint.getHost()); if (!usesAStandardPort(config.getServiceURL())) { data.append(":"); data.append(endpoint.getPort()); } data.append("\n"); String uri = endpoint.getPath(); if (uri == null || uri.length() == 0) { uri = "/"; } data.append(uri); data.append("\n"); Map<String, String> sorted = new TreeMap<String, String>(); sorted.putAll(parameters); Iterator<Map.Entry<String, String>> pairs = sorted.entrySet().iterator(); while (pairs.hasNext()) { Map.Entry<String, String> pair = pairs.next(); String key = pair.getKey(); data.append(urlEncode(key)); data.append("="); String value = pair.getValue(); data.append(urlEncode(value)); if (pairs.hasNext()) { data.append("&"); } } System.out.println(data.toString()); return data.toString(); }
From source file:com.amazonaws.mws.MarketplaceWebServiceClient.java
/** * Calculate String to Sign for SignatureVersion 2 * @param parameters request parameters// w ww .ja v a 2 s . c o m * @return String to Sign * @throws java.security.SignatureException */ private String calculateStringToSignV2(Map<String, String> parameters) throws SignatureException { StringBuilder data = new StringBuilder(); data.append("POST"); data.append("\n"); URI endpoint = null; try { endpoint = new URI(config.getServiceURL().toLowerCase()); } catch (URISyntaxException ex) { log.error("URI Syntax Exception", ex); throw new SignatureException("URI Syntax Exception thrown " + "while constructing string to sign", ex); } data.append(endpoint.getHost()); if (!usesAStandardPort(config.getServiceURL())) { data.append(":"); data.append(endpoint.getPort()); } data.append("\n"); String uri = endpoint.getPath(); if (uri == null || uri.length() == 0) { uri = "/"; } data.append(uri); data.append("\n"); Map<String, String> sorted = new TreeMap<String, String>(); sorted.putAll(parameters); Iterator<Map.Entry<String, String>> pairs = sorted.entrySet().iterator(); while (pairs.hasNext()) { Map.Entry<String, String> pair = pairs.next(); String key = pair.getKey(); data.append(urlEncode(key)); data.append("="); String value = pair.getValue(); data.append(urlEncode(value)); if (pairs.hasNext()) { data.append("&"); } } return data.toString(); }
From source file:API.amazon.mws.feeds.service.MarketplaceWebServiceClient.java
/** * Computes RFC 2104-compliant HMAC signature. * *///from w w w . j a v a 2s. co m private String sign(String data, String key, String algorithm) throws SignatureException { byte[] signature; try { Mac mac = Mac.getInstance(algorithm); mac.init(new SecretKeySpec(key.getBytes(), algorithm)); signature = Base64.encodeBase64(mac.doFinal(data.getBytes(DEFAULT_ENCODING))); } catch (Exception e) { throw new SignatureException("Failed to generate signature: " + e.getMessage(), e); } return new String(signature); }