Jump to content


Jonas Gozdecki

Member Since 29/03/2007
Offline Last Active 29/03/2007, 10:10
-----

Posts I've Made

In Topic: Instalação E Configuração Básica Do Tomcat

29/03/2007, 10:10

Saudações, Como faço pra configurar o context.xml para que o TopicConnectionFactory não fique out of bound,
e no meu HelloWorld.java:

InitialContext ic = new InitialContext();
TopicConnectionFactory tcf = (TopicConnectionFactory) ic.lookup("java:comp/env/TopicConnectionFactory");
TopicConnection tc = tcf.createTopicConnection();
TopicSession ts = (TopicSession) tc.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) ic.lookup("java:comp/env/topic/ui.message");
MessageProducer mp = ts.createProducer(topic);
mp.setDeliveryMode(DeliveryMode.PERSISTENT);


... eu não precise colocar esse: java:comp/env/ na fente do TopicConnectionFactory? já tentei de tudo...

eis os fontes completos abaixo pra vcs poderem testar:

Hello2.java

#######################################################################

package mypackage;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;

import javax.jms.TopicSession;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.jms.Message;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.catalina.User;



public final class Hello2 extends HttpServlet {


public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

response.setContentType("text/html");
PrintWriter writer = response.getWriter();

writer.println("<html>");
writer.println("<head>");
writer.println("<title>Sample Application Servlet Page</title>");
writer.println("</head>");
writer.println("<body bgcolor=white>");

writer.println("<table border=\"0\">");
writer.println("<tr>");
writer.println("<td>");
writer.println("<img src=\"images/tomcat.gif\">");
writer.println("</td>");
writer.println("<td>");
writer.println("<h1>Sample Application Servlet</h1>");
writer.println("This is the output of a servlet that is part of");
writer.println("the Hello, World application. It displays the");
writer.println("request headers from the request we are currently");
writer.println("processing.");
writer.println("</td>");
writer.println("</tr>");
writer.println("</table>");

writer.println("<table border=\"0\" width=\"100%\">");
Enumeration names = request.getHeaderNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
writer.println("<tr>");
writer.println(" <th align=\"right\">" + name + ":</th>");
writer.println(" <td>" + request.getHeader(name) + "</td>");
writer.println("</tr>");
}
writer.println("</table>");
writer.println("<H1> xpto</H1>");

try {
InitialContext ic = new InitialContext();
TopicConnectionFactory tcf = (TopicConnectionFactory) ic.lookup("java:comp/env/TopicConnectionFactory");
TopicConnection tc = tcf.createTopicConnection();
TopicSession ts = (TopicSession) tc.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) ic.lookup("java:comp/env/topic/ui.message");
MessageProducer mp = ts.createProducer(topic);
mp.setDeliveryMode(DeliveryMode.PERSISTENT);

ObjectMessage om = ts.createObjectMessage();
writer.println("<br> getTimeToLive= " + mp.getTimeToLive());

} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();

} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
writer.println("<br>e agora Jose</br>");
writer.println("</body>");
writer.println("</html>");

}


}

##########################################

context.xml

<Context path="/demo" docBase="${catalina.home}/webapps/sample" privileged="true"
antiResourceLocking="false" antiJARLocking="false">

<Manager pathname="java:comp/env" />

<ResourceLink name="serverType" global="serverType" type="java.lang.String"/>

<Resource name="cbrealm/RealmFactory" auth="Container" type="cv.security.realm.JNDIRealm" factory="cv.security.realm.JNDIRealmFactory" />

<Resource name="java:comp/env/ConnectionFactory" auth="Container" type="org.apache.activemq.ActiveMQConnectionFactory" description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory" brokerURL="vm://tech-bernardi2" brokerName="LocalActiveMQBroker"/>

<Resource name="TopicConnectionFactory" auth="Container" type="org.apache.activemq.ActiveMQConnectionFactory" description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory" brokerURL="vm://tech-bernardi2" brokerName="LocalActiveMQBroker"/>

<Resource name="topic/ui.message" auth="Container" type="org.apache.activemq.command.ActiveMQTopic" description="JMS Topic"
factory="org.apache.activemq.jndi.JNDIReferenceFactory" brokerURL="vm://tech-bernardi2" brokerName="LocalActiveMQBroker"/>


</Context>






É isso aí... quem tiver alguma idéia pra resolver esse problema do path, eu agradeço muito!!!

Flws

IPB Skin By Virteq