[EJB/JBoss] - The requested resource (/NewsApp-war/ListNews) is not availa
by badhikary81
Hi!
I am Basudev.
I am trying to run a simple enterprise application. My application's name is 'NewsApp' and I have used jboss-5.0.0.Beta4 , jdk1.6.0 and Netbean IDE 6.1.When I run my application then server throw the requested resource (/NewsApp-war/ListNews) is not available.
Here is my code
1.ListNews.java
package web;
import ejb.NewsEntity;
import ejb.NewsEntityFacadeLocal;
import java.io.*;
//import java.net.*;
import java.util.Iterator;
import java.util.List;
import javax.ejb.EJB;
import javax.servlet.*;
import javax.servlet.http.*;
public class ListNews extends HttpServlet {
@EJB
private NewsEntityFacadeLocal newsEntityFacade;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("");
out.println("");
out.println("Servlet ListNews");
out.println("");
out.println("");
out.println("<h1>Servlet ListNews at " + request.getContextPath () + "</h1>");
//newsEntityFacade = (NewsEntityFacadeLocal) lookupNewsEntityFacade();
List news = newsEntityFacade.findAll();
for (Iterator it = news.iterator(); it.hasNext();) {
NewsEntity elem = (NewsEntity) it.next();
out.println(" "+elem.getTitle()+" ");
out.println(elem.getBody()+" ");
}
out.println("Add new message");
out.println("");
out.println("");
} finally {
out.close();
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
/*private ejb.NewsEntityFacadeLocal lookupNewsEntityFacade() {
try {
javax.naming.Context c = new javax.naming.InitialContext();
return (ejb.NewsEntityFacadeLocal) c.lookup("NewsApp/NewsEntityFacade/local");
}
catch(javax.naming.NamingException ne) {
java.util.logging.Logger.getLogger(getClass().
getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
throw new RuntimeException(ne);
}
}*/
// </editor-fold>
}
postMessage.java
package web;
import ejb.NewsEntity;
import java.io.*;
//import java.net.*;
import java.util.Queue;
import javax.jms.Destination;
import javax.jms.JMSException;
//import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSession;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.jms.MessageProducer;
public class PostMessage extends HttpServlet {
/**
* Processes requests for both HTTP GET and POST methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String title=request.getParameter("title");
String body=request.getParameter("body");
if ((title!=null) && (body!=null)) {
Queue queue = null;
QueueConnection connection = null;
QueueSession session = null;
MessageProducer messageProducer = null;
try {
InitialContext ctx = new InitialContext();
queue = (Queue) ctx.lookup("queue/mdb");
QueueConnectionFactory factory =
(QueueConnectionFactory) ctx.lookup("ConnectionFactory");
connection = factory.createQueueConnection();
session = connection.createQueueSession(false,
QueueSession.AUTO_ACKNOWLEDGE);
messageProducer = session.createProducer((Destination) queue);
ObjectMessage message = session.createObjectMessage();
// here we create a NewsEntity, that will be sent in JMS message
NewsEntity e = new NewsEntity();
e.setTitle(title);
e.setBody(body);
message.setObject(e);
messageProducer.send(message);
messageProducer.close();
connection.close();
response.sendRedirect("ListNews");
} catch (JMSException ex) {
ex.printStackTrace();
} catch (NamingException ex) {
ex.printStackTrace();
}
}
PrintWriter out = response.getWriter();
try {
out.println("");
out.println("");
out.println("Servlet PostMessage");
out.println("");
out.println("");
out.println("<h1>Servlet PostMessage at " + request.getContextPath () + "</h1>");
out.println("");
out.println("Title: ");
out.println("Message: ");
out.println("");
out.println("");
out.println("");
out.println("");
} finally {
out.close();
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
// </editor-fold>
}
NewsEntity.java
package ejb;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class NewsEntity implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String title;
private String body;
public void setId(Long id) {
this.id = id;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof NewsEntity)) {
return false;
}
NewsEntity other = (NewsEntity) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "ejb.NewsEntity[id=" + id + "]";
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
}
NewMessageBean.java
package ejb;
import javax.annotation.Resource;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenContext;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@MessageDriven(mappedName = "jms/NewMessage", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/mdb")
})
public class NewMessageBean implements MessageListener {
@Resource
private MessageDrivenContext mdc;
@PersistenceContext
private EntityManager em;
public NewMessageBean() {
}
public void onMessage(Message message) {
ObjectMessage msg = null;
try {
if (message instanceof ObjectMessage) {
msg = (ObjectMessage) message;
NewsEntity e = (NewsEntity) msg.getObject();
save(e);
}
} catch (JMSException e) {
e.printStackTrace();
mdc.setRollbackOnly();
} catch (Throwable te) {
te.printStackTrace();
}
}
public void save(Object object) {
em.persist(object);
}
}
NewsEntityFacade.java
package ejb;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
*
* @author Administrator
*/
@Stateless
public class NewsEntityFacade implements NewsEntityFacadeLocal {
@PersistenceContext
private EntityManager em;
public void create(NewsEntity newsEntity) {
em.persist(newsEntity);
}
public void edit(NewsEntity newsEntity) {
em.merge(newsEntity);
}
public void remove(NewsEntity newsEntity) {
em.remove(em.merge(newsEntity));
}
public NewsEntity find(Object id) {
return em.find(ejb.NewsEntity.class, id);
}
public List findAll() {
return em.createQuery("select object(o) from NewsEntity as o").getResultList();
}
}
please Sir I need help.Where is my fault?How can solve it?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4146715#4146715
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4146715
17 years, 12 months
[Installation, Configuration & DEPLOYMENT] - running EJB pplication in jboss giving NoClassDefFoundError
by Shiveeta
Hi,
I am a new user of jboss. I tried deploying a sample EJB apllication by following the tutorial at :- http://www.huihoo.org/jboss/online_manual/2.4/ch01s15.html . I was able to deploy the application in jboss <4.2.2GA> . but on calling EJB via a simple client, I face the following exception :-
interest-client:
[java] hi
[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss
/logging/Logger
[java] at org.jnp.interfaces.NamingContext.(NamingContext.java:
143)
[java] at org.jnp.interfaces.NamingContextFactory.getInitialContext(Nam
ingContextFactory.java:41)
[java] at javax.naming.spi.NamingManager.getInitialContext(NamingManage
r.java:667)
[java] at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.
java:247)
[java] at javax.naming.InitialContext.init(InitialContext.java:223)
[java] at javax.naming.InitialContext.(InitialContext.java:175)
[java] at org.jboss.docs.interest.InterestClient.main(InterestClient.ja
va:30)
[java] Java Result: 1
I tried googling and my classpath has jbossall-client.jar in it. However still facing this problem.
The client code is :-
package org.jboss.docs.interest;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import org.jboss.docs.interest.Interest;
import org.jboss.docs.interest.InterestHome;
/** This simple application tests the 'Interest' Enterprise JavaBean which is
implemented in the package 'org.jboss.docs.interest'. For this to work, the
Bean must be deployed on an EJB server.
*/
class InterestClient
{
/** This method does all the work. It creates an instance of the Interest EJB on
the EJB server, and calls its `calculateCompoundInterest()' method, then prints
the result of the calculation.
*/
public static void main(String[] args)
{
System.out.println("hi");
// Enclosing the whole process in a single `try' block is not an ideal way
// to do exception handling, but I don't want to clutter the program up
// with catch blocks
InitialContext jndiContext=null;
try
{
// Get a naming context
jndiContext = new InitialContext();
System.out.println("Got context");
}
catch(Exception e)
{
System.out.println("I am here!!");
e.printStackTrace();
}
try
{
// Get a reference to the Interest Bean
Object ref = jndiContext.lookup("interest/Interest");
System.out.println("Got reference");
// Get a reference from this to the Bean's Home interface
InterestHome home = (InterestHome)
PortableRemoteObject.narrow(ref, InterestHome.class);
// Create an Interest object from the Home interface
Interest interest = home.create();
// call the calculateCompoundInterest() method to do the calculation
System.out.println("Interest on 1000 units, at 10% per period, compounded over 2 periods is:");
System.out.println(interest.calculateCompoundInterest(1000, 0.10, 2));
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
Please guide in this ...Any help would be apprecitated. Thanks in advance.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4146712#4146712
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4146712
17 years, 12 months
[JBoss Messaging] - Re: JOBSS Messaging POC
by ssjboss
F:\jms\jboss messaging\jboss-messaging-1.4.0.SP3\examples\queue>ant
| Buildfile: build.xml
|
| identify:
| [echo] ####################################################################
| #######
| [echo] # Running the QUEUE example
| #
| [echo] ####################################################################
| #######
| [echo] The queue: testQueue
| [echo] The client jar: ../..//jboss-messaging-client.jar
|
| sanity-check:
|
| init:
|
| compile:
| [javac] Compiling 1 source file to F:\jms\jboss messaging\jboss-messaging-1.
| 4.0.SP3\examples\queue\output\classes
|
| run:
| [java] Queue /queue/testQueue exists
| [java] The message was successfully sent to the testQueue queue
| [java] Received message: Hello!
| [java] The example connected to JBoss Messaging version 1.4.0.SP3 (1.4)
| [java]
| [java]
| [java] #####################
| [java] ### SUCCESS! ###
| [java] #####################
|
| BUILD SUCCESSFUL
| Total time: 4 seconds
| F:\jms\jboss messaging\jboss-messaging-1.4.0.SP3\examples\queue>ant
| Buildfile: build.xml
|
| identify:
| [echo] ####################################################################
| #######
| [echo] # Running the QUEUE example
| #
| [echo] ####################################################################
| #######
| [echo] The queue: testQueue
| [echo] The client jar: ../..//jboss-messaging-client.jar
|
| sanity-check:
|
| init:
|
| compile:
|
| run:
| [java] javax.naming.CommunicationException: Could not obtain connection to
| any of these urls: 10.12.170.180:1099 and discovery failed with error: javax.nam
| ing.CommunicationException: Receive timed out [Root exception is java.net.Socket
| TimeoutException: Receive timed out] [Root exception is javax.naming.Communicati
| onException: Failed to connect to server 10.12.170.180:1099 [Root exception is j
| avax.naming.ServiceUnavailableException: Failed to connect to server 10.12.170.1
| 80:1099 [Root exception is java.net.ConnectException: Connection refused: connec
| t]]]
| [java] at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:
| 1562)
| [java] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:63
| 4)
| [java] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:62
| 7)
| [java] at javax.naming.InitialContext.lookup(InitialContext.java:351)
| [java] at org.jboss.example.jms.common.Util.doesDestinationExist(Util.j
| ava:55)
| [java] at org.jboss.example.jms.common.ExampleSupport.setup(ExampleSupp
| ort.java:214)
| [java] at org.jboss.example.jms.common.ExampleSupport.setup(ExampleSupp
| ort.java:194)
| [java] at org.jboss.example.jms.common.ExampleSupport.run(ExampleSuppor
| t.java:146)
| [java] at org.jboss.example.jms.queue.QueueExample.main(QueueExample.ja
| va:135)
| [java] Caused by: javax.naming.CommunicationException: Failed to connect to
| server 10.12.170.180:1099 [Root exception is javax.naming.ServiceUnavailableExc
| eption: Failed to connect to server 10.12.170.180:1099 [Root exception is java.n
| et.ConnectException: Connection refused: connect]]
| [java] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java
| :274)
| [java] at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:
| 1533)
| [java] ... 8 more
| [java] Caused by: javax.naming.ServiceUnavailableException: Failed to conne
| ct to server 10.12.170.180:1099 [Root exception is java.net.ConnectException: Co
| nnection refused: connect]
| [java] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java
| :248)
| [java] ... 9 more
| [java] Caused by: java.net.ConnectException: Connection refused: connect
| [java] at java.net.PlainSocketImpl.socketConnect(Native Method)
| [java] at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
| [java] at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.jav
| a:195)
| [java] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
| [java] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:364)
| [java] at java.net.Socket.connect(Socket.java:507)
| [java] at java.net.Socket.connect(Socket.java:457)
| [java] at java.net.Socket.<init>(Socket.java:365)
| [java] at java.net.Socket.<init>(Socket.java:265)
| [java] at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocke
| tFactory.java:84)
| [java] at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocke
| tFactory.java:77)
| [java] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java
| :244)
| [java] ... 9 more
| [java]
| [java] #####################
| [java] ### FAILURE! ###
| [java] #####################
|
| BUILD FAILED
| F:\jms\jboss messaging\jboss-messaging-1.4.0.SP3\examples\queue\build.xml:81: Ja
| va returned: 1
|
| Total time: 8 seconds
|
|
| i am getting above error, please help me
|
| --------
| -SS
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4146702#4146702
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4146702
17 years, 12 months
[JBoss Messaging] - Re: JOBSS Messaging POC
by ssjboss
F:\jms\jboss messaging\jboss-messaging-1.4.0.SP3\examples\queue>ant
Buildfile: build.xml
identify:
[echo] ####################################################################
#######
[echo] # Running the QUEUE example
#
[echo] ####################################################################
#######
[echo] The queue: testQueue
[echo] The client jar: ../..//jboss-messaging-client.jar
sanity-check:
init:
compile:
[javac] Compiling 1 source file to F:\jms\jboss messaging\jboss-messaging-1.
4.0.SP3\examples\queue\output\classes
run:
[java] Queue /queue/testQueue exists
[java] The message was successfully sent to the testQueue queue
[java] Received message: Hello!
[java] The example connected to JBoss Messaging version 1.4.0.SP3 (1.4)
[java]
[java]
[java] #####################
[java] ### SUCCESS! ###
[java] #####################
BUILD SUCCESSFUL
Total time: 4 seconds
F:\jms\jboss messaging\jboss-messaging-1.4.0.SP3\examples\queue>ant
Buildfile: build.xml
identify:
[echo] ####################################################################
#######
[echo] # Running the QUEUE example
#
[echo] ####################################################################
#######
[echo] The queue: testQueue
[echo] The client jar: ../..//jboss-messaging-client.jar
sanity-check:
init:
compile:
run:
[java] javax.naming.CommunicationException: Could not obtain connection to
any of these urls: 10.12.170.180:1099 and discovery failed with error: javax.nam
ing.CommunicationException: Receive timed out [Root exception is java.net.Socket
TimeoutException: Receive timed out] [Root exception is javax.naming.Communicati
onException: Failed to connect to server 10.12.170.180:1099 [Root exception is j
avax.naming.ServiceUnavailableException: Failed to connect to server 10.12.170.1
80:1099 [Root exception is java.net.ConnectException: Connection refused: connec
t]]]
[java] at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:
1562)
[java] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:63
4)
[java] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:62
7)
[java] at javax.naming.InitialContext.lookup(InitialContext.java:351)
[java] at org.jboss.example.jms.common.Util.doesDestinationExist(Util.j
ava:55)
[java] at org.jboss.example.jms.common.ExampleSupport.setup(ExampleSupp
ort.java:214)
[java] at org.jboss.example.jms.common.ExampleSupport.setup(ExampleSupp
ort.java:194)
[java] at org.jboss.example.jms.common.ExampleSupport.run(ExampleSuppor
t.java:146)
[java] at org.jboss.example.jms.queue.QueueExample.main(QueueExample.ja
va:135)
[java] Caused by: javax.naming.CommunicationException: Failed to connect to
server 10.12.170.180:1099 [Root exception is javax.naming.ServiceUnavailableExc
eption: Failed to connect to server 10.12.170.180:1099 [Root exception is java.n
et.ConnectException: Connection refused: connect]]
[java] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java
:274)
[java] at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:
1533)
[java] ... 8 more
[java] Caused by: javax.naming.ServiceUnavailableException: Failed to conne
ct to server 10.12.170.180:1099 [Root exception is java.net.ConnectException: Co
nnection refused: connect]
[java] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java
:248)
[java] ... 9 more
[java] Caused by: java.net.ConnectException: Connection refused: connect
[java] at java.net.PlainSocketImpl.socketConnect(Native Method)
[java] at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
[java] at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.jav
a:195)
[java] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
[java] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:364)
[java] at java.net.Socket.connect(Socket.java:507)
[java] at java.net.Socket.connect(Socket.java:457)
[java] at java.net.Socket.(Socket.java:365)
[java] at java.net.Socket.(Socket.java:265)
[java] at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocke
tFactory.java:84)
[java] at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocke
tFactory.java:77)
[java] at org.jnp.interfaces.NamingContext.getServer(NamingContext.java
:244)
[java] ... 9 more
[java]
[java] #####################
[java] ### FAILURE! ###
[java] #####################
BUILD FAILED
F:\jms\jboss messaging\jboss-messaging-1.4.0.SP3\examples\queue\build.xml:81: Ja
va returned: 1
Total time: 8 seconds
i am getting above error, please help me
--------
-SS
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4146701#4146701
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4146701
17 years, 12 months