Permalink
Browse files

Working to get msg consumer started.

  • Loading branch information...
1 parent 51d8c58 commit 4dea1b389a585539f5732646c8ca79d0ea3db275 ckaminsk committed Jun 19, 2012
View
No changes.
View
0 README
No changes.
@@ -3,14 +3,11 @@
import java.io.IOException;
import java.util.Properties;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NameClassPair;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
+import javax.jms.*;
+import javax.naming.*;
import javax.servlet.http.*;
-import com.sun.xml.rpc.processor.modeler.j2ee.xml.javaXmlTypeMappingType;
+//import com.sun.xml.rpc.processor.modeler.j2ee.xml.javaXmlTypeMappingType;
@SuppressWarnings("serial")
public class MainServlet extends HttpServlet {
@@ -28,7 +25,7 @@ private String getJMSNames() {
NameClassPair entry = (NameClassPair)ne.next();
System.out.println("name: " + entry.getName() + " class: " + entry.getClassName());
if ( retVal.length() > 0 ) retVal.append(";");
- retVal.append(entry.getName());
+ retVal.append("jms/" + entry.getName());
}
}
@@ -38,6 +35,44 @@ private String getJMSNames() {
return retVal.toString();
}
+
+ // TODO: Add authentication capabilities.
+ void runMessageListener(HttpServletRequest request, HttpServletResponse response) {
+ String connFactoryName = request.getParameter("ConnFactoryName");
+ String replyToName = request.getParameter("ReplyToName");
+ String replyToType = request.getParameter("ReplyToType");
+ InitialContext ctx = null;
+
+ try {
+ ctx = new InitialContext();
+ ConnectionFactory cfactory = (ConnectionFactory) ctx.lookup(connFactoryName);
+ Queue queue = (Queue) ctx.lookup (replyToName);
+
+ if ( null == cfactory ) System.out.println("no connection factory!");
+ if ( null == queue ) System.out.println("no queue!");
+ Connection conn = cfactory.createConnection();
+ Session msgSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer consumer = msgSession.createConsumer(queue);
+
+ conn.start();
+ while ( 1 ) {
+ // TODO: wait on exit flag
+ // TODO: make this a user-specifiable parameter.
+ Message msg = consumer.receive(1000);
+ }
+ conn.stop();
+
+ msgSession.close();
+ conn.close();
+ ctx.close();
+ } catch (NamingException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+
+ }
+ }
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
@@ -50,6 +85,8 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) {
} catch (IOException e) {
e.printStackTrace();
}
+ } else if (action.equals("jmsmessages") ) {
+ runMessageListener(request, response);
} else {
}
@@ -6,7 +6,7 @@
<script type="text/javascript">
$(document).ready(function() {
$.get('./jmsops/?action=jmsdata', function(data) {
- alert("data received: " + data);
+ alert("returned jmsdata equals: [" + data + "]");
});
});
</script>
@@ -19,6 +19,7 @@ Source: <select name="Source"> <option value="" /> </select> Custom: <input typ
ReplyTo: <select name="ReplyTo"> <option value=""/> </select> Custom: <input type="text" name="ReplyToCustom"/> <br/>
<input type="radio" name="ConnectionType" value="Queue">Queue</input>
<input type="radio" name="ConnectionType" value="Topic">Topic</input>
+<input type="submit" name="submitbutton" value="Start Listening"/>
<br/>
</body>

0 comments on commit 4dea1b3

Please sign in to comment.