130
Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant Glarimy Technology Services, Bengaluru, India [email protected] | www.glarimy.com 091-9731 4231 66 © 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com G l a r i m y

Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

  • Upload
    lamtu

  • View
    231

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

Java Web Services using JAX-WSKrishna Mohan Koyya, M.Tech

Proprietor and Principle Consultant Glarimy Technology Services, Bengaluru, India

[email protected] | www.glarimy.com091-9731 4231 66

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

G l a r i m y

Page 2: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 3: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Do’s– Session is open only for registered participants– Mark your attendance without fail– Stop me at any point if you have questions– Please fill-in feedback at the end of the session

• Don’ts– Please switch-off/mute mobile phones– Do not carry your day-to-day work to the training room– Avoid internet browsing, chatting and mailing during the

session– No cross-discussions, please!

• Resources– Slides and code are available for your reference at

www.glarimy.com

The ProtocolG l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Page 4: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• You are expected to have basic understanding of XML and XML Schema development

• You are expected to have basic understanding of HTTP

• You are expected to have good experience in working with Java Technology

• You are expected to have exposure to annotations and servlets

• You are expected to have exposure to Eclipse IDE

PrerequisitesG l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Page 5: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Windows XP O/S or upwards• JDK 1.6 or upwards

– http://download.cnet.com/Java-SE-6-0-JDK-6/3001-2212_4-10857945.html?spi=f7875945cc3f3d3fd5496cf43d0e7bd2

• A Web Browser, preferably Chrome– http://download.cnet.com/Google-Chrome/3001-2356_4-10881381.html?spi=2d2f99c7cd3e886332d2ac7da08a68da

• Eclipse Indigo– http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/indigo/SR2/eclipse-jee-indigo-SR2-win32.zip&url=http://mirror.yongbok.net/eclipse//technology/epp/downloads/release/indigo/SR2/eclipse-jee-indigo-SR2-win32.zip&mirror_id=1078

• Tomcat 6 or upwards– http://apache.techartifact.com/mirror/tomcat/tomcat-6/v6.0.36/bin/apache-tomcat-6.0.36-windows-x86.zip

• SoapUI 4 Pro– http://www.soapui.org/Downloads/latest-release.html

EnvironmentG l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Page 6: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Call me Krishna– Originally from Tadepalligudem in

Andhra Pradesh– Have been living in Bengaluru since

1998• Held various positions in the IT

Industry– Worked on development of huge

systems • Extensive work in the areas of

– Object Oriented Technologies– Distributed Systems– Network Management Systems– Enterprise Java Technologies– Web and RIA Technologies

Krishna Mohan KoyyaG l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Page 7: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Graduation– B.E. in Electronics & Communication Engineering

• SRKR Engineering College, Bhimavaram, affiliated to Andhra University, Visakhapatnam

• 1989-1993

• Post Graduation– M.Tech in Computer Science & Technology

• College of Engineering, Andhra University, Visakhapatnam• 1995-1997

• Certifications– PMP (Project Management Professional)

• PMI® USA• 2005

AcademicsG l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Page 8: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• A total of 14 years of experience with the IT Industry• Since July 2008

– Technology Consultant & Corporate Trainer– Founded Glarimy Technology Services and runs G l a r i m y portal

• June 2007- May 2008– Associate Professor & HOD of Department of IT– Sasi Institute of Technology and Engineering, Tadepalligudem, India

• Jan 2006 – Dec 2006– Chief Executive Officer– Sudhari IT Solutions India Private Limited, Bangalore, India

• Dec 2000 – Jan 2006– Software Engineer– Cisco Systems India Private Limited, Bangalore, India

• Nov 1998 – Dec 2000– Senior Software Engineer– Wipro Technologies, Bangalore, India

• Others– Dhanya Software for Hewlett-Packard ISO, Bangalore, India in 1998– Ace Software Exports Limited, Rajkot, India in 1997– Neo Software, Visakhapatnam in 1994-1995

CareerG l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Page 9: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Programming Languages– Java, C, C++

• J2EE Technologies– Servlets, JSP, JSTL, JDBC, JMS, EJB, JPA, JNDI, JBoss, Tomcat

• MVC Frameworks– Struts, JSF, Seam, Spring MVC

• ORM Technologies– Hibernate, JAP, iBatis

• AJAX technologies– JavaScript, Ajax, JSON, DWR, Dojo, GWT, JQuery , ExtJS

• XML Technologies– XML, DTD, XSD, XSLT, XPath, XPointer, XQuery

• Web Services– SOAP/XML Webservices, JAX-WS, REST, SoapUI

• Databases– SQL, MySQL, HSQL, T-SQL, Oracle

• Software Engineering– SDLC, OOAD, Agile Methodologies, TDD, Extreme Programming, Design Patterns, UML

• Test, Build and Release Engineering– Junit, HTTPUnit, EasyMock, Ant, Maven, OSGi

• Spring Framework– Code, AOP, DB, ORM, Transactions, Messaging, Batch, MVC, WebFlow, Security

TechnologiesG l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Page 10: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 11: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• What are Web Services?– Web Services are to build interoperable distributed

services across different platforms.• The client and server can be developed on different

platforms and in different languages, yet they can exchange requests & responses.

• For example, a Java client can consume a .NET based service and vice-versa

– Legacy or new systems can be integrated rather easily by exposing them as web services.

• A better ROI from every system can be achieved.

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Web Services

Page 12: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Typical Distributed Architecture

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Web Services

Page 13: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Distributed Architecture Examples– Java Platform

• RMI (Remote Method Invocation), EJB (Enterprise Java Beans), CORBA, now not so famous– @Remote interface as the interface

– @SessionBean as implementation

– JNDI Directory as the registry

– JBoss as the service container & publisher

– InitialContext.lookup() for fetching proxy on the client side

– COM/DCOM on Microsoft platform

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Web Services

Page 14: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Major Shortcomings of Distributed Systems– Both client and server must be on the same platform

• Clients on other platforms can not utilize the services

• Changes in server-side environment affect all the clients

– Client must have server side API for interaction• Client can not be developed unless the API is distrbuted

• Often the API may be priced, poorly documented and etc.,

– The protocol between client and server is also platform specific and often proprietary

• Client that wants to connect to several remote objects have to implement all the specified protocols

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Web Services

Page 15: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Web Service Architecture Solution

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Web Services

Page 16: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Web Service Standards– Web Services are build on three foundation standards

• Web Service Definition Language (WSDL): An XML based IDL to describe the service definitions in a language agnostic way

• Service Oriented Architecture Protocol (SOAP): An XML based PDU for communication between the clients and services

• Universal Description Discovery and Integration (UDDI): An XML based registry for service publication and discovery

– Bodies like OASIS proposed and publicized other standards as well

• Standards like WS-Address, WS-Security, WS-Authentication and etc., are built on top of foundation standards

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Web Services

Page 17: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Web Services Vs SOA– Web Services is one of the technologies to implement

Service Oriented Architectures (SOA)• However, Web Services predates SOA.

• Primary intention of web services was to make RPC calls, later it became a technology of choice for SOA implementation

– Clients can be developed as an orchestration of services from various endpoints that confirms to SOA.

• Business processes can be delivered in accordance with Software As A Service (SAAS) paradigm.

• Services needs not be installed at client site, they are just consumed.

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Web Services

Page 18: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 19: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• What is WSDL?– Its an IDL for describing a web service interface.

• The service is meant for the clients of any platform.– Its XML based.

• And hence platform agnostic

• Who develops them?– WSDL is hand-written in Contract-First Approach

• Server developer first specifies the WSDL before implementing and publishing the service.

– WSDL is generated in Contract-Last Approach• Server developer generates the WSDL while deploying an

existing web service.

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

WSDL

Page 20: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• What it consists of?– An abstract section

• Types: Describes the XML types & elements that are used in the messages to/from the web services.

• Messages: Describes the input, output and fault messages that comes into and goes out of web service operations.

• PortType: Names the web service and describes the operations offered by the web service

– A concrete section• Bindings: Describes the transport protocol like HTTP to carry

the SOAP envelope for communicating with web service.• Service: Describes the endpoint where the service is really

available for consumption

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

WSDL

Page 21: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Simple Case Study: Calculator– Lets have a calculator exposed as a web service which offers a

service to add two numbers and return the sum.

– At this point, no assumptions we make regarding the platform on which the service is going to be developed and deployed and the same case with the client environment as well.

– However, we are going to choose HTTP as the transport layer protocol between the client and server.

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Web Services

Page 22: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Types describes the schema for elements<xs:schema

xmlns:tns="http://jws.glarimy.com/"xmlns:xs="http://www.w3.org/2001/XMLSchema"version="1.0" targetNamespace="http://jws.glarimy.com/"><xs:element name="add" type="tns:add" /><xs:element name="addResponse" type="tns:addResponse" /><xs:complexType name="add"><xs:sequence>

<xs:element name="arg0" type="xs:int" /><xs:element name="arg1" type="xs:int" />

</xs:sequence></xs:complexType><xs:complexType name="addResponse"><xs:sequence>

<xs:element name="return" type="xs:int" /></xs:sequence>

</xs:complexType></xs:schema>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

WSDL

Page 23: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Messages for each of the operations<message name="add">

<part name="parameters" element="tns:add" /></message><message name="addResponse">

<part name="parameters" element="tns:addResponse" /></message>

• PortType section lists the operations<portType name="Calc">

<operation name="add"><input

wsam:Action="http://jws.glarimy.com/Calc/addRequest"message="tns:add" />

<outputwsam:Action="http://jws.glarimy.com/Calc/addResponse"message="tns:addResponse" />

</operation></portType>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

WSDL

Page 24: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Binding Section– It binds the port type with the underlying transport

layer protocol– It also specifies SOAP style

• Supported styles are document (suggested for SOA) and RPC. A document style SOAP envelop must have reference to type definitions.

<binding name="MyCalcPortBinding" type="tns:Calc"><soap:bindingtransport=http://schemas.xmlsoap.org/soap/http style="document" /><operation name="add">

<soap:operation soapAction="" /><input> <soap:body use="literal" /> </input><output> <soap:body use="literal" /> </output>

</operation></binding>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

WSDL

Page 25: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Service Section– It specifies various locations at which the service is

ready for consumption

<service name="MyCalcService"><port name="MyCalcPort" binding="tns:MyCalcPortBinding">

<soap:address location="http://localhost:8080/calc" /></port>

</service>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

WSDL

Page 26: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

<definitions xmlns:tns=http://jws.glarimy.com/ xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns=http://schemas.xmlsoap.org/wsdl/ targetNamespace=http://jws.glarimy.com/ name="MyCalcService"><types>

<xsd:schema>…</xsd:schema>

</types><message name="add“><part name="parameters" element="tns:add" /></message><message name="addResponse“><part name="parameters" element="tns:addResponse" /></message><portType name="Calc">

<operation name="add“><input wsam:Action=http://jws.glarimy.com/Calc/addRequest message="tns:add" /><output wsam:Action=http://jws.glarimy.com/Calc/addResponse

message="tns:addResponse" /></operation>

</portType><binding name="MyCalcPortBinding" type="tns:Calc">

<soap:binding transport=http://schemas.xmlsoap.org/soap/http style="document" /><operation name="add“><soap:operation soapAction="" />

<input><soap:body use="literal" /></input><output><soap:body use="literal" /></output>

</operation></binding><service name="MyCalcService">

<port name="MyCalcPort" binding="tns:MyCalcPortBinding"><soap:address location="http://localhost:8080/calc" />

</port></service>

</definitions>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

WSDL

Page 27: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• What is SOAP?– It stands for Service Oriented Architecture Protocol in

the SOA/Web Services combination.• It originally stood for Simple Object Access Protocol when

web services were merely meant for lightweight RPC calls.

• What is its job?– It carries the payload for request/response between

the client and the server.• Obviously its an XML document (JSON is also supported)

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SOAP/XML

Page 28: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Who writes and consumes it?– Web Service clients/servers dynamically prepares and

consumes the SOAP envelopes

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SOAP/XML

Page 29: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Who carries it and what it consists of?– HTTP or protocol (as specified in WSDL) carries it– It consists of optional Header and mandatory Body

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SOAP/XML

Page 30: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• A SOAP message embedded in HTTP RequestPOST /calc HTTP/1.1Accept: text/xml, multipart/relatedContent-Type: text/xml; charset=utf-8SOAPAction: "http://jws.glarimy.com/Calc/addRequest"User-Agent: JAX-WS RI 2.2.4-b01Host: localhost:9090Connection: keep-aliveContent-Length: 199<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">

<S:Body><ns2:add xmlns:ns2="http://jws.glarimy.com/">

<arg0>1</arg0><arg1>2</arg1>

</ns2:add></S:Body>

</S:Envelope>© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

G l a r i m y

SOAP/XML

Page 31: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• SOAP Request and SOAP Response have no distinction in their structures.HTTP/1.1 200 OKTransfer-encoding: chunkedContent-type: text/xml; charset=utf-8Date: Mon, 22 Oct 2012 06:59:47 GMT

<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">

<S:Body><ns2:addResponsexmlns:ns2="http://jws.glarimy.com/">

<return>3</return></ns2:addResponse>

</S:Body></S:Envelope>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SOAP/XML

Page 32: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 33: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Extensible Markup Language– What Java for logic is what XML for data

• Platform independent way for defining data structures• Text based, no binaries and hence human readable• A well-formed XML document confirms to basic XML rules

– Offers no pre-defined tags, only rules to define tags• Defining new tags is creating new language• A valid XML document confirms to tag definitions

– Hence, every valid document is a also a well-formed document

• Popular Definition Languages– Document Type Definition (DTD)

• Little outdated, but still in use– XML Schema (XSD)

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

XML and XML Schema

Page 34: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• XML Schema– A language to define XML tags– Offers rich set of types

• int, decimal, string, date and etc., – Offers ways to define new types

• Simple Types: Consists of only text value• Complex Types: May consists of children, text values,

attributes• Restrictions and extensions of other types

– Offers ways to defined new elements• Attributes and Elements

– Supports namespaces• Elements from multiple XSDs can be used in a document

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

XML and XML Schema

Page 35: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• XML Schema Definition (glarimy.xsd)<?xml version="1.0" encoding="UTF-8"?><schema targetNamespace="http://www.glarimy.com/gl”

xmlns="http://www.w3.org/2001/XMLSchema" mlns:gl="http://www.glarimy.com/gl"elementFormDefault="qualified">

<simpleType name="money"><restriction base="decimal">

<fractionDigits value="2" /><minInclusive value="0" />

</restriction></simpleType><simpleType name="type"><restriction base="string">

<enumeration value="pc" /><enumeration value="laptop" />

</restriction></simpleType><!-- continue on the next slide -->

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

XML and XML Schema

Page 36: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• XML Schema Definition Continued<!-- from previous slide --><complexType name="configuration"><sequence>

<element name="processor" type="string" /><element name="memory" type="int" /><element name="harddisk" type="int" />

</sequence></complexType>

<complexType name="item"><sequence>

<element name="sno" type="string" /><element name="configuration" type="gl:configuration" /><element name="value" type="gl:money" />

</sequence><attribute name="type" type="gl:type" use="required" />

</complexType> <!-- continue on the next slide -->

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

XML and XML Schema

Page 37: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• XML Schema Definition Continued<!-- from previous slide --><element name="item" type="gl:item" /><element name="inventory"><complexType> <sequence> <element ref="gl:item" minOccurs="0“ maxOccurs="unbounded" /> </sequence></complexType>

</element></schema>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

XML and XML Schema

Page 38: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• XML Document (glarimy.xml)<?xml version="1.0" encoding="UTF-8"?><inventory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://www.glarimy.com/gl" xsi:schemaLocation="http://www.glarimy.com/gl glarimy.xsd"><item type="laptop"><sno>BW952</sno><configuration>

<processor>celeron</processor><memory>512</memory><harddisk>30</harddisk>

</configuration><value>35000</value>

</item></inventory>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

XML and XML Schema

Page 39: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 40: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Objective– Mapping Java types to XML and vice versa

• Not just primitive types but also classes/complex types.– Serialization and de-serialization

• Programmatic conversion between Java types and XML types

• Options– Manually writing everything– Using a binding technology

• Castor XML: Almost outdated• JiXB: Still popular• ADB: Still popular with Axis users• JAXB: Used in JAX-WS stack

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java – XML Bindings

Page 41: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Java Architecture for XML Bindings (JAXB)– What ORM for Java/DB is JAXB for Java/XML

• Binds Java types with XML types• Marshalls and un-marshalls XML from/into Java

• Binding– Creates Java Beans from XSD types & elements

• Support for DTD is still available, if needed– Creates XML elements from Java Beans– Provides rich set of Java annotations

• Marshalling and Unmarshalling– Reads XML data into Java program– Serializes Java Beans into XML documents

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java – XML Bindings

Page 42: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Bindings– Generating Java Types from XSD

• Use the tool JAVA_HOME/bin/xjc– xjc –d <destination> <schema file>

– Generating XML Types from Java Types• Use JAXB Annotations

• Serialization– Get the JAXBContext

• On the Java Bean that refers other beans (root element) • Get a marshaller from the JAXBContext

– Marshal Java Objects into XML Document

• Get an unmarshaller from the JAXBContext– Unmarshal XML Document into Java Objects

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java – XML Bindings

Page 43: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The XSD file (glarimy.xsd)<?xml version="1.0" encoding="UTF-8"?><schema xmlns="http://www.w3.org/2001/XMLSchema"

targetNamespace="http://www.glarimy.com/jws”xmlns:gl="http://www.glarimy.com/jws" elementFormDefault="qualified">

<simpleType name="money"> <restriction base="decimal"> <fractionDigits value="2" />

<minInclusive value="0" /> </restriction> </simpleType> <simpleType name="type"> <restriction base="string"> <enumeration value="pc" /> <enumeration value="laptop" /> </restriction> </simpleType>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 44: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The XSD file continued<complexType name="configuration"> <sequence> <element name="processor" type="string" /> <element name="memory" type="int" /> <element name="harddisk" type="int" /> </sequence></complexType><complexType name="item"> <sequence> <element name="sno" type="string" /> <element name="configuration" type="gl:configuration" /> <element name="value" type="gl:money" /> </sequence> <attribute name="type" type="gl:type" use="required" /></complexType><element name="item" type="gl:item" />

</schema>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 45: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Generate the JAXB Classes– xjc –d src glarimy.xsd

• List of generated classes– com.glarimy.jws.Item

• sno: java.lang.String• configuration: com.glarimy.jws.Configuration

– processor: java.lang.String– memory: int– harddisk: int

• value: java.math.BigDecimal• type: com.glarimy.jws.Type

– enum {Laptop, PC}– com.glarimy.jws.ObjectFactory– com.glarimy.jws.package-info

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 46: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• JAXB Annotated Java Class (Inventory.java)@XmlRootElement(namespace = "http://www.glarimy.com/jws/client")public class Inventory {

private ArrayList<Item> list = new ArrayList<Item>();@XmlElementWrapper(name = "items",

namespace = "http://www.glarimy.com/jws/client")@XmlElement(name = "item",

namespace = "http://www.glarimy.com/jws/client")public ArrayList<Item> getList() {

return list; }public void setList(ArrayList<Item> list) {

this.list = list;}

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 47: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• JAXB Client (JAXBClient.java)public class JAXBClient {

public static void main(String[] args) throws Exception {Configuration configuration = new Configuration();configuration.setProcessor("Pentium");configuration.setMemory(1024);configuration.setHarddisk(300);

Item item = new Item();item.setConfiguration(configuration);item.setSno("BW952");item.setType(Type.LAPTOP);item.setValue(new BigDecimal(35000.00));

//continued on the next slide

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 48: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• JAXB Client Continued//from previous slideInventory inventory = new Inventory();inventory.getList().add(item);inventory.getList().add(item);JAXBContext ctx = JAXBContext.newInstance(Inventory.class);Marshaller marshaller = ctx.createMarshaller();marshaller.marshal(inventory, new File("inventory.xml"));Unmarshaller unmarshaller = ctx.createUnmarshaller();inventory = (Inventory) unmarshaller

.unmarshal(new File("inventory.xml"));System.out.println("Number of items: "

+ inventory.getList().size());}

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 49: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Marshaled XML Document (inventory.xml)<?xml version="1.0" encoding="UTF-8" standalone="yes"?><inventory xmlns="http://www.glarimy.com/jws/client"

xmlns:ns2="http://www.glarimy.com/jws"><items><item type="laptop">

<ns2:sno>BW952</ns2:sno><ns2:configuration>

<ns2:processor>Pentium</ns2:processor><ns2:memory>1024</ns2:memory><ns2:harddisk>300</ns2:harddisk>

</ns2:configuration><ns2:value>35000</ns2:value>

</item><!–- other item element -->

</inventory>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 50: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 51: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Java’s support to web services– Java Technology supports Web Services through

JAX-WS standards• SAAJ (Soap with Attachments API for Java) and WS4J (Web

Service Security for Java) and etc are built on top of JAX-WS

– JAX-WS subsumes various older and related standards like JAX-RPC and JAX-RS.

– Starting from Version 1.6, JAX-WS is distributed as part of JDK.

– JAX-WS unifies both SOAP/XML and RESTful Web services into single standard.

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java Web Services

Page 52: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Java Web Service Engines– AXIS 2 is one of the prominent web service engines

which also supports JAX-WS

– JDK 1.6 onwards, a reference implementation of JAX-WS is made available on JETTY

– Tomcat and other app servers support JAX-WS service deployment

• Java Framework Support– Frameworks like Spring and JEE have built-in support

for easy development, deployment and consumption of web services

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java Web Services

Page 53: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Java Web Services Architecture

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java Web Services

Page 54: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Service in Contract Last Approach– Step 1: Create Service Endpoint Interface (SEI)

• Define a Java Interface, like in any standard Java application development

• Add JAX-WS annotations to the interface

– Step 2: Prepare a Service End Point (SEP) • Implement the interface as a business class

• Add JAX-WS annotations to the business class

– Step 3: Publish the SEP• Use the Endpoint implementation on JETTY, for now

• Verify the WSDL at the SEP

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

G l a r i m y

Java Web Services

Page 55: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Step 1: Create Service Endpoint Interface (SEI)– The annotation @WebService turns a normal

interface as an SEI

– SEI Code (Calc.java)

package com.glarimy.jws;import javax.jws.WebService;

@WebServicepublic interface Calc {

public int add(int first, int second);}

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

G l a r i m y

Java Web Services

Page 56: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Step 2: Prepare a Service End Point (SEP)– The @WebService annotation chooses the endpoint

interface in case of multiple interfaces.

– The SEP is free to access any server side resources.

– SEP Code (MyCalc.java) package com.glarimy.jws;import javax.jws.WebService;

@WebService(endpointInterface = "com.glarimy.jws.Calc")public class MyCalc implements Calc {

public int add(int first, int second) {return first + second;

}}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java Web Services

Page 57: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Step 3: Publish the SEP– Endpoint supplied with JDK publishes the web service

using embedded server Jetty

– Make sure 8080 port is free before publishing or change the port number.

– Publisher Code (JWSFirstEngine.java)package com.glarimy.jws;import javax.xml.ws.Endpoint;

public class SimpleCalcEngine {public static void main(String[] args) {

String url = "http://localhost:8080/calc";Endpoint.publish(url, new MyCalc());

}}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java Web Services

Page 58: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Done! Check the WSDL in the browser– At http://localhost:8080/calc?wsdl

– If the service is properly deployed, the WSDL would be available at this URL, with Endpoint.

– Different engines place the WSDL in different places.

– Clients can access this WSDL from anywhere

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java Web Services

Page 59: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Service in Contract First Approach– Step 1: Develop the WSDL

• Some third-party tools help in hand coding the WSDL file

– Step 2: Generate JAX-WS artifacts• Run the wsimport tool to generate the stub code for interface

and the classes

– Step 3: Implement and publish the service• Use the Endpoint implementation on JETTY, for now

• Verify the WSDL at the SEP

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java Web Services

Page 60: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Developing Web Service Client– Step 1: Choose and have the WSDL

– Step 2: Use wsimport tool to generate the client side artifacts

• This tool is supplied as part of JDK 1.6

• AXIS 2 has a similar tool call wsdl2java

– Step 3: Place the generated classes in the classpath• If Eclipse is used, simply place these classes in the client

project

– Step 4: Use these classes in the client

– Step 5: Run the client

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java Web Services

Page 61: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Steps 1, 2 and 3: – Choose and have the WSDL– Use wsimport tool to generate the client side artifacts

– Place the generated classes in the classpath• Create the client project on any machine with src as the

source code folder and bin as the bytecode folder

• Run the following command to generate the artifactswsimport -s src -d bin http://localhost:8080/calc?wsdl

• Verify the following classes are generatedAdd, AddResponse, Calc, MyCalcService and etc.,

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

G l a r i m y

Java Web Services

Page 62: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Step 4: Develop the client– Use the Service factory to get the proxy

– Client Code (JWSFirstClient.java)package com.glarimy.jws.client;import java.net.URL;import javax.xml.namespace.QName;import javax.xml.ws.Service;import com.glarimy.jws.Calc;

public class SimpleCalcClient {public static void main(String[] args) throws Exception {

URL url = new URL("http://localhost:8080/calc?wsdl");QName name = new QName(“http://jws.glarimy.com/

”,"MyCalcService");Calc c = Service.create(url,name).getPort(Calc.class);System.out.println(c.add(1, 2));

}}

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

G l a r i m y

Java Web Services

Page 63: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Have you noticed? – Client used only WSDL, no other API

• The client generated the required API by using a tool specific it its language. In this case wsimport for java

• If the client is to be developed in .NET, there would be a tool for them in their environment

• Client did not bothered about the environment in which the service is developed. No idea, even if it wants to find out.

• Web Services are to build interoperable distributed services across different platforms. Haven’t we did the same, just now?

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java Web Services

Page 64: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 65: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• @WebService (javax.jws.WebService) – Marks a Java class as implementing a Web Service,

or a Java interface as defining a Web Service interface

– Elements:• endPointInterface (String):The FQN of endpoint interface on SEP

• name (String): The name of the Web Service on SEI

• portName (String):  The port name of the Web Service

• serviceName (String): The service name of the Web Service

• targetNamespace (String): namespace for the wsdl:portType

• wsdlLocation (String): The location of a pre-defined WSDL describing the service for Contract First services

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API

Page 66: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• @WebParam (javax.jws.WebParam) – Customizes the mapping of an individual parameter to

a Web Service message part and XML element.

– Elements:• header (boolean): Marks it as a header parameter

• mode (WebParam.Mode): Marks the direction (IN, OUT, INOUT)

• name (String): Name of the parameter

• partName (String): Names the wsdl:part of the parameter

• targetNamespace (String): The XML Namespace of the parameter

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API

Page 67: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• @WebResult (javax.jws.WebResult) – Customizes the mapping of the return value to a

WSDL part and XML element.

– Elements:• header (boolean): Marks it as a header parameter

• name (String): Name of the return value

• partName (String): Names the wsdl:part of the return value

• targetNamespace (String): The XML Namespace of the return value

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API

Page 68: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• @OneWay (javax.jws.OneWay) – Indicates that the given @WebMethod has only an

input message and no output.

– A oneway method returns the thread of control to the calling application prior to executing the actual business method.

– The compiler reports an error if an operation marked @Oneway has a return value or Holder parameters, or declares any checked exceptions.

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API

Page 69: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• @SOAPBinding (javax.jws.soap.SOAPBinding) – Specifies the mapping of the Web Service onto the

SOAP message protocol on SEI

– Elements• parameterStyle (SOAPBinding.ParameterStyle): Determines whether

the parameters are elements wrapped inside a top-level element named after the operation (BARE, WRAPPED)

• style (SOAPBinding.Style): Defines the encoding style for messages send to and from the Web Service (DOCUMENT, RPC)

• use (SOAPBinding.Use): Defines the formatting style for messages sent to and from the Web Service (ENCODED, LITERAL)

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API

Page 70: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Endpoint (javax.xml.ws.Endpoint) – A web service endpoint.

– Important Methods• create: To create a web service endpoint. It must be

published in order to accept the client requests

• Publish: To publish a web service endpoint so that it can start accepting the client requests

• Stop: To stop a web service end point.

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API

Page 71: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Service (javax.xml.ws.Service) – Provides client view of the web service

– Acts as factory for Proxy for the target service end point

– Important Methods• create: To create a Service instance

• getPort: To returns the proxy for the service end point.

– Other features• Helps in working with the handler framework

• Helps in working creating dynamic clients without using the proxy

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API

Page 72: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• wsimport (JAVA_HOME/bin)– Generates JAX-WS portable artifacts like Service

Endpoint Interface, Service, Exception classes, Java Beans mapped to XML types (based on JAXB)

• Used both on server as well as client side development in Contract-First approach

• Used on client side in Contract-Last approach

• wsgen (JAVA_HOME/bin)– Reads a web service endpoint class and generates

JAX-WS portable artifacts for web service deployment and invocation.

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Tools

Page 73: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• A Customized Calculator Service– Lets rewrite the Calculator web service.

– It delivers the same functionality like the earlier one

– However, lot of customization as a web service• A changed name space

• Renamed operations

• Renamed parameters

• Renamed returns

• Excluded operations

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API and Tools

Page 74: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Annotated SEI Code (Calc.java)@WebService(name = "GlarimyCalc")@SOAPBinding(parameterStyle = ParameterStyle.WRAPPED, style =

Style.DOCUMENT, use = Use.LITERAL)public interface Calc {

@WebMethod(action = "totalAction", operationName = "total")@WebResult(header = false, name = "sum", targetNamespace = "http://calc.glarimy.com")public int add(

@WebParam(header=false, mode = Mode.IN, name = "first", targetNamespace = "http://calc.glarimy.com") int first,@WebParam(header=false, mode = Mode.IN, name = "second", targetNamespace = http://calc.glarimy.com) int second

);@WebMethod(exclude = true)public int square(int number);

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API and Tools

Page 75: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Annotated Implementation (MyCalc.java)package com.glarimy.jws;import javax.jws.WebService;@WebService(endpointInterface = "com.glarimy.jws.Calc", name =

"GlarimyCalc", portName = "GlarimyCalcPort", serviceName = "GlarimyCalcService", targetNamespace = "http://calc.glarimy.com")

public class MyCalc implements Calc {

@Overridepublic int add(int first, int second) {

return first + second;}

@Overridepublic int square(int number) {

return number * number;}

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API and Tools

Page 76: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Publishing using Endpoint, as usual

• Verify the WSDL after publication• Publisher Code (JWSSecondEngine.java)

package com.glarimy.jws;import javax.xml.ws.Endpoint;

public class AnnotatedCalcEngine {public static void main(String[] args) {

String url = "http://localhost:8080/calc";Endpoint.publish(url, new MyCalc());

}}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API and Tools

Page 77: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Interesting parts of the WSDL<definitions

xmlns:tns="http://calc.glarimy.com" targetNamespace="http://calc.glarimy.com" name="GlarimyCalcService">

<types>

<xsd:schema>

<xs:element name="first" type="xs:int"/>

<xs:element name="second" type="xs:int"/>

<xs:element name="sum" type="xs:int"/>

<xs:complexType name="total">

<xs:sequence><xs:element ref="ns1:first"/><xs:element ref="ns1:second"/></xs:sequence>

</xs:complexType>

<xs:complexType name="totalResponse">

<xs:sequence><xs:element ref="ns1:sum"/></xs:sequence>

</xs:complexType>

<xs:element name="total" type="tns:total"/>

<xs:element name="totalResponse" type="tns:totalResponse"/>

</xsd:schema>

</types>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API and Tools

Page 78: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Interesting parts of the WSDL<message name="total“>

<part name="parameters" element="tns:total"/>

</message>

<message name="totalResponse“>

<part name="parameters" element="tns:totalResponse"/>

</message>

<portType name="GlarimyCalc">

<operation name="total">

<input xmlns:ns1="http://www.w3.org/2007/05/addressing/metadata" ns1:Action="totalAction" message="tns:total"/>

<output xmlns:ns2="http://www.w3.org/2007/05/addressing/metadata" ns2:Action="http://jws.glarimy.com/GlarimyCalc/totalResponse" message="tns:totalResponse"/>

</operation>

</portType>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API and Tools

Page 79: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Interesting parts of the WSDL<binding xmlns:ns1="http://jws.glarimy.com/" name="GlarimyCalcPortBinding" type="ns1:GlarimyCalc">

<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>

<operation name="total">

<soap:operation soapAction="totalAction"/>

<input><soap:body use="literal"/></input>

<output><soap:body use="literal"/></output>

</operation>

</binding>

<service name="GlarimyCalcService">

<port name="GlarimyCalcPort" binding="tns:GlarimyCalcPortBinding">

<soap:address location="http://localhost:8080/calc"/>

</port>

</service>

</definitions>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API and Tools

Page 80: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Client with new namespace & stubspackage com.glarimy.jws.client;

import java.net.URL;

import javax.xml.namespace.QName;import javax.xml.ws.Service;

import com.glarimy.calc.GlarimyCalc;

public class AnnotatedCalcClient {public static void main(String[] args) throws Exception {URL url = new URL("http://localhost:8080/calc?wsdl");QName name = new QName("http://calc.glarimy.com", "GlarimyCalcService");GlarimyCalc calc = Service.create(url, name).getPort(GlarimyCalc.class);System.out.println(calc.total(1, 2));

}}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS API and Tools

Page 81: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Little more real-time case study– Lets develop a web service that uses not just

primitive types but also Java Beans. Let it also throw some exceptions and we would handle them.

– This web service is a Library service which can add a Book to the library, lists the books in the library and search for a book in the library. A Book is our bean and LibraryException is going to be thrown at appropriate places.

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java Web Services

Page 82: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The Library SEI (Library.java)package com.glarimy.jws;

import java.util.List;

import javax.jws.Oneway;import javax.jws.WebService;

@WebServicepublic interface Library {

public void add(Book book) throws InvalidBookException, LibraryException;

public Book search(int isbn) throws BookNotFoundException, LibraryException;

public List<Book> list() throws LibraryException;

@Onewaypublic void remove(int isbn);

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 83: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The Library SEP (GlarimyLibrary.java)package com.glarimy.jws;

//imports

@WebService(endpointInterface = "com.glarimy.jws.Library")public class GlarimyLibrary implements Library {

private Map<Integer, Book> rack;

public GlarimyLibrary() {rack = new HashMap<Integer, Book>();

}

@Overridepublic void add(Book book) throws InvalidBookException, LibraryException {if (book.getIsbn() < 1)

throw new InvalidBookException("Invalid ISBN");rack.put(book.getIsbn(), book);

}

//see next slide

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 84: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The Library SEP Continued//continued from preview slide

@Overridepublic Book search(int isbn) throws BookNotFoundException, LibraryException {Book book = rack.get(isbn);if (book == null)

throw new BookNotFoundException("Book with ISBN: " + isbn+ " is not found");

return book;}

@Overridepublic List<Book> list() throws LibraryException {return new ArrayList<Book>(rack.values());

}

@Overridepublic void remove(int isbn) {rack.remove(isbn);

}}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 85: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The Java Beans (Book.java and Author.java)package com.glarimy.jws;

public class Book {private int isbn;private String title;private double price;private Author author;private boolean reference;//getters and setters

}

public class Author {private String name;private long phone;//getters and setters

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 86: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The Exception Classespackage com.glarimy.jws;public class LibraryException extends Exception {

//overloaded constructors from the super class}

public class BookNotFoundException extends LibraryException {//overloaded constructors from the super class

}

public class InvalidBookException extends LibraryException {//overloaded constructors from the super class

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 87: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The Deployer (JWSThirdEngine.java)

package com.glarimy.jws;

import javax.xml.ws.Endpoint;

public class LibraryEngine {public static void main(String[] args) {Endpoint.publish(

"http://localhost:8080/lib", new GlarimyLibrary()

);}

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 88: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The WSDL<definitions xmlns:tns="http://jws.glarimy.com/"

targetNamespace="http://jws.glarimy.com/" name="GlarimyLibraryService"><types>

<xs:schema xmlns:tns="http://jws.glarimy.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://jws.glarimy.com/"><xs:element name="BookNotFoundException” type="tns:BookNotFoundException"/>

<xs:element name="InvalidBookException" type="tns:InvalidBookException"/><xs:element name="LibraryException" type="tns:LibraryException"/><xs:element name="add" type="tns:add"/><xs:element name="addResponse" type="tns:addResponse"/><xs:element name="list" type="tns:list"/><xs:element name="listResponse" type="tns:listResponse"/><xs:element name="remove" type="tns:remove"/><xs:element name="search" type="tns:search"/><xs:element name="searchResponse" type="tns:searchResponse"/><!– continue to next slide -->

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 89: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The WSDL<xs:complexType name="book">

<xs:sequence><xs:element name="author" type="tns:author" minOccurs="0"/><xs:element name="isbn" type="xs:int"/><xs:element name="price" type="xs:double"/><xs:element name="reference" type="xs:boolean"/><xs:element name="title" type="xs:string" minOccurs="0"/>

</xs:sequence></xs:complexType><xs:complexType name="author">

<xs:sequence><xs:element name="name" type="xs:string" minOccurs="0"/><xs:element name="phone" type="xs:long"/>

</xs:sequence></xs:complexType><!–- other complex types --><!–- continue to next slide -->

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 90: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The WSDL<xs:complexType name="add"><xs:sequence>

<xs:element name="arg0" type="tns:book" minOccurs="0"/></xs:sequence>

</xs:complexType><xs:complexType name="addResponse"><xs:sequence/>

</xs:complexType><xs:complexType name="InvalidBookException"><xs:sequence>

<xs:element name="message" type="xs:string" minOccurs="0"/></xs:sequence>

</xs:complexType><!–- other complex types -->

</xs:schema></types><!–- continue to next slide -->

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 91: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The WSDL<message name="add“><part name="parameters" element="tns:add"/></message><message name="addResponse“>

<part name="parameters" element="tns:addResponse"/></message><message name="InvalidBookException">

<part name="fault" element="tns:InvalidBookException"/></message><message name="LibraryException">

<part name="fault" element="tns:LibraryException"/></message><message name="remove“><part name="parameters" element="tns:remove"/></message><message name="list“><part name="parameters" element="tns:list"/></message><message name="listResponse">

<part name="parameters" element="tns:listResponse"/></message><message name="search“><part name="parameters" element="tns:search"/></message><message name="searchResponse">

<part name="parameters" element="tns:searchResponse"/></message><message name="BookNotFoundException">

<part name="fault" element="tns:BookNotFoundException"/></message>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 92: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The WSDL<portType name="Library">

<operation name="add"><input message="tns:add"/><output message="tns:addResponse"/><fault message="tns:InvalidBookException" name="InvalidBookException"/><fault message="tns:LibraryException" name="LibraryException" />

</operation><operation name="remove“><input message="tns:remove"/></operation><operation name="list"><input message="tns:list"/><output message="tns:listResponse"/><fault message="tns:LibraryException" name="LibraryException"/>

</operation><operation name="search"><input message="tns:search"/><output message="tns:searchResponse"/><fault message="tns:BookNotFoundException" name="BookNotFoundException“/><fault message="tns:LibraryException" name="LibraryException“/>

</operation></portType>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 93: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The WSDL<binding name="GlarimyLibraryPortBinding" type="tns:Library">

<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/><operation name="add">

<soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/></output><fault name="InvalidBookException">

<soap:fault name="InvalidBookException" use="literal"/></fault><fault name="LibraryException">

<soap:fault name="LibraryException" use="literal"/></fault>

</operation><!– other operations --></binding><service name="GlarimyLibraryService">

<port name="GlarimyLibraryPort" binding="tns:GlarimyLibraryPortBinding"><soap:address location="http://localhost:8080/lib"/>

</port></service></definitions>

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 94: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• The Client (JWSThirdClient.java)package com.glarimy.jws.client;//importspublic class LibraryClient {

public static void main(String[] args) throws Exception {URL url = new URL("http://localhost:8080/lib?wsdl");QName name = new QName("http://jws.glarimy.com/",

"GlarimyLibraryService");Library library = Service.create(url, name).getPort(Library.class);Book book = new Book();book.setIsbn(12345);//other setterslibrary.add(book);System.out.println("Added ISBN: 12345");System.out.println("Found: " + library.search(12345).getTitle());//other usage

}}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Java-XML Binding with JAXB

Page 95: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 96: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• SOAP with Attachments API for Java– Latest version: 1.3– Package: javax.xml.soap– Provides API for

• creating a point-to-point connection to a specified endpoint• creating a SOAP message• creating an XML fragment• adding content to the header/body of a SOAP message• creating attachment parts and add content to them• accessing/adding/modifying parts of a SOAP message• creating/adding/modifying SOAP fault information• extracting content from a SOAP message• sending a SOAP request-response message

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SAAJ API

Page 97: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Important Interfaces– SOAPEnvelope, SOAPConstants– SOAPHeader, SOAPHeaderElement– SOAPBody, SOAPBodyElement– SOAPFault, SOAPFaultElement– Node, Text, Name, Detail, DetailEntry

• Important Classes– SOAPMessage, SOAPConnection, SOAPException– SOAPFactory, SOAPConnectionFactory,

MessageFactory– SOAPPart, AttachmentPart, MimeHeader,

MimeHeaders

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SAAJ API

Page 98: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• SOAPConnectionFactory– A factory to create SOAPConnections

• newInstance(): SOAPConnectionFactory– Creates a new instance of SOAPConnectionFactory– Throws UnsupportedOperationException, if not implemented on a

platform• createConnection(): SOAPConnection

– Creates an instance of SOAPConnection

• SOAPConnection– A point-to-point connection between client & SEI

• call(SOAPMessage message, Object to)– Sends a message to endpoint and blocks until a response is received

• close()– Closes the connection

• get(Object to)– Blocks till it gets the message from the endpoint

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SAAJ API

Page 99: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• SOAPMessage– Implements Document, Node– Represents the XML/SOAP document on wire– Structure

• SOAPPart: Mandatory– SOAPEnvelope

» SOAPHeader with zero to many SOAPHeaderElement instances» SOAPBody with zero to many SOAPBodyElement instances

• AttachmentPart: Zero to any number– Important Methods

• getSOAPBody, getSOAPHeader, getSOAPPart• create/addAttachmentPart• getAttachment, get/count/removeAttachments• saveChanges, setProperty, saveRequired

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SAAJ API

Page 100: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• SOAPPart– Container for the SOAP portion of SOAPMessage– Represents MIME part– Structure

• Content-Id, Content-Location, Content-Type (text/xml)• Envelope

– Important Methods• get/setContent, get/setContentId, get/setContentLocation• get/add/removeMimeHeader• get/removeAllMimeHeaders• getMatchingMimeHeaders, getNonMatchingMimeHeaders• getEnvelope

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SAAJ API

Page 101: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• SOAPElement– Extends Element and Node– Represents an element in the SOAP message– Methods

• addAttribute, addChildElement, addNamespaceDeclaration, addTextNode

• createQName, getAllAttributes, getAllAttributeQNames, getAttributevalue,

• getChildElements, getElementName, getElementQName, getEncodingStyle,

• getNamespacePrefixes, getNamespaceURI, • removeAttribute, removeContents

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SAAJ API

Page 102: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• SOAPEnvelope– Extends SOAPElement– Container for SOAPBody and SOAPHeader

• Empty SOAPBody and SOAPHeader, by default• Elements are to be added to them

– Methods• add/getBody, add/getHeader• createName

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SAAJ API

Page 103: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• SOAPHeader– Represents SOAP Header

• Extends SOAPElement, Element, Node– Methods

• addHeaderElement, addNotUnderstoodHeaderElement• examine/extractAllHeaderElements• examine/extractHeaderElements

• SOAPHeaderElement– Represents an element in the SOAP Header

• Extends SOAPElement, Element, Node– Methods

• get/setActor, get/setMustUnderstand• get/setRelay, get/setRole

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SAAJ API

Page 104: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• SOAPBody– Represents the SOAP Body

• Extends SOAPElement– Structure

• SOAPBodyElement, any number– Methods

• addBodyElement, addDocument, add/has/getFault

• SOAPBodyElement– Represents an element in the SOAP Body

• Extends SOAPElement, Element and Node– Methods

• No defined methods, separately

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SAAJ API

Page 105: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• SOAPFault– Represents SOAP Fault

• Extends SOAPElement, SOAPBodyElement– Methods

• add/getDetail, set/getFaultCode, set/getFaultRole• set/getFaultActor, set/getFaultString

• SOAPFaultElement– Represents an element in the SOAP Fault

• Extends SOAPElement, Element and Node– Methods

• No defined methods, separately

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

SAAJ API

Page 106: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 107: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Client Code (JWSFourthDispatchClient.java)package com.glarimy.jws.client;// imports public class DispatchClient {

public static void main(String[] args) throws Exception {Service service = Service.create(

new URL("http://localhost:8080/calc?wsdl"), new Qname("http://jws.glarimy.com/", "MyCalcService"));

Dispatch<SOAPMessage> dispatch = service.createDispatch(new Qname("http://jws.glarimy.com/", "MyCalcPort"), SOAPMessage.class,Service.Mode.MESSAGE);

MessageFactory factory = ((SOAPBinding)((BindingProvider)dispatch).getBinding()).getMessageFactory();

//continue to the next slide

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Dispatch Client

Page 108: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Client Code Continued//from the previous slideSOAPMessage request = factory.createMessage();SOAPBody body = request.getSOAPBody();SOAPBodyElement payload = body.addBodyElement(

new Qname("http://jws.glarimy.com/", "add", "ns1"));payload.addChildElement("arg0").addTextNode("1");payload.addChildElement("arg1").addTextNode("2");SOAPMessage response = dispatch.invoke(request);

QName responseName = new QName("http://jws.glarimy.com/", "addResponse");

SOAPBodyElement bodyElement = (SOAPBodyElement) response.getSOAPBody().getChildElements(responseName).next();

System.out.println(((SOAPElement) bodyElement.getChildElements().next()).getValue());

}}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Dispatch Client

Page 109: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Step 1: Binding Customization

– bindings.xml<bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" wsdlLocation="http://localhost:8080/calc?wsdl"xmlns="http://java.sun.com/xml/ns/jaxws"><bindings node="wsdl:definitions">

<package name=“com.glarimy.jws.client" /><enableAsyncMapping>true</enableAsyncMapping>

</bindings></bindings>

• Step 2: Client Stub Generation– wsimport –s src –d bin –b bindings.xml

http://localhost:8080/calc?wsdl

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Asynchronous Client

Page 110: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Client Code (JWSFifthClient.java)public class AsyncClient {

public static void main(String[] args) throws Exception {URL url = new URL("http://localhost:8080/calc?wsdl");QName name = new QName("http://jws.glarimy.com/", "MyCalcService");Calc calc = Service.create(url, name).getPort(Calc.class);Future<?> future = calc.addAsync(1, 2, new AsyncHandler<AddResponse>() { public void handleResponse(Response<AddResponse> response) { try {

System.out.println(response.get().getReturn()); } catch (Exception e) { System.out.println(“Response: “ + e.getCause()); } } });System.out.println("Requested! Waiting for the response...");future.get();

}}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Asynchronous Client

Page 111: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Client Code (JWSFifthAsyncDispatchClient.java)public class AsyncDispatchClient { public static void main(String[] args) throws Exception { Service service = Service.create( new URL("http://localhost:9090/calc?wsdl"), new Qname("http://jws.glarimy.com/", "MyCalcService")); Dispatch<SOAPMessage> dispatch = service.createDispatch( new Qname("http://jws.glarimy.com/", "MyCalcPort"), SOAPMessage.class, Service.Mode.MESSAGE);

MessageFactory factory = ((SOAPBinding) ((BindingProvider) dispatch)

.getBinding()).getMessageFactory();

SOAPMessage request = factory.createMessage(); SOAPBody body = request.getSOAPBody(); SOAPBodyElement payload = body.addBodyElement( new Qname("http://jws.glarimy.com/", "add", "ns1")); payload.addChildElement("arg0").addTextNode("1"); payload.addChildElement("arg1").addTextNode("2");

//continued to the next slide

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Asynchronous Dispatch Client

Page 112: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Client Code Continued Future<?> future = dispatch.invokeAsync(request, new AsyncHandler<SOAPMessage>() { public void handleResponse(Response<SOAPMessage> response) { try { QName responseName = new Qname("http://jws.glarimy.com/", "addResponse"); SOAPBodyElement bodyElement = (SOAPBodyElement)

response.get() .getSOAPBody().getChildElements(responseName).next(); System.out.println(((SOAPElement) bodyElement.getChildElements().next()).getValue()); } catch (Exception e) { System.out.println("Received an execption: “+ e.getCause()); } } }); System.out.println("Requested! Waiting for the response..."); future.get(); }}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Asynchronous Dispatch Client

Page 113: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 114: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• What are they?– Handlers are pre and post processors– May appear both on server & client side

• What the types of Handlers?– Logical Handlers

• To intercept only the payload• Precedes the Protocol Handlers in the order

– Protocol Handlers • To intercept the entire message

• How are they added?– Either declaratively or programmatically

• Typically declared on SEP & programmed in the client

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Handlers

Page 115: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• API and Annotations– HandlerResolver (javax.ws.xml.handler) interface

• getHandlerChain() to provide the list of handlers– Handler (javax.ws.xml.handler) interface

• Lifecycle annotations: @PostCreate and @PreDestroy• handleMessage() to handle the messages• handleFault() to handle the faults• close() both after handling messages or faults• SOAPHandler (javax.ws.xml.handler.soap)

– getHeaders() to list out the headers to be processed

• LogicalHandler– MessageContext

• SOAPMessageContext• LogicalMessageContext

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Handlers

Page 116: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• API and Annotations– MessageContext

• HTTP Contsants– HTTP_RESPONSE_CODE , HTTP_RESPONSE_HEADERS 

• Direction based constants– INBOUND_MESSAGE_ATTACHMENTS – MESSAGE_OUTBOUND_PROPERTY – OUTBOUND_MESSAGE_ATTACHMENTS 

• Servlet Constants– SERVLET_CONTEXT , SERVLET_REQUEST – SERVLET_RESPONSE , PATH_INFO, QUERY_STRING

• WSDL Constants– WSDL_DESCRIPTION , WSDL_INTERFACE , WSDL_OPERATION – WSDL_PORT , WSDL_SERVICE 

• getScope() to return Handler or Application

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Handlers

Page 117: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Protocol Handler (Authenticator.java) public class Authenticator implements SOAPHandler<SOAPMessageContext> {

public boolean handleMessage(SOAPMessageContext ctx) {if (Boolean.FALSE.equals(ctx

.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) try { SOAPHeader header = ctx.getMessage().getSOAPHeader(); SOAPElement user = (SOAPElement) header.getChildElements( new QName("http://jws.glarimy.com/", "user", "gl")).next(); SOAPElement uid = (SOAPElement) user.getChildElements( new QName("http://jws.glarimy.com/", "uid", "ar")).next(); if (uid.getTextContent().equals("1987")) return true; ctx.getMessage().getSOAPBody().removeContents(); ctx.getMessage().getSOAPBody().addFault( new QName("http://jws.glarimy.com/","error"),

“Authentication failed"); } catch (SOAPException e) { } return false;

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Handlers

Page 118: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Protocol Handler Continued public boolean handleFault(SOAPMessageContext ctx) {return true;

}public void close(MessageContext ctx) { }public Set<QName> getHeaders() {Set<QName> set = new HashSet<>();set.add(new QName("http://jws.glarimy.com/", "error"));return set;

}@PostConstructpublic void init() {System.out.println(new Date() + " - SecurityHandler: initiated");

}@PreDestroypublic void finish() {System.out.println(new Date() + " - SecurityHandler: finished");

}}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Handlers

Page 119: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Handlers Configuration (handlers.xml)<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">

<handler-chain><handler>

<handler-class>com.glarimy.jws.Authenticator

</handler-class></handler>

</handler-chain></handler-chains>

• SEP with Handlers (MyCalc.java) @WebService(endpointInterface = "com.glarimy.jws.Calc")@HandlerChain(file = "handlers.xml")public class MyCalc implements Calc {

public int add(int first, int second) {return first + second;

}}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Handlers

Page 120: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Protocol Handler (SecurityHandler.java) public class SecurityHandler implements SOAPHandler<SOAPMessageContext>{

public boolean handleMessage(SOAPMessageContext ctx) { if (Boolean.TRUE.equals(ctx

.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) try {

SOAPHeader header = ctx.getMessage().getSOAPHeader(); if (header == null)

header = ctx.getMessage().getSOAPPart().getEnvelope().addHeader();

SOAPHeaderElement element = header.addHeaderElement( new Qname("http://jws.glarimy.com/", "user", "gl"));

element.addChildElement( new QName("http://jws.glarimy.com/", "uid", "ar"))

.addTextNode("1972"); } catch (SOAPException e) { }

return true; }

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Handlers

Page 121: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Protocol Handler (SecurityHandler.java) public boolean handleFault(SOAPMessageContext ctx) {

if (Boolean.FALSE.equals( ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) {

try { System.out.println(ctx.getMessage().getSOAPBody().getFault()

.getFaultString()); } catch (SOAPException e) { }}return false;

} public void close(MessageContext ctx) { } public Set<QName> getHeaders() {

return null;}

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Handlers

Page 122: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Logical Handler (Logger.java) public class Logger implements LogicalHandler<LogicalMessageContext> {

public boolean handleMessage(LogicalMessageContext ctx) {try { JAXBContext jaxbc = JAXBContext.newInstance(ObjectFactory.class); if (Boolean.TRUE.equals(

ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) { Add add = (Add) ((JAXBElement) ctx.getMessage().getPayload(

jaxbc)).getValue(); System.out.println(new Date() + " - arg0: “+ add.getArg0()); System.out.println(new Date() + " - arg1: “+ add.getArg1()); } else { AddResponse addResponse = (AddResponse) ((JAXBElement) ctx .getMessage().getPayload(jaxbc)).getValue(); System.out.println(new Date() + " - return: "

+ addResponse.getReturn()); }} catch (JAXBException e) { }return true;

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Handlers

Page 123: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Logical Handler Continued@Overridepublic boolean handleFault(LogicalMessageContext ctx) {if (Boolean.FALSE.equals(ctx

.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) {System.out.println(new Date() + " - fault");

}return false;

}

@Overridepublic void close(MessageContext ctx) {}

}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Handlers

Page 124: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

• Client with Handlers (JWSSixthClient.java)public class HandlerClient {

public static void main(String[] args) {try { URL url = new URL("http://localhost:9090/calc?wsdl"); QName name=new QName("http://jws.glarimy.com/", "MyCalcService"); Service service = Service.create(url, name); service.setHandlerResolver(new HandlerResolver() {

public List<Handler> getHandlerChain(PortInfo portInfo) {List<Handler> list = new ArrayList<Handler>();list.add(new Logger());list.add(new SecurityHandler());return list;

} }); Calc calc = service.getPort(Calc.class); System.out.println(calc.add(1, 2));} catch (Exception e) { }

}}

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

JAX-WS Handlers

Page 125: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 126: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 127: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 128: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

• Web Services Architecture• Web Service Standards• XML Schema• Java – XML Binding with JAXB• Java Web Services using JAX-WS• JAX-WS API and Tools• SAAJ API• Dispatch & Asynchronous Clients• Handler Framework• Working with Attachments• Deployment on Tomcat• Testing with SOAP-UIJa

va W

eb Se

rvic

es

usin

g JAX

-WS

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Agenda

Page 129: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

G l a r i m y

Going ForwardG l a r i m y

• Books– Glarimy QuickLook Series PDF Books

• Portal– http://www.glarimy.com– FAQ, Tutorials, Presentations and etc

• Phone– 091-9731 4231 66– For appointments

• E-mail– [email protected]– For any technical queries

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com

Page 130: Java Web Services using JAX-WS - Glarimy · Java Web Services using JAX-WS Krishna Mohan Koyya, M.Tech Proprietor and Principle Consultant ... –Web Services are to build interoperable

Thank You

G l a r i m y

© 2012, Glarimy Technology Services. All rights reserved. http://www.glarimy.com