Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Invalid XML error...Newbie question

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to send an XML to a SERVLET using the POST method and I run into a problem.

I am trying to integrate a login component written by another team. They have a test client which shows the XML that will be sent to the servlet. Their input xml and mine matches exactly.
I know that I am forming the input XML correctly, because if I go to http://app.com/test.jsp and replace the XML in the textbox with the XML I create in my code, it always gives me back a good response.

I am using standard POST request in my code, nothing special, so I am lost as to why this happens.

input xml from my code
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<Credentials>
<UserID>smhsrvuser1</UserID>
<Password>{SSHA}CoM8yMtxnTy8BR2PmOjkbe/c2vccHF+3w==</Password>
</Credentials>
<Data>
<Action>23</Action>
<ESELoginID>vrangaraj</ESELoginID>
<AppID>1,2</AppID>
</Data>
</Request>

correct output xml that I get back from the test.jsp
<?xml version="1.0" encoding="UTF-8" ?>
<SM>
<STAT>
<CD>0</CD>
<TXT>OK</TXT>
</STAT>
<R>2^3^112</R>
<G>
<A2>8001^8100^8102^1111111111^8112^8110^8107^8105</A2>
</G>
</SM>

incorrect output xml that I get back in the code
<?xml version="1.0" encoding="UTF-8"?>
<SM>
<STAT>
<CD>999</CD>
<TXT>Invalid input xml</TXT>
</STAT>
</SM>
----------------------------------------
code that I use to send the request

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aparna,

Have you tried this?

create a new document builder as you are creating new xml doc. try to use the below mentioned example...

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.newDocument(); // Create from whole cloth

Element root =
(Element) document.createElement("rootElement");
document.appendChild(root);
root.appendChild( document.createTextNode("Some") );
root.appendChild( document.createTextNode(" ") );
root.appendChild( document.createTextNode("text") );

} catch (ParserConfigurationException pce) {
// Parser with specified options can't be built
pce.printStackTrace();
}
 
Aparna Sharma
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit,
I apologize. I should have mentioned that I use the dom4j Document , not the org.w3c.Dom.Document.

I got an error when I tried to use the code snippet that you provided. Here are the import statements that I forgot to include.

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Vector;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentFactory;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

I did find out how to convert a w3c Document to a dom4j Document, but the following didnt work for me. It gave me an incompatible type error.

//convert the org.w3c.dom.Document tree into DOM4J's org.dom4j.Document
//tree using the DOM4J DOMReader class

org.dom4j.io.DOMReader reader = new org.dom4j.io.DOMReader();
org.dom4j.Document document = reader.read((org.w3c.dom.Document )doc);

I am beginning to wonder if this has anything to do with the problem posted in the java forums.
http://forum.java.sun.com/thread.jspa?threadID=282485&start=0&tstart=120

because I get the following exceptions in my console, along with the Invalid Input XML Format error.

<?xml version="1.0" encoding="UTF-8"?>
<Request><Credentials><UserID>smhsrvuser1</UserID><Password>{SSHA}ylYXKCoM8yMtxnTy8BR2PmOjkbe/c2vccHF+3w==</Password></Credentials><Data><Action>23</Action><ESELoginID>vrangaraj</ESELoginID><AppID>1,2</AppID></Data></Request>
[10/11/05 9:45:33:264 EDT] 4ee41b3f SystemOut O
<?xml version="1.0" encoding="UTF-8"?><SM><STAT><CD>999</CD><TXT>Invalid input xml</TXT></STAT></SM>
[10/11/05 9:45:33:274 EDT] 4ee41b3f SystemOut O
b4 Parsing output xml =<?xml version="1.0" encoding="UTF-8"?><SM><STAT><CD>999</CD><TXT>Invalid input xml</TXT></STAT></SM>
4ee41b3f SystemErr R org.dom4j.DocumentException: no protocol: <?xml version="1.0" encoding="UTF-8"?><SM><STAT><CD>999</CD><TXT>Invalid input xml</TXT></STAT></SM> Nested exception: no protocol: <?xml version="1.0" encoding="UTF-8"?><SM><STAT><CD>999</CD><TXT>Invalid input xml</TXT></STAT></SM>
4ee41b3f SystemErr R at org.dom4j.io.SAXReader.read(SAXReader.java:333)
4ee41b3f SystemErr R at org.dom4j.io.SAXReader.read(SAXReader.java:229)
4ee41b3f SystemErr R at com.lifeadmin.security.AppSecurity.getRolesGroups(AppSecurity.java:306)
4ee41b3f SystemErr R at com.lifeadmin.security.AppSecurity.GetRolesGroups(AppSecurity.java:119)
4ee41b3f SystemErr R at com.presentment.client.login.doPost(login.java:76)
4ee41b3f SystemErr R at com.presentment.client.login.doGet(login.java:40)
4ee41b3f SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
4ee41b3f SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
4ee41b3f SystemErr R at com.m.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
4ee41b3f SystemErr R at com.m.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555)
4ee41b3f SystemErr R at com.m.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
4ee41b3f SystemErr R at com.m.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
4ee41b3f SystemErr R at com.m.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
4ee41b3f SystemErr R at com.m.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
4ee41b3f SystemErr R at com.m.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
4ee41b3f SystemErr R at com.m.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
4ee41b3f SystemErr R at com.m.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
4ee41b3f SystemErr R at com.m.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
4ee41b3f SystemErr R at com.m.ws.http.HttpConnection.run(HttpConnection.java:439)
4ee41b3f SystemErr R at com.m.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
4ee41b3f SystemErr R Nested exception:
4ee41b3f SystemErr R java.net.MalformedURLException: no protocol: <?xml version="1.0" encoding="UTF-8"?><SM><STAT><CD>999</CD><TXT>Invalid input xml</TXT></STAT></SM>
4ee41b3f SystemErr R at java.net.URL.<init>(URL.java(Compiled Code))
4ee41b3f SystemErr R at java.net.URL.<init>(URL.java(Compiled Code))
4ee41b3f SystemErr R at java.net.URL.<init>(URL.java:450)
4ee41b3f SystemErr R at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
4ee41b3f SystemErr R at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
4ee41b3f SystemErr R at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
4ee41b3f SystemErr R at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
4ee41b3f SystemErr R at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
4ee41b3f SystemErr R at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
4ee41b3f SystemErr R at org.dom4j.io.SAXReader.read(SAXReader.java:314)
4ee41b3f SystemErr R at org.dom4j.io.SAXReader.read(SAXReader.java:229)
4ee41b3f SystemErr R at com.lifeadmin.security.AppSecurity.getRolesGroups(AppSecurity.java:306)
4ee41b3f SystemErr R at com.lifeadmin.security.AppSecurity.GetRolesGroups(AppSecurity.java:119)
4ee41b3f SystemErr R at com.presentment.client.login.doPost(login.java:76)
4ee41b3f SystemErr R at com.presentment.client.login.doGet(login.java:40)
4ee41b3f SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
4ee41b3f SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
4ee41b3f SystemErr R at com.m.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
4ee41b3f SystemErr R at com.m.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555)
4ee41b3f SystemErr R at com.m.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
4ee41b3f SystemErr R at com.m.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
4ee41b3f SystemErr R at com.m.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
4ee41b3f SystemErr R at com.m.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
4ee41b3f SystemErr R at com.m.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
4ee41b3f SystemErr R at com.m.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
4ee41b3f SystemErr R at com.m.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
4ee41b3f SystemErr R at com.m.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
4ee41b3f SystemErr R at com.m.ws.http.HttpConnection.run(HttpConnection.java:439)
4ee41b3f SystemErr R at com.m.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
4ee41b3f SystemErr R Nested exception: java.net.MalformedURLException: no protocol: <?xml version="1.0" encoding="UTF-8"?><SM><STAT><CD>999</CD><TXT>Invalid input xml</TXT></STAT></SM>
4ee41b3f SystemErr R at java.net.URL.<init>(URL.java(Compiled Code))
4ee41b3f SystemErr R at java.net.URL.<init>(URL.java(Compiled Code))
4ee41b3f SystemErr R at java.net.URL.<init>(URL.java:450)
4ee41b3f SystemErr R at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
4ee41b3f SystemErr R at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
4ee41b3f SystemErr R at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
4ee41b3f SystemErr R at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
4ee41b3f SystemErr R at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
4ee41b3f SystemErr R at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
4ee41b3f SystemErr R at org.dom4j.io.SAXReader.read(SAXReader.java:314)
4ee41b3f SystemErr R at org.dom4j.io.SAXReader.read(SAXReader.java:229)
4ee41b3f SystemErr R at com.lifeadmin.security.AppSecurity.getRolesGroups(AppSecurity.java:306)
4ee41b3f SystemErr R at com.lifeadmin.security.AppSecurity.GetRolesGroups(AppSecurity.java:119)
4ee41b3f SystemErr R at com.presentment.client.login.doPost(login.java:76)
4ee41b3f SystemErr R at com.presentment.client.login.doGet(login.java:40)
4ee41b3f SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
4ee41b3f SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
4ee41b3f SystemErr R at com.m.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
4ee41b3f SystemErr R at com.m.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
4ee41b3f SystemErr R at com.m.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555)
4ee41b3f SystemErr R at com.m.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
4ee41b3f SystemErr R at com.m.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
4ee41b3f SystemErr R at com.m.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)[10/11/05 9:45:33:314 EDT] 4ee41b3f SystemOut O
processRequest

4ee41b3f SystemErr R at com.m.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
4ee41b3f SystemErr R at com.m.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
4ee41b3f SystemErr R at com.m.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
4ee41b3f SystemErr R at com.m.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
4ee41b3f SystemErr R at com.m.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
4ee41b3f SystemErr R at com.m.ws.http.HttpConnection.run(HttpConnection.java:439)
4ee41b3f SystemErr R at com.m.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
4ee41b3f WebGroup I SRVE0180I: [LifeAdminClient] [/LifeAdminClient] [Servlet.LOG]: /home.jsp: init
 
Amit Goel
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WOW!!!

That was a pretty big stack thrown

anyway, if u r sure that u r following the correct procedure and are not missing any step... i am really wondered how this unusual stack is curned out..

okay.. can u mail across the code to me.. i'l also have a look . although i havent used dom4j doc but then also , i 'll try to have a look..

my email id is amitgoel1287@yahoo.com
 
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!