Skip to content

Instantly share code, notes, and snippets.

@jirihelmich
Created March 19, 2014 23:34
Show Gist options
  • Select an option

  • Save jirihelmich/9653951 to your computer and use it in GitHub Desktop.

Select an option

Save jirihelmich/9653951 to your computer and use it in GitHub Desktop.
Store graph in virtuoso via HTTP Graph Store Protocol
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