+ All Categories
Home > Software > The First Contact with Java EE 7

The First Contact with Java EE 7

Date post: 22-Jan-2018
Category:
Upload: roberto-cortez
View: 374 times
Download: 1 times
Share this document with a friend
29
The First Contact with Java EE 7
Transcript

The First Contact with Java EE 7

Questions?Ask them right away!

New Specifications

• Websockets

• Batch Applications

• Concurrency Utilities

• JSON Processing

Improvements• Simplified JMS API

• Default Resources

• JAX-RS Client API

• EJB’s External Transactions

• More Annotations

• Entity Graphs

Java EE 7 JSRs

Websockets

• Supports Client and Server

• Declarative and Programmatic

Websockets Chat Server@ServerEndpoint("/chatWebSocket")public class ChatWebSocket { private static final Set<Session> sessions = Collections.synchronizedSet(new HashSet<Session>());

@OnOpen public void onOpen(Session session) {sessions.add(session);}

@OnMessage public void onMessage(String message) { for (Session session : sessions) { session.getAsyncRemote().sendText(message);} }

@OnClose public void onClose(Session session) {sessions.remove(session);}}

Batch Applications

• For long, non-interactive processes

• Either sequential or parallel (partitions)

• Task or Chunk oriented processing

Batch Applications

Batch Applications - job.xml

<job id="myJob" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0"> <step id="myStep" > <chunk item-count="3"> <reader ref="myItemReader"/> <processor ref="myItemProcessor"/> <writer ref="myItemWriter"/> </chunk> </step></job>

Concurrency Utilities

• Asynchronous capabilities to the Java EE world

• Java SE Concurrency API extension

• Safe and propagates context

Concurrency Utilitiespublic class TestServlet extends HttpServlet { @Resource(name = "concurrent/MyExecutorService") ManagedExecutorService executor;

Future future = executor.submit(new MyTask());

class MyTask implements Runnable { public void run() {

// do something } }}

JSON Processing

• Read, generate and transform JSON

• Streaming API and Object Model API

JSON ProcessingJsonArray jsonArray = Json.createArrayBuilder() .add(Json.createObjectBuilder() .add("name", “Jack")) .add("age", "30")) .add(Json.createObjectBuilder() .add("name", “Mary")) .add("age", "45")) .build();

[ {“name”:”Jack”, “age”:”30”}, {“name”:”Mary”, “age”:”45”} ]

JMS

• New interface JMSContext

• Modern API with Dependency Injection

• Resources AutoCloseable

• Simplified how to send messages

JMS @Resource(lookup = "java:global/jms/demoConnectionFactory") ConnectionFactory connectionFactory; @Resource(lookup = "java:global/jms/demoQueue") Queue demoQueue;

public void sendMessage(String payload) { try { Connection connection = connectionFactory.createConnection(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer messageProducer = session.createProducer(demoQueue); TextMessage textMessage = session.createTextMessage(payload); messageProducer.send(textMessage); } finally { connection.close(); } } catch (JMSException ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } }

JMS @Inject private JMSContext context;

@Resource(mappedName = "jms/inboundQueue") private Queue inboundQueue;

public void sendMessage (String payload) { context.createProducer() .setPriority(1) .setTimeToLive(1000) .setDeliveryMode(NON_PERSISTENT) .send(inboundQueue, payload); }

JAX-RS

• New API to consume REST services

• Asynchronous processing (client and server)

• Filters and Interceptors

JAX-RS

String movie = ClientBuilder.newClient() .target("http://www.movies.com/movie") .request(MediaType.TEXT_PLAIN) .get(String.class);

JPA

• Schema generation

• Stored Procedures

• Entity Graphs

• Unsynchronized Persistence Context

JPA<persistence-unit name="myPU" transaction-type="JTA"> <properties> <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/> <property name="javax.persistence.schema-generation.create-source" value="script"/> <property name="javax.persistence.schema-generation.drop-source" value="script"/> <property name="javax.persistence.schema-generation.create-script-source" value="META-INF/create.sql"/> <property name="javax.persistence.schema-generation.drop-script-source" value="META-INF/drop.sql"/> <property name="javax.persistence.sql-load-script-source" value="META-INF/load.sql"/> </properties> </persistence-unit>

JPA @Entity @NamedStoredProcedureQuery(name="top10MoviesProcedure", procedureName = "top10Movies") public class Movie {}

StoredProcedureQuery query = entityManager.createNamedStoredProcedureQuery( "top10MoviesProcedure"); query.registerStoredProcedureParameter(1, String.class, ParameterMode.INOUT); query.setParameter(1, "top10"); query.registerStoredProcedureParameter(2, Integer.class, ParameterMode.IN); query.setParameter(2, 100); query.execute(); query.getOutputParameterValue(1);

JSF

• HTML 5 support

• @FlowScoped and @ViewScoped

• File Upload component

• Flow Navigation by Convention

• Resource Library Contracts

Others• JTA: @Transactional, @TransactionScoped

• Servlet: Non-blocking I/O, Security

• CDI: Automatic for EJB’s and annotated beans (beans.xml opcional), @Vetoed

• Interceptors: @Priority, @AroundConstruct

• EJB: Passivation opcional

• EL: Lambdas, isolated API

• Bean Validator: Restrictions in parameters and return types

Certified Servers

• Glassfish 4.0

• Wildfly 8.0.0

• TMAX JEUS 8

Java EE 8• Alignment with Java 8

• JCache

• JSON-B

• MVC

• HTTP 2.0 Support

• Cloud Support

Materials• Tutorial Java EE 7 - http://docs.oracle.com/javaee/7/

tutorial/doc/home.htm

• Samples Java EE 7 - https://github.com/javaee-samples/javaee7-samples

• Batch Sample - WoW Auctions - https://github.com/radcortez/wow-auctions

• WebSocket Sample - Chat Server - https://github.com/radcortez/cbrjug-websockets-chat

Thank you!


Recommended