I am trying to find some example or demo "How to integrate OGM with unmanaged extension" but not able to find any good example.
I tried to use the restapi as unmanaged extension and individually its working fine but OGM have smart object mapping capability and can be achieved by the Session
and Session
is obtained from a
SessionFactory
.
private final static SessionFactory sessionFactory = new SessionFactory("some.domain");
sessionFactory .openSession();
Now how OGM can be use integrate with Unmanaged Extension ?
Can someone please help me for same.
Edit 1
Please check below screen shot
EDIT 2
Below is code we wrote
import org.neo4j.ogm.drivers.embedded.extension.OgmPluginInitializer;
public class MyApplicationPluginInitializer extends OgmPluginInitializer {
public MyApplicationPluginInitializer(String packages) {
super(packages);
}
}
Class TopologyExtController
@Path("/")
public class TopologyExtController {
@javax.ws.rs.core.Context
public org.neo4j.ogm.session.Session session;
public TopologyExtController( ) {
}
@POST
@Path("/uiv/topology")
public Response getTopology(TopologyDescription topology, @javax.ws.rs.core.Context HttpHeaders headers) {
try{
ObjectMapper mapper = new ObjectMapper();
Map convertValue = mapper.convertValue(topology, Map.class);
Map<String, Object> map = new HashMap<>();
map.put("topology", convertValue);
//OGM session used execute the procedure and return the mapped result to end user.
Result query = session.query("call uiv.traversal($topology)",map);
Iterator<Map<String, Object>> iterator = query.iterator();
if (iterator.hasNext()) {
Map<String, Object> next = iterator.next();
Object object = next.get("rootNodes");
return Response.ok(object).status(200).build();
}
}catch (Exception e)
{
e.printStackTrace();
}
return Response.ok("Something went wrong").status(400).build();
}
}
META-INF Entry \META-INF\services\org.neo4j.server.plugins.PluginLifecycle
- framework.traversal.ext.config.MyApplicationPluginInitializer
But error we are geting
Nov 30 15:17:27 surerest2 neo4j: 2018-11-30 09:47:27.611+0000 ERROR The following errors and warnings have been detected with resource and/or provider classes: Nov 30 15:17:27 surerest2 neo4j: SEVERE: Missing dependency for field: public org.neo4j.ogm.session.Session framework.traversal.ext.ogm.controller.TopologyExtController.session Nov 30 15:17:27 surerest2 neo4j: 2018-11-30 09:47:27.612+0000 WARN unavailable Nov 30 15:17:27 surerest2 neo4j: com.sun.jersey.spi.inject.Errors$ErrorMessagesException Nov 30 15:17:27 surerest2 neo4j: at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170) Nov 30 15:17:27 surerest2 neo4j: at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136) Nov 30 15:17:27 surerest2 neo4j: at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199) Nov 30 15:17:27 surerest2 neo4j: at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795) Nov 30 15:17:27 surerest2 neo4j: at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790) Nov 30 15:17:27 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:509) Nov 30 15:17:27 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:339) Nov 30 15:17:27 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) Nov 30 15:17:27 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207) Nov 30 15:17:27 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394) Nov 30 15:17:27 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577) Nov 30 15:17:27 surerest2 neo4j: at javax.servlet.GenericServlet.init(GenericServlet.java:244) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:665) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:423) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:760) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:348) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:133) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:115) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:133) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.server.Server.start(Server.java:418) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:107) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.server.Server.doStart(Server.java:385) Nov 30 15:17:27 surerest2 neo4j: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) Nov 30 15:17:27 surerest2 neo4j: at org.neo4j.server.web.Jetty9WebServer.startJetty(Jetty9WebServer.java:320) Nov 30 15:17:27 surerest2 neo4j: at org.neo4j.server.web.Jetty9WebServer.start(Jetty9WebServer.java:152) Nov 30 15:17:27 surerest2 neo4j: at org.neo4j.server.AbstractNeoServer.startWebServer(AbstractNeoServer.java:321) Nov 30 15:17:27 surerest2 neo4j: at org.neo4j.server.AbstractNeoServer.access$700(AbstractNeoServer.java:102) Nov 30 15:17:27 surerest2 neo4j: at org.neo4j.server.AbstractNeoServer$ServerComponentsLifecycleAdapter.start(AbstractNeoServer.java:527) Nov 30 15:17:27 surerest2 neo4j: at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:445) Nov 30 15:17:27 surerest2 neo4j: at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107) Nov 30 15:17:27 surerest2 neo4j: at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:212) Nov 30 15:17:27 surerest2 neo4j: at org.neo4j.server.ServerBootstrapper.start(ServerBootstrapper.java:111) Nov 30 15:17:27 surerest2 neo4j: at org.neo4j.server.ServerBootstrapper.start(ServerBootstrapper.java:79) Nov 30 15:17:27 surerest2 neo4j: at com.neo4j.server.enterprise.CommercialEntryPoint.main(CommercialEntryPoint.java:22) Nov 30 15:17:27 surerest2 neo4j: 2018-11-30 09:47:27.639+0000 ERROR Failed to start Neo4j on 127.0.0.1:7474: org.neo4j.server.web.NeoServletContainer-737fd68@2dde7c07==org.neo4j.server.web.NeoServletContainer,jsp=null,order=-1,inst=false Nov 30 15:17:27 surerest2 neo4j: 2018-11-30 09:47:27.658+0000 INFO Stopping... Nov 30 15:17:28 surerest2 neo4j: 2018-11-30 09:47:28.279+0000 INFO Stopped. Nov 30 15:17:28 surerest2 neo4j: 2018-11-30 09:47:28.281+0000 ERROR Failed to start Neo4j: Starting Neo4j failed: Component 'org.neo4j.server.AbstractNeoServer$ServerComponentsLifecycleAdapter@6c49db66' was successfully initialized, but failed to start. Please see the attached cause exception "null". Starting Neo4j failed: Component 'org.neo4j.server.AbstractNeoServer$ServerComponentsLifecycleAdapter@6c49db66' was successfully initialized, but failed to start. Please see the attached cause exception "null". Nov 30 15:17:28 surerest2 neo4j: org.neo4j.server.ServerStartupException: Starting Neo4j failed: Component 'org.neo4j.server.AbstractNeoServer$ServerComponentsLifecycleAdapter@6c49db66' was successfully initialized, but failed to start. Please see the attached cause exception "null". Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.server.exception.ServerStartupErrors.translateToServerStartupError(ServerStartupErrors.java:68) Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:220) Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.server.ServerBootstrapper.start(ServerBootstrapper.java:111) Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.server.ServerBootstrapper.start(ServerBootstrapper.java:79) Nov 30 15:17:28 surerest2 neo4j: at com.neo4j.server.enterprise.CommercialEntryPoint.main(CommercialEntryPoint.java:22) Nov 30 15:17:28 surerest2 neo4j: Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.server.AbstractNeoServer$ServerComponentsLifecycleAdapter@6c49db66' was successfully initialized, but failed to start. Please see the attached cause exception "null". Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:466) Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107) Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:212) Nov 30 15:17:28 surerest2 neo4j: ... 3 more Nov 30 15:17:28 surerest2 neo4j: Caused by: javax.servlet.ServletException: org.neo4j.server.web.NeoServletContainer-737fd68@2dde7c07==org.neo4j.server.web.NeoServletContainer,jsp=null,order=-1,inst=false Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:686) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:423) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:760) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:348) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:133) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:115) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:133) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.server.Server.start(Server.java:418) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:107) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.server.Server.doStart(Server.java:385) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.server.web.Jetty9WebServer.startJetty(Jetty9WebServer.java:320) Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.server.web.Jetty9WebServer.start(Jetty9WebServer.java:152) Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.server.AbstractNeoServer.startWebServer(AbstractNeoServer.java:321) Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.server.AbstractNeoServer.access$700(AbstractNeoServer.java:102) Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.server.AbstractNeoServer$ServerComponentsLifecycleAdapter.start(AbstractNeoServer.java:527) Nov 30 15:17:28 surerest2 neo4j: at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:445) Nov 30 15:17:28 surerest2 neo4j: ... 5 more Nov 30 15:17:28 surerest2 neo4j: Caused by: com.sun.jersey.spi.inject.Errors$ErrorMessagesException Nov 30 15:17:28 surerest2 neo4j: at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170) Nov 30 15:17:28 surerest2 neo4j: at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136) Nov 30 15:17:28 surerest2 neo4j: at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199) Nov 30 15:17:28 surerest2 neo4j: at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795) Nov 30 15:17:28 surerest2 neo4j: at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790) Nov 30 15:17:28 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:509) Nov 30 15:17:28 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:339) Nov 30 15:17:28 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) Nov 30 15:17:28 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207) Nov 30 15:17:28 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394) Nov 30 15:17:28 surerest2 neo4j: at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577) Nov 30 15:17:28 surerest2 neo4j: at javax.servlet.GenericServlet.init(GenericServlet.java:244) Nov 30 15:17:28 surerest2 neo4j: at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:665) Nov 30 15:17:28 surerest2 neo4j: ... 27 more
This is in general not possible. Neo4j-OGM abstracts all transport modes (Bolt, HTTP, embedded) by using Cypher.
...but if your unmanaged extension works completely separated from your business logic (e.g. no transaction boundaries that also contain Neo4j-OGM calls) you could create a call directly through the (Neo4j-OGM) HTTP-driver:
HttpDriver httpDriver = (HttpDriver) sessionFactory.getDriver();
CloseableHttpResponse response = httpDriver.executeHttpRequest(new HttpGet("http://somewhere"));
response.getEntity().getContent()....
please note that this is just a hack to use the raw connection.
Edit (add information for running inside Neo4j):
As described in the documentation you need to provide your own OgmPluginInitializer
as you already did. But your implementation/constructor does expect the package to be provided somewhere. The service extension that loads the extension does not know about your package structure so the initializer class should look sth. like
public class MyApplicationPluginInitializer extends OgmPluginInitializer {
public MyApplicationPluginInitializer() {
super("Your package to scan");
}
}
As a warning: The API used to provide this feature is deprecated in Neo4j 3.5. and could be removed in upcoming versions. As a consequent this feature might get also a refactoring or deleting depending on the changes.