Your SlideShare is downloading. ×
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Java EE 7 in details, David Delabasse, Oracle
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Java EE 7 in details, David Delabasse, Oracle

1,915

Published on

Oracle Java Developer Day 28.11.2012

Oracle Java Developer Day 28.11.2012

Published in: Technology
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,915
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
10
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Java EE 7 - In more detailsOracle Java Developer DayWarszawa Nov. 2012David Delabassee - @delabasseeJava EE & GlassFish Team Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 2. The following 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.2 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 3. Java EE Past, Present, & Future Productivity & HTML5 Java EE 7 Lightweight JMS 2.0, Ease of Batch, Java EE 6 Caching, TX Development Interceptor, Java EE 5 Pruning, WebSocket, Web Extensibility JSON, Services Ease of Dev, Concurrency J2EE 1.4 CDI, JAX-RS JAX-RPC, CMP/ Enterprise Robustness Ease of BMP, JSR 88Java Platform J2EE 1.3 Web Services Development, Mgmt, Annotations, Web Profile Web Profile J2EE 1.2 Deployment, EJB 3.0, JPA, Async JSF, JAXB, Servlet 3.0, JAX-RS 2.0 Servlet, JSP, CMP, JAX-WS, Connector EJB 3.1 Lite EJB, JMS, Connector StAX, SAAJ RMI/IIOP ArchitectureDec 1999 Sep 2001 Nov 2003 May 2006 Dec 2009 Q2 201310 specs 13 specs 20 specs 23 specs 28 specs 32+ specs 3 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 4. Java EE 7 - Revised Scope Productivity and HTML5 • Higher Productivity – Less Boilerplate – Richer Functionality – More Defaults • HTML5 Support – WebSocket – JSON – HTML5 Forms • JSR 3524 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 5. Java EE 7 - Candidate JSRs JAX-RS JSP 2.2 JSF 2.2 EL 3.0 Java Caching API Portable 2.0Extensions Bean Validation 1.1 Servlet 3.1 Batch Applications Common Interceptors 1.1 CDI 1.1 Java API for JSONAnnotations 1.1 Java API for Managed Beans 1.0 EJB 3.2 WebSocketConnector JPA 2.1 JTA 1.2 JMS 2.0 Concurrency 1.6 New Major Updated Release 5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 6. Java EE 7 - New APIs6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 7. Java API for JSON Processing 1.0 JSR 353 • API to parse, generate, transform, query, ... JSON • Streaming API – Similar to StAX • Object Model API – Similar to DOM • Binding JSON to Java objects forthcoming7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 8. Java API for JSON Processing 1.0 Build a JSON object"phoneNumber": [ { "type": "home", "number": ”321-123-4567” }, { "type": ”work", "number": ”123-456-7890” } ]8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 9. Java API for JSON Processing 1.0 Build a JSON object JsonObject jsonObject = new JsonBuilder()"phoneNumber": [ .beginArray("phoneNumber") { .beginObject() "type": "home", .add("type", "home") "number": ”321-123-4567” .add("number", "321-123-4567") }, .endObject() { .beginObject() "type": ”work", .add("type", ”work") "number": ”123-456-7890” .add("number", "123-456-7890") } .endObject() ] .endArray() .build();8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 10. Java API for JSON Processing 1.0 Parse a JSON object { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] }9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 11. Java API for JSON Processing 1.0 Parse a JSON object { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } JsonParser parser = Json.createParser(new StringReader(str));10 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 12. Java API for JSON Processing 1.0 Parse a JSON object { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } JsonParser parser = Json.createParser(new StringReader(str)); Iterator<Event> it = parser.iterator();11 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 13. Java API for JSON Processing 1.0 Parse a JSON object { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } JsonParser parser = Json.createParser(new StringReader(str)); Iterator<Event> it = parser.iterator(); Event event = it.next(); // START_OBJECT12 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 14. Java API for JSON Processing 1.0 Parse a JSON object { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } JsonParser parser = Json.createParser(new StringReader(str)); Iterator<Event> it = parser.iterator(); Event event = it.next(); // START_OBJECT event = it.next(); // KEY_NAME13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 15. Java API for JSON Processing 1.0 Parse a JSON object { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } JsonParser parser = Json.createParser(new StringReader(str)); Iterator<Event> it = parser.iterator(); Event event = it.next(); // START_OBJECT event = it.next(); // KEY_NAME event = it.next(); // VALUE_STRING14 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 16. Java API for JSON Processing 1.0 Parse a JSON object { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } JsonParser parser = Json.createParser(new StringReader(str)); Iterator<Event> it = parser.iterator(); Event event = it.next(); // START_OBJECT event = it.next(); // KEY_NAME event = it.next(); // VALUE_STRING String name = parser.getString(); // "John”15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 17. Java API for JSON Processing 1.0 Parse a JSON object { "firstName": "John", "lastName": "Smith", "age": 25, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } JsonParser parser = Json.createParser(new StringReader(str)); Iterator<Event> it = parser.iterator(); Event event = it.next(); // START_OBJECT event = it.next(); // KEY_NAME event = it.next(); // VALUE_STRING String name = parser.getString(); // "John”15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 18. WebSocket • Bi-directional full-duplex communication protocol – IETF RFC 6455 – TCP based – Handshake to establish connection – Send message back & forth – End the connection • Extensible – Eg. multiplexing • Part of HTML 5 – W3C JavaScript API16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 19. Main classes • Session – Represents the active conversation • Endpoint – Intercept WebSocket lifecycle events • Remote Endpoint – Represents the ‘other end’ of the conversation • Message Handler – Handles all incoming messages for an Endpoint17 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 20. Java API for WebSocket 1.0 HelloWorld - Server import javax.net.websocket.*; public class HelloServer extends Endpoint { @Override public void onOpen(Session session) { session.addMessageHandler(new MessageHandler.Text() { public void onMessage(String text) { System.out.println(“Someone said “ + text); } }); } }18 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 21. Java API for WebSocket 1.0 HelloWorld - Client import javax.net.websocket.*; public class HelloClient extends Endpoint { @Override public void onOpen(Session session) { try { session.getRemote().sendString("Hello world"); } catch (IOException ioe) { // Oops! } } }19 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 22. Java API for WebSocket 1.0 Configuration URI serverURI = new URI("/hello"); ServerContainer serverContainer = ContainerProvider.getServerContainer(); Endpoint helloServer = new HelloServer(); ServerEndpointConfiguration serverConfig = new DefaultServerConfiguration(serverURI); serverContainer.publishServer(helloServer, serverConfig); URI clientURI = new URI("ws://myserver.com/websockets/hello"); ClientContainer container = ContainerProvider.getClientContainer(); Endpoint helloClient = new HelloClient(); ClientEndpointConfiguration clientConfig = new DefaultClientConfiguration(clientURI); container.connectToServer(helloClient, clientConfig);20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 23. Java API for WebSocket 1.0 Configuration URI serverURI = new URI("/hello"); ServerContainer serverContainer = ContainerProvider.getServerContainer(); Endpoint helloServer = new HelloServer(); ServerEndpointConfiguration serverConfig = new DefaultServerConfiguration(serverURI); serverContainer.publishServer(helloServer, serverConfig); URI clientURI = new URI("ws://myserver.com/websockets/hello"); ClientContainer container = ContainerProvider.getClientContainer(); Endpoint helloClient = new HelloClient(); ClientEndpointConfiguration clientConfig = new DefaultClientConfiguration(clientURI); container.connectToServer(helloClient, clientConfig);20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 24. Message Handler string MessageHandler.Text onMessage(String message) onMessage(ByteBuffer binary data MessageHandler.Binary message) onMessage(String part, string fragments MessageHandler.AsyncText boolean last) binary data onMessage(ByteBuffer part, MessageHandler.AsyncBinary fragments boolean last)blocking stream of MessageHandler.CharacterStream onMessage(Reader r) textblocking stream of MessageHandler.BinaryStream onMessage(InputStream r) binary datacustom object of MessageHandler.DecodedObject<T> onMessage(T customObject) type T21 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 25. Java API for WebSocket 1.0 Hello Annotation import javax.net.websocket.annotations.*; @WebSocketEndpoint(“/hello”) public class HelloBean { @WebSocketMessage public void handleMessage(String message) { System.out.println(“Someone said: “ + message); } }22 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 26. Java API for WebSocket 1.0 Echo Annotation import javax.net.websocket.annotations.*; @WebSocketEndpoint(“/echo”) public class EchoBean { @WebSocketMessage public String echo(String message) { return (message + “ (via the server).”); } }23 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 27. Java API for WebSocket 1.0 Annotations Annotation level Purpose @WebSocketEndpoint class Turns a POJO into a WebSocket Endpoint @WebSocketOpen method Intercepts WebSocket Open events @WebSocketMessage method Intercepts WebSocket Message events@WebSocketPathParam method Flags a matched path segment of a URI- param. template @WebSocketError method Intercepts errors during a conversation @WebSocketClose method Intercepts WebSocket open events24 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 28. Java API for WebSocket 1.0 @WebSocketEndpoint(path=”/chat”) public class ChatServer {     Set<Session> peers = … @WebSocketOpen public void onOpen(Session peer) { peers.add(session); } @WebSocketClose public void onClose(Session session) { peers.remove(session); }    ...25 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 29. Java API for WebSocket 1.0    ... @WebSocketMessage public void message(String message, Session client) throws IOException { for (Session session : peers) { if (!session.equals(client)) { session.getRemote().sendObject(message); } } } }26 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 30. Batch Applications for the Java Platform 1.0 JSR 352 • “Job” – One or more Step(s) • “Step” – Sequential phase of a batch job – Item Read, Process & Write – In a certain order • Checkpoint(s) • Job Control – Job Specification Language27 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 31. Batch Applications for the Java Platform 1.0<step id=”sendStatements”> <chunk reader=”AccountReader” processor=”AccountProcessor” writer=”EmailWriter” chunk-size=”10” /></step> 28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 32. Batch Applications for the Java Platform 1.0<step id=”sendStatements”> @ReadItem <chunk reader=”AccountReader” public Account readAccount() { processor=”AccountProcessor” // read account using JPA writer=”EmailWriter” } chunk-size=”10” /></step> 28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 33. Batch Applications for the Java Platform 1.0<step id=”sendStatements”> @ReadItem <chunk reader=”AccountReader” public Account readAccount() { processor=”AccountProcessor” // read account using JPA writer=”EmailWriter” } chunk-size=”10” /></step> @ProcessItem public Account processAccount(Account account) { // calculate balance } 28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 34. Batch Applications for the Java Platform 1.0<step id=”sendStatements”> @ReadItem <chunk reader=”AccountReader” public Account readAccount() { processor=”AccountProcessor” // read account using JPA writer=”EmailWriter” } chunk-size=”10” /></step> @ProcessItem public Account processAccount(Account account) { // calculate balance } @WriteItems public void sendEmail(List<Account> accounts) { // use JavaMail to send email } 28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 35. Java Temporary Caching API 1.0 JSR 107 • API for temporary in-memory caching of Java objects • “Interceptor” to protect (expensive) resources • Improve capacity / performance • Scaling out • Java SE 6, Java EE 6 (and above)29 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 36. Java Temporary Caching API 1.0 • “Key value named store” – CacheManagerCache(s) – CacheEntry(‘s) – Entry : Key, Value pair • Cache Provider – Ex. simple, in-process caching implementation • javax.cache.* – Atomic operations – read/write-through, event listeners, statistics, etc. – Optional : Transaction & annotations30 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 37. Java Temporary Caching API 1.0 String cacheName = "sampleCache"; CacheManager cacheManager = Caching.getCacheManager()31 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 38. Java Temporary Caching API 1.0 String cacheName = "sampleCache"; CacheManager cacheManager = Caching.getCacheManager(); Cache<String, Integer> cache = cacheManager.getCache(cacheName);32 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 39. Java Temporary Caching API 1.0 String cacheName = "sampleCache"; CacheManager cacheManager = Caching.getCacheManager(); Cache<String, Integer> cache = cacheManager.getCache(cacheName); cache = cacheManager.<String, Integer> createCacheBuilder(cacheName) .setStoreByValue(false).build();33 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 40. Java Temporary Caching API 1.0 String cacheName = "sampleCache"; CacheManager cacheManager = Caching.getCacheManager(); Cache<String, Integer> cache = cacheManager.getCache(cacheName); cache = cacheManager.<String, Integer> createCacheBuilder(cacheName) .setStoreByValue(false).build(); String key = "key"; Integer value1 = 1; cache.put(key, value1); Integer value2 = cache.get(key); cache.remove("key");34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 41. Java Temporary Caching API 1.0 String cacheName = "sampleCache"; CacheManager cacheManager = Caching.getCacheManager(); Cache<String, Integer> cache = cacheManager.getCache(cacheName); cache = cacheManager.<String, Integer> createCacheBuilder(cacheName) .setStoreByValue(false).build(); String key = "key"; Integer value1 = 1; cache.put(key, value1); Integer value2 = cache.get(key); cache.remove("key");34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 42. Java Temporary Caching API 1.0 String cacheName = "sampleCache"; CacheManager cacheManager = Caching.getCacheManager(); Cache<String, Integer> cache = cacheManager.getCache(cacheName); cache = cacheManager.<String, Integer> createCacheBuilder(cacheName) .setStoreByValue(false).build(); String key = "key"; Integer value1 = 1; cache.put(key, value1); Integer value2 = cache.get(key); cache.remove("key");34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 43. Java Temporary Caching API 1.0 public class CustomerBean { " @CachePut(cacheName=“myCache”) " public void addCustomer( " " @CacheKeyParam int cid, " " @CacheValue Customer customer) { " " //... " } }35 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 44. Concurrency Utilities for Java EE JSR 236 • Easily add concurrency to Java EE applications • Consistent between the Java SE and EE platforms • Simple to advanced concurrency patterns without sacrificing usability • Tasks – Units of work that represent a computation or some business logic – Implementations of java.util.concurrent.Callable and java.lang.Runnable interfaces36 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 45. Concurrency Utilities for Java EE public class ReporterTask implements Runnable { String reportName; public ReporterTask(String reportName) { " " this.reportName = reportName; " } public void run() { // Run the named report " if("TransactionReport".equals(reportName)) { runTxReport(); " else if("SummaryReport".equals(reportName)) { runSumReport(); } } Datasource ds = ...; void runTxReport() { " Connection con = ds.getConnection(); // Read/Write... " con.commit(); " con.close(); }37 } Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 46. Concurrency Utilities for Java EE public class MyServlet extends HTTPServlet implements Servlet { // Cache our executor instance @Resource(name=”concurrent/BatchExecutor”) ManagedExecutorService mes; protected void doPost(HttpServletRequest req, HttpServletResponse rep) " " " throws ServletException, IOException { // Get the name of the report to run from the input params // Create a task instance ReporterTask reporterTask = new ReporterTask(reportName); // Submit the task to the ManagedExecutorService Future reportFuture = mes.submit(reporterTask); // Using future, client can poll to determine the status... ... " " } }38 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 47. Concurrency Utilities for Java EE Added to web.xml <resource-env-ref> <description>This executor is used for the application’s builder tasks </description> <resource-env-ref-name>concurrent/BatchExecutor</resource-env-ref-name> <resource-env-ref-type>javax.enterprise.concurrent.ManagedExecutorService </resource-env-ref-type> </resource-env>39 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 48. Concurrency Utilities for Java EE public class AccountTask implements Callable<AccountInfo>, Identifiable { String reqID; String accountID; AcctInfoHome acctInfoHome; public AccountTask(String reqID, String acctID, AcctInfoHome acctInfoHome) { this.reqID=reqID; this.acctID=acctID; this.acctInfoHome = acctInfoHome; } public AccountInfo call() { // Find the entity bean & return it return acctInfoHome.find(accountID); } public String getIdentityName() { return "AccountTask ReqID=" + reqID + " Acct=" + accountID; } public String getIdentityDescription(Locale locale) { return "AccountTask asynchronous EJB invoker"; }40 } Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 49. Concurrency Utilities for Java EE public class AppServlet extends HTTPServlet implements Servlet { @Resource(name=”concurrent/BuilderExecutor”) ManagedExecutorService mes; // Retrieve our executor instance. AccountInfoHome acctInfoHome; InsuranceInfoHome insInfoHome; protected void doPost(HttpServletRequest req, HttpServletResponse rep) throws ServletException, IOException { ArrayList<Callable> builderTasks = new ArrayList<Callable>(); " " builderTasks.add(new AccountTask(reqID, accountID, acctInfoHome)); " " builderTasks.add(new InsuranceTask(reqID, accountID,insInfoHome)); " " // Submit the tasks and wait. " " List<Future<Object>> results = mes.invokeAll(builderTasks); " " AccountInfo accountInfo = (AccountInfo) results.get(0).get(); " " InsuranceInfo insInfo = (InsuranceInfo) results.get(1).get(); " " // Process the results } }41 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 50. Java EE 7 - Revised APIs42 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 51. Java API for RESTful Web Services 2.0 JSR 339 • Message Filters & Entity Interceptors • Asynchronous Processing – Server & Client • Hypermedia Support • Common Configuration • Client API43 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 52. Java Message Service Primer • A standard messaging API – Application API only • Not a messaging system in itself – Not a wire protocol • Java API only – Doesn’t define API for non-Java clients • Widely used but... • JMS 1.1 – Circa 200244 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 53. Java Message Service Primer • A standard messaging API – Application API only • Not a messaging system in itself – Not a wire protocol • Java API only – Doesn’t define API for non-Java clients • Widely used but... • JMS 1.1 – Circa 200244 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 54. Java Message Service Primer • A standard messaging API – Application API only • Not a messaging system in itself – Not a wire protocol • Java API only – Doesn’t define API for non-Java clients • Widely used but... • JMS 1.1 – Circa 200244 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 55. Java Message Service Sending a Message using JMS 1.1 @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) { //. . . } } }45 } Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 56. Java Message Service Sending a Message using JMS 1.1 @Resource(lookup = "myConnectionFactory”) ConnectionFactory connectionFactory; Application Server @Resource(lookup = "myQueue”) Specific Resources 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) { //. . . } } }45 } Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 57. Java Message Service Sending a Message using JMS 1.1 @Resource(lookup = "myConnectionFactory”) ConnectionFactory connectionFactory; Application Server @Resource(lookup = "myQueue”) Specific Resources 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); Boilerplate Code TextMessage textMessage = session.createTextMessage(payload); messageProducer.send(textMessage); } catch (JMSException ex) { //. . . } finally { if (connection != null) { try { connection.close(); } catch (JMSException ex) { //. . . } } }45 } Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 58. Java Message Service Sending a Message using JMS 1.1 @Resource(lookup = "myConnectionFactory”) ConnectionFactory connectionFactory; Application Server @Resource(lookup = "myQueue”) Specific Resources Queue myQueue; public void sendMessage (String payload) { Connection connection = null; Confusing Args try { connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(myQueue); Boilerplate Code TextMessage textMessage = session.createTextMessage(payload); messageProducer.send(textMessage); } catch (JMSException ex) { //. . . } finally { if (connection != null) { try { connection.close(); } catch (JMSException ex) { //. . . } } }45 } Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 59. Java Message Service Sending a Message using JMS 1.1 @Resource(lookup = "myConnectionFactory”) ConnectionFactory connectionFactory; Application Server @Resource(lookup = "myQueue”) Specific Resources Queue myQueue; public void sendMessage (String payload) { Connection connection = null; Confusing Args try { connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(myQueue); Boilerplate Code TextMessage textMessage = session.createTextMessage(payload); messageProducer.send(textMessage); } catch (JMSException ex) { //. . . } finally { if (connection != null) { try { connection.close(); } catch (JMSException ex) { //. . . } } Close }45 } Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 60. Java Message Service Sending a Message using JMS 1.1 @Resource(lookup = "myConnectionFactory”) ConnectionFactory connectionFactory; Application Server @Resource(lookup = "myQueue”) Specific Resources Queue myQueue; public void sendMessage (String payload) { Connection connection = null; Confusing Args try { connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(myQueue); Boilerplate Code TextMessage textMessage = session.createTextMessage(payload); messageProducer.send(textMessage); } catch (JMSException ex) { //. . . } finally { if (connection != null) { try { Exception Handling connection.close(); } catch (JMSException ex) { //. . . } } Close }45 } Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 61. Java Message Service 2.0 JSR 343 • Define new simplified API – + Simplify existing API • Reduce boilerplate code • Less verbose • Resource injection • Connection, Session and other objects are Auto- Closable • Requires Resource Adapter for Java EE containers46 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 62. Java Message Service 2.0 Simplify the existing API • New methods to create session • Existing methods remains – connection.createSesssion(transacted, deliveryMode) • New method for Java SE – connection.createSesssion(sessionMode) • New method for Java EE – connection.createSesssion()47 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 63. Java Message Service 2.0 Simplify the existing API @Resource(lookup = "jms/connFactory") ConnectionFactory cf; Existing @Resource(lookup="jms/inboundQueue") Destination dest; connection.createSession(transacted, deliveryMode); public void sendMessage (String payload) throws JMSException { try ( Connon conn = connectionFactory.createConnection(); Session session = conn.createSession(); New48 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 64. Java Message Service 2.0 Simplify the existing API @Resource(lookup = "jms/connFactory") ConnectionFactory cf; @Resource(lookup="jms/inboundQueue") Destination dest; public void sendMessage (String payload) throws JMSException { try ( Connection conn = connectionFactory.createConnection(); Session session = conn.createSession(); try with MessageProducer producer = session.createProducer(dest); resource ){ Message mess = sess.createTextMessage(payload); producer.send(mess); } catch(JMSException e){ // exception handling } }49 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 65. Java Message Service 2.0 New simplified API @Resource(lookup = "java:global/jms/demoConnectionFactory") ConnectionFactory connectionFactory; @Resource(lookup = "java:global/jms/demoQueue") Queue demoQueue; public void sendMessageNew(String payload) { try (JMSContext context = connectionFactory.createContext();){ context.createProducer().send(demoQueue, payload); } catch (JMSRuntimeException ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } }50 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 66. Java Message Service 2.0 JMSContext combines New simplified API Connection & Session @Resource(lookup = "java:global/jms/demoConnectionFactory") ConnectionFactory connectionFactory; @Resource(lookup = "java:global/jms/demoQueue") Queue demoQueue; public void sendMessageNew(String payload) { try (JMSContext context = connectionFactory.createContext();){ context.createProducer().send(demoQueue, payload); } catch (JMSRuntimeException ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } }50 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 67. Java Message Service 2.0 JMSContext combines New simplified API Connection & Session @Resource(lookup = "java:global/jms/demoConnectionFactory") ConnectionFactory connectionFactory; @Resource(lookup = "java:global/jms/demoQueue") Queue demoQueue; JMSProducer public void sendMessageNew(String payload) { try (JMSContext context = connectionFactory.createContext();){ context.createProducer().send(demoQueue, payload); } catch (JMSRuntimeException ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } }50 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 68. Java Message Service 2.0 JMSContext combines New simplified API Connection & Session @Resource(lookup = "java:global/jms/demoConnectionFactory") ConnectionFactory connectionFactory; @Resource(lookup = "java:global/jms/demoQueue") Queue demoQueue; JMSProducer public void sendMessageNew(String payload) { try (JMSContext context = connectionFactory.createContext();){ context.createProducer().send(demoQueue, payload); } catch (JMSRuntimeException ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } } Payload can be sent directly50 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 69. Java Message Service 2.0 JMSContext combines New simplified API Connection & Session @Resource(lookup = "java:global/jms/demoConnectionFactory") ConnectionFactory connectionFactory; @Resource(lookup = "java:global/jms/demoQueue") Queue demoQueue; JMSProducer public void sendMessageNew(String payload) { try (JMSContext context = connectionFactory.createContext();){ context.createProducer().send(demoQueue, payload); } catch (JMSRuntimeException ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } } No checked Payload can be exception thrown sent directly50 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 70. Java Message Service 2.0 JMSContext combines New simplified API Connection & Session @Resource(lookup = "java:global/jms/demoConnectionFactory") ConnectionFactory connectionFactory; @Resource(lookup = "java:global/jms/demoQueue") Queue demoQueue; JMSProducer public void sendMessageNew(String payload) { try (JMSContext context = connectionFactory.createContext();){ context.createProducer().send(demoQueue, payload); } catch (JMSRuntimeException ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } } No checked Payload can be exception thrown sent directly No close50 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 71. Java Message Service 2.0 Sending a Message using JMS 2.0 Simplified API @Inject JMSContext context; @Resource(mappedName=”myQueue") Queue myQueue; public void sendMessage(String payload) { context.createProducer().send(myQueue, payload); }51 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 72. Java Message Service 2.0 Sending a Message using JMS 2.0 Simplified API Default resource definition @Inject Or JMSContext context; @JmsConnectionFactory @Resource(mappedName=”myQueue") Queue myQueue; public void sendMessage(String payload) { context.createProducer().send(myQueue, payload); }51 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 73. Java Message Service 2.0 Sending a Message using JMS 2.0 Simplified API Default resource definition @Inject Or JMSContext context; @JmsConnectionFactory @Resource(mappedName=”myQueue") Queue myQueue; 18 lines 1 line public void sendMessage(String payload) { context.createProducer().send(myQueue, payload); }51 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 74. Java Message Service 2.0 Sending a Message using JMS 2.0 Simplified API @Inject JMSContext context; @Resource(mappedName=”myQueue") Queue myQueue; public void sendMessage(String payload) { context.createProducer() .setProperty(“foo”,”bar”).send(myQueue, payload); }52 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 75. Beans Validation 1.1 Method Parameter and Result Validation public void placeOrder( @NotNull String productName, @NotNull @Max(“10”) Integer quantity, @Customer String customer) { //... } @Future public Date getAppointment() { //... }53 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 76. Beans Validation 1.1 Method Parameter and Result Validation public void placeOrder(Built-in @NotNull String productName, @NotNull @Max(“10”) Integer quantity,Custom @Customer String customer) { //... } @Future public Date getAppointment() { //... }53 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 77. Beans Validation 1.1 Method Parameter and Result Validation public void placeOrder(Built-in @NotNull String productName, @NotNull @Max(“10”) Integer quantity,Custom @Customer String customer) { //... } @Future public Date getAppointment() { //... }53 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 78. JavaServer Faces 2.2 JSR 344 • Faces Flows • HTML5 support • Loading Facelets via ResourceHandler • File Upload Component • Cross Site Request Forgery Protection • Multi-Templating • etc.54 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 79. Many other improvements ... • JPA 2.1: Schema generation, unsynchronized PC, ... • EJB 3.2: Optional CMP/BMP, Ease-of-use, Refactoring, … • Servlet 3.1: Non-blocking IO, Upgrade to WebSocket, … • EL 3.0: Lambda expressions, Collection, Operators, … • JTA 1.2: Transactional interceptors • CDI 1.1: Ordering of interceptors, Servlet events, …55 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 80. Wrap up...56 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 81. Java EE 7 – Implementation Status 4.0 http://download.java.net/glassfish/4.0/promoted/57 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 82. Call To Action • Java EE 7 Transparent Expert Groups – http://javaee-spec.java.net • Java EE 7 Reference Implementation – http://glassfish.org • The Aquarium – http://blogs.oracle.com/theaquarium • Hands-on lab – https://github.com/jersey/hol-sse-websocket/58 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 83. Hands-on Lab • Hands-on lab – https://github.com/jersey/hol-sse-websocket/ – http://delabassee.com/hold/1211PL/59 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 84. Graphic Section Divider60 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

×