Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

Joe qiang

Greenhorn
+ Follow
since Mar 27, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Joe qiang

I have the servlet to use this line of code
TemporaryTopic temporaryTopic = session.createTemporaryTopic();
When I compile it, everything is fine. However, when I run it, I had the following error message:
weblogic.jms.common.JMSException: javax.naming.NameNotFoundException: Unable to
resolve 'weblogic.jms.TempDestinationFactory' Resolved: 'weblogic.jms' Unresolve
d:'TempDestinationFactory' ; remaining name 'TempDestinationFactory'
at weblogic.jms.frontend.FEManager.getTemporaryDestinationFactory(FEMana
ger.java:120)
I tried to use session.createTemporaryQueue() and I had the same problem. I do not know what is TempDestinationFactory. I search it in Google and found nothing about it. Did anyone run into this problem before? Thanks
It failed at this line:
replyQueue = qSession.createTemporaryQueue();
I believe qSession.createTemporaryQueue() will try to use TempDestinationFactory.
I have one servlet to call a MDB to verify login information. I compile it and everything is fine. But when I run it, I got the javax.naming.NameNotFoundException. Here is the partial code for servlet:
String userName;
String userPw;
Queue replyQueue = null;
InitialContext ctx = null;
TopicConnectionFactory factory = null;
TopicConnection connection = null;
TopicSession session = null;
Topic topic = null;
TopicPublisher publisher = null;
TextMessage msg = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession qSession = null;
QueueReceiver qReceiver = null;
public void init(ServletConfig config) throws ServletException {
super.init(config);

}
public void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
try {
response.setContentType( "text/HTML" );
PrintWriter out = response.getWriter();
//Login login=null;
// Initialize JNDI
//Context ctx = new InitialContext(System.getProperties());
ctx = new InitialContext();
//Context ctx2 = new InitialContext(System.getProperties());
// 1: Lookup ConnectionFactory via JNDI
factory =
(TopicConnectionFactory)
ctx.lookup("javax.jms.TopicConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
connection =
factory.createTopicConnection();
// 3: Use Connection to create session
session = connection.createTopicSession(
false, Session.AUTO_ACKNOWLEDGE);
// 4: Lookup Desintation (topic) via JNDI
topic = (Topic) ctx.lookup("logtopic");
// 5: Create a Message Producer
publisher = session.createPublisher(topic);
// 6: Create a text message, and publish it
msg = session.createTextMessage();
// 1: Lookup ConnectionFactory via JNDI
queueConnectionFactory =
(QueueConnectionFactory)
ctx.lookup("javax.jms.QueueConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
queueConnection =
queueConnectionFactory.createQueueConnection();
// 3: Use Connection to create session
qSession = queueConnection.createQueueSession(
false, Session.AUTO_ACKNOWLEDGE);
replyQueue = qSession.createTemporaryQueue();
qReceiver = qSession.createReceiver(replyQueue);
//qReceiver.setMessageListener(new LogBean());
queueConnection.start();
//MapMessage m = null;
userName = request.getParameter("userName");
userPw = request.getParameter("Password");
if (userName.equals("")||userPw.equals("")){
response.sendRedirect("/CourseWebApp/login.jsp?message=novalue");
}
else{
msg.setText(userName+"$"+userPw);
msg.setJMSReplyTo(replyQueue);
publisher.publish(msg);
session.commit();
TextMessage inMessage = (TextMessage)qReceiver.receive();
System.out.println("message in: "+ inMessage.getText());
Here is the error message:
javax.naming.NameNotFoundException: Unable to resolve 'weblogic.jms.TempDestinat
ionFactory' Resolved: 'weblogic.jms' Unresolved:'TempDestinationFactory' ; remai
ning name 'TempDestinationFactory'
at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:17
4)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteR
ef.java:263)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteR
ef.java:230)
at weblogic.jndi.internal.ServerNamingNode_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:337)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:332)
at weblogic.jms.frontend.FEManager.getTemporaryDestinationFactory(FEMana
ger.java:118)
at weblogic.jms.frontend.FEConnection.createTemporaryDestination(FEConne
ction.java:1371)
at weblogic.jms.frontend.FEConnection.invoke(FEConnection.java:1514)
at weblogic.jms.dispatcher.Request.wrappedFiniteStateMachine(Request.jav
a:602)
at weblogic.jms.dispatcher.DispatcherImpl.dispatchSync(DispatcherImpl.ja
va:275)
at weblogic.jms.client.JMSSession.createTemporaryDestination(JMSSession.
java:1764)
at weblogic.jms.client.JMSSession.createTemporaryQueue(JMSSession.java:1
482)
at course.VerifyServlet.service(VerifyServlet.java:127)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
(ServletStubImpl.java:1058)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:401)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:306)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
n.run(WebAppServletContext.java:5445)
at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
eManager.java:780)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
rvletContext.java:3105)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2588)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)
I checked the line number and found the server run into the problem in one line:
replyQueue = qSession.createTemporaryQueue();
To me, this code is fine. Could anyone tell me what is wrong? Thanks
Could anyone give me some sample code for javax.jms.QueueRequestor and javax.jms.TopicRequestor, especially how they work with MessageDrivenBean? Thanks.
Thanks a lot for your reply. It is very clear to me what I need to do.
Here is partial code of the servlet. I compiled it and there is no error:
// Initialize JNDI
Context ctx = new InitialContext(System.getProperties());
// 1: Lookup ConnectionFactory via JNDI
TopicConnectionFactory factory =
(TopicConnectionFactory)
ctx.lookup("javax.jms.TopicConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
TopicConnection connection =
factory.createTopicConnection();
// 3: Use Connection to create session
TopicSession session = connection.createTopicSession(
false, Session.AUTO_ACKNOWLEDGE);
// 4: Lookup Desintation (topic) via JNDI
Topic topic = (Topic) ctx.lookup("logtopic");
// 5: Create a Message Producer
TopicPublisher publisher = session.createPublisher(topic);
// 6: Create a text message, and publish it
TextMessage msg = session.createTextMessage();
// 1: Lookup ConnectionFactory via JNDI
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)
ctx.lookup("javax.jms.QueueConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
QueueConnection queueConnection =
queueConnectionFactory.createQueueConnection();
// 3: Use Connection to create session
QueueSession qSession = queueConnection.createQueueSession(
false, Session.AUTO_ACKNOWLEDGE);
Queue replyQueue = qSession.createTemporaryQueue();
QueueReceiver qReceiver = qSession.createReceiver(replyQueue);
queueConnection.start();
userName = request.getParameter("userName");
userPw = request.getParameter("Password");
if (userName.equals("")||userPw.equals("")){
response.sendRedirect("/CourseWebApp/login.jsp?message=novalue");
}
else{
msg.setText(userName+"$"+userPw);
msg.setJMSReplyTo(replyQueue);
publisher.publish(msg);
session.commit();
Message inMessage = (Message)qReceiver.receive();
System.out.println("message in: "+ inMessage.getStringProperty("match"));

In the onMessage() method, here is code:
protected MessageDrivenContext ctx;
protected int match = 0;
public void setMessageDrivenContext(MessageDrivenContext ctx) {
this.ctx = ctx;
}
public void onMessage(Message msg) {
try {
TextMessage tm = (TextMessage) msg;
String text = tm.getText();
System.out.println("message is: " + text);
String user1Name ="";
String user1Pw = "";
//String patternStr = "$";
StringTokenizer user1 = new StringTokenizer(text,"$");
int count = 1;
while (user1.hasMoreTokens()){
if (count == 1){
user1Name = user1.nextToken();
count++;
}
else {
user1Pw = user1.nextToken();
}
}
System.out.println("reach context: ");
ctx2 = new InitialContext(System.getProperties());
LoginHome home = (LoginHome)
PortableRemoteObject.narrow(
ctx2.lookup("LoginHome"), LoginHome.class);
System.out.println("find loginHome: ");
Login login = home.findByPrimaryKey(user1Name);
match = login.verify(user1Name, user1Pw);
System.out.println("match is: " + match);

// 1: Lookup ConnectionFactory via JNDI
ConnectionFactory cF = (ConnectionFactory) ctx.lookup("javax.jms.ConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
Connection connection = cF.createConnection();
// 3: Use Connection to create session
Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Message msg2 = session2.createMessage();
Queue replyQueue = (Queue)msg2.getJMSReplyTo();
MessageProducer producer = session2.createProducer(replyQueue);

if (match==1){
msg2.setStringProperty("match","1");
}
else{
msg2.setStringProperty("match","0");
}
}
catch(JMSException e) {
e.printStackTrace();
}
catch(Exception e) {
e.printStackTrace();
}
finally {
producer.send(msg2);
session2.commit();
}
}

When I compiled it, there are 7 error message. I checked JMS API, they are fine to me. Why does the compiler complain?
src\LogBean.java:106: cannot resolve symbol
symbol : method lookup (java.lang.String)
location: interface javax.ejb.MessageDrivenContext
ConnectionFactory cF = (ConnectionFactory) ctx.lookup("javax.jms.ConnectionF
actory");
^
src\LogBean.java:109: cannot resolve symbol
symbol : method createConnection ()
location: interface javax.jms.ConnectionFactory
Connection connection = cF.createConnection();
^
src\LogBean.java:111: cannot resolve symbol
symbol : method createSession (boolean,int)
location: interface javax.jms.Connection
Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
;
^
src\LogBean.java:115: cannot resolve symbol
symbol : method createProducer (javax.jms.Queue)
location: interface javax.jms.Session
MessageProducer producer = session2.createProducer(replyQueue);
^
src\LogBean.java:143: cannot resolve symbol
symbol : variable msg2
location: class examples.LogBean
producer.send(msg2);
^
src\LogBean.java:143: cannot resolve symbol
symbol : variable producer
location: class examples.LogBean
producer.send(msg2);
^
src\LogBean.java:144: cannot resolve symbol
symbol : variable session2
location: class examples.LogBean
session2.commit();
^
7 errors
Could you please help me take a look at the code and let me know whether I am in the right track? Many thanks.
I have a servlet to process the login request. The user name and password are passed to one MessageDrivenBean from the servlet. And from onMessage() method in the MessageDrivenBean I call Login CMP bean to verify the login information. If Login information exists in the database, return true, otherwise return false. Now this return value is in onMessage() method in the MessageDrivenBean.
Chris from Javaranch suggested me to use temporary queue to get the return value from the servlet. Then I created a temporary queue in the servlet like the following:
// 1: Lookup ConnectionFactory via JNDI
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)
ctx.lookup("javax.jms.QueueConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
QueueConnection queueConnection =
queueConnectionFactory.createQueueConnection();
// 3: Use Connection to create session
QueueSession qSession = queueConnection.createQueueSession(
false, Session.AUTO_ACKNOWLEDGE);
Queue replyQueue = qSession.createTemporaryQueue();
QueueReceiver qReceiver = qSession.createReceiver(replyQueue);
qReceiver.setMessageListener(new LogBean());
queueConnection.start();
MapMessage m = null;
m = tsession.createMapMessage();
m.setJMSReplyTo(replyQueue);
Here LogBean is the messageDrivenBean. I have to return one Boolean or interger value from onMessage() to the servlet. There are two questions:
How can I send back the value from onMessage() method?
How can I pick it up in the servlet?
Please do not question the design. This is an assignment I have no control. Thanks in advance for your help.
Hi Chris,
Now I have temporary queue in the servlet like the following:
// 1: Lookup ConnectionFactory via JNDI
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)
ctx.lookup("javax.jms.QueueConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
QueueConnection queueConnection =
queueConnectionFactory.createQueueConnection();
// 3: Use Connection to create session
QueueSession qSession = queueConnection.createQueueSession(
false, Session.AUTO_ACKNOWLEDGE);
Queue replyQueue = qSession.createTemporaryQueue();
QueueReceiver qReceiver = qSession.createReceiver(replyQueue);
qReceiver.setMessageListener(new LogBean());
queueConnection.start();
MapMessage m = null;
m = tsession.createMapMessage();
m.setJMSReplyTo(replyQueue);
Here LogBean is the messageDrivenBean. I have to return one interger value from onMessage() to the servlet. There are two questions:
How can I send back the interger value from onMessage() method?
How can I pick it up in the servlet?
Many thanks.
I have a servlet to process the login request. The user name and password are passed to one MessageDrivenBean from the servlet. And from onMessage() method in the MessageDrivenBean I call Login BMP bean to verify the login information. If Login information exists in the database, return true, otherwise return false. Now this return value is in onMessage() method in the MessageDrivenBean. However, onMessage() has return type void, how can I return a value from here to the original servlet or I can directly call sentRedirect inside onMessage() and go to the main page?
Please do not question this design. This is assignment from the instructor. Thanks in advance for your help.
I created CMP EJB for order processing. OrderId is the primary key and it will automatically be increased by 1 when new order come in. How can I write object sql in ejb-jar.xml to get the maximum number of order id? Is ther any other way to increase orderid every time except use object sql? many thanks