4. Default enabling
Finer scanning control
• Possible values: all, annotated, none
• all behaves like in Java EE 6 (default if not set)
<beans ... version="1.1" bean-discovery-mode="all">!
<alternatives>!
<class>org.agoncal.book.MockGenerator</class>!
</alternatives>!
</beans>!
#DV13-UniJavaEE7
@arungupta @agoncal
5. @Vetoed
Veto the processing of the class or package
@Vetoed!
public class NonProcessedBean {
...!
}!
!
package-info.java!
@Vetoed!
package com.non.processed.package;!
#DV13-UniJavaEE7
@arungupta @agoncal
7. Method validation
Pre/post conditions on method and constructors
public class CardValidator {!
!
public CardValidator(@NotNull Algorithm algorithm) {!
this.algorithm = algorithm;!
}!
!
@AssertTrue!
public Boolean validate(@NotNull CreditCard creditCard){!
return algorithm.validate(creditCard.getNumber());!
}!
}!
#DV13-UniJavaEE7
@arungupta @agoncal
8. CDI in validators
Injection in validators is now possible
public class ZipCodeValidator implements!
ConstraintValidator<ZipCode, String> {!
!
@Inject @USA!
ZipCodeChecker checker = new ZipCodeChecker();!
!
public boolean isValid(String value,!
ConstraintValidatorContext context) {!
!
return checker.isZipCodeValid(value);!
}!
}!
#DV13-UniJavaEE7
@arungupta @agoncal
13. ManagedExecutor
Threads in Java EE
• User threads in Java EE applications
• Support simple and advance concurrency design patterns
• Extend Concurrency Utilities API from Java SE (JSR 166y)
• java.util.concurrent
#DV13-UniJavaEE7
package
@arungupta @agoncal
16. ManagedScheduledExecutor
Thread Scheduler in Java EE
• Managed version of ScheduledExecutorService
• Submit delayed or periodic tasks
@Resource
ManagedScheduledExecutorService executor;!
#DV13-UniJavaEE7
@arungupta @agoncal
17. ManagedScheduledExecutor
Access using JNDI
• Can be defined in web.xml as well
InitialContext ctx = new InitialContext();
ManagedScheduledExecutorService executor =
(ManagedScheduledExecutorService)ctx.lookup(
"java:comp/DefaultManagedScheduledExecutorService");
!
#DV13-UniJavaEE7
@arungupta @agoncal
25. @Index
Defines additional indexes in schema generation
@Entity!
@Table(indexes = {!
@Index(columnList = ISBN),!
@Index(columnList = NBOFPAGE)!
})!
public class Book {!
!
@Id @GeneratedValue!
private Long id;!
private String isbn;!
private Integer nbOfPage;!
...!
}!
#DV13-UniJavaEE7
@arungupta @agoncal
26. Unsynchronized Persistence Context
Persistence context not enlisted in any tx unless explicitly joined
@PersistenceContext(synchronization =!
SynchronizationType.UNSYNCHRONIZED)!
private EntityManager em;!
...!
!
em.persist(book);!
!
...!
em.joinTransaction();!
!
#DV13-UniJavaEE7
@arungupta @agoncal
27. Stored Procedure
Calling a stored procedure
@Entity!
@NamedStoredProcedureQuery(name = archiveOldBooks, !
procedureName = sp_archive_books,!
parameters = {!
@StoredProcedureParameter(name = ”date, mode = IN, !
type = Date.class),!
@StoredProcedureParameter(name = warehouse, mode = IN, !
type = String.class)!
})!
public class Book {...}!
#DV13-UniJavaEE7
@arungupta @agoncal
28. CDI in listeners
Injection is now possible into event listeners
public class AgeCalculationListener {!
!
@Inject!
private AgeCalculator ageCalculator;!
!
@PostLoad!
@PostPersist!
@PostUpdate!
public void calculateAge(Customer c) {!
customer.setAge(ageCalculator.calc(c.getBirth));!
}!
}!
#DV13-UniJavaEE7
@arungupta @agoncal
29. Converters
Classes that convert between database and attributes
@Converter!
public class CreditCardEnumConverter implements!
AttributeConverterCreditCard, String {!
!
public String convertToDatabaseColumn(CreditCard attr) {...}!
public CreditCard convertToEntityAttribute(String data){...}!
}!
!
@Entity!
public class Order {!
!
@Convert(converter = CreditCardEnumConverter.class)!
private CreditCard creditCard;!
}!
#DV13-UniJavaEE7
@arungupta @agoncal
34. Disable passivation of stateful
In some cases increases performance, scalability and robustness
@Stateful(passivationCapable = false)!
public class ShoppingCart {!
...!
}!
#DV13-UniJavaEE7
@arungupta @agoncal
35. EJB-Lite: Async + Non-persistent timer
EJB Lite includes async invocations and non-persistent EJB Timer
@Stateless!
public class OrderEJB {!
!
@Asynchronous!
public void sendEmail (Order order) {!
// Very Long task!
}!
!
@Schedule(hour=2, persistent=false)!
public void createDailyReport() {!
// ...!
}!
}!
#DV13-UniJavaEE7
@arungupta @agoncal
37. JMSContext API
New simplified API to produce and consume messages
JMSContext ctx = connectionFactory.createContext()!
!
ctx.createProducer().send(queue, Text message sent);!
!
ctx.createConsumer(queue).receiveBody(String.class);!
!
ctx.createProducer()!
.setPriority(2)!
.setTimeToLive(1000)!
.setDeliveryMode(DeliveryMode.NON_PERSISTENT)!
.send(queue, message);!
#DV13-UniJavaEE7
@arungupta @agoncal
38. Runtime Exceptions
A set of new unchecked exceptions have been created
RuntimeException!
JMSRuntimeException!
IllegalStateRuntimeException!
InvalidClientIDRuntimeException!
InvalidDestinationRuntimeException!
InvalidSelectorRuntimeException!
JMSSecurityRuntimeException!
MessageFormatRuntimeException!
MessageNotWriteableRuntimeException!
ResourceAllocationRuntimeException!
TransactionInProgressRuntimeException!
TransactionRolledBackRuntimeException!
#DV13-UniJavaEE7
@arungupta @agoncal
39. Autocloseable
Several JMS interfaces implement Autocloseable
try (JMSContext ctx = connectionFactory.createContext()) {!
ctx.createProducer().send(queue, Text message sent);!
}!
!
...!
!
try (JMSContext ctx = connectionFactory.createContext()) {!
while (true) { !
String s =ctx.createConsumer(q).receiveBody(String.class);!
}!
}!
#DV13-UniJavaEE7
@arungupta @agoncal
40. JMSConnectionFactoryDefinition
ConnectionFactory can be defined using an annotation
@Stateless!
@JMSConnectionFactoryDefinition(!
name = java:app/jms/MyConnectionFactory,!
interfaceName = javax.jms.TopicConnectionFactory)!
!
!
!
public class ExpensiveOrderEJB {...}!
#DV13-UniJavaEE7
@arungupta @agoncal
41. JMSDestinationDefinition
A JMS queue or topic can be defined using an annotation
@Stateless!
@JMSConnectionFactoryDefinition(!
name = java:app/jms/MyConnectionFactory,!
interfaceName = javax.jms.TopicConnectionFactory)!
@JMSDestinationDefinition(!
name = java:app/jms/MyTopic,!
interfaceName = javax.jms.Topic)!
public class ExpensiveOrderEJB {...}!
#DV13-UniJavaEE7
@arungupta @agoncal
43. Non-blocking I/O
Non-blocking I/O in Servlets
public class TestServlet extends HttpServlet
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {!
ServletInputStream input = request.getInputStream();
byte[] b = new byte[1024];
int len = -1;
while ((len = input.read(b)) != -1) {
. . .
}
}
}!
#DV13-UniJavaEE7
@arungupta @agoncal
44. Non-blocking I/O
New methods to existing interfaces
• ServletInputStream
• public
• public
• public
void setReadListener(ReadListener l);
boolean isFinished();
boolean isReady();
• public
• public
setWriteListener(WriteListener l);
boolean canWrite();
• ServletOutputStream
#DV13-UniJavaEE7
@arungupta @agoncal
45. Non-blocking I/O
New interfaces
public interface ReadListener extends EventListener {
public void onDataAvailable();
public void onAllDataRead();
public void onError();
}!
public interface WriteListener extends EventListener {
public void onWritePossible();
public void onError();
}!
#DV13-UniJavaEE7
@arungupta @agoncal
52. Annotated server endpoint
Full-duplex bi-directional communication over single TCP connection
@javax.websocket.server.ServerEndpoint(/chat)
public class ChatServer {
@OnMessage
public String chat(String name, Session session) {
for (Session peer : client.getOpenSessions()) {!
peer.getBasicRemote().sendObject(message);!
}
}
}!
#DV13-UniJavaEE7
@arungupta @agoncal
54. Annotated client endpoint
Full-duplex bi-directional communication over single TCP connection
@javax.websocket.ClientEndpoint
public class MyClient {
@javax.websocket.OnOpen
public void open(Session session) { … }
// Lifecycle callbacks
}!
#DV13-UniJavaEE7
@arungupta @agoncal
55. Annotated client endpoint
Full-duplex bi-directional communication over single TCP connection
ContainerProvider
.getWebSocketContainer()
.connectToServer(
MyClient.class,
URI.create(ws://. . .));!
!
#DV13-UniJavaEE7
@arungupta @agoncal
56. Programmatic endpoints
API of rendpoints
public class ChatServer extends Endpoint {
@Override
public void onOpen(Session s, EndpointConfig ec) {
s.addMessageHandler(new MessageHandler.WholeString() {
public void onMessage(String text) { . . . }
}
}
@Override
public void onClose(Session s, CloseReason cr) { . . . }
//. . .
}!
#DV13-UniJavaEE7
@arungupta @agoncal
57. Programmatic endpoints
API of rendpoints
public class MyApplicationConfig implements
ServerApplicationConfig {
public SetServerEndpointConfig getEndpointConfigs(…) {
ServerEndpointConfig.Builder
.create(MyEndpoint.class, /websocket”)
.configurator(new MyConfig())
.build()
}
}!
#DV13-UniJavaEE7
@arungupta @agoncal
58. Programmatic endpoints
API of rendpoints
public class MyConfig extends ServerEndpointConfig.Configurator{
public T T getEndpointInstance(. . .) { . . . }
public void modifyHandshake(. . .) { . . . }
. . .
}!
#DV13-UniJavaEE7
@arungupta @agoncal
59. Encoder and Decoder
Encodes and decodes messages
@javax.websocket.server.ServerEndpoint(
value=/chat,
decoders=MyDecoder.class,
encoders=MyEncoder.class)
public class ChatServer {
@OnMessage
public String chat(ChatMessage name, Session session) {
. . .
}
}!
#DV13-UniJavaEE7
@arungupta @agoncal
60. Encoder and Decoder
Encodes and decodes messages
public class MyDecoder implements Decoder.TextChatMessage {
public ChatMessage decode(String s) {
// . . .
}
public boolean willDecode(String string) {
// . . .
}
//. . .
}!
#DV13-UniJavaEE7
@arungupta @agoncal
61. Encoder and Decoder
Encodes and decodes messages
public class MyEncoder implements Encoder.TextChatMessage {
public String encode(ChatMessage chatMessage) {
// . . .
}
!
// . . .
}!
#DV13-UniJavaEE7
@arungupta @agoncal
63. ELProcessor
Use EL in a stand-alone environment
ELProcessor el = new ELProcessor();!
!
assert ((Integer)el.eval(a = [1, 2]; a[1])) == 2;!
!
el.defineBean(employee, new Employee(John));!
assert (el.eval(employee.name)).equals(John);!
!
#DV13-UniJavaEE7
@arungupta @agoncal
64. Lambda expression
Use lambdas before Java SE 8
ELProcessor el = new ELProcessor();!
!
assert ((Integer)(el.eval(((x,y) - x+y)(4, 5)))) == 9;!
#DV13-UniJavaEE7
@arungupta @agoncal
67. Faces Flow
Use annotations
Named
@FlowScoped(flow1)
public class Flow1Bean implements Serializable {
}!
!
@Produces @FlowDefinition
public Flow defineFlow(@FlowBuilderParameter FlowBuilder fb) {
String flowId = flow1;
//. . .
return fb.getFlow();
}!
#DV13-UniJavaEE7
@arungupta @agoncal
68. Faces Flow
Use flows in EL
#{flowScope}: Local flow storage
#{facesContext.application.flowHandler.currentFlow}: Returns !
true if within a flow!
#DV13-UniJavaEE7
@arungupta @agoncal
69. Resource Library Contract
Apply templates in a reusable and interchangeable manner
index-blue.xhtml
index-red.xhtml
WEB-INF/lib/contracts-library-1.0-SNAPSHOT.jar
/META-INF/contracts/blue
/style.css
/javax.faces.contract.xml
/template.xhtml
/META-INF/contracts/red
/style.css
/javax.faces.contract.xml
/template.xhtml!
#DV13-UniJavaEE7
@arungupta @agoncal
70. Resource Library Contract
Apply templates in a reusable and interchangeable manner
f:view contracts=”red”
ui:composition template=/template.xhtml
. . .
/ui:composition
/f:view
!
#DV13-UniJavaEE7
@arungupta @agoncal
74. Client API
New API to consume rest services
Client client = ClientBuilder.newClient();!
WebTarget target = client.target(http://www.foo.com/book);!
Invocation invocation = target.request(TEXT_PLAIN).get();!
Response response = invocation.invoke();!
!
Response response = ClientBuilder.newClient()!
.target(http://www.foo.com/book)!
.request(MediaType.TEXT_PLAIN)!
.get();!
!
String body = ClientBuilder.newClient()!
.target(http://www.foo.com/book)!
.request()!
.get(String.class);!
#DV13-UniJavaEE7
@arungupta @agoncal
75. Async client
The client API also supports asynchronous invocation
FutureString future = ClientBuilder.newClient()!
.target(http://www.foo.com/book)!
.request()!
.async()!
.get(String.class);!
!
try {!
String body = future.get(1, TimeUnit.MINUTES);!
} catch (InterruptedException |ExecutionException e){!
...!
}!
#DV13-UniJavaEE7
@arungupta @agoncal
76. Async server
Asynchronous request processing on the server
@Path(/async)!
public class AsyncResource {!
!
@GET!
public void asyncGet(@Suspended AsyncResponse resp){!
!
new Thread(new Runnable() {!
!
public void run() {!
String result = veryExpensiveOperation();!
resp.resume(result);!
}!
}).start();!
}}!
#DV13-UniJavaEE7
@arungupta @agoncal
77. Message Filter
Process incoming/outgoing request/response headers
• Filters on client side
• javax.ws.rs.client.ClientRequestFilter
• javax.ws.rs.client.ClientResponseFilter
• Filters on server side
• javax.ws.rs.container.ContainerRequestFilter
• javax.ws.rs.container.ContainerResponseFilter
#DV13-UniJavaEE7
@arungupta @agoncal
78. Message Filter
Process incoming/outgoing request/response headers
public class LogginFilter implements ClientRequestFilter{!
!
public void filter(ClientRequestContext ctx) ... {!
System.out.println(ctx.getMethod());!
System.out.println(ctx.getUri());!
}!
}!
#DV13-UniJavaEE7
@arungupta @agoncal
79. Entity Interceptors
Marshalling and unmarshalling HTTP message bodies
• Intercepts inbound stream (read from the “wire”)
• javax.ws.rs.ext.ReaderInterceptor
• Intercepts outbound stream (written to the “wire”)
• javax.ws.rs.ext.WriterInterceptor
#DV13-UniJavaEE7
@arungupta @agoncal
80. Entity Interceptors
Marshalling and unmarshalling HTTP message bodies
public class ZipInterceptor implements WriterInterceptor{!
!
public void aroundWriteTo(WriterInterceptorContext ctx){!
OutputStream os = ctx.getOutputStream();!
ctx.setOutputStream(new GZIPOutputStream(os));!
ctx.proceed();!
}!
}!
#DV13-UniJavaEE7
@arungupta @agoncal