Skip to content

Instantly share code, notes, and snippets.

@dalanlan
Created June 20, 2016 07:33
Show Gist options
  • Select an option

  • Save dalanlan/1dbb042d5d494a15f87aebdbbc5e219d to your computer and use it in GitHub Desktop.

Select an option

Save dalanlan/1dbb042d5d494a15f87aebdbbc5e219d to your computer and use it in GitHub Desktop.

Revisions

  1. dalanlan created this gist Jun 20, 2016.
    47 changes: 47 additions & 0 deletions neo4jClient.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    package com.hulu.neo4j;

    /**
    * Created by simei.he on 6/14/16.
    */

    import com.sun.jersey.api.client.Client;
    import com.sun.jersey.api.client.ClientResponse;
    import com.sun.jersey.api.client.WebResource;
    import sun.misc.BASE64Encoder;

    public class neoRestClient {

    public static void main(String[] args) {

    try {

    String name = "neo4j";
    String pwd = "secret";
    String authString = name + ":" + pwd;
    String authStringEnc = new BASE64Encoder().encode(authString.getBytes());
    Client client = Client.create();

    WebResource webResource = client.resource("http://localhost:7474/service/neighbor/all/actor/Mariann%20%20Aalda/movie/MV000233260000");

    ClientResponse response = webResource.accept("application/json")
    .header("Authorization", "Basic "+ authStringEnc)
    .get(ClientResponse.class);


    if (response.getStatus() != 200) {
    throw new RuntimeException("Failed : HTTP error code : "
    + response.getStatus());
    }

    System.out.println("Output from Server .... \n");
    String output = response.getEntity(String.class);
    System.out.println(output);

    } catch (Exception e) {

    e.printStackTrace();

    }

    }
    }