netHttp.HttpResponseMessage GetHttpResponse(object content, SerializationType serializationType) { string s = GetStringContent(content, serializationType); Encoding encoding = serializationType == SerializationType.Xml ? Encoding.Unicode : Encoding.UTF8; return(new netHttp.HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new netHttp.StringContent(s, encoding, SerializationContentType.GetContentType(serializationType)) }); }
object WaitForTerminalStatusOrTimeout(long instanceId, string planUniqueName, string path, SerializationType serializationType, int pollingIntervalSeconds, int timeoutSeconds, bool setContentType) { object result = SyncExecuteHelper.WaitForTerminalStatusOrTimeout( this, planUniqueName, instanceId, path, serializationType, pollingIntervalSeconds, timeoutSeconds); if (setContentType) { Encoding encoding = serializationType == SerializationType.Xml ? Encoding.Unicode : Encoding.UTF8; netHttp.HttpResponseMessage response = new netHttp.HttpResponseMessage(System.Net.HttpStatusCode.OK); response.Content = new netHttp.StringContent(GetStringContent(result, serializationType), encoding, SerializationContentType.GetContentType(serializationType)); return(response); } else { return(result); } }
public object GetPlanElements(string planUniqueName, long planInstanceId, string elementPath, SerializationType serializationType = SerializationType.Json, bool setContentType = true) { InitPlanServer(); string context = GetContext(nameof(GetPlanStatus), nameof(planUniqueName), planUniqueName, nameof(planInstanceId), planInstanceId, nameof(elementPath), elementPath, nameof(serializationType), serializationType); try { SynapseServer.Logger.Debug(context); PlanElementParms pep = new PlanElementParms(); pep.Type = serializationType; pep.ElementPaths.Add(elementPath); object result = _server.GetPlanElements(planUniqueName, planInstanceId, pep); if (setContentType) { Encoding encoding = serializationType == SerializationType.Xml ? Encoding.Unicode : Encoding.UTF8; netHttp.HttpResponseMessage response = new netHttp.HttpResponseMessage(System.Net.HttpStatusCode.OK); response.Content = new netHttp.StringContent(GetStringContent(result, serializationType), encoding, SerializationContentType.GetContentType(serializationType)); return(response); } else { return(result); } } catch (Exception ex) { SynapseServer.Logger.Error( Utilities.UnwindException(context, ex, asSingleLine: true)); throw; } }
public void Configuration(IAppBuilder app) { HttpListener listener = (HttpListener)app.Properties["System.Net.HttpListener"]; listener.AuthenticationSchemes = SynapseServer.Config.WebApi.Authentication.Scheme; // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); if (SynapseServer.Config.Service.IsRoleController && SynapseServer.Config.Controller.HasAssemblies) { config.Services.Replace(typeof(IAssembliesResolver), new CustomAssembliesResolver()); } // Web API configuration and services config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; // Web API routes config.MapHttpAttributeRoutes(new ServerConfigFileRouteProvider()); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "synapse/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); config.MessageHandlers.Add(new RawContentHandler()); //ss: if( (SynapseServer.Config.WebApi.Authentication.Scheme | AuthenticationSchemes.Basic) != 0 ) if ((SynapseServer.Config.WebApi.Authentication.Scheme & AuthenticationSchemes.Basic) == AuthenticationSchemes.Basic) { IAuthenticationProvider auth = AuthenticationProviderUtil.GetInstance( "Synapse.Authentication", "Synapse.Authentication.AuthenticationProvider", config); string authConfig = Core.Utilities.YamlHelpers.Serialize(SynapseServer.Config.WebApi.Authentication.Config); BasicAuthenticationConfig ac = Core.Utilities.YamlHelpers.Deserialize <BasicAuthenticationConfig>(authConfig); auth.ConfigureBasicAuthentication(ac.LdapRoot, ac.Domain, SynapseServer.Config.WebApi.IsSecure); } if (!SynapseServer.Config.WebApi.AllowContentTypeXml) { var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => SerializationContentType.IsApplicationXml(t.MediaType)); config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType); } else { // Must have this line to support XML body config.Formatters.XmlFormatter.UseXmlSerializer = true; } config.EnableSwagger(x => x.SingleApiVersion("v1", "Synapse Server")).EnableSwaggerUi(); //didn't work :(. //config.EnableSwagger( "synapse/{apiVersion}/swagger", x => x.SingleApiVersion( "v1", "Synapse Server" ) ).EnableSwaggerUi( "synapse/swagger/ui/{*assetPath}" ); app.UseWebApi(config); }