Java EE 7 : What’s new in the Java EE Platform Arun Gupta Antonio Goncalves #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 CDI 1.1 (JSR 346) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
Default enabling Finer scanning control •  Possible values: all, annotated, none •  all behaves like in Java EE 6 (default if not set) <beans ... version="1.1" bean-discovery-mode="all">! <alternatives>! <class>org.agoncal.book.MockGenerator</class>! </alternatives>! </beans>! #DV13-UniJavaEE7 @arungupta @agoncal
@Vetoed Veto the processing of the class or package @Vetoed! public class NonProcessedBean {
 ...! }! ! package-info.java! @Vetoed! package com.non.processed.package;! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 Bean Validation 1.1 (JSR 349) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
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());! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
CDI in validators Injection in validators is now possible public class ZipCodeValidator implements! ConstraintValidator<ZipCode, String> {! ! @Inject @USA! ZipCodeChecker checker = new ZipCodeChecker();! ! public boolean isValid(String value,! ConstraintValidatorContext context) {! ! return checker.isZipCodeValid(value);! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 Interceptors 1.2 (JSR 318) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
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) ... {! // ...! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
@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! ...! }! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 Concurrency utilities 1.0 (JSR 236) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
ManagedExecutor Threads in Java EE •  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 #DV13-UniJavaEE7 package @arungupta @agoncal
ManagedExecutor Default ManagedExectuor @Resource
 ManagedExecutorService executor;
 ! 
 ManagedExecutorService executor = (ManagedExecutorService) ! ctx.lookup("java:comp/DefaultManagedExecutorService");! #DV13-UniJavaEE7 @arungupta @agoncal
ManagedExecutor Specify in web.xml <web-app … version="3.1">! <resource-env-ref>! <resource-env-ref-name>! concurrent/myExecutor! </resource-env-ref-name>! <resource-env-ref-type>! javax.enterprise.concurrent.ManagedExecutorService! </resource-env-ref-type>! </resource-env-ref>! </web-app>! #DV13-UniJavaEE7 @arungupta @agoncal
ManagedScheduledExecutor Thread Scheduler in Java EE •  Managed version of ScheduledExecutorService •  Submit delayed or periodic tasks @Resource
 ManagedScheduledExecutorService executor;! #DV13-UniJavaEE7 @arungupta @agoncal
ManagedScheduledExecutor Access using JNDI •  Can be defined in web.xml as well InitialContext ctx = new InitialContext(); 
 
 ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService)ctx.lookup(
 "java:comp/DefaultManagedScheduledExecutorService");
 ! #DV13-UniJavaEE7 @arungupta @agoncal
ManagedScheduledExecutor Samples executor.schedule(new MyCallableTask(), 5, TimeUnit.SECONDS);! ! executor.scheduleAtFixedRate(new MyRunnableTask(), 2, 3,! TimeUnit.SECONDS);! ! executor.scheduleWithFixedDelay(new MyRunnableTask(), 2, 3,! TimeUnit.SECONDS);! ! #DV13-UniJavaEE7 @arungupta @agoncal
ManagedThreadFactory Extends ThreadFactory @Resource(name = DefaultManagedThreadFactory)
 ManagedThreadFactory factory; ManagedThreadFactory factory = (ManagedThreadFactory) ctx.lookup(java:comp/DefaultManagedThreadFactory);
 ! #DV13-UniJavaEE7 @arungupta @agoncal
ManagedThreadFactory Extends ThreadFactory Thread thread = factory.newThread(new MyTask());
 
 ! ((ManageableThread)thread).isShutdown();
 
 ! #DV13-UniJavaEE7 @arungupta @agoncal
DynamicProxy Dynamic proxies •  Create dynamic proxy objects, adds contextual information •  available for applications running in Java EE environment Classloading, JNDI, Security, … #DV13-UniJavaEE7 @arungupta @agoncal
DynamicProxy Create contextual proxies @Resource
 ContextService service;
 
 
 Runnable proxy = service.createContextualProxy(! new MyRunnable(), Runnable.class);
 
 
 Future f = executor.submit(proxy);! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 JPA 2.1 (JSR 338) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
Schema Generation Standardized database schema generation persistence ... version=2.1! persistence-unit ...! properties! property name=javax.persistence.schema-generation.scripts.action! value=drop-and-create/! property name=javax.persistence.schema-generation.scripts.create-target value=create.sql/! property name=javax.persistence.sql-load-script-source ! value=insert.sql/! /properties! /persistence-unit! #DV13-UniJavaEE7 @arungupta @agoncal
@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;! ...! }! #DV13-UniJavaEE7 @arungupta @agoncal
Unsynchronized Persistence Context Persistence context not enlisted in any tx unless explicitly joined @PersistenceContext(synchronization =! SynchronizationType.UNSYNCHRONIZED)! private EntityManager em;! ...! ! em.persist(book);! ! ...! em.joinTransaction();! ! #DV13-UniJavaEE7 @arungupta @agoncal
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 {...}! #DV13-UniJavaEE7 @arungupta @agoncal
CDI in listeners Injection is now possible into event listeners public class AgeCalculationListener {! ! @Inject! private AgeCalculator ageCalculator;! ! @PostLoad! @PostPersist! @PostUpdate! public void calculateAge(Customer c) {! customer.setAge(ageCalculator.calc(c.getBirth));! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
Converters Classes that convert between database and attributes @Converter! public class CreditCardEnumConverter implements! AttributeConverterCreditCard, String {! ! public String convertToDatabaseColumn(CreditCard attr) {...}! public CreditCard convertToEntityAttribute(String data){...}! }! ! @Entity! public class Order {! ! @Convert(converter = CreditCardEnumConverter.class)! private CreditCard creditCard;! }! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 JTA 1.2 (JSR 907) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
@Transactional TX 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) {...}! }! #DV13-UniJavaEE7 @arungupta @agoncal
@TransactionScoped CDI scope whose lifecycle is scoped to the currently active JTA tx @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(); }}! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 EJB 3.2 (JSR 345) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
Disable passivation of stateful In some cases increases performance, scalability and robustness @Stateful(passivationCapable = false)! public class ShoppingCart {! ...! }! #DV13-UniJavaEE7 @arungupta @agoncal
EJB-Lite: Async + Non-persistent timer EJB Lite includes async invocations and non-persistent EJB Timer @Stateless! public class OrderEJB {! ! @Asynchronous! public void sendEmail (Order order) {! // Very Long task! }! ! @Schedule(hour=2, persistent=false)! public void createDailyReport() {! // ...! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 JMS 2.0 (JSR 343) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
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);! #DV13-UniJavaEE7 @arungupta @agoncal
Runtime Exceptions A set of new unchecked exceptions have been created RuntimeException! JMSRuntimeException! IllegalStateRuntimeException! InvalidClientIDRuntimeException! InvalidDestinationRuntimeException! InvalidSelectorRuntimeException! JMSSecurityRuntimeException! MessageFormatRuntimeException! MessageNotWriteableRuntimeException! ResourceAllocationRuntimeException! TransactionInProgressRuntimeException! TransactionRolledBackRuntimeException! #DV13-UniJavaEE7 @arungupta @agoncal
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(q).receiveBody(String.class);! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
JMSConnectionFactoryDefinition ConnectionFactory can be defined using an annotation @Stateless! @JMSConnectionFactoryDefinition(! name = java:app/jms/MyConnectionFactory,! interfaceName = javax.jms.TopicConnectionFactory)! ! ! ! public class ExpensiveOrderEJB {...}! #DV13-UniJavaEE7 @arungupta @agoncal
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 {...}! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 Servlet 3.1 (JSR 340) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
Non-blocking I/O Non-blocking I/O in Servlets 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) {
 . . .
 }
 }
 }! #DV13-UniJavaEE7 @arungupta @agoncal
Non-blocking I/O New methods to existing interfaces •  ServletInputStream •  public •  public •  public void setReadListener(ReadListener l); boolean isFinished(); boolean isReady(); •  public •  public setWriteListener(WriteListener l); boolean canWrite(); •  ServletOutputStream #DV13-UniJavaEE7 @arungupta @agoncal
Non-blocking I/O New interfaces public interface ReadListener extends EventListener {
 public void onDataAvailable();
 public void onAllDataRead();
 public void onError();
 }! public interface WriteListener extends EventListener {
 public void onWritePossible();
 public void onError();
 }! #DV13-UniJavaEE7 @arungupta @agoncal
Non-blocking I/O Only for Asynchronous Servlets AsyncContext context = request.startAsync();
 ServletInputStream input = request.getInputStream();
 input.setReadListener(new MyReadListener(input, context)); ! #DV13-UniJavaEE7 @arungupta @agoncal
Protocol Upgrade New interface •  T •  extends HttpUpgradeHandler T HttpServletRequest.upgrade(ClassT class) throws IOException; HttpUpgradeHandler •  init(WebConnection •  destroy(); #DV13-UniJavaEE7 wc); @arungupta @agoncal
Protocol Upgrade New interface public interface WebConnection {
 ServletInputStream getInputStream();
 ServletOutputStream getOutputStream();
 }! #DV13-UniJavaEE7 @arungupta @agoncal
Improved Security Deny an HTTP method request for an uncovered HTTP method web-app . . . version=3.1 
 web-resource-collection
 url-pattern/account/*/url-pattern 
 http-methodGET/http-method
 /web-resource-collection
 /web-app ! ! #DV13-UniJavaEE7 @arungupta @agoncal
Improved Security Deny an HTTP method request for an uncovered HTTP method web-app . . . version=3.1 
 deny-uncovered-http-methods/
 web-resource-collection
 url-pattern/account/*/url-pattern 
 http-methodGET/http-method
 /web-resource-collection
 /web-app ! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 Web Socket 1.0 (JSR 356) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
Annotated server endpoint 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);! }
 }
 }! #DV13-UniJavaEE7 @arungupta @agoncal
Lifecycle callbacks Connection lifecycle @javax.websocket.OnOpen
 public void open(Session s) { . . . }
 
 @javax.websocket.OnClose
 public void close(CloseReason c) { . . . }
 
 @javax.websocket.OnError
 public void error(Throwable t) { . . . }! #DV13-UniJavaEE7 @arungupta @agoncal
Annotated client endpoint Full-duplex bi-directional communication over single TCP connection @javax.websocket.ClientEndpoint
 public class MyClient {
 @javax.websocket.OnOpen
 public void open(Session session) { … }
 
 // Lifecycle callbacks
 }! #DV13-UniJavaEE7 @arungupta @agoncal
Annotated client endpoint Full-duplex bi-directional communication over single TCP connection ContainerProvider
 .getWebSocketContainer()
 .connectToServer(
 MyClient.class, 
 URI.create(ws://. . .));! ! #DV13-UniJavaEE7 @arungupta @agoncal
Programmatic endpoints API of rendpoints public class ChatServer extends Endpoint {
 @Override
 public void onOpen(Session s, EndpointConfig ec) {
 s.addMessageHandler(new MessageHandler.WholeString() {
 public void onMessage(String text) { . . . }
 }
 }
 
 @Override
 public void onClose(Session s, CloseReason cr) { . . . }
 
 //. . . 
 }! #DV13-UniJavaEE7 @arungupta @agoncal
Programmatic endpoints API of rendpoints public class MyApplicationConfig implements ServerApplicationConfig {
 public SetServerEndpointConfig getEndpointConfigs(…) { ServerEndpointConfig.Builder
 .create(MyEndpoint.class, /websocket”)
 .configurator(new MyConfig())
 .build()
 }
 }! #DV13-UniJavaEE7 
 @arungupta @agoncal
Programmatic endpoints API of rendpoints public class MyConfig extends ServerEndpointConfig.Configurator{
 
 public T T getEndpointInstance(. . .) { . . . }
 
 public void modifyHandshake(. . .) { . . . }
 
 . . .
 }! #DV13-UniJavaEE7 @arungupta @agoncal
Encoder and Decoder Encodes and decodes messages @javax.websocket.server.ServerEndpoint(
 value=/chat,
 decoders=MyDecoder.class,
 encoders=MyEncoder.class)
 public class ChatServer {
 
 @OnMessage
 public String chat(ChatMessage name, Session session) {
 . . . 
 }
 }! #DV13-UniJavaEE7 @arungupta @agoncal
Encoder and Decoder Encodes and decodes messages public class MyDecoder implements Decoder.TextChatMessage {
 public ChatMessage decode(String s) {
 // . . .
 }
 
 public boolean willDecode(String string) {
 // . . .
 }
 
 //. . .
 }! #DV13-UniJavaEE7 @arungupta @agoncal
Encoder and Decoder Encodes and decodes messages public class MyEncoder implements Encoder.TextChatMessage {
 
 public String encode(ChatMessage chatMessage) {
 // . . .
 }
 ! // . . .
 }! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 Expression Language 3.0 (JSR 341) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
ELProcessor Use EL in a stand-alone environment ELProcessor el = new ELProcessor();! ! assert ((Integer)el.eval(a = [1, 2]; a[1])) == 2;! ! el.defineBean(employee, new Employee(John));! assert (el.eval(employee.name)).equals(John);! ! #DV13-UniJavaEE7 @arungupta @agoncal
Lambda expression Use lambdas before Java SE 8 ELProcessor el = new ELProcessor();! ! assert ((Integer)(el.eval(((x,y) - x+y)(4, 5)))) == 9;! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 JSF 2.2 (JSR 344) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
Faces Flow Package reusable flows in JAR ./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! #DV13-UniJavaEE7 @arungupta @agoncal
Faces Flow Use annotations Named
 @FlowScoped(flow1)
 public class Flow1Bean implements Serializable {
 }! ! @Produces @FlowDefinition
 public Flow defineFlow(@FlowBuilderParameter FlowBuilder fb) {
 String flowId = flow1;
 //. . .
 return fb.getFlow();
 }! #DV13-UniJavaEE7 @arungupta @agoncal
Faces Flow Use flows in EL #{flowScope}: Local flow storage
 
 #{facesContext.application.flowHandler.currentFlow}: Returns ! true if within a flow! #DV13-UniJavaEE7 @arungupta @agoncal
Resource Library Contract Apply templates in a reusable and interchangeable manner 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! #DV13-UniJavaEE7 @arungupta @agoncal
Resource Library Contract Apply templates in a reusable and interchangeable manner f:view contracts=”red”
 ui:composition template=/template.xhtml
 . . .
 /ui:composition
 /f:view
 ! #DV13-UniJavaEE7 @arungupta @agoncal
Pass-through Attributes HTML5-Friendly Markup h:inputText type=email value=#{user.email}/ 
 ! input type=text name=j_idt6:j_idt10/! ! ! h:inputText p:type=email value=#{user.email}/ 
 
 input type=email name=j_idt6:j_idt10/! #DV13-UniJavaEE7 @arungupta @agoncal
File Upload Component Upload files h:form enctype=multipart/form-data
 h:inputFile value=#{fileUploadBean.file}/
 h:commandButton value=Upload/
 /h:form ! ! ! @Named @RequestScoped 
 public class FileUploadBean {
 private Part file;
 
 //getter and setter
 } ! ! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 JAX-RS 2.0 (JSR 339) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
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).get();! 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);! #DV13-UniJavaEE7 @arungupta @agoncal
Async client The client API also supports asynchronous invocation FutureString 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){! ...! }! #DV13-UniJavaEE7 @arungupta @agoncal
Async server Asynchronous request processing on the server @Path(/async)! public class AsyncResource {! ! @GET! public void asyncGet(@Suspended AsyncResponse resp){! ! new Thread(new Runnable() {! ! public void run() {! String result = veryExpensiveOperation();! resp.resume(result);! }! }).start();! }}! #DV13-UniJavaEE7 @arungupta @agoncal
Message Filter Process incoming/outgoing request/response headers •  Filters on client side •  javax.ws.rs.client.ClientRequestFilter •  javax.ws.rs.client.ClientResponseFilter •  Filters on server side •  javax.ws.rs.container.ContainerRequestFilter •  javax.ws.rs.container.ContainerResponseFilter #DV13-UniJavaEE7 @arungupta @agoncal
Message Filter Process incoming/outgoing request/response headers public class LogginFilter implements ClientRequestFilter{! ! public void filter(ClientRequestContext ctx) ... {! System.out.println(ctx.getMethod());! System.out.println(ctx.getUri());! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
Entity Interceptors Marshalling and unmarshalling HTTP message bodies •  Intercepts inbound stream (read from the “wire”) •  javax.ws.rs.ext.ReaderInterceptor •  Intercepts outbound stream (written to the “wire”) •  javax.ws.rs.ext.WriterInterceptor #DV13-UniJavaEE7 @arungupta @agoncal
Entity Interceptors Marshalling and unmarshalling HTTP message bodies public class ZipInterceptor implements WriterInterceptor{! ! public void aroundWriteTo(WriterInterceptorContext ctx){! OutputStream os = ctx.getOutputStream();! ctx.setOutputStream(new GZIPOutputStream(os));! ctx.proceed();! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 JSON-P 1.0 (JSR 353) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
JSON Builder Builds an object model 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, j.rorri@me.com)! .add(phoneNumber, +44 1234 1234)! )! .build();! #DV13-UniJavaEE7 @arungupta @agoncal
JSON Parser Event-based parser reading 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();! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 Batch 1.0 (JSR 352) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
Chunk-style Processing Item-oriented Processing Style (primary) #DV13-UniJavaEE7 @arungupta @agoncal
Chunk-style Processing Item-oriented Processing Style (primary) 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! }! #DV13-UniJavaEE7 @arungupta @agoncal
Batchlet-style Processing Task-oriented processing style step id=”transferFile”! batchlet ref=“MyFileTransfer” /! /step! …implements Batchlet {! @Override
 public void process() {
 // Transfer file! }! #DV13-UniJavaEE7 @arungupta @agoncal
Job/Step/Chunk Listeners Listeners job id=myJob xmlns=http://xmlns.jcp.org/xml/ns/javaee ...
 listeners
 listener ref=myJobListener/
 /listeners
 step id=myStep 
 listeners
 listener ref=myStepListener/
 listener ref=myChunkListener/
 listener ref=myItemReadListener/
 listener ref=myItemProcessorListener/
 listener ref=myItemWriteListener/
 /listeners
 chunk item-count=3”. . ./chunk
 /step
 /job! ! #DV13-UniJavaEE7 @arungupta @agoncal
Job/Step/Chunk Listeners Listeners Interface Abstract Classes JobListener! AbstractJobListener! StepListener! AbstractStepListener! ChunkListener! AbstractChunkListener! ItemRead/Write/ProcessListener! AbstractItemRead/Write/ProcessListener! SkipRead/Write/ProcessListener! AbstractSkipRead/Write/ProcessListener! RetryRead/Write/ProcessListener! AbstractRetryRead/Write/ProcessListener! #DV13-UniJavaEE7 @arungupta @agoncal
Job/Step/Chunk Listeners Listeners @Named
 public class MyJobListener extends AbstractJobListener {
 
 @Override
 public void beforeJob() throws Exception { . . . }
 
 @Override
 public void afterJob() throws Exception { . . . }
 }! #DV13-UniJavaEE7 @arungupta @agoncal
Partition Partitioning step
 chunk item-count=3
 reader ref=myItemReader
 properties
 property name=start value=#{partitionPlan['start']}/
 property name=end value=#{partitionPlan['end']}/
 /properties 
 /reader
 . . .
 /chunk! #DV13-UniJavaEE7 @arungupta @agoncal
Partition Partitioning partition
 plan partitions=2
 properties partition=0
 property name=start value=1/
 property name=end value=10/
 /properties
 properties partition=1
 property name=start value=11/
 property name=end value=20/
 /properties
 /plan
 /partition
 /step! #DV13-UniJavaEE7 @arungupta @agoncal
Creating Workflows Flow: Elements that execute together as a unit flow id=flow1 next=step3
 step id=step1 next=step2 . . . /step
 step id=step2 . . . /step
 /flow
 step id=step3 . . . /step! #DV13-UniJavaEE7 @arungupta @agoncal
Creating Workflows Split: Concurrent execution of flows split id=split1 next= . . . 
 flow id=flow1”
 step id=step1” . . . /step
 /flow
 flow id=flow2”
 step id=step2” . . . /step
 /flow
 /split! #DV13-UniJavaEE7 @arungupta @agoncal
Creating Workflows Decision: Customized way of sequencing between steps, flows, splits step id=step1 next=decider1. . ./step
 decision id=decider1 ref=myDecider 
 next on=DATA_LOADED to=step2/ 
 end on=NOT_LOADED/ /decision
 step id=step2. . ./step ! ! @Named
 public class MyDecider implements Decider {
 @Override
 public String decide(StepExecution[] ses) throws Exception {
 . . .
 return DATA_LOADED; // or NOT_LOADED! } ! }! ! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 JavaMail 1.5 (JSR 919) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
MailSessionDefinition A mail session can be defined using an annotation @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;! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 JCA 1.7 (JSR 322) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
Connector definition A connector can be defined using an annotation @ConnectionDefinition(! connection=MyConnection.class,! connectionImpl=MyConnectionImpl.class,! connectionFactory=MyConnectionFactory.class,! connectionFactoryImpl=MyConnectionFactoryImpl.class! )! ! @AdministeredObjectDefinition(! className=MyQueueImpl.class,! name=java:comp/MyQueue,! resourceAdapter=myAdapter,! )! #DV13-UniJavaEE7 @arungupta @agoncal
CDI 1.1 Bean Validation 1.1 Interceptors 1.2 Concurrency 1.0 Java EE 7 (JSR 342) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
Default Resources Default datasource @Resource(lookup=java:comp/DefaultDataSource)! private DataSource myDS;! ! @Resource! private DataSource myDS; ! #DV13-UniJavaEE7 @arungupta @agoncal
Default Resources Default JMS factory @Resource(lookup=java:comp/DefaultJMSConnectionFactory) ! private ConnectionFactory myCF; ! ! @Resource! private ConnectionFactory myCF;! #DV13-UniJavaEE7 @arungupta @agoncal
Default Resources Default Concurrency Utilities objects @Resource(lookup=java:comp/DefaultManagedExecutorService) ! private ManagedExecutorService mes; ! @Resource(lookup=java:comp/DefaultManagedScheduledExecutorService) ! private ManagedScheduledExecutorService mses; ! @Resource(lookup=java:comp/DefaultManagedThreadFactory) ! private ManagedThreadFactory mtf; ! @Resource(lookup=java:comp/DefaultContextService) ! private ContextService cs; ! ! @Resource! private ManagedExecutorService mes; ! @Resource! private ManagedScheduledExecutorService mses; ! @Resource! private ManagedThreadFactory mtf; ! @Resource! private ContextService cs; ! #DV13-UniJavaEE7 @arungupta @agoncal
New namespaces Bye bye Sun persistence xmlns=http://xmlns.jcp.org/xml/ns/persistence! xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance! xsi:schemaLocation=http://xmlns.jcp.org/xml/ns/persistence ! http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd! version=2.1! ! web-app xmlns=http://xmlns.jcp.org/xml/ns/javaee! xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance! xsi:schemaLocation=http://xmlns.jcp.org/xml/ns/javaee ! http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd! version=3.1! ! #DV13-UniJavaEE7 @arungupta @agoncal
Buy our books! #DV13-UniJavaEE7 @arungupta @agoncal
Q/A #DV13-UniJavaEE7 @arungupta @agoncal
Thank you Arun Gupta Antonio Goncalves #DV13-UniJavaEE7 @arungupta @agoncal

Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013

  • 1.
    Java EE 7: What’s new in the Java EE Platform Arun Gupta Antonio Goncalves #DV13-UniJavaEE7 @arungupta @agoncal
  • 2.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 3.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 CDI 1.1 (JSR 346) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 4.
    Default enabling Finer scanningcontrol •  Possible values: all, annotated, none •  all behaves like in Java EE 6 (default if not set) <beans ... version="1.1" bean-discovery-mode="all">! <alternatives>! <class>org.agoncal.book.MockGenerator</class>! </alternatives>! </beans>! #DV13-UniJavaEE7 @arungupta @agoncal
  • 5.
    @Vetoed Veto the processingof the class or package @Vetoed! public class NonProcessedBean {
 ...! }! ! package-info.java! @Vetoed! package com.non.processed.package;! #DV13-UniJavaEE7 @arungupta @agoncal
  • 6.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 Bean Validation 1.1 (JSR 349) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 7.
    Method validation Pre/post conditionson 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());! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 8.
    CDI in validators Injectionin validators is now possible public class ZipCodeValidator implements! ConstraintValidator<ZipCode, String> {! ! @Inject @USA! ZipCodeChecker checker = new ZipCodeChecker();! ! public boolean isValid(String value,! ConstraintValidatorContext context) {! ! return checker.isZipCodeValid(value);! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 9.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 Interceptors 1.2 (JSR 318) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 10.
    AroundConstruct Interceptor associated witha 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) ... {! // ...! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 11.
    @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! ...! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 12.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 Concurrency utilities 1.0 (JSR 236) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 13.
    ManagedExecutor Threads in JavaEE •  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 #DV13-UniJavaEE7 package @arungupta @agoncal
  • 14.
    ManagedExecutor Default ManagedExectuor @Resource
 ManagedExecutorService executor;
 ! 
 ManagedExecutorServiceexecutor = (ManagedExecutorService) ! ctx.lookup("java:comp/DefaultManagedExecutorService");! #DV13-UniJavaEE7 @arungupta @agoncal
  • 15.
    ManagedExecutor Specify in web.xml <web-app… version="3.1">! <resource-env-ref>! <resource-env-ref-name>! concurrent/myExecutor! </resource-env-ref-name>! <resource-env-ref-type>! javax.enterprise.concurrent.ManagedExecutorService! </resource-env-ref-type>! </resource-env-ref>! </web-app>! #DV13-UniJavaEE7 @arungupta @agoncal
  • 16.
    ManagedScheduledExecutor Thread Scheduler inJava EE •  Managed version of ScheduledExecutorService •  Submit delayed or periodic tasks @Resource
 ManagedScheduledExecutorService executor;! #DV13-UniJavaEE7 @arungupta @agoncal
  • 17.
    ManagedScheduledExecutor Access using JNDI • Can be defined in web.xml as well InitialContext ctx = new InitialContext(); 
 
 ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService)ctx.lookup(
 "java:comp/DefaultManagedScheduledExecutorService");
 ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 18.
    ManagedScheduledExecutor Samples executor.schedule(new MyCallableTask(), 5,TimeUnit.SECONDS);! ! executor.scheduleAtFixedRate(new MyRunnableTask(), 2, 3,! TimeUnit.SECONDS);! ! executor.scheduleWithFixedDelay(new MyRunnableTask(), 2, 3,! TimeUnit.SECONDS);! ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 19.
    ManagedThreadFactory Extends ThreadFactory @Resource(name= DefaultManagedThreadFactory)
 ManagedThreadFactory factory; ManagedThreadFactory factory = (ManagedThreadFactory) ctx.lookup(java:comp/DefaultManagedThreadFactory);
 ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 20.
    ManagedThreadFactory Extends ThreadFactory Threadthread = factory.newThread(new MyTask());
 
 ! ((ManageableThread)thread).isShutdown();
 
 ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 21.
    DynamicProxy Dynamic proxies •  Createdynamic proxy objects, adds contextual information •  available for applications running in Java EE environment Classloading, JNDI, Security, … #DV13-UniJavaEE7 @arungupta @agoncal
  • 22.
    DynamicProxy Create contextual proxies @Resource
 ContextServiceservice;
 
 
 Runnable proxy = service.createContextualProxy(! new MyRunnable(), Runnable.class);
 
 
 Future f = executor.submit(proxy);! #DV13-UniJavaEE7 @arungupta @agoncal
  • 23.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 JPA 2.1 (JSR 338) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 24.
    Schema Generation Standardized databaseschema generation persistence ... version=2.1! persistence-unit ...! properties! property name=javax.persistence.schema-generation.scripts.action! value=drop-and-create/! property name=javax.persistence.schema-generation.scripts.create-target value=create.sql/! property name=javax.persistence.sql-load-script-source ! value=insert.sql/! /properties! /persistence-unit! #DV13-UniJavaEE7 @arungupta @agoncal
  • 25.
    @Index Defines additional indexesin 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;! ...! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 26.
    Unsynchronized Persistence Context Persistencecontext not enlisted in any tx unless explicitly joined @PersistenceContext(synchronization =! SynchronizationType.UNSYNCHRONIZED)! private EntityManager em;! ...! ! em.persist(book);! ! ...! em.joinTransaction();! ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 27.
    Stored Procedure Calling astored 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 {...}! #DV13-UniJavaEE7 @arungupta @agoncal
  • 28.
    CDI in listeners Injectionis now possible into event listeners public class AgeCalculationListener {! ! @Inject! private AgeCalculator ageCalculator;! ! @PostLoad! @PostPersist! @PostUpdate! public void calculateAge(Customer c) {! customer.setAge(ageCalculator.calc(c.getBirth));! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 29.
    Converters Classes that convertbetween database and attributes @Converter! public class CreditCardEnumConverter implements! AttributeConverterCreditCard, String {! ! public String convertToDatabaseColumn(CreditCard attr) {...}! public CreditCard convertToEntityAttribute(String data){...}! }! ! @Entity! public class Order {! ! @Convert(converter = CreditCardEnumConverter.class)! private CreditCard creditCard;! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 30.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 JTA 1.2 (JSR 907) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 31.
    @Transactional TX management onManaged 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) {...}! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 32.
    @TransactionScoped CDI scope whoselifecycle is scoped to the currently active JTA tx @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(); }}! #DV13-UniJavaEE7 @arungupta @agoncal
  • 33.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 EJB 3.2 (JSR 345) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 34.
    Disable passivation ofstateful In some cases increases performance, scalability and robustness @Stateful(passivationCapable = false)! public class ShoppingCart {! ...! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 35.
    EJB-Lite: Async +Non-persistent timer EJB Lite includes async invocations and non-persistent EJB Timer @Stateless! public class OrderEJB {! ! @Asynchronous! public void sendEmail (Order order) {! // Very Long task! }! ! @Schedule(hour=2, persistent=false)! public void createDailyReport() {! // ...! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 36.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 JMS 2.0 (JSR 343) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 37.
    JMSContext API New simplifiedAPI 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);! #DV13-UniJavaEE7 @arungupta @agoncal
  • 38.
    Runtime Exceptions A setof new unchecked exceptions have been created RuntimeException! JMSRuntimeException! IllegalStateRuntimeException! InvalidClientIDRuntimeException! InvalidDestinationRuntimeException! InvalidSelectorRuntimeException! JMSSecurityRuntimeException! MessageFormatRuntimeException! MessageNotWriteableRuntimeException! ResourceAllocationRuntimeException! TransactionInProgressRuntimeException! TransactionRolledBackRuntimeException! #DV13-UniJavaEE7 @arungupta @agoncal
  • 39.
    Autocloseable Several JMS interfacesimplement Autocloseable try (JMSContext ctx = connectionFactory.createContext()) {! ctx.createProducer().send(queue, Text message sent);! }! ! ...! ! try (JMSContext ctx = connectionFactory.createContext()) {! while (true) { ! String s =ctx.createConsumer(q).receiveBody(String.class);! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 40.
    JMSConnectionFactoryDefinition ConnectionFactory can bedefined using an annotation @Stateless! @JMSConnectionFactoryDefinition(! name = java:app/jms/MyConnectionFactory,! interfaceName = javax.jms.TopicConnectionFactory)! ! ! ! public class ExpensiveOrderEJB {...}! #DV13-UniJavaEE7 @arungupta @agoncal
  • 41.
    JMSDestinationDefinition A JMS queueor 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 {...}! #DV13-UniJavaEE7 @arungupta @agoncal
  • 42.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 Servlet 3.1 (JSR 340) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 43.
    Non-blocking I/O Non-blocking I/Oin Servlets 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) {
 . . .
 }
 }
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 44.
    Non-blocking I/O New methodsto existing interfaces •  ServletInputStream •  public •  public •  public void setReadListener(ReadListener l); boolean isFinished(); boolean isReady(); •  public •  public setWriteListener(WriteListener l); boolean canWrite(); •  ServletOutputStream #DV13-UniJavaEE7 @arungupta @agoncal
  • 45.
    Non-blocking I/O New interfaces publicinterface ReadListener extends EventListener {
 public void onDataAvailable();
 public void onAllDataRead();
 public void onError();
 }! public interface WriteListener extends EventListener {
 public void onWritePossible();
 public void onError();
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 46.
    Non-blocking I/O Only forAsynchronous Servlets AsyncContext context = request.startAsync();
 ServletInputStream input = request.getInputStream();
 input.setReadListener(new MyReadListener(input, context)); ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 47.
    Protocol Upgrade New interface • T •  extends HttpUpgradeHandler T HttpServletRequest.upgrade(ClassT class) throws IOException; HttpUpgradeHandler •  init(WebConnection •  destroy(); #DV13-UniJavaEE7 wc); @arungupta @agoncal
  • 48.
    Protocol Upgrade New interface publicinterface WebConnection {
 ServletInputStream getInputStream();
 ServletOutputStream getOutputStream();
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 49.
    Improved Security Deny anHTTP method request for an uncovered HTTP method web-app . . . version=3.1 
 web-resource-collection
 url-pattern/account/*/url-pattern 
 http-methodGET/http-method
 /web-resource-collection
 /web-app ! ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 50.
    Improved Security Deny anHTTP method request for an uncovered HTTP method web-app . . . version=3.1 
 deny-uncovered-http-methods/
 web-resource-collection
 url-pattern/account/*/url-pattern 
 http-methodGET/http-method
 /web-resource-collection
 /web-app ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 51.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 Web Socket 1.0 (JSR 356) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 52.
    Annotated server endpoint Full-duplexbi-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);! }
 }
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 53.
    Lifecycle callbacks Connection lifecycle @javax.websocket.OnOpen
 publicvoid open(Session s) { . . . }
 
 @javax.websocket.OnClose
 public void close(CloseReason c) { . . . }
 
 @javax.websocket.OnError
 public void error(Throwable t) { . . . }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 54.
    Annotated client endpoint Full-duplexbi-directional communication over single TCP connection @javax.websocket.ClientEndpoint
 public class MyClient {
 @javax.websocket.OnOpen
 public void open(Session session) { … }
 
 // Lifecycle callbacks
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 55.
    Annotated client endpoint Full-duplexbi-directional communication over single TCP connection ContainerProvider
 .getWebSocketContainer()
 .connectToServer(
 MyClient.class, 
 URI.create(ws://. . .));! ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 56.
    Programmatic endpoints API ofrendpoints public class ChatServer extends Endpoint {
 @Override
 public void onOpen(Session s, EndpointConfig ec) {
 s.addMessageHandler(new MessageHandler.WholeString() {
 public void onMessage(String text) { . . . }
 }
 }
 
 @Override
 public void onClose(Session s, CloseReason cr) { . . . }
 
 //. . . 
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 57.
    Programmatic endpoints API ofrendpoints public class MyApplicationConfig implements ServerApplicationConfig {
 public SetServerEndpointConfig getEndpointConfigs(…) { ServerEndpointConfig.Builder
 .create(MyEndpoint.class, /websocket”)
 .configurator(new MyConfig())
 .build()
 }
 }! #DV13-UniJavaEE7 
 @arungupta @agoncal
  • 58.
    Programmatic endpoints API ofrendpoints public class MyConfig extends ServerEndpointConfig.Configurator{
 
 public T T getEndpointInstance(. . .) { . . . }
 
 public void modifyHandshake(. . .) { . . . }
 
 . . .
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 59.
    Encoder and Decoder Encodesand decodes messages @javax.websocket.server.ServerEndpoint(
 value=/chat,
 decoders=MyDecoder.class,
 encoders=MyEncoder.class)
 public class ChatServer {
 
 @OnMessage
 public String chat(ChatMessage name, Session session) {
 . . . 
 }
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 60.
    Encoder and Decoder Encodesand decodes messages public class MyDecoder implements Decoder.TextChatMessage {
 public ChatMessage decode(String s) {
 // . . .
 }
 
 public boolean willDecode(String string) {
 // . . .
 }
 
 //. . .
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 61.
    Encoder and Decoder Encodesand decodes messages public class MyEncoder implements Encoder.TextChatMessage {
 
 public String encode(ChatMessage chatMessage) {
 // . . .
 }
 ! // . . .
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 62.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 Expression Language 3.0 (JSR 341) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 63.
    ELProcessor Use EL ina stand-alone environment ELProcessor el = new ELProcessor();! ! assert ((Integer)el.eval(a = [1, 2]; a[1])) == 2;! ! el.defineBean(employee, new Employee(John));! assert (el.eval(employee.name)).equals(John);! ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 64.
    Lambda expression Use lambdasbefore Java SE 8 ELProcessor el = new ELProcessor();! ! assert ((Integer)(el.eval(((x,y) - x+y)(4, 5)))) == 9;! #DV13-UniJavaEE7 @arungupta @agoncal
  • 65.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 JSF 2.2 (JSR 344) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 66.
    Faces Flow Package reusableflows in JAR ./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! #DV13-UniJavaEE7 @arungupta @agoncal
  • 67.
    Faces Flow Use annotations Named
 @FlowScoped(flow1)
 publicclass Flow1Bean implements Serializable {
 }! ! @Produces @FlowDefinition
 public Flow defineFlow(@FlowBuilderParameter FlowBuilder fb) {
 String flowId = flow1;
 //. . .
 return fb.getFlow();
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 68.
    Faces Flow Use flowsin EL #{flowScope}: Local flow storage
 
 #{facesContext.application.flowHandler.currentFlow}: Returns ! true if within a flow! #DV13-UniJavaEE7 @arungupta @agoncal
  • 69.
    Resource Library Contract Applytemplates in a reusable and interchangeable manner 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! #DV13-UniJavaEE7 @arungupta @agoncal
  • 70.
    Resource Library Contract Applytemplates in a reusable and interchangeable manner f:view contracts=”red”
 ui:composition template=/template.xhtml
 . . .
 /ui:composition
 /f:view
 ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 71.
    Pass-through Attributes HTML5-Friendly Markup h:inputTexttype=email value=#{user.email}/ 
 ! input type=text name=j_idt6:j_idt10/! ! ! h:inputText p:type=email value=#{user.email}/ 
 
 input type=email name=j_idt6:j_idt10/! #DV13-UniJavaEE7 @arungupta @agoncal
  • 72.
    File Upload Component Uploadfiles h:form enctype=multipart/form-data
 h:inputFile value=#{fileUploadBean.file}/
 h:commandButton value=Upload/
 /h:form ! ! ! @Named @RequestScoped 
 public class FileUploadBean {
 private Part file;
 
 //getter and setter
 } ! ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 73.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 JAX-RS 2.0 (JSR 339) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 74.
    Client API New APIto consume rest services Client client = ClientBuilder.newClient();! WebTarget target = client.target(http://www.foo.com/book);! Invocation invocation = target.request(TEXT_PLAIN).get();! 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);! #DV13-UniJavaEE7 @arungupta @agoncal
  • 75.
    Async client The clientAPI also supports asynchronous invocation FutureString 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){! ...! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 76.
    Async server Asynchronous requestprocessing on the server @Path(/async)! public class AsyncResource {! ! @GET! public void asyncGet(@Suspended AsyncResponse resp){! ! new Thread(new Runnable() {! ! public void run() {! String result = veryExpensiveOperation();! resp.resume(result);! }! }).start();! }}! #DV13-UniJavaEE7 @arungupta @agoncal
  • 77.
    Message Filter Process incoming/outgoingrequest/response headers •  Filters on client side •  javax.ws.rs.client.ClientRequestFilter •  javax.ws.rs.client.ClientResponseFilter •  Filters on server side •  javax.ws.rs.container.ContainerRequestFilter •  javax.ws.rs.container.ContainerResponseFilter #DV13-UniJavaEE7 @arungupta @agoncal
  • 78.
    Message Filter Process incoming/outgoingrequest/response headers public class LogginFilter implements ClientRequestFilter{! ! public void filter(ClientRequestContext ctx) ... {! System.out.println(ctx.getMethod());! System.out.println(ctx.getUri());! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 79.
    Entity Interceptors Marshalling andunmarshalling HTTP message bodies •  Intercepts inbound stream (read from the “wire”) •  javax.ws.rs.ext.ReaderInterceptor •  Intercepts outbound stream (written to the “wire”) •  javax.ws.rs.ext.WriterInterceptor #DV13-UniJavaEE7 @arungupta @agoncal
  • 80.
    Entity Interceptors Marshalling andunmarshalling HTTP message bodies public class ZipInterceptor implements WriterInterceptor{! ! public void aroundWriteTo(WriterInterceptorContext ctx){! OutputStream os = ctx.getOutputStream();! ctx.setOutputStream(new GZIPOutputStream(os));! ctx.proceed();! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 81.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 JSON-P 1.0 (JSR 353) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 82.
    JSON Builder Builds anobject model 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, j.rorri@me.com)! .add(phoneNumber, +44 1234 1234)! )! .build();! #DV13-UniJavaEE7 @arungupta @agoncal
  • 83.
    JSON Parser Event-based parserreading 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();! }! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 84.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 Batch 1.0 (JSR 352) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 85.
    Chunk-style Processing Item-oriented ProcessingStyle (primary) #DV13-UniJavaEE7 @arungupta @agoncal
  • 86.
    Chunk-style Processing Item-oriented ProcessingStyle (primary) 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! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 87.
    Batchlet-style Processing Task-oriented processingstyle step id=”transferFile”! batchlet ref=“MyFileTransfer” /! /step! …implements Batchlet {! @Override
 public void process() {
 // Transfer file! }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 88.
    Job/Step/Chunk Listeners Listeners job id=myJobxmlns=http://xmlns.jcp.org/xml/ns/javaee ...
 listeners
 listener ref=myJobListener/
 /listeners
 step id=myStep 
 listeners
 listener ref=myStepListener/
 listener ref=myChunkListener/
 listener ref=myItemReadListener/
 listener ref=myItemProcessorListener/
 listener ref=myItemWriteListener/
 /listeners
 chunk item-count=3”. . ./chunk
 /step
 /job! ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 89.
  • 90.
    Job/Step/Chunk Listeners Listeners @Named
 public classMyJobListener extends AbstractJobListener {
 
 @Override
 public void beforeJob() throws Exception { . . . }
 
 @Override
 public void afterJob() throws Exception { . . . }
 }! #DV13-UniJavaEE7 @arungupta @agoncal
  • 91.
    Partition Partitioning step
 chunk item-count=3
 reader ref=myItemReader
 properties
 propertyname=start value=#{partitionPlan['start']}/
 property name=end value=#{partitionPlan['end']}/
 /properties 
 /reader
 . . .
 /chunk! #DV13-UniJavaEE7 @arungupta @agoncal
  • 92.
    Partition Partitioning partition
 plan partitions=2
 properties partition=0
 propertyname=start value=1/
 property name=end value=10/
 /properties
 properties partition=1
 property name=start value=11/
 property name=end value=20/
 /properties
 /plan
 /partition
 /step! #DV13-UniJavaEE7 @arungupta @agoncal
  • 93.
    Creating Workflows Flow: Elementsthat execute together as a unit flow id=flow1 next=step3
 step id=step1 next=step2 . . . /step
 step id=step2 . . . /step
 /flow
 step id=step3 . . . /step! #DV13-UniJavaEE7 @arungupta @agoncal
  • 94.
    Creating Workflows Split: Concurrentexecution of flows split id=split1 next= . . . 
 flow id=flow1”
 step id=step1” . . . /step
 /flow
 flow id=flow2”
 step id=step2” . . . /step
 /flow
 /split! #DV13-UniJavaEE7 @arungupta @agoncal
  • 95.
    Creating Workflows Decision: Customizedway of sequencing between steps, flows, splits step id=step1 next=decider1. . ./step
 decision id=decider1 ref=myDecider 
 next on=DATA_LOADED to=step2/ 
 end on=NOT_LOADED/ /decision
 step id=step2. . ./step ! ! @Named
 public class MyDecider implements Decider {
 @Override
 public String decide(StepExecution[] ses) throws Exception {
 . . .
 return DATA_LOADED; // or NOT_LOADED! } ! }! ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 96.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 JavaMail 1.5 (JSR 919) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 97.
    MailSessionDefinition A mail sessioncan be defined using an annotation @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;! #DV13-UniJavaEE7 @arungupta @agoncal
  • 98.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 JCA 1.7 (JSR 322) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 99.
    Connector definition A connectorcan be defined using an annotation @ConnectionDefinition(! connection=MyConnection.class,! connectionImpl=MyConnectionImpl.class,! connectionFactory=MyConnectionFactory.class,! connectionFactoryImpl=MyConnectionFactoryImpl.class! )! ! @AdministeredObjectDefinition(! className=MyQueueImpl.class,! name=java:comp/MyQueue,! resourceAdapter=myAdapter,! )! #DV13-UniJavaEE7 @arungupta @agoncal
  • 100.
    CDI 1.1 Bean Validation1.1 Interceptors 1.2 Concurrency 1.0 Java EE 7 (JSR 342) JSP JSTL EL 3.0 Servlet 3.1 JTA 1.2 JSF 2.2 Web Socket 1.0 EJB 3.2 JPA 2.1 JMS 2.0 JAX-RS 2.0 JSON-P 1.0 Batch 1.0 JavaMail 1.5 JCA 1.7 Java EE 7 #DV13-UniJavaEE7 @arungupta @agoncal
  • 101.
    Default Resources Default datasource @Resource(lookup=java:comp/DefaultDataSource)! privateDataSource myDS;! ! @Resource! private DataSource myDS; ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 102.
    Default Resources Default JMSfactory @Resource(lookup=java:comp/DefaultJMSConnectionFactory) ! private ConnectionFactory myCF; ! ! @Resource! private ConnectionFactory myCF;! #DV13-UniJavaEE7 @arungupta @agoncal
  • 103.
    Default Resources Default ConcurrencyUtilities objects @Resource(lookup=java:comp/DefaultManagedExecutorService) ! private ManagedExecutorService mes; ! @Resource(lookup=java:comp/DefaultManagedScheduledExecutorService) ! private ManagedScheduledExecutorService mses; ! @Resource(lookup=java:comp/DefaultManagedThreadFactory) ! private ManagedThreadFactory mtf; ! @Resource(lookup=java:comp/DefaultContextService) ! private ContextService cs; ! ! @Resource! private ManagedExecutorService mes; ! @Resource! private ManagedScheduledExecutorService mses; ! @Resource! private ManagedThreadFactory mtf; ! @Resource! private ContextService cs; ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 104.
    New namespaces Bye byeSun persistence xmlns=http://xmlns.jcp.org/xml/ns/persistence! xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance! xsi:schemaLocation=http://xmlns.jcp.org/xml/ns/persistence ! http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd! version=2.1! ! web-app xmlns=http://xmlns.jcp.org/xml/ns/javaee! xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance! xsi:schemaLocation=http://xmlns.jcp.org/xml/ns/javaee ! http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd! version=3.1! ! #DV13-UniJavaEE7 @arungupta @agoncal
  • 105.
  • 106.
  • 107.
    Thank you Arun Gupta AntonioGoncalves #DV13-UniJavaEE7 @arungupta @agoncal