java ee7

Post on 08-May-2015

283 Views

Category:

Technology

5 Downloads

Preview:

Click to see full reader

DESCRIPTION

Java EE7 Introduction presented at Java Developer Day 2013

TRANSCRIPT

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.1

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.2

The Java EE 7 PlatformProductivity++ and HTML5이창재Senior Architectblogs.oracle.com/jaylee

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.3

Java: Broadest Industry Adoption

9,000,000자바 개발자

Java EE Compliant 한 18 개의 어플리케이션 서버

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.4

Java EE 7 Platform2013 년 6 월 12 일

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.5

Java EE 7 메인 테마

Batch Concurrency 좀 더 단순화 된 JMS API

POJO 를 위한 좀 더 다양한 annotation 지원

코드 단순화 더욱 쉬워진 통합

개발자 생산성

WebSockets JSON Servlet 3.1 NIO REST

기업의 요구사항충족

Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.6

Top Ten Features in Java EE 7

1. WebSocket client/server endpoints2. JSON Processing3. JAX-RS Client API4. JSF 2.25. Concurrency Utilities6. Servlet 3.17. Simplified JMS API8. Batch Applications9. @Transactional and @TransactionScoped10. Default Resources

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.7

JSR 356: Java API for WebSocket 1.0

Server, Client WebSocket Endpoint

– Annotation: @ServerEndpoint, @ClientEndpoint

– Programmatic: Endpoint

라이프 사이클 지원 (@OnOpen,@OnClose)

패키징 및 배포 ( 표준 JavaEE)

@ServerEndpoint(“/chat”) public class ChatServer { @OnMessage public void chat(String m) { . . . } }

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.8

JSR 356: Java API for WebSocket 1.0

@ServerEndpoint("/chat")

public class ChatBean {

static Set<Session> peers = Collections.synchronizedSet(…);

@OnOpen public void onOpen(Session peer) { peers.add(peer); }

@OnClose public void onClose(Session peer) { peers.remove(peer); }

. . .

Chat Server

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.9

JSR 356: Java API for WebSocket 1.0

. . .

@OnMessage

public void message(String message) {

for (Session peer : peers) { peer.getRemote().sendObject(message); } }}

Chat Server ( 계속 )

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.10

JSR 353: JSON Processing 1.0

JSON 파싱 및 생성을 위한 API

Streaming API

– 저수준

– XML 의 StAX API 와 유사

Object Model API

– 단순 , 좀 더 간편해진 고수준의 API

– XML 의 DOM API 와 유사

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.11

JsonGenerator generator = Json.createGenerator(out);

generator.writeStartObject();

generator.writeStartArray("phones");

generator.writeStartObject();

generator.write("name", "iPhone");

generator.write("model", "5");

generator.writeEnd();

generator.writeEnd();

generator.write("total", 1);

generator.writeEnd();

generator.close();

JSR 353: JSON Processing 1.0Streaming API

{“phones”:[{“name”:”iPhone”,”model”:”5”], {“total”:1}

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.12

{

"firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ]}

JsonParser p = Json.createParser(…);JsonParser.Event event = p.next(); // START_OBJECTevent = p.next(); // KEY_NAMEevent = p.next(); // VALUE_STRINGString name = p.getString(); // "John”

JSR 353: JSON Processing 1.0Streaming API

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.13

{“phones”:[{“name”:”iPhone”,”model”:”5”], {“total”:1}

JsonObject jsonObject = Json.createObjectBuilder()

.add(“phones", Json.createArrayBuilder()

.add(Json.createObjectBuilder()

.add("name", “iPhone")

.add(“model", 5)

.add("Total", 1).build();

JSR 353: JSON Processing 1.0Object Model API

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.14

JSR 339: Java API for RESTful Web Services 2.0

클라이언트 API 비동기 처리 지원 – Server and Client Message Filters 와 Entity Interceptors Common Configuration

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.15

JSR 339: Java API for RESTful Web Services 2.0

// Get instance of ClientClient client = ClientBuilder.newClient(); // Get customer name for the shipped productsString name = client.target(“../orders/{orderId}/customer”) .resolveTemplate(”orderId", ”10”) .queryParam(”shipped", ”true”) .request() .get(String.class);

Client API

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.16

JSR 339: Java API for RESTful Web Services 2.0

URL url = new URL("http://. . ./orders/“ + orderId + “/customer”);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod("GET");

conn.setDoInput(true);

conn.setDoOutput(false);

BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));

String line;

while ((line = br.readLine()) != null) { //…… }

Client API - before

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.17

JSR 339: Java API for RESTful Web Services 2.0

@Path("/async/longRunning")

public class MyResource {

@GET

public void longRunningOp(@Suspended AsyncResponse ar) {

ar.setTimeoutHandler(new MyTimoutHandler());

ar.setTimeout(15, SECONDS);

Executors.newSingleThreadExecutor().submit(new Runnable() {public void run() {

ar.resume(result);

}});

}

}}

Asynchronous 처리 예 - Server

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.18

JSR 339: Java API for RESTful Web Services 2.0Filter 와 Interceptor

로깅 , 보안등 cross-cutting concern 들을 위한 용도로 사용 Filter

– ContainerRequestFilter(Server), ClientRequestFilter

– 주로 헤더 처리에 사용 Interceptor

– WriterInteceptor, ReaderInteceptor

– 메시지 바디 처리에 사용

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.19

JSR 344: JSF 2.2HTML5 친화적인 변화 기본적으로 HTML5 doctype 으로 렌더링 Pass-through attribute Pass-through element

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.20

JSR 344: JSF 2.2HTML5 친화적인 변화<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:h="http://xmlns.jcp.org/jsf/html"

xmlns:pt="http://xmlns.jcp.org/jsf/passthrough">

<h:head><title>JSF 2.2</title></h:head>

<h:body>

<h:form id="form">

<h:inputText id="email" value="#{bean.email}"

pt:type="email" pt:placeholder="Enter email"/>

</h:form>

</h:body>

</html>

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.21

JSR 344: JSF 2.2HTML5 친화적인 변화<html xmlns="http://www.w3.org/1999/xhtml"

xmlns:jsf="http://xmlns.jcp.org/jsf">

<head jsf:id="head"><title>JSF 2.2</title></head>

<body jsf:id="body">

<form jsf:id="form">

<input type="text" jsf:id="name“ placeholder="Enter name"

jsf:value="#{bean.name}"/>

<button jsf:action="#{bean.save}">Save</button>

</form>

</body>

</html>

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.22

JSR 236: Concurrency Utilities for Java EE 1.0

Java SE Concurrency API 의 확장

Java EE 어플리케이션 컴포넌트에 비동기 처리 기능 지원

4 가지 종류의 managed object

– ManagedExecutorService

– ManagedScheduledExecutorService

– ManagedThreadFactory

– ContextService

Context Propagation, Task Event Notification

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.23

JSR 236: Concurrency Utilities for Java EE 1.0

public class TestServlet extends HttpPServlet { @Resource(name=“java:comp/DefaultManagedExecutorService”) ManagedExecutorService executor;

Future future = executor.submit(new MyTask());

class MyTask implements Runnable { public void run() { . . . // task logic } }}

JNDI 를 이용해서 ManagedExecutorService 에 Task 를 전달

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.24

JSR 236: Concurrency Utilities for Java EE 1.0ContextService

Container 의 Context(JNDI, Classloading 등 ) 를 capture 하여 , 이후에 동일한 Context 에서 어플리케이션이 실행 될 수 있도록 함 .

– ManagedExecutorService 가 내부적으로 context 전달을 위해서 ContextService 를 사용할 수 있음

Serializable 함 Customize 가능

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.25

JSR 236: Concurrency Utilities for Java EE 1.0ContextService

// Within your servlet or EJB method…

@Resource

ContextService ctxSvc;

void businessMethod() {

Runnable runnableTask= new Runnable() {

void run() {// Interact with a database… use component's security}}

// Wrap with the current context

Runnable runnableTaskWithCtx= (Runnable) ctxSvc.createContextObject(runnableTask,

new Class[]{Runnable.class}

// Store the runnablewith context somewhere and run later

store.putIt(runnableTaskWithCtx);

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.26

JSR 236: Concurrency Utilities for Java EE 1.0ContextService

// Retreivethe Runnable with Context

Runnable runnableTaskWithContext= store.getIt();

// Runnable will run on this thread, but with the context of the servlet/EJB that created it.

runnableTaskWithContext.run();

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.27

Servlet 3.1

Non-blocking I/O Protocol Upgrade (ex. WebSocket) Security Enhancements

– <deny-uncovered-http-methods>: Deny request to HTTP methods not explicitly covered

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.28

Servlet 3.1

public class TestServlet extends HttpServlet protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ServletInputStream input = request.getInputStream(); byte[] b = new byte[1024]; int len = -1; while ((len = input.read(b)) != -1) { . . . } }}

Non-blocking I/O Traditional

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.29

Servlet 3.1

AsyncContext context = request.startAsync();ServletInputStream input = request.getInputStream();input.setReadListener( new MyReadListener(input, context));

Non-blocking I/O: doGet

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.30

Servlet 3.1

@Overridepublic void onDataAvailable() { try { StringBuilder sb = new StringBuilder(); int len = -1; byte b[] = new byte[1024]; while (input.isReady() && (len = input.read(b)) != -1) { String data = new String(b, 0, len); System.out.println("--> " + data); } } catch (IOException ex) { . . . }}. . .

Non-blocking read

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.31

Java Message Service 2.0

새로운 JMSContext 인터페이스

AutoCloseable JMSContext, Connection, Session, …

RunTimeException 사용

메소드 체이닝 사용 JMSProducer

Message 전송 방법 간소화

Get More from LessJava EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.32

@Resource(lookup = "myConnectionFactory”)ConnectionFactory connectionFactory;

@Resource(lookup = "myQueue”)Queue myQueue;

public void sendMessage (String payload) { Connection connection = null; try { connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(myQueue); TextMessage textMessage = session.createTextMessage(payload); messageProducer.send(textMessage); } catch (JMSException ex) { //. . . } finally { if (connection != null) { try { connection.close(); } catch (JMSException ex) {

//. . . } } }}

어플리케이션 서버의 리소스

Boilerplate Code

예외 처리

Java Message Service 2.0JMS 1.1 의 Message 전송 방법

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.33

Java Message Service 2.0

@InjectJMSContext context;

@Resource(lookup = "java:global/jms/demoQueue”)Queue demoQueue;

public void sendMessage(String payload) { context.createProducer().send(demoQueue, payload);}

JMS 2.0 의 Message 전송 방법

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.34

JSR 352: Batch Applications for Java Platform 1.0

인터렉티브 하지 않은 대용량 처리 , 및 처리 시간이 긴 작업에 적합

배치 실행 방법 : 순차 , 병렬 , 조건 ( 결정 ) 기반

프로세싱 방법

– 아이템 기반 : Chunked ( 기본옵션 )

– 태스크 기반 : Batchlet

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.35

JSR 352: Batch Applications for Java Platform 1.0개념

Job 메타데이타 저장소

배치프로세스관리

배치프로세스

각각이 독립적이면서순차적인 job 의 실행

Chunk

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.36

<step id=”sendStatements”> <chunk item-count=“3”> <reader ref=”accountReader”/> <processor ref=”accountProcessor”/> <writer ref=”emailWriter”/></step>

…implements ItemReader {public Object readItem() { // read account using JPA}

…implements ItemProcessor {Public Object processItems(Object account) { // read Account, return Statement}

…implements ItemWriter {public void writeItems(List accounts) { // use JavaMail to send email}

JSR 352: Batch Applications for Java Platform 1.0Chunked Job Specification

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.37

Contexts and Dependency Injection 1.1

JavaEE7 에서는 beans.xml 디스크립터 지정이 필요 없이 기본적으로 CDI 가 활성화 됨

Bean 디스커버리 모드– all: All types

– annotated: Scope Type 이 지정된 bean

– none: CDI 비활성화 @Vetoed 프로그래밍 적으로 비활성화 (ex. Spring @Veto) Inteceptor 와 decorator 에 global 우선 순위 및 순서 정의

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.38

Bean Validation 1.1

Dependency Injection 과의 더욱 단단해진 연계 메소드 레벨의 validation

– Constraints on parameters and return values

– Check pre-/post-conditions

JAX-RS 와의 통합

Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.39

Built-in

Custom

@Futurepublic Date getAppointment() { //. . .}

public void placeOrder( @NotNull String productName, @NotNull @Max(“10”) Integer quantity, @Customer String customer) { //. . .}

Bean Validation 1.1Method Parameter and Result Validation

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.40

Java Persistence API 2.1

스키마 생성 지원– javax.persistence.schema-generation.* properties

SynchronizationType.UNSYNCHRONIZED Criteria 를 이용한 대량의 update/delete FUNCTION 을 이용하여 유저가 만든 function 호출 가능 Stored Procedure 실행 가능

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.41

Java Transaction API 1.2

@Transactional: Define transaction boundaries on CDI managed beans

@TransactionScoped: CDI scope for bean instances scoped to the active JTA transaction

@Transactional(rollbackOn={SQLException.class},

dontRollbackOn={SQLWarning.class})

public class shoppingCart() {}

Java EE 7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.42

EJB 3.2

Servlet 3.1

CDIExtensions

Be

an

Va

lid

ati

on

1.1

Batch 1.0

Web Fragments

Java EE 7 JSRs

JCA 1.7JMS 2.0JPA 2.1

Managed Beans 1.0

Concurrency 1.0Common

Annotations 1.1Interceptors1.2, JTA 1.2

CDI 1.1

JSF 2.2,JSP 2.3,EL 3.0

JAX-RS 2.0,JAX-WS 2.2

JSON 1.0WebSocket

1.0

FINAL!

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.43

DOWNLOADJava EE 7 SDKoracle.com/javaee

GlassFish 4.0Full Platform or Web Profile

glassfish.org

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.44

4.0Java EE 7 Implementation

download.java.net/glassfish/4.0/promoted/

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.45

Java EE 8 and Beyond

Java EE 7

StateManagement

PaaS

NoSQL

JSON-B

Modularity

HTML5++

Caching

Cloud

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.46

Adopt-a-JSRParticipating JUGs

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.47

Call to Action

Specs: javaee-spec.java.net Implementation: glassfish.org Blog: blogs.oracle.com/theaquarium Twitter: @glassfish NetBeans: wiki.netbeans.org/JavaEE7

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.48

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.49

The preceding material is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Copyright © 2012, Oracle and/or its affiliates. All rights reserved.50

top related