private bool ValidateTransaction(EndpointVersionType endpointVersion, NodeMethod transactionWebMethod, ComplexContent content, bool doValidateFlowOperation, string flowId, out string networkId) { networkId = null; string dbOperation; NodeMethod webMethod; bool isNetworkTransactionId = false; string transactionFlowId; TransactionStatus transactionStatus = TransactionManager.GetTransactionStatus(content.Transaction.Id, out transactionFlowId, out dbOperation, out webMethod); if (transactionStatus == null) { transactionStatus = TransactionManager.GetTransactionStatusByNetworkId(content.Transaction.Id, out transactionFlowId, out dbOperation, out webMethod); if (transactionStatus == null) { throw FaultProvider.GetFault(endpointVersion, ENExceptionCodeType.E_TransactionId, "Transaction \"{0}\" was not found", content.Transaction.Id); } isNetworkTransactionId = true; } if (transactionFlowId != flowId) { throw FaultProvider.GetFault(endpointVersion, ENExceptionCodeType.E_InvalidDataflow, "Flow operation \"{0}\" is not valid for transaction \"{1}\"", content.Flow.Operation, content.Transaction.Id); } if (doValidateFlowOperation && !string.Equals(dbOperation, content.Flow.Operation ?? string.Empty, StringComparison.InvariantCultureIgnoreCase)) { throw FaultProvider.GetFault(endpointVersion, ENExceptionCodeType.E_InvalidDataflow, "Flow operation \"{0}\" is not valid for transaction \"{1}\"", content.Flow.Operation, content.Transaction.Id); } if ((transactionWebMethod == NodeMethod.Submit) && (webMethod != NodeMethod.Submit)) { // Create new transaction and reference the input transaction id as the network id for // the new transcation networkId = content.Transaction.Id; } if (networkId != null) { content.Transaction.Id = string.Empty; return(true); } else { if (isNetworkTransactionId) { // Use the "real" db transcation id content.Transaction.Id = transactionStatus.Id; } return(false); } }
/// <summary> /// Makes EN Client /// </summary> /// <returns></returns> private INodeEndpointClient MakeClient(string targetEndpointUrl, EndpointVersionType type, AuthenticationCredentials credentials, string naasUserToken, string tempDirectoryPath, IWebProxy proxy) { INodeEndpointClient client = null; if ((credentials != null) && (naasUserToken != null)) { throw new ArgumentException("Must specify either credentials or naasUserToken, not both"); } if (string.IsNullOrEmpty(tempDirectoryPath)) { tempDirectoryPath = Path.GetTempPath(); } // TSM: This is a fix to allow clients to work with older versions of OpenNode2 that have not been // upgraded to the node version 2.1 spec yet. bool compatibilityMode = false; if (type == EndpointVersionType.EN20CompatibilityMode) { compatibilityMode = true; type = EndpointVersionType.EN20; } switch (type) { case EndpointVersionType.EN11: if (credentials != null) { client = new Client11(targetEndpointUrl, credentials, tempDirectoryPath, proxy); } else { client = new Client11(targetEndpointUrl, naasUserToken, tempDirectoryPath, proxy); } break; case EndpointVersionType.EN20: if (credentials != null) { client = new Client20(targetEndpointUrl, credentials, tempDirectoryPath, proxy, compatibilityMode); } else { client = new Client20(targetEndpointUrl, naasUserToken, tempDirectoryPath, proxy, compatibilityMode); } break; default: throw new ArgumentException("Invalid endpoint type"); } if (client != null) { // Set default timeout client.Timeout = DefaultTimeout; } return(client); }
public PartnerIdentity(string id, string name, string endpointUrl, EndpointVersionType version) { Id = id; _name = name; _url = endpointUrl; _version = version; }
public INodeEndpointClient Make(string targetEndpointUrl, EndpointVersionType type) { if (_defaultAuthenticationCredentials == null) { throw new InvalidOperationException("Please set DefaultAuthenticationCredentials before calling this method."); } // TODO: return(MakeClient(targetEndpointUrl, type, _defaultAuthenticationCredentials, null, null, null)); }
public INodeEndpointClient Make(string targetEndpointUrl, EndpointVersionType type, string username, string testPassword, string prodPassword) { ExceptionUtils.ThrowIfEmptyString(username); ExceptionUtils.ThrowIfEmptyString(testPassword); ExceptionUtils.ThrowIfEmptyString(prodPassword); INodeEndpointClient client = null; try { AuthenticationCredentials credentials = new AuthenticationCredentials(username, testPassword); client = Make(targetEndpointUrl, type, credentials); // First, check to ping the node to make sure it is up and running try { client.NodePing(); } catch (Exception pingEx) { throw new ArgumentException(string.Format("The node endpoint \"{0}\" cannot be contacted. NodePing returned the error: {1}", targetEndpointUrl, ExceptionUtils.GetDeepExceptionMessage(pingEx))); } client.Authenticate(); } catch (Exception) { DisposableBase.SafeDispose(ref client); } if (client == null) { try { AuthenticationCredentials credentials = new AuthenticationCredentials(username, prodPassword); client = Make(targetEndpointUrl, type, credentials); client.Authenticate(); } catch (Exception) { DisposableBase.SafeDispose(ref client); } } if (client == null) { throw new ArgumentException(string.Format("The NAAS user \"{0}\" failed to authenticate against the node endpoint \"{1}\". Please check that the NAAS user's username and password have been entered correctly.", username, targetEndpointUrl)); } return(client); }
/// <summary> /// Return all service names as a dictionary of key/value pairs. /// </summary> public IDictionary <string, string> GetAllPartnerNames() { Dictionary <string, string> partnerNames = new Dictionary <string, string>(); DoSimpleQueryWithRowCallbackDelegate( TABLE_NAME, null, null, null, "Id,Name,Version", delegate(IDataReader reader) { string name = reader.GetString(1); EndpointVersionType version = EnumUtils.ParseEnum <EndpointVersionType>(reader.GetString(2)); string displayName = string.Format("{0} ({1})", name, EnumUtils.ToDescription(version)); partnerNames.Add(reader.GetString(0), displayName); }); return(partnerNames); }
public INodeEndpointClient GetNodeEndpointClient(string targetEndpointUrl, EndpointVersionType type, string endpointUsername) { if (!string.IsNullOrEmpty(endpointUsername)) { string testPassword, prodPassword; if (!EndpointUserDao.GetEnpointUserPasswordsByUsername(endpointUsername, out testPassword, out prodPassword)) { throw new ArgumentException(string.Format("The node endpoint user \"{0}\" could not be found.", endpointUsername)); } INodeEndpointClient client = NodeEndpointClientFactory.Make(targetEndpointUrl, type, endpointUsername, testPassword, prodPassword); return(client); } else { return(NodeEndpointClientFactory.Make(targetEndpointUrl, type)); } }
public static Exception PingNode(string targetEndpointUrl, EndpointVersionType type) { try { using (INodeEndpointClient client = new NodeEndpointClientFactory().Make(targetEndpointUrl, type, new AuthenticationCredentials("test", "test"), null, null)) { client.Timeout = 8000; client.NodePing(); } return(null); } catch (Exception e) { return(e); } }
public SoapException GetFault(EndpointVersionType endpointVersion, Exception ex) { LOG.Error(ex.Message, ex); ENExceptionCodeType code = ENExceptionCodeType.E_Unknown; if (!string.IsNullOrEmpty(ex.HelpLink)) { try { code = (ENExceptionCodeType)Enum.Parse(typeof(ENExceptionCodeType), ex.HelpLink, true); } catch (Exception enumEx) { LOG.Error("Invalid eror code: " + ex.HelpLink, enumEx); } } return(GetFault(endpointVersion, code, CleanseExceptionMessage(ex))); }
protected NetworkNodeType GetServices(ServiceType returnServiceTypes) { LatLongRectangle nodeBox = _settingsProvider.NodeBoundingBox; EndpointVersionType endpointVersionType = _transactionManager.GetTransactionEndpointVersionType(_dataRequest.TransactionId); if (endpointVersionType == EndpointVersionType.Undefined) { endpointVersionType = EndpointVersionType.EN20; } Dictionary <ServiceType, NodeMethodTypeCode> publishServiceTypeMap = new Dictionary <ServiceType, NodeMethodTypeCode>(); if (EnumUtils.IsFlagSet(returnServiceTypes, ServiceType.Query)) { publishServiceTypeMap.Add(ServiceType.Query, NodeMethodTypeCode.Query); } if (EnumUtils.IsFlagSet(returnServiceTypes, ServiceType.Solicit)) { publishServiceTypeMap.Add(ServiceType.Solicit, NodeMethodTypeCode.Solicit); } if (EnumUtils.IsFlagSet(returnServiceTypes, ServiceType.Submit)) { publishServiceTypeMap.Add(ServiceType.Submit, NodeMethodTypeCode.Submit); } if (EnumUtils.IsFlagSet(returnServiceTypes, ServiceType.Execute)) { publishServiceTypeMap.Add(ServiceType.Execute, NodeMethodTypeCode.Execute); } if (publishServiceTypeMap.Count == 0) { throw new ArgumentException(string.Format("Invalid ServiceType specified: \"{0}\"", returnServiceTypes)); } NetworkNodeType networkNodeType = new NetworkNodeType(); networkNodeType.NodeServiceList = new ServiceDescriptionListTypeService[0]; networkNodeType.BoundingBoxDetails = new NodeBoundingBoxType(); networkNodeType.BoundingBoxDetails.BoundingCoordinateNorth = nodeBox.North; networkNodeType.BoundingBoxDetails.BoundingCoordinateEast = nodeBox.East; networkNodeType.BoundingBoxDetails.BoundingCoordinateSouth = nodeBox.South; networkNodeType.BoundingBoxDetails.BoundingCoordinateWest = nodeBox.West; if (endpointVersionType == EndpointVersionType.EN20) { networkNodeType.NodeAddress = _settingsProvider.Endpoint20Url; networkNodeType.NodeVersionIdentifier = NodeVersionCode.Item20; } else { networkNodeType.NodeAddress = _settingsProvider.Endpoint11Url; networkNodeType.NodeVersionIdentifier = NodeVersionCode.Item11; } networkNodeType.NodeContact = _settingsProvider.NodeAdminEmail; if (_settingsProvider.IsProductionNode) { networkNodeType.NodeDeploymentTypeCode = NodeStageCode.Production; } else { networkNodeType.NodeDeploymentTypeCode = NodeStageCode.Development; } networkNodeType.NodeIdentifier = _settingsProvider.NodeId + " - " + (_settingsProvider.IsProductionNode ? "Prod" : "Test"); networkNodeType.NodeName = networkNodeType.NodeIdentifier; networkNodeType.OrganizationIdentifier = _settingsProvider.NodeOrganizationName; networkNodeType.NodeStatus = NodeStatusCode.Operational; string username = _transactionManager.GetTransactionUsername(_dataRequest.TransactionId); AppendAuditLogEvent("Loading information for all data flows for user: {0}", username); IList <DataFlow> dataFlows = _flowManager.GetAllDataFlows(true, true); if (!CollectionUtils.IsNullOrEmpty(dataFlows)) { AppendAuditLogEvent("Loaded information for {0} data flows for user: {1}", dataFlows.Count.ToString(), username); DataServicePublishFlags validPublishFlags = (endpointVersionType == EndpointVersionType.EN20) ? DataServicePublishFlags.PublishToEndpointVersion20 : DataServicePublishFlags.PublishToEndpointVersion11; List <ServiceDescriptionListTypeService> services = null; foreach (DataFlow dataFlow in dataFlows) { if (!CollectionUtils.IsNullOrEmpty(dataFlow.Services)) { foreach (DataService dataService in dataFlow.Services) { if (EnumUtils.IsFlagSet(dataService.PublishFlags, validPublishFlags) && dataService.IsActive && (dataService.PluginInfo != null) && !string.IsNullOrEmpty(dataService.PluginInfo.ImplementingClassName)) { foreach (KeyValuePair <ServiceType, NodeMethodTypeCode> pair in publishServiceTypeMap) { if (EnumUtils.IsFlagSet(dataService.Type, pair.Key)) { ServiceDescriptionListTypeService nodeService = new ServiceDescriptionListTypeService(); nodeService.Dataflow = dataFlow.FlowName; nodeService.MethodName = pair.Value; nodeService.ServiceDescription = string.Format("{0} - {1} Service", dataFlow.FlowName, dataService.Name); nodeService.ServiceDocumentURL = dataFlow.InfoUrl; nodeService.ServiceIdentifier = dataService.Name; int publishParamCount = GetPublishParamCount(dataService.ServiceParameters); if (publishParamCount > 0) { nodeService.Parameter = new RequestParameterType[publishParamCount]; for (int i = 0, index = 0; i < dataService.ServiceParameters.Count; ++i) { TypedParameter typedParameter = dataService.ServiceParameters[i]; if (typedParameter.DoPublishParam) { RequestParameterType requestParameter = new RequestParameterType(); requestParameter.ParameterName = typedParameter.Name; requestParameter.ParameterSortIndex = index.ToString(); requestParameter.ParameterRequiredIndicator = typedParameter.IsRequired; nodeService.Parameter[index++] = requestParameter; } } } CollectionUtils.Add(nodeService, ref services); } } } } } } if (!CollectionUtils.IsNullOrEmpty(services)) { services.Sort(delegate(ServiceDescriptionListTypeService s1, ServiceDescriptionListTypeService s2) { int result = string.Compare(s1.Dataflow, s2.Dataflow); if (result != 0) { return(result); } result = string.Compare(s1.ServiceIdentifier, s2.ServiceIdentifier); if (result != 0) { return(result); } return(string.Compare(s1.MethodName.ToString(), s2.MethodName.ToString())); }); networkNodeType.NodeServiceList = services.ToArray(); } } return(networkNodeType); }
public static string GetNodeClientExceptionMessage(string endpointUrl, EndpointVersionType endpointVersion, string endpointMethod, SoapException e) { try { string message = e.Message; if ((e.Detail != null) && !string.IsNullOrEmpty(e.Detail.InnerXml)) { string innerXml = e.Detail.InnerXml; string errorCodeElemName, descriptionElemName; if (endpointVersion == EndpointVersionType.EN11) { errorCodeElemName = "<errorcode>"; descriptionElemName = "<description>"; } else { errorCodeElemName = "<errorCode>"; descriptionElemName = "<description>"; } string errorCode = null; int errorCodeIndex = innerXml.IndexOf(errorCodeElemName); if (errorCodeIndex > 0) { errorCodeIndex += errorCodeElemName.Length; int errorCodeEndIndex = innerXml.IndexOf(errorCodeElemName.Replace("<", "</"), errorCodeIndex); if (errorCodeEndIndex > 0) { errorCode = innerXml.Substring(errorCodeIndex, errorCodeEndIndex - errorCodeIndex); } } string description = null; int descriptionCodeIndex = innerXml.IndexOf(descriptionElemName); if (descriptionCodeIndex > 0) { descriptionCodeIndex += descriptionElemName.Length; int descriptionCodeEndIndex = innerXml.IndexOf(descriptionElemName.Replace("<", "</"), descriptionCodeIndex); if (descriptionCodeEndIndex > 0) { description = innerXml.Substring(descriptionCodeIndex, descriptionCodeEndIndex - descriptionCodeIndex); } } if ((errorCode != null) && (description != null)) { message = string.Format("Error Code: {0}, Description: {1}", errorCode, description); } else if (errorCode != null) { message = string.Format("Error Code: {0}", errorCode); } else if (description != null) { message = string.Format("Description: {0}", description); } } return(string.Format("An error occurred communicating with the \"{0}\" remote node at url \"{1}\" using method \"{2}\": {3}", EnumUtils.ToDescription(endpointVersion), endpointUrl, endpointMethod, message)); } catch (Exception) { return(e.Message); } }
public INodeEndpointClient GetNodeEndpointClientForEndpointUserId(string targetEndpointUrl, EndpointVersionType type, string endpointUserId, out string endpointUsername) { if (string.IsNullOrEmpty(endpointUserId)) { endpointUsername = NodeEndpointClientFactory.DefaultAuthenticationCredentials.UserName; return(GetNodeEndpointClient(targetEndpointUrl, type, null)); } else { UserAccount account = EndpointUserDao.GetById(endpointUserId); if (account == null) { throw new ArgumentException(string.Format("The node endpoint user with id \"{0}\" could not be found.", endpointUserId)); } endpointUsername = account.NaasAccount; return(GetNodeEndpointClient(targetEndpointUrl, type, endpointUsername)); } }
/// <summary> /// Create a new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node. /// The input credentials are authenticated against the client node before this method returns. /// </summary> /// <param name="targetEndpointUrl">The url for the Exchange node endpoint.</param> /// <param name="type">The version of the Exchange node endpoint.</param> /// <param name="credentials">The credentials used to authenticate with the Exchange node endpoint.</param> /// <param name="tempDirectoryPath">A local directory path used for creating temporary files during INodeEndpointClient method /// execution. This value can be null, in which case the dafault system temp directory will be used.</param> /// <param name="proxy">Proxy information for accessing the Exchange node endpoint. This value can be null if /// no proxy is required.</param> /// <returns>A new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node. Dispose() /// should be called on the returned instance when the caller is finished using the instance.</returns> public static INodeEndpointClient CreateClientAndAuthenticate(string targetEndpointUrl, EndpointVersionType type, AuthenticationCredentials credentials, string tempDirectoryPath, IWebProxy proxy) { INodeEndpointClient client = new NodeEndpointClientFactory().Make(targetEndpointUrl, type, credentials, tempDirectoryPath, proxy); try { client.Authenticate(); } catch (Exception) { DisposableBase.SafeDispose(client); throw; } return(client); }
public NodeClientException(string endpointUrl, EndpointVersionType endpointVersion, string endpointMethod, SoapException e) : base(GetNodeClientExceptionMessage(endpointUrl, endpointVersion, endpointMethod, e), e.Code, e.Actor, e.Role, e.Lang, e.Detail, e.SubCode, null) { }
/// <summary> /// Makes EN Client /// </summary> /// <param name="targetEndpointUrl"></param> /// <param name="type"></param> /// <param name="credentials"></param> /// <param name="path"></param> /// <returns></returns> public INodeEndpointClient Make(string targetEndpointUrl, EndpointVersionType type, AuthenticationCredentials credentials, string path, IWebProxy proxy) { return(MakeClient(targetEndpointUrl, type, credentials, null, path, proxy)); }
/// <summary> /// Create a new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node. /// The node is pinged after is it created to ensure it can be accessed. /// </summary> /// <param name="targetEndpointUrl">The url for the Exchange node endpoint.</param> /// <param name="type">The version of the Exchange node endpoint.</param> /// <param name="naasUserToken">A valid NAAS user token that will be used for validating this endpoint.</param> /// <param name="tempDirectoryPath">A local directory path used for creating temporary files during INodeEndpointClient method /// execution. This value can be null, in which case the dafault system temp directory will be used.</param> /// <param name="proxy">Proxy information for accessing the Exchange node endpoint. This value can be null if /// no proxy is required.</param> /// <returns>A new <see cref="INodeEndpointClient"/> instance for accessing and communicating with a specific Exchange node. Dispose() /// should be called on the returned instance when the caller is finished using the instance.</returns> public static INodeEndpointClient CreateClientAndPing(string targetEndpointUrl, EndpointVersionType type, string naasUserToken, string tempDirectoryPath, IWebProxy proxy) { INodeEndpointClient client = new NodeEndpointClientFactory().Make(targetEndpointUrl, type, naasUserToken, tempDirectoryPath, proxy); try { client.NodePing(); } catch (Exception) { DisposableBase.SafeDispose(client); throw; } return(client); }
/// <summary> /// Makes EN Client using the temp directory as the target path /// </summary> /// <param name="targetEndpointUrl"></param> /// <param name="type"></param> /// <param name="credentials"></param> /// <returns></returns> public INodeEndpointClient Make(string targetEndpointUrl, EndpointVersionType type, AuthenticationCredentials credentials) { return(MakeClient(targetEndpointUrl, type, credentials, null, null, null)); }
public NetworkPartnerSetting(PartnerIdentity partnerIdentity) { Name = partnerIdentity.Name; Url = partnerIdentity.Url; Version = partnerIdentity.Version; }
public ByIndexOrNameDictionary(EndpointVersionType endpointType) : this(endpointType == EndpointVersionType.EN20) { }
/// <summary> /// Makes EN Client /// </summary> /// <returns></returns> public INodeEndpointClient Make(string targetEndpointUrl, EndpointVersionType type, string naasUserToken, string path, IWebProxy proxy) { return(MakeClient(targetEndpointUrl, type, null, naasUserToken, path, proxy)); }
public SoapException GetFault(EndpointVersionType endpointVersion, ENExceptionCodeType code, string format, params object[] args) { return(GetFault(endpointVersion, code, string.Format(format, args))); }
public ByIndexOrNameStringDictionary(EndpointVersionType endpointType) : base(endpointType) { }
public SoapException GetFault(EndpointVersionType endpointVersion, ENExceptionCodeType code, string descr) { if (string.IsNullOrEmpty(descr)) { descr = _defaultErrorDescription; } string detailName, detailNamespaceUri, errorCodeName, faultName, namespaceUri; if (endpointVersion == EndpointVersionType.EN20) { detailName = "soap:Detail"; detailNamespaceUri = "http://www.w3.org/2003/05/soap-envelope"; errorCodeName = "errorCode"; faultName = "NodeFaultDetailType"; namespaceUri = "http://www.exchangenetwork.net/schema/node/2"; } else { detailName = SoapException.DetailElementName.Name; errorCodeName = "errorcode"; faultName = "faultdetail"; namespaceUri = detailNamespaceUri = string.Empty; } XmlDocument doc = new XmlDocument(); XmlNode node = doc.CreateNode( XmlNodeType.Element, detailName, detailNamespaceUri); System.Xml.XmlNode details = doc.CreateNode( XmlNodeType.Element, faultName, namespaceUri); System.Xml.XmlNode errorCode = doc.CreateNode( XmlNodeType.Element, errorCodeName, namespaceUri); errorCode.InnerText = code.ToString(); details.AppendChild(errorCode); System.Xml.XmlNode desc = doc.CreateNode( XmlNodeType.Element, "description", namespaceUri); desc.InnerText = descr; details.AppendChild(desc); // Append the two child elements to the detail node. node.AppendChild(details); string errorUri = null; if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Request != null) { errorUri = System.Web.HttpContext.Current.Request.RawUrl.ToString(); } //Throw the exception. SoapException soapException = new SoapException(descr, SoapException.ServerFaultCode, errorUri, node); soapException.HelpLink = code.ToString(); return(soapException); }
public void SetNetworkEndpointTransactionInfo(string transactionId, string networkId, EndpointVersionType networkEndpointVersion, string networkEndpointUrl, string networkFlowName, string networkFlowOperation, string endpointUsername) { TransactionDao.SetNetworkEndpointTransactionInfo(transactionId, networkId, networkEndpointVersion, networkEndpointUrl, networkFlowName, networkFlowOperation, endpointUsername); }
/// <summary> /// Makes EN Client using the temp directory as the target path /// </summary> /// <returns></returns> public INodeEndpointClient Make(string targetEndpointUrl, EndpointVersionType type, string naasUserToken) { return(MakeClient(targetEndpointUrl, type, null, naasUserToken, null, null)); }