1

How do I actually get the weather from webservicex.net?

thufir@dur:~/NetBeansProjects/javaClientGlobalWeather$ 
thufir@dur:~/NetBeansProjects/javaClientGlobalWeather$ gradle clean shadowJar;java -jar build/libs/weather.jar 

> Task :shadowJar 
A problem was found with the configuration of task ':shadowJar'. Registering invalid inputs and outputs via TaskInputs and TaskOutputs methods has been deprecated and is scheduled to be removed in Gradle 5.0.
 - No value has been specified for property 'mainClassName'.
The SimpleWorkResult type has been deprecated and is scheduled to be removed in Gradle 5.0. Please use WorkResults.didWork() instead.


BUILD SUCCESSFUL in 2s
3 actionable tasks: 3 executed
Feb 16, 2018 2:42:10 AM net.bounceme.dur.java.soap.weather.App run
INFO: begin
Feb 16, 2018 2:42:11 AM net.bounceme.dur.java.soap.weather.Weather getWeather
INFO: Data Not Found
thufir@dur:~/NetBeansProjects/javaClientGlobalWeather$ 

java code:

package net.bounceme.dur.java.soap.weather;

import java.util.logging.Logger;
import net.webservicex.GetCitiesByCountry;
import net.webservicex.GetWeather;
import net.webservicex.GetWeatherResponse;
import net.webservicex.GlobalWeather;
import net.webservicex.GlobalWeatherSoap;
import net.webservicex.ObjectFactory;

public class Weather {

    private static final Logger log = Logger.getLogger(App.class.getName());

    public void getWeather(String country, String city) {
        GlobalWeather gw = new GlobalWeather();

        GlobalWeatherSoap gws = gw.getGlobalWeatherSoap();
        String w = gws.getWeather(city, country);

        log.info(w);
    }

    public void getWeather3(String country, String city) {
        ObjectFactory o = new ObjectFactory();

        GetWeather gw = o.createGetWeather();

        gw.setCountryName(country);
        gw.setCityName(city);

        GetWeatherResponse gwr = o.createGetWeatherResponse();

        gwr.setGetWeatherResult(city);

        String r = gwr.getGetWeatherResult();

        log.info(r);

    }

    public void getWeather2(String country, String city) {
        log.info("getting weather");

        GetCitiesByCountry g = new GetCitiesByCountry();

        g.setCountryName(country);

        log.fine(g.getCountryName());

        GetWeather getWeather = new GetWeather();

        getWeather.setCountryName(country);
        getWeather.setCityName(city);

        log.fine(getWeather.getCountryName());
        log.fine(getWeather.getCityName());
        log.info(getWeather.toString());

        GetWeatherResponse weatherResponse = new GetWeatherResponse();

        log.info("weather response result:\t" + weatherResponse.getGetWeatherResult());

        log.info("end");
    }

}

the stubs were generated by wsimport http://www.webservicex.net/globalweather.asmx?WSDL -Xnocompile. Looking through the generated classes, not sure how to actually use this service from Java.

Do Need to pass the WSDL to GlobalWeather or GlobalWeatherSoap? That would be odd, since they were generated with wsimport. Is this just a matter of knowing how to read the WSDL?

See also:

Working Soap client example

Thufir
  • 8,216
  • 28
  • 125
  • 273

0 Answers0