Hello,
        I'm having some problems getting a service to run on Axis 1.2.1 (Tomcat
5.0.28, Java 1.5.03, Linux).  I get the following error message:

java.lang.reflect.InvocationTargetException
        at
org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:221)
        at
org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:128)
        at
org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)


I know this has something to do with my code, because I can comment out
some of it and the error goes away.  I believe it has something to do
with Java 1.5 and XML parsing, because my service makes use of some XML
features new to Java 1.5.  Here is the code for my service, if this is
not readable, please view the code at
http://test.chronos.org:9090/SitemapDifference.jws

Any help would be great!

--Brice




import java.io.FileWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.InputSource;



/*
 * Created on Jul 13, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author blambi
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class SitemapDifference {

        String xsl="/home/common/sitemap/sitemap.xsl";
        
        /*public static void main(String args[])
        {
                try{
                        //String 
a="http://test.chronos.org:9090/sitemap-chronos.xml";;
                        //String 
b="http://test.chronos.org:9090/sitemap-chronos-after.xml";;
                        String 
a="file:///home/common/sitemap/sitemap-chronos.xml";
                        String 
b="file:///home/common/sitemap/sitemap-chronos-after.xml";
                        SitemapDifference sd=new SitemapDifference();
                FileWriter out=new FileWriter("out.txt");
                String x=sd.getDiff(a,b);
                String y=sd.getRss(x);
                out.write(y);
                out.close();
                }catch(Exception e){
                        e.printStackTrace();
                }
        }*/
        
        
        public String getRss(String fileA,String fileB)throws Exception
        {
                String xml=getDiff(fileA,fileB);
                DocumentBuilder
docb=DocumentBuilderFactory.newInstance().newDocumentBuilder();
                Document doc=docb.parse(new InputSource(new StringReader(xml)));
                StringWriter sw=new StringWriter();
                Source source=new DOMSource(doc);
                Source x=new StreamSource(xsl);
                Result r=new StreamResult(sw);
                Transformer 
tform=TransformerFactory.newInstance().newTransformer(x);
                tform.transform(source,r);
                return sw.toString();
        }
        
        private String getDiff(String fileA, String fileB)throws Exception
        {
                DocumentBuilder
docb=DocumentBuilderFactory.newInstance().newDocumentBuilder();
                Document a=docb.parse(fileA);
                Document b=docb.parse(fileB);

                NodeList listA=a.getElementsByTagName("url");
                NodeList listB=b.getElementsByTagName("url");
                Document diff=docb.newDocument();
                Node root=diff.createElement("urlset");
                for (int i=0;i<listA.getLength();i++)
                {
                        Node url=listA.item(i);
                        NodeList urlList=url.getChildNodes();
                        Node loc=urlList.item(1);
                        Node mod=urlList.item(3);
                        String locStr=loc.getTextContent();
                        String modStr=mod.getTextContent();
                        for (int j=0;j<listB.getLength();j++)
                        {
                                Node urlB=listB.item(j);
                                NodeList bList=urlB.getChildNodes();
                                Node locB=bList.item(1);
                                Node modB=bList.item(3);
                                String bVal=locB.getTextContent();
                                String bMod=modB.getTextContent();
                                if (locStr.equals(bVal)&&!modStr.equals(bMod))
                                {
                                        //Node imp=diff.importNode(urlB,true);
                                        //root.appendChild(imp);
                                        Node newUrl=diff.createElement("url");
                                        Node newLoc=diff.createElement("loc");
                                        Node 
newDate=diff.createElement("lastmod");
                                        Text 
newLocText=diff.createTextNode(bVal);
                                        Date today=new Date();
                                        SimpleDateFormat sdf=new 
SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss
Z");
                                        Text 
newDateText=diff.createTextNode(sdf.format(today));
                                        newLoc.appendChild(newLocText);
                                        newDate.appendChild(newDateText);
                                        newUrl.appendChild(newLoc);
                                        newUrl.appendChild(newDate);
                                        
//newUrl.appendChild(diff.importNode(bList.item(5),true));//priority node not 
necessary
                                        root.appendChild(newUrl);
                                        break;
                                }
                        }
                }
                diff.appendChild(root);
                StringWriter sw=new StringWriter();
                Source source=new DOMSource(diff);
        Result result=new StreamResult(sw);
        Transformer
tform=TransformerFactory.newInstance().newTransformer();
        tform.transform(source,result);
                return sw.toString();
        }
}


Reply via email to