Created
March 19, 2014 23:34
-
-
Save jirihelmich/9653951 to your computer and use it in GitHub Desktop.
Store graph in virtuoso via HTTP Graph Store Protocol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def storeGraphGraphProtocol(graphURI: String, graph: Graph){ | |
| val httpSuffix = if(endpointUsesSSL){"s"}else{""} | |
| val requestUri = String.format("http%s://%s:%s/sparql-graph-crud-auth?graph-uri=%s", httpSuffix, server, endpointPort.toString, graphURI) | |
| val creds = new UsernamePasswordCredentials(sqlUsername, sqlPassword) | |
| val httpclient = new DefaultHttpClient() | |
| val post = new HttpPost(requestUri) | |
| post.addHeader("X-Requested-Auth", "Digest") | |
| post.addHeader("Content-Type", "application/xml") | |
| try { | |
| httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds) | |
| val stringEntity = new StringEntity( graph.toStringRepresentation(RdfRepresentation.RdfXml) , "UTF-8") | |
| stringEntity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/xml")) | |
| post.setEntity(stringEntity) | |
| httpclient.execute(post) | |
| } finally { | |
| httpclient.getConnectionManager().shutdown() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment