2

I am getting the below error in the Sitecore Authroing logs. What is the issue or any configuration problem?

ERROR SitecoreConnectionManager.Error: Message=Invalid URI: The hostname could not be parsed.|Trace=   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at Sitecore.Commerce.Plugin.Management.SitecoreConnectionManager.ProcessRequest(CommerceContext commerceContext, String action, String method, ItemModel itemModel)
System.UriFormatException: Invalid URI: The hostname could not be parsed.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at Sitecore.Commerce.Plugin.Management.SitecoreConnectionManager.ProcessRequest(CommerceContext commerceContext, String action, String method, ItemModel itemModel)
  • do you have all the time ? is it your commerce running? – Vlad Iobagiu Oct 30 '18 at 7:32
  • I see from time to time this error when Sitecore is restarted and commerce engine cannot connect to CM . – Vlad Iobagiu Oct 30 '18 at 7:33
  • Yes. Always Commerce Engine running. Is this expected behaviour if Sitecore restarts? or Any additional configuration requires? – Hussain Oct 30 '18 at 8:23
8

It's not a normal behavior.

If you look at the error message, you can see that problem is related to:

System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)

It meant that when any block tries to send request to Sitecore via SitecoreConnectionManager, and SitecoreConnectionManager processes request via SitecoreConnectionManager.ProcessRequest and couldn't create Uri:

SitecoreConnectionPolicy policy = commerceContext.GetPolicy<SitecoreConnectionPolicy>();
Uri address = new Uri(string.Format("https://{0}", (object) policy.Host));

From the first look it must works correctly, but...not...

Why do you see this error?

Commerce Engine OOTB has AdventureWorks, Habitat, any your custom environment(s) and ... Global environment

Engine tries to send request and get any item from Sitecore, but commerceContext has Environment property which is set to GlobalEnvironment.

If you will open Global.json file you will see that SitecoreConnectionPolicy is missing for GlobalEnvironment and for sure policy.Host is equal null.

How to fix it?

You need to copy and paste configuration below to Global.json file to Policies list:

{
        "$type": "Sitecore.Commerce.Plugin.Management.SitecoreConnectionPolicy, Sitecore.Commerce.Plugin.Management",
        "Host": "{hostname.com}",
        "SitecoreDatabase": "master",
        "UserName": "admin",
        "Domain": "sitecore",
        "Password": "b",
        "ConnectionLeaseTimeout": 60000,
        "AuthRequestUrl": "sitecore/api/ssc/auth/login",
        "Protocol": "https"
}

You need to change Host, UserName, Password base on your configuration. Also you can find your existing configuration in PlugIn.Content.PolicySet-1.0.0.json file and copy it to Global.json file.

After that you need to Bootstrap engine and restart apppool or iis.

This fix I checked on Sitecore Commerce 9 Update-1.

In Sitecore Commerce 9 Update-2 was added additional check:

        SitecoreConnectionPolicy policy = commerceContext.GetPolicy<SitecoreConnectionPolicy>();
        if (string.IsNullOrEmpty(policy?.Host))
        {
          commerceContext.Logger.LogError(string.Format("SitecoreConnectionManager: SitecoreConnectionPolicy for {0} is missing the host configuration", (object) commerceContext.Environment.Name), Array.Empty<object>());
          return (HttpResponseMessage) null;
        }
        Uri address = new Uri(string.Format("https://{0}", (object) policy.Host));

Which is more informative

2

This is a normal behavior when your Sitecore is restarting.

Commerce engine tries to connect to Sitecore to get some data from Commerce Control Panel (items under: /sitecore/Commerce/Commerce Control Panel) and he can not read data.

The Commerce Control Panel is installed when you install Commerce Connect. The Commerce Control Panel enables you to configure commerce engines, your storefronts, and business tools (such as Customer and Order Manager, and Pricing and Promotion Manager) by editing content in Sitecore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.