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

GWT et Vaadin Java Discussion :

GWT et Yahoo weather RSS


Sujet :

GWT et Vaadin Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Janvier 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Janvier 2009
    Messages : 107
    Par défaut GWT et Yahoo weather RSS
    bonjour,

    j'ai beau cherché un moyen d'afficher yahoo weather dans mon application gwt.

    j'ai suivi ce tuto.

    je lance en local pour tester mais je recupere pas les informations depuis le WS yahoo

    voici la classe qui recupere les informations a partir d'un zipCode :
    classe
    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
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
     
     
    package jee.gwt.server;
     
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
     
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
     
    import jee.gwt.client.YweatherService;
     
    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
    import org.apache.commons.httpclient.methods.GetMethod;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.xml.sax.SAXException;
     
    import com.google.gwt.user.client.Window;
    import com.google.gwt.user.server.rpc.RemoteServiceServlet;
     
    public class YweatherServiceImpl extends RemoteServiceServlet implements YweatherService
    {
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
    	private static DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
     
    	public YweatherServiceImpl()
    	{
     
    	}
     
    	public String getWeatherHtmlInfos(String zip)
    	{
    		return getWeatherHtml( getWeatherRssDocument(zip) );
    	}
     
     
    	private String getWeatherHtml(Document rss)
    	{
    		Element item = (Element)rss.getElementsByTagName("item").item(0);
    		Element desc = (Element)item.getElementsByTagName("description").item(0);
    		return desc.getFirstChild().getNodeValue();
    	}
     
     
    	private Document getWeatherRssDocument(String zip)
    	{
     
    		String url = getYahooRssUrl(zip);
    //		URLConnection conn = null;
    //		try {
    //			conn = new URL(url).openConnection();
    //		} 
    //		catch (MalformedURLException e3) 
    //		{
    //			e3.printStackTrace();
    //		} 
    //		catch (IOException e3) 
    //		{
    //			e3.printStackTrace();
    //		}
    		//MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    		HttpClient client = new HttpClient();
    		GetMethod get = new GetMethod(url);
     
    		try 
    		{
    			int resultCode = client.executeMethod(get);
    			if (resultCode == 200)
     
    			{
    				InputStream in = get.getResponseBodyAsStream();
    				//in = conn.getInputStream();
    				DocumentBuilder builder = null;
    				try 
    				{
    					builder = builderFactory.newDocumentBuilder();
    					try 
    					{
    						return builder.parse(in);
    					} 
    					catch (SAXException e1) 
    					{
    						Window.alert( "Erreur d'analyse : " + e1.getMessage() );
    					}
    				} 
    				catch (ParserConfigurationException e2) 
    				{
    					Window.alert( "Erreur de Configuration  du Parser : " + e2.getMessage() );				}
    			}
    		} 
    		catch (IOException e) 
    		{
    			Window.alert( "Probleme de communication HTTP" + e.getMessage() );
    		}
    //		finally 
    //		{
    //		      get.releaseConnection();
    //		}
     
    		return null;
    	}
     
     
    	private String getYahooRssUrl(String zip) 
    	{
    		final String base= "http://xml.weather.yahoo.com/forecastrss?";
    		return base + "p=" + zip;
    	}
     
    }
    la meethode getWeatherHtmlInfos(zip) recupere les infos depuis yahoo mais la String de retour ne contient rien et je n'est pas de messages d'erreurs !
    Quelq'un peut m'aider SVP ?

    Merci d'avance

  2. #2
    Rédacteur
    Avatar de benwit
    Profil pro
    dev
    Inscrit en
    Septembre 2004
    Messages
    1 676
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Septembre 2004
    Messages : 1 676
    Par défaut
    As tu essayé d'afficher le document rss que reçoit ta méthode en paramètre : getWeatherHtml(Document rss)

    Peut être est-ce le document qui ne contient pas la chaine que tu recherches. Ce qui expliquerait que tu n'es pas d'erreurs.

  3. #3
    Membre confirmé
    Inscrit en
    Janvier 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Janvier 2009
    Messages : 107
    Par défaut
    Citation Envoyé par benwit Voir le message
    As tu essayé d'afficher le document rss que reçoit ta méthode en paramètre : getWeatherHtml(Document rss)

    Peut être est-ce le document qui ne contient pas la chaine que tu recherches. Ce qui expliquerait que tu n'es pas d'erreurs.
    je crois que oui, j'ai essayé de l'afficher en mode console : l'objet HTML ne contient rien

  4. #4
    Membre confirmé
    Inscrit en
    Janvier 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Janvier 2009
    Messages : 107
    Par défaut
    voila le ce que j'obtiens :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <DIV class=gwt-HTML></DIV>
    normalement je dois obtenir le resultat de yahoo weather n'est ce pas ?

  5. #5
    Membre confirmé
    Inscrit en
    Janvier 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Janvier 2009
    Messages : 107
    Par défaut
    Citation Envoyé par benwit Voir le message
    As tu essayé d'afficher le document rss que reçoit ta méthode en paramètre : getWeatherHtml(Document rss)

    Peut être est-ce le document qui ne contient pas la chaine que tu recherches. Ce qui expliquerait que tu n'es pas d'erreurs.
    j'ai retsté l'application je recuppere le rss yahoo weather :

    voici le resultat obtenu
    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
     
     
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    		<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
    			<channel>
     
    <title>Yahoo! Weather - Rochester, NY</title>
    <link>http://us.rd.yahoo.com/dailynews/rss/weather/Rochester__NY/*http://weather.yahoo.com/forecast/USNY1232_f.html</link>
    <description>Yahoo! Weather for Rochester, NY</description>
    <language>en-us</language>
    <lastBuildDate>Sat, 29 Jan 2011 1:52 pm EST</lastBuildDate>
    <ttl>60</ttl>
    <yweather:location city="Rochester" region="NY"   country="US"/>
    <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
    <yweather:wind chill="25"   direction="0"   speed="0" />
    <yweather:atmosphere humidity="82"  visibility="2.5"  pressure="29.86"  rising="1" />
    <yweather:astronomy sunrise="7:28 am"   sunset="5:17 pm"/>
    <image>
    <title>Yahoo! Weather</title>
    <width>142</width>
    <height>18</height>
    <link>http://weather.yahoo.com</link>
    <url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url>
    </image>
    <item>
    <title>Conditions for Rochester, NY at 1:52 pm EST</title>
    <geo:lat>43.16</geo:lat>
    <geo:long>-77.61</geo:long>
    <link>http://us.rd.yahoo.com/dailynews/rss/weather/Rochester__NY/*http://weather.yahoo.com/forecast/USNY1232_f.html</link>
    <pubDate>Sat, 29 Jan 2011 1:52 pm EST</pubDate>
    <yweather:condition  text="Light Snow"  code="14"  temp="25"  date="Sat, 29 Jan 2011 1:52 pm EST" />
    <description><![CDATA[
    <img src="http://l.yimg.com/a/i/us/we/52/14.gif"/><br />
    <b>Current Conditions:</b><br />
    Light Snow, 25 F<BR />
    <BR /><b>Forecast:</b><BR />
    Sat - Snow Showers. High: 26 Low: 17<br />
    Sun - Few Snow Showers. High: 22 Low: 8<br />
    <br />
    <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Rochester__NY/*http://weather.yahoo.com/forecast/USNY1232_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
    (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
    ]]></description>
    <yweather:forecast day="Sat" date="29 Jan 2011" low="17" high="26" text="Snow Showers" code="14" />
    <yweather:forecast day="Sun" date="30 Jan 2011" low="8" high="22" text="Few Snow Showers" code="14" />
    <guid isPermaLink="false">USNY1232_2011_01_29_13_52_EST</guid>
    </item>
    </channel>
    </rss>
    <!-- api3.weather.ch1.yahoo.com uncompressed/chunked Sat Jan 29 11:50:20 PST 2011 -->
    et voici les erreurs affichées :

    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
     
     
    Erreur d'analyse : Premature end of file.
    Starting Jetty on port 8888
       [WARN] Exception while dispatching incoming RPC call
    com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.lang.String mql.gwt.client.YweatherService.getWeatherHtmlInfos(java.lang.String)' threw an unexpected exception: java.lang.NullPointerException
    	at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:378)
    	at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:581)
    	at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:207)
    	at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:243)
    	at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    	at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
    	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    	at org.mortbay.jetty.Server.handle(Server.java:324)
    	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
    	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
    	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
    	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
    Caused by: java.lang.NullPointerException
    	at jee.gwt.server.YweatherServiceImpl.getWeatherHtml(YweatherServiceImpl.java:48)
    	at jee.gwt.server.YweatherServiceImpl.getWeatherHtmlInfos(YweatherServiceImpl.java:42)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:562)
    	... 22 more
    [ERROR] 500 - POST /exemple/yweather (127.0.0.1) 57 bytes
       Request headers
          Accept: */*
          Referer: http://127.0.0.1:8888/Exemple.html?gwt.codesvr=127.0.0.1:9997
          Accept-Language: fr
          User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2)
          Accept-Encoding: gzip, deflate
          Host: 127.0.0.1:8888
          Connection: Keep-Alive
          x-gwt-module-base: http://127.0.0.1:8888/exemple/
          Content-Type: text/x-gwt-rpc; charset=utf-8
          x-gwt-permutation: HostedMode
          Content-Length: 169
          Cache-Control: no-cache
       Response headers
          Content-Type: text/plain
    [Fatal Error] :1:1: Premature end of file.
    et voici le bout d code d'ou vient l'erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    	private String getWeatherHtml(Document rss)
    	{
    		Element item = (Element)rss.getElementsByTagName("item").item(0);
    		Element desc = (Element)item.getElementsByTagName("description").item(0);
    		return desc.getFirstChild().getNodeValue();
    	}

    je comprends pas

  6. #6
    Rédacteur
    Avatar de benwit
    Profil pro
    dev
    Inscrit en
    Septembre 2004
    Messages
    1 676
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : dev

    Informations forums :
    Inscription : Septembre 2004
    Messages : 1 676
    Par défaut
    System.out.println(rss.getElementsByTagName("item"));
    Element item = (Element)rss.getElementsByTagName("item").item(0);
    System.out.println(item);
    System.out.println(item.getElementsByTagName("description"));
    Element desc = (Element)item.getElementsByTagName("description").item(0);
    System.out.println(desc);
    System.out.println(desc.getFirstChild());
    return desc.getFirstChild().getNodeValue();
    si l'un des System.out.println t'affiche un null, tu aura trouvé ce qui cause le NullPointerException

  7. #7
    Membre confirmé
    Inscrit en
    Janvier 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Janvier 2009
    Messages : 107
    Par défaut
    Citation Envoyé par benwit Voir le message
    si l'un des System.out.println t'affiche un null, tu aura trouvé ce qui cause le NullPointerException
    d'accord , je testerai et je posterai le resultat

  8. #8
    Membre confirmé
    Inscrit en
    Janvier 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Janvier 2009
    Messages : 107
    Par défaut
    Citation Envoyé par benwit Voir le message
    si l'un des System.out.println t'affiche un null, tu aura trouvé ce qui cause le NullPointerException
    vous avez raison, je me suis trompé au depart

    j'ai fait un test j'ai compris alors que le DocumentBuilder ne parse pas l'inputStream

    Que faire alors ?

  9. #9
    Membre confirmé
    Inscrit en
    Janvier 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Janvier 2009
    Messages : 107
    Par défaut
    Citation Envoyé par benwit Voir le message
    si l'un des System.out.println t'affiche un null, tu aura trouvé ce qui cause le NullPointerException
    j'ai fait le test que vous m'avez demandé et voici le resultat :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl@a32cdd
    [item: null]
    [description: null]

  10. #10
    Membre confirmé
    Inscrit en
    Janvier 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Janvier 2009
    Messages : 107
    Par défaut
    Citation Envoyé par benwit Voir le message
    si l'un des System.out.println t'affiche un null, tu aura trouvé ce qui cause le NullPointerException
    j'ai fait le test que vous m'avez demandé et voici le resultat :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    com.sun.org.apache.xerces.internal.dom.DeepNodeListImpl@a32cdd
    [item: null]
    [description: null]

Discussions similaires

  1. Réponses: 2
    Dernier message: 30/01/2015, 17h06
  2. Réponses: 0
    Dernier message: 10/10/2014, 17h27
  3. Réponses: 1
    Dernier message: 08/04/2010, 23h33
  4. [Connexion] Ports : MSN, ICQ, Yahoo! ...
    Par StouffR dans le forum Développement
    Réponses: 7
    Dernier message: 26/05/2003, 11h13

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