Strange bug between SemanticMediaWiki and 4store

129 views
Skip to first unread message

Olivier Rossel

unread,
Apr 25, 2013, 4:17:09 AM4/25/13
to 4store-...@googlegroups.com
Hi all.

I have a problem connection SemanticMediaWiki and 4store.
I could trace the HTTP communication that creates this error:

127.000.000.001.37818-127.000.000.001.09000: POST /update/ HTTP/1.1
Host: localhost:9000
Accept: */*
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
Content-Length: 691

update=PREFIX+wiki%3A+%3Chttp%3A%2F%2F192.168.56.101%2Fmediawiki-1.20.4%2Findex.php%2FSpecial%3AURIResolver%2F%3E%0APREFIX+rdf%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%0APREFIX+rdfs%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%0APREFIX+owl%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2002%2F07%2Fowl%23%3E%0APREFIX+swivt%3A+%3Chttp%3A%2F%2Fsemantic-mediawiki.org%2Fswivt%2F1.0%23%3E%0APREFIX+property%3A+%3Chttp%3A%2F%2F192.168.56.101%2Fmediawiki-1.20.4%2Findex.php%2FSpecial%3AURIResolver%2FProperty-3A%3E%0APREFIX+xsd%3A+%3Chttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23%3E%0ADELETE+%7B+property%3AUnTest+%3Fp+%3Fo+%7D+WHERE+%7B+property%3AUnTest+%3Fp+%3Fo+%7D
127.000.000.001.09000-127.000.000.001.37818: HTTP/1.0 
127.000.000.001.09000-127.000.000.001.37818: 400 4store only implements application/x-www-form-urlencoded
127.000.000.001.09000-127.000.000.001.37818: 

127.000.000.001.09000-127.000.000.001.37818: Server: 4s-httpd/v1.1.4

I am not exactly sure what the problem can be.
Should I upgrade to 4store 1.1.5 ?

Olivier Rossel

unread,
Apr 25, 2013, 4:21:15 AM4/25/13
to 4store-...@googlegroups.com
For your information, here is the error message as it appears in SemanticMediaWiki:

Unexpected non-MediaWiki exception encountered, of type "SMWSparqlDatabaseError"

exception 'SMWSparqlDatabaseError' with message 'A SPARQL query error has occurred
Query: 
PREFIX wiki: <http://192.168.56.101/mediawiki-1.20.4/index.php/Special:URIResolver/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX swivt: <http://semantic-mediawiki.org/swivt/1.0#>
PREFIX property: <http://192.168.56.101/mediawiki-1.20.4/index.php/Special:URIResolver/Property-3A>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
DELETE { property:UnTest ?p ?o } WHERE { property:UnTest ?p ?o }
Error: Malformed query
Endpoint: http://localhost:9000/update/
HTTP response code: 400
' in /var/www/mediawiki-1.20.4/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php:590

Steve Harris

unread,
Apr 25, 2013, 5:10:53 AM4/25/13
to 4store-...@googlegroups.com
It might be worth trying 1.1.5.

If that doesn't work, could you try applying the following patch.

It should log something to give us a clue why it's being rejected. The request looks OK at a glance, but it's hard to tell by eye of course.

- Steve

diff --git a/src/http/httpd.c b/src/http/httpd.c
index 02e16b2..a669647 100644
--- a/src/http/httpd.c
+++ b/src/http/httpd.c
@@ -1203,6 +1203,7 @@ static void http_post_request(client_ctxt *ctxt, gchar *url, gchar *protocol)
       http_error(ctxt, "400 4store only implements application/x-www-form-urlencoded");
       http_close(ctxt);
       g_free(form_type);
+      fs_error(LOG_ERR, "received Content-Type of '%s', expecting 'application/x-www-form-urlencoded'", form_type);
       return;
     }
     g_free(form_type);

--
You received this message because you are subscribed to the Google Groups "4store-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 4store-support+u...@googlegroups.com.
To post to this group, send email to 4store-sup...@googlegroups.com.
Visit this group at http://groups.google.com/group/4store-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
Steve Harris
Experian
Registered in England and Wales 653331 VAT # 887 1335 93
80 Victoria Street, London, SW1E 5JL

Olivier Rossel

unread,
Apr 25, 2013, 10:54:21 AM4/25/13
to 4store-...@googlegroups.com
Ok. So I could figure out the problem. 

The Content-Type sent by SemanticMediaWiki contains the string "application/x-www-form-urlencoded", followed by the encoding.
But 4store tests a strict matching of the Content-Type string value against the string "application/x-www-form-urlencoded"
(via the strcasecmp() function).

This is wrong.
Because what you really want to test is that the Content-Type starts with the string "application/x-www-form-urlencoded".

The correct way should be to use the strncasecmp() function in httpd.c.

Instead of:
strcasecmp(form_type, "application/x-www-form-urlencoded")

you should use:
strncasecmp(form_type, "application/x-www-form-urlencoded", strlen("application/x-www-form-urlencoded"))

That change should be done at line 1202, 1291, 1370, 

Note: I have no clue how to alter the code on GitHub.
Here is a patch generated by Git:

From 9d02d69abb09547880319715684e2cd43b2447aa Mon Sep 17 00:00:00 2001
From: Olivier Rossel <git...@lolive.net>
Date: Thu, 25 Apr 2013 16:48:09 +0200
Subject: [PATCH] Content-type must ***begin with*** 
 "application/x-www-form-urlencoded"

---
 src/http/httpd.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/http/httpd.c b/src/http/httpd.c
index 02e16b2..00dcd2d 100644
--- a/src/http/httpd.c
+++ b/src/http/httpd.c
@@ -1199,7 +1199,7 @@ static void http_post_request(client_ctxt *ctxt, gchar *url, gchar *protocol)
   url_decode(url);
   if (!strcmp(url, "/sparql/")) {
     char *form_type = just_content_type(ctxt);
-    if (!form_type || strcasecmp(form_type, "application/x-www-form-urlencoded")) {
+    if (!form_type || strncasecmp(form_type, "application/x-www-form-urlencoded", strlen("application/x-www-form-urlencoded"))) {
       http_error(ctxt, "400 4store only implements application/x-www-form-urlencoded");
       http_close(ctxt);
       g_free(form_type);
@@ -1288,7 +1288,7 @@ static void http_post_request(client_ctxt *ctxt, gchar *url, gchar *protocol)
 
   } else if (!strcmp(url, "/update/")) {
     const char *form_type = g_hash_table_lookup(ctxt->headers, "content-type");
-    if (!form_type || strcasecmp(form_type, "application/x-www-form-urlencoded")) {
+    if (!form_type || strncasecmp(form_type, "application/x-www-form-urlencoded", strlen("application/x-www-form-urlencoded"))) {
       http_error(ctxt, "400 4store only implements application/x-www-form-urlencoded");
       http_close(ctxt);
       return;
@@ -1367,7 +1367,7 @@ static void http_post_request(client_ctxt *ctxt, gchar *url, gchar *protocol)
 
   } else if (!strcmp(url, "/data/")) {
     char *form_type = just_content_type(ctxt);
-    if (!form_type || strcasecmp(form_type, "application/x-www-form-urlencoded")) {
+    if (!form_type || strncasecmp(form_type, "application/x-www-form-urlencoded", strlen("application/x-www-form-urlencoded"))) {
       http_error(ctxt, "400 4store only implements application/x-www-form-urlencoded");
       http_close(ctxt);
       g_free(form_type);
-- 
1.7.10.4

Steve Harris

unread,
Apr 25, 2013, 12:29:31 PM4/25/13
to 4store-...@googlegroups.com
That isn't what 4store does.

It calls a function called "just_content_type()", which strips the encoding off, before doing the case insensitive comparison.

- Steve

--
You received this message because you are subscribed to the Google Groups "4store-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 4store-support+u...@googlegroups.com.
To post to this group, send email to 4store-sup...@googlegroups.com.
Visit this group at http://groups.google.com/group/4store-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Douglas Beeson

unread,
Apr 26, 2013, 8:52:44 AM4/26/13
to 4store-...@googlegroups.com
I have run into the same error and resolved the problem by commenting out the SMW code the ";charset=UTF-8" portion of the Content-Type string.
Olivier, try searching the Semantic MediaWiki group on Google or try the thread here: http://wikimedia.7.n6.nabble.com/4Store-and-SMW-1-8-Error-Malformed-query-tp4992768p4999183.html

Steve, does it make sense that 4store would choke on the charset clause?

-doug 

Steve Harris

unread,
Apr 29, 2013, 10:02:04 AM4/29/13
to 4store-...@googlegroups.com
No, there's code specifically there to handle it - could be it's buggy of course.

I posted a patch that would let someone see where the issue is, I don't SWM installed, so can't try it myself.

- Steve

--
You received this message because you are subscribed to the Google Groups "4store-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 4store-support+u...@googlegroups.com.
To post to this group, send email to 4store-sup...@googlegroups.com.
Visit this group at http://groups.google.com/group/4store-support?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Karel Gardas

unread,
Jul 7, 2014, 2:19:56 PM7/7/14
to 4store-...@googlegroups.com

Steve,

unfortunately in case of /update which Oliver hits here you made a mistake and not use just_content_type() so Oliver is right with his observation. I've hit the exact issue here with Jena running against 4store. I agree with you thought that the Oliver's patch is not the best hence I've already sent pull request for this: https://github.com/garlik/4store/pull/111 issue.

Cheers,
Karel
Reply all
Reply to author
Forward
0 new messages