public string SubmitExecute(OpenGis.Wps.Execute executeInput) { IO.Swagger.Model.Execute execute = BuildExecute(executeInput); HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(this.Url + "/jobs"); webRequest.Method = "POST"; webRequest.Accept = "application/json"; webRequest.ContentType = "application/json"; var json = ServiceStack.Text.JsonSerializer.SerializeToString <IO.Swagger.Model.Execute>(execute); context.LogDebug(this, json); byte[] data = System.Text.Encoding.UTF8.GetBytes(json); webRequest.ContentLength = data.Length; using (var requestStream = webRequest.GetRequestStream()) { requestStream.Write(data, 0, data.Length); requestStream.Close(); using (var httpResponse = (HttpWebResponse)webRequest.GetResponse()) { using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); var response = ServiceStack.Text.JsonSerializer.DeserializeFromString <Wps3>(result); var location = new Uri(httpResponse.Headers["Location"], UriKind.RelativeOrAbsolute); if (!location.AbsoluteUri.StartsWith("http")) { location = new Uri(new Uri(this.Url), location); } return(location.AbsoluteUri); } } } }
/*******************/ /* WPS 3.0 EXECUTE */ /*******************/ public new object Execute(OpenGis.Wps.Execute executeInput, string jobreference = null) { if (this.IsWPS3()) { context.LogDebug(this, "WPS 3.0.0 Execute"); var creationTime = DateTime.UtcNow; var location = SubmitExecute(executeInput); ExecuteResponse response = new ExecuteResponse(); response.statusLocation = location; var uri = new Uri(location); response.serviceInstance = string.Format("{0}://{1}/", uri.Scheme, uri.Host); response.Process = ProcessBrief; response.service = "WPS"; response.version = "3.0.0"; response.Status = new StatusType { Item = new ProcessAcceptedType() { Value = string.Format("Preparing job") }, creationTime = creationTime }; //TODO return(response); //TODO: handle case of errors } else { context.LogDebug(this, "WPS 1.0.0 Execute"); return(base.Execute(executeInput, jobreference)); } }
protected IO.Swagger.Model.Execute BuildExecute(OpenGis.Wps.Execute executeInput) { context.LogDebug(this, "BuildExecute"); var wps3 = GetWps3ProcessingFromDescribeProcess(this.Url); List <IO.Swagger.Model.Input> inputs = new List <IO.Swagger.Model.Input>(); foreach (var dataInput in executeInput.DataInputs) { var inp = new Inputs(); inp.Id = dataInput.Identifier.Value; context.LogDebug(this, "BuildExecute - input = " + dataInput.Identifier.Value); if (dataInput.Data != null && dataInput.Data.Item != null) { if (dataInput.Data.Item is OpenGis.Wps.LiteralDataType) { var datatype = "string"; foreach (var i in wps3.Process.Inputs) { if (inp.Id == i.Id) { if (i.Input.LiteralDataDomains != null) { var literaldomain = i.Input.LiteralDataDomains[0]; if (!string.IsNullOrEmpty(literaldomain.DataType.Reference)) { datatype = literaldomain.DataType.Reference; } } } } var ld = dataInput.Data.Item as OpenGis.Wps.LiteralDataType; string inputValue = ld.Value; Uri outUri; if (Uri.TryCreate(inputValue, UriKind.Absolute, out outUri) && (outUri.Scheme == Uri.UriSchemeHttp || outUri.Scheme == Uri.UriSchemeHttps)) { try { var urib = new UriBuilder(inputValue); var nvc = HttpUtility.ParseQueryString(urib.Query); //case WPS3 endpoint does not support format=json if (CatalogueFactory.IsCatalogUrl(urib.Uri) && !string.IsNullOrEmpty(context.GetConfigValue("wps3input-format"))) { nvc["format"] = context.GetConfigValue("wps3input-format"); } //case WPS3 endpoint needs a specific downloadorigin if (CatalogueFactory.IsCatalogUrl(urib.Uri) && !string.IsNullOrEmpty(context.GetConfigValue("wps3input-downloadorigin"))) { nvc["do"] = context.GetConfigValue("wps3input-downloadorigin"); } string[] queryString = Array.ConvertAll(nvc.AllKeys, key => string.Format("{0}={1}", key, nvc[key])); urib.Query = string.Join("&", queryString); inputValue = urib.Uri.AbsoluteUri; } catch (System.Exception e) { context.LogError(this, e.Message); } } StupidData literalData = new StupidData(inputValue, new StupidDataType(datatype)); inputs.Add(new IO.Swagger.Model.Input(dataInput.Identifier.Value, literalData)); } } } List <IO.Swagger.Model.Output> outputs = new List <IO.Swagger.Model.Output>(); var output = new IO.Swagger.Model.Output(); output.Id = "wf_outputs"; output.TransmissionMode = TransmissionMode.Reference; output.Format = new IO.Swagger.Model.Format("application/json"); outputs.Add(output); return(new IO.Swagger.Model.Execute(inputs, outputs, IO.Swagger.Model.Execute.ModeEnum.Async, IO.Swagger.Model.Execute.ResponseEnum.Raw, null)); }