File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes MalformedURLException with xmlParser.parse(inputSource) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "MalformedURLException with xmlParser.parse(inputSource)" Watch "MalformedURLException with xmlParser.parse(inputSource)" New topic
Author

MalformedURLException with xmlParser.parse(inputSource)

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Hiya,

Can anyone tell me why I'm getting a MalformedURLException from this code? It is because of the URL in the htmlContent String / what can I do about it?

This problem doesn't happen when I test locally (jdk1.6.0_23) but does happen when I upload to our host (jdk1.6.0_26).



Thanks in advance,
James
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

James

Can you provide the full stack trace of the exception?
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Sure, it's:

org.w3c.mwi.mobileok.basic.TestException: One or more exceptions were caught while processing the resources:
org.w3c.mwi.mobileok.basic.TestException: 2. java.net.MalformedURLException: no protocol: %
org.w3c.mwi.mobileok.basic.XhtmlContent5.validateMobile(XhtmlContent5.java:978)
org.w3c.mwi.mobileok.basic.XhtmlContent5.<init>(XhtmlContent5.java:211)
org.w3c.mwi.mobileok.basic.MobileOKDecodedContentFactory.decodeContent(MobileOKDecodedContentFactory.java:64)
org.w3c.mwi.mobileok.basic.Resource.decode(Resource.java:243)
org.w3c.mwi.mobileok.basic.Preprocessor.processResource(Preprocessor.java:484)
org.w3c.mwi.mobileok.basic.Preprocessor.access$000(Preprocessor.java:33)
org.w3c.mwi.mobileok.basic.Preprocessor$2.run(Preprocessor.java:529)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:662)


at org.w3c.mwi.mobileok.basic.Preprocessor.preprocess(Preprocessor.java:420)
at org.w3c.mwi.mobileok.basic.Tester.getPreprocessorResults(Tester.java:140)
at org.w3c.mwi.mobileok.basic.Tester.runTests(Tester.java:181)
at org.w3c.mwi.mobileok.basic.Tester.runTests(Tester.java:166)
at uk.co.mobilewebexpert.UriAnalyser.processRequest(UriAnalyser.java:63)
at uk.co.mobilewebexpert.UriAnalyser.doGet(UriAnalyser.java:445)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:269)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:301)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:283)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:56)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:189)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:774)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:703)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:896)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Thread.java:662)
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Forget that strack trace. Here's a better one:

java.net.MalformedURLException: no protocol: %
at java.net.URL.<init>(URL.java:567)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:650)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1315)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1282)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:283)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1194)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1090)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1003)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.w3c.mwi.mobileok.basic.XhtmlContent6.validateMobile(XhtmlContent6.java:950)
at org.w3c.mwi.mobileok.basic.XhtmlContent6.<init>(XhtmlContent6.java:211)
at org.w3c.mwi.mobileok.basic.MobileOKDecodedContentFactory.decodeContent(MobileOKDecodedContentFactory.java:64)
at org.w3c.mwi.mobileok.basic.Resource.decode(Resource.java:243)
at org.w3c.mwi.mobileok.basic.Preprocessor.processResource(Preprocessor.java:484)
at org.w3c.mwi.mobileok.basic.Preprocessor.access$000(Preprocessor.java:33)
at org.w3c.mwi.mobileok.basic.Preprocessor$2.run(Preprocessor.java:529)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Okay. So now we know there's a DTD involved and that it doesn't declare some entity correctly -- apparently the parser thinks there should be a URL but there's a % character, or something like that.

I see your code uses an EntityResolver. Is that because you have to resolve those W3C URLs locally because the W3C's servers are sending 403s for them? At any rate I suspect you should compare the catalogs between the two systems.
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Hiya Paul,

It's not my code, so I don't understand it 100%, but it seems to works fine for everyone else and on my local machine. I did fix the aforementioned problem though with the DTD by adding this code...

...before I create saxParser.


But now I have this MalformedURLException...

net.sf.saxon.trans.XPathException: java.net.MalformedURLException: no protocol: %
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:424)
at net.sf.saxon.event.Sender.send(Sender.java:193)
at net.sf.saxon.event.Sender.send(Sender.java:50)
at net.sf.saxon.Configuration.buildDocument(Configuration.java:2973)
at org.w3c.mwi.mobileok.basic.XhtmlContent10.parseDOM(XhtmlContent10.java:334)
at org.w3c.mwi.mobileok.basic.XhtmlContent10.<init>(XhtmlContent10.java:226)
at org.w3c.mwi.mobileok.basic.MobileOKDecodedContentFactory.decodeContent(MobileOKDecodedContentFactory.java:64)
at org.w3c.mwi.mobileok.basic.Resource.decode(Resource.java:243)
at org.w3c.mwi.mobileok.basic.Preprocessor.processResource(Preprocessor.java:484)
at org.w3c.mwi.mobileok.basic.Preprocessor.access$000(Preprocessor.java:33)
at org.w3c.mwi.mobileok.basic.Preprocessor$2.run(Preprocessor.java:529)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.net.MalformedURLException: no protocol: %
at java.net.URL.<init>(URL.java:567)
at java.net.URL.<init>(URL.java:464)
at java.net.URL.<init>(URL.java:413)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:650)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1315)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1282)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:283)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1194)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1090)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1003)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:404)
... 13 more

...being create by this code...


Any ideas?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Paul Clapham wrote:At any rate I suspect you should compare the catalogs between the two systems.
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
OK Paul, thanks. I'm not particularly clued up on XML / catalogs - any idea how I would do this and/or do you know a good resource where I can read up?

Thanks,
James
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187




What is the value of "htmlContent"? Is it compatible with the constructor for an InputSource? Read the API documentation for InputSource and make sure that you are properly creating an InputSource object.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

James Hodgkiss wrote:I'm not particularly clued up on XML / catalogs - any idea how I would do this and/or do you know a good resource where I can read up?


Given this line of code:


I would start by looking at the source code for those two classes. They are the ones which access the catalog; perhaps there's something hard-coded in them which will lead you to the catalog's location.
 
jQuery in Action, 2nd edition
 
subject: MalformedURLException with xmlParser.parse(inputSource)
 
Similar Threads
JSP 2.0 document
isErrorPage and errorPage attributes
updating database records via jsp
struts 2 don�t get radio button
Help