[jdom-interest] Please Help!
Molina, Alexis E
aemolina at kpmg.com
Wed Apr 4 09:38:33 PDT 2001
Laurent:
No, that's what is strange. There is not exception thrown, and no error
perse. It's just that from a command line program (TestClass.class) I get
the full string I want, but from an equivalent servlet
(GetSchedulerData.class) I only get a partial string. The servlet can't
seem to retieve all the data, but the other program can.
Alexis
-----Original Message-----
From: Laurent Bihanic [mailto:laurent.bihanic at atosorigin.com]
Sent: Wednesday, April 04, 2001 1:10 AM
To: Molina, Alexis E
Subject: Re: [jdom-interest] Please Help!
Any exception thrown?
Laurent
Molina, Alexis E wrote:
> Hello All:
> I'm in a serious jam here, and I'm hoping someone can help.
> I have created a class (SchedulerJDOMHandler.class) that uses SaxBuilder
to
> grab some data from an XML source, based on an ID I pass it.
> I have a servlet that invokes the getData() method of
> SchedulerJDOMHandler.class. The getData method should retrieve a list of
> values from the xml file, then append them to a url string as parameters,
> and return the final url string to the servlet.
> To test it, I also created a little program called TestClass.class. This
> program and servlet are virtually identical in their function.
>
> The problem is, when I run TestClass, it returns the final string
perfectly
> like so:
> C:\Program Files\Allaire\JRun\servers\default\cdnm\WEB-INF\classes>java
> TestClass
> ..../scheduler/config_scheduler.jsp?id="ftp.dc.viacom.com"&zone="North
> America - East"&mantype="Cisco Content Switch"&format="MIB"&pollfreq="5"
> &ftpurl="ftp://ftp.dc.viacom.com"&userid="user2"&pass="pass2"
>
> But, when I do the same thing from the servlet, it only returns what the
url
> string was initialzed to (like: ../scheduler/config_scheduler.jsp?), but
> without the appended parameter values grabbed from the XML source. For
> your convenience, I am pasting the code for the 3 classes below. Could
> someone please explain why TestClass.class get's the correct data returned
> to it, but the servlet (GetSchedulerData.class) doesn't? A serious
thanks,
> in advance, to anyone that can possibly help! If it would help to have
the
> XML file, please let me know and I'll be glad to post it as well.
>
> Appreciatively,
>
> Alexis Molina
> San Diego, CA
>
> import java.util.*;
> import java.net.*;
> import org.jdom.*;
> import org.jdom.input.SAXBuilder;
>
>
> public class SchedulerJDOMHandler
> {
>
> //public static String filePath = "scheduler_config.xml";
> //public static String idPassed = passedID;
>
> public static List callListData(String idPassed, String xmlUrl) throws
> JDOMException {
> return listData(xmlUrl, idPassed);
> }
>
> public static List listData(String xmlUrl, String passedID)
> throws JDOMException, NullPointerException {
>
> if (xmlUrl == null) {
> throw new NullPointerException("File Path must be non-null");
> }
>
> SAXBuilder builder = new SAXBuilder();
> // Load the entire document into memory
> // from the network or file system
> Document doc = builder.build(xmlUrl);
>
> // Descend the tree and find the Elements
> Element schedulersRoot = doc.getRootElement();
> List schedulers = schedulersRoot.getChildren("scheduler");
> Vector schedulerData = new Vector(schedulers.size());
> Iterator iterator = schedulers.iterator();
> while (iterator.hasNext()) {
> Object o = iterator.next();
> Element scheduler = (Element) o;
> try {
>
> Element id = scheduler.getChild("id");
> String idContent = id.getTextTrim();
> // Only grab content from record matching idPassed
> if(idContent.equals(passedID)) {
>
> schedulerData.addElement(idContent);
>
> Element zone = scheduler.getChild("zone");
> if (zone == null) continue;
> String zoneContent = zone.getTextTrim();
> schedulerData.addElement(zoneContent);
>
> Element manufacturerType =
> scheduler.getChild("manufacturertype");
> if (manufacturerType == null) continue;
> String manufacturerTypeContent =
> manufacturerType.getTextTrim();
> schedulerData.addElement(manufacturerTypeContent);
>
> Element format = scheduler.getChild("format");
> if (format == null) continue;
> String formatContent = format.getTextTrim();
> schedulerData.addElement(formatContent);
>
> Element pollingFrequency =
> scheduler.getChild("pollingfrequency");
> if (pollingFrequency == null) continue;
> String pollingFrequencyContent =
> pollingFrequency.getTextTrim();
> schedulerData.addElement(pollingFrequencyContent);
>
> Element ftpUrl = scheduler.getChild("ftpurl");
> if (ftpUrl == null) continue;
> String ftpUrlContent = ftpUrl.getTextTrim();
> schedulerData.addElement(ftpUrlContent);
>
> Element userID = scheduler.getChild("userid");
> if (userID == null) continue;
> String userIDContent = userID.getTextTrim();
> schedulerData.addElement(userIDContent);
>
> Element password = scheduler.getChild("password");
> if (password == null) continue;
> String passwordContent = password.getTextTrim();
> schedulerData.addElement(passwordContent);
> }
> }
> catch (Exception e) {
> }
> }
> return schedulerData;
>
> }
>
> public String getData(String idPassed, String xmlUrl, String UrlRoot)
> {
> //Create URL
> StringBuffer redirectURL = new StringBuffer(500);
> redirectURL.append(UrlRoot);
>
> try {
>
> List schedulerData;
> schedulerData = callListData(idPassed, xmlUrl);
>
> String strID = (String)schedulerData.get(0);
> String strZone = (String)schedulerData.get(1);
> String strManType = (String)schedulerData.get(2);
> String strFormat = (String)schedulerData.get(3);
> String strPollFreq = (String)schedulerData.get(4);
> String strFtpUrl = (String)schedulerData.get(5);
> String strUserID = (String)schedulerData.get(6);
> String strPass = (String)schedulerData.get(7);
>
> //Append parameters to redirectUrl
> redirectURL.append("id=\"" + strID + "\"&");
> redirectURL.append("zone=\"" + strZone + "\"&");
> redirectURL.append("mantype=\"" + strManType + "\"&");
> redirectURL.append("format=\"" + strFormat + "\"&");
> redirectURL.append("pollfreq=\"" + strPollFreq + "\"&");
> redirectURL.append("ftpurl=\"" + strFtpUrl + "\"&");
> redirectURL.append("userid=\"" + strUserID + "\"&");
> redirectURL.append("pass=\"" + strPass + "\"");
>
> //Return the Value
> return redirectURL.toString();
> }
> catch (JDOMException jdme) {
> System.out.println("JDOMException Occured :" +
> jdme.getMessage());
> jdme.printStackTrace();
> }
> catch (NullPointerException ne) {
> System.out.println("NullPointerException Occured :" +
> ne.getMessage());
> ne.printStackTrace();
> }
> catch (Exception e) {
> System.out.println("Some Exception Occured :" +
> e.getMessage());
> e.printStackTrace();
> }
> //Return the Value
> return redirectURL.toString();
> }
> }
> __________________________________
>
> import java.io.*;
> import java.util.*;
> import java.net.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class GetSchedulerData extends HttpServlet {
>
> public void init(ServletConfig config) throws ServletException
> {
> super.init( config );
> }
>
> public void destroy()
> {
> super.destroy();
> }
>
> public String getServletInfo()
> {
> return this.getClass().getName();
> }
>
> public void service(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException
> {
> // Set the content-type to HTML
> res.setContentType("text/html");
>
> // Get the PrintWriter for the servlet response
> PrintWriter out = res.getWriter();
>
> // Retrieve field values entered
> String schedulerID = req.getParameter("id");
> //String schedulerID = "ftp.la.viacom.com";
> String xmlUrl = "scheduler_config.xml";
> String redirectUrlRoot =
> "../scheduler/config_scheduler.jsp?";
>
> SchedulerJDOMHandler dataRetrieved = new
> SchedulerJDOMHandler();
> String finalRedirectUrl = dataRetrieved.getData(schedulerID,
> xmlUrl, redirectUrlRoot);
>
> try
> {
> //Redirect and Pass all Data Parameters
> out.println("Hell Yep!");
> out.println("<br>");
> out.println(finalRedirectUrl);
> out.println("<br>");
> out.println(schedulerID);
> //res.sendRedirect(finalRedirectUrl);
> }
> catch (Exception e)
> {
> out.println("Exception: " + e);
> }
> }
> }
> __________________________
>
> public class TestClass
> {
> public static void main(String[] args)
> {
>
> String schedulerID = "ftp.dc.viacom.com";
> String xmlUrl = "scheduler_config.xml";
> String redirectUrlRoot =
> "../scheduler/config_scheduler.jsp?";
>
> SchedulerJDOMHandler dataRetrieved = new
> SchedulerJDOMHandler();
> String finalRedirectUrl = dataRetrieved.getData(schedulerID,
> xmlUrl, redirectUrlRoot);
>
>
> System.out.println(finalRedirectUrl);
> }
> }
>
****************************************************************************
*
> The information in this email is confidential and may be legally
privileged.
> It is intended solely for the addressee. Access to this email by anyone
else
> is unauthorized.
>
> If you are not the intended recipient, any disclosure, copying,
distribution
> or any action taken or omitted to be taken in reliance on it, is
prohibited
> and may be unlawful. When addressed to our clients any opinions or advice
> contained in this email are subject to the terms and conditions expressed
in
> the governing KPMG client engagement letter.
>
****************************************************************************
*
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
*****************************************************************************
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorized.
If you are not the intended recipient, any disclosure, copying, distribution
or any action taken or omitted to be taken in reliance on it, is prohibited
and may be unlawful. When addressed to our clients any opinions or advice
contained in this email are subject to the terms and conditions expressed in
the governing KPMG client engagement letter.
*****************************************************************************
More information about the jdom-interest
mailing list