I understand that several folks have had this exception in conjunction
with Fuseki/TDB:
http://jena.markmail.org/search/?q=BadURIException#query:BadURIException+pa
ge:1+mid:fur2joez3ny5ibvw+state:results

I've tracked down this exception in a Scala example from the w3/banana-rdf
project -- specifically:
https://github.com/w3c/banana-rdf/blob/master/examples/src/main/scala/org/w
3/banana/examples/IOExample.scala

This exception happens during the RDF/XML serialization:

Unparser.wObjStar() line: 358   
Unparser.wRDF() line: 345       
Unparser.write() line: 247      
Abbreviated.writeBody(Model, PrintWriter, String, Boolean) line: 142    
BaseXMLWriter.writeXMLBody(Model, PrintWriter, String) line: 492        
BaseXMLWriter.write(Model, Writer, String) line: 464    
Abbreviated.write(Model, Writer, String) line: 127      
BaseXMLWriter.write(Model, OutputStream, String) line: 450      
AdapterRDFWriter.write(OutputStream, Graph, PrefixMap, String, Context)
line: 52        
RDFDataMgr.write$(OutputStream, Graph, RDFFormat) line: 1262    
RDFDataMgr.write(OutputStream, Graph, RDFFormat) line: 1028     
RDFDataMgr.write(OutputStream, Graph, Lang) line: 1018  
JenaRDFWriter$$anon$1$$anonfun$write$1.apply$mcV$sp() line: 20  
JenaRDFWriter$$anon$1$$anonfun$write$1.apply() line: 17 
JenaRDFWriter$$anon$1$$anonfun$write$1.apply() line: 17 
Try$.apply(Function0) line: 191 
JenaRDFWriter$$anon$1.write(Graph, OutputStream, String) line: 17       
JenaRDFWriter$$anon$1.write(Object, OutputStream, String) line: 15      
IOExample$class.main(IOExample, Array[String]) line: 44 
IOExampleWithJena$.main(Array[String]) line: 64 
IOExampleWithJena.main(Array[String]) line: not available       


I believe the problem originates, in part, here:

RDFDataMgr.write$(OutputStream, Graph, RDFFormat) line: 1262


    private static void write$(OutputStream out, Graph graph, RDFFormat
serialization)
    {
        WriterGraphRIOT w = createGraphWriter$(serialization) ;
        w.write(out, graph, RiotLib.prefixMap(graph), null, null) ; //
line 1262
    }

The last 2 null arguments are the values for the "baseURI" and "context"
parameters.
Are all writers able to cope with a null base URI?

It seems that the Turtle writer can but not the RDF/XML writer.
The BadURIException happens during Unparser.wObjStar() when one of the
Resources has a null URI:

BaseXMLWriter.checkURI(String) line: 820        
BaseXMLWriter.relativize(String) line: 797      
Unparser.wURIreference(String) line: 918        
Unparser.wURIreference(Resource) line: 922      
Unparser.wAboutAttr(Resource) line: 913 
Unparser.wIdAboutAttrOpt(Resource) line: 869    
Unparser.wTypedNodeOrDescriptionLong(Unparser$WType, Resource, Resource,
List) line: 830 
Unparser.wTypedNodeOrDescription(Unparser$WType, Resource, Resource) line:
764     
Unparser.wTypedNode(Resource) line: 737 
Unparser.wObj(Resource, Boolean) line: 677      
Unparser.wObjStar() line: 364   

Because the writer has a null baseURI, then BaseXMLWriter.relativize(null)
returns null.
This then fails the URI check; hence the BadURIException.

To avoid this problem, I refactored the call to RDFDataMgr.write(),
originally:

def write(graph: Jena#Graph, os: OutputStream, base: String): Try[Unit] =
Try {
      import org.w3.banana.jena.Jena.ops._
      val relativeGraph : Jena#Graph = graph.relativize(URI(base))
      RDFDataMgr.write(os, relativeGraph, lang)
    }

To the following:

def write(graph: Jena#Graph, os: OutputStream, base: String): Try[Unit] =
Try {
      import org.w3.banana.jena.Jena.ops._
      val relativeGraph : Jena#Graph = graph.relativize(URI(base))
      val serialization: RDFFormat =
RDFWriterRegistry.defaultSerialization(lang)
      val wf: WriterGraphRIOTFactory =
RDFWriterRegistry.getWriterGraphFactory(serialization)
      if ( wf == null )
            throw new RiotException("No graph writer for "+serialization)
; 
      val w: WriterGraphRIOT = wf.create(serialization)
      w.write(os, relativeGraph, system.RiotLib.prefixMap(relativeGraph),
base, null)
    }

This is basically a copy/paste adaptation of what the Jena API does anyway
with the difference that I pass the graph's base URI to the writer.

Well, the refactored version of the test works, the original doesn't.

- Nicolas.

Reply via email to