/// <summary> /// Processes requests /// </summary> /// <param name="context">HTTP Context</param> public void ProcessRequest(HttpContext context) { this._config = this.LoadConfig(context, out this._basePath); //Add our Standard Headers HandlerHelper.AddStandardHeaders(context, this._config); String path = context.Request.Path; if (path.StartsWith(this._basePath)) { path = path.Substring(this._basePath.Length); } //Q: Commented out as current Service Description draft specifications says only a single Service can be described in a document. Reinstate if drafts change? //if (context.Request.HttpMethod.Equals("OPTIONS")) //{ // //OPTIONS requests always result in the Service Description document // IGraph svcDescrip = SparqlServiceDescriber.GetServiceDescription(context, this._config, new Uri(new Uri(context.Request.Url.AbsoluteUri), this._basePath + "description")); // HandlerHelper.SendToClient(context, svcDescrip, this._config); //} //else //{ switch (path) { case "query": this.ProcessQueryRequest(context); break; case "update": this.ProcessUpdateRequest(context); break; //case "description": // this.ProcessDescriptionRequest(context); // break; default: this.ProcessProtocolRequest(context); break; } //} }
/// <summary> /// Processes requests /// </summary> /// <param name="context">HTTP Context</param> public void ProcessRequest(HttpContext context) { this._config = this.LoadConfig(context, out this._basePath); //Add our Standard Headers HandlerHelper.AddStandardHeaders(context, this._config); String path = context.Request.Path; if (path.StartsWith(this._basePath)) { path = path.Substring(this._basePath.Length); } //OPTIONS requests always result in the Service Description document if (context.Request.HttpMethod.Equals("OPTIONS")) { IGraph svcDescrip = SparqlServiceDescriber.GetServiceDescription(context, this._config, new Uri(new Uri(context.Request.Url.AbsoluteUri), this._basePath + "description"), ServiceDescriptionType.All); HandlerHelper.SendToClient(context, svcDescrip, this._config); } else { //Otherwise determine the type of request based on the Path switch (path) { case "query": this.ProcessQueryRequest(context); break; case "update": this.ProcessUpdateRequest(context); break; case "description": this.ProcessDescriptionRequest(context); break; default: this.ProcessProtocolRequest(context); break; } } }
/// <summary> /// Generates a SPARQL Service Description Graph for the specified portion of the SPARQL Server Handler Configuration or uses the configuration supplied Description Graph /// </summary> /// <param name="context">HTTP Context</param> /// <param name="config">SPARQL Server Configuration</param> /// <param name="descripUri">Base URI of the Description</param> /// <param name="type">Portion of the SPARQL Server to describe</param> /// <returns></returns> public static IGraph GetServiceDescription(HttpContext context, BaseSparqlServerConfiguration config, Uri descripUri, ServiceDescriptionType type) { //Use user specified Service Description if present if (config.ServiceDescription != null) return config.ServiceDescription; IGraph g = SparqlServiceDescriber.GetNewGraph(); IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType)); IUriNode service = g.CreateUriNode("sd:" + ClassService); INode queryNode, updateNode, protocolNode; //Query Service Description if (config.QueryProcessor != null && (type == ServiceDescriptionType.Query || type == ServiceDescriptionType.All)) { //Add the Top Level Node representing the Query Service queryNode = g.CreateUriNode(new Uri(descripUri, "query")); g.Assert(queryNode, rdfType, service); //Add its sd:url IUriNode url = g.CreateUriNode("sd:" + PropertyUrl); g.Assert(queryNode, url, queryNode); //Add the sd:supportedLanguage IUriNode supportedLang = g.CreateUriNode("sd:" + PropertySupportedLanguage); IUriNode lang; switch (config.QuerySyntax) { case SparqlQuerySyntax.Extended: case SparqlQuerySyntax.Sparql_1_1: lang = g.CreateUriNode("sd:" + InstanceSparql11Query); break; default: lang = g.CreateUriNode("sd:" + InstanceSparql10Query); break; } g.Assert(queryNode, supportedLang, lang); //Add the Result Formats IUriNode resultFormat = g.CreateUriNode("sd:" + PropertyResultFormat); foreach (MimeTypeDefinition definition in MimeTypesHelper.Definitions) { if (definition.CanWriteRdf || definition.CanWriteSparqlResults) { if (definition.FormatUri != null) { g.Assert(queryNode, resultFormat, g.CreateUriNode(new Uri(definition.FormatUri))); } } } //Add Features and Dataset Description //First add descriptions for Global Expression Factories IUriNode extensionFunction = g.CreateUriNode("sd:" + PropertyExtensionFunction); IUriNode extensionAggregate = g.CreateUriNode("sd:" + PropertyExtensionAggregate); foreach (ISparqlCustomExpressionFactory factory in SparqlExpressionFactory.Factories) { foreach (Uri u in factory.AvailableExtensionFunctions) { g.Assert(queryNode, extensionFunction, g.CreateUriNode(u)); } foreach (Uri u in factory.AvailableExtensionAggregates) { g.Assert(queryNode, extensionAggregate, g.CreateUriNode(u)); } } } else { queryNode = null; } //Update Service Description if (config.UpdateProcessor != null && (type == ServiceDescriptionType.Update || type == ServiceDescriptionType.All)) { //Add the Top Level Node representing the Update Service updateNode = g.CreateUriNode(new Uri(descripUri, "update")); g.Assert(updateNode, rdfType, service); //Add its sd:url IUriNode url = g.CreateUriNode("sd:" + PropertyUrl); g.Assert(updateNode, url, updateNode); //Add the sd:supportedLanguage IUriNode supportedLang = g.CreateUriNode("sd:" + PropertySupportedLanguage); g.Assert(updateNode, supportedLang, g.CreateUriNode("sd:" + InstanceSparql11Update)); //Add Features and Dataset Description //First add descriptions for Global Expression Factories IUriNode extensionFunction = g.CreateUriNode("sd:" + PropertyExtensionFunction); IUriNode extensionAggregate = g.CreateUriNode("sd:" + PropertyExtensionAggregate); foreach (ISparqlCustomExpressionFactory factory in SparqlExpressionFactory.Factories) { foreach (Uri u in factory.AvailableExtensionFunctions) { g.Assert(updateNode, extensionFunction, g.CreateUriNode(u)); } foreach (Uri u in factory.AvailableExtensionAggregates) { g.Assert(updateNode, extensionAggregate, g.CreateUriNode(u)); } } } else { updateNode = null; } //Graph Store HTTP Protocol Description if (config.ProtocolProcessor != null && (type == ServiceDescriptionType.Protocol || type == ServiceDescriptionType.All)) { //Add the Top Level Node representing the Service if (descripUri.ToString().EndsWith("/description")) { String actualUri = descripUri.ToString(); actualUri = actualUri.Substring(0, actualUri.LastIndexOf("/description") + 1); protocolNode = g.CreateUriNode(new Uri(actualUri)); } else { protocolNode = g.CreateUriNode(descripUri); } g.Assert(protocolNode, rdfType, service); //Add its sd:url IUriNode url = g.CreateUriNode("sd:" + PropertyUrl); g.Assert(protocolNode, url, protocolNode); //Add the Input Formats IUriNode inputFormat = g.CreateUriNode("sd:" + PropertyInputFormat); foreach (MimeTypeDefinition definition in MimeTypesHelper.Definitions) { if (definition.CanParseRdf) { if (definition.FormatUri != null) { g.Assert(protocolNode, inputFormat, g.CreateUriNode(new Uri(definition.FormatUri))); } } } //Add the Result Formats IUriNode resultFormat = g.CreateUriNode("sd:" + PropertyResultFormat); foreach (MimeTypeDefinition definition in MimeTypesHelper.Definitions) { if (definition.CanWriteRdf) { if (definition.FormatUri != null) { g.Assert(protocolNode, resultFormat, g.CreateUriNode(new Uri(definition.FormatUri))); } } } } else { protocolNode = null; } //Finally get the Configuration Node to add additional feature and dataset descriptions config.AddFeatureDescription(g, queryNode, updateNode, protocolNode); return g; }