Weather Service part 2

Weather service delegates its process in two formats, one of the service is based of a XML server and another one plain old wsdl style.  For either of it we would need a XSD to parse data elements. To start with we will download or reference the XSD for weather service. This link is used for the XSD information.One can download the actual WSDL from here.  If you examine the WSDL producer/webservice exchanges data in XML format. So it would be ideal to fit a XML parser for this scenario. Since am using Java 5 for our development and I know Jaxb has matured well over the past version. Here is the high level arch diagram for Jaxb,


On a high level JAXB contains the following components- Schema compiler, Schema generator and binding runtime framework. We will use this framework to marshal and un-marshal the xml schema that is hosted by weather service. So according to specifications after we download the xsd, we will use the XJC file to generate our Jaxb object classes. JAXB API's as mentioned above will have the XJC installed. For our case I have the xsd stored in my drive /user/sathish/workspace/weather.xsd. Running the xjc command generate the following classes for weather service xsd.

Jaxb classes

Now that java objects are ready, we can start constructing the actual parser.

WeatherService Parser.

The working of Jaxb needs a brief introduction before we dissect this above code. According to Java tutorial general steps of Jaxb binding are,

  • Generate Classes- A schema is used to generate the JAXB java classes.

  • Compile Classes-All the generated classes are to be compiled.

  • UnMarshall-XML documents that follow the XSD schema rules are converted to Jaxb based java objects. Unmarshall has the capability to build a Dom node, String buffer and sax buffers.

  • Generate Content tree-Unmarshalling process produces a content tree represents a structure and content of the source XML documents.

  • Validate-Unmarshalling process has an optional validation process of the source XML document.

  • Process content- Client application can modify the Jaxb object to a

  • XML data represented in the Java content tree.

  • Marshal-Processed content is marshaled from one or more XML output documents.

First and second bullet points are performed by the XJC compiler. To un-marshall the content information we create an instance of the JAXBContext. From the context we create the actual unmarshaller. But before that, we need a latitude and longitude value to get the actual weather information. Weatherservice contains within it  a utility service that performs this operation.

So here is the actual implementation details for the weather-service. We will be using a facade to request the input zip code, from the facade layer application delegates the call to WeatherServiceClient object. Client object now communicates with the WSDL service and returns the actual response. Information response is now sent to a parser, data from parser is sent to the UI layer for display. Here is a sequence diagram from this workflow.


Next we will see how to bring the GeoService API to get ZipCode and City information.