SlideShare uma empresa Scribd logo
1 de 102
Baixar para ler offline
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.1
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.2
50 new features of Java EE 7
in 50 minutes
Antonio Goncalves, @agoncal
Arun Gupta, @arungupta
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.3
#NN: <spec>: <feature>
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.4
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.5
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.6
#01: CDI: 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>!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.7
#02: CDI: @Vetoed
Veto the processing of the class or package
@Vetoed!
public class NonProcessedBean {

...!
}!
!
package-info.java
@Vetoed!
package com.non.processed.package;!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.8
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.9
#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());!
}!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.10
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.11
#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) ... {!
// ...!
}!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.12
#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!
...!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.13
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.14
#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
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.15
#06: Concurrency: ManagedExecutor
@Resource

ManagedExecutorService executor;

!


ManagedExecutorService executor =
(ManagedExecutorService) ctx

.lookup("java:comp/DefaultManagedExecutorService");!
Default ManagedExectuor
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.16
#06: Concurrency: ManagedExecutor
<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>!
Specify in web.xml
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.17
#07: Concurrency: ManagedScheduledExecutor
§  Managed version of ScheduledExecutorService!
§  Submit delayed or periodic tasks
@Resource

ManagedScheduledExecutorService executor;!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.18
#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
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.19
#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);!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.20
#08: Concurrency: ManagedThreadFactory
§  Extends ThreadFactory
@Resource(name = "DefaultManagedThreadFactory")

ManagedThreadFactory factory;
ManagedThreadFactory factory =
(ManagedThreadFactory) ctx.lookup("java:comp/
DefaultManagedThreadFactory");

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.21
#08: Concurrency: ManagedThreadFactory
§  Thread thread = factory.newThread(new MyTask());
§  ((ManageableThread)thread).isShutdown();

Copyright © 2013, Oracle and/or its affiliates. All rights reserved.22
#09: Concurrency: DynamicProxy
§  Create dynamic proxy objects, adds contextual information available
for applications running in Java EE environment
§  Classloading, JNDI, Security, …
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.23
#09: Concurrency: DynamicProxy
@Resource

ContextService service;





Runnable proxy = service.createContextualProxy(new
MyRunnable(), Runnable.class);





Future f = executor.submit(proxy);!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.24
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.25
#10: JPA: 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>!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.26
#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;!
...!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.27
#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();!
!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.28
#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 {...}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.29
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.30
#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) {...}!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.31
#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();!
}!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.32
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.33
#16: EJB: Disable passivation of stateful
In some cases increases performance, scalability and robustness
@Stateful(passivationCapable = false)!
public class ShoppingCart {!
...!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.34
#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() {!
// ...!
}!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.35
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.36
#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);!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.37
#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);!
}!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.38
#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 {...}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.39
#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 {...}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.40
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.41
#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) {

. . .

}

}

}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.42
#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
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.43
#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
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.44
#22: Servlet: Non-blocking I/O
AsyncContext context = request.startAsync();

ServletInputStream input = request.getInputStream();

input.setReadListener(

new MyReadListener(input, context)); !
Only for Asynchronous Servlets
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.45
#23: Servlet: Protocol Upgrade
§  <T extends HttpUpgradeHandler> T
HttpServletRequest.upgrade(Class<T> class) throws
IOException;





!
§  HttpUpgradeHandler!
–  init(WebConnection wc);!
–  destroy();!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.46
#23: Servlet: Protocol Upgrade
public interface WebConnection {

ServletInputStream getInputStream();

ServletOutputStream getOutputStream();

}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.47
#24: Servlet: Improved Security
<web-app . . . version="3.1"> 

<web-resource-collection>

<url-pattern>/account/*</url-pattern> 

<http-method>GET</http-method>

</web-resource-collection>

</web-app> !
!
Deny an HTTP method request for an uncovered HTTP method
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.48
#24: Servlet: Improved Security
<web-app . . . version="3.1"> 

<deny-uncovered-http-methods/>

<web-resource-collection>

<url-pattern>/account/*</url-pattern> 

<http-method>GET</http-method>

</web-resource-collection>

</web-app> !
!
Deny an HTTP method request for an uncovered HTTP method
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.49
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.50
#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);!
}

}

}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.51
#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) { . . . }!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.52
#27: WebSocket: Annotated client endpoint
@javax.websocket.ClientEndpoint

public class MyClient {

@javax.websocket.OnOpen

public void open(Session session) { … }



// Lifecycle callbacks

}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.53
#27: WebSocket: Annotated client endpoint
ContainerProvider

.getWebSocketContainer()

.connectToServer(

MyClient.class, 

URI.create("ws://. . ."));!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.54
#28: WebSocket: Programmatic endpoints
public class ChatServer extends Endpoint {

@Override

public void onOpen(Session s, EndpointConfig ec) {

s.addMessageHandler(new MessageHandler.Whole<String>() {

public void onMessage(String text) { . . . }

}

}



@Override

public void onClose(Session s, CloseReason cr) { . . . }



//. . . 

}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.55
#28: WebSocket: Programmatic endpoints
public class MyApplicationConfig implements
ServerApplicationConfig {

public Set<ServerEndpointConfig> getEndpointConfigs(…) { 

ServerEndpointConfig.Builder

.create(MyEndpoint.class, "/websocket”)

.configurator(new MyConfig())

.build()

}

}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.56
#28: WebSocket: Programmatic endpoints
public class MyConfig extends ServerEndpointConfig.Configurator {



public <T> T getEndpointInstance(. . .) { . . . }



public void modifyHandshake(. . .) { . . . }



. . .

}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.57
#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) {

. . . 

}

}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.58
#29: WebSocket: Encoder and Decoder
public class MyDecoder implements Decoder.Text<ChatMessage> {

public ChatMessage decode(String s) {

// . . .

}



public boolean willDecode(String string) {

// . . .

}



//. . .

}



!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.59
#29: WebSocket: Encoder and Decoder
public class MyEncoder implements Encoder.Text<ChatMessage> {



public String encode(ChatMessage chatMessage) {

// . . .

}

!
// . . .

}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.60
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.61
#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");!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.62
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.63
#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
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.64
#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
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.65
#31: JSF: Faces Flow
Package reusable flows in JAR
#{flowScope}: Local flow storage
#{facesContext.application.flowHandler.currentFlow}: Returns true if
within a flow
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.66
#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
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.67
#32: JSF: Resource Library Contract
<f:view contracts=”red”>

<ui:composition template="/template.xhtml">

. . .

</ui:composition>

</f:view>

!
Apply templates in a reusable and interchangeable manner
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.68
#33: JSF: Pass-through Attributes
<h:inputText type="email" value="#{user.email}"/> 

!
<input type="text" name="j_idt6:j_idt10"/>!
HTML5-Friendly Markup
<h:inputText p:type="email" value="#{user.email}"/> 



<input type="email" name="j_idt6:j_idt10"/>!
!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.69
#34: JSF: File Upload Component
<h:form enctype="multipart/form-data">

<h:inputFile value="#{fileUploadBean.file}"/><br/>

<h:commandButton value="Upload"/><p/>

</h:form> !
@Named @RequestScoped 

public class FileUploadBean {

private Part file;



//getter and setter

} !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.70
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.71
#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);!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.72
#36: JAX-RS: Async Client
The client API also supports asynchronous invocation
Future<String> 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) {...}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.73
#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();!
}}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.74
#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!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.75
#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());!
}!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.76
#39: JAX-RS: Entity Interceptors
Marshalling and unmarshalling HTTP message bodies
§  Intercepts inbound entity streams (read from the “wire”)
–  ReaderInterceptor!
§  Intercepts outbound entity streams (written to the “wire”)
–  WriterInterceptor!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.77
#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();!
}!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.78
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.79
#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", "j.rorri@me.com")!
.add("phoneNumber", "+44 1234 1234")!
)!
.build();!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.80
#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();!
}!
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.81
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.82
#42: Batch: Chunk-style Processing
Item-oriented Processing Style (primary)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.83
#42: Batch: Chunk-style Processing
<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!
}!
!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.84
#43: Batch: Batchlet-style Processing
Task-oriented processing style
<step id=”transferFile”>!
<batchlet ref=“MyFileTransfer” />!
</step>!
…implements Batchlet {!
@Override

public void process() {

// Transfer file!
}!
!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.85
#44: Batch: Job/Step/Chunk Listeners
<job id="myJob" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0”>

<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>!
!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.86
#44: Batch: Job/Step/Chunk 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!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.87
#44: Batch: Job/Step/Chunk Listeners
@Named

public class MyJobListener extends AbstractJobListener {



@Override

public void beforeJob() throws Exception { . . . }



@Override

public void afterJob() throws Exception { . . . }

}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.88
#45: Batch: Partition
<step>

<chunk item-count="3">

<reader ref="myItemReader">

<properties>

<property name="start" value="#{partitionPlan['start']}"/>

<property name="end" value="#{partitionPlan['end']}"/>

</properties> 

</reader>

. . .

</chunk>!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.89
#45: Batch: Partition
<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>!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.90
#46: Batch: Creating Workflows
<flow id="flow1" next="step3">

<step id="step1" next="step2"> . . . </step>

<step id="step2"> . . . </step>

</flow>

<step id="step3"> . . . </step>!
Flow: Elements that execute together as a unit
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.91
#46: Batch: Creating Workflows
<split id="split1" next=" . . . ">

<flow id="flow1”>

<step id="step1”> . . . </step>

</flow>

<flow id="flow2”>

<step id="step2”> . . . </step>

</flow>

</split>!
Split: Concurrent execution of flows
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.92
#46: Batch: Creating Workflows
<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> !
!
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"!
} !
}!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.93
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.94
#48: 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;!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.95
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.96
#49: 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",

)!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.97
#47: Default Resources
JNDI name: java:comp/DefaultDataSource
Default Data Source
@Resource(lookup="java:comp/DefaultDataSource")

DataSource myDS;

!
@Resource

DataSource myDS; !
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.98
JAX-RS 2.0
JSON-P 1.0
Web Socket 1.0Servlet 3.1
JSF 2.2EL 3.0
JSP
JSTLBeanValidation1.1
Interceptors1.2
CDI1.1
Concurrency1.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)
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.99
#47: Default Resources
JNDI name: java:comp/DefaultJMSConnectionFactory





@Resource(lookup="java:comp/DefaultJMSConnectionFactory") 

ConnectionFactory myCF;
@Resource

ConnectionFactory myCF;!
Default JMS Connection Factory
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.100
#47: Default Resources
JNDI names
§  java:comp/DefaultManagedExecutorService!
§  java:comp/DefaultManagedScheduledExecutorService!
§  java:comp/DefaultManagedThreadFactory!
§  java:comp/DefaultContextService!
Default Concurrency Utilities Objects
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.101
#50: Buy our books!
Copyright © 2013, Oracle and/or its affiliates. All rights reserved.102
DOWNLOAD
Java EE 7 SDK
oracle.com/javaee
GlassFish 4.0
Full Platform or Web Profile
glassfish.org

Mais conteúdo relacionado

Mais procurados

比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotationjavatwo2011
 
OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7Bruno Borges
 
Getting Started with Java EE 7
Getting Started with Java EE 7Getting Started with Java EE 7
Getting Started with Java EE 7Arun Gupta
 
Spring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationsourabh aggarwal
 
Resthub framework presentation
Resthub framework presentationResthub framework presentation
Resthub framework presentationSébastien Deleuze
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Ryan Cuprak
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Saeed Zarinfam
 
Testing Your Application On Google App Engine
Testing Your Application On Google App EngineTesting Your Application On Google App Engine
Testing Your Application On Google App EngineIndicThreads
 
JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)Hendrik Ebbers
 
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUGThe Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUGArun Gupta
 

Mais procurados (19)

Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Hibernate
HibernateHibernate
Hibernate
 
Java Enterprise Edition
Java Enterprise EditionJava Enterprise Edition
Java Enterprise Edition
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Dropwizard
DropwizardDropwizard
Dropwizard
 
OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7OTN Tour 2013: What's new in java EE 7
OTN Tour 2013: What's new in java EE 7
 
Getting Started with Java EE 7
Getting Started with Java EE 7Getting Started with Java EE 7
Getting Started with Java EE 7
 
DataFX - JavaOne 2013
DataFX - JavaOne 2013DataFX - JavaOne 2013
DataFX - JavaOne 2013
 
Spring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentation
 
Resthub framework presentation
Resthub framework presentationResthub framework presentation
Resthub framework presentation
 
Advance Java
Advance JavaAdvance Java
Advance Java
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]
 
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter PilgrimJavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)
 
Whats New In Java Ee 6
Whats New In Java Ee 6Whats New In Java Ee 6
Whats New In Java Ee 6
 
Testing Your Application On Google App Engine
Testing Your Application On Google App EngineTesting Your Application On Google App Engine
Testing Your Application On Google App Engine
 
JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)JavaFX Enterprise (JavaOne 2014)
JavaFX Enterprise (JavaOne 2014)
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUGThe Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
 

Semelhante a Java EE 7 features in 50 minutes

50 features of Java EE 7 in 50 minutes at JavaZone 2014
50 features of Java EE 7 in 50 minutes at JavaZone 201450 features of Java EE 7 in 50 minutes at JavaZone 2014
50 features of Java EE 7 in 50 minutes at JavaZone 2014Arun Gupta
 
GlassFish BOF
GlassFish BOFGlassFish BOF
GlassFish BOFglassfish
 
Java EE7
Java EE7Java EE7
Java EE7Jay Lee
 
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 201450 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014Arun Gupta
 
50 New Features of Java EE 7 in 50 minutes
50 New Features of Java EE 7 in 50 minutes50 New Features of Java EE 7 in 50 minutes
50 New Features of Java EE 7 in 50 minutesArun Gupta
 
The Java EE 7 Platform: Productivity++ & Embracing HTML5
The Java EE 7 Platform: Productivity++ & Embracing HTML5The Java EE 7 Platform: Productivity++ & Embracing HTML5
The Java EE 7 Platform: Productivity++ & Embracing HTML5Arun Gupta
 
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012Arun Gupta
 
50 features of Java EE 7 in 50 minutes at Geecon 2014
50 features of Java EE 7 in 50 minutes at Geecon 201450 features of Java EE 7 in 50 minutes at Geecon 2014
50 features of Java EE 7 in 50 minutes at Geecon 2014Arun Gupta
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRCtepsum
 
Java EE 7 in practise - OTN Hyderabad 2014
Java EE 7 in practise - OTN Hyderabad 2014Java EE 7 in practise - OTN Hyderabad 2014
Java EE 7 in practise - OTN Hyderabad 2014Jagadish Prasath
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java PlatformSivakumar Thyagarajan
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesArun Gupta
 
Java EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersJava EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersBruno Borges
 
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX LondonJAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX LondonArun Gupta
 
Presente e Futuro: Java EE.next()
Presente e Futuro: Java EE.next()Presente e Futuro: Java EE.next()
Presente e Futuro: Java EE.next()Bruno Borges
 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...jaxLondonConference
 
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionJava EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionArun Gupta
 
Java EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerJava EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerArun Gupta
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGArun Gupta
 

Semelhante a Java EE 7 features in 50 minutes (20)

50 features of Java EE 7 in 50 minutes at JavaZone 2014
50 features of Java EE 7 in 50 minutes at JavaZone 201450 features of Java EE 7 in 50 minutes at JavaZone 2014
50 features of Java EE 7 in 50 minutes at JavaZone 2014
 
GlassFish BOF
GlassFish BOFGlassFish BOF
GlassFish BOF
 
Java EE7
Java EE7Java EE7
Java EE7
 
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 201450 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
50 New Features of Java EE 7 in 50 minutes @ Devoxx France 2014
 
50 New Features of Java EE 7 in 50 minutes
50 New Features of Java EE 7 in 50 minutes50 New Features of Java EE 7 in 50 minutes
50 New Features of Java EE 7 in 50 minutes
 
The Java EE 7 Platform: Productivity++ & Embracing HTML5
The Java EE 7 Platform: Productivity++ & Embracing HTML5The Java EE 7 Platform: Productivity++ & Embracing HTML5
The Java EE 7 Platform: Productivity++ & Embracing HTML5
 
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
 
50 features of Java EE 7 in 50 minutes at Geecon 2014
50 features of Java EE 7 in 50 minutes at Geecon 201450 features of Java EE 7 in 50 minutes at Geecon 2014
50 features of Java EE 7 in 50 minutes at Geecon 2014
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRC
 
Java EE 7 in practise - OTN Hyderabad 2014
Java EE 7 in practise - OTN Hyderabad 2014Java EE 7 in practise - OTN Hyderabad 2014
Java EE 7 in practise - OTN Hyderabad 2014
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java Platform
 
JAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web ServicesJAX-RS 2.0: RESTful Web Services
JAX-RS 2.0: RESTful Web Services
 
Java EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersJava EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c Developers
 
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX LondonJAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
 
Java ee7 1hour
Java ee7 1hourJava ee7 1hour
Java ee7 1hour
 
Presente e Futuro: Java EE.next()
Presente e Futuro: Java EE.next()Presente e Futuro: Java EE.next()
Presente e Futuro: Java EE.next()
 
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
Java EE 7 Platform: Boosting Productivity and Embracing HTML5 - Arun Gupta (R...
 
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionJava EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
 
Java EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerJava EE 6 = Less Code + More Power
Java EE 6 = Less Code + More Power
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
 

Mais de glassfish

GlassFish Story by Kerry Wilson/Vanderbilt University Medical Center
GlassFish Story by Kerry Wilson/Vanderbilt University Medical CenterGlassFish Story by Kerry Wilson/Vanderbilt University Medical Center
GlassFish Story by Kerry Wilson/Vanderbilt University Medical Centerglassfish
 
GlassFish Story by David Heffelfinger/Ensode Technology
GlassFish Story by David Heffelfinger/Ensode TechnologyGlassFish Story by David Heffelfinger/Ensode Technology
GlassFish Story by David Heffelfinger/Ensode Technologyglassfish
 
GlassFish Story by Jaromir Hamala/C2B2 Consulting
GlassFish Story by Jaromir Hamala/C2B2 ConsultingGlassFish Story by Jaromir Hamala/C2B2 Consulting
GlassFish Story by Jaromir Hamala/C2B2 Consultingglassfish
 
GlassFish Roadmap
GlassFish RoadmapGlassFish Roadmap
GlassFish Roadmapglassfish
 
OTN Developer Days - GlassFish
OTN Developer Days - GlassFishOTN Developer Days - GlassFish
OTN Developer Days - GlassFishglassfish
 
OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6glassfish
 

Mais de glassfish (6)

GlassFish Story by Kerry Wilson/Vanderbilt University Medical Center
GlassFish Story by Kerry Wilson/Vanderbilt University Medical CenterGlassFish Story by Kerry Wilson/Vanderbilt University Medical Center
GlassFish Story by Kerry Wilson/Vanderbilt University Medical Center
 
GlassFish Story by David Heffelfinger/Ensode Technology
GlassFish Story by David Heffelfinger/Ensode TechnologyGlassFish Story by David Heffelfinger/Ensode Technology
GlassFish Story by David Heffelfinger/Ensode Technology
 
GlassFish Story by Jaromir Hamala/C2B2 Consulting
GlassFish Story by Jaromir Hamala/C2B2 ConsultingGlassFish Story by Jaromir Hamala/C2B2 Consulting
GlassFish Story by Jaromir Hamala/C2B2 Consulting
 
GlassFish Roadmap
GlassFish RoadmapGlassFish Roadmap
GlassFish Roadmap
 
OTN Developer Days - GlassFish
OTN Developer Days - GlassFishOTN Developer Days - GlassFish
OTN Developer Days - GlassFish
 
OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6
 

Último

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Último (20)

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Java EE 7 features in 50 minutes

  • 1. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.1
  • 2. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.2 50 new features of Java EE 7 in 50 minutes Antonio Goncalves, @agoncal Arun Gupta, @arungupta
  • 3. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.3 #NN: <spec>: <feature>
  • 4. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.4 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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
  • 5. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.5 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 6. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.6 #01: CDI: 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>!
  • 7. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.7 #02: CDI: @Vetoed Veto the processing of the class or package @Vetoed! public class NonProcessedBean {
 ...! }! ! package-info.java @Vetoed! package com.non.processed.package;!
  • 8. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.8 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 9. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.9 #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());! }! }!
  • 10. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.10 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 11. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.11 #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) ... {! // ...! }! }!
  • 12. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.12 #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! ...! }!
  • 13. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.13 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 14. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.14 #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
  • 15. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.15 #06: Concurrency: ManagedExecutor @Resource
 ManagedExecutorService executor;
 ! 
 ManagedExecutorService executor = (ManagedExecutorService) ctx
 .lookup("java:comp/DefaultManagedExecutorService");! Default ManagedExectuor
  • 16. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.16 #06: Concurrency: ManagedExecutor <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>! Specify in web.xml
  • 17. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.17 #07: Concurrency: ManagedScheduledExecutor §  Managed version of ScheduledExecutorService! §  Submit delayed or periodic tasks @Resource
 ManagedScheduledExecutorService executor;!
  • 18. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.18 #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
  • 19. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.19 #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);!
  • 20. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.20 #08: Concurrency: ManagedThreadFactory §  Extends ThreadFactory @Resource(name = "DefaultManagedThreadFactory")
 ManagedThreadFactory factory; ManagedThreadFactory factory = (ManagedThreadFactory) ctx.lookup("java:comp/ DefaultManagedThreadFactory");

  • 21. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.21 #08: Concurrency: ManagedThreadFactory §  Thread thread = factory.newThread(new MyTask()); §  ((ManageableThread)thread).isShutdown();

  • 22. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.22 #09: Concurrency: DynamicProxy §  Create dynamic proxy objects, adds contextual information available for applications running in Java EE environment §  Classloading, JNDI, Security, …
  • 23. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.23 #09: Concurrency: DynamicProxy @Resource
 ContextService service;
 
 
 Runnable proxy = service.createContextualProxy(new MyRunnable(), Runnable.class);
 
 
 Future f = executor.submit(proxy);!
  • 24. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.24 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 25. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.25 #10: JPA: 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>!
  • 26. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.26 #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;! ...! }!
  • 27. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.27 #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();! !
  • 28. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.28 #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 {...}!
  • 29. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.29 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 30. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.30 #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) {...}! }!
  • 31. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.31 #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();! }! }!
  • 32. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.32 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 33. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.33 #16: EJB: Disable passivation of stateful In some cases increases performance, scalability and robustness @Stateful(passivationCapable = false)! public class ShoppingCart {! ...! }!
  • 34. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.34 #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() {! // ...! }! }!
  • 35. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.35 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 36. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.36 #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);!
  • 37. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.37 #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);! }! }!
  • 38. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.38 #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 {...}!
  • 39. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.39 #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 {...}!
  • 40. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.40 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 41. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.41 #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) {
 . . .
 }
 }
 }!
  • 42. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.42 #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
  • 43. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.43 #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
  • 44. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.44 #22: Servlet: Non-blocking I/O AsyncContext context = request.startAsync();
 ServletInputStream input = request.getInputStream();
 input.setReadListener(
 new MyReadListener(input, context)); ! Only for Asynchronous Servlets
  • 45. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.45 #23: Servlet: Protocol Upgrade §  <T extends HttpUpgradeHandler> T HttpServletRequest.upgrade(Class<T> class) throws IOException;
 
 
 ! §  HttpUpgradeHandler! –  init(WebConnection wc);! –  destroy();!
  • 46. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.46 #23: Servlet: Protocol Upgrade public interface WebConnection {
 ServletInputStream getInputStream();
 ServletOutputStream getOutputStream();
 }!
  • 47. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.47 #24: Servlet: Improved Security <web-app . . . version="3.1"> 
 <web-resource-collection>
 <url-pattern>/account/*</url-pattern> 
 <http-method>GET</http-method>
 </web-resource-collection>
 </web-app> ! ! Deny an HTTP method request for an uncovered HTTP method
  • 48. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.48 #24: Servlet: Improved Security <web-app . . . version="3.1"> 
 <deny-uncovered-http-methods/>
 <web-resource-collection>
 <url-pattern>/account/*</url-pattern> 
 <http-method>GET</http-method>
 </web-resource-collection>
 </web-app> ! ! Deny an HTTP method request for an uncovered HTTP method
  • 49. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.49 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 50. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.50 #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);! }
 }
 }!
  • 51. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.51 #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) { . . . }!
  • 52. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.52 #27: WebSocket: Annotated client endpoint @javax.websocket.ClientEndpoint
 public class MyClient {
 @javax.websocket.OnOpen
 public void open(Session session) { … }
 
 // Lifecycle callbacks
 }!
  • 53. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.53 #27: WebSocket: Annotated client endpoint ContainerProvider
 .getWebSocketContainer()
 .connectToServer(
 MyClient.class, 
 URI.create("ws://. . ."));!
  • 54. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.54 #28: WebSocket: Programmatic endpoints public class ChatServer extends Endpoint {
 @Override
 public void onOpen(Session s, EndpointConfig ec) {
 s.addMessageHandler(new MessageHandler.Whole<String>() {
 public void onMessage(String text) { . . . }
 }
 }
 
 @Override
 public void onClose(Session s, CloseReason cr) { . . . }
 
 //. . . 
 }!
  • 55. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.55 #28: WebSocket: Programmatic endpoints public class MyApplicationConfig implements ServerApplicationConfig {
 public Set<ServerEndpointConfig> getEndpointConfigs(…) { 
 ServerEndpointConfig.Builder
 .create(MyEndpoint.class, "/websocket”)
 .configurator(new MyConfig())
 .build()
 }
 }!
  • 56. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.56 #28: WebSocket: Programmatic endpoints public class MyConfig extends ServerEndpointConfig.Configurator {
 
 public <T> T getEndpointInstance(. . .) { . . . }
 
 public void modifyHandshake(. . .) { . . . }
 
 . . .
 }!
  • 57. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.57 #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) {
 . . . 
 }
 }!
  • 58. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.58 #29: WebSocket: Encoder and Decoder public class MyDecoder implements Decoder.Text<ChatMessage> {
 public ChatMessage decode(String s) {
 // . . .
 }
 
 public boolean willDecode(String string) {
 // . . .
 }
 
 //. . .
 }
 
 !
  • 59. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.59 #29: WebSocket: Encoder and Decoder public class MyEncoder implements Encoder.Text<ChatMessage> {
 
 public String encode(ChatMessage chatMessage) {
 // . . .
 }
 ! // . . .
 }!
  • 60. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.60 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 61. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.61 #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");!
  • 62. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.62 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 63. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.63 #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
  • 64. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.64 #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
  • 65. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.65 #31: JSF: Faces Flow Package reusable flows in JAR #{flowScope}: Local flow storage #{facesContext.application.flowHandler.currentFlow}: Returns true if within a flow
  • 66. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.66 #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
  • 67. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.67 #32: JSF: Resource Library Contract <f:view contracts=”red”>
 <ui:composition template="/template.xhtml">
 . . .
 </ui:composition>
 </f:view>
 ! Apply templates in a reusable and interchangeable manner
  • 68. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.68 #33: JSF: Pass-through Attributes <h:inputText type="email" value="#{user.email}"/> 
 ! <input type="text" name="j_idt6:j_idt10"/>! HTML5-Friendly Markup <h:inputText p:type="email" value="#{user.email}"/> 
 
 <input type="email" name="j_idt6:j_idt10"/>! !
  • 69. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.69 #34: JSF: File Upload Component <h:form enctype="multipart/form-data">
 <h:inputFile value="#{fileUploadBean.file}"/><br/>
 <h:commandButton value="Upload"/><p/>
 </h:form> ! @Named @RequestScoped 
 public class FileUploadBean {
 private Part file;
 
 //getter and setter
 } !
  • 70. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.70 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 71. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.71 #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);!
  • 72. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.72 #36: JAX-RS: Async Client The client API also supports asynchronous invocation Future<String> 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) {...}!
  • 73. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.73 #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();! }}!
  • 74. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.74 #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!
  • 75. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.75 #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());! }! }!
  • 76. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.76 #39: JAX-RS: Entity Interceptors Marshalling and unmarshalling HTTP message bodies §  Intercepts inbound entity streams (read from the “wire”) –  ReaderInterceptor! §  Intercepts outbound entity streams (written to the “wire”) –  WriterInterceptor!
  • 77. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.77 #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();! }! }!
  • 78. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.78 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 79. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.79 #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", "j.rorri@me.com")! .add("phoneNumber", "+44 1234 1234")! )! .build();!
  • 80. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.80 #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();! }! }!
  • 81. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.81 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 82. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.82 #42: Batch: Chunk-style Processing Item-oriented Processing Style (primary)
  • 83. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.83 #42: Batch: Chunk-style Processing <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! }! !
  • 84. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.84 #43: Batch: Batchlet-style Processing Task-oriented processing style <step id=”transferFile”>! <batchlet ref=“MyFileTransfer” />! </step>! …implements Batchlet {! @Override
 public void process() {
 // Transfer file! }! !
  • 85. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.85 #44: Batch: Job/Step/Chunk Listeners <job id="myJob" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0”>
 <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>! !
  • 86. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.86 #44: Batch: Job/Step/Chunk 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!
  • 87. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.87 #44: Batch: Job/Step/Chunk Listeners @Named
 public class MyJobListener extends AbstractJobListener {
 
 @Override
 public void beforeJob() throws Exception { . . . }
 
 @Override
 public void afterJob() throws Exception { . . . }
 }!
  • 88. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.88 #45: Batch: Partition <step>
 <chunk item-count="3">
 <reader ref="myItemReader">
 <properties>
 <property name="start" value="#{partitionPlan['start']}"/>
 <property name="end" value="#{partitionPlan['end']}"/>
 </properties> 
 </reader>
 . . .
 </chunk>!
  • 89. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.89 #45: Batch: Partition <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>!
  • 90. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.90 #46: Batch: Creating Workflows <flow id="flow1" next="step3">
 <step id="step1" next="step2"> . . . </step>
 <step id="step2"> . . . </step>
 </flow>
 <step id="step3"> . . . </step>! Flow: Elements that execute together as a unit
  • 91. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.91 #46: Batch: Creating Workflows <split id="split1" next=" . . . ">
 <flow id="flow1”>
 <step id="step1”> . . . </step>
 </flow>
 <flow id="flow2”>
 <step id="step2”> . . . </step>
 </flow>
 </split>! Split: Concurrent execution of flows
  • 92. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.92 #46: Batch: Creating Workflows <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> ! ! 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"! } ! }!
  • 93. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.93 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 94. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.94 #48: 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;!
  • 95. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.95 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 96. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.96 #49: 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",
 )!
  • 97. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.97 #47: Default Resources JNDI name: java:comp/DefaultDataSource Default Data Source @Resource(lookup="java:comp/DefaultDataSource")
 DataSource myDS;
 ! @Resource
 DataSource myDS; !
  • 98. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.98 JAX-RS 2.0 JSON-P 1.0 Web Socket 1.0Servlet 3.1 JSF 2.2EL 3.0 JSP JSTLBeanValidation1.1 Interceptors1.2 CDI1.1 Concurrency1.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)
  • 99. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.99 #47: Default Resources JNDI name: java:comp/DefaultJMSConnectionFactory
 
 
 @Resource(lookup="java:comp/DefaultJMSConnectionFactory") 
 ConnectionFactory myCF; @Resource
 ConnectionFactory myCF;! Default JMS Connection Factory
  • 100. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.100 #47: Default Resources JNDI names §  java:comp/DefaultManagedExecutorService! §  java:comp/DefaultManagedScheduledExecutorService! §  java:comp/DefaultManagedThreadFactory! §  java:comp/DefaultContextService! Default Concurrency Utilities Objects
  • 101. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.101 #50: Buy our books!
  • 102. Copyright © 2013, Oracle and/or its affiliates. All rights reserved.102 DOWNLOAD Java EE 7 SDK oracle.com/javaee GlassFish 4.0 Full Platform or Web Profile glassfish.org