I'm deploying your java checkout solution on my local machine for testing purposes. The code I'm using is available in the Sky Developer area. .
Follow the code:
public String envia() {
String responseLine = "";
try {
String json = "{"
+ " \"OrderNumber\": \"12344\","
+ " \"SoftDescriptor\": \"Nome que aparecerá na fatura\","
+ " \"Cart\": {"
+ " \"Discount\": {"
+ " \"Type\": \"Percent\","
+ " \"Value\": 10"
+ " },"
+ " \"Items\": ["
+ " {"
+ " \"Name\": \"Nome do produto\","
+ " \"Description\": \"Descrição do produto\","
+ " \"UnitPrice\": 100,"
+ " \"Quantity\": 2,"
+ " \"Type\": \"Asset\","
+ " \"Sku\": \"Sku do item no carrinho\","
+ " \"Weight\": 200"
+ " }"
+ " ]"
+ " },"
+ " \"Shipping\": {"
+ " \"Type\": \"Correios\","
+ " \"SourceZipCode\": \"14400000\","
+ " \"TargetZipCode\": \"11000000\","
+ " \"Address\": {"
+ " \"Street\": \"Endereço de entrega\","
+ " \"Number\": \"123\","
+ " \"Complement\": \"\","
+ " \"District\": \"Bairro da entrega\","
+ " \"City\": \"Cidade de entrega\","
+ " \"State\": \"SP\""
+ " },"
+ " \"Services\": ["
+ " {"
+ " \"Name\": \"Serviço de frete\","
+ " \"Price\": 123,"
+ " \"Deadline\": 15"
+ " }"
+ " ]"
+ " },"
+ " \"Payment\": {"
+ " \"BoletoDiscount\": 0,"
+ " \"DebitDiscount\": 0,"
+ " \"RecurrentPayment\": {"
+ " \"Interval\": \"Monthly\","
+ " \"EndDate\": \"2015-12-31\""
+ " }"
+ " },"
+ " \"Customer\": {"
+ " \"Identity\": 11111111111,"
+ " \"FullName\": \"Fulano Comprador da Silva\","
+ " \"Email\": \"[email protected]\","
+ " \"Phone\": \"11999999999\""
+ " },"
+ " \"Options\": {"
+ " \"AntifraudEnabled\": false"
+ " }"
+ "}";
BufferedReader bufferedReader;
URL url = new URL("https://cieloecommerce.cielo.com.br/api/public/v1/orders");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.addRequestProperty("MerchantId", "xxxx-xxxx-xxxx-xxxx-xxxx");
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
connection.setDoOutput(true);
DataOutputStream jsonRequest = new DataOutputStream(
connection.getOutputStream());
jsonRequest.writeBytes(json);
jsonRequest.flush();
jsonRequest.close();
bufferedReader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
StringBuffer jsonResponse = new StringBuffer();
while ((responseLine = bufferedReader.readLine()) != null) {
jsonResponse.append(responseLine);
}
bufferedReader.close();
connection.disconnect();
} catch (Exception ex) {
return ex.getMessage();
}
return responseLine;
}
Running the code returns the following error:
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I make it clear that I imported the ecommerce.cielo.com.br
certificate into the browser as indicated. In addition, I imported the other certificates, Raiz.crt
and Intermediaria.crt
, plus ecommerce.cielo.com.br.crt
to my TrustStore with the following commands:
keytool -keystore cacerts -import -alias ecommerce -file ecommerce.cielo.com.br.crt -trustcacerts
keytool -keystore cacerts -import -alias intermediaria -file Intermediaria.crt -trustcacerts
keytool -keystore cacerts -import -alias raiz -file Raiz.crt -trustcacerts
What can I do to remedy the error already described?