1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package client;
import ejb.Remot;
import ejb.StatelessEJB;
import entite.Facture;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.embeddable.EJBContainer;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
*
* @author laleye
*/
//@EJB
public class Client {
/**
* @param args the command line arguments
*/
@Resource(mappedName = "jms/facture")
private Topic facture;
@Resource(mappedName = "jms/factureFactory")
private ConnectionFactory factureFactory;
public static void main(String[] args) throws NamingException, JMSException {
// TODO code application logic here
Client cl=new Client();
cl.sendJMSMessageToFacture_jms("JESUS");
// sendJMSMessageToFacture_jms("JESUS");
// System.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
//// System.setProperty("java.naming.provider.url", "localhost:1099");
//// try{
//// Properties props = new Properties();
////
//// props.setProperty("java.naming.factory.initial",
//// "com.sun.enterprise.naming.SerialInitContextFactory");
////
//// props.setProperty("java.naming.factory.url.pkgs",
//// "com.sun.enterprise.naming");
////
//// props.setProperty("java.naming.factory.state",
//// "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
//// InitialContext ic = new InitialContext(props);
////
//// Remot rm=(Remot) ic.lookup("java:global/test/FactureEJB!ejb.Remot");
//// rm.sendJMSMessageToFacture_jms("JESUS");
// rm.envoimessage("JESUS");
// List<Facture> f;
// f=rm.findAllFacture();
// f=rm.envoimessage();
// System.out.println(f.get(1).getDate().toString());
//// }catch(Exception e){
//// //System.out.println("impossible");
//// e.printStackTrace();
//// }
}
private Message createJMSMessageForjmsFacture(Session session, Object messageData) throws JMSException {
// TODO create and populate message to send
TextMessage tm = session.createTextMessage();
tm.setText(messageData.toString());
return tm;
}
public void sendJMSMessageToFacture_jms(Object messageData) throws JMSException {
Connection connection = null;
Session session = null;
try {
connection = factureFactory.createConnection();
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(facture);
messageProducer.send(createJMSMessageForjmsFacture(session, messageData));
} finally {
if (session != null) {
try {
session.close();
} catch (JMSException e) {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot close session", e);
}
}
if (connection != null) {
connection.close();
}
} }
} |
Partager