Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'trunk' of github.com:impetus-opensource/Kundera into trunk

  • Loading branch information...
commit 9852237b948907e18c38dec1f75d05f2a4790725 2 parents 298cf60 + 120be23
@mevivs mevivs authored
View
8 kundera-neo4j/pom.xml
@@ -82,6 +82,14 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
+
+ <!-- Jersey - REST Libraries -->
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>1.12</version>
+ </dependency>
+
</dependencies>
<build>
<plugins>
View
1  kundera-neo4j/src/main/java/com/impetus/client/neo4j/Neo4JRESTClient.java
@@ -28,6 +28,7 @@
/**
* Client implementation of Neo4J using Neo4J REST API
* (See Neo4j REST API in http://www.neo4j.org/develop/drivers)
+ * (See http://docs.neo4j.org/chunked/milestone/server-java-rest-client-example.html)
* @author amresh.singh
*/
public class Neo4JRESTClient extends Neo4JClientBase implements Client<Neo4JQuery>
View
30 kundera-neo4j/src/main/java/com/impetus/client/neo4j/Neo4JRESTClientFactory.java
@@ -18,6 +18,8 @@
import java.util.Map;
import java.util.Properties;
+import javax.ws.rs.core.MediaType;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,6 +30,8 @@
import com.impetus.kundera.loader.GenericClientFactory;
import com.impetus.kundera.metadata.model.KunderaMetadata;
import com.impetus.kundera.metadata.model.PersistenceUnitMetadata;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
/**
* Factory of {@link Neo4JRESTClient}
@@ -71,15 +75,15 @@ protected Object getConnectionPoolOrConnection()
.getPersistenceUnitMetadata(getPersistenceUnit());
Properties props = puMetadata.getProperties();
-
+
String host = null;
String port = null;
-
+
if (externalProperties != null)
{
host = (String) externalProperties.get(PersistenceProperties.KUNDERA_NODES);
port = (String) externalProperties.get(PersistenceProperties.KUNDERA_PORT);
-
+
}
if (host == null)
{
@@ -89,9 +93,25 @@ protected Object getConnectionPoolOrConnection()
{
port = (String) props.get(PersistenceProperties.KUNDERA_PORT);
}
+
+ final String SERVER_ROOT_URI = "http://" + host + ":" + port + "/db/data/";
- //TODO: complete code while implementing REST Client factory for Neo4J
- return null;
+ WebResource resource = com.sun.jersey.api.client.Client.create().resource(SERVER_ROOT_URI);
+ WebResource.Builder builder = resource.path(SERVER_ROOT_URI).accept(MediaType.APPLICATION_JSON);
+
+ ClientResponse response = (ClientResponse) builder.get(ClientResponse.class);
+
+ if(response.getStatus() == 200) {
+ log.info(String.format("GET on [%s], status code [%d]", SERVER_ROOT_URI, response.getStatus()));
+ }
+ else
+ {
+ log.error("Could not connect to " + SERVER_ROOT_URI + "; Connection to Neo4J failed.");
+ return null;
+ }
+ response.close();
+
+ return resource;
}
@Override
Please sign in to comment.
Something went wrong with that request. Please try again.