IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Format d'échange (XML, JSON...) Java Discussion :

Charger un xml à partir d'un lien internet [JDOM]


Sujet :

Format d'échange (XML, JSON...) Java

  1. #1
    Membre confirmé
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2008
    Messages
    97
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Octobre 2008
    Messages : 97
    Par défaut Charger un xml à partir d'un lien internet
    Bonjour,
    J'essaye de charger un xml à partir d'un lien, 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
     
    org.jdom.Document document;
    Element racine;
    SAXBuilder sxb = new SAXBuilder();
    try
       {
        document = sxb.build(new File("http://adresseSiteXml");
        racine = document.getRootElement();
        afficheALL( racine);
        }
        catch(Exception e){
          e.printStackTrace();
    	 }
    J'ai l'erreur suivant
    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
     
    java.io.FileNotFoundException: C:\IDE\eclipse\https:\adresseSiteXml (La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte)
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at java.io.FileInputStream.<init>(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
    	at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:518)
    	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:905)
    	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:884)
    	at com.afflelou.extranet.franchises.ConnexionExtra.doAction(ConnexionExtra.java:92)
    	at com.triangle.lightfw.AbstractServlet.doAll(AbstractServlet.java:130)
    	at com.triangle.lightfw.AbstractServlet.doPost(AbstractServlet.java:66)
    	at com.triangle.lightfw.AbstractServlet.doGet(AbstractServlet.java:41)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    	at java.lang.Thread.run(Unknown Source)
    En gros il me dis que le lien n'est pas valide car il va chercher le fichier dans "C:\IDE\eclipse\https:\adresseSiteXml" alors qu'il se trouve sur le site "https:\adresseSiteXml"

    Comment je pourrais faire pour parser le fichier xml?

  2. #2
    Membre confirmé
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2008
    Messages
    97
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Octobre 2008
    Messages : 97
    Par défaut
    j'ai poster trop vite.

    La solution :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    document = sxb.build("http://adresseSiteXml");

  3. #3
    Expert confirmé
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Par défaut
    Dans ton cas le plus propre et sûr serait de passer par la version de la méthode prenant un objet de type URL en paramètre

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    document = sxb.build(new URL("http://adresseSiteXml"));

  4. #4
    Membre confirmé
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2008
    Messages
    97
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Octobre 2008
    Messages : 97
    Par défaut
    Je me permets de relancer le sujet.
    J'arriver à charger mon fichier en utilisant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    document = sxb.build(new URL("http://adresseSiteXml"));
    J'ai de nouveau un probléme car le site de mon webservice est cryptée en SSL.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    document = sxb.build(new URL("https://adresseSiteXml"));
    à ce moment la j'ai une exception qui est généré:

    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
     
    javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching aadev.69.kernix.biz found
    	at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    	at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
    	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:518)
    	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:905)
    	at com.afflelou.extranet.franchises.ConnexionExtra.doAction(ConnexionExtra.java:94)
    	at com.triangle.lightfw.AbstractServlet.doAll(AbstractServlet.java:130)
    	at com.triangle.lightfw.AbstractServlet.doPost(AbstractServlet.java:66)
    	at com.triangle.lightfw.AbstractServlet.doGet(AbstractServlet.java:41)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.security.cert.CertificateException: No name matching aadev.69.kernix.biz found
    	at sun.security.util.HostnameChecker.matchDNS(Unknown Source)
    	at sun.security.util.HostnameChecker.match(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)
    	at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
    comment faire pour corriger ce probléme???

  5. #5
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 582
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 582
    Par défaut
    Apparemment le certificat SSL du site est invalide. La manière correcte de résoudre ça est de le remplacer le certificat par un certificat valide.

    Une autre méthode serait de remplacer la politique par défaut de vérification de certificats pour accepter n'importe quoi (trop souvent vu en pratique.) 'Faudrait que je retrouve les tutoriels.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  6. #6
    Membre confirmé
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2008
    Messages
    97
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Octobre 2008
    Messages : 97
    Par défaut
    en cherchant sur tes conseils, j'ai récupéré ceci:
    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
     
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[]{
        new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }
            public void checkClientTrusted(
                java.security.cert.X509Certificate[] certs, String authType) {
            }
            public void checkServerTrusted(
                java.security.cert.X509Certificate[] certs, String authType) {
            }
        }
    };
     
    // Install the all-trusting trust manager
    try {
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
    }
    Mais une autre exception est apparu
    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
     
    java.io.IOException: HTTPS hostname wrong:  should be <url>
    	at sun.net.www.protocol.https.HttpsClient.checkURLSpoofing(Unknown Source)
    	at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
    	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:518)
    	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:905)
    	at com.afflelou.extranet.franchises.ConnexionExtra.doAction(ConnexionExtra.java:127)
    	at com.triangle.lightfw.AbstractServlet.doAll(AbstractServlet.java:130)
    	at com.triangle.lightfw.AbstractServlet.doPost(AbstractServlet.java:66)
    	at com.triangle.lightfw.AbstractServlet.doGet(AbstractServlet.java:41)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    	at java.lang.Thread.run(Unknown Source)

  7. #7
    Membre confirmé
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2008
    Messages
    97
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Octobre 2008
    Messages : 97
    Par défaut
    Il fallait ignorer la vérification du hostName
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    HttpsURLConnection.setDefaultHostnameVerifier(new MyHostnameVerifier());
    classe MyHostNameVerifier:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    import javax.net.ssl.SSLSession;
     
    public class MyHostnameVerifier implements com.sun.net.ssl.HostnameVerifier, javax.net.ssl.HostnameVerifier{
        public boolean verify(String urlHostName, String certHostName){
            return true;
        }
     
    	public boolean verify(String hostname, SSLSession session) {
    		return true;
    	}
    }

  8. #8
    Membre éclairé Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Par défaut
    Bonjour,

    je relance de même le sujet étant donné que j'ai un problème similaire.

    Je souhaite parser un fichier XML sur internet ( http://www.ecb.europa.eu/stats/eurof...xref-daily.xml )

    C'est dans le cadre de la récupération de valeurs des taux de changes...

    Comme s'est fourni par la BCE je pense pas qu'il y a de cryptage particulier, cependant j'obtiens un Timed Out lorsque j'essaye de lire le fichier !

    J'utilise, comme cité plus haut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    document = sxb.build(new URL("http://[...]daily.xml"));
    Merci

  9. #9
    Membre confirmé
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2008
    Messages
    97
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Octobre 2008
    Messages : 97
    Par défaut
    Tu peux mettre ton erreur?

  10. #10
    Membre éclairé Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Par défaut
    Oui, le code ( c'est vraiment une methode de test avec un bouton bidou pour tester la lecture...)
    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
    private void connect() {
    		JButton bouton = new JButton("Connexion");
    		add(bouton, BorderLayout.SOUTH);
     
     
     
    		bouton.addActionListener(new ActionListener() {
     
    			@Override
    			public void actionPerformed(ActionEvent arg0) {
    				{
    				      SAXBuilder sxb = new SAXBuilder();
    				      try {
    						//document = sxb.build(new File(url2));
     
    				    	  document = sxb.build(new URL("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"));
    				    	    racine = document.getRootElement();
    				    	    }
    				    	    catch(Exception e){
    				    	      e.printStackTrace();
    				    		 }
     
    				    	    System.out.println(racine);
    				}
    			}
    		});
    Erreur :
    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
    java.net.ConnectException: Connection timed out: connect
    	at java.net.PlainSocketImpl.socketConnect(Native Method)
    	at java.net.PlainSocketImpl.doConnect(Unknown Source)
    	at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    	at java.net.PlainSocketImpl.connect(Unknown Source)
    	at java.net.SocksSocketImpl.connect(Unknown Source)
    	at java.net.Socket.connect(Unknown Source)
    	at java.net.Socket.connect(Unknown Source)
    	at sun.net.NetworkClient.doConnect(Unknown Source)
    	at sun.net.www.http.HttpClient.openServer(Unknown Source)
    	at sun.net.www.http.HttpClient.openServer(Unknown Source)
    	at sun.net.www.http.HttpClient.<init>(Unknown Source)
    	at sun.net.www.http.HttpClient.New(Unknown Source)
    	at sun.net.www.http.HttpClient.New(Unknown Source)
    	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
    	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    	at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    	at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    	at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:518)
    	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:905)
    	at src.NewJFrame$2.actionPerformed(NewJFrame.java:71)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

  11. #11
    Membre confirmé
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2008
    Messages
    97
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Octobre 2008
    Messages : 97
    Par défaut
    Tu n'es pas derriére un proxy?

  12. #12
    Membre éclairé Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Par défaut
    Je viens d'y penser... et oui je suis dérrière un proxy ( celui de ma boîte)

  13. #13
    Membre éclairé Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Par défaut
    Bonjour,
    passant par un proxy j'ai décidé d'enregistrer dans mon workspace le fichier xml pour pouvoir le parser convenablement.

    Voici le fichier xml :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <?xml version="1.0" encoding="UTF-8"?>
    <gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
    	<gesmes:subject>Reference rates</gesmes:subject>
    	<gesmes:Sender>
    		<gesmes:name>European Central Bank</gesmes:name>
    	</gesmes:Sender>
    	<Cube>
    		<Cube time='2011-03-14'>
    			<Cube currency='USD' rate='1.3948'/>
    			<Cube currency='JPY' rate='114.16'/>
    // ...
    		</Cube>
    	</Cube>
    </gesmes:Envelope>
    Hélas, en me basant sur le tuto "Manipuler des fichiers XML avec JDOM" je n'arrive pas à réaliser la même chose étant donné qu'apres "Cube" tout les neuds porte le même nom.

  14. #14
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 582
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 582
    Par défaut
    Citation Envoyé par pendoRa Voir le message
    Hélas, en me basant sur le tuto "Manipuler des fichiers XML avec JDOM" je n'arrive pas à réaliser la même chose étant donné qu'apres "Cube" tout les neuds porte le même nom.
    Euh, c'est quand même pas compliqué à gérer, un arbre JDOM. Je reconnais que ce format-là n'est pas terrible, mais c'est pas une raison.
    Tu veux faire quoi, au juste ?
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  15. #15
    Membre éclairé Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Par défaut
    Récupérer les valeurs correspondantes aux devises. ex : on demande "USD" on récupère sa valeur, soit 1,3948..
    Je sais que la difficulté n'est pas insurmontable, mais je n'arrive pas récupérer la valeur...sinon le reste est ok.

    Edit : mon code
    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
     
     
         SAXBuilder sxb = new SAXBuilder();
    					try
    					{						document = sxb.build(new File("devises.xml"));
    					}
    					catch(Exception e){}
    				racine = document.getRootElement();
     
       List listDevises = racine.getChildren("Cube");
     
     
       Iterator i = listDevises.iterator();
       while(i.hasNext())
       {
          Element courant = (Element)i.next();
          System.out.println(courant.getChild("Cube").getText());
       }
    }

  16. #16
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 582
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 582
    Par défaut
    Hum. Bon, je n'ai pas le format entier alors je dois présupposer des choses.

    Déjà première remarque, ça ne se voit pas, mais Cube est dans le namespace http://www.ecb.int/vocabulary/2002-08-01/eurofxref . Il va donc falloir l'indiquer.

    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
    // constantes
    public static final Namespace REF_NS =
      Namespace.getNamespace("http://www.ecb.int/vocabulary/2002-08-01/eurofxref");
    public static final String CUBE = "Cube";
     
    // ... puis ailleurs le code
    String getCurrencyValue(String currencyCode) {
      List<Element> cubes =
        (List<Element>)racine.getChild(CUBE, REF_NS).
        getChild(CUBE, REF_NS).
        getChildren(CUBE, REF_NS);
      for(Element cube : cubes) {
        if(cube.getAttributeValue("currency").equals(currencyCode)) {
          return cube.getAttributeValue("rate");
        }
      }
      throw new IllegalArgumentException("Cannot find currency " + currencyCode);
    }
    Ça c'était la méthode compliquée.

    Méthode simple :

    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
    // constantes
    // En XPath, les éléments qui sont dans un namespace soivent être préfixés
    public static final Namespace REF_NS =
      Namespace.getNamespace("ref", "http://www.ecb.int/vocabulary/2002-08-01/eurofxref");
    // Pas envie de mettre le nom de la racine, remplaçons par *
    public static final String CURRENCY_PATH_TEMPLATE =
      "/*/ref:Cube/ref:Cube/ref:Cube[@currency='%s']";
     
    // ... puis ailleurs le code
    String getCurrencyValue(String currencyCode) {
      String sXPath = String.format(CURRENCY_PATH_TEMPLATE, currencyCode);
      XPath path = XPath.newInstance(sXPath);
     
      path.addNamespace(REF_NS);
     
      Element cube = (Element)path.selectSingleNode(document);
      return cube.getAttributeValue("rate");
    }
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  17. #17
    Membre confirmé
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2008
    Messages
    97
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Octobre 2008
    Messages : 97
    Par défaut
    Désolé de ne pas avoir répondu plus tôt
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    System.setProperty("proxySet","true") ;
    System.setProperty("http.proxyHost","urlServerProxy") ;
    System.setProperty("http.proxyPort","portProxy") ;
    essaye de mettre ça avant ton new URL()

  18. #18
    Membre éclairé Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Par défaut
    Merci tamildark, ce problème est réglé.
    Merci thelvin, j'ai un peu de mal a comprendre mais je vais éssayé.
    J'ai pas compris pourquoi cube est dans le namespace?

    tiens l'url du fichier xml : http://www.ecb.europa.eu/stats/eurof...xref-daily.xml

  19. #19
    Membre confirmé
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2008
    Messages
    97
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Octobre 2008
    Messages : 97
    Par défaut
    Essaye ça, pour récupérer la valeur de rate, j'ai aps essayer de compiler le code mais ds l'ensemble ca doit etre bon
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    SAXBuilder sxb = new SAXBuilder();
    try
    {
       document = sxb.build(new File("devises.xml"));
    }
    catch(Exception e){}
    racine = document.getRootElement();
    List<Element> lstElement = (List<Element>) XPath.selectNodes(document, "//Cube[@currency='USD']");			
    if (lstElement.size() > 0) {	
    Element cubeElement=lstElement.get(0);
    String rate=cubeElement.getAttributeValue("rate");
    }

  20. #20
    Membre éclairé Avatar de pendoRa
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Mai 2007
    Messages
    317
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2007
    Messages : 317
    Par défaut
    Merci tamildark,

    dans la condition
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(lstElement.size() > 0) { }
    la condition ne se vérifie pas, peut être qu'il ne s'y retrouve pas avec XPath.SelectNodes ?

    Merci de votre aide en tout les cas.

    Edit : J'ai éssayé une méthode d'un de mes programmes Java qui lit un ml de configuration.

    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
    		SAXBuilder sxb = new SAXBuilder();
    		Document document = null;
    		try {
    			document = sxb.build(new File("devises.xml"));
    			org.jdom.Element racine = document.getRootElement();
    			XPath xpa = null;
    			xpa = XPath.newInstance("//usd"); // variables
    			chemin = xpa.valueOf(racine);
    			//Si chemin trouvé, l'ecrire dans la console...
    			System.out.println(chemin);
    		}catch (JDOMException e) {
     
    			e.printStackTrace();
    		} catch (IOException e) {
     
    	}
    	}
    }
    Mais c'est pas encore ca :s
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <?xml version="1.0" encoding="UTF-8"?> 
    <java version="1.6.0_17" class="java.beans.XMLDecoder"> 
     <usd>1,3841</usd>
     <eur>1</eur> 
     <yen>114</yen> 
    </java>
    Cela fonctionne avec un xml comme ca.. mais le problème c'est qu'il est pas comme ca sur le site de la BCE ! ; (

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Charger 2 frames à partir d'un lien IE KO FF OK
    Par emmeline.a dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 06/10/2010, 15h13
  2. charger un swf à partir d'un xml
    Par condon dans le forum ActionScript 1 & ActionScript 2
    Réponses: 2
    Dernier message: 26/08/2008, 17h21
  3. Enregistrement à partir du lien internet
    Par imparator_42 dans le forum Langage
    Réponses: 13
    Dernier message: 30/05/2008, 21h15
  4. charger un xml avec liens hypertextes
    Par lecirederf dans le forum Flash
    Réponses: 12
    Dernier message: 23/10/2006, 15h03
  5. Lien internet a partir d'une image
    Par Furlaz dans le forum C++Builder
    Réponses: 28
    Dernier message: 15/06/2006, 13h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo