Skip to content

Commit

Permalink
Various fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
janno-p committed Feb 16, 2018
1 parent a2a3e22 commit c078609
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 13 deletions.
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#### 1.1.3 - 16.02.2018

* Common definition for all protocol versions.
* Move more properties and methods to service manager interface.
* EmptyContentDefinition type.
* More service execution options.

#### 1.1.2 - 15.02.2018

* Allow operation filter to override visibility of operations hidden by schema exporter.
Expand Down
5 changes: 5 additions & 0 deletions src/XRoadLib/Headers/IXRoadHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ public interface IXRoadHeader
/// </summary>
void WriteTo(XmlWriter writer, Style style, HeaderDefinition headerDefinition);
}

public interface IXRoadHeader<out THeader>
{
THeader InitFrom(XRoadCommonHeader commonHeader);
}
}
24 changes: 24 additions & 0 deletions src/XRoadLib/Headers/XRoadCommonHeader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace XRoadLib.Headers
{
public class XRoadCommonHeader
{
public XRoadClientIdentifier Client { get; set; }
public XRoadServiceIdentifier Service { get; set; }

public string UserId { get; set; }
public string Issue { get; set; }
public string Id { get; set; }
public string ProtocolVersion { get; set; }
public string Unit { get; set; }
public string Position { get; set; }
public string UserName { get; set; }
public string Authenticator { get; set; }
public string Paid { get; set; }
public string Encrypt { get; set; }
public string EncryptCert { get; set; }
public string Encrypted { get; set; }
public string EncryptedCert { get; set; }

public bool? Async { get; set; }
}
}
24 changes: 23 additions & 1 deletion src/XRoadLib/Headers/XRoadHeader20.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace XRoadLib.Headers
/// <summary>
/// Details of X-Road message protocol version 2.0 header.
/// </summary>
public class XRoadHeader20 : IXRoadHeader, IXRoadHeader20
public class XRoadHeader20 : IXRoadHeader, IXRoadHeader<XRoadHeader20>, IXRoadHeader20
{
private readonly XRoadClientIdentifier client = new XRoadClientIdentifier();
private readonly XRoadServiceIdentifier service = new XRoadServiceIdentifier();
Expand Down Expand Up @@ -214,5 +214,27 @@ void WriteHeaderValue(string elementName, object value, XName typeName)
WriteHeaderValue("salastatud", Salastatud, XmlTypeConstants.String);
WriteHeaderValue("salastatud_sertifikaadiga", SalastatudSertifikaadiga, XmlTypeConstants.String);
}

public XRoadHeader20 InitFrom(XRoadCommonHeader commonHeader)
{
Asutus = commonHeader.Client.MemberCode;
Andmekogu = commonHeader.Service.MemberCode;
Isikukood = commonHeader.UserId;
Toimik = commonHeader.Issue;
Nimi = commonHeader.Service.ToFullName();
Id = commonHeader.Id;
Allasutus = commonHeader.Unit;
Amet = commonHeader.Position;
AmetnikNimi = commonHeader.UserName;
Asünkroonne = commonHeader.Async;
Autentija = commonHeader.Authenticator;
Makstud = commonHeader.Paid;
Salastada = commonHeader.Encrypt;
SalastadaSertifikaadiga = commonHeader.EncryptCert;
Salastatud = commonHeader.Encrypted;
SalastatudSertifikaadiga = commonHeader.EncryptedCert;

return this;
}
}
}
24 changes: 23 additions & 1 deletion src/XRoadLib/Headers/XRoadHeader31.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace XRoadLib.Headers
/// <summary>
/// Details of X-Road message protocol version 3.1 header.
/// </summary>
public class XRoadHeader31 : IXRoadHeader, IXRoadHeader31
public class XRoadHeader31 : IXRoadHeader, IXRoadHeader<XRoadHeader31>, IXRoadHeader31
{
private readonly XRoadClientIdentifier client = new XRoadClientIdentifier();
private readonly XRoadServiceIdentifier service = new XRoadServiceIdentifier();
Expand Down Expand Up @@ -205,5 +205,27 @@ void WriteHeaderValue(string elementName, object value, XName typeName)
WriteHeaderValue("encrypted", Encrypted, XmlTypeConstants.String);
WriteHeaderValue("encryptedCert", EncryptedCert, XmlTypeConstants.String);
}

public XRoadHeader31 InitFrom(XRoadCommonHeader commonHeader)
{
Consumer = commonHeader.Client.MemberCode;
Producer = commonHeader.Service.MemberCode;
UserId = commonHeader.UserId;
Issue = commonHeader.Issue;
ServiceName = commonHeader.Service.ToFullName();
Id = commonHeader.Id;
Unit = commonHeader.Unit;
Position = commonHeader.Position;
UserName = commonHeader.UserName;
Async = commonHeader.Async;
Authenticator = commonHeader.Authenticator;
Paid = commonHeader.Paid;
Encrypt = commonHeader.Encrypt;
EncryptCert = commonHeader.EncryptCert;
Encrypted = commonHeader.Encrypted;
EncryptedCert = commonHeader.EncryptedCert;

return this;
}
}
}
14 changes: 13 additions & 1 deletion src/XRoadLib/Headers/XRoadHeader40.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace XRoadLib.Headers
/// <summary>
/// Implements default X-Road message protocol version 4.0 SOAP header.
/// </summary>
public class XRoadHeader40 : IXRoadHeader, IXRoadHeader40
public class XRoadHeader40 : IXRoadHeader, IXRoadHeader<XRoadHeader40>, IXRoadHeader40
{
/// <summary>
/// Client identity.
Expand Down Expand Up @@ -360,5 +360,17 @@ void WriteHeaderValue(string elementName, object value, XName typeName)
WriteHeaderValue("issue", Issue, XmlTypeConstants.String);
WriteHeaderValue("protocolVersion", ProtocolVersion, XmlTypeConstants.String);
}

public XRoadHeader40 InitFrom(XRoadCommonHeader commonHeader)
{
Client = commonHeader.Client;
Service = commonHeader.Service;
UserId = commonHeader.UserId;
Issue = commonHeader.Issue;
ProtocolVersion = commonHeader.ProtocolVersion;
Id = commonHeader.Id;

return this;
}
}
}
28 changes: 28 additions & 0 deletions src/XRoadLib/IServiceManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Web.Services.Description;
using System.Xml;
using XRoadLib.Headers;
Expand Down Expand Up @@ -38,6 +39,16 @@ public interface IServiceManager
/// </summary>
string ProducerNamespace { get; }

/// <summary>
/// Header definition of the protocol.
/// </summary>
HeaderDefinition HeaderDefinition { get; }

/// <summary>
/// Protocol specification.
/// </summary>
ProtocolDefinition ProtocolDefinition { get; }

/// <summary>
/// Get serializer instance of schema definition runtime serialization.
/// </summary>
Expand All @@ -51,12 +62,29 @@ public interface IServiceManager
/// <returns>Initialized header instance.</returns>
IXRoadHeader CreateHeader();

/// <summary>
/// Converts common header description to specific header.
/// </summary>
/// <returns>Initialized header instance.</returns>
IXRoadHeader ConvertHeader(XRoadCommonHeader commonHeader);

/// <summary>
/// Generates service description based on current schema definition.
/// </summary>
/// <param name="operationFilter">Allows to filter out unwanted operations which should not appear in service description.</param>
/// <param name="version">Global DTO version of wanted service description.</param>
/// <returns>Service description instance of current schema definition.</returns>
ServiceDescription CreateServiceDescription(Func<OperationDefinition, bool> operationFilter = null, uint? version = null);

/// <summary>
/// Executes X-Road operation on endpoint specified by WebRequest parameter.
/// </summary>
/// <param name="webRequest">WebRequest used to transfer X-Road messages.</param>
/// <param name="body">Soap body part of outgoing serialized X-Road message.</param>
/// <param name="header">Soap header part of outgoing serialized X-Road message.</param>
/// <param name="options">Additional options to configure service call execution.</param>
/// <typeparam name="TResult">Expected result type of the operation.</typeparam>
/// <returns>Deserialized value of X-Road response message Soap body.</returns>
TResult Execute<TResult>(WebRequest webRequest, object body, XRoadCommonHeader header, ServiceExecutionOptions options = null);
}
}
3 changes: 3 additions & 0 deletions src/XRoadLib/Schema/ContentDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ protected ContentDefinition(ParticleDefinition particle)

public static ContentDefinition FromType(ParticleDefinition particle, ICustomAttributeProvider customAttributeProvider, Type runtimeType, string runtimeName)
{
if (customAttributeProvider == null)
return new EmptyContentDefinition(particle, runtimeName);

if (runtimeType.IsArray)
return new ArrayContentDefiniton(particle, customAttributeProvider, runtimeType, runtimeName);

Expand Down
9 changes: 9 additions & 0 deletions src/XRoadLib/Schema/EmptyContentDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace XRoadLib.Schema
{
public class EmptyContentDefinition : ContentDefinition
{
public EmptyContentDefinition(ParticleDefinition particle, string runtimeName)
: base(particle)
{}
}
}
3 changes: 1 addition & 2 deletions src/XRoadLib/Schema/RequestDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public RequestDefinition(OperationDefinition declaringOperationDefinition)
DeclaringOperationDefinition = declaringOperationDefinition;
ParameterInfo = methodParameters.SingleOrDefault();

if (ParameterInfo != null)
Content = ContentDefinition.FromType(this, ParameterInfo, ParameterInfo.ParameterType, "request");
Content = ContentDefinition.FromType(this, ParameterInfo, ParameterInfo?.ParameterType, "request");
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/XRoadLib/ServiceExecutionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class ServiceExecutionOptions
{
public string RequestNamespace { get; set; }
public IServiceMap ServiceMap { get; set; }
public string OperationName { get; set; }
public uint? Version { get; set; }
public EventHandler<XRoadRequestEventArgs> BeforeRequest;
public EventHandler<XRoadResponseEventArgs> BeforeDeserialize;
}
Expand Down
21 changes: 13 additions & 8 deletions src/XRoadLib/ServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace XRoadLib
/// Manages available services and provides their definitions and serialization details.
/// </summary>
public class ServiceManager<THeader> : IServiceManager
where THeader : class, IXRoadHeader, new()
where THeader : class, IXRoadHeader, IXRoadHeader<THeader>, new()
{
private readonly IDictionary<uint, ISerializer> serializers = new Dictionary<uint, ISerializer>();
private readonly SchemaDefinitionProvider schemaDefinitionProvider;
Expand All @@ -34,16 +34,16 @@ public class ServiceManager<THeader> : IServiceManager
/// <inheritdoc />
public string ProducerNamespace => ProtocolDefinition.ProducerNamespace;

/// <summary>
/// Header definition of the protocol.
/// </summary>
/// <inheritdoc />
public HeaderDefinition HeaderDefinition { get; }

/// <summary>
/// Protocol specification.
/// </summary>
/// <inheritdoc />
public ProtocolDefinition ProtocolDefinition { get; }

/// <inheritdoc />
public IXRoadHeader ConvertHeader(XRoadCommonHeader commonHeader) =>
new THeader().InitFrom(commonHeader);

/// <summary>
/// Initializes new X-Road service manager instance.
/// <param name="name">Identifies service manager instance.</param>
Expand All @@ -67,6 +67,10 @@ public ServiceManager(string name, ISchemaExporter schemaExporter)
SetContractAssembly();
}

/// <inheritdoc />
public virtual TResult Execute<TResult>(WebRequest webRequest, object body, XRoadCommonHeader commonHeader, ServiceExecutionOptions options = null) =>
Execute<TResult>(webRequest, body, new THeader().InitFrom(commonHeader), options);

/// <summary>
/// Executes X-Road operation on endpoint specified by WebRequest parameter.
/// </summary>
Expand All @@ -93,7 +97,8 @@ public virtual TResult Execute<TResult>(WebRequest webRequest, object body, THea

writer.WriteStartElement("Body", NamespaceConstants.SOAP_ENV);

operationServiceMap = options?.ServiceMap ?? requestMessage.GetSerializer().GetServiceMap(XName.Get(header.Service.ServiceCode, ProducerNamespace));
var operationName = XName.Get(options?.OperationName ?? header.Service.ServiceCode, ProducerNamespace);
operationServiceMap = options?.ServiceMap ?? GetSerializer(options?.Version ?? requestMessage.Version).GetServiceMap(operationName);
operationServiceMap.SerializeRequest(writer, body, requestMessage, options?.RequestNamespace);

writer.WriteEndElement();
Expand Down

0 comments on commit c078609

Please sign in to comment.