5. WebSocket Primer
•
•
HTTP is half duplex and traditional flavors of server
push were long polling, Comet/AJAX → Inefficient
and wasteful
WebSocket to the rescue !
TCP based, bi-directional, full-duplex messaging
Originally proposed as part of HTML5
W3C defined Javascript API
6. WebSocket Primer
•
In 4 lines
Establish connection (Single TCP Connection)
Send messages in both directions (Bi-directional)
Send messages independent of each other (Full Duplex)
End Connection
7. Java API for WebSocket
•
Higher level API for WebSocket
•
Both client and server-side (Java SE and Java EE)
•
Both declarative and programmatic
8. Java API for WebSocket
@ServerEndpoint(”/chat”)
public class ChatServer {
Set<Session> peers = ...
@OnOpen
public void onOpen(Session peer) {
peers.add(peer);
}
@OnClose
public void onClose(Session peer) {
peers.remove(peer);
}
...
9. Java API for WebSocket
...
@OnMessage
public void message(String message, Session client)
throws IOException {
for (Session session : peers) {
if (!session.equals(client)) {
session.getRemote().sendObject(message);
}
}
}
•
}
10. Java API for JSON Processing
•
•
•
API to parse, generate, transform, query JSON
Object Model and Streaming API -- similar to DOM
and StAX
Binding JSON to Java objects forthcoming
15. Concurrency Utilities for Java EE
•
•
•
Provides simple, safe API for concurrency in Java EE
Builds on Java SE concurrency
java.util.concurrent.ExecutorService
Relatively low-level API and provides
ManagedExecutorService
ManagedScheduledExecutorService
ManagedThreadFactory
ContextService
•
Context Propagation (except Transactions !!)
16. Concurrency Utilities for Java EE
Managed Task Executor
public class TestServlet extends HTTPServlet {
@Resource(name=“concurrent/MyExecutorService”)
ManagedExecutorService executor;
Future future = executor.submit(new MyTask());
class MyTask implements Runnable {
public void run() {
... // Task logic
}
}
}
20. JMS 2
JMS Resource Definition
@JMSConnectionFactoryDefinition(
name="java:global/jms/demoConnectionFactory",
interfaceName= "javax.jms.ConnectionFactory",
description="ConnectionFactory to use in demonstration")
@JMSDestinationDefinition(
name = "java:global/jms/demoQueue",
description = "Queue to use in demonstration",
interfaceName = "javax.jms.Queue",
destinationName="demoQueue")
21. JMS 2/EJB 3.2
More Standard MDB Properties
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(
propertyName = "destinationLookup",
propertyValue = "jms/OrderQueue"),
@ActivationConfigProperty(
propertyName = "connectionFactoryLookup",
propertyValue = "jms/MyConnectionFactory")})
public class OrderListener implements MessageListener {
...
public void onMessage(Message message) { ... }
...
}
22. JAX-RS 2
•
Client API
•
Message Filters & Entity Interceptors
•
Asynchronous Processing – Server & Client
•
Hypermedia Support
•
Content negotiation
23. JAX-RS 2
Client API
// Get instance of Client
Client client = ClientBuilder.newClient();
// Get customer name for the shipped products
String name = client.target(“../orders/{orderId}/customer”)
.pathParam(”orderId", ”10”)
.queryParam(”shipped", ”true”)
.request()
.get(String.class);
24. JAX-RS 2
Logging Filter
public class RequestLoggingFilter
implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext
requestContext) {
log(requestContext);
// Non-wrapping => returns without invoking next filter
}
...
}
38. Cargo Tracker
Planned Reference Architectural Blueprint for Java EE 7
utilizing DDD
•
•
•
•
Clean DDD design utilizing almost all the JSRs for Java
EE 7
Demonstrates building of modern mobile/desktop
applications utilizing Java EE 7
Project code is available at
https://java.net/projects/cargotracker/pages/Home
Contributors/Reviewers needed. Ask Reza
Rahman/myself for more details