( Padowan | 2018. 03. 06., k – 10:15 )

Sziasztok!

Egy kis segítséget szeretnék kérni. Java-ban próbálok egy tokent lekérni a NAV online rendszerétől, de nem sikerül. Még nem csináltam korábban hasonlót (REST API csatlakozás), és nem tudok átlépné ezen a problémán. A hibaüzenetem a következő.

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target : sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

NetBeans-ben próbálom futtatni a következő kódot:

package httppostdata;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import javax.net.ssl.HttpsURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.util.Arrays;

public class NetClientPost {

public static void main(String[] args) {

try {

URL url = new URL("https://api-test.onlineszamla.nav.gov.hu/invoiceService/tokenExchange");
HttpsURLConnection uc = (HttpsURLConnection) url.openConnection();

uc.setRequestMethod("POST");
uc.setAllowUserInteraction(false);
uc.setDoOutput(true);
uc.setRequestProperty( "Content-type", "application/xml" );
uc.setRequestProperty( "Accept", "text/xml" );

File xmlFile = new File("tokenExchange.xml");
byte[] xmlData = null;
try {
xmlData = Files.readAllBytes(xmlFile.toPath());
} catch (IOException ex) {
}

String xmlDataStr = Arrays.toString(xmlData);

String[] byteValues = xmlDataStr.substring(1, xmlDataStr.length() - 1).split(",");
byte[] bytes = new byte[byteValues.length];

for (int i=0, len=bytes.length; i 'kisebb(<)' len; i++) {
bytes[i] = Byte.parseByte(byteValues[i].trim());
}

OutputStream os = uc.getOutputStream();
os.write(bytes);
os.flush();

if (uc.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
throw new RuntimeException("Failed : HTTP error code : "
+ uc.getResponseCode());
}

BufferedReader br = new BufferedReader(new InputStreamReader(
(uc.getInputStream())));

String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}

uc.disconnect();

} catch (MalformedURLException e) {

System.out.println(e.getMessage() + " : " + e.getLocalizedMessage());

} catch (IOException e) {

System.out.println(e.getMessage() + " : " + e.getLocalizedMessage());

}

}

}