JAX – WS – 13 – Sample Public Web Service – Airport Web Service

Merhaba Arkadaslar
Bu bolumde internetten public olarak bulabilecegimiz bir web service’i kullanacagiz.
Bunun icin Airport Web Service i ornek olarak yapabiliriz.

http://www.webservicex.net/airport.asmx?wsdl

wsimport

Client Java siniflarimizi komut satirinda wsimport komutu ile olusturabiliriz.
Masaustunde bir klasor olusturduktan sonra ilgili komutu command lineda calistiralim. (dosyalari bu klasor icerisinde olusturabiliriz)

wsimport -keep -verbose http://www.webservicex.net/airport.asmx?wsdl

Yeni bir Java project olusturalim , olusan java dosyalarini projemize ekleyelim.

Simdi de test sinifimizi yazalim;
3 farkli metodu kullanarak Airport bilgilerine ulasabiliriz ;

getAirportInformationByAirportCode
getAirportInformationByCityOrAirportName
getAirportInformationByCountry

TestAirportWebService.java

package test;

import net.webservicex.Airport;
import net.webservicex.AirportSoap;

public class TestAirportWebService {

	private static String ISTANBUL = "IST";
	private static String ANKARA_ESENBOGA = "ANKARA ESENBOGA";
	private static String TURKEY ="TURKEY";

	public static void main(String[] args) {
		Airport airport = new Airport();
		AirportSoap airportSoap = airport.getAirportSoap();
		//

		System.out.println("getAirportInformationByAirportCode : ");
		System.out.println("--------------------------------------");
		String airportInformationByAirportCode = airportSoap.getAirportInformationByAirportCode(ISTANBUL);
		System.out.println(airportInformationByAirportCode);
		System.out.println("--------------------------------------");
		
		System.out.println("getAirportInformationByCityOrAirportName : ");
		System.out.println("--------------------------------------");
		String airportInformationByCity=airportSoap.getAirportInformationByCityOrAirportName(ANKARA_ESENBOGA);
		System.out.println(airportInformationByCity);
		System.out.println("--------------------------------------");
		
		System.out.println("getAirportInformationByCountry : ");
		System.out.println("--------------------------------------");
		String airportInformationByCountry=airportSoap.getAirportInformationByCountry(TURKEY);
		System.out.println(airportInformationByCountry);
		System.out.println("--------------------------------------");

	}
}

Ornegimizi calistirdigimizda;
(Burada outputun bir kismini paylasiyorum )

getAirportInformationByAirportCode : 
--------------------------------------
<NewDataSet>
  <Table>
    <AirportCode>IST</AirportCode>
    <CityOrAirportName>ISTANBUL ATATURK</CityOrAirportName>
    <Country>Turkey</Country>
    <CountryAbbrviation>TR</CountryAbbrviation>
    <CountryCode>679</CountryCode>
    <GMTOffset>-2</GMTOffset>
    <RunwayLengthFeet>9842</RunwayLengthFeet>
    <RunwayElevationFeet>157</RunwayElevationFeet>
    <LatitudeDegree>40</LatitudeDegree>
    <LatitudeMinute>58</LatitudeMinute>
    <LatitudeSecond>0</LatitudeSecond>
    <LatitudeNpeerS>N</LatitudeNpeerS>
    <LongitudeDegree>28</LongitudeDegree>
    <LongitudeMinute>49</LongitudeMinute>
    <LongitudeSeconds>0</LongitudeSeconds>
    <LongitudeEperW>E</LongitudeEperW>
  </Table>
  <Table>
    <AirportCode>IST</AirportCode>
    <CityOrAirportName>ISTANBUL ATATURK</CityOrAirportName>
    <Country>Turkey</Country>
    <CountryAbbrviation>TR</CountryAbbrviation>
    <CountryCode>679</CountryCode>
    <GMTOffset>-2</GMTOffset>
    <RunwayLengthFeet>9842</RunwayLengthFeet>
    <RunwayElevationFeet>157</RunwayElevationFeet>
    <LatitudeDegree>40</LatitudeDegree>
    <LatitudeMinute>58</LatitudeMinute>
    <LatitudeSecond>0</LatitudeSecond>
    <LatitudeNpeerS>N</LatitudeNpeerS>
    <LongitudeDegree>28</LongitudeDegree>
    <LongitudeMinute>49</LongitudeMinute>
    <LongitudeSeconds>0</LongitudeSeconds>
    <LongitudeEperW>E</LongitudeEperW>
  </Table>
</NewDataSet>
--------------------------------------

Via Eclipse

Eclipse yardimiyla da Web Service client java dosyalarini olusturabiliriz.(Bir onceki ornekte yaptigimiz gibi)
Bunun icin normal Java SE projesi de kullanabiliriz. Yeni bir proje olusturalim (injavawetrust.jaxws.client.axis)
Projeye sag tiklayip New -> Other -> Web Services -> Web Service Client diyelim.
Sonrasinda WSDL linkinden yararlanalim.

http://www.webservicex.net/airport.asmx?wsdl

Simdi de test sinifimizi yazalim;
3 farkli metodu kullanarak Airport bilgilerine ulasabiliriz , yukaridaki client ornegimize benzer sekilde yaziyoruz..

getAirportInformationByAirportCode
getAirportInformationByCityOrAirportName
getAirportInformationByCountry

TestAirportWebService.java

package test;

import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import NET.webserviceX.www.AirportLocator;
import NET.webserviceX.www.AirportSoap;

public class TestAirportWebService {

	private static String ISTANBUL = "IST";
	private static String ANKARA_ESENBOGA = "ANKARA ESENBOGA";
	private static String TURKEY = "TURKEY";

	public static void main(String[] args) throws RemoteException, ServiceException {

		AirportLocator locator = new AirportLocator();
		AirportSoap airportSoap = locator.getairportSoap();

		System.out.println("getAirportInformationByAirportCode : ");
		System.out.println("--------------------------------------");
		String airportInformationByAirportCode = airportSoap.getAirportInformationByAirportCode(ISTANBUL);
		System.out.println(airportInformationByAirportCode);
		System.out.println("--------------------------------------");

		System.out.println("getAirportInformationByCityOrAirportName : ");
		System.out.println("--------------------------------------");
		String airportInformationByCity = airportSoap.getAirportInformationByCityOrAirportName(ANKARA_ESENBOGA);
		System.out.println(airportInformationByCity);
		System.out.println("--------------------------------------");

		System.out.println("getAirportInformationByCountry : ");
		System.out.println("--------------------------------------");
		String airportInformationByCountry = airportSoap.getAirportInformationByCountry(TURKEY);
		System.out.println(airportInformationByCountry);
		System.out.println("--------------------------------------");

	}
}

Ornegimizi calistirdigimizda ciktimiz yine ayni sekilde olacaktir.

 

Github kaynak kodlar / source folder
injavawetrust.jaxws.airport.client | injavawetrust.jaxws.airport.client.axis

Yazimi burada sonlandiriyorum.
Herkese bol Javali gunler dilerim.
Be an oracle man , import java.*;

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published.