What is wrong with this Servlet? It keeps telling me a method is undefined when it very clearly is....

Hello,
I have a servlet which renders xml data, and sends it out over http. I have built an object called XMLStructure which allows me to create the xml via functions, and then dump the xml text to various formats. Anyways, when I hit the servlet, I get this error:

StandardWrapperValve[xmlDataServices]: PWC1406: Servlet.service() for servlet xmlDataServices threw exception
java.lang.NoSuchMethodError: XMLStructure.getXMLText()Ljava/lang/String;
        at xmlDataServices.createServerData(xmlDataServices.java:247)
        at xmlDataServices.processRequest(xmlDataServices.java:89)
        at xmlDataServices.doPost(xmlDataServices.java:332)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)

Now normally this would mean that the getXMLText() function im using doesnt  exist... but here's the thing. It very clearly does... see the class below.

Here is an example of the usage, and where the error occurs:


XMLStructure serverData = new XMLStructure();

serverData.putValue("root/data","some data");

out.print(serverData.getXMLText()); // <!---- this is the equivalent of the line that throws the exception


A correct fix for this problem is worth 500 points.

Thanks,
Rick
/*
 * XMLStructure.java
 *
 * Created on April 8, 2007, 6:52 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
 
 
 
//VoipTrix BroadcastPBX 
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
import javax.xml.parsers.DocumentBuilderFactory;  
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;  
import org.w3c.dom.*;
import javax.xml.xpath.*;
import java.util.*;
import javax.xml.transform.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import java.net.*;
import java.io.*;
 
/**
 *
 * @author Rick
 */
public class XMLStructure
{
    private Document data;
    
    /** Creates a new instance of XMLStructure */
    public XMLStructure()
    {
        //create a new Blank Structure
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();    	
    	try 
        {
            DocumentBuilder builder = factory.newDocumentBuilder();
            data = builder.newDocument();
            Element root = data.createElement("root");
            data.appendChild(root);
            
	 }
	 catch (ParserConfigurationException pce) 
         {
	       // Parser with specified options can't be built
	       System.out.println("Error initializing config.xml parser. " + pce.getMessage());
	 }
    }
    
    public XMLStructure(String xml)
    {
        //create a structure from the passed XML
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    	
        //System.out.println("XML DATA:\n\n" + xml);
        
                try 
                {
                    DocumentBuilder builder = factory.newDocumentBuilder();
                    data = builder.parse(new ByteArrayInputStream(xml.getBytes()));
                }
		catch (SAXException sxe) 
		{
                    System.out.println("XMLSAX:" + sxe.getMessage());
		} 
		catch (ParserConfigurationException pce) 
		{
                    System.out.println("XMLPCE:" + pce.getMessage());
                }
		catch (IOException ioe)
		{
                    System.out.println("IO:" + ioe.getMessage());
                }
    }
    
    public String getXMLText()
    {
        //returns the xml structure as a URL Encoded String
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        
        StringWriter stringOut = new StringWriter();
        
        Result r = new StreamResult(stringOut);
        
        try
        {
            Transformer serializer = transformerFactory.newTransformer();
            serializer.transform(new DOMSource(data),r);
        }
        catch (Exception e)
        {
            System.out.println("Exception converting XML.\n\n\n");
        }
        
        return stringOut.toString();
    }
    
    public String getValueList(String key)
    {
    	String valuelist="";
    	
    	try
    	{
    		 XPath xpath = XPathFactory.newInstance().newXPath();
    		 NodeList nodeList = (NodeList) xpath.evaluate(key, data, XPathConstants.NODESET);
    		 for (int i = 0; i < nodeList.getLength(); i++)
    			 valuelist = valuelist + nodeList.item(i).getNodeName() + ",";
    	}
    	catch (XPathExpressionException e) 
        {
		//System.out.println("Error while retrieving valuelist for " + key);
		valuelist = null;
	}
    	
        if (valuelist.length() > 0)
            return valuelist.substring(0,valuelist.length()-1);
        else
            return "";
    }
    
    private Node getNode(String path) throws Exception
    {
        XPath xpath = XPathFactory.newInstance().newXPath();
        Node widgetNode = (Node) xpath.evaluate(path, data, XPathConstants.NODE);
        return widgetNode;
    }
    
    public boolean pathExists(String path)
    {
        try
        {
            XPath xpath = XPathFactory.newInstance().newXPath();
            return ((Node) xpath.evaluate(path, data, XPathConstants.NODE) != null);
        }
        catch(Exception e)
        {
            return false;
        }
    }
    
     public void removeValue(String xpath)
    {
        //remove a reference in the XML tree
        try
        {
           Node node = getNode(xpath);
           node.getParentNode().removeChild(node);
        }
        catch (Exception e)
        {
        }
    }
    
     public void putValue(String path, String value)
    {
         try
         {
          if (pathExists(path))
          {
              String keys[] = path.split("/");
              Element newNode = data.createElement(keys[keys.length-1]);
              newNode.setTextContent(value.replaceAll("\\\\","/"));
              Node node = getNode(generateNewPath(keys,keys.length-2));
              node.replaceChild(newNode,getNode(path));
          }
          else
          {
              //the path doesnt exist so lets drill down and add them as we need to
              String keys[] = path.split("/");
              
              for (int i = 0; i < keys.length; i++)
                  if (!pathExists(generateNewPath(keys,i)))
                  {
                        //create the new node
                        Element newNode = data.createElement(keys[i]);
                        Node node = getNode(generateNewPath(keys,i-1));
                        if (i == (keys.length - 1))
                            newNode.setTextContent(value.replaceAll("\\\\","/"));
                        node.appendChild((Node) newNode);
                  }
          }
         }
         catch(Exception e)
         {
            System.out.println("There was an error putting the config value.\n " + e.getMessage());
         }
    }
    
    private String generateNewPath(String nodes[],int index)
    {
        //generate a new xmlpath based on the nodes array and index
        String retVal = "";
        retVal = nodes[0];
        for (int j = 1; j <= index; j++)
           retVal += "/" + nodes[j];      
        return retVal;
    }
 
    public String getValue(String key)
    {
	String value="";
	//return the value associated with given XML Path
	try 
	{
            value=(getNode(key)).getFirstChild().getNodeValue();
        } 
        catch (Exception e) 
        {
	}	
        return value;
    }
     
    public Hashtable getValueHash(String key)
    {
        Hashtable retVal = new Hashtable();
        
        //get a list of all the corresponding values in this record
        String[] columns = getValueList(key + "/*").split(",");
        
        for (int i = 0; i < columns.length; i++)
            retVal.put(columns[i],getValue(key + "/" + columns[i]));
        
        return retVal;
    }
 
    public String getXMLURLText()
    {
        //returns the xml structure as a URL Encoded String
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        
        StringWriter stringOut = new StringWriter();
        
        Result r = new StreamResult(stringOut);
        
        try
        {
            Transformer serializer = transformerFactory.newTransformer();
            serializer.transform(new DOMSource(data),r);
        }
        catch (Exception e)
        {
            System.out.println("Exception converting XML.\n\n\n");
        }
        
        return URLEncoder.encode(stringOut.toString());
    }
    
     public boolean loadXML(String filetoload)
	{
    	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    	boolean error = true;
    	
    	try 
	{
			DocumentBuilder builder = factory.newDocumentBuilder();
			data = builder.parse(new File(filetoload));	
	}
	catch (SAXException sxe) 
	{
		System.out.println("Invalid XML construct found in config.xml. " + sxe.getMessage());
		error = false;
	} 
	catch (ParserConfigurationException pce) 
	{
	      // Parser with specified options can't be built
	      System.out.println("Error initializing config.xml parser. " + pce.getMessage());
	      error = false;
	}
	catch (IOException ioe)
	{
	       // I/O error
	       System.out.println(ioe.getMessage());
	       error=false;
	}
	    		
	    return error;
	}
    
   public void writeXML(String filetowrite)
   {
           try 
           {
            // Prepare the DOM document for writing
            Source source = new DOMSource(data);
    
            // Prepare the output file
            File file = new File(filetowrite);
            Result result = new StreamResult(file);
    
            // Write the DOM document to the file
            Transformer xformer = TransformerFactory.newInstance().newTransformer();
            xformer.transform(source, result);
           } catch (TransformerConfigurationException e) {
           } catch (TransformerException e) {
        }
   }
}

Open in new window

richardsimnettAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bart CremersJava ArchitectCommented:
My best guess in this case is that the XMLStructure class evolved and the method getXMLText is new or changed signature.

It looks to me the new servlet was compiled against the correct class and got deployed correctly, while somehow the servlet container still loads and uses the old XMLStructure class.

If this is the case you'll have to look in the servlet container's classpath and check out where the XMLStructure class exists (possibly more then one place).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ragerinoCommented:
I think Bart Cr is right. maybe you should delete the work-directory of your server.

here's the procedure for a regular tomcat installation deploying a war-file:
- shutdown tomcat
- delete the folder and the war-file of your webapplication in te webapps-directory found in the tomcat-directory
- delete the work-folder in your tomcat-directory
- copy the new war-file to the webapps-directory
- restart your server

to be on the secure side you should move the files/folders to som temp-directory or backup your tomcat-directory if something goes wrong
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.