How to neo4j server using popoto js - neo4j

I am trying to run popoto js example but not working.
code:
popoto.rest.CYPHER_URL = "http://localhost:7474/db/data/transaction/commit";
popoto.rest.AUTHORIZATION = "Basic " + btoa("neo4j:password");
But the cypher url not working.

You need to change the password portion of popoto.rest.AUTHORIZATION = "Basic " + btoa("neo4j:password"); to the password of the neo4j server. This assumes that the default username is still neo4j.

Related

HTTP Basic Authentication for phantomjs in Ruby on Rails

I'm currently developing a script where users can access a page and scrape data from it.
Problem is, it has an HTTP Basic Authentication.
At first I was using the http://user:password#site.com and it works. But when the password contains special characters besides the Base64, it doesn't login.
I am using phantomjs and watir-webdriver for this script.
I already tried this code:
caps = { 'phantomjs.page.settings.userName' => 'admin', 'phantomjs.page.settings.password' => 'password' }
browser = Watir::Browser.new :phantomjs, :desired_capabilites => caps
sometimes it works, sometimes not.
I also tried the custom headers:
caps = {'phantomjs.page.customHeaders.Authorization'=> "Basic " + Base64.encode64(admin+ ":" + password).chomp}
but it doesn't work.
I also tried this solution from another link:
popup = RAutomation::Window.new(:title => /Authentication/i)        
popup.text_field(:index => 0).set('XXXXXX') # USER ID 
popup.text_field(:index => 1).set('YYYYYYYYY') # PASSWORD
popup.button(:index => 1).click 
but it doesn't see the dialog box.
What are the other possible solutions for this? I cannot ask users to change their passwords for them to login.

Is it possible to query a Neo4J db using Cypher, via the REST API, and return the URI of a node?

Background:
I am using a locally run Neo4J instance, (at localhost:7474), and accessing it through a Java adaptor which uses Cypher via the REST API (with Jersey), and makes data accessible to my Grails app running on the same server.
Question:
Is it possible to query a Neo4J db using Cypher, via the REST API, and return the URI of a node? Right now, I can check Neo4J server status, create nodes, populate node properties, query, and create relationships.
My problem is that my "add relationship" and traversal code requires a node URIs as input. I can query for nodes and obtain the correct JSON describing the results, but I cannot seem to get the URI locations.
Here is a simplified version of my getUserByEmail code:
public URI getUserByEmail( String email )
{
System.out.println( "GETTING USER BY EMAIL [" + email + "]..." );
String queryStr = "MATCH (user) WHERE user.nodetype=\'user\' and user.email=\'" + email + "\' RETURN user";
WebResource webResource = client.resource( ROOT_URI + "/transaction/commit" );
String payload = "{\"statements\" : [ {\"statement\" : \"" + queryStr + "\"} ]}";
ClientResponse response = webResource
.accept( MediaType.APPLICATION_JSON )
.type( MediaType.APPLICATION_JSON )
.entity( payload )
.post( ClientResponse.class );
String responseStr = response.getEntity( String.class );
URI responseLocation = response.getLocation();
System.out.println( "RESPONSE STRING: " + responseStr );
System.out.println( "GOT USER AT: [" + responseLocation + "]" );
return responseLocation;
}
The JSON results come back fine and reflect what is in the graph db. The location, however, is always null.
The "add relationship" code that I am using works, as long as I have the URI to the start node. The code I have is based on the addRelationship() code that lives here:
https://github.com/neo4j/neo4j/blob/2.1.6/community/server-examples/src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java
In your JSON results, the self property value for each "user" will be its URI.
In this example, the response has 2 "n" nodes, and the self property value of each is its URI.
Here is an example of how to get the transactional endpoint (which is normally less verbose than the legacy endpoint) to also return the self property.
You can in your case create the node uri yourself by just appending the node internal id to the following url :
http://localhost:7474/db/data/node/your-123-id
maybe you want to set the scheme, host and database port in a configuration file to not do hardcode changes when changing the database location.

Getting 404 Not Found when doing a jira search for project

I am trying to learn RESTFul web services using Jersey
I have written some java code to return the json for a JIRA search for a project ID, the code is based on that created by Bernd Hort (BP206 at connect2014)
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter("username", "password");
client.addFilter(authFilter);
WebResource service = client.resource(getBaseURI());
String searchquery = "search?jql=id=" + id + "&maxResults=5000";
System.out.println("Query=" + searchquery);
String json = service.path(searchquery).accept(
MediaType.APPLICATION_JSON).get(String.class);
I have tested the search using both Postman and putting it into the browser url and it returns data.
http://myserver:8080/rest/api/2/search?jql=id=12408&maxResults=5000
when I try it in my java code I get the following error;
com.sun.jersey.api.client.UniformInterfaceException: GET http://myserver:8080/rest/api/2/search%3Fjql=id=12408&maxResults=5000 returned a response status of 404 Not Found
it seems to be changing the '?' to '%3f' which the search doesn't like
You're specifying that query as part of the path, so it's being escaped as such:
String json = service.path(searchquery).accept(
MediaType.APPLICATION_JSON).get(String.class);
You want to make it a query parameter:
String json = service.path("search")
.queryParam("jql", "id=" + id)
.queryParam("maxResults", "5000)
.accept(MediaType.APPLICATION_JSON).get(String.class);

Using REST APIs

I am new to gerrit. I am using gerrit V. 2.6 . I want to use gerrit REST APIs in my python script. But not able to figure out how to use it. I tried below code but getting errors.
curl --digest --user user:password http://server/a/changes/path/to/project~branch~change_id/rebase
getting error :
401 Authorization Required
Authorization Required
This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.
Am I missing something.??
Are you using the correct username:password combination? This isn't your network password - it is the HTTP password that gerrit generates. You can find it by going to Settings->HTTP Password. If the password box is blank, click the button to have Gerrit generate a new password.
You may try using pygerrit. https://pypi.python.org/pypi/pygerrit/0.2.1
I think it has some APIs to easily access gerrit.
As #Ramraj mentioned, you can try using pygerrit or pygerrit2.
And I provide some examples that how I use gerrit REST APIs in my python script.
Here is the code.
auth = HTTPBasicAuth(username, password)
rest = GerritRestAPI(url='http://review.xxxxxx.com:8080', auth=auth)
Query changes by change number.
info = rest.get("/changes/?q=change:{}".format(change_number))
change_id = info[0]['change_id']
subject = info[0]['subject']
Query changes by commit id.
info = rest.get("/changes/?q=commit:{}".format(commit_id))
change_id = info[0]['change_id']
subject = info[0]['subject']
Revert a change.
headers = {'content-type': 'application/json'}
query = "/changes/" + str(change_number) + "/revert"
my_data = {"message": "{}".format("Revert "+str(subject))}
rest.post(query, data=json.dumps(my_data), timeout=30, headers=headers)
Review a change
headers = {'content-disposition': 'attachment', 'content-type': 'application/json'}
query = "/changes/" + str(change_number) + "/revisions/current/review"
my_data = { "labels": {"Code-Review": "+2", "Verified": "+1"} }
rest.post(query, data=json.dumps(my_data), timeout=30, headers=headers)

Sending Post Data through a HTTP Request POST

I am trying to post data from a Textarea to a classic ASP script that updates the MS SQL on the local machine then posts to a PHP script on another server. However doing the below does not work, as it will cut off the data for the textarea. It has special characters in it for HTML and other data.
So my question is, how do I pass this data through a POST using ASP Classic?
I have been searching all day, so hopefully someone can enlighten me, thanks!
strUrl = "http://www.example.com/index.php"
requestData = request("request")
requestData2 = request("request2")
strData = "request=" & requestData & "&request2=" & requestData2
postHTML (strUrl, strData)
function postHTML (strUrl, strData)
Set xmlHttp = Server.Createobject("MSXML2.ServerXMLHTTP")
xmlHttp.Open "POST", strUrl, False
xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
xmlHttp.Send strData
postHTML = xmlHttp.responseText
xmlHttp.abort()
set xmlHttp = Nothing
end function
For example if an & is in the requestdata2, anything after that & is truncated, because it is thinking it is starting a new string. But I want to be able to pass this along.
Only Solution I can think of as of right now: do a string replace for special characters such as = and & and restore them with another string replace on the php server. This however is not what I want to accomplish this task. I would like the correct way of sending a post.
You need to URL encode the parameter values, so change this line...
strData = "request=" & requestData & "&request2=" & requestData2
...to...
strData = "request=" & Server.UrlEncode(requestData) & "&request2=" & Server.UrlEncode(requestData2)
The receiving server should automatically decode the values.

Resources