ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General Discussion » Using servlet for MQ

Post new topic  Reply to topic
 Using servlet for MQ « View previous topic :: View next topic » 
Author Message
chanchal
PostPosted: Wed Mar 17, 2004 1:25 pm    Post subject: Using servlet for MQ Reply with quote

Apprentice

Joined: 30 Jan 2004
Posts: 38

Hey,I am passing some parameters from a form to a Servlet and in Servlet I am creating a MQSeries message from form parameters and putting this message on queue.When servlet is invoked then it gives following error:
-----------------------------------------------------------------------------------

HTTP ERROR: 500 com/ibm/mq/MQException
RequestURI=/jmx-console/servlet/ServletMQ

----------------------------------------------------------------------------------

Here is my Servlet code:Its small example.Please take a look at this and tell me where I am wrong.

-----------------------------------------------------------------------------

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.ibm.mq.*; //include the MQ package



public class ServletMQ extends javax.servlet.http.HttpServlet {

private String qManager = "QM1"; //name of queue manager to connect to

private MQQueueManager qMgr; //define a queue manager object

public ServletMQ() {
super();
}

public void destroy() {
System.out.println("In destroy()");
try
{
//Disconnect from the queue manager
qMgr.disconnect();
}
catch (MQException ex)
{
System.out.println("An MQ error occourred: Completion code " + ex.completionCode + " Reason code" + ex.reasonCode);
}

System.out.println("out of destroy()");
}

public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{

String tempAddress = "Input information is";
res.setContentType("text/plain");
PrintWriter out = res.getWriter();

if ("application/x-www-form-urlencoded".equals(req.getContentType())) {
out.println("In doPost()");
Enumeration enum = req.getParameterNames();
while (enum.hasMoreElements()) {
String name = (String) enum.nextElement();
String values = req.getParameter(name);
if(values != null) {
tempAddress = tempAddress + "; " + name + ": " + values;
}

}
out.println(tempAddress);

try {
//calling to put the order
out.println("Calling putOrder()");
putOrder(tempAddress);


}
catch (Exception ex)
{
out.println("Exception caught in doPost()");
ex.printStackTrace();
}

}

out.println("out of doPost()");

}

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

String tempAddress = "Input information is";
res.setContentType("text/plain");
PrintWriter out = res.getWriter();

if ("application/x-www-form-urlencoded".equals(req.getContentType())) {
System.out.println("In doPost()");
Enumeration enum = req.getParameterNames();
while (enum.hasMoreElements()) {
String name = (String) enum.nextElement();
String values = req.getParameter(name);
if(values != null) {
tempAddress = tempAddress + "; " + name + ": " + values;
}

}
System.out.println(tempAddress);

try {
//calling to put the order
System.out.println("Calling putOrder()");
putOrder(tempAddress);


}
catch (Exception ex)
{
System.out.println("Exception caught in doPost()");
ex.printStackTrace();
}

}

System.out.println("System.out of doGet()");

}


public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
//Create a connection to the queue manager
System.out.println("Create a connection to the queue manager");
qMgr = new MQQueueManager("QM1");
System.out.println("Connection created in init()");

}
catch (MQException ex)
{
System.out.println("An MQ error occourred in init(): Completion code " + ex.completionCode + " Reason code" + ex.reasonCode);
try {
if (qMgr != null)
//Disconnect from the queue manager
qMgr.disconnect();
}
catch (MQException e)
{
System.out.println("An MQ error occourred in init() while disconnecting: Completion code " + e.completionCode + " Reason code" + e.reasonCode);
}
}

}

public void putOrder(String tempAddress) {
try {
System.out.println("In putOrder()");
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;

//Specify the queue that we wish to open, and the open options.
System.out.println("Specifying the queue that we wish to open, and the open options.");

MQQueue ncOrderDataQ = qMgr.accessQueue("LQ1",openOptions);
//Define a MQ message
System.out.println("Define a MQ message");
MQMessage customerAddress = new MQMessage();

System.out.println("tempAddress =" + tempAddress);

customerAddress.writeUTF(tempAddress);

//specify the message options
MQPutMessageOptions pmo = new MQPutMessageOptions();

//put the message on the queue
ncOrderDataQ.put(customerAddress, pmo);

System.out.println("Put message done");

//Close the queue
ncOrderDataQ.close();

}
catch (MQException ex)
{
System.out.println("An MQ error occourred: Completion code " + ex.completionCode +
" Reason code" + ex.reasonCode);
System.out.println("disconnecting in doPost()");
try {
if (qMgr != null)
//Disconnect from the queue manager
qMgr.disconnect();
}
catch (MQException e)
{

System.out.println("An MQ error occourred while disconnecting in doPost(): Completion code " + e.completionCode +
" Reason code" + e.reasonCode);
}


}
catch (java.io.IOException ex)
{
System.out.println("An error occourred while writing to the message buffer: " + ex);
System.out.println("disconnecting in doPost()");
try {
if (qMgr != null)
//Disconnect from the queue manager
qMgr.disconnect();
}
catch (MQException ep)
{
System.out.println("An MQ error occourred while disconnecting in doPost(): Completion code " + ep.completionCode +
" Reason code" + ep.reasonCode);
}
}


System.out.println("System.out of putOrder()");

}
}

-----------------------------------------------------------------------------
Back to top
View user's profile Send private message
bower5932
PostPosted: Thu Mar 18, 2004 7:56 am    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

I've never messed with servlets. My advice would be to find the exact line that it is failing on and let us know what it is. It would also be nice to know the exact failure that is happening.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General Discussion » Using servlet for MQ
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.