java web services and glassfish metro 2009

28
Java Web Services Using Java in Service-Oriented Architectures By Oğuzhan ACARGİL 1 http://0guzhan.blogspot.com

Upload: oguzhan-acargil

Post on 06-May-2015

1.178 views

Category:

Technology


0 download

DESCRIPTION

Java Web Service Technologies and Glassfish Metro @2009

TRANSCRIPT

Page 1: Java Web Services and Glassfish Metro 2009

Java Web Services

Using Java in Service-Oriented Architectures

By Oğuzhan ACARGİL

1http://0guzhan.blogspot.com

Page 2: Java Web Services and Glassfish Metro 2009

Developing Web Services at a Glance

Core Web Services: JAX-WS, JAXB Enhanced Web Services: WSIT Secure Web Services: XWS-Security Legacy Web Services: JAX-RPC

2http://0guzhan.blogspot.com

Page 3: Java Web Services and Glassfish Metro 2009

Java api for XML Web Services (JAX-WS) Between web services and clients with

using XML Message oriented and RPC oriented web

services Soap Messages (XML) over HTTP Java EE api hiding complexitiy from the

application developer

3http://0guzhan.blogspot.com

Page 4: Java Web Services and Glassfish Metro 2009

4http://0guzhan.blogspot.com

Page 5: Java Web Services and Glassfish Metro 2009

JAX-WS...

Developing web services on server side with using java apiDefine methods in an interface Implement those methodsAdd required annotations to classes and web

service methods (@WebService & @WebMethod)

5http://0guzhan.blogspot.com

Page 6: Java Web Services and Glassfish Metro 2009

JAX-WS Implementation

package helloservice.endpoint;

import javax.jws.WebService;

@WebServicepublic class Hello {

private String message = new String("Hello, ");

public void Hello() {}

@WebMethodpublic String sayHello(String name) {

return message + name + ".";}

}

6http://0guzhan.blogspot.com

Page 7: Java Web Services and Glassfish Metro 2009

JAX-WS... Developing web services on client side

with using java apiCreate an object representing the serviceThen simply, invoke web service methods

7http://0guzhan.blogspot.com

Page 8: Java Web Services and Glassfish Metro 2009

import javax.xml.ws.WebServiceRef;import helloservice.endpoint.HelloService;import helloservice.endpoint.Hello;

public class HelloClient {

@WebServiceRef(wsdlLocation="http://localhost:8080/helloservice/hello?wsdl")static HelloService service;

public void doTest(String pName) {try {

System.out.println("Retrieving the port from the following service: " + service);Hello port = service.getHelloPort();System.out.println("Invoking the sayHello operation on the port.");String name;

String response = port.sayHello(name);System.out.println(response);

} catch(Exception e) e.printStackTrace();

}

public static void main(String[] args) {HelloClient client = new HelloClient();client.doTest(“Misal...!”);

}}

8http://0guzhan.blogspot.com

Page 9: Java Web Services and Glassfish Metro 2009

Advantages of JAX-WS1. Generating and parsing XML problem

solved2. Converting API calls and responses from

& to SOAP messages3. Platform independence of JAVA4. Non-restrictive to platforms5. Flexibility6. Supporting WS-I(Web Services

Interoperability) Basic Profile Version 1.1

9http://0guzhan.blogspot.com

Page 10: Java Web Services and Glassfish Metro 2009

Java API for XML Binding(JAXB) Binding between XML schema and Java

representations Incorporate XML data and process functions in

Java applications Unmarshalling(reading) XML instance

documents to Java content trees Marshalling(writing) Java content trees back into

XML instance documents Generating XML schema from Java objects

10http://0guzhan.blogspot.com

Page 11: Java Web Services and Glassfish Metro 2009

Prerequisite for JAXB Unmarshalling

Converting XML data into JAXB-derived Java objects

Marshalling

Converting a JAXB-derived Java objects tree to XMLdata

Validation

Checking XML documents content meets the constraints of schema

11http://0guzhan.blogspot.com

Page 12: Java Web Services and Glassfish Metro 2009

JAXB Architecture Overview

12http://0guzhan.blogspot.com

Page 13: Java Web Services and Glassfish Metro 2009

Schema compiler: Binds a source schema to a set of schema-derived program elements.

Schema generator:Maps a set of existing program elements to a derived schema.

Binding runtime framework: Provides unmarshalling (reading) and marshalling (writing) operations for accessing, manipulating, and validating XML content using either schema-derived or existing program elements.

13http://0guzhan.blogspot.com

Page 14: Java Web Services and Glassfish Metro 2009

JAXB Binding Process1. Generate Classes: read schema and create

JAXB mapped classes2. Compile Classes: Create objects of all recently

created JAXB mapped classes3. Unmarshal: Read document to JAXB objects4. Generate content tree5. Validation is optional since data cannot be

meets the constraints of first schema6. Process content7. Marshal: Write to document

14http://0guzhan.blogspot.com

Page 15: Java Web Services and Glassfish Metro 2009

• Steps in the JAXB binding process visualization

15http://0guzhan.blogspot.com

Page 16: Java Web Services and Glassfish Metro 2009

SOAP Attachments API for JAVA (SAAJ)

Behind the JAX-WS handlers Directly creating and populating a SOAP

messages Directly sending request-response

messages Conforms to SOAP 1.1 and 1.2

specifications and the SOAP with attachments specification.

16http://0guzhan.blogspot.com

Page 17: Java Web Services and Glassfish Metro 2009

Approach of SAAJ, Shortly

1. Connection created

2. Invoke method with sending SOAP envelope

3. Retrieve response

17http://0guzhan.blogspot.com

Page 18: Java Web Services and Glassfish Metro 2009

XWS-Security

An implementation the Web Services Security (WSS) specification developed by OASIS

WSS accomadate a wide variety of models and encryption technologies

Message level security Secure JAX-RPC & stand-alone SAAJ applications with

Signing some parts Encrypting some parts Sending username-password authentication info Or some combination of these...

18http://0guzhan.blogspot.com

Page 19: Java Web Services and Glassfish Metro 2009

WSIT: Tango Project Providing interoperability with Windows

Communication Foundation(WCF), the Web services stack bundled with the .NET 3.0 platform.

Project Tango(WSIT) implements for Security Reliability Transactions

Using the protocols and mechanisms of WS-* specifications.

19http://0guzhan.blogspot.com

Page 20: Java Web Services and Glassfish Metro 2009

20http://0guzhan.blogspot.com

Page 21: Java Web Services and Glassfish Metro 2009

METRO

High-performance, Extensible, Easy-to-use web service stack. One-stop shop for all your web service needs,

from the simplest hello world web service to reliable, secured, and transacted web service that involves .NET services.

21http://0guzhan.blogspot.com

Page 22: Java Web Services and Glassfish Metro 2009

22http://0guzhan.blogspot.com

Page 23: Java Web Services and Glassfish Metro 2009

•HTTP transport •MTOM and XOP •SOAP/TCP

23http://0guzhan.blogspot.com

Page 24: Java Web Services and Glassfish Metro 2009

•Reliability recover from failures caused by messages transmission.•Recovery is handled by the underlying system without consumer or provider application code.

24http://0guzhan.blogspot.com

Page 25: Java Web Services and Glassfish Metro 2009

Metro enables transactional support for web services.

25http://0guzhan.blogspot.com

Page 26: Java Web Services and Glassfish Metro 2009

implements the WS-Security specification

26http://0guzhan.blogspot.com

Page 27: Java Web Services and Glassfish Metro 2009

J2EE Web Services vs .Net Web Services

The performance of core SOAP-based web services is significant

WSTest was used to compare the performance of the J2EE and Windows .NET platforms when performing basic web services.

In the basic web services call, echoVoid, and the most complex one, echoSynthetic, JAX-RPC performs nearly 3 times better than .NET. In the other cases, J2EE technology performs nearly twice as well as .NET.

Conclusion: J2EE platform is completely portable, developers can expect to see this top-of-the-line performance on the Linux and Solaris platforms as well.

27http://0guzhan.blogspot.com

Page 28: Java Web Services and Glassfish Metro 2009

28http://0guzhan.blogspot.com