Before Chrome makes a cross-domain AJAX call it makes an OPTIONS check like this:
curl \
'https://fubar.com/users/sign_in' \
-X OPTIONS \
-H 'Access-Control-Request-Method: POST' \
-H 'Origin: http://snafu.com' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' \
-H 'Access-Control-Request-Headers: content-type' \
--compressed \
--insecure \
--verbose
(I added --insecure and --verbose for testing.)
I can see this request in the Apache logs but it doesn't get to Rails.
127.0.0.1 - - [27/Jul/2018:09:22:44 -0400] "OPTIONS /users/sign_in HTTP/1.1" 200 -
If I remove either the Access-Control-Request-Method or Origin headers then it does pass the request to Rails.
Something about the combination of these two headers seems to be causing Apache to handle the request itself and not give Rails a chance to process it.
I am not setting any headers or defining any rewrite rules in the Apache config; it's basically a vanilla install.
I'm not able to find any documentation or configurations explaining why this would be happening and how to prevent it.
1) OPTIONS HTTP call at 'https://fubar.com/users/sign_in' performed from chrome browser with request headers 'Access-Control-Request-Method: POST' and 'Origin: http://snafu.com'
2) the server at 'https://fubar.com/users/sign_in' receives the request
STEP 1
The routing is handles from either nginx or apache webserver which will first apply their own config rules. This settings are included in the file inside /etc/apache2 or /etc/nginx
For example with nginx you can define rules to add_header to the http response or settings to redirect to another url
for example
add_header "Access-Control-Allow-Origin: '*'"
this will add the header "Access-Control-Allow-Origin: '*'" to all responses.
If for example you apply this response to all OPTIONS requests, then all subsequent http request will be whitelisted from any http origin
STEP 2
once the nginx/apache redirection rules are applied, the rails router receives the request and redirects to your controller.
Here you can still add any header you want inside the controller, you can redirect OPTIONS request to a specific controller action, which can add a specific header, be careful to not add twice the same header as that can cause issues.
In this action you can rewrite the Access-Control-Allow-Origin header in the response from the OPTIONS request to whitelist only specific origin domains (you just need to write a routing rule which is applied only to OPTIONS requests)
The origin domain is written in the header of the request
request headers 'Access-Control-Request-Method: POST' and 'Origin: http://snafu.com'
I'm trying to get Slim to run on my Windows 7 system.
So far I've gotten everything installed with Composer but when I run a very simple program, the output is not as intended.
Below is my code:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use Slim\App;
use Slim\Http\Request;
use Slim\Http\Response;
require '../vendor/autoload.php';
$app = new App;
$app->get('/', function (Request $in, Response $out, $args) {
return $out->write("xxxxx");
});
$app->run();
I am expecting output "xxxxx", instead i get "x".
This means I loose 4 characters somewhere.
Running PHP 5.5.12
The encoding is UTF-8 (not BOM)
When i run
"curl -v http://localhost:8080/"
I get
D:\wamp\www\slim_test\src\public>curl -v http://localhost:8080/
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Host: localhost:8080
< Connection: close
< X-Powered-By: PHP/5.5.12
< Content-Type: text/html; charset=UTF-8
< Content-Length: 5
<
x* Closing connection 0
I'd appreciate your help.
EDIT
Once i append these lines of code to the end of the file, the response is correct.
$response = $app->run(true); //Silent mode, wont send the response
$response = $response->withoutHeader("Content-Length"); //Remove the Content-Length
$app->respond($response); //Now we send the response
I cannot figure out why.....?
This issue has been solved as I found a very stupid mistake.
I had 2 blank spaces before the <?php tag.
Using curl I have:
$ curl -v -d "userName=user1&password=passwd1&language=en" http://myhost:23094/api/v2/authToken
...
> POST /api/v2/authToken HTTP/1.1
> User-Agent: curl/7.30.0
> Host: myhost:23094
> Accept: */*
> Content-Length: 39
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 39 out of 39 bytes
< HTTP/1.1 200 OK
I try to build a yandex tank script using this query:
My load.ini:
[phantom]
address=my.ip.v4.here
port=8094
rps_schedule=line(1, 10, 1m)
ammo_type=uripost
My ammo.txt
133 login
POST /api/v2/authToken HTTP/1.1
User-Agent: tank
Host: somemyhost.com
Content-Length: 39
userName=user1&password=passwd1&language=en
When I run yandex-tank ammo.txt, I get the 400 Bad Request error.
It seems to me, that tank can't use the body parameters. How to make it use them? What do I do wrong?
Your ammo is not in uripost format. Don't specify ammo_type at all and it should work properly. If you want to use uripost format, specify your headers in load.ini and write something like the following in your ammo file:
39 /api/v2/authToken login
userName=user1&password=passwd1&language=en
Here is the description of the uripost format.
How i can send request like this via rails
POST /token/ HTTP/1.1
Host: api.admitad.com
Authorization: Basic XXX
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
grant_type=client_credentials&scope=public_data&client_id=XXX
based on admitad api
You can send the POST request via the command line with a tool like cURL:
curl --data-urlencode "grant_type=client_credentials&scope=public_data&client_id=XXX" http://api.admitad.com/token
If you want to use HTTP basic authorization, add the -u option:
curl --data-urlencode "grant_type=client_credentials&scope=public_data&client_id=XXX" http://api.admitad.com/token -u "client_id:public_key"
Another similar command line tool is httpie.org, which uses a slightly different syntax.
I'm a newbie to Neo4j, which is at the moment my main candidate of all the graph databases out there. I'm writing a thesis about integrating a database to a smart city, and Neo4j is one of the best candidates for this purpose, if not the best.
However, I'm unable to get Neo4j's SPARQL plugin working. I'm a newbie also to Maven, but I was able to download the plugin from GitHub and compile it - however, I had to skip the tests to be able to compile it. Anyway, 'build success.'
I followed the instructions
http://neo4j-contrib.github.io/sparql-plugin/
and I suppose that I was able to insert the example quads (example 1) to my database:
curl -X POST -H Content-Type:application/json -H Accept:application/json --data-binary #sampledata.txt -v http:// l o c a l h o s t :7474/db/data/ext/SPARQLPlugin/graphdb/insert_quad
Response:
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 7474 (#0)
> POST /db/data/ext/SPARQLPlugin/graphdb/insert_quad HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:7474
> Content-Type:application/json
> Accept:application/json
> Content-Length: 130
>
* upload completely sent off: 130 out of 130 bytes
< HTTP/1.1 204 No Content
< Access-Control-Allow-Origin: *
* Server Jetty(9.0.5.v20130815) is not blacklisted
< Server: Jetty(9.0.5.v20130815)
<
* Connection #0 to host localhost left intact
However, I cannot find that quad in my database. I suppose that a query 'MATCH (n) RETURN n LIMIT 100' would show them, right? Anyway, I only find one node with one property, 'value: urn:com.tinkerpop.blueprints.pgm.oupls.sail:namespaces.' When I try querying (example 2):
curl -X POST -H Content-Type:application/json -H Accept:application/json --data-binary #sampledata.txt -v http:// l o c a l h o s t :7474/db/data/ext/SPARQLPlugin/graphdb/execute_sparql
Response:
Hostname was NOT found in DNS cache
Trying 127.0.0.1...
Connected to localhost (127.0.0.1) port 7474 (#0)
POST /db/data/ext/SPARQLPlugin/graphdb/execute_sparql HTTP/1.1
User-Agent: curl/7.35.0
Host: localhost:7474
Content-Type:application/json
Accept:application/json
Content-Length: 74
upload completely sent off: 74 out of 74 bytes < HTTP/1.1 500 Server Error < Content-Type: application/json; charset=UTF-8 <
Access-Control-Allow-Origin: * < Content-Length: 3274
Server Jetty(9.0.5.v20130815) is not blacklisted < Server: Jetty(9.0.5.v20130815) < { "message" :
"org.openrdf.query.algebra.Var.setConstant(Z)V", "exception" :
"NoSuchMethodError", "fullname" : "java.lang.NoSuchMethodError",
"stacktrace" : [
"org.openrdf.query.parser.sparql.TupleExprBuilder.createConstVar(TupleExprBuilder.java:340)",
"org.openrdf.query.parser.sparql.TupleExprBuilder.mapValueExprToVar(TupleExprBuilder.java:271)",
"org.openrdf.query.parser.sparql.TupleExprBuilder.visit(TupleExprBuilder.java:1512)",
"org.openrdf.query.parser.sparql.ast.ASTPathSequence.jjtAccept(ASTPathSequence.java:20)",
"org.openrdf.query.parser.sparql.TupleExprBuilder.visit(TupleExprBuilder.java:1323)",
"org.openrdf.query.parser.sparql.ast.ASTPathAlternative.jjtAccept(ASTPathAlternative.java:18)",
"org.openrdf.query.parser.sparql.TupleExprBuilder.visit(TupleExprBuilder.java:1875)",
"org.openrdf.query.parser.sparql.ast.ASTPropertyListPath.jjtAccept(ASTPropertyListPath.java:18)",
"org.openrdf.query.parser.sparql.ast.SimpleNode.childrenAccept(SimpleNode.java:157)",
"org.openrdf.query.parser.sparql.ASTVisitorBase.visit(ASTVisitorBase.java:979)",
"org.openrdf.query.parser.sparql.ast.ASTTriplesSameSubjectPath.jjtAccept(ASTTriplesSameSubjectPath.java:18)",
"org.openrdf.query.parser.sparql.ast.SimpleNode.childrenAccept(SimpleNode.java:157)",
"org.openrdf.query.parser.sparql.ASTVisitorBase.visit(ASTVisitorBase.java:421)",
"org.openrdf.query.parser.sparql.ast.ASTBasicGraphPattern.jjtAccept(ASTBasicGraphPattern.java:19)",
"org.openrdf.query.parser.sparql.TupleExprBuilder.visit(TupleExprBuilder.java:1144)",
"org.openrdf.query.parser.sparql.ast.ASTGraphPatternGroup.jjtAccept(ASTGraphPatternGroup.java:19)",
"org.openrdf.query.parser.sparql.ast.SimpleNode.childrenAccept(SimpleNode.java:157)",
"org.openrdf.query.parser.sparql.ASTVisitorBase.visit(ASTVisitorBase.java:1021)",
"org.openrdf.query.parser.sparql.ast.ASTWhereClause.jjtAccept(ASTWhereClause.java:19)",
"org.openrdf.query.parser.sparql.TupleExprBuilder.visit(TupleExprBuilder.java:389)",
"org.openrdf.query.parser.sparql.TupleExprBuilder.visit(TupleExprBuilder.java:228)",
"org.openrdf.query.parser.sparql.ast.ASTSelectQuery.jjtAccept(ASTSelectQuery.java:19)",
"org.openrdf.query.parser.sparql.TupleExprBuilder.visit(TupleExprBuilder.java:378)",
"org.openrdf.query.parser.sparql.TupleExprBuilder.visit(TupleExprBuilder.java:228)",
"org.openrdf.query.parser.sparql.ast.ASTQueryContainer.jjtAccept(ASTQueryContainer.java:21)",
"org.openrdf.query.parser.sparql.SPARQLParser.buildQueryModel(SPARQLParser.java:210)",
"org.openrdf.query.parser.sparql.SPARQLParser.parseQuery(SPARQLParser.java:164)",
"org.neo4j.server.plugin.sparql.SPARQLPlugin.executeSPARQL(SPARQLPlugin.java:68)",
"java.lang.reflect.Method.invoke(Method.java:606)",
"org.neo4j.server.plugins.PluginMethod.invoke(PluginMethod.java:61)",
"org.neo4j.server.plugins.PluginManager.invoke(PluginManager.java:159)",
"org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension(ExtensionService.java:312)",
"org.neo4j.server.rest.web.ExtensionService.invokeGraphDatabaseExtension(ExtensionService.java:134)",
"java.lang.reflect.Method.invoke(Method.java:606)",
"org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)",
"java.lang.Thread.run(Thread.java:744)" ]
Connection #0 to host localhost left intact
I'm wondering what could be causing this kind of behavior. I have tried SPARQL plugin with many configurations, according to all the instructions I have found, but the plugin just refuses to work.
By the way, I'm wondering is it suitable for production use. Can someone comment on this?
Perhaps there are more ways than one to get RDF working in Neo4j? As I'm a newbie to Neo4j, I'm, of course, interested in solutions that are somewhat easy to install and tailor. Well, first and foremost, they should really work in production use.
Neo4j is working otherwise just great! REST API works just fine, but I would like to compare it with the SPARQL endpoint if possible.