This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques and have Mario Casciaro & Luciano Mammino on-line!
See this thread for details.
Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Help with xml parsing xml stream getting this see below code and exception

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.net.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import jcifs.smb.*;
import java.util.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.apache.xerces.parsers.*;
//import javax.xml.parsers.*;
//import org.xml.sax.*;
public class pleasework extends HttpServlet {

URL url;
URLConnection urlConn;
DataOutputStream printout;
BufferedReader input;
String str;
String testing ="hello son";
Vector trade = new Vector(1,1);


public void init() throws ServletException {

System.out.println("TestServlet : init");
}
public void destroy() {
System.out.println("TestServlet : destroy");
}


public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
try
{
String user = req.getParameter("username");
String password = req.getParameter("password");

PrintWriter out = res.getWriter();


// URL of asp page.

url = new URL ("http://ssteward:5000");
// URL connection channel.
urlConn = url.openConnection();
// Let the run-time system (RTS) know that we want input.
urlConn.setDoInput (true);
// Let the RTS know that we want to do output.
urlConn.setDoOutput (true);
// No caching, we want the real thing.
urlConn.setUseCaches (false);
// Specify the content type.
urlConn.setRequestProperty("Content-Type", "application/InScope");

// Send POST output.
printout = new DataOutputStream (urlConn.getOutputStream ());

//send the content to the server.
// <InScopeLogin><UserName>"+user+"</UserName><Password>"+password+"</Password></InScopeLogin>
// <person sex="female"><firstname>Anna</firstname><lastname>Smith</lastname></person>


String content = "<?xml version=\"1.0\"?><methodCall><methodName>getFibonacci</methodName><params><param><value><i4>4</i4></value></param>< ;/params></methodCall>";
printout.writeBytes (content);
printout.flush ();
printout.close ();


// Get response data.


input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
InputStream in = urlConn.getInputStream();
while (null != ((str = input.readLine())))
{
System.out.println (str);
out.println(str);
}
System.out.println ("outside of while "+str);

InputSource source = new InputSource(in);
DOMParser parser = new DOMParser();
parser.parse(source);
Document document = parser.getDocument();

Element methodCall = document.getDocumentElement();
if (!methodCall.getTagName().equals("methodCall")) {
fault("Root element must be methodCall", 1);
return;
}

NodeList methodNames = methodCall.getElementsByTagName("methodName");
if (methodNames.getLength() != 1) {
fault("There must be exactly one method name element", 1);
return;
}

Node methodName = methodNames.item(0).getFirstChild();
if (methodName == null | | methodName.getNodeType() != Node.TEXT_NODE ) {
fault("No method name", 1);
return;
}

Text methodNameText = (Text) methodName;
if (!methodNameText.getData().trim().equals("Fibonacci")) {
fault("Unrecognized method name: " + methodNameText.getData(), 1);
return;
}

NodeList paramsList = methodCall.getElementsByTagName("params");
if (paramsList.getLength() != 1) {
fault("There must be exactly one params element", 1);
return;
}

Element params = (Element) paramsList.item(0);
NodeList paramList = params.getElementsByTagName("param");
if (paramList.getLength() != 1) {
fault("There must be exactly one param element", 1);
return;
}

Element param = (Element) paramList.item(0);
NodeList valueList = param.getElementsByTagName("value");
if (valueList.getLength() != 1) {
fault("There must be exactly one value element", 1);
return;
}

Element value = (Element) valueList.item(0);
NodeList intList = value.getChildNodes();
if (intList.getLength() != 1) {
fault("There must be exactly one int or i4 element", 1);
return;
}

String intString = intList.item(0).getFirstChild().getNodeValue();
System.out.println("Int string: " + intString);

// close the Input Stream
//input.close ();
in.close();

}
catch (SAXException e)
{
System.err.println(e.getMessage());
}
catch (IOException ioe)
{
System.out.println("11");
System.err.println(ioe.getMessage());
}

System.out.println ("-----------------------");

//doGet(req, res);
}

private void fault(String errorMessage, int code)throws IOException
{
System.out.println("Fault: " + errorMessage);
}

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

res.setContentType("text/html");

PrintWriter out = res.getWriter();

// print content

out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?><pwCmdXML><Command>SubmitJob</Command><CommandPassword>aPwd</CommandPassword><ProjectName>TheProject</ProjectName>& lt;ProjectType>pType</ProjectType><ObjectClass>stuff</ObjectClass><ObjectList>1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28, 29,30,31,32,33,34,35,36</ObjectList></pwCmdXML>");
out.flush();
out.close();

}


}
//////////////////Servlet Exception any ideas thansk///////////

A Servlet Exception Has Occurred
Exception Report:
javax.servlet.ServletException: Servlet execution threw an exception
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at filters.ExampleFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source)
at java.lang.Thread.run(Thread.java:484)
Root Cause:
java.lang.LinkageError: Class org/xml/sax/InputSource violates loader constraints
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at org.apache.xerces.readers.DefaultEntityHandler.startReadingFromDocument(DefaultEntityHandler.java:484)
at org.apache.xerces.framework.XMLParser.parseSomeSetup(XMLParser.java:303)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:860)
at pleasework.doPost(pleasework.java:110)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at filters.ExampleFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source)
at java.lang.Thread.run(Thread.java:484)

------------------
Sun Certified Java Programmer
Sun Certified Java Developer
I-Net Certified
A+ Certified
Network+ Certified
MCP
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic