2

I am learning how to implement web services in Java. Following the example in O'Reilly's book "Learning Java," I downloaded a WSDL file (see http://bit.ly/13moiTh) for a weather service at cdyne.com and generated a set of classes using the wsimport tool.

The first problem was that when I generated a JAR file and referenced it in the Eclipse project, the classes were not recognized. I had to use wsimport -keep and individually copy all source files into the project to make it build.

Next, to make sure that the service was available, I constructed a simple HTTP POST client based on the code from the book. I could successfully access the getCityWeatherByZIP service with that code, so there was no connectivity or authentication issue.

Finally, I tried to access the getCityWeatherByZIP and getCityForecastByZIP services using the automatically-generated web services client code. Both silently failed, i.e. the isSuccess() methods returned false and all response fields were null:

Weather service = new Weather();
WeatherSoap weatherSoap = service.getWeatherSoap();
WeatherReturn weather = weatherSoap.getCityWeatherByZIP(ZIP);
if (weather.isSuccess()) {      
    System.out.format("%s, %s : %s : Temperature: %s, Wind: %s\n",
            weather.getCity(), weather.getState(), weather.getDescription(),
            weather.getTemperature(), weather.getWind());
}
else {
    System.out.println("Failed to obtain weather");
}

In stepping through the code, in getCityWeatherByZIP() I discovered the following NoSuchMethodException: com.sun.xml.internal.ws.api.message.Packet.setHeaderList(com.sun.xml.internal.ws.api.message.HeaderList)"

This exception occurs in line that says (in the Debug perspective of Eclipse): "SEIStub.invoke(Object, Method, Object[]) line: not available"

Clearly, the Packet.setHeaderList(HeaderList) method does not exist, which is also corroborated by the documentation of the non-internal class: https://jax-ws.java.net/nonav/jax-ws-20-fcs/arch/com/sun/xml/ws/api/message/Packet.html

I am using the latest JDK 1.7 and Eclipse Version: Kepler Service Release 1, Build id: 20130919-0819.

I do not know how to fix this problem. Any help would be appreciated.

user1408140
  • 639
  • 3
  • 9
  • 20
  • 1
    I fixed the problem: the package-info.java file was missing in the Eclipse project. Once I added it to the package following these instructions, everything started to work: http://stackoverflow.com/questions/8405336/how-do-i-use-or-edit-package-info-java – user1408140 Feb 27 '14 at 18:06

1 Answers1

0

In addition to the source code from the book, you also need a copy of the JAX-WS web service code in order to compile and run. You update the Build Path inside Eclipse to reference any jars for the JAX-WS web service, and it sounds like Eclipse doesn't have a copy on the classpath.

JAX-WS is the specification but you will need an actual implementation of JAX-WS in order to run, possibly the Reference Implementation?

mikemil
  • 1,213
  • 10
  • 21
  • Well, I also have a very simple implementation of a web service using WebService and WebMethod annotations from another example in the book, and it seems to run fine. Without doing anything special, I can just start the program in Eclipse and then use the browser to access the running server, e.g. to obtain the automatically-generated WSDL file. The client code I described above compiles and runs without any visible exceptions (I can only see exceptions when stepping through the code); however, the WeatherReturn and ForecastReturn instances are simply empty. So, I do not know what to do. – user1408140 Feb 24 '14 at 21:58
  • Have you seen this page - http://wiki.cdyne.com/index.php/CDYNE_Weather#Example_Source_Code which is from their wiki - looks like it has some links at the bottom of the page to some samples in different languages. – mikemil Feb 24 '14 at 22:26
  • Thanks, but that does not solve the problem. The code from the book is very straightforward and uses the API provided by classes automatically generated by wsimport from cdyne's WSDL. BTW, this says that JDK 1.7 includes JAX-WS 2.2: http://docs.oracle.com/javase/7/docs/technotes/guides/xml/jax-ws/ which explains why I can compile and run both the client and server without anything special in Eclipse or from the command line. – user1408140 Feb 24 '14 at 22:42