JAX – WS – 01 – Hello JAX – WS

Acknowledgement/Takdim/Mukaddime

İlim; ezberlenen şey değil, ezberlenen şeyden hasıl olan faydadır.
İmam-ı Şafii (Radıyallahu Anh)

Web Service nedir ?

Merhaba Arkadaslar
Yeni bir tutorial serisine bu yazi ile basliyoruz.
Faydali olmasi dileklerimle…

Web Service kavrami “self explanatory/ açıklama gerektirmeyecek kadar açık” bir isme sahiptir.
Web/Internet uzerinde calisan , HTTP protokolu ile iletisim kurabilecegimiz hizmetler/uygulamalardir.

Web Service kavrami , RPC (Remote Procedure Call) mekanizmasinin gelismesi(evolve) ile ortaya cikan bir kavramdir.

Web services evolved from the RPC (Remote Procedure Call) mechanism in 
DCE (Distributed Computing Environment), a framework for software development from 
the early 1990s. 

Web Service’leri farkli uygulamalarin birlikte calismalarina olanak saglar. (interoperating)
Farkli uygulamalar , farkli programlama dilleri ya da frameworklerini kullansalar bile bu birlikte calisma prensibini (interoperating) Web Service’ler ile saglayabilirler.

Java EE Tutorial’da Web Service icin su aciklama yer almaktadir ;

Web services are client and server applications that communicate over the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP). As described by the World Wide Web Consortium (W3C), web services provide a standard means of interoperating between software applications running on a variety of platforms and frameworks.

What Are Web Services?

Java da 2 tip Web Service bulunmaktadir.

JAX-RS ile ilgili tutoriallari ilgili linkte bulabilirsiniz. Burada JAX-WS i incelemeye baslayacagiz.

Hello JAX-WS

JAX-WS , Java API for XML Web Services olarak ifade edilmektedir. Big Web Services olarak da isimlendirilmektedir.

Big web service’ler XML message formatini ve SOAP standardini kullanmaktadir.

Big web services use XML messages that follow the Simple Object Access Protocol (SOAP) 
standard, an XML language defining a message architecture and message formats.

Client ile Server/Service arasinda kullanilan programlama dilinin ayni olmasina gerek yoktur. Birbirinden farkli bir dilde olsa XML ortak dil olacaktir.

XML Web Services use XML as the basis for communication between Web-based 
services and clients of those services and inherit XML’s platform independence.
jaxws spec

JAX-WS , Java EE/Enterprise Edition platformunun bir parcasidir.

JSR-224 linkinden ilgili JSR: Java Specification Request’e erisim saglanabilir.
JSR-224 sadece bir spect’tir. Simdi de JAX-WS icin implementation’lari listeleyelim ;

  • Metro Project in GlassFish /reference implementation
  • Apache CXF
  • Apache Axis2
  • JBossWS in JBoss
  • IBM WebSphere Jax-Ws in WebSphere
  • Oracle Weblogic

JAX-WS reference implementation , Glassfish projesinin bir parcasi olan Metro ‘dur.
JAX-WS official olarak JavaEE nin bir parcasidir , fakat JDK1.6 ve uzeri versiyonlar icin JAX-WS sadece core java se uygulamasiyla da publish edilebilir.
Bununla birlikte Apache Tomcat gibi bir Container ile de publish edilebilir.

Burada ilk olarak Java SE uygulamasi uzerinde publish islemini gerceklestirecegiz.
Bir sonraki bolumde ise Apache Tomcat uzerinde publish islemini yapacagiz.

SOAP , WSDL , UDDI ?

SOAP , Simple Object Access Protocol olarak ifade edilmektedir.
SOAP , Web Service gelistirmek icin kullanilan , XML tabanli ve standard olmus bir protocol dur. Platform ve programlama dili bagimsizdir.

SOAP message’lari complex bir yapiya sahiptir JAX-WS API’si bu complexity’yi developerdan saklamaktadir.

SOAP messages are complex, the JAX-WS API hides this complexity 
from the application developer.

JAX-WS sayesinde , developer SOAP message’larini olusturmak/generate ya da parse etmek zorunda kalmaz.
JAX-WS , call’lari (istek/request) ve response’lari SOAP messaga’larina donusturur.

WSDL , Web Service Description Language anlamina gelmektedir.
WSDL , XML tabanli bir dokumandir ve Web Service hakkinda tum teknik bilgileri barindirmaktadir.
method isimleri , parametreleri , service ismi , port bilgisi gibi …

WSDL , bir web service nasil erisebiliriz ve hangi isleri/operation/method gerceklestirilebilecegini tanimlar.

WSDL is "an XML format for describing network services as a set of endpoints operating 
on messages containing either document-oriented or procedure-oriented information." 
WSDL can be considered the de-facto service description language for XML Web Services.
jaxws spec

https://www.w3.org/TR/wsdl

WSDL can be used to describe the details of the contract, 
which may include messages, operations, bindings, and the location of the web service.
https://docs.oracle.com/javaee/7/tutorial/webservices-intro002.htm 

WSDL Elements

<definitions>
<definitions> element’i WSDL dokumanindaki root element’tir ve web service’in ismini tanimlar. targetNamespace attribute’u ilgili Java package ile iliskilidir.

A WSDL document has a root wsdl:definitions element. 
A wsdl:definitions element and its associated targetNamespace attribute 
is mapped to a Java package.

<types>
<types> element’i Web Service’te kullanilan data tiplerini belirtmek icin kullanilmaktadir.
Web Service eger basit olarak String ve Integer tipinde type kullaniyorsa bu durumda <types> element’in de bir tanima gerek yoktur.

Complex Type’lar icin yani Person sinifimiz olsun id , name , surname property’leri olsun.

Ornek XML yapisini inceleyecek olursak , <types> element’inin WSDL icerisinde nasil kullanildigini gostermektedir.

Complex Type’lar icin bu bilgi ayri bir link uzerinde yer alacaktir yani ayri bir dokuman olacaktir.

Types Supported by JAX-WS

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://service/">
	<xs:complexType name="person">
		<xs:sequence>
			<xs:element name="id" type="xs:int"/>
			<xs:element name="name" type="xs:string" minOccurs="0"/>
			<xs:element name="surname" type="xs:string" minOccurs="0"/>
		</xs:sequence>
	</xs:complexType>
</xs:schema>

<message>
<message> element’i Web Service’te tanimli metotlari ifade etmektedir.
<message> element’inde 0 ya da daha fazla <part> element’i icerebilir.

Ornek WSDL blogu inceleyelim ;
Burada getWelcomeMessage metodu tanimlanmaktadir ve parametre olarak String tipinde 1 parametre almaktadir.

getWelcomeMessageResponse message etiketi de donus tipini tanimlamaktadir.

<message name="getWelcomeMessage">
	<part name="name" type="xsd:string" />
	<part name="surname" type="xsd:string" />
</message>
<message name="getWelcomeMessageResponse">
	<part name="return" type="xsd:string" />
</message>

<portType>
<portType> element’inde <input> <output> elementleri yer almaktadir.
message attribute’u ile <message> element’i eslesmektedir.

JAX-WS spect’in de portType icin su ifade yer almaktadir ;

A WSDL port type is a named set of abstract operation definitions.

wsdl:portType ‘da tanimli interface’e Service Endpoint Interface ya da kisaca SEI adi verilir.
<portType> icerisinde <operation> yer almaktadir. SEI’de tanimli metotlar burada <operation> etiketi ile yer almaktadir.

A Java interface mapped from a wsdl:portType is called a Service Endpoint Interface 
or SEI for short.
Each wsdl:operation in a wsdl:portType is mapped to a Java method 
in the corresponding Java service endpoint interface.
<portType name="MessageWriter">
	<operation name="getWelcomeMessage" parameterOrder="name surname">
		<input
			wsam:Action="http://service.ws.injavawetrust/MessageWriter/getWelcomeMessageRequest"
			message="tns:getWelcomeMessage" />
		<output
			wsam:Action="http://service.ws.injavawetrust/MessageWriter/getWelcomeMessageResponse"
			message="tns:getWelcomeMessageResponse" />
	</operation>
</portType>

Service Endpoint Interface (SEI) taniminda javax.jws.WebService annotation’i kullanilmalidir.

A mapped SEI MUST be annotated with a javax.jws.WebService annotation.

<operation> etiketi icerisinde <input> ve <output> etiketleri yer almaktadir , message attribute’u ilgili message etiketlerine referansta bulunmaktadir.

<operation> metotlari javax.jws.WebMethod annotation’i ile tanimlanir.

A mapped Java method MUST be annotated with a javax.jws.WebMethod annotation.

<binding>
<binding> element’inde name ve type attribute’leri yer almaktadir.
<soap:binding> , <soap:operation> , <soap:body> gibi element’ler yer almaktadir.

<binding name="MessageWriterImplPortBinding" type="tns:MessageWriter">
	<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
		style="rpc" />
	<operation name="getWelcomeMessage">
		<soap:operation soapAction="" />
		<input>
			<soap:body use="literal" namespace="http://service.ws.injavawetrust/" />
		</input>
		<output>
			<soap:body use="literal" namespace="http://service.ws.injavawetrust/" />
		</output>
	</operation>
</binding>

<soap:binding> element’i 2 tane attribute almaktadir ; style ve transport
style attribute’u rpc ya da document olabilir.

transport ‘da HTTP , SMTP , TCP gibi protokoller olabilir. Burada HTTP kullaniyoruz.

2 farkli communication style/iletisim yaklasimi vardir ; RPC , Document
Bununla birlikte 2 farkli encoding modeli kullanilmaktadir ; literal , encoded

http://stackoverflow.com/questions/9062475/what-is-the-difference-between-document-style-and-rpc-style-communication

https://www.ibm.com/developerworks/library/ws-whichwsdl/

<service>
service name ve <soap:address> element’i yer almaktadir.
<soap:address> element’inde location bilgisi Web Service address bilgisi yer almaktadir.

A wsdl:service is a collection of related wsdl:port elements. 
A wsdl:port element describes a port type bound to a particular protocol 
(a wsdl:binding) that is available at particular endpoint address.
<service name="MessageWriterImplService">
	<port name="MessageWriterImplPort" binding="tns:MessageWriterImplPortBinding">
		<soap:address location="http://localhost:8888/injavawetrust/hello.jaxws" />
	</port>
</service>

UDDI , Universal Description, Discovery and Integration anlamina gelmektedir.

Bir UDDI implementation olan jUDDI , bu kavrami soyle ifade eder;
Think of UDDI as the yellow pages of the phone book for web services.

http://juddi.apache.org/


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. Required fields are marked *