gudii9
asked on
servlet and mdb, jms error
Hi,
I created servlet as below using netbeans
why netbeans complains saying
Add @Override at line 15.
also at line 20 i clicked and selected insert code--->send jms message--->Message Driven bean radio button
i do not see in the drop box my MDB which i create( it suppoesed to show like DemoMDB-ejb in drop down)
please advise on
1. why i need to override i servlet
2. why my mdb is ot showing while inserting send jms message
i just tried on other machine and i was able to go till end
when i give name gp etc(on IE browser it shoud say mesage is
queued but did not do anything) it should send that message from html to servlet to jms and should be listened by mdb and should print on glassfish console as
Mr gp( i did not see that either)
https://www.youtube.com/watch?v=Ed8cuL1Ch1U&index=6&list=PLsyeobzWxl7r1gBJr5wB2Vb_QZ3G9oGul
my code is
mdb is
servet is
when i deploy MDB super project and when i try to run html file as i keep geting error like cannot be depoyed.
ant -f C:\\Users\\saiganesh\\Docu ments\\Net BeansProje cts\\DemoM DB\\DemoMD B-war -Dnb.internal.action.name= run.single -Ddirectory.deployment.sup ported=tru e -DforceRedeploy=false -Dnb.wait.for.caches=true -Dbrowser.context=C:\\User s\\saigane sh\\Docume nts\\NetBe ansProject s\\DemoMDB \\DemoMDB- war\\web\\ index.html -Dclient.urlPart=/index.ht ml run
init:
deps-module-jar:
DemoMDB-ejb.init:
DemoMDB-ejb.deps-jar:
DemoMDB-ejb.compile:
DemoMDB-ejb.library-inclus ion-in-arc hive:
DemoMDB-ejb.dist:
deps-ear-jar:
deps-jar:
library-inclusion-in-archi ve:
library-inclusion-in-manif est:
compile:
compile-jsps:
In-place deployment at C:\Users\saiganesh\Documen ts\NetBean sProjects\ DemoMDB\De moMDB-war\ build\web
GlassFish Server, deploy, null, false
C:\Users\saiganesh\Documen ts\NetBean sProjects\ DemoMDB\De moMDB-war\ nbproject\ build-impl .xml:1051: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 0 seconds)
i have to deploy sub projects ejb, war separately. not sure how to resove this issue as well. please advise
jmsStr.png
jms.png
nameQ.png
nameQ2.png
consoleGF.png
mdb22.png
I created servlet as below using netbeans
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = {"/MyServlet"})
public class MyServlet extends HttpServlet {
// @Override
public void doGet(HttpServletRequest req, HttpServletResponse res){
try {
PrintWriter out=res.getWriter();
out.println("Demo...");
} catch (IOException ex) {
System.out.println(ex);
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
why netbeans complains saying
Add @Override at line 15.
also at line 20 i clicked and selected insert code--->send jms message--->Message Driven bean radio button
i do not see in the drop box my MDB which i create( it suppoesed to show like DemoMDB-ejb in drop down)
please advise on
1. why i need to override i servlet
2. why my mdb is ot showing while inserting send jms message
i just tried on other machine and i was able to go till end
when i give name gp etc(on IE browser it shoud say mesage is
queued but did not do anything) it should send that message from html to servlet to jms and should be listened by mdb and should print on glassfish console as
Mr gp( i did not see that either)
https://www.youtube.com/watch?v=Ed8cuL1Ch1U&index=6&list=PLsyeobzWxl7r1gBJr5wB2Vb_QZ3G9oGul
my code is
mdb is
package com.navin;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "jmsDemo/navinDest"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class MyBean implements MessageListener {
public MyBean() {
}
@Override
public void onMessage(Message message)
{
TextMessage msg=(TextMessage) message;
try {
System.out.println("Mr.."+msg.getText());
} catch (JMSException ex) {
Logger.getLogger(MyBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
index html is<!DOCTYPE html>
<html>
<body>
<form action="MyServlet"></form>
Enter your name: <input type="text" name="t1"><br>
<input type="submit" value="send...">
</body>
</html>
servet is
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = {"/MyServlet"})
public class MyServlet extends HttpServlet {
@Resource(mappedName = "jmsDemo/navinDest")
private Queue demoNavinDest;
@Resource(mappedName="jmsDemo/navin")
private ConnectionFactory queue;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response){
try {
String str=request.getParameter("t1");
PrintWriter out=response.getWriter();
sendJMSMessageToNavinDest(str);
out.println("name cute...");
} catch (IOException ex) {
System.out.println(ex);
} }
private void sendJMSMessageToNavinDest(String messageData) {
//context.createProducer().send(demoNavinDest, messageData);
try {
Connection con=queue.createConnection();
Session s=con.createSession();
MessageProducer mp=s.createProducer(demoNavinDest);
TextMessage tm=s.createTextMessage();
tm.setText(messageData);
mp.send(tm);
} catch (Exception e) {
System.out.println("e");
}
}
}
when i deploy MDB super project and when i try to run html file as i keep geting error like cannot be depoyed.
ant -f C:\\Users\\saiganesh\\Docu
init:
deps-module-jar:
DemoMDB-ejb.init:
DemoMDB-ejb.deps-jar:
DemoMDB-ejb.compile:
DemoMDB-ejb.library-inclus
DemoMDB-ejb.dist:
deps-ear-jar:
deps-jar:
library-inclusion-in-archi
library-inclusion-in-manif
compile:
compile-jsps:
In-place deployment at C:\Users\saiganesh\Documen
GlassFish Server, deploy, null, false
C:\Users\saiganesh\Documen
See the server log for details.
BUILD FAILED (total time: 0 seconds)
i have to deploy sub projects ejb, war separately. not sure how to resove this issue as well. please advise
jmsStr.png
jms.png
nameQ.png
nameQ2.png
consoleGF.png
mdb22.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.