# Load XML from java driver using apoc

**URL:** <https://community.neo4j.com/t/load-xml-from-java-driver-using-apoc/26147>\
**Category:** Procedures & APOC\
**Created:** [September 29, 2020, 7:17am UTC](https://community.neo4j.com/t/load-xml-from-java-driver-using-apoc/26147 "2020-09-29T07:17:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![antonio.agj](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/antonio.agj/32/14062_2.png) [@antonio.agj](https://community.neo4j.com/u/antonio.agj)\
**Post date:** [September 29, 2020, 7:17am UTC](https://community.neo4j.com/t/load-xml-from-java-driver-using-apoc/26147/1 "2020-09-29T07:17:58Z")

</div>

Hi all,

I am trying to implement a junit to test a procedure. In order to do this, I would like to load an XML using apoc, but I get the following error:

org.neo4j.driver.exceptions.ClientException: Failed to invoke procedure `apoc.load.xml`: Caused by: java.lang.RuntimeException: Import from files not enabled, please set apoc.import.file.enabled=true in your neo4j.conf

To fix this, I added to the Neo4jRule the config as follow:

import java.util.Iterator;  
import java.util.stream.Stream;

import org.junit.Rule;  
import org.junit.Test;  
import org.neo4j.driver.Config;  
import org.neo4j.driver.Driver;  
import org.neo4j.driver.GraphDatabase;  
import org.neo4j.driver.Record;  
import org.neo4j.driver.Session;  
import org.neo4j.harness.junit.rule.Neo4jRule;  
import apoc.load.Xml;

import static org.junit.Assert.assertTrue;  
import static org.neo4j.configuration.SettingImpl.newBuilder;  
import static org.neo4j.configuration.SettingValueParsers.STRING;

public class TestImport  
{  
@Rule  
public Neo4jRule neo4j = new Neo4jRule()  
.withConfig(  
newBuilder("apoc.import.file.enabled",STRING, "false").build(),  
"true")   
.withProcedure(Xml.class);  
@Test  
public void testImportProcedure() throws Throwable  
{  
try(Driver driver = GraphDatabase.driver(neo4j.boltURI(), Config.builder().withoutEncryption().build())) {  
Session session = driver.session();  
System.out.println(neo4j.config().toString());  
Stream all = session.run("CALL apoc.load.xml('file:src/test/resources/xml/small.xml')").stream();  
Iterator itMap = all.iterator();  
while (itMap.hasNext()) {  
Record record = itMap.next();  
System.out.println("Test");  
}   
}   
assertTrue(true);  
}  
}

I still get this error, Would you give me any hint on how I can fix this? Thanks in advance.

I am using neo4j 4.1.0 and apoc 3.5.0.14.

Kind regards,  
Antonio

---

<div class="post-metadata">

**Author:** ![stefan.armbruster](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stefan.armbruster/32/74_2.png) [@stefan.armbruster](https://community.neo4j.com/u/stefan.armbruster)\
**Post date:** [September 29, 2020, 12:28pm UTC](https://community.neo4j.com/t/load-xml-from-java-driver-using-apoc/26147/2 "2020-09-29T12:28:50Z")

</div>

you cannot used APOC 3.5.x.x with Neo4j 4.1 - checkout the version compatibility matrix at [Installation - APOC Extended Documentation](https://neo4j.com/labs/apoc/4.1/installation/#neo4j-server)

In APOC \>= 4.0 `apoc.import.file.enabled=true` needs to be set either in apoc.conf, as env variable or as a system property, see [Configuration Options - APOC Extended Documentation](https://neo4j.com/labs/apoc/4.1/config/)

You can use e.g. [System Rules](https://stefanbirkner.github.io/system-rules/) for managing env variables and system properties with a junit rule. You might need to use RuleChain to combine that with your Neo4jRule.

---

<div class="post-metadata">

**Author:** ![antonio.agj](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/antonio.agj/32/14062_2.png) [@antonio.agj](https://community.neo4j.com/u/antonio.agj)\
**Post date:** [September 29, 2020, 4:28pm UTC](https://community.neo4j.com/t/load-xml-from-java-driver-using-apoc/26147/3 "2020-09-29T16:28:48Z")

</div>

Hi Stefan,

Thanks! Appreciate a lot your answer, gave me a lot of clues.

I do not know why I overlooked the compatibility between neo4j and apoc:-(.

At this moment, I included the apoc version 4.1.0.2 using Maven in eclipse, but I cannot find where it is defined the procedure "apoc.load.xml". In the previous version it was in the package apoc.load in the XML.java, but I cannot find this class anymore. I just check in the Github repo ([neo4j-apoc-procedures/Xml.java at 4.1 · neo4j-contrib/neo4j-apoc-procedures · GitHub](https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/4.1/core/src/main/java/apoc/load/Xml.java)) and it seems that the class has not been deleted. Do you know why I cannot find it in this version? Thanks again.

Kind regards,  
Antonio

---

<div class="post-metadata">

**Author:** ![stefan.armbruster](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stefan.armbruster/32/74_2.png) [@stefan.armbruster](https://community.neo4j.com/u/stefan.armbruster)\
**Post date:** [September 30, 2020, 10:05am UTC](https://community.neo4j.com/t/load-xml-from-java-driver-using-apoc/26147/4 "2020-09-30T10:05:06Z")

</div>

APOC has been splitted into a "core" part and a "extended" part. Rationale: we wanted to enable most commonly used features being available on Aura.

Not sure, maybe the maven deployed one is the core variant only. Can you try using the `-all` from [Release 4.1.0.2 · neo4j-contrib/neo4j-apoc-procedures · GitHub](https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/tag/4.1.0.2)?

---

<div class="post-metadata">

**Author:** ![antonio.agj](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/antonio.agj/32/14062_2.png) [@antonio.agj](https://community.neo4j.com/u/antonio.agj)\
**Post date:** [September 30, 2020, 4:37pm UTC](https://community.neo4j.com/t/load-xml-from-java-driver-using-apoc/26147/5 "2020-09-30T16:37:57Z")

</div>

Hi Stefan,

Thanks! I did not know this change.

Indeed, it seems that the maven deployed one is the core variant. So, in order to import the -all I use the `<classifier>all</classifier>` as follows:

```auto
  <dependency>
	  <groupId>org.neo4j.procedure</groupId>
	  <artifactId>apoc</artifactId>
	  <version>4.1.0.2</version>	
	  <classifier>all</classifier> 
	  <scope>test</scope>  
    </dependency> 

```

The thing is now that a new error appears in the console: "APOC couln't set a URLStreamHandlerFactory since some other tool already did this". I think that it related to [APOC couln't set a URLStreamHandlerFactory message always there as of apoc 4.1.0.0 - neo4j 4.1.0 · Issue #1571 · neo4j-contrib/neo4j-apoc-procedures · GitHub](https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/1571) and a workaround is proposed in [APOC couln't set a URLStreamHandlerFactory since some other tool already did this (e.g. tomcat). · Issue #1642 · neo4j-contrib/neo4j-apoc-procedures · GitHub](https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/1642). However, I did not make it work, because when I try to run a query I catch the error: "Timeout waiting for database to become available and allow new transactions. Waited 1s. 1 reasons for blocking: Database unavailable.". At this moment, the RuleChain is defined as follows:

```auto
@Rule
    public RuleChain chain = RuleChain.outerRule(
    new EnvironmentVariables()
    .set("apoc.import.file.enabled", "true")    																		 
    .set("NEO4JLABS_PLUGINS", "apoc"))
    .around(neo4j = new Neo4jRule()    								  						 
   .withProcedure(Xml.class)    								  						 
   .withProcedure(NewProcedure.class));	

```

How can I include this programmatically as suggested by **[nathanschepers](https://github.com/nathanschepers)**

```auto
neo4j:
    image: neo4j

```

Thanks in advance.

Kind regards,  
Antonio

---

<div class="post-metadata">

**Author:** ![stefan.armbruster](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stefan.armbruster/32/74_2.png) [@stefan.armbruster](https://community.neo4j.com/u/stefan.armbruster)\
**Post date:** [October 1, 2020, 8:29am UTC](https://community.neo4j.com/t/load-xml-from-java-driver-using-apoc/26147/6 "2020-10-01T08:29:57Z")

</div>

You don't need

```auto
  .set("NEO4JLABS_PLUGINS", "apoc"))

```

since this is only processed by the docker entrypoint script.

The complaint about URLStreamHandlerFactory can be safely ignored. This is already fixed in the code, but not yet released.

Will take a look into your rule definition the next days - being quite busy atm.

---

<div class="post-metadata">

**Author:** ![antonio.agj](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/antonio.agj/32/14062_2.png) [@antonio.agj](https://community.neo4j.com/u/antonio.agj)\
**Post date:** [October 4, 2020, 8:06am UTC](https://community.neo4j.com/t/load-xml-from-java-driver-using-apoc/26147/7 "2020-10-04T08:06:37Z")

</div>

Hi Stefan,

I just reset my environment and it seems to work atm (I think that I had some problems with maven). Probably, the above code is more accurate as follows:

```auto
    public Neo4jRule neo4j = new Neo4jRule();	
    @Rule
    public RuleChain ruleChain = RuleChain.outerRule(new EnvironmentVariables()    													 
                               .set("apoc.import.file.enabled", "true"))
                               .around(neo4j.withProcedure(Xml.class));

```

Thanks.

Kind regards,  
Antonio
