esercizio e test usando jms e mdb
This commit is contained in:
44
exercise2_client/ClientPrintAll.java
Normal file
44
exercise2_client/ClientPrintAll.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package exercise2_client;
|
||||
|
||||
import exercise2.Book;
|
||||
import exercise2.RemoteInterface;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ClientPrintAll {
|
||||
|
||||
|
||||
public static void main (String[] args) {
|
||||
|
||||
|
||||
Context ctx = null;
|
||||
try {
|
||||
ctx =new InitialContext();
|
||||
} catch (NamingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
RemoteInterface r = null;
|
||||
try {
|
||||
r =(RemoteInterface) ctx.lookup("java:global/web/EJBBook!exercise2.RemoteInterface");
|
||||
List<Book> l = r.findall();
|
||||
Iterator<Book> it = l.iterator();
|
||||
while (it.hasNext()){
|
||||
Book b = it.next();
|
||||
System.out.print(b.getIsbn() + " " + b.getTitle() + " " + b.getAuthor() + " " +b.getPrice() + " ");
|
||||
}
|
||||
|
||||
} catch (NamingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
37
exercise2_client/ClientUpdatePrice.java
Normal file
37
exercise2_client/ClientUpdatePrice.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package exercise2_client;
|
||||
|
||||
import exercise2.BookMessage;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSContext;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
/**
|
||||
* Created by Giovanni on 31/05/2015.
|
||||
*/
|
||||
public class ClientUpdatePrice {
|
||||
|
||||
public static void main(String[] args) throws NamingException {
|
||||
|
||||
|
||||
BookMessage m = new BookMessage("0001",Float.valueOf(10000));
|
||||
|
||||
Context jndiContext = new InitialContext();
|
||||
|
||||
ConnectionFactory connectionFactory = (ConnectionFactory) jndiContext.lookup("jms/javaee7/ConnectionFactory");
|
||||
Destination topic = (Destination) jndiContext.lookup("jms/javaee7/Topic");
|
||||
try (JMSContext jmsContext = connectionFactory.createContext()) {
|
||||
jmsContext.createProducer().send(topic, m);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user