Is it possible to use Anzo in an AJAX scenario

14 views
Skip to first unread message

Andy

unread,
Jun 20, 2009, 4:54:48 PM6/20/09
to OpenAnzo
I checked the previous posts and the Anzo documentation, but I didn't
see anything that would allow me to construct an XML HTTP Javascript
request to an HTTP endpoint to the Anzo server. The closest thing I
found was the sparql endpoint at:

http://localhost:18080/sparql

BTW, I changed my default port from 8080 due to conflict. However, it
doesn't look like I can POST to this endpoint. Well I can, but it
always returns nothing even for SPARQL queries that work with the anzo
query -f command line.

Does anyone know whether Anzo has a REST style interface analogous to
the command line?

Andy

unread,
Jun 20, 2009, 5:44:52 PM6/20/09
to OpenAnzo
OK, after some playing around I discovered that the above endpoint is
the SPARQL endpoint that probably is suppose to conform to the SPARQL
Protocol for RDF. However, it seems to be buggy. When I send a
properly encoded URI:

http://localhost:18080/sparql/?query=encoded-query

Anzo returns me an HTTP 200 response with media type "application/
sparql-results+xml" and encoding "ISO-8859-1". I'm not really fond of
non-utf-8 encodings, so I added an Accept-Charset header to my request
and Anzo ignored it still giving me "ISO-8859-1". It also appears
that the actual entity body is encoded in N3 and not SPARQL results
XML, even though the media type is "application/sparql-results+xml".

Lee Feigenbaum

unread,
Jun 22, 2009, 2:12:17 PM6/22/09
to open...@googlegroups.com
Andy wrote:
>
>
> On Jun 20, 4:54 pm, Andy <kayak.bl...@gmail.com> wrote:
>> I checked the previous posts and the Anzo documentation, but I didn't
>> see anything that would allow me to construct an XML HTTP Javascript
>> request to an HTTP endpoint to the Anzo server. The closest thing I
>> found was the sparql endpoint at:
>>
>> http://localhost:18080/sparql
>>
>> BTW, I changed my default port from 8080 due to conflict. However, it
>> doesn't look like I can POST to this endpoint. Well I can, but it
>> always returns nothing even for SPARQL queries that work with the anzo
>> query -f command line.
>>
>> Does anyone know whether Anzo has a REST style interface analogous to
>> the command line?

We do not currently have a full REST interface for all of the
command-line interface.

> OK, after some playing around I discovered that the above endpoint is
> the SPARQL endpoint that probably is suppose to conform to the SPARQL
> Protocol for RDF. However, it seems to be buggy. When I send a
> properly encoded URI:
>
> http://localhost:18080/sparql/?query=encoded-query
>
> Anzo returns me an HTTP 200 response with media type "application/
> sparql-results+xml" and encoding "ISO-8859-1". I'm not really fond of
> non-utf-8 encodings, so I added an Accept-Charset header to my request
> and Anzo ignored it still giving me "ISO-8859-1". It also appears
> that the actual entity body is encoded in N3 and not SPARQL results
> XML, even though the media type is "application/sparql-results+xml".

Can you provide sample data and a URL + HTTP request that you supplied
to trigger this behavior?

From a browser (AJAX) environment, you might be better off using the
Anzo.js API. The general API is documented at:

http://www.openanzo.org/projects/openanzo/wiki/AnzoClientDesign

...and there is a sample application in SVN at:

http://www.openanzo.org/projects/openanzo/browser/openanzo/trunk/org.openanzo.js/src/main/resources/docroot/anzo/examples

Lee

>
> >

--
Lee Feigenbaum
VP Technology & Standards, Cambridge Semantics Inc
l...@cambridgesemantics.com
1-617-553-1060

Andy

unread,
Jun 26, 2009, 10:21:15 AM6/26/09
to OpenAnzo
HTTP Request:

GET /sparql/?query=PREFIX%20rdf%3A%20%3Chttp%3A%2F%2Fwww.w3.org
%2F1999%2F02%2F22-rdf-syntax-ns%23%3E%20PREFIX%20rdfs%3A%20%3Chttp%3A
%2F%2Fwww.w3.org%2F2000%2F01%2Frdf-schema%23%3E%20PREFIX%20domain%3A
%20%3Chttp%3A%2F%2Fexample.org%2F%3E%20PREFIX%20ontology%3A%20%3Chttp
%3A%2F%2Fexample.org%2Fontology%2F%3E%20PREFIX%20class%3A%20%3Chttp%3A
%2F%2Fexample.org%2Fontology-class%2F%3E%20PREFIX%20datatype%3A
%20%3Chttp%3A%2F%2Fexample.org%2Fontology-datatype%2F%3E%20PREFIX
%20property%3A%20%3Chttp%3A%2F%2Fexample.org%2Fontology-property%2F%3E
%20CONSTRUCT%20%7B%20%3Finstance%20%3Fproperty%20%3Fvalue%20.%20%7D
%20FROM%20domain%3Aperson%20WHERE%20%7B%20%3Finstance%20rdf%3Atype
%20class%3Aperson%20.%20%3Finstance%20property%3Aid%20%3Fid
%20.%20%3Finstance%20%3Fproperty%20%3Fvalue%20.%20%7D%20ORDER%20BY
%20ASC%28%3Fid%29 HTTP/1.1
User-Agent: Fiddler
Accept-Charset: utf-8
Host: localhost:18080
Authorization: Basic c3lzYWRtaW46MTIz

HTTP Response:

HTTP/1.1 200 OK
Content-Type: application/sparql-results+xml; charset=ISO-8859-1
Transfer-Encoding: chunked
Server: Jetty(6.1.x)

231B

<http://example.org/person/6> <http://example.org/ontology-property/
id> "6"^^<http://www.w3.org/2001/XMLSchema#unsignedInt> ;
<http://lda.info/ontology-property/created>
"2009-04-29T00:00:00.0Z"^^<http://www.w3.org/2001/
XMLSchema#dateTime> .

<http://example.org/person/1> a <http://example.org/ontology-class/
person> .

<http://example.org/person/10> <http://example.org/ontology-property/
gender> "male"^^<http://www.w3.org/2001/XMLSchema#string> .

<http://example.org/person/9> <http://example.org/ontology-property/
name> "Roger Thompson"^^<http://www.w3.org/2001/XMLSchema#string> ;
<http://lda.info/ontology-property/updated>
"2009-04-29T00:00:00.0Z"^^<http://www.w3.org/2001/
XMLSchema#dateTime> .

[lots of triples deleted]

0


Note, the request has Accept-Charset: utf-8, the response has
ISO-8859-1. If the server can only return ISO-8859-1, then it should
have returned HTTP 406 Not Acceptable not 200 OK. Second the response
Content-Type says application/sparql-results+xml, but the entity body
doesn't look like XML, but N3. The request and response was pulled
from the Fiddler HTTP debug proxy Raw session output. Basically,
everything sent or received over the wire. I deleted a number of
triples in the response, to keep this message to a reasonable size.

I looked at the Anzo.js API, but it seemed like it was for debugging
and I didn't get a feel for how to use it from the Wiki page. I'll
look at the example in SVN to see if that gives me a better
understanding on how to use it.

Thanks, Andy.


On Jun 22, 2:12 pm, Lee Feigenbaum <l...@cambridgesemantics.com>
wrote:
> http://www.openanzo.org/projects/openanzo/browser/openanzo/trunk/org....
>
> Lee
>
>
>
> --
> Lee Feigenbaum
> VP Technology & Standards, Cambridge Semantics Inc
> l...@cambridgesemantics.com
> 1-617-553-1060- Hide quoted text -
>
> - Show quoted text -

Lee Feigenbaum

unread,
Jun 26, 2009, 10:39:39 AM6/26/09
to open...@googlegroups.com
Thanks, Andy. I've opened tickets regarding the incorrect handling of
the Content-type and Accept-charset headers.

http://www.openanzo.org/projects/openanzo/ticket/680
http://www.openanzo.org/projects/openanzo/ticket/681

The Anzo.js API is a full-fledged, first-class client API for accessing
an Open Anzo server from a Web application, particularly in AJAX
scenarios. The abstract client API on the wiki page below is implemented
in JavaScript to enable you to write full AJAX applications against an
Open Anzo server. I hope that the examples might provide some guidance
for you.

best,
Lee

Andy

unread,
Jun 26, 2009, 11:25:46 AM6/26/09
to OpenAnzo
The Anzo client API looks interesting, but I'm missing something
fundamental about it. I can see the documentation at:

http://www.openanzo.org/projects/openanzo/wiki/AnzoClientDesign

and the sample at:

http://www.openanzo.org/projects/openanzo/browser/openanzo/trunk/org....

but there isn't any Anzo.js file under my installation. The sample
has a line in it:

dojo.require("anzo.client.AnzoClient");

OK, its using dojo javascript library, but I would expect that there
is a
anzo.client.AnzoClient.js file somewhere and I don't find that either.

So I don't see how the sample actually works or where I need to get
these
javascript files. Can you clear this up for me, it looks like this
would be
ideal for what I'm trying to accomplish.

Thanks, Andy.


On Jun 26, 10:39 am, Lee Feigenbaum <l...@cambridgesemantics.com>
wrote:
> Thanks, Andy. I've opened tickets regarding the incorrect handling of
> the Content-type and Accept-charset headers.
>
> http://www.openanzo.org/projects/openanzo/ticket/680http://www.openanzo.org/projects/openanzo/ticket/681

Ben Szekely

unread,
Jun 26, 2009, 12:38:36 PM6/26/09
to open...@googlegroups.com
Hi Andy,
I'm glad you are going to try out the Anzo.js API. It was designed
to provide simple AJAX-based access to the Anzo repository from the
browser. Sorry for the confusion. 'Anzo.js' is the name of the API, but
we don't actually have such a file. We do have AnzoClient.js and you
can find it and all the other Anzo.js API files in and around

http://www.openanzo.org/projects/openanzo/browser/openanzo/trunk/org.openanzo.js/src/main/resources/docroot/anzo/client

Getting started with Anzo.js is a bit tricky to setup. We are going to
put together some better instructions and a good example next week, but
here is a rough outline of how to get going.

- Because Anzo.js connects directly to the server via Ajax, any HTML and
JS files you write need to be hosted from the Anzo server due to
cross-domain restrictions.

- To do this, you must setup a docroot with the Anzo server. In
openanzo-3.1.0/configuration/regressionConfig you'll find a file called
"org.openanzo.servlet.PublicResources.properties".

- Copy this file to openanzo-3.1.0/configuration/config

- Edit the file with values that make sense for your app. For example

service.factoryPid=org.openanzo.servlet.StaticResourceFactory
org.openanzo.services.instanceURI=http://openanzo.org/servlets/AndyApp
org.openanzo.servlet.contextPath=/andyapp
org.openanzo.servlet.pathSpec=/*
org.openanzo.servlet.docRoot=c:/webapps/andyapp
org.openanzo.servlet.authorizationType=NONE

- Because this is a configuration change, you'll need to delete
openanzo-3.1.0/configuration/org.eclipse.* directories before restarting
the server.

- The docRoot should contain all your HTML and JS files. You can find
some examples of using Anzo.js at

Example 1
-----------

http://www.openanzo.org/projects/openanzo/browser/openanzo/trunk/org.openanzo.js/src/main/resources/docroot/anzo/examples/FOAFBrowser.html

I wouldn't recommend trying to get this running as is, but you can use
it to help build an HTML/JS file that connects to Anzo You can ignore
the BinaryStore stuff in that file. You should replace the script tag

<script type="text/javascript" src="../../dojo/dojo.js"></script>

with

<script type="text/javascript">
var djConfig = {
modulePaths: {'anzo': '/openanzo-js/anzo'}
};
</script>
<script type="text/javascript" src="/openanzo-js/dojo/dojo.js"></script>

Example 2
-----------

http://www.openanzo.org/projects/openanzo/browser/openanzo/trunk/org.openanzo.js/src/main/resources/docroot/anzo/tests/client/AnzoClientTest.js

AnzoClientTest.js is a rather intimidating file, but if you take a look
at the first few simple tests, you'll get an idea of how to use named
graphs from the browser. Use the sample code from the test file in the
HTML file you created based on FOAFBrowser.html and see if you can get
something working.

Please let us know if you have any other questions.

- Ben

Lee Feigenbaum

unread,
Jun 28, 2009, 2:53:19 PM6/28/09
to open...@googlegroups.com
Hi Andy,

We believe that the latest Open Anzo nightly build fixes both the
Accept-Charset and the Content-type bugs. Please do let us know if you
try it out.

best,
Lee
Reply all
Reply to author
Forward
0 new messages