Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed the server examples.

  • Loading branch information...
commit 3db76baf409c9c1dcfdfd7b6776632daaa0cd8a1 1 parent 789b7df
@nawroth nawroth authored
View
60 pom.xml
@@ -4,13 +4,17 @@
<artifactId>neo4j-examples</artifactId>
<name>Neo4j Examples</name>
<version>1.3-SNAPSHOT</version>
- <description>Neo4j Distribution and examples</description>
+ <description>Neo4j Embedded Examples</description>
<url>http://components.neo4j.org/${project.artifactId}/${project.version}/</url>
<parent>
<groupId>org.neo4j.examples</groupId>
<artifactId>examples-pom</artifactId>
- <version>8</version>
+ <version>17</version>
</parent>
+
+ <scm>
+ <url>https://github.com/neo4j/examples</url>
+ </scm>
<properties>
<short-name>neo4j-examples</short-name>
@@ -19,12 +23,6 @@
<license-text.header>ApacheLicense-2.0-header.txt</license-text.header>
</properties>
- <scm>
- <connection>scm:svn:https://svn.neo4j.org/examples/neo4j-examples/trunk</connection>
- <developerConnection>scm:svn:https://svn.neo4j.org/examples/neo4j-examples/trunk</developerConnection>
- <url>https://trac.neo4j.org/browser/examples/neo4j-examples/</url>
- </scm>
-
<dependencies>
<dependency>
<groupId>org.neo4j</groupId>
@@ -47,15 +45,10 @@
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-udc</artifactId>
- <version>0.2-SNAPSHOT</version>
+ <version>1.3-SNAPSHOT</version>
<classifier>neo4j</classifier>
</dependency>
<dependency>
- <groupId>org.neo4j.app</groupId>
- <artifactId>neo4j-server</artifactId>
- <version>0.6-SNAPSHOT</version>
- </dependency>
- <dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
</dependency>
@@ -63,27 +56,6 @@
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
</dependency>
- <!-- Server example dependencies -->
- <dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-jaxrs</artifactId>
- <version>1.6.1</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-mapper-asl</artifactId>
- <version>1.6.1</version>
- </dependency>
- <dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-server</artifactId>
- <version>1.4</version>
- </dependency>
- <dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-client</artifactId>
- <version>1.4</version>
- </dependency>
</dependencies>
<licenses>
@@ -222,6 +194,8 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
+ <!-- skip building the download assembly -->
+ <!--
<execution>
<id>download-assembly</id>
<phase>package</phase>
@@ -236,6 +210,7 @@
<goal>single</goal>
</goals>
</execution>
+ -->
<execution>
<id>site-assembly</id>
<phase>package</phase>
@@ -307,22 +282,9 @@
</execution>
</executions>
</plugin>
- <plugin>
- <artifactId>maven-release-plugin</artifactId>
- <configuration>
- <tagBase>https://svn.neo4j.org/examples/${short-name}/tags</tagBase>
- </configuration>
- </plugin>
</plugins>
</build>
- <repositories>
- <repository>
- <id>java.net</id>
- <url>http://download.java.net/maven/2/</url>
- </repository>
- </repositories>
-
<reporting>
<plugins>
<plugin>
@@ -344,8 +306,6 @@
</plugin>
<plugin>
<artifactId>maven-jxr-plugin</artifactId>
- <!-- remove version after upgrade to parent-central:11 -->
- <version>2.2</version>
<configuration>
<linkJavadoc>false</linkJavadoc>
</configuration>
View
164 src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java
@@ -1,164 +0,0 @@
-/**
- * Licensed to Neo Technology under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Neo Technology licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.neo4j.examples.server;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import javax.ws.rs.core.MediaType;
-
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
-
-public class CreateSimpleGraph {
-
- private static final String SERVER_ROOT_URI = "http://localhost:7474/db/data/";
-
- public static void main(String[] args) throws URISyntaxException {
- checkDatabaseIsRunning();
-
- // START SNIPPET: nodesAndProps
- URI firstNode = createNode();
- addProperty(firstNode, "name", "Joe Strummer");
- URI secondNode = createNode();
- addProperty(secondNode, "band", "The Clash");
- // END SNIPPET: nodesAndProps
-
- // START SNIPPET: addRel
- URI relationshipUri = addRelationship(firstNode, secondNode, "singer", "{ \"from\" : \"1976\", \"until\" : \"1986\" }");
- // END SNIPPET: addRel
-
- // START SNIPPET: addMetaToRel
- addMetadataToProperty(relationshipUri, "stars", "5");
- // END SNIPPET: addMetaToRel
-
- // START SNIPPET: queryForSingers
- findSingersInBands(firstNode);
- // END SNIPPET: queryForSingers
- }
-
- private static void findSingersInBands(URI startNode) throws URISyntaxException {
- // START SNIPPET: traversalDesc
- // TraversalDescription turns into JSON to send to the Server
- TraversalDescription t = new TraversalDescription();
- t.setOrder(TraversalDescription.DEPTH_FIRST);
- t.setUniqueness(TraversalDescription.NODE);
- t.setMaxDepth(10);
- t.setReturnFilter(TraversalDescription.ALL);
- t.setRelationships(new Relationship("singer", Relationship.OUT));
- // END SNIPPET: traversalDesc
-
- // START SNIPPET: traverse
- URI traverserUri = new URI(startNode.toString() + "/traverse/node");
- WebResource resource = Client.create().resource(traverserUri);
- String jsonTraverserPayload = t.toJson();
- ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).entity(jsonTraverserPayload).post(ClientResponse.class);
-
- System.out.println(String.format("POST [%s] to [%s], status code [%d], returned data: " + System.getProperty("line.separator") + "%s", jsonTraverserPayload, traverserUri, response.getStatus(), response.getEntity(String.class)));
- // END SNIPPET: traverse
- }
-
- // START SNIPPET: insideAddMetaToProp
- private static void addMetadataToProperty(URI relationshipUri, String name, String value) throws URISyntaxException {
- URI propertyUri = new URI(relationshipUri.toString() + "/properties");
- WebResource resource = Client.create().resource(propertyUri);
-
- String entity = toJsonNameValuePairCollection(name, value);
- ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).entity(entity).put(ClientResponse.class);
-
- System.out.println(String.format("PUT [%s] to [%s], status code [%d]", entity, propertyUri, response.getStatus()));
- }
- // END SNIPPET: insideAddMetaToProp
-
- private static String toJsonNameValuePairCollection(String name, String value) {
- return String.format("{ \"%s\" : \"%s\" }", name, value);
- }
-
- private static URI createNode() {
- // START SNIPPET: createNode
- final String nodeEntryPointUri = SERVER_ROOT_URI + "node"; // http://localhost:7474/db/manage/node
-
- WebResource resource = Client.create().resource(nodeEntryPointUri); // http://localhost:7474/db/data/node
- ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).entity("{}").post(ClientResponse.class); // POST {} to the node entry point URI
-
- System.out.println(String.format("POST to [%s], status code [%d], location header [%s]", nodeEntryPointUri, response.getStatus(), response.getLocation().toString()));
-
- return response.getLocation();
- // END SNIPPET: createNode
- }
-
- // START SNIPPET: insideAddRel
- private static URI addRelationship(URI startNode, URI endNode, String relationshipType, String jsonAttributes) throws URISyntaxException {
- URI fromUri = new URI(startNode.toString() + "/relationships");
- String relationshipJson = generateJsonRelationship(endNode, relationshipType, jsonAttributes);
-
- WebResource resource = Client.create().resource(fromUri);
- ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).entity(relationshipJson).post(ClientResponse.class); // POST JSON to the relationships URI
-
- System.out.println(String.format("POST to [%s], status code [%d], location header [%s]", fromUri, response.getStatus(), response.getLocation().toString()));
-
- return response.getLocation();
- }
- // END SNIPPET: insideAddRel
-
- private static String generateJsonRelationship(URI endNode, String relationshipType, String ... jsonAttributes) {
- StringBuilder sb = new StringBuilder();
- sb.append("{ \"to\" : \"");
- sb.append(endNode.toString());
- sb.append("\", ");
-
- sb.append("\"type\" : \"");
- sb.append(relationshipType);
- if(jsonAttributes == null || jsonAttributes.length < 1) {
- sb.append("\"");
- } else {
- sb.append("\", \"data\" : ");
- for(int i = 0; i < jsonAttributes.length; i++) {
- sb.append(jsonAttributes[i]);
- if(i < jsonAttributes.length -1) { // Miss off the final comma
- sb.append(", ");
- }
- }
- }
-
- sb.append(" }");
- return sb.toString();
- }
-
- private static void addProperty(URI nodeUri, String propertyName, String propertyValue) {
- // START SNIPPET: addProp
- String propertyUri = nodeUri.toString() + "/properties/" + propertyName;
-
- WebResource resource = Client.create().resource(propertyUri); // http://localhost:7474/db/data/node/{node_id}/properties/{property_name}
- ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).entity("\"" + propertyValue + "\"").put(ClientResponse.class);
-
- System.out.println(String.format("PUT to [%s], status code [%d]", propertyUri, response.getStatus()));
- // END SNIPPET: addProp
- }
-
- private static void checkDatabaseIsRunning() {
- // START SNIPPET: checkServer
- WebResource resource = Client.create().resource(SERVER_ROOT_URI);
- ClientResponse response = resource.get(ClientResponse.class);
-
- System.out.println(String.format("GET on [%s], status code [%d]", SERVER_ROOT_URI, response.getStatus()));
- // END SNIPPET: checkServer
- }
-}
View
57 src/main/java/org/neo4j/examples/server/Relationship.java
@@ -1,57 +0,0 @@
-/**
- * Licensed to Neo Technology under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Neo Technology licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.neo4j.examples.server;
-
-public class Relationship {
-
- public static final String OUT = "out";
- public static final String IN = "in";
- public static final String BOTH = "both";
- private String type;
- private String direction;
-
- public String toJsonCollection() {
- StringBuilder sb = new StringBuilder();
- sb.append("{ ");
- sb.append(" \"type\" : \"" + type + "\"");
- if(direction != null) {
- sb.append(", \"direction\" : \"" + direction + "\"");
- }
- sb.append(" }");
- return sb.toString();
- }
-
- public Relationship(String type, String direction) {
- setType(type);
- setDirection(direction);
- }
-
-
- public Relationship(String type) {
- this(type, null);
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public void setDirection(String direction) {
- this.direction = direction;
- }
-}
View
84 src/main/java/org/neo4j/examples/server/TraversalDescription.java
@@ -1,84 +0,0 @@
-/**
- * Licensed to Neo Technology under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Neo Technology licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.neo4j.examples.server;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public class TraversalDescription {
-
- public static final String DEPTH_FIRST = "depth first";
- public static final String NODE = "node";
- public static final String ALL = "all";
-
- private String uniqueness = NODE;
- private int maxDepth = 1;
- private String returnFilter = ALL;
- private String order = DEPTH_FIRST;
- private List<Relationship> relationships = new ArrayList<Relationship>();
-
- public void setOrder(String order) {
- this.order = order;
- }
-
- public void setUniqueness(String uniqueness) {
- this.uniqueness = uniqueness;
- }
-
- public void setMaxDepth(int maxDepth) {
- this.maxDepth = maxDepth;
- }
-
- public void setReturnFilter(String returnFilter) {
- this.returnFilter = returnFilter;
- }
-
- public void setRelationships(Relationship... relationships) {
- this.relationships = Arrays.asList(relationships);
- }
-
- public String toJson() {
- StringBuilder sb = new StringBuilder();
- sb.append("{ ");
- sb.append(" \"order\" : \"" + order + "\"");
- sb.append(", ");
- sb.append(" \"uniqueness\" : \"" + uniqueness + "\"");
- sb.append(", ");
- if (relationships.size() > 0) {
- sb.append("\"relationships\" : [");
- for (int i = 0; i < relationships.size(); i++) {
- sb.append(relationships.get(i).toJsonCollection());
- if (i < relationships.size() - 1) { // Miss off the final comma
- sb.append(", ");
- }
- }
- sb.append("], ");
- }
- sb.append("\"return filter\" : { ");
- sb.append("\"language\" : \"builtin\", ");
- sb.append("\"name\" : \"");
- sb.append(returnFilter);
- sb.append("\" }, ");
- sb.append("\"max depth\" : ");
- sb.append(maxDepth);
- sb.append(" }");
- return sb.toString();
- }
-}
View
76 src/main/java/org/neo4j/examples/server/plugins/DepthTwo.java
@@ -1,76 +0,0 @@
-/**
- * Licensed to Neo Technology under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Neo Technology licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.neo4j.examples.server.plugins;
-
-import org.neo4j.graphdb.Node;
-import org.neo4j.graphdb.Path;
-import org.neo4j.graphdb.Relationship;
-import org.neo4j.graphdb.traversal.PruneEvaluator;
-import org.neo4j.graphdb.traversal.TraversalDescription;
-import org.neo4j.helpers.Predicate;
-import org.neo4j.kernel.Traversal;
-import org.neo4j.kernel.Uniqueness;
-import org.neo4j.server.plugins.Description;
-import org.neo4j.server.plugins.PluginTarget;
-import org.neo4j.server.plugins.ServerPlugin;
-import org.neo4j.server.plugins.Source;
-
-
-/**
-* An extension performaing a predefined graph traversal
-*/
-@Description( "Performs a depth two traversal along all relationship types." )
-public class DepthTwo extends ServerPlugin
-{
- @Description( "Traverse depth two and return the end nodes" )
- @PluginTarget( Node.class )
- public Iterable<Node> nodesOnDepthTwo( @Source Node node )
- {
- return traversal.traverse( node ).nodes();
- }
-
- @Description( "Traverse depth two and return the last relationships" )
- @PluginTarget( Node.class )
- public Iterable<Relationship> relationshipsOnDepthTwo( @Source Node node )
- {
- return traversal.traverse( node ).relationships();
- }
-
- @Description( "Traverse depth two and return the paths" )
- @PluginTarget( Node.class )
- public Iterable<Path> pathsOnDepthTwo( @Source Node node )
- {
- return traversal.traverse( node );
- }
-
- private static final TraversalDescription traversal = Traversal.description().uniqueness(
- Uniqueness.RELATIONSHIP_PATH ).prune( new PruneEvaluator()
- {
- public boolean pruneAfter( Path position )
- {
- return position.length() >= 2;
- }
- } ).filter( new Predicate<Path>()
- {
- public boolean accept( Path item )
- {
- return item.length() == 2;
- }
- } );
-}
View
60 src/main/java/org/neo4j/examples/server/plugins/GetAll.java
@@ -1,60 +0,0 @@
-/**
- * Licensed to Neo Technology under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Neo Technology licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.neo4j.examples.server.plugins;
-
-import java.util.Iterator;
-
-import org.neo4j.graphdb.Direction;
-import org.neo4j.graphdb.GraphDatabaseService;
-import org.neo4j.graphdb.Node;
-import org.neo4j.graphdb.Relationship;
-import org.neo4j.helpers.collection.NestingIterable;
-import org.neo4j.server.plugins.Description;
-import org.neo4j.server.plugins.Name;
-import org.neo4j.server.plugins.PluginTarget;
-import org.neo4j.server.plugins.ServerPlugin;
-import org.neo4j.server.plugins.Source;
-// START SNIPPET: GetAll
-
-@Description( "An extension to the Neo4j Server for getting all nodes or relationships" )
-public class GetAll extends ServerPlugin
-{
- @Name( "get_all_nodes" )
- @Description( "Get all nodes from the Neo4j graph database" )
- @PluginTarget( GraphDatabaseService.class )
- public Iterable<Node> getAllNodes( @Source GraphDatabaseService graphDb )
- {
- return graphDb.getAllNodes();
- }
-
- @Description( "Get all relationships from the Neo4j graph database" )
- @PluginTarget( GraphDatabaseService.class )
- public Iterable<Relationship> getAllRelationships( @Source GraphDatabaseService graphDb )
- {
- return new NestingIterable<Relationship, Node>( graphDb.getAllNodes() )
- {
- @Override
- protected Iterator<Relationship> createNestedIterator( Node item )
- {
- return item.getRelationships( Direction.OUTGOING ).iterator();
- }
- };
- }
-}
-//END SNIPPET: GetAll
View
61 src/main/java/org/neo4j/examples/server/plugins/ShortestPath.java
@@ -1,61 +0,0 @@
-/**
- * Licensed to Neo Technology under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Neo Technology licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.neo4j.examples.server.plugins;
-
-import org.neo4j.graphalgo.GraphAlgoFactory;
-import org.neo4j.graphalgo.PathFinder;
-import org.neo4j.graphdb.DynamicRelationshipType;
-import org.neo4j.graphdb.Expander;
-import org.neo4j.graphdb.Node;
-import org.neo4j.graphdb.Path;
-import org.neo4j.kernel.Traversal;
-import org.neo4j.server.plugins.Description;
-import org.neo4j.server.plugins.Parameter;
-import org.neo4j.server.plugins.PluginTarget;
-import org.neo4j.server.plugins.ServerPlugin;
-import org.neo4j.server.plugins.Source;
-
-public class ShortestPath extends ServerPlugin
-{
- @Description( "Find the shortest path between two nodes." )
- @PluginTarget( Node.class )
- public Iterable<Path> shortestPath(
- @Source Node source,
- @Description( "The node to find the shortest path to." ) @Parameter( name = "target" ) Node target,
- @Description( "The relationship types to follow when searching for the shortest path(s). Order is insignificant, if omitted all types are followed." ) @Parameter( name = "types", optional = true ) String[] types,
- @Description( "The maximum path length to search for, default value (if omitted) is 4." ) @Parameter( name = "depth", optional = true ) Integer depth )
- {
- Expander expander;
- if ( types == null )
- {
- expander = Traversal.expanderForAllTypes();
- }
- else
- {
- expander = Traversal.emptyExpander();
- for ( int i = 0; i < types.length; i++ )
- {
- expander = expander.add( DynamicRelationshipType.withName( types[i] ) );
- }
- }
- PathFinder<Path> shortestPath = GraphAlgoFactory.shortestPath( expander, depth == null ? 4
- : depth.intValue() );
- return shortestPath.findAllPaths( source, target );
- }
-}
View
66 src/main/java/org/neo4j/examples/server/unmanaged/HelloWorldResource.java
@@ -1,66 +0,0 @@
-/**
- * Licensed to Neo Technology under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Neo Technology licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.neo4j.examples.server.unmanaged;
-
-//START SNIPPET: All
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
-import org.neo4j.server.database.Database;
-import org.neo4j.server.rest.repr.OutputFormat;
-import org.neo4j.server.webadmin.rest.SessionFactoryImpl;
-
-@Path( "/helloworld" )
-public class HelloWorldResource
-{
-
- private final Database database;
-
- public HelloWorldResource( @Context Database database,
- @Context HttpServletRequest req, @Context OutputFormat output )
- {
- this( new SessionFactoryImpl( req.getSession( true ) ), database,
- output );
- }
-
- public HelloWorldResource( SessionFactoryImpl sessionFactoryImpl,
- Database database, OutputFormat output )
- {
- this.database = database;
- }
-
- @GET
- @Produces( MediaType.TEXT_PLAIN )
- @Path( "/{nodeId}" )
- public Response hello( @PathParam( "nodeId" ) long nodeId )
- {
- // Do stuff with the database
- return Response.status( Status.OK ).entity(
- ( "Hello World, nodeId=" + nodeId).getBytes() ).build();
- }
-}
-// END SNIPPET: All
-
View
9 src/site/apt/index.apt
@@ -1,12 +1,3 @@
-Neo4j Server
-
- * {{{./server-rest-api.html}Programming in Java against the Neo4j Server REST API}}
-
- * {{{./server-plugins.html}Extending the Neo4j Server REST API with custom functionality}}
-
- * {{{./server-unmanaged-extensions.html}Deploying arbitrary code and URL endpoints into Neo4j Server}}
-
-
Neo4j Embedded
Neo4j examples contains code examples using the different components
View
72 src/site/apt/server-plugins.apt
@@ -1,72 +0,0 @@
-Server-Plugins
-
- Server-plugins are an easy way to extend the Neo4j REST API with your own functionality.
- In order to compile your plugin, you should include the neo4j-server-xx.jar in your classpath,
- e.g. via pom.xml:
-
----
-<dependency>
- <groupId>org.neo4j.app</groupId>
- <artifactId>neo4j-server</artifactId>
- <version>0.5-SNAPSHOT</version>
-</dependency>
-----
-
- from the neo4j repository at http://m2.neo4j.org/org/neo4j/app/neo4j-server/ or in the system/lib
- directory of the Neo4j Server distribution.
-
-
-%{source-code|snippet=GetAll|file=src/main/java/org/neo4j/examples/server/plugins/GetAll.java}
-
- In order to let the Neo4j Server find your extension, you need to add the file /META-INF/services/org.neo4j.server.plugins.ServerPlugin
- to the resulting .jar file, containing the classname of your plugin as a single line per plugin:
-
----
-org.neo4j.examples.server.plugins.GetAll
----
-
- Now, place the myextension.jar (and any custom dependencies) into the $NEO$J_SERVER_HOME/plugins directory, start the server check out the
- database representation for the listing of your extension:
-
----
-curl -v htto://localhost:7474/db/data
----
- will get you
-
----
-{
-"extensions-info" : "http://localhost:7474/db/data/ext",
-"node" : "http://localhost:7474/db/data/node",
-"node-index" : "http://localhost:7474/db/data/index/node",
-"relationship-index" : "http://localhost:7474/db/data/index/relationship",
-"reference_node" : "http://localhost:7474/db/data/node/0",
-"extensions" : {
- "GetAll" : {
- "get_all_nodes" : "http://localhost:7474/db/data/ext/GetAll/graphdb/get_all_nodes",
- "getAllRelationships" : "http://localhost:7474/db/data/ext/GetAll/graphdb/getAllRelationships"
- }
-}
----
-
- Also, all extensions are listed upon a GET to `http://localhost:7474/db/data/ext/`
-
- Requesting a GET on one of the two extension endpoints...
-
----
-curl http://localhost:7474/db/data/ext/GetAll/graphdb/get_all_nodes
----
-
- ...gives back the meta information about the service:
-
----
-{
- "extends" : "graphdb",
- "description" : "Get all nodes from the Neo4j graph database",
- "name" : "get_all_nodes",
- "parameters" : [ ]
-}
----
-
- To use it, just POST to this URL, with parameters as specified in the description (none in this case).
-
- Full source code: {{{./xref/org/neo4j/examples/server/plugins/GetAll.html}GetAll.java}}
View
176 src/site/apt/server-rest-api.apt
@@ -1,176 +0,0 @@
-Neo4j Server REST API
-
- The Neo4j server combines the REST API and the Web admin application in a single
- easy to install and run solution. The REST API has remained consistent from the 0.8
- release and has simply been ported to the new server infrastructure. As such existing
- code should continue to run.
-
- There's also information on the server
- {{{http://wiki.neo4j.org/content/Getting_Started_With_Neo4j_Server} on the wiki}}.
-
-Creating a graph through the REST API from Java
-
- The REST API uses HTTP and JSON, so that it can be used from many languages and platforms.
- Still, when geting started it's useful to see some patterns that can be re-used. In this
- brief overview, we'll show you how to create and manipulate a simple graph through
- the REST API and also how to query it.
-
- For these examples, we've chosen the {{{http://jersey.java.net/} Jersey}}client components,
- which are easily {{{http://jersey.java.net/nonav/documentation/latest/user-guide.html#chapter_deps}
- downloaded}} via Maven.
-
-Start the server
-
- Before we can perform any actions on the server, we need to start it as per the
- {{{http://wiki.neo4j.org/content/Getting_Started_With_Neo4j_Server#Starting_Neo4j_Server}instructions on the wiki}}.
-
-%{source-code|snippet=checkServer|file=src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java}
-
- If the status of the response is 200 OK, then we know the server is running fine and we
- can continue. If the code fails to conenct to the server, then please revisit the
- {{{http://wiki.neo4j.org/content/Getting_Started_With_Neo4j_Server#Starting_Neo4j_Server}getting started page
- on the wiki}}.
-
- <<If you get any other response than 200 OK (particularly 4xx or 5xx responses) then please
- check your configuration and look in the log files in the data/log directory.>>
-
-
-Creating a node
-
- The REST API uses POST to create nodes. Encapsulating that in Java is straightforward using the Jersey
- client:
-
-%{source-code|snippet=createNode|file=src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java}
-
- If the call completes successfully, under the covers it will have sent a HTTP request containing a JSON
- payload to the server. The server will then have created a new node in the database and responded with a
- <<201 Created>> response and a <<Location>> header with the URI of the newly created node.
-
- In our example, we call this functionality twice to create two nodes in our database.
-
-Adding properties
-
- Once we have nodes in our datatabase, we can use them to store useful data. In this case, we're going to
- store information about music in our database. Let's start by looking at the code that we use to create nodes
- and add properties. Here we've added nodes to represent "Joe Strummer" and a band called "The Clash".
-
-%{source-code|snippet=nodesAndProps|file=src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java}
-
- Inside the addProperty method we determine the resource that represents properties for the node and
- decide on a name for that property. We then proceed to <<PUT>> the value of that property to the server.
-
-%{source-code|snippet=addProp|file=src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java}
-
- If everything goes well, we'll get a <<204 No Content>> back indicating that the server processed the
- request but didn't echo back the property value.
-
-Adding relations
-
- Now that we have nodes to represent Joe Strummer and The Clash, we can relate them. The REST API
- supports this through a POST of a relation representation to the start node of the relation.
- Correspondingly in Java we POST some JSON to the URI of our node that represents Joe Strummer,
- to establish a relation between that node and the node representing The Clash.
-
-%{source-code|snippet=addRel|file=src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java}
-
- Inside the <<addRelationship>> method, we determine the URI of the Joe Strummer node's relations,
- and then POST a JSON description of our intended relationship. This description contains the
- destination node, a label for the relationship type, and any attributes for the relation as a
- JSON collection.
-
-%{source-code|snippet=insideAddRel|file=src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java}
-
- If all goes well, we receive a <<201 Created>> status code and a <<Location>> header which
- contains a URI of the newly created relation.
-
-Add properties to a relation
-
- Like nodes, relations can have properties. Since we're big fans of both Joe Strummer and the Clash,
- we'll add a rating to the relation so that others can see he's a 5-star singer with the band.
-
-%{source-code|snippet=addMetaToRel|file=src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java}
-
- Inside the <<addMetadataToProperty>> method, we determine the URI of the properties of the relationship
- and PUT our new values (since it's PUT it will always overwrite existing values, so be careful).
-
-%{source-code|snippet=insideAddMetaToProp|file=src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java}
-
- Assuming all goes well, we'll get a <<200 OK>> response back from the server (which we can check by calling
- <<ClientResponse.getStatus()>>) and we've now established a very small graph that we can query.
-
-Querying graphs
-
- As with the embedded version of the database, the Neo4j server uses graph traversals to look for data
- in graphs. Currently the Neo4j server expects a JSON payload describing the traversal to be POSTed at
- the starting node for the traversal (though this is <<likely to change>> in time to a GET-based approach).
-
- To start this process, we use a simple class that can turn itself into the equivalent JSON, ready
- for POSTing to the server, and in this case we've hardcoded the traverser to look for all nodes with
- outgoing relationships with the type "singer".
-
-%{source-code|snippet=traversalDesc|file=src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java}
-
- Once we have defined the parameters of our traversal, we just need to transfer it. We do this by
- determining the URI of the traversers for the start node, and then POSTing the JSON representation
- of the traverser to it.
-
-%{source-code|snippet=traverse|file=src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java}
-
- Once that request has completed, we get back our dataset of singers and the bands they belong to:
-
----
-[ {
- "outgoing_relationships" : "http://localhost:7474/db/data/node/82/relationships/out",
- "data" : {
- "band" : "The Clash",
- "name" : "Joe Strummer"
- },
- "traverse" : "http://localhost:7474/db/data/node/82/traverse/{returnType}",
- "all_typed_relationships" : "http://localhost:7474/db/data/node/82/relationships/all/{-list|&|types}",
- "property" : "http://localhost:7474/db/data/node/82/properties/{key}",
- "all_relationships" : "http://localhost:7474/db/data/node/82/relationships/all",
- "self" : "http://localhost:7474/db/data/node/82",
- "properties" : "http://localhost:7474/db/data/node/82/properties",
- "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/82/relationships/out/{-list|&|types}",
- "incoming_relationships" : "http://localhost:7474/db/data/node/82/relationships/in",
- "incoming_typed_relationships" : "http://localhost:7474/db/data/node/82/relationships/in/{-list|&|types}",
- "create_relationship" : "http://localhost:7474/db/data/node/82/relationships"
-}, {
- "outgoing_relationships" : "http://localhost:7474/db/data/node/83/relationships/out",
- "data" : {
- },
- "traverse" : "http://localhost:7474/db/data/node/83/traverse/{returnType}",
- "all_typed_relationships" : "http://localhost:7474/db/data/node/83/relationships/all/{-list|&|types}",
- "property" : "http://localhost:7474/db/data/node/83/properties/{key}",
- "all_relationships" : "http://localhost:7474/db/data/node/83/relationships/all",
- "self" : "http://localhost:7474/db/data/node/83",
- "properties" : "http://localhost:7474/db/data/node/83/properties",
- "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/83/relationships/out/{-list|&|types}",
- "incoming_relationships" : "http://localhost:7474/db/data/node/83/relationships/in",
- "incoming_typed_relationships" : "http://localhost:7474/db/data/node/83/relationships/in/{-list|&|types}",
- "create_relationship" : "http://localhost:7474/db/data/node/83/relationships"
-} ]
----
-
-Phew, is that it?
-
- That's a flavor of what we can do with the REST API. Naturally any of the HTTP idioms we provide on
- the server can be easily wrapped, including removing nodes and relationships through DELETE. Still if
- you've gotten this far, then switching .post() for .delete() in the Jersey client code should be
- straightforward.
-
-What's next?
-
- The HTTP API provides a a good basis for implementers of client libraries, it's also great for
- HTTP and REST folks. In the future though we expect that idiomatic language bindings will
- appear to take advantage of the REST API while providing comfortable language-level constructs
- for developers to use, much as there are similar bindings for the embedded database.
-
-Appendix: the code
-
- * {{{./xref/org/neo4j/examples/server/CreateSimpleGraph.html}CreateSimpleGraph}}
-
- * {{{./xref/org/neo4j/examples/server/Relationship.html}Relationship}}
-
- * {{{./xref/org/neo4j/examples/server/TraversalDescription.html}TraversalDescription}}
-
View
43 src/site/apt/server-unmanaged-extensions.apt
@@ -1,43 +0,0 @@
-Unmanged Server JAXRS extensions
-
- Some projects want extremely fine control over their server-side code and the representation. For this we’ve introduced an unmanaged extension API. It’s a sharp tool, allowing users to deploy arbitrary JAX-RS classes to the server and so you should be careful when thinking about using this. In particular you should understand that it’s easy to consume lots of heap space on the server and hinder performance if you’re not careful. Still, if you understand the disclaimer, then you load your JAX-RS classes into the Neo4j server simply by adding adding a @Context annotation to your code, compiling against the Neo4j server jar, and then adding your classes to the runtime classpath (just drop it in the lib directory of the Neo4j server). In return you get access to the hosted environment of the Neo4j server like logging through the org.neo4j.server.logging.Logger.
-
- You can mout the neo4j server dependencies in Maven via something like
-
----
-<dependency>
- <groupId>org.neo4j.app</groupId>
- <artifactId>neo4j-server</artifactId>
- <version>0.6-SNAPSHOT</version>
-</dependency>
-----
-
- or get the JAR files from the neo4j repository at http://m2.neo4j.org/org/neo4j/app/neo4j-server/ or in the system/lib
- directory of the Neo4j Server distribution.
-
-
-%{source-code|snippet=All|file=src/main/java/org/neo4j/examples/server/unmanaged/HelloWorldResource.java}
-
- This defines a GET endpoint at /helloworld/{nodeId} that will be added to the mount point of this resource
-
- Now, list your extension package in neo4j-server.properties with something like
-
----
-#Comma separated list of JAXRS classes, one package name for each mount point.
-org.neo4j.server.thirdparty_jaxrs_classes=com.example.mycoolextensions="/custom"
----
-
- Now, place the myextension.jar (and any custom dependencies) into the $NEO$J_SERVER_HOME/plugins directory, start the server check out the
- database representation for the listing of your extension:
-
----
-curl -v htto://localhost:7474/custom/helloworld/123
----
-
- will get you
-
----
-Hello World, nodeId=123
----
-
- Full source code: {{{./xref/org/neo4j/examples/server/unmanaged/HelloWorldResource.html}HelloWorldResource.java}}
View
7 src/site/site.xml
@@ -35,11 +35,11 @@
<item name="components" href="http://components.neo4j.org/" />
<item name="apidocs" href="http://api.neo4j.org/" />
</links>
- <menu name="Neo4j">
+ <menu name="Neo4j Embedded Examples">
<item name="Introduction" href="index.html" />
<item name="Neo4j JavaDocs" href="apidocs/index.html" />
<item name="Wiki" href="http://wiki.neo4j.org/content/Getting_Started_With_Apoc" />
- <item name="Source Repository" href="https://svn.neo4j.org/examples/neo4j-examples/trunk/" />
+ <item name="Source Repository" href="${scm.url}" />
<item name="Downloads" href="http://neo4j.org/download/" />
</menu>
<menu name="Examples">
@@ -52,9 +52,6 @@
<item name="Social network" href="social-network.html" />
<item name="Graph algorithms" href="graphalgo.html" />
<item name="Management features" href="management.html" />
- <item name="Neo4j Server REST" href="server-rest-api.html" />
- <item name="Neo4j Server Plugins" href="server-plugins.html" />
- <item name="Neo4j Server Unmanaged Extensions" href="server-unmanaged-extensions.html" />
</menu>
<menu name="Test examples">
<item name="Base test" href="base-test.html" />
Please sign in to comment.
Something went wrong with that request. Please try again.