ju113n
ju113n

Reputation: 21

Neo4j server using Java Bolt neo4j-ogm on Weblogic

I have a problem connecting to a neo4j server from Java EE.

I use :
- neo4j 3.0.1 in server mode on localhost
- Weblogic 12.1.3
- JEE 7
- neo4j-ogm-core 2.0.3
- neo4j-ogm-bolt-driver 2.0.3

My Maven dependencies :

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-core</artifactId>
    <version>2.0.3</version>
</dependency>
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-bolt-driver</artifactId>
    <version>2.0.3</version>
</dependency>

My ogm.properties in resources/META-INF :

#Driver, required
driver=org.neo4j.ogm.drivers.bolt.driver.BoltDriver

#URI of the Neo4j database, required. If no port is specified, the default port 7687 is used. Otherwise, a port can be specified with bolt://neo4j:password@localhost:1234
URI=bolt://neo4j:xxxxxx@localhost

#Connection pool size (the maximum number of sessions per URL), optional, defaults to 50
connection.pool.size=150

#Encryption level (TLS), optional, defaults to REQUIRED. Valid values are NONE,REQUIRED
encryption.level=NONE

#Trust strategy, optional, not used if not specified. Valid values are TRUST_ON_FIRST_USE,TRUST_SIGNED_CERTIFICATES
trust.strategy=TRUST_ON_FIRST_USE

I use a EJB Singleton to define Session Factory :

@Singleton
public class Neo4jSessionFactory {

    private SessionFactory sessionFactory;

    @PostConstruct
    public void init() {
        sessionFactory = new SessionFactory("com.toto.poc.ejb.data.access");
    }

    /**
     * Get neo4j session
     * @return the session
     */
    public Session getNeo4jSession() {
        return sessionFactory.openSession();
    }
}

it is in "com.toto.poc.ejb.data.access" package.

I have a EJB to define the business method in want to call :

@Stateless
public class TopologyBusiness {

    private @EJB Neo4jSessionFactory neo4jSessionFactory;

    public Iterable<Map<String, Object>> getApplication(String irt) {
        String query = "MATCH (a:Application) WHERE a.irt = '" + irt + "' RETURN a";

        Session session = neo4jSessionFactory.getNeo4jSession();

        return session.query(query, Collections.emptyMap());
    }
}

But when my client call TopologyBusiness, the init (PostConstruct) method of Neo4jSessionFactory is called, and an error occur :

com.oracle.pitchfork.interfaces.LifecycleCallbackException: Failure to invoke public void com.toto.poc.ejb.data.access.Neo4jSessionFactory.init() on bean class class com.toto.poc.ejb.data.access.Neo4jSessionFactory_wi88u8_Impl with args: null
    at com.oracle.pitchfork.inject.Jsr250Metadata.invokeLifecycleMethod(Jsr250Metadata.java:379)
    at com.oracle.pitchfork.inject.Jsr250Metadata.invokeLifecycleMethods(Jsr250Metadata.java:352)
    at com.oracle.pitchfork.intercept.InterceptionMetadata.invokeLifecycleMethods(InterceptionMetadata.java:399)
    at weblogic.ejb.container.injection.EjbComponentCreatorImpl.invokePostConstruct(EjbComponentCreatorImpl.java:55)
    at weblogic.ejb.container.manager.SingletonSessionManager.constructAndInitBean(SingletonSessionManager.java:330)
    Truncated. see log file for complete stacktrace
Caused By: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.oracle.pitchfork.inject.Jsr250Metadata.invokeLifecycleMethod(Jsr250Metadata.java:377)
    Truncated. see log file for complete stacktrace
Caused By: java.lang.RuntimeException: org.neo4j.ogm.exception.ServiceNotFoundException: Resource: zip:C:/oracle/wls/12.1.3/user_projects/domains/CMDB/servers/LocalServer/tmp/_WL_user/poc-cdb-ear_ear/a8qjfi/poc-cdb-ejb-1.0-SNAPSHOT.jar!/com/toto.poc/ejb/data/access
    at org.neo4j.ogm.ClassUtils.getUniqueClasspathElements(ClassUtils.java:178)
    at org.neo4j.ogm.scanner.ClassPathScanner.getUniqueClasspathElements(ClassPathScanner.java:158)
    at org.neo4j.ogm.scanner.ClassPathScanner.scan(ClassPathScanner.java:130)
    at org.neo4j.ogm.metadata.DomainInfo.load(DomainInfo.java:316)
    at org.neo4j.ogm.metadata.DomainInfo.<init>(DomainInfo.java:67)
    Truncated. see log file for complete stacktrace
Caused By: org.neo4j.ogm.exception.ServiceNotFoundException: Resource: zip:C:/oracle/wls/12.1.3/user_projects/domains/CMDB/servers/LocalServer/tmp/_WL_user/poc-cdb-ear_ear/a8qjfi/poc-cdb-ejb-1.0-SNAPSHOT.jar!/com/toto.poc/ejb/data/access
    at org.neo4j.ogm.service.ResourceService.resolve(ResourceService.java:53)
    at org.neo4j.ogm.ClassUtils.getUniqueClasspathElements(ClassUtils.java:175)
    at org.neo4j.ogm.scanner.ClassPathScanner.getUniqueClasspathElements(ClassPathScanner.java:158)
    at org.neo4j.ogm.scanner.ClassPathScanner.scan(ClassPathScanner.java:130)
    at org.neo4j.ogm.metadata.DomainInfo.load(DomainInfo.java:316)
    Truncated. see log file for complete stacktrace

The root cause seems to be :

Caused By: org.neo4j.ogm.exception.ServiceNotFoundException: Resource: zip:C:/oracle/wls/12.1.3/user_projects/domains/CMDB/servers/LocalServer/tmp/_WL_user/poc-cdb-ear_ear/a8qjfi/poc-cdb-ejb-1.0-SNAPSHOT.jar!/com/toto.poc/ejb/data/access

I have no idea why it wants to look into a zip in the classpath ...
Thank for your help !

Upvotes: 0

Views: 632

Answers (1)

ju113n
ju113n

Reputation: 21

I can finally resolve my problem, I browsed odd forums and found someone who had similar issue on JBoss.
So I managed to transpose this solution to Weblogic.

First, you need to create your own resource resolver to provide the way to deal with "zip".
Overwrite ResourceResolver and implements resolve method like below :

public class Neo4jResourceResolver implements ResourceResolver {

    @Override
    public File resolve(URL resource) throws Exception {

        switch (resource.getProtocol()) {
            case "file":
                return new File(resource.toURI());
            case "jar":
            case "zip":
                String jarPath = resource.getPath().substring(0, resource.getPath().indexOf("!"));
                return new File(jarPath);
            default:
                return null;
        }
    }
}

Then create a file named "org.neo4j.ogm.classloader.ResourceResolver" in path "src/main/resources/META-INF/services".
This file contains only one line, the path to your custom ResourceResolver class :

com.toto.poc.core.access.ucmdb.Neo4jResourceResolver

And it's magic, it works !!!

Neo4j will now explore the jar archive, found your NodeEntities and map it to your graph :)

Upvotes: 2

Related Questions