Azure / logicapps

Azure Logic Apps labs, samples, and tools
MIT License
361 stars 301 forks source link

Getting CallBackUrl for container throws nullreference exception #129

Closed scleynen closed 4 years ago

scleynen commented 4 years ago

When i try to get the callbackUrl according this step in the wiki by doing this

POST /runtime/webhooks/flow/api/management/workflows/{workflowName}/triggers/{triggerName}/ listCallbackUrl?api-version=2019-10-01-edge-preview&code=

it results in a 500 error

Docker logs is showing this

fail: Host.Triggers.Workflows[22] Error message: subscriptionId='myedgeenvironment', correlationId='dc9f60f8-4c8b-40e7-a0c3-06e94c5f7ac6', principalOid='', principalPuid='(null)', tenantId='myedgeenvironment-tenantId', operationName='POST/RUNTIME/FLOW/MANAGEMENT/DEMOLOGICAPP/MANUAL/', message='Http request failed with unhandled exception of type 'NullReferenceException' and message: 'System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Azure.Workflows.Data.Engines.FlowUriTemplateEngine.GetRelativePathTriggerDirectApiUri(Uri endpoint, String apiVersion, String scaleUnit, String flowId, String flowName, String triggerName) at Microsoft.Azure.Workflows.Data.Definitions.CallbackUrlDefinition.GetTriggerCallbackUrlDefinition(Uri endpoint, String apiVersion, FlowAccessKey flowAccessKey, AccessKeyType keyType, Flow flow, String triggerName, String relativePath, FlowHttpMethod triggerHttpMethod, Nullable1 expirationTime, String flowSequenceId) at Microsoft.Azure.Workflows.Web.Common.RequestHandlers.FlowTriggerApiRequestHandler.GetCallbackUrl(FlowContext context, String flowVersion, String triggerName) at Microsoft.Azure.Workflows.Web.Controllers.EdgeFlowTriggerController.ListCallbackUrl(String flowName, String triggerName, CancellationToken cancellationToken) at Microsoft.Azure.Workflows.Web.FlowExtensionRouteInitializer.Invoke(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Azure.Workflows.Web.Handlers.FlowExtensionHttpRequestHandler.HandleRequest(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Azure.Workflows.Web.Handlers.FlowExtensionRequestCancellationHandler.HandleRequest(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Azure.Workflows.Web.Handlers.FlowExtensionAuthorizationHandler.HandleRequest(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Azure.Workflows.Web.Handlers.FlowExtensionErrorResponseHandler.HandleRequest(HttpRequestMessage request, CancellationToken cancellationToken)'.', exception='System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Azure.Workflows.Data.Engines.FlowUriTemplateEngine.GetRelativePathTriggerDirectApiUri(Uri endpoint, String apiVersion, String scaleUnit, String flowId, String flowName, String triggerName) at Microsoft.Azure.Workflows.Data.Definitions.CallbackUrlDefinition.GetTriggerCallbackUrlDefinition(Uri endpoint, String apiVersion, FlowAccessKey flowAccessKey, AccessKeyType keyType, Flow flow, String triggerName, String relativePath, FlowHttpMethod triggerHttpMethod, Nullable1 expirationTime, String flowSequenceId) at Microsoft.Azure.Workflows.Web.Common.RequestHandlers.FlowTriggerApiRequestHandler.GetCallbackUrl(FlowContext context, String flowVersion, String triggerName) at Microsoft.Azure.Workflows.Web.Controllers.EdgeFlowTriggerController.ListCallbackUrl(String flowName, String triggerName, CancellationToken cancellationToken) at Microsoft.Azure.Workflows.Web.FlowExtensionRouteInitializer.Invoke(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Azure.Workflows.Web.Handlers.FlowExtensionHttpRequestHandler.HandleRequest(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Azure.Workflows.Web.Handlers.FlowExtensionRequestCancellationHandler.HandleRequest(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Azure.Workflows.Web.Handlers.FlowExtensionAuthorizationHandler.HandleRequest(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Azure.Workflows.Web.Handlers.FlowExtensionErrorResponseHandler.HandleRequest(HttpRequestMessage request, CancellationToken cancellationToken)', organizationId='(null)', activityVector='IN.04', realPuid='', altSecId='', additionalProperties='(null)'.

tomkerkhove commented 4 years ago

Have same issue here - Any update on this @MattFarm ?

tomkerkhove commented 4 years ago

You can repro it by running:

docker run -d -p 8080:80 -e "AzureWebJobsStorage=storage-connection-string" tomkerkhove/logic-apps-anywhere

And doing POST:

http://localhost:8080/runtime/webhooks/flow/api/management/workflows/StatefulSample/triggers/manual/listCallbackUrl?api-version=2019-10-01-edge-preview&code=

tomkerkhove commented 4 years ago

Under active investigation: https://github.com/Azure/logicapps/issues/123#issuecomment-644209054

tomkerkhove commented 4 years ago

Any update on this? It's blocking us a bit to proceed on our end.

/cc @MattFarm

tomkerkhove commented 4 years ago

Bumping - Any progress @MattFarm @laveeshb? We'd like to continue with our testing but are fully blocked.

tomkerkhove commented 4 years ago

Bump @laveeshb @rohithah

laveeshb commented 4 years ago

@tomkerkhove our apologies this is taking time. We are actively investigating it and will post an update as soon as we have a solution.

tomkerkhove commented 4 years ago

No problem, thanks for letting us know!

tomkerkhove commented 4 years ago

Any update on this @laveeshb?

rohithah commented 4 years ago

Sorry for the delay in getting this resolved. The issue was that the function runtime needed the WEBSITE_HOSTNAME environment variable to be pointing to the host name of the container endpoint.

for example, running your container like below should fix this issue. (will have a tracking bug to surface the right error in this case)

docker run -e WEBSITE_HOSTNAME=localhost -p 8080:80 local/workflowcontainer1

tomkerkhove commented 4 years ago

That seems to get me a step further but when I follow this guide it returns this error:

{
  "error": {
    "code": "InvalidFlowExtensionRequestRoute",
    "message": "The flow extension request route '/runtime/webhooks/flow/api/management/workflows/StatefulSample/triggers/manual/listCallbackUrl' is invalid."
  }
}

After using this call:

curl --location --request GET 'http://localhost:8080/runtime/webhooks/flow/api/management/workflows/StatefulSample/triggers/manual/listCallbackUrl?api-version=2019-10-01-edge-preview&code=<code>'

Where StatefulSample is name of my Logic App and manual of my trigger.

Workflow:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Response": {
                "type": "Response",
                "kind": "http",
                "inputs": {
                    "statusCode": 202,
                    "body": "@outputs('Invoke_a_function_in_this_function_app')?['body']"
                },
                "runAfter": {
                    "Invoke_a_function_in_this_function_app": [
                        "Succeeded"
                    ]
                }
            },
            "Invoke_a_function_in_this_function_app": {
                "type": "InvokeFunction",
                "inputs": {
                    "functionName": "EnrichOrderFunction"
                },
                "runAfter": {}
            }
        },
        "triggers": {
            "manual": {
                "type": "Request",
                "kind": "Http",
                "inputs": {
                    "schema": {
                        "type": "object",
                        "properties": {
                            "order": {
                                "type": "object",
                                "properties": {
                                    "amount": {
                                        "type": "integer"
                                    },
                                    "productId": {
                                        "type": "integer"
                                    }
                                }
                            },
                            "merchant": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer"
                                    },
                                    "name": {
                                        "type": "string"
                                    }
                                }
                            },
                            "customer": {
                                "type": "object",
                                "properties": {
                                    "firstName": {
                                        "type": "string"
                                    },
                                    "lastName": {
                                        "type": "string"
                                    },
                                    "address": {
                                        "type": "object",
                                        "properties": {
                                            "street": {
                                                "type": "string"
                                            },
                                            "city": {
                                                "type": "string"
                                            },
                                            "country": {
                                                "type": "string"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {}
    },
    "kind": "Stateful"
}
rohithah commented 4 years ago

can you check the casings of the workflow and trigger name? The url is case sensitive when running in linux containers

tomkerkhove commented 4 years ago

It looks fine, the logs show this: image

tomkerkhove commented 4 years ago

Ok I've managed to figure it out!

When calling following URL (which requires a POST instead of GET?):

http://localhost:8080/runtime/webhooks/flow/api/management/workflows/StatefulSample/triggers/manual/listCallbackUrl?api-version=2019-10-01-edge-preview&code=<code>

The result gave me all the info to call it:

{
  "value": "https://localhost:443/api/StatefulSample/triggers/manual/invoke?api-version=2020-05-01-preview&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=<code>",
  "method": "POST",
  "basePath": "https://localhost/api/StatefulSample/triggers/manual/invoke",
  "queries": {
    "api-version": "2020-05-01-preview",
    "sp": "/triggers/manual/run",
    "sv": "1.0",
    "sig": "<sig>"
  }
}

Once that info was mapped to my container it was working, for example:

http://localhost:8080/api/StatefulSample/triggers/manual/invoke?api-version=2020-05-01-preview&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=<code>
tomkerkhove commented 4 years ago

I've misread the docs on this part, sorry!

tomkerkhove commented 4 years ago

@rohithah Can you please update the wiki to reflect this along with the ENV AZURE_FUNCTIONS_ENVIRONMENT Development for others to avoid this issue please?

Or let us help with PRs :) (#140)

John-Dawson commented 2 years ago

Thanks very much @rohithah et. al. that got me over a hump; documentation could be better and I've found this sooner. But I still get the 'myedgeenvironment' error, not sure if it matters? Follow-up question: I think I can now initiate my test logic app, but I can't find any way of tracking what going on in it, like you can do so well in the Azure Logic App runtime. The Docker logs tell you that the App was initiated, but nothing about happens inside it. Ideas?