Web Services with Apache CXF Part 2: JAXB and WSDL to Java Robert Thornton.

Slides:



Advertisements
Similar presentations
1/7 ITApplications XML Module Session 8: Introduction to Programming with XML.
Advertisements

Web Services (Nuts and Bolts) ITEC 625 Web Development Fall 2006 Reference: Building Web Services with Java (Making sense of XML, SOAP, WSDL, and UDDI),
Web Services with Apache CXF
Multi-Model Digital Video Library Professor: Michael Lyu Member: Jacky Ma Joan Chung Multi-Model Digital Video Library LYU9904 Multi-Model Digital Video.
Web Services with Apache CXF
Open-DIS and XML DIS in Other Formats. Distributed Interactive Simulation DIS is an IEEE standard for simulations, primarily virtual worlds Binary protocol:
JAXB Java Architecture for XML Binding Andy Fanton Khalid AlBayat.
Web Services with Apache CXF
XML Parsing Using Java APIs AIP Independence project Fall 2010.
CS 571. Web services Web service: "a software system designed to support interoperable machine-to-machine interaction over a network“ – W3C In short,
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
SaxStore: a n aspect oriented persistence library for Java based on SAX events Riccardo Solmi University of Bologna May 2001.
Fonts and colors Times New Roman “quotes” Trebuchet "quotes" yellow blue pink green violet.
MC365 XML Parsers. Today We Will Cover: An overview of the Java API’s used for XML processing Creating an XML document in Java Parsing an XML document.
29-Jun-15 JAXB Java Architecture for XML Binding.
JAXB Java Architecture for XML Bindings. What is JAXB? JAXB defines the behavior of a standard set of tools and interfaces that automatically generate.
1 WS Technologies II API Roberto Bruni Dipartimento di Informatica Università di Pisa Models and Languages for Coordination and Orchestration IMT- Institutions.
XML: Java Dr Andy Evans. Java and XML Couple of things we might want to do: Parse/write data as XML. Load and save objects as XML. We’ll mainly discuss.
Web Service Implementation Maitreya, Kishore, Jeff.
Web Services with Apache CXF Part 2: JAXB and WSDL to Java Robert Thornton.
PHP and XML TP2653 Advance Web Programming. PHP and XML PHP5 – XML-based extensions, library and functionalities (current XAMPP PHP version is )
By: Shawn Li. OUTLINE XML Definition HTML vs. XML Advantage of XML Facts Utilization SAX Definition DOM Definition History Comparison between SAX and.
AIXM Viewer Implementation Presentation to AIXM Users’ Conference, Federal Aviation Administration, Washington D.C., Feb 27-March 1, By: Mark Austin,
1 Lecture 22 George Koutsogiannakis Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
Object-oriented tools for XML Schema JAXB (Java Architecture for XML Binding) –object connectivity for XML documents HyperJAXB –relational persistence.
JAXB Java API for XML Binding. The Objective JAXB is concerned with the translation process between Java objects and XML documents You have a Java object.
T Network Application Frameworks and XML Web Services and WSDL Sasu Tarkoma Based on slides by Pekka Nikander.
Java API for XML Processing (JAXP) توسط : محمّدمهدي حامد استاد راهنما : دكتر مسعود رهگذر.
CS 157B: Database Management Systems II May 8 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak
Sheet 1XML Technology in E-Commerce 2001Lecture 7 XML Technology in E-Commerce Lecture 7 XSL Formatting Objects, Java Data Binding.
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
Introduction to XML Extensible Markup Language. What is XML XML stands for eXtensible Markup Language. A markup language is used to provide information.
XML Parsers Overview  Types of parsers  Using XML parsers  SAX  DOM  DOM versus SAX  Products  Conclusion.
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
Or, Hey can’t we just do it using HTTP for the envelope?
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Scripting with the DOM Ellen Pearlman Eileen Mullin Programming the Web.
Web Services with Apache CXF Part 2: JAXB and WSDL to Java Robert Thornton.
Sheet 1XML Technology in E-Commerce 2001Lecture 3 XML Technology in E-Commerce Lecture 3 DOM and SAX.
Course Schedule Report Web Service Carolyn Cracraft Lisa de Larios-Heiman.
© Drexel University Software Engineering Research Group (SERG) 1 An Introduction to Web Services.
XML Grammar and Parser for WSOL Kruti Patel, Vladimir Tosic, Bernard Pagurek Network Management & Artificial Intelligence Lab Department of Systems & Computer.
XML Study-Session: Part III
COSC617 Project XML Tools Mark Liu Sanjay Srivastava Junping Zhang.
User Profiling using Semantic Web Group members: Ashwin Somaiah Asha Stephen Charlie Sudharshan Reddy.
6/2/2003O.Balsoy et al. Automating Metadata Services Ozgur Balsoy Community Grids Lab, Indiana University Marlon Pierce, Presenting.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
Web Services from 10,000 feet Part I Tom Perkins NTPCUG CertSIG XML Web Services.
Web services. DOM parsing and SOAP.. Summary. ● Exercise: SAX-Based checkInvoice(), ● push parsing, ● event-based parsing, ● traversal order is depth-first.
Martin Kruliš by Martin Kruliš (v1.1)1.
XML for Scientific Applications Marlon Pierce ERDC Tutorial August
7-Mar-16 Simple API XML.  SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files  DOM is a W3C standard  SAX is an.
Design Overview. Generated Packages ► fUML.Library.* - generated ► fUML.Semantics.* - generated ► fUML.Syntax.* - generated ► fUML.Test.* - generated.
Net-centric Computing Web Services. Lecture Outline  What is Web Service  Web Service Architecture  Creating and using Java Web Services  Apache Axis.
XML & JSON. Background XML and JSON are to standard, textual data formats for representing arbitrary data – XML stands for “eXtensible Markup Language”
Java High level programming language ◦ Sun Microsystems ◦ ORACLE acquired Java Development Kit – JDK Java Runtime Environment – JRE Java Virtual Machine.
Lecture Transforming Data: Using Apache Xalan to apply XSLT transformations Marc Dumontier Blueprint Initiative Samuel Lunenfeld Research Institute.
I Copyright © 2004, Oracle. All rights reserved. Introduction.
The Java API for XML Binding. The Need for Data Binding To support unmarshlling to convert XML data into Java objects. To support marshalling to convert.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
Unit 4 Representing Web Data: XML
An Introduction to Web Services
T Network Application Frameworks and XML Web Services and WSDL Sasu Tarkoma Based on slides by Pekka Nikander.
Web Services-JAX-RPC JAX-RPC enables a Web Service endpoint to be developed using either a Java Servlet or Enterprise JavaBeans (EJB) component model.
XML in Web Technologies
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
CS 240 – Advanced Programming Concepts
XML Programming in Java
Enterprise Web Services
XML and Web Services (II/2546)
Presentation transcript:

Web Services with Apache CXF Part 2: JAXB and WSDL to Java Robert Thornton

Notes This is a training, NOT a presentation Please ask questions This is being recorded Prerequisites – Maven, Spring, and Web Application Development – Web Services, Part I: SOAP – A general familiarity with XML simple and complex schema types.

Objectives At the end of this presentation, the participant will be able to: Understand the role of JAXB as a web service data binding solution. Model data entities using JAXB annotations. Understand the purpose and usage of the CXF WSDL2Java tool. Be able to use WSDL2Java to generate a client proxy in a stand- alone Java application. Be able to configure Spring to manage a generated WSDL2Java client proxy. Be able to use JAXB as the data binding solution in a Java Stack application.

Java and XML The Marriage of XML and Java: XML is a data markup language. – Used for long or short-term data storage. – Useful for data transfer between vastly different architectures. – Particularly useful for web service architectures. Java is an object-oriented programming language. – Unmarshalls (reads) data from existing XML into Java data objects. – Performs manipulations on Java objects via services. – Marshalls (writes) Java objects into a new XML representation.

Java and XML: Choices, choices…. The marriage of Java and XML has produced a large family of technologies, strategies, and libraries: DOM SAX JAXP DOM4J JAXB XML Beans JDOM XStream and many more….

Java and XML: Overview Most Java XML strategies fall into three spaces: DOM (Document Object Model) – Entire document model is held in memory as nodes in a document tree. XML-to-Object Binding – XML types and elements are bound to Java types and fields. SAX (Simple API for XML) – An event-based API for operating on each piece of the XML document individually and in sequence. Most often used to parse DOM trees or construct XML Object bindings. In practice, most solutions use some combination of these.

JAXB: A Data Binding Solution The JAXB API is the standard solution provided by the JDK for Java XML data binding: Java classes are bound to XML types, elements, and attributes through Java annotations. A SAX event-based parser is used to parse XML documents and construct Java objects as well as to write Java objects back to XML. The XJC tool (included in the JDK) can generate JAXB annotated classes from an existing XML. The Schemagen tool (also included in the JDK) can generate an XML schema from JAXB annotated classes.

JAXB and Web Services As a data modeling API, JAXB is particularly useful to web services, because: XML is the most common form of data transport. Annotated Java classes can be made to represent XML schema types. JAXB APIs can unmarshall XML into Java data objects and back again. * Note that the CXF web service framework automatically handles the marshalling and unmarshalling of XML data to and from JAXB annotated Java classes.

JAXB: Marshalling and Unmarshalling Although CXF handles the marshalling and unmarshalling of serviced XML, it can be helpful to know how it does it. A web service developer occasionally needs to experiment with how JAXB annotations affect the parsing and rendering of XML. A web service developer often needs to debug issues that arise from data being marshalled or unmarshalled incompletely.

JAXB: Unmarshalling JAXB makes unmarshalling from XML easy: // Just create a JAXB context for your Java data classes JAXBContext jaxb = JAXBContext.newInstance(myClasses); // Then unmarshall the XML document into instances of // those classes. MyClass obj = jaxb.createUnmarshaller().unmarshall(xml) The Unmarshaller can accept XML input as a character stream, a file, a DOM node, or several other input types.

JAXB: Marshalling Marshalling objects into XML is just as easy: // Create a JAXB context for your Java data classes JAXBContext jaxb = JAXBContext.newInstance(myClasses); // Marshall your Java object hierarchy into an XML document. jaxb.createMarshaller().marshall(myObject, output); The Marshaller can serialize the XML to a character stream, a file, a DOM node, or several other output types.

JAXB: The Context Instances of the JAXBContext class effectively represent an “in-memory” schema of your data: It is a registry of all the classes that can be bound to XML types. It is a factory for Marshaller and Unmarshaller instances. It can be supplied listeners and a Schema for additional validation.

JAXB: Annotations Although JAXB can bind almost any data object with little or no annotations, annotations are typically desirable, for example: They can tell JAXB whether to unmarshal a field into an attribute or an element. They can inform JAXB of ID fields, element order, and other schema constraints. They can be used to identify or customize schema types, element names, attribute names, element wrapping, etc.

JAXB: Common Annotations JAXB defines many annotations to customize Java XML data binding. Here are just These and more can be found in the following package: javax.xml.bind.annotation

JAXB: Limitations XML elements are instances of XML types, hence the following limitations apply due to the dissimilarities between types in XML and Java: JAXB cannot bind Java interfaces to XML types, elements, or attributes. JAXB can bind abstract classes to XML types but not to elements or attributes. JAXB can bind concrete classes to XML types, elements, and attributes.

JAXB: Rules and Conventions Some general rules about JAXB annotations: Concrete classes must have a public default no-arg constructor. Properties that reference interfaces must be annotated with one or annotations that identify the possible concrete types. Annotations may be placed on the fields or on the setters but not on both. By convention, annotating fields is preferable for simple POJOs. Annotate setters if the property is not backed by a field or if custom logic is required to set the property. Properties not bound to XML values must be annotated

Apache CXF: SOAP: Lab 1 Lab 1: JAXB Data Binding

Consuming 3 rd Party Web Services Third-party SOAP web services are typically consumed in one of the following ways: Using a client JAR that contains the necessary Java classes and service proxies to access the web service. Using a WSDL-to-Java tool to automatically generate a web service proxy from a published WSDL.

WSDL to Java CXF provides the wsdl2java tool to consume third- party SOAP services: wsdl2Java

Apache CXF: SOAP: Lab 2 Lab 2: Using WSDL 2 Java

Apache CXF: SOAP: Lab 3 Lab 3: Consuming a WSDL to Java Client in Spring

Resources On the web: rest rest In Print: Developing Web Services with Apache CXF and Axis 2, Kent Kai Iok Tong, TipTech Development, ISBN: