salem,
j'ai un prob au niveau de la connexion à Internet
je suis en train de développer un projet en java et je veux avoir télécharger un fichier via Internet.
Le prob est que l'URL pour télécharger ce fichier est (https)
voila mon codetoujours il me marque des erreurs comme par exemple:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.net.*; import java.security.Security; import java.util.Properties; public class Telechargement { public void Telechargement(String urlll) { Class factoryClass = null; URLStreamHandlerFactory factory = null; String socksServer = ""; String socksPort = ""; String usage = "Usage: java UseHttps URL-to-be-read socksServerName(optional) socksPortNumber(optional)"; // Build the complete URL, including the protocol String fullURL = urlll; System.out.println("Computed URL is " + fullURL); // Now either we can rely on the user to have added us to // the security.provider list in java.security, or we can // dynamically add ourselves here. We'll set it up here. Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); Properties properties = System.getProperties(); String handlers = System.getProperty("java.protocol.handler.pkgs"); if (handlers == null) { // nothing specified yet (expected case) properties.put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); } else { // something already there, put ourselves out front properties.put("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol|".concat(handlers)); } if (!socksServer.equals("")) { // Must do the setup to get to the socks host // Could check first to see if the user already specified it on the invocation line if (System.getProperty("socksProxyHost") == null) { properties.put("socksProxyHost", socksServer); } if (!socksPort.equals("")) { if (System.getProperty("socksProxyPort") == null) { properties.put("socksProxyPort", socksPort); } } } System.setProperties(properties); // put the updated properties back in System try { URL page = new URL(fullURL); // Process the URL far enough to find the right handler URLConnection urlc = page.openConnection(); urlc.setUseCaches(false); // Don't look at possibly cached data System.out.println("Content-type = " + urlc.getContentType()); // See what's here System.out.println("Content-length = " + urlc.getContentLength()); // See how much of it there is // Read it all and print it out BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream())); String buffer = ""; while (buffer != null) { try { System.out.println(buffer); buffer = br.readLine(); } catch (IOException ioe) { ioe.printStackTrace(); break; } } } catch (MalformedURLException mue) { System.out.println(fullURL + " is not a URL that can be resolved"); } catch (IOException ie) { ie.printStackTrace(); } } public static void main(String argv[]) { Telechargement t=new Telechargement(); t.Telechargement("https://www.certification.tn/cgi-bin/pub/crl/cacrl.crl"); } }
pouvez vous m'aider
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 Computed URL is https://www.certification.tn/cgi-bin/pub/crl/cacrl.crl Content-type = null Content-length = -1 javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1298) at java.security.AccessController.doPrivileged(Native Method) at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1292) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:948) at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl.getInputStream(HttpsURLConnectionOldImpl.java:204) at Telechargement.Telechargement(Telechargement.java:68) at Telechargement.main(Telechargement.java:92) Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1520) at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:182) at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:176) at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:975) at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:123) at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:511) at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:449) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:817) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1029) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1056) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1040) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:405) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:170) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:981) at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:2025) at java.net.URLConnection.getContentType(URLConnection.java:485) at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl.getContentType(HttpsURLConnectionOldImpl.java:352) at Telechargement.Telechargement(Telechargement.java:65) ... 1 more Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:285) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:191) at sun.security.validator.Validator.validate(Validator.java:218) at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126) at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209) at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249) at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:954) ... 15 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174) at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238) at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:280)
merci d'avance
Partager