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 MQSeries

Post new topic  Reply to topic
 Using Servlet for MQSeries « View previous topic :: View next topic » 
Author Message
chanchalmalik
PostPosted: Tue Mar 16, 2004 6:55 am    Post subject: Using Servlet for MQSeries Reply with quote

Newbie

Joined: 16 Mar 2004
Posts: 3

Hey,
I am passing user name and password from a login HTML page to a Servlet which is accessing these parameters and then creating MQSeries message from this information.Its a very simple Servlet which I am not able to invoke after adding MQSEries code.Please take a look at Servlet code and let me know where I am wrong.Please help me.
-------------------------------------------------------------------------------------

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.ibm.mq.*;
import java.util.*;

public class MQSample11 extends HttpServlet {

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

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

out.println("<HTML>");
out.println("<HEAD><TITLE>Simple Servlet</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<H1>Sample MQ Servlet Test</H1>");

try
{

response.setContentType("text/html");
String tempAddress = "Input information is";
Enumeration enum = request.getParameterNames();
while (enum.hasMoreElements())
{
String name = (String) enum.nextElement();
String values = request.getParameter(name);
if(values != null)
{
tempAddress = tempAddress + "; " + name + ": " + values;

}

}
out.println(tempAddress);
// out.println("</BODY></HTML>");
MQQueueManager qMgr;
qMgr = new MQQueueManager("QM1");

int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
//Specify the queue that we wish to open, and the open options.
MQQueue ncOrderDataQ = qMgr.accessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE",openOptions);

//Define a MQ message
MQMessage customerAddress = new MQMessage();

customerAddress.writeUTF(tempAddress);

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

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

//Close the queue
ncOrderDataQ.close();
qMgr.disconnect();
MQQueueManager qMgr1;
qMgr1 = new MQQueueManager("QM1");


int openOptions1 = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;

//Specify the queue that we wish to open, and the open options.
MQQueue ncOrderUpdateQ = qMgr1.accessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE",openOptions1);

//create a new get the message
MQMessage retrievedMessage = new MQMessage();

retrievedMessage.messageId = MQC.MQMI_NONE;

//set the get message options
MQGetMessageOptions gmo = new MQGetMessageOptions();

//get the message off the queue
ncOrderUpdateQ.get(retrievedMessage, gmo);

//Display the message
String msgText;
msgText = retrievedMessage.readString(retrievedMessage.getMessageLength());
//for NC.UpdateQ
out.println(msgText);

//Close the queue
ncOrderUpdateQ.close();
qMgr1.disconnect();
}

catch(MQException ex)
{

}
out.println("</BODY></HTML>");

}




}
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Mar 16, 2004 6:59 am    Post subject: Re: Using Servlet for MQSeries Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

chanchalmalik wrote:
Please take a look at Servlet code and let me know where I am wrong.Please help me.
Please help us help you.
Please look at your code and add exception handling to catch the linked MQSeries exception and provide us the reason code.

Please look at your system error logs for MQSeries errors.

Please read the Using Java manual for more information about working with MQSeries from Java.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
chanchalmalik
PostPosted: Tue Mar 16, 2004 8:11 am    Post subject: Using Servlet for MQseries Reply with quote

Newbie

Joined: 16 Mar 2004
Posts: 3

Hey,
Its not giving any MQseries specific error.Thing is that I can invoke this servlet if I dont add any MQSeries code.It displays Servlet page but after adding MQSeries code in same servlet,it cannot find my page.Here is my Servlet code:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.ibm.mq.*;
import java.util.*;

/**
* <h2>JRun programming techniques application</h2>
* <p>Modify this servlet to test dynamic Servlet compilation.</p>
*/
public class MQSample11 extends HttpServlet {

/**
* This servlet creates a simple HTML page.
*
* @param HttpServletRequest - Request object
* @param HttpServletResponse - Response object
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

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

out.println("<HTML>");
out.println("<HEAD><TITLE>Simple Servlet</TITLE>");
out.println("</HEAD>");


out.println("<BODY>");
out.println("<H1>Sample MQ Servlet Test</H1>");
// out.println("</BODY></HTML>");



//try
//{
// MQQueueManager qMgr;
//qMgr = new MQQueueManager("QM1");

response.setContentType("text/html");
String tempAddress = "Input information is";
Enumeration enum = request.getParameterNames();
while (enum.hasMoreElements())
{
String name = (String) enum.nextElement();
String values = request.getParameter(name);
if(values != null)
{
tempAddress = tempAddress + "; " + name + ": " + values;

}

}
out.println(tempAddress);

try
{
MQQueueManager qMgr;
qMgr = new MQQueueManager("QM1");
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
//Specify the queue that we wish to open, and the open options.
MQQueue ncOrderDataQ = qMgr.accessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE",openOptions);

//MQQueueManager qMgr;
//qMgr = new MQQueueManager("QM1");
//Define a MQ message
MQMessage customerAddress = new MQMessage();

customerAddress.writeUTF(tempAddress);

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

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

//Close the queue
ncOrderDataQ.close();
qMgr.disconnect();
out.println("</BODY></HTML>");
}

catch(MQException e)
{
System.out.println("An MQSeries error occurred : Completion code " +e.completionCode + " Reason code " + e.reasonCode);
out.println("</BODY></HTML>");
}
}
}
Back to top
View user's profile Send private message
techno
PostPosted: Wed Mar 17, 2004 8:51 am    Post subject: Reply with quote

Chevalier

Joined: 22 Jan 2003
Posts: 429

Can you see any errors in your servlet engine/application server logs? You may be getting some unchecked exception. What is the application server you are using?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General Discussion » Using Servlet for MQSeries
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.