Slide 1

Slide 1 text

1 50 best features of Java EE 7 in 50 minutes Markus Eisele, @myfear Developer Advocate September, 2014

Slide 2

Slide 2 text

2

Slide 3

Slide 3 text

3 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5

Slide 4

Slide 4 text

4 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 CDI 1.1 (JSR 346)

Slide 5

Slide 5 text

5 #01: CDI: Default enabling Finer scanning control Possible values: all, annotated, none all behaves like in Java EE 6 (default if not set) org.agoncal.book.MockGenerator

Slide 6

Slide 6 text

6 #02: CDI: @Vetoed Veto the processing of the class or package @Vetoed public class NonProcessedBean { ... } package-info.java @Vetoed package com.non.processed.package;

Slide 7

Slide 7 text

7 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 Bean Validation 1.1 (JSR 349)

Slide 8

Slide 8 text

8 #03: Bean Validation: Method validation Pre/post conditions on method and constructors public class CardValidator { public CardValidator(@NotNull Algorithm algorithm) { this.algorithm = algorithm; } @AssertTrue public Boolean validate(@NotNull CreditCard creditCard) { return algorithm.validate(creditCard.getNumber()); } }

Slide 9

Slide 9 text

9 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 Interceptors 1.2 (JSR 318)

Slide 10

Slide 10 text

10 #04: Interceptors: AroundConstruct Interceptor associated with a constructor public class LoggingInterceptor { @AroundConstruct private void init(InvocationContext ic) throws Exception{ logger.fine("Entering constructor"); ic.proceed(); logger.fine("Exiting constructor"); } @AroundInvoke public Object logMethod(InvocationContext ic) ... { // ... } }

Slide 11

Slide 11 text

11 #05: Interceptors: @Priority Prioritizing interceptor bindings PLATFORM_BEFORE (0), LIBRARY_BEFORE (1000), APPLICATION (2000), LIBRARY_AFTER (3000), PLATFORM_AFTER (4000) @Interceptor @Loggable @Priority(Interceptor.Priority.LIBRARY_BEFORE+10) public class LoggingInterceptor { @AroundInvoke ... }

Slide 12

Slide 12 text

12 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 Concurrency utilities 1.0 (JSR 236)

Slide 13

Slide 13 text

13 #06: Concurrency: ManagedExecutor User threads in Java EE applications Support simple and advance concurrency design patterns Extend Concurrency Utilities API from Java SE (JSR 166y) java.util.concurrent package

Slide 14

Slide 14 text

14 #06: Concurrency: ManagedExecutor @Resource ManagedExecutorService executor; ManagedExecutorService executor = (ManagedExecutorService) ctx .lookup("java:comp/DefaultManagedExecutorService"); Default ManagedExectuor

Slide 15

Slide 15 text

15 #06: Concurrency: ManagedExecutor concurrent/myExecutor javax.enterprise.concurrent.ManagedExecutorService Specify in web.xml

Slide 16

Slide 16 text

16 #07: Concurrency: ManagedScheduledExecutor Managed version of ScheduledExecutorService Submit delayed or periodic tasks @Resource ManagedScheduledExecutorService executor;

Slide 17

Slide 17 text

17 #07: Concurrency: ManagedScheduledExecutor InitialContext ctx = new InitialContext(); ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService)ctx.lookup( "java:comp/DefaultManagedScheduledExecutorService "); Can be defined in web.xml as well Access using JNDI

Slide 18

Slide 18 text

18 #07: Concurrency: ManagedScheduledExecutor executor.schedule(new MyCallableTask(), 5, TimeUnit.SECONDS); executor.scheduleAtFixedRate(new MyRunnableTask(), 2, 3, TimeUnit.SECONDS); executor.scheduleWithFixedDelay(new MyRunnableTask(), 2, 3, TimeUnit.SECONDS);

Slide 19

Slide 19 text

19 #08: Concurrency: ManagedThreadFactory Extends ThreadFactory @Resource(name = "DefaultManagedThreadFactory") ManagedThreadFactory factory; ManagedThreadFactory factory = (ManagedThreadFactory) ctx.lookup("java:comp/DefaultManagedThreadFactory ");

Slide 20

Slide 20 text

20 #08: Concurrency: ManagedThreadFactory Thread thread = factory.newThread(new MyTask()); ((ManageableThread)thread).isShutdown();

Slide 21

Slide 21 text

21 #09: Concurrency: DynamicProxy Create dynamic proxy objects, adds contextual information available for applications running in Java EE environment Classloading, JNDI, Security, …

Slide 22

Slide 22 text

22 #09: Concurrency: DynamicProxy @Resource ContextService service; Runnable proxy = service.createContextualProxy(new MyRunnable(), Runnable.class); Future f = executor.submit(proxy);

Slide 23

Slide 23 text

23 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 JPA 2.1 (JSR 338)

Slide 24

Slide 24 text

24 #10: JPA: Schema Generation Standardized database schema generation

Slide 25

Slide 25 text

25 #11: JPA: @Index Defines additional indexes in schema generation @Entity @Table(indexes = { @Index(columnList = "ISBN"), @Index(columnList = "NBOFPAGE") }) public class Book { @Id @GeneratedValue private Long id; private String isbn; private Integer nbOfPage; ... }

Slide 26

Slide 26 text

26 #12: JPA: Unsynchronized Persistence Context Persistence context is not enlisted in any tx unless explicitly joined @PersistenceContext(synchronization = SynchronizationType.UNSYNCHRONIZED) private EntityManager em; ... em.persist(book); ... em.joinTransaction();

Slide 27

Slide 27 text

27 #13: JPA: Stored Procedure Calling a stored procedure @Entity @NamedStoredProcedureQuery(name = "archiveOldBooks", procedureName = "sp_archive_books", parameters = { @StoredProcedureParameter(name = ”date", mode = IN, type = Date.class), @StoredProcedureParameter(name = "warehouse", mode = IN, type = String.class) }) public class Book {...}

Slide 28

Slide 28 text

28 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 JTA 1.2 (JSR 907)

Slide 29

Slide 29 text

29 #14: JTA: @Transactional Transaction management on Managed Beans as CDI interceptor binding @Path("book") @Transactional(value = Transactional.TxType.REQUIRED, rollbackOn = {SQLException.class, JMSException.class}, dontRollbackOn = SQLWarning.class) public class BookRestService { @PersistenceContext private EntityManager em; @POST @Consumes(MediaType.APPLICATION_XML) public Response createBook(Book book) {...} }

Slide 30

Slide 30 text

30 #15: JTA: @TransactionScoped CDI scope whose lifecycle is scoped to the currently active JTA transaction @TransactionScoped public class BookBean {...} @WebServlet public class TxServlet extends HttpServlet { @Inject UserTransaction tx; @Inject BookBean b1; @Inject BookBean b2; protected void processRequest(...) { tx.begin(); s_out.println(b1.getReference()); s_out.println(b2.getReference()); tx.commit(); } }

Slide 31

Slide 31 text

31 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 EJB 3.2 (JSR 345)

Slide 32

Slide 32 text

32 #16: EJB: Disable passivation of stateful In some cases increases performance, scalability and robustness @Stateful(passivationCapable = false) public class ShoppingCart { ... }

Slide 33

Slide 33 text

33 #17: EJB-Lite: Async + Non-persistent timer Extended the EJB Lite to include local asynchronous invocations and non-persistent EJB Timer Service @Stateless public class OrderEJB { @Asynchronous public void sendEmail (Order order) { // Very Long task } @Schedule(hour="2", persistent=false) public void createDailyReport() { // ... } }

Slide 34

Slide 34 text

34 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 JMS 2.0 (JSR 343)

Slide 35

Slide 35 text

35 #18: JMS: JMSContext API New simplified API to produce and consume messages JMSContext ctx = connectionFactory.createContext() ctx.createProducer().send(queue, "Text message sent"); ctx.createConsumer(queue).receiveBody(String.class); ctx.createProducer() .setPriority(2) .setTimeToLive(1000) .setDeliveryMode(DeliveryMode.NON_PERSISTENT) .send(queue, message);

Slide 36

Slide 36 text

36 #19: JMS: Autocloseable Several JMS interfaces implement Autocloseable try (JMSContext ctx = connectionFactory.createContext()) { ctx.createProducer().send(queue, "Text message sent"); } ... try (JMSContext ctx = connectionFactory.createContext()) { while (true) { String s = ctx.createConsumer(queue).receiveBody(String.class); } }

Slide 37

Slide 37 text

37 #20: JMS: JMSConnectionFactoryDefinition A JMS ConnectionFactory can be defined using an annotation on a container-managed class @Stateless @JMSConnectionFactoryDefinition( name = "java:app/jms/MyConnectionFactory", interfaceName = "javax.jms.TopicConnectionFactory") public class ExpensiveOrderEJB {...}

Slide 38

Slide 38 text

38 #21: JMS: JMSDestinationDefinition A JMS queue or topic can be defined using an annotation @Stateless @JMSConnectionFactoryDefinition( name = "java:app/jms/MyConnectionFactory", interfaceName = "javax.jms.TopicConnectionFactory") @JMSDestinationDefinition( name = "java:app/jms/MyTopic", interfaceName = "javax.jms.Topic") public class ExpensiveOrderEJB {...}

Slide 39

Slide 39 text

39 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 Servlet 3.1 (JSR 340)

Slide 40

Slide 40 text

40 #22: Servlet: Non-blocking I/O 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) { . . . } } }

Slide 41

Slide 41 text

41 #22: Servlet: Non-blocking I/O ServletInputStream public void setReadListener(ReadListener listener); public boolean isFinished(); public boolean isReady(); ServletOutputStream public setWriteListener(WriteListener listener); public boolean canWrite(); New methods to existing interfaces

Slide 42

Slide 42 text

42 #22: Servlet: Non-blocking I/O public interface ReadListener extends EventListener { public void onDataAvailable(); pubic void onAllDataRead(); public void onError(); } public interface WriteListener extends EventListener { public void onWritePossible(); public void onError(); } New interfaces

Slide 43

Slide 43 text

43 #22: Servlet: Non-blocking I/O AsyncContext context = request.startAsync(); ServletInputStream input = request.getInputStream(); input.setReadListener( new MyReadListener(input, context)); Only for Asynchronous Servlets

Slide 44

Slide 44 text

44 #23: Servlet: Protocol Upgrade T HttpServletRequest.upgrade(Class class) throws IOException; HttpUpgradeHandler init(WebConnection wc); destroy();

Slide 45

Slide 45 text

45 #23: Servlet: Protocol Upgrade public interface WebConnection { ServletInputStream getInputStream(); ServletOutputStream getOutputStream(); }

Slide 46

Slide 46 text

46 #24: Servlet: Improved Security /account/* GET . . . Deny an HTTP method request for an uncovered HTTP method

Slide 47

Slide 47 text

47 #24: Servlet: Improved Security /account/* GET . . . Deny an HTTP method request for an uncovered HTTP method

Slide 48

Slide 48 text

48 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 Web Socket 1.0 (JSR 356)

Slide 49

Slide 49 text

49 #25: WebSocket: Annotated server endpoint Enables full-duplex bi-directional communication over single TCP connection @javax.websocket.server.ServerEndpoint("/chat") public class ChatServer { @OnMessage public String chat(String name, Session session) { for (Session peer : client.getOpenSessions()) { peer.getBasicRemote().sendObject(message); } } }

Slide 50

Slide 50 text

50 #26: WebSocket: Lifecycle callbacks @javax.websocket.OnOpen public void open(Session s) { . . . } @javax.websocket.OnClose public void close(CloseReason c) { . . . } @javax.websocket.OnError public void error(Throwable t) { . . . }

Slide 51

Slide 51 text

51 #27: WebSocket: Annotated client endpoint @javax.websocket.ClientEndpoint public class MyClient { @javax.websocket.OnOpen public void open(Session session) { … } // Lifecycle callbacks }

Slide 52

Slide 52 text

52 #27: WebSocket: Annotated client endpoint ContainerProvider .getWebSocketContainer() .connectToServer( MyClient.class, URI.create("ws://. . ."));

Slide 53

Slide 53 text

53 #28: WebSocket: Programmatic endpoints public class ChatServer extends Endpoint { @Override public void onOpen(Session s, EndpointConfig ec) { s.addMessageHandler(new MessageHandler.Whole() { public void onMessage(String text) { . . . } } } @Override public void onClose(Session s, CloseReason cr) { . . . } //. . . }

Slide 54

Slide 54 text

54 #28: WebSocket: Programmatic endpoints public class MyApplicationConfig implements ServerApplicationConfig { public Set getEndpointConfigs(…) { ServerEndpointConfig.Builder .create(MyEndpoint.class, "/websocket”) .configurator(new MyConfig()) .build() } }

Slide 55

Slide 55 text

55 #28: WebSocket: Programmatic endpoints public class MyConfig extends ServerEndpointConfig.Configurator { public T getEndpointInstance(. . .) { . . . } public void modifyHandshake(. . .) { . . . } . . . }

Slide 56

Slide 56 text

56 #29: WebSocket: Encoder and Decoder @javax.websocket.server.ServerEndpoint( value="/chat", decoders="MyDecoder.class", encoders="MyEncoder.class") public class ChatServer { @OnMessage public String chat(ChatMessage name, Session session) { . . . } }

Slide 57

Slide 57 text

57 #29: WebSocket: Encoder and Decoder public class MyDecoder implements Decoder.Text { public ChatMessage decode(String s) { // . . . } public boolean willDecode(String string) { // . . . } //. . . }

Slide 58

Slide 58 text

58 #29: WebSocket: Encoder and Decoder public class MyEncoder implements Encoder.Text { public String encode(ChatMessage chatMessage) { // . . . } // . . . }

Slide 59

Slide 59 text

59 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 Expression Language 3.0 (JSR 341)

Slide 60

Slide 60 text

60 #30: Expression Langauge: ELProcessor Use EL in a stand-alone environment Evaluate EL expressions Get/set bean properties Defining a static method as an EL function Defining an object instance as an EL name ELProcessor elp = new ELProcessor(); elp.defineBean("employee", new Employee("Charlie Brown")); String name = elp.eval("employee.name");

Slide 61

Slide 61 text

61 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 JSF 2.2 (JSR 344)

Slide 62

Slide 62 text

62 #31: JSF: Faces Flow ./src/main/webapp/flow1 /flow1.xhtml /flow1a.xhtml /flow1b.xhtml ./src/main/webapp/flow2 /flow2-flow.xml /flow2.xhtml /flow2a.xhtml /flow2b.xhtml /index.xhtml Package reusable flows in JAR

Slide 63

Slide 63 text

63 #31: JSF: Faces Flow @Named @FlowScoped("flow1") public class Flow1Bean implements Serializable { } @Produces @FlowDefinition public Flow defineFlow(@FlowBuilderParameter FlowBuilder fb) { String flowId = "flow1"; //. . . return fb.getFlow(); } Package reusable flows in JAR

Slide 64

Slide 64 text

64 #31: JSF: Faces Flow Package reusable flows in JAR #{flowScope}: Local flow storage #{facesContext.application.flowHandler.currentFlow} : Returns true if within a flow

Slide 65

Slide 65 text

65 #32: JSF: Resource Library Contract index-blue.xhtml index-red.xhtml WEB-INF/lib/contracts-library-1.0-SNAPSHOT.jar /META-INF/contracts/blue /style.css /javax.faces.contract.xml /template.xhtml /META-INF/contracts/red /style.css /javax.faces.contract.xml /template.xhtml Apply templates in a reusable and interchangeable manner

Slide 66

Slide 66 text

66 #32: JSF: Resource Library Contract . . . Apply templates in a reusable and interchangeable manner

Slide 67

Slide 67 text

67 #33: JSF: Pass-through Attributes HTML5-Friendly Markup

Slide 68

Slide 68 text

68 #34: JSF: File Upload Component

@Named @RequestScoped public class FileUploadBean { private Part file; //getter and setter }

Slide 69

Slide 69 text

69 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 JAX-RS 2.0 (JSR 339)

Slide 70

Slide 70 text

70 #35: JAX-RS: Client API New API to consume rest services Client client = ClientBuilder.newClient(); WebTarget target = client.target("http://www.foo.com/book"); Invocation invocation = target.request(TEXT_PLAIN).buildGet(); Response response = invocation.invoke(); Response response = ClientBuilder.newClient() .target("http://www.foo.com/book") .request(MediaType.TEXT_PLAIN) .get(); String body = ClientBuilder.newClient() .target("http://www.foo.com/book") .request() .get(String.class);

Slide 71

Slide 71 text

71 #36: JAX-RS: Async Client The client API also supports asynchronous invocation Future future = ClientBuilder.newClient() .target("http://www.foo.com/book") .request() .async() .get(String.class); try { String body = future.get(1, TimeUnit.MINUTES); } catch (InterruptedException | ExecutionException e) {...}

Slide 72

Slide 72 text

72 #37: JAX-RS: Async Server Asynchronous request processing on the server @Path("/async") public class AsyncResource { @GET public void asyncGet(@Suspended AsyncResponse asyncResp) { new Thread(new Runnable() { public void run() { String result = veryExpensiveOperation(); asyncResp.resume(result); } }).start(); }}

Slide 73

Slide 73 text

73 #38: JAX-RS: Message Filter Used to process incoming and outgoing request or response headers Filters on client side ClientRequestFilter ClientResponseFilter Filters on server side ContainerRequestFilter ContainerResponseFilter

Slide 74

Slide 74 text

74 #38: JAX-RS: Message Filter Used to process incoming and outgoing request or response headers public class LogginFilter implements ClientRequestFilter { public void filter(ClientRequestContext ctx) throws IOException { System.out.println(ctx.getMethod()); System.out.println(ctx.getUri()); } }

Slide 75

Slide 75 text

75 #39: JAX-RS: Entity Interceptors Marshalling and unmarshalling HTTP message bodies Intercepts inbound entity streams (reads from the “wire”) ReaderInterceptor Intercepts outbound entity streams (writes to the “wire”) WriterInterceptor

Slide 76

Slide 76 text

76 #39: JAX-RS: Entity Interceptors Marshalling and unmarshalling HTTP message bodies public class GZipInterceptor implements WriterInterceptor { public void aroundWriteTo(WriterInterceptorContext ctx){ OutputStream os = ctx.getOutputStream(); ctx.setOutputStream(new GZIPOutputStream(os)); ctx.proceed(); } }

Slide 77

Slide 77 text

77 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 JSON-P 1.0 (JSR 353)

Slide 78

Slide 78 text

78 #40: JSON-P: JSON Builder Creates an object model (or an array) in memory by adding elements JsonObject value = Json.createObjectBuilder() .add("id", "1234") .add("date", "19/09/2012") .add("total_amount", "93.48") .add("customer", Json.createObjectBuilder() .add("first_name", "James") .add("last_name", "Rorrison") .add("email", "[email protected]") .add("phoneNumber", "+44 1234 1234") ) .build();

Slide 79

Slide 79 text

79 #41: JSON-P: JsonParser Event-based parser that can read JSON data from a stream JsonParser parser = Json.createParser(new FileReader(“order.json")); while (parser.hasNext()) { JsonParser.Event event = parser.next(); if (event.equals(JsonParser.Event.KEY_NAME) && parser.getString().matches("email")) { parser.next(); email = parser.getString(); } }

Slide 80

Slide 80 text

80 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 Batch 1.0 (JSR 352)

Slide 81

Slide 81 text

81 #42: Batch: Chunk-style Processing Item-oriented Processing Style (primary)

Slide 82

Slide 82 text

82 #42: Batch: Chunk-style Processing …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 }

Slide 83

Slide 83 text

83 #43: Batch: Batchlet-style Processing Task-oriented processing style …implements Batchlet { @Override public void process() { // Transfer file }

Slide 84

Slide 84 text

84 #44: Batch: Job/Step/Chunk Listeners

Slide 85

Slide 85 text

85 #44: Batch: Job/Step/Chunk Listeners Interface Abstract Classes JobListener AbstractJobListener StepListener AbstractStepListener ChunkListener AbstractChunkListener ItemRead/Write/ProcessL istener AbstractItemRead/Write/Proce ssListener SkipRead/Write/ProcessL istener AbstractSkipRead/Write/Proce ssListener RetryRead/Write/Process Listener AbstractRetryRead/Write/Proc essListener

Slide 86

Slide 86 text

86 #44: Batch: Job/Step/Chunk Listeners @Named public class MyJobListener extends AbstractJobListener { @Override public void beforeJob() throws Exception { . . . } @Override public void afterJob() throws Exception { . . . } }

Slide 87

Slide 87 text

87 #45: Batch: Partition . . .

Slide 88

Slide 88 text

88 #45: Batch: Partition

Slide 89

Slide 89 text

89 #46: Batch: Creating Workflows . . . . . . . . . Flow: Elements that execute together as a unit

Slide 90

Slide 90 text

90 #46: Batch: Creating Workflows . . . . . . Split: Concurrent execution of flows

Slide 91

Slide 91 text

91 #46: Batch: Creating Workflows . . . . . . Decision: Customized way of sequencing between steps, flows, splits @Named public class MyDecider implements Decider { @Override public String decide(StepExecution[] ses) throws Exception { . . . return "DATA_LOADED"; // or "NOT_LOADED" } }

Slide 92

Slide 92 text

92 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 JavaMail 1.5 (JSR 919)

Slide 93

Slide 93 text

93 #47: JavaMail @MailSessionDefinition(name = "java:comp/myMailSession", properties = { "mail.smtp.host=smtp.gmail.com", "mail.smtp.ssl.enable=true", "mail.smtp.auth=true", "mail.transport.protocol=smtp", "mail.debug=true" }) @Resource(lookup = "java:comp/myMailSession") Session session;

Slide 94

Slide 94 text

94 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 JCA 1.7 (JSR 322)

Slide 95

Slide 95 text

95 #48: Java Connector Architecture @ConnectionDefinition( connection="MyConnection.class", connectionImpl="MyConnectionImpl.class", connectionFactory="MyConnectionFactory.class", connectionFactoryImpl="MyConnectionFactoryImpl.class" ) @AdministeredObjectDefinition( className="MyQueueImpl.class", name="java:comp/MyQueue", resourceAdapter="myAdapter", )

Slide 96

Slide 96 text

96 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0 Servlet 3.1 JSF 2.2 EL 3.0 JSP JSTL Bean Validation 1.1 Interceptors 1.2 CDI 1.1 Concurrency 1.0 JPA 2.1 JTA 1.2 EJB 3.2 JMS 2.0 Batch 1.0 JCA 1.7 Java EE 7 JavaMail 1.5 Java EE 7 (JSR 342)

Slide 97

Slide 97 text

97 #49: Default Resources JNDI name: java:comp/DefaultDataSource Default Data Source @Resource(lookup="java:comp/DefaultDataSource") DataSource myDS; @Resource DataSource myDS;

Slide 98

Slide 98 text

98 #49: Default Resources JNDI name: java:comp/DefaultJMSConnectionFactory @Resource(lookup="java:comp/DefaultJMSConnectionFactory") ConnectionFactory myCF; @Resource ConnectionFactory myCF; Default JMS Connection Factory

Slide 99

Slide 99 text

99 #49: Default Resources JNDI names java:comp/DefaultManagedExecutorService java:comp/DefaultManagedScheduledExecutorS ervice java:comp/DefaultManagedThreadFactory java:comp/DefaultContextService Default Concurrency Utilities Objects

Slide 100

Slide 100 text

100 #50: Buy the books!

Slide 101

Slide 101 text

101 #50.1: Virtal:JBUG http://www.meetup.com/JBoss-User-Group-Worldwide/ Testing the Enterprise layers, with Arquillian Aslak Knutsen 21. October 6PM BST / 5PM UTC / 1PM EDT / 10 AM PDT

Slide 102

Slide 102 text

102 #50.2: References Java EE Samples Project: https://github.com/javaee-samples/javaee7-samples Ticket-Monster Examples Applications (EE 6!): https://github.com/jboss-developer/ticket- monster/tree/2.6.0.Final-with-tutorials http://www.jboss.org/ticket-monster/

Slide 103

Slide 103 text

103 http://www.wildfly.org #50.3: Get started today!

Slide 104

Slide 104 text

104 http://www.jboss.org/products/eap/get-started/  Version 6.3.0.GA  Java EE 6 certified  Support Subscription available  For commercial use #50.4: Fully supported!

Slide 105

Slide 105 text

105 https://www.openshift.com/app/account/new