diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 00000000..49a79976
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,46 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
+
+## Our Standards
+
+Examples of behavior that contributes to creating a positive environment include:
+
+* Using welcoming and inclusive language
+* Being respectful of differing viewpoints and experiences
+* Gracefully accepting constructive criticism
+* Focusing on what is best for the community
+* Showing empathy towards other community members
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery and unwelcome sexual attention or advances
+* Trolling, insulting/derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or electronic address, without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a professional setting
+
+## Our Responsibilities
+
+Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
+
+Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
+
+## Scope
+
+This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at tom@threemammals.co.uk. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
+
+Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
+
+[homepage]: http://contributor-covenant.org
+[version]: http://contributor-covenant.org/version/1/4/
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 00000000..e6f89046
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,9 @@
+We love to receive contributions from the community so please keep them coming :)
+
+Pull requests, issues and commentary welcome!
+
+Please complete the relavent template for issues and PRs. Sometimes it's worth getting in touch with us to discuss changes
+before doing any work incase this is something we are already doing or it might not make sense. We can also give
+advice on the easiest way to do things :)
+
+Finally we mark all existing issues as help wanted, small, medium and large effort. If you want to contriute for the first time I suggest looking at a help wanted & small effort issue :)
diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md
new file mode 100644
index 00000000..3f0d0f3a
--- /dev/null
+++ b/ISSUE_TEMPLATE.md
@@ -0,0 +1,17 @@
+## Expected Behavior / New Feature
+
+
+## Actual Behavior / Motivation for New Feautre
+
+
+## Steps to Reproduce the Problem
+
+ 1.
+ 1.
+ 1.
+
+## Specifications
+
+ - Version:
+ - Platform:
+ - Subsystem:
diff --git a/Ocelot.sln b/Ocelot.sln
index 6aa429fe..c9ac2782 100644
--- a/Ocelot.sln
+++ b/Ocelot.sln
@@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
build-and-run-tests.ps1 = build-and-run-tests.ps1
build.cake = build.cake
build.ps1 = build.ps1
+ codeanalysis.ruleset = codeanalysis.ruleset
GitVersion.yml = GitVersion.yml
global.json = global.json
LICENSE.md = LICENSE.md
diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 00000000..72a3b6fe
--- /dev/null
+++ b/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,7 @@
+Fixes / New Feature #
+
+## Proposed Changes
+
+ -
+ -
+ -
diff --git a/README.md b/README.md
index 7145dc38..6bbc77e0 100644
--- a/README.md
+++ b/README.md
@@ -1,15 +1,17 @@
-# Ocelot
+[
](http://threemammals.com/ocelot)
[](https://ci.appveyor.com/project/TomPallister/ocelot-fcfpb)
[](https://ci.appveyor.com/project/TomPallister/ocelot-fcfpb/history?branch=develop)
-
[](https://coveralls.io/github/TomPallister/Ocelot?branch=develop)
+# Ocelot
+
Ocelot is a .NET Api Gateway. This project is aimed at people using .NET running
a micro services / service orientated architecture
-that need a unified point of entry into their system.
+that need a unified point of entry into their system. However it will worth with anything that
+speaks HTTP and run on any platform that asp.net core supports.
In particular I want easy integration with
IdentityServer reference and bearer tokens.
@@ -26,11 +28,29 @@ Ocelot manipulates the HttpRequest object into a state specified by its configur
it reaches a request builder middleware where it creates a HttpRequestMessage object which is
used to make a request to a downstream service. The middleware that makes the request is
the last thing in the Ocelot pipeline. It does not call the next middleware.
-The response from the downstream service is stored in a per request scoped repository
-and retrieved as the requests goes back up the Ocelot pipeline. There is a piece of middleware
-that maps the HttpResponseMessage onto the HttpResponse object and that is returned to the client.
-That is basically it with a bunch of other features.
-
+The response from the downstream service is retrieved as the requests goes back up the Ocelot pipeline.
+There is a piece of middleware that maps the HttpResponseMessage onto the HttpResponse object and that
+is returned to the client. That is basically it with a bunch of other features!
+
+## Features
+
+A quick list of Ocelot's capabilities for more information see the [documentation](http://ocelot.readthedocs.io/en/latest/).
+
+* Routing
+* Request Aggregation
+* Service Discovery with Consul
+* Service Fabric
+* Authentication
+* Authorisation
+* Rate Limiting
+* Caching
+* Retry policies / QoS
+* Load Balancing
+* Logging / Tracing / Correlation
+* Headers / Query String / Claims Transformation
+* Custom Middleware / Delegating Handlers
+* Configuration / Administration REST API
+
## How to install
Ocelot is designed to work with ASP.NET core only and is currently
@@ -48,20 +68,22 @@ Please click [here](http://ocelot.readthedocs.io/en/latest/) for the Ocleot docu
## Coming up
-You can see what we are working on [here](https://github.com/TomPallister/Ocelot/projects/1)
+You can see what we are working on [here](https://github.com/ThreeMammals/Ocelot/issues).
## Contributing
-Pull requests, issues and commentary welcome! No special process just create a request and get in
-touch either via gitter or create an issue.
+We love to receive contributions from the community so please keep them coming :)
+Pull requests, issues and commentary welcome!
+
+Please complete the relavent template for issues and PRs. Sometimes it's worth getting in touch with us to discuss changes
+before doing any work incase this is something we are already doing or it might not make sense. We can also give
+advice on the easiest way to do things :)
+
+Finally we mark all existing issues as help wanted, small, medium and large effort. If you want to contriute for the first time I suggest looking at a help wanted & small effort issue :)
## Things that are currently annoying me
-+ The base OcelotMiddleware lets you access things that are going to be null
-and doesnt check the response is OK. I think the fact you can even call stuff
-that isnt available is annoying. Let alone it be null.
-
[ Get more details at **codescene.io**.](https://codescene.io/projects/697/jobs/latest-successful/results)
diff --git a/codeanalysis.ruleset b/codeanalysis.ruleset
new file mode 100644
index 00000000..ee66e99d
--- /dev/null
+++ b/codeanalysis.ruleset
@@ -0,0 +1,152 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/docs/features/servicediscovery.rst b/docs/features/servicediscovery.rst
index 28728db3..f8cadd2e 100644
--- a/docs/features/servicediscovery.rst
+++ b/docs/features/servicediscovery.rst
@@ -6,16 +6,18 @@ for the downstream service Ocelot is forwarding a request to. At the moment this
GlobalConfiguration section which means the same service discovery provider will be used for all ReRoutes
you specify a ServiceName for at ReRoute level.
-At the moment the only supported service discovery provider is Consul. The following is required in the
-GlobalConfiguration. The Provider is required and if you do not specify a host and port the Consul default
+Consul
+^^^^^^
+
+The following is required in the GlobalConfiguration. The Provider is required and if you do not specify a host and port the Consul default
will be used.
.. code-block:: json
"ServiceDiscoveryProvider": {
- "Host": "localhost",
- "Port": 9500
- }
+ "Host": "localhost",
+ "Port": 9500
+ }
In the future we can add a feature that allows ReRoute specfic configuration.
@@ -35,4 +37,4 @@ and LeastConnection algorithm you can use. If no load balancer is specified Ocel
"UseServiceDiscovery": true
}
-When this is set up Ocelot will lookup the downstream host and port from the service discover provider and load balance requests across any available services.
\ No newline at end of file
+When this is set up Ocelot will lookup the downstream host and port from the service discover provider and load balance requests across any available services.
diff --git a/docs/features/servicefabric.rst b/docs/features/servicefabric.rst
new file mode 100644
index 00000000..d3faa40f
--- /dev/null
+++ b/docs/features/servicefabric.rst
@@ -0,0 +1,43 @@
+Service Fabric
+==============
+
+If you have services deployed in Service Fabric you will normally use the naming service to access them.
+
+The following example shows how to set up a ReRoute that will work in Service Fabric. The most important thing is the ServiceName which is made up of the
+Service Fabric application name then the specific service name. We also need to set UseServiceDiscovery as true and set up the ServiceDiscoveryProvider in
+GlobalConfiguration. The example here shows a typical configuration. It assumes service fabric is running on localhost and that the naming service is on port 19081.
+
+The example below is taken from the samples folder so please check it if this doesnt make sense!
+
+.. code-block:: json
+
+ {
+ "ReRoutes": [
+ {
+ "DownstreamPathTemplate": "/api/values",
+ "UpstreamPathTemplate": "/EquipmentInterfaces",
+ "UpstreamHttpMethod": [
+ "Get"
+ ],
+ "DownstreamScheme": "http",
+ "ServiceName": "OcelotServiceApplication/OcelotApplicationService",
+ "UseServiceDiscovery" : true
+ }
+ ],
+ "GlobalConfiguration": {
+ "RequestIdKey": "OcRequestId",
+ "ServiceDiscoveryProvider": {
+ "Host": "localhost",
+ "Port": 19081,
+ "Type": "ServiceFabric"
+ }
+ }
+ }
+
+If you are using stateless / guest exe services ocelot will be able to proxy through the naming service without anything else. However
+if you are using statefull / actor services you must send the PartitionKind and PartitionKey query string values with the client
+request e.g.
+
+GET http://ocelot.com/EquipmentInterfaces?PartitionKind=xxx&PartitionKey=xxx
+
+There is no way for Ocelot to work these out for you.
diff --git a/docs/images/OcelotServiceFabric.jpg b/docs/images/OcelotServiceFabric.jpg
new file mode 100644
index 00000000..e4aaab7a
Binary files /dev/null and b/docs/images/OcelotServiceFabric.jpg differ
diff --git a/docs/index.rst b/docs/index.rst
index 258085ef..43a6c436 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -22,6 +22,7 @@ Thanks for taking a look at the Ocelot documentation. Please use the left hand n
features/routing
features/requestaggregation
features/servicediscovery
+ features/servicefabric
features/authentication
features/authorisation
features/administration
diff --git a/docs/introduction/bigpicture.rst b/docs/introduction/bigpicture.rst
index 95e62fdc..989c0f5c 100644
--- a/docs/introduction/bigpicture.rst
+++ b/docs/introduction/bigpicture.rst
@@ -36,3 +36,7 @@ Multiple Instances
With Consul
^^^^^^^^^^^
.. image:: ../images/OcelotMultipleInstancesConsul.jpg
+
+With Service Fabric
+^^^^^^^^^^^^^^^^^^^
+.. image:: ../images/OcelotServiceFabric.jpg
diff --git a/ocelot.postman_collection.json b/postman/ocelot.postman_collection.json
similarity index 96%
rename from ocelot.postman_collection.json
rename to postman/ocelot.postman_collection.json
index 2dc33d33..28bbeb0c 100644
--- a/ocelot.postman_collection.json
+++ b/postman/ocelot.postman_collection.json
@@ -1,314 +1,314 @@
-{
- "id": "4dbde9fe-89f5-be35-bb9f-d3b438e16375",
- "name": "Ocelot",
- "description": "",
- "order": [
- "a1c95935-ed18-d5dc-bcb8-a3db8ba1934f",
- "ea0ed57a-2cb9-8acc-47dd-006b8db2f1b2",
- "c4494401-3985-a5bf-71fb-6e4171384ac6",
- "09af8dda-a9cb-20d2-5ee3-0a3023773a1a",
- "e8825dc3-4137-99a7-0000-ef5786610dc3",
- "fddfc4fa-5114-69e3-4744-203ed71a526b",
- "c45d30d7-d9c4-fa05-8110-d6e769bb6ff9",
- "4684c2fa-f38c-c193-5f55-bf563a1978c6",
- "5f308240-79e3-cf74-7a6b-fe462f0d54f1",
- "178f16da-c61b-c881-1c33-9d64a56851a4",
- "26a08569-85f6-7f9a-726f-61be419c7a34"
- ],
- "folders": [],
- "timestamp": 0,
- "owner": "212120",
- "public": false,
- "requests": [
- {
- "folder": null,
- "id": "09af8dda-a9cb-20d2-5ee3-0a3023773a1a",
- "name": "GET http://localhost:5000/comments?postId=1",
- "dataMode": "params",
- "data": null,
- "rawModeData": null,
- "descriptionFormat": "html",
- "description": "",
- "headers": "",
- "method": "GET",
- "pathVariables": {},
- "url": "http://localhost:5000/comments?postId=1",
- "preRequestScript": null,
- "tests": null,
- "currentHelper": "normal",
- "helperAttributes": {},
- "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
- },
- {
- "id": "178f16da-c61b-c881-1c33-9d64a56851a4",
- "headers": "Authorization: Bearer {{AccessToken}}\n",
- "url": "http://localhost:5000/administration/configuration",
- "preRequestScript": null,
- "pathVariables": {},
- "method": "GET",
- "data": null,
- "dataMode": "params",
- "tests": null,
- "currentHelper": "normal",
- "helperAttributes": {},
- "time": 1508914722969,
- "name": "GET http://localhost:5000/admin/configuration",
- "description": "",
- "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
- },
- {
- "id": "26a08569-85f6-7f9a-726f-61be419c7a34",
- "headers": "",
- "url": "http://localhost:5000/administration/connect/token",
- "preRequestScript": null,
- "pathVariables": {},
- "method": "POST",
- "data": [
- {
- "key": "client_id",
- "value": "raft",
- "type": "text",
- "enabled": true
- },
- {
- "key": "client_secret",
- "value": "REALLYHARDPASSWORD",
- "type": "text",
- "enabled": true
- },
- {
- "key": "scope",
- "value": "admin raft ",
- "type": "text",
- "enabled": true
- },
- {
- "key": "username",
- "value": "admin",
- "type": "text",
- "enabled": false
- },
- {
- "key": "password",
- "value": "secret",
- "type": "text",
- "enabled": false
- },
- {
- "key": "grant_type",
- "value": "client_credentials",
- "type": "text",
- "enabled": true
- }
- ],
- "dataMode": "params",
- "tests": "var jsonData = JSON.parse(responseBody);\npostman.setGlobalVariable(\"AccessToken\", jsonData.access_token);\npostman.setGlobalVariable(\"RefreshToken\", jsonData.refresh_token);",
- "currentHelper": "normal",
- "helperAttributes": {},
- "time": 1513240031907,
- "name": "POST http://localhost:5000/admin/connect/token copy copy",
- "description": "",
- "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
- },
- {
- "folder": null,
- "id": "4684c2fa-f38c-c193-5f55-bf563a1978c6",
- "name": "DELETE http://localhost:5000/posts/1",
- "dataMode": "params",
- "data": null,
- "rawModeData": null,
- "descriptionFormat": "html",
- "description": "",
- "headers": "",
- "method": "DELETE",
- "pathVariables": {},
- "url": "http://localhost:5000/posts/1",
- "preRequestScript": null,
- "tests": null,
- "currentHelper": "normal",
- "helperAttributes": {},
- "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
- },
- {
- "id": "5f308240-79e3-cf74-7a6b-fe462f0d54f1",
- "headers": "Authorization: Bearer {{AccessToken}}\n",
- "url": "http://localhost:5000/administration/.well-known/openid-configuration",
- "preRequestScript": null,
- "pathVariables": {},
- "method": "GET",
- "data": null,
- "dataMode": "params",
- "tests": null,
- "currentHelper": "normal",
- "helperAttributes": "{}",
- "time": 1488038888813,
- "name": "GET http://localhost:5000/admin/.well-known/openid-configuration",
- "description": "",
- "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375",
- "folder": null,
- "rawModeData": null,
- "descriptionFormat": null,
- "queryParams": [],
- "headerData": [
- {
- "key": "Authorization",
- "value": "Bearer {{AccessToken}}",
- "description": "",
- "enabled": true
- }
- ],
- "pathVariableData": []
- },
- {
- "id": "a1c95935-ed18-d5dc-bcb8-a3db8ba1934f",
- "folder": null,
- "name": "GET http://localhost:5000/posts",
- "dataMode": "params",
- "data": [
- {
- "key": "client_id",
- "value": "admin",
- "type": "text",
- "enabled": true
- },
- {
- "key": "client_secret",
- "value": "secret",
- "type": "text",
- "enabled": true
- },
- {
- "key": "scope",
- "value": "admin",
- "type": "text",
- "enabled": true
- },
- {
- "key": "username",
- "value": "admin",
- "type": "text",
- "enabled": true
- },
- {
- "key": "password",
- "value": "admin",
- "type": "text",
- "enabled": true
- },
- {
- "key": "grant_type",
- "value": "password",
- "type": "text",
- "enabled": true
- }
- ],
- "rawModeData": null,
- "descriptionFormat": "html",
- "description": "",
- "headers": "",
- "method": "POST",
- "pathVariables": {},
- "url": "http://localhost:5000/admin/configuration",
- "preRequestScript": null,
- "tests": null,
- "currentHelper": "normal",
- "helperAttributes": "{}",
- "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
- },
- {
- "folder": null,
- "id": "c4494401-3985-a5bf-71fb-6e4171384ac6",
- "name": "GET http://localhost:5000/posts/1/comments",
- "dataMode": "params",
- "data": null,
- "rawModeData": null,
- "descriptionFormat": "html",
- "description": "",
- "headers": "",
- "method": "GET",
- "pathVariables": {},
- "url": "http://localhost:5000/posts/1/comments",
- "preRequestScript": null,
- "tests": null,
- "currentHelper": "normal",
- "helperAttributes": {},
- "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
- },
- {
- "folder": null,
- "id": "c45d30d7-d9c4-fa05-8110-d6e769bb6ff9",
- "name": "PATCH http://localhost:5000/posts/1",
- "dataMode": "raw",
- "data": [],
- "descriptionFormat": "html",
- "description": "",
- "headers": "",
- "method": "PATCH",
- "pathVariables": {},
- "url": "http://localhost:5000/posts/1",
- "preRequestScript": null,
- "tests": null,
- "currentHelper": "normal",
- "helperAttributes": {},
- "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375",
- "rawModeData": "{\n \"title\": \"gfdgsgsdgsdfgsdfgdfg\",\n}"
- },
- {
- "folder": null,
- "id": "e8825dc3-4137-99a7-0000-ef5786610dc3",
- "name": "POST http://localhost:5000/posts/1",
- "dataMode": "raw",
- "data": [],
- "descriptionFormat": "html",
- "description": "",
- "headers": "",
- "method": "POST",
- "pathVariables": {},
- "url": "http://localhost:5000/posts",
- "preRequestScript": null,
- "tests": null,
- "currentHelper": "normal",
- "helperAttributes": {},
- "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375",
- "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}"
- },
- {
- "folder": null,
- "id": "ea0ed57a-2cb9-8acc-47dd-006b8db2f1b2",
- "name": "GET http://localhost:5000/posts/1",
- "dataMode": "params",
- "data": null,
- "rawModeData": null,
- "descriptionFormat": "html",
- "description": "",
- "headers": "",
- "method": "GET",
- "pathVariables": {},
- "url": "http://localhost:5000/posts/1",
- "preRequestScript": null,
- "tests": null,
- "currentHelper": "normal",
- "helperAttributes": {},
- "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
- },
- {
- "folder": null,
- "id": "fddfc4fa-5114-69e3-4744-203ed71a526b",
- "name": "PUT http://localhost:5000/posts/1",
- "dataMode": "raw",
- "data": [],
- "descriptionFormat": "html",
- "description": "",
- "headers": "",
- "method": "PUT",
- "pathVariables": {},
- "url": "http://localhost:5000/posts/1",
- "preRequestScript": null,
- "tests": null,
- "currentHelper": "normal",
- "helperAttributes": {},
- "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375",
- "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}"
- }
- ]
+{
+ "id": "4dbde9fe-89f5-be35-bb9f-d3b438e16375",
+ "name": "Ocelot",
+ "description": "",
+ "order": [
+ "a1c95935-ed18-d5dc-bcb8-a3db8ba1934f",
+ "ea0ed57a-2cb9-8acc-47dd-006b8db2f1b2",
+ "c4494401-3985-a5bf-71fb-6e4171384ac6",
+ "09af8dda-a9cb-20d2-5ee3-0a3023773a1a",
+ "e8825dc3-4137-99a7-0000-ef5786610dc3",
+ "fddfc4fa-5114-69e3-4744-203ed71a526b",
+ "c45d30d7-d9c4-fa05-8110-d6e769bb6ff9",
+ "4684c2fa-f38c-c193-5f55-bf563a1978c6",
+ "5f308240-79e3-cf74-7a6b-fe462f0d54f1",
+ "178f16da-c61b-c881-1c33-9d64a56851a4",
+ "26a08569-85f6-7f9a-726f-61be419c7a34"
+ ],
+ "folders": [],
+ "timestamp": 0,
+ "owner": "212120",
+ "public": false,
+ "requests": [
+ {
+ "folder": null,
+ "id": "09af8dda-a9cb-20d2-5ee3-0a3023773a1a",
+ "name": "GET http://localhost:5000/comments?postId=1",
+ "dataMode": "params",
+ "data": null,
+ "rawModeData": null,
+ "descriptionFormat": "html",
+ "description": "",
+ "headers": "",
+ "method": "GET",
+ "pathVariables": {},
+ "url": "http://localhost:5000/comments?postId=1",
+ "preRequestScript": null,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
+ },
+ {
+ "id": "178f16da-c61b-c881-1c33-9d64a56851a4",
+ "headers": "Authorization: Bearer {{AccessToken}}\n",
+ "url": "http://localhost:5000/administration/configuration",
+ "preRequestScript": null,
+ "pathVariables": {},
+ "method": "GET",
+ "data": null,
+ "dataMode": "params",
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "time": 1508914722969,
+ "name": "GET http://localhost:5000/admin/configuration",
+ "description": "",
+ "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
+ },
+ {
+ "id": "26a08569-85f6-7f9a-726f-61be419c7a34",
+ "headers": "",
+ "url": "http://localhost:5000/administration/connect/token",
+ "preRequestScript": null,
+ "pathVariables": {},
+ "method": "POST",
+ "data": [
+ {
+ "key": "client_id",
+ "value": "raft",
+ "type": "text",
+ "enabled": true
+ },
+ {
+ "key": "client_secret",
+ "value": "REALLYHARDPASSWORD",
+ "type": "text",
+ "enabled": true
+ },
+ {
+ "key": "scope",
+ "value": "admin raft ",
+ "type": "text",
+ "enabled": true
+ },
+ {
+ "key": "username",
+ "value": "admin",
+ "type": "text",
+ "enabled": false
+ },
+ {
+ "key": "password",
+ "value": "secret",
+ "type": "text",
+ "enabled": false
+ },
+ {
+ "key": "grant_type",
+ "value": "client_credentials",
+ "type": "text",
+ "enabled": true
+ }
+ ],
+ "dataMode": "params",
+ "tests": "var jsonData = JSON.parse(responseBody);\npostman.setGlobalVariable(\"AccessToken\", jsonData.access_token);\npostman.setGlobalVariable(\"RefreshToken\", jsonData.refresh_token);",
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "time": 1513240031907,
+ "name": "POST http://localhost:5000/admin/connect/token copy copy",
+ "description": "",
+ "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
+ },
+ {
+ "folder": null,
+ "id": "4684c2fa-f38c-c193-5f55-bf563a1978c6",
+ "name": "DELETE http://localhost:5000/posts/1",
+ "dataMode": "params",
+ "data": null,
+ "rawModeData": null,
+ "descriptionFormat": "html",
+ "description": "",
+ "headers": "",
+ "method": "DELETE",
+ "pathVariables": {},
+ "url": "http://localhost:5000/posts/1",
+ "preRequestScript": null,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
+ },
+ {
+ "id": "5f308240-79e3-cf74-7a6b-fe462f0d54f1",
+ "headers": "Authorization: Bearer {{AccessToken}}\n",
+ "url": "http://localhost:5000/administration/.well-known/openid-configuration",
+ "preRequestScript": null,
+ "pathVariables": {},
+ "method": "GET",
+ "data": null,
+ "dataMode": "params",
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": "{}",
+ "time": 1488038888813,
+ "name": "GET http://localhost:5000/admin/.well-known/openid-configuration",
+ "description": "",
+ "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375",
+ "folder": null,
+ "rawModeData": null,
+ "descriptionFormat": null,
+ "queryParams": [],
+ "headerData": [
+ {
+ "key": "Authorization",
+ "value": "Bearer {{AccessToken}}",
+ "description": "",
+ "enabled": true
+ }
+ ],
+ "pathVariableData": []
+ },
+ {
+ "id": "a1c95935-ed18-d5dc-bcb8-a3db8ba1934f",
+ "folder": null,
+ "name": "GET http://localhost:5000/posts",
+ "dataMode": "params",
+ "data": [
+ {
+ "key": "client_id",
+ "value": "admin",
+ "type": "text",
+ "enabled": true
+ },
+ {
+ "key": "client_secret",
+ "value": "secret",
+ "type": "text",
+ "enabled": true
+ },
+ {
+ "key": "scope",
+ "value": "admin",
+ "type": "text",
+ "enabled": true
+ },
+ {
+ "key": "username",
+ "value": "admin",
+ "type": "text",
+ "enabled": true
+ },
+ {
+ "key": "password",
+ "value": "admin",
+ "type": "text",
+ "enabled": true
+ },
+ {
+ "key": "grant_type",
+ "value": "password",
+ "type": "text",
+ "enabled": true
+ }
+ ],
+ "rawModeData": null,
+ "descriptionFormat": "html",
+ "description": "",
+ "headers": "",
+ "method": "POST",
+ "pathVariables": {},
+ "url": "http://localhost:5000/admin/configuration",
+ "preRequestScript": null,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": "{}",
+ "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
+ },
+ {
+ "folder": null,
+ "id": "c4494401-3985-a5bf-71fb-6e4171384ac6",
+ "name": "GET http://localhost:5000/posts/1/comments",
+ "dataMode": "params",
+ "data": null,
+ "rawModeData": null,
+ "descriptionFormat": "html",
+ "description": "",
+ "headers": "",
+ "method": "GET",
+ "pathVariables": {},
+ "url": "http://localhost:5000/posts/1/comments",
+ "preRequestScript": null,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
+ },
+ {
+ "folder": null,
+ "id": "c45d30d7-d9c4-fa05-8110-d6e769bb6ff9",
+ "name": "PATCH http://localhost:5000/posts/1",
+ "dataMode": "raw",
+ "data": [],
+ "descriptionFormat": "html",
+ "description": "",
+ "headers": "",
+ "method": "PATCH",
+ "pathVariables": {},
+ "url": "http://localhost:5000/posts/1",
+ "preRequestScript": null,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375",
+ "rawModeData": "{\n \"title\": \"gfdgsgsdgsdfgsdfgdfg\",\n}"
+ },
+ {
+ "folder": null,
+ "id": "e8825dc3-4137-99a7-0000-ef5786610dc3",
+ "name": "POST http://localhost:5000/posts/1",
+ "dataMode": "raw",
+ "data": [],
+ "descriptionFormat": "html",
+ "description": "",
+ "headers": "",
+ "method": "POST",
+ "pathVariables": {},
+ "url": "http://localhost:5000/posts",
+ "preRequestScript": null,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375",
+ "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}"
+ },
+ {
+ "folder": null,
+ "id": "ea0ed57a-2cb9-8acc-47dd-006b8db2f1b2",
+ "name": "GET http://localhost:5000/posts/1",
+ "dataMode": "params",
+ "data": null,
+ "rawModeData": null,
+ "descriptionFormat": "html",
+ "description": "",
+ "headers": "",
+ "method": "GET",
+ "pathVariables": {},
+ "url": "http://localhost:5000/posts/1",
+ "preRequestScript": null,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375"
+ },
+ {
+ "folder": null,
+ "id": "fddfc4fa-5114-69e3-4744-203ed71a526b",
+ "name": "PUT http://localhost:5000/posts/1",
+ "dataMode": "raw",
+ "data": [],
+ "descriptionFormat": "html",
+ "description": "",
+ "headers": "",
+ "method": "PUT",
+ "pathVariables": {},
+ "url": "http://localhost:5000/posts/1",
+ "preRequestScript": null,
+ "tests": null,
+ "currentHelper": "normal",
+ "helperAttributes": {},
+ "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375",
+ "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}"
+ }
+ ]
}
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/.gitignore b/samples/OcelotServiceFabric/.gitignore
new file mode 100644
index 00000000..733dbb07
--- /dev/null
+++ b/samples/OcelotServiceFabric/.gitignore
@@ -0,0 +1,269 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Service fabric
+OcelotApplicationApiGatewayPkg/Code
+OcelotApplication/OcelotApplicationApiGatewayPkg/Code/appsettings.json
+OcelotApplication/OcelotApplicationApiGatewayPkg/Code/configuration.json
+OcelotApplication/OcelotApplicationApiGatewayPkg/Code/runtimes/
+OcelotApplicationServicePkg/Code
+OcelotApplication/OcelotApplicationApiGatewayPkg/Code/web.config
+OcelotApplication/OcelotApplicationServicePkg/Code/runtimes/
+!entryPoint.cmd
+!entryPoint.sh
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+
+# Visual Studio 2015 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUNIT
+*.VisualState.xml
+TestResult.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# DNX
+project.lock.json
+artifacts/
+
+*_i.c
+*_p.c
+*_i.h
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# JustCode is a .NET coding add-in
+.JustCode
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# TODO: Comment the next line if you want to checkin your web deploy settings
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# The packages folder can be ignored because of Package Restore
+**/packages/*
+# except build/, which is used as an MSBuild target.
+!**/packages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/packages/repositories.config
+# NuGet v3's project.json files produces more ignoreable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.pfx
+*.publishsettings
+node_modules/
+orleans.codegen.cs
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+*.mdf
+*.ldf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# JetBrains Rider
+.idea/
+*.sln.iml
+
+# Dotnet generated files
+*.dll
+*.pdb
+*.deps.json
+*.runtimeconfig.json
diff --git a/samples/OcelotServiceFabric/CONTRIBUTING.md b/samples/OcelotServiceFabric/CONTRIBUTING.md
new file mode 100644
index 00000000..5577d2d7
--- /dev/null
+++ b/samples/OcelotServiceFabric/CONTRIBUTING.md
@@ -0,0 +1,11 @@
+# Contributing to Azure samples
+
+Thank you for your interest in contributing to Azure samples!
+
+## Ways to contribute
+
+You can contribute to [Azure samples](https://azure.microsoft.com/documentation/samples/) in a few different ways:
+
+- Submit feedback on [this sample page](https://azure.microsoft.com/documentation/samples/service-fabric-dotnet-web-reference-app/) whether it was helpful or not.
+- Submit issues through [issue tracker](https://github.com/Azure-Samples/service-fabric-dotnet-web-reference-app/issues) on GitHub. We are actively monitoring the issues and improving our samples.
+- If you wish to make code changes to samples, or contribute something new, please follow the [GitHub Forks / Pull requests model](https://help.github.com/articles/fork-a-repo/): Fork the sample repo, make the change and propose it back by submitting a pull request.
diff --git a/samples/OcelotServiceFabric/LICENSE.md b/samples/OcelotServiceFabric/LICENSE.md
new file mode 100644
index 00000000..70aed34a
--- /dev/null
+++ b/samples/OcelotServiceFabric/LICENSE.md
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2016 Azure Samples
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/samples/OcelotServiceFabric/OcelotApplication/ApplicationManifest.xml b/samples/OcelotServiceFabric/OcelotApplication/ApplicationManifest.xml
new file mode 100644
index 00000000..d002e811
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/ApplicationManifest.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Code/entryPoint.cmd b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Code/entryPoint.cmd
new file mode 100644
index 00000000..c93389bd
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Code/entryPoint.cmd
@@ -0,0 +1,2 @@
+dotnet %~dp0\OcelotApplicationApiGateway.dll
+exit /b %errorlevel%
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Code/entryPoint.sh b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Code/entryPoint.sh
new file mode 100644
index 00000000..9cc67287
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Code/entryPoint.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+check_errs()
+{
+ # Function. Parameter 1 is the return code
+ if [ "${1}" -ne "0" ]; then
+ # make our script exit with the right error code.
+ exit ${1}
+ fi
+}
+
+DIR=`dirname $0`
+
+echo 0x3f > /proc/self/coredump_filter
+
+source $DIR/dotnet-include.sh
+dotnet $DIR/OcelotApplicationApiGateway.dll $@
+check_errs $?
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Config/Settings.xml b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Config/Settings.xml
new file mode 100644
index 00000000..902c747a
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Config/Settings.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Config/_readme.txt b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Config/_readme.txt
new file mode 100644
index 00000000..f5e5e287
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Config/_readme.txt
@@ -0,0 +1,12 @@
+contains a Settings.xml file, that can specify parameters for the service
+
+Configuration packages describe user-defined, application-overridable configuration settings (sections of key-value pairs)
+required for running service replicas/instances of service types specified in the ser-vice manifest. The configuration settings
+must be stored in Settings.xml in the config package folder.
+
+The service developer uses Service Fabric APIs to locate the package folders and read applica-tion-overridable configuration settings.
+The service developer can also register callbacks that are in-voked when any of the configuration packages specified in the
+service manifest are upgraded and re-reads new configuration settings inside that callback.
+
+This means that Service Fabric will not recycle EXEs and DLLHOSTs specified in the host and support packages when
+configuration packages are up-graded.
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Data/_readme.txt b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Data/_readme.txt
new file mode 100644
index 00000000..de32b7d3
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/Data/_readme.txt
@@ -0,0 +1,5 @@
+Data packages contain data files like custom dictionaries,
+non-overridable configuration files, custom initialized data files, etc.
+
+Service Fabric will recycle all EXEs and DLLHOSTs specified in the host and support packages when any of the data packages
+specified inside service manifest are upgraded.
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/ServiceManifest-Linux.xml b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/ServiceManifest-Linux.xml
new file mode 100644
index 00000000..c1990112
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/ServiceManifest-Linux.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+ entryPoint.sh
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/ServiceManifest-Windows.xml b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/ServiceManifest-Windows.xml
new file mode 100644
index 00000000..a96730d3
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/ServiceManifest-Windows.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+ entryPoint.cmd
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/ServiceManifest.xml b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/ServiceManifest.xml
new file mode 100644
index 00000000..a96730d3
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationApiGatewayPkg/ServiceManifest.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+ entryPoint.cmd
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Code/entryPoint.cmd b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Code/entryPoint.cmd
new file mode 100644
index 00000000..9b71795b
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Code/entryPoint.cmd
@@ -0,0 +1,2 @@
+dotnet %~dp0\OcelotApplicationService.dll
+exit /b %errorlevel%
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Code/entryPoint.sh b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Code/entryPoint.sh
new file mode 100644
index 00000000..9e187faa
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Code/entryPoint.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+check_errs()
+{
+ # Function. Parameter 1 is the return code
+ if [ "${1}" -ne "0" ]; then
+ # make our script exit with the right error code.
+ exit ${1}
+ fi
+}
+
+DIR=`dirname $0`
+source $DIR/dotnet-include.sh
+
+dotnet $DIR/OcelotApplicationService.dll $@
+check_errs $?
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Config/Settings.xml b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Config/Settings.xml
new file mode 100644
index 00000000..902c747a
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Config/Settings.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Config/_readme.txt b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Config/_readme.txt
new file mode 100644
index 00000000..f5e5e287
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Config/_readme.txt
@@ -0,0 +1,12 @@
+contains a Settings.xml file, that can specify parameters for the service
+
+Configuration packages describe user-defined, application-overridable configuration settings (sections of key-value pairs)
+required for running service replicas/instances of service types specified in the ser-vice manifest. The configuration settings
+must be stored in Settings.xml in the config package folder.
+
+The service developer uses Service Fabric APIs to locate the package folders and read applica-tion-overridable configuration settings.
+The service developer can also register callbacks that are in-voked when any of the configuration packages specified in the
+service manifest are upgraded and re-reads new configuration settings inside that callback.
+
+This means that Service Fabric will not recycle EXEs and DLLHOSTs specified in the host and support packages when
+configuration packages are up-graded.
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Data/_readme.txt b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Data/_readme.txt
new file mode 100644
index 00000000..e51dae93
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/Data/_readme.txt
@@ -0,0 +1,5 @@
+Data packages contain data files like custom dictionaries,
+non-overridable configuration files, custom initialized data files, etc.
+
+Service Fabric will recycle all EXEs and DLLHOSTs specified in the host and support packages when any of the data packages
+specified inside service manifest are upgraded.
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/ServiceManifest-Linux.xml b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/ServiceManifest-Linux.xml
new file mode 100644
index 00000000..e94651cb
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/ServiceManifest-Linux.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+ entryPoint.sh
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/ServiceManifest-Windows.xml b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/ServiceManifest-Windows.xml
new file mode 100644
index 00000000..61c7ac80
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/ServiceManifest-Windows.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+ entryPoint.cmd
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/ServiceManifest.xml b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/ServiceManifest.xml
new file mode 100644
index 00000000..61c7ac80
--- /dev/null
+++ b/samples/OcelotServiceFabric/OcelotApplication/OcelotApplicationServicePkg/ServiceManifest.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+ entryPoint.cmd
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/OcelotServiceFabric/README.md b/samples/OcelotServiceFabric/README.md
new file mode 100644
index 00000000..a601e9f4
--- /dev/null
+++ b/samples/OcelotServiceFabric/README.md
@@ -0,0 +1,51 @@
+---
+services: service-fabric
+platforms: dotnet
+author: raunakpandya edited by Tom Pallister for Ocelot
+---
+
+# Ocelot Service Fabric example
+
+This shows a service fabric cluster with Ocelot exposed over HTTP accessing services in the cluster via the naming service. If you want to try and use Ocelot with
+Service Fabric I reccomend using this as a starting point.
+
+If you want to use statefull / actors you must send the PartitionKind and PartitionKey to Ocelot as query string parameters.
+
+I have not tested this sample on Service Fabric hosted on Linux just a Windows dev cluster. This sample assumes a good understanding of Service Fabric.
+
+The rest of this document is from the Microsoft asp.net core service fabric getting started guide.
+
+# Getting started with Service Fabric with .NET Core
+
+This repository contains a set of simple sample projects to help you getting started with Service Fabric on Linux with .NET Core as the framework. As a pre requisite ensure you have the Service Fabric C# SDK installed on ubuntu box. Follow these instruction to [prepare your development environment on Linux][service-fabric-Linux-getting-started]
+
+### Folder Hierarchy
+* src/ - Source of the application divided by different modules by sub-folders.
+* <application package folder>/ - Service Fabric Application folder heirarchy. After compilation the executables are placed in code subfolders.
+* build.sh - Script to build source on Linux shell.
+* build.ps1 - PowerShell script to build source on Windows.
+* install.sh - Script to install Application from Linux shell.
+* install.ps1 - PowerShell script to install application from Windows. Before calling this script run Connect-ServiceFabricCluster localhost:19000 or however you prefer to connect.
+* uninstall.sh - Script to uninstall application from Linux shell.
+* uninstall.ps1 - PowerShell script to unintall application from Windows.
+* dotnet-include.sh - Script to conditionally handle RHEL dotnet cli through scl(software collections)
+
+# Testing
+
+Once everything is up and running on your dev cluster visit http://localhost:31002/EquipmentInterfaces and you should see the following returned.
+
+```json
+["value1","value2"]
+```
+
+If you get any errors please check the service fabric logs and let me know if you need help.
+
+## More information
+
+The [Service Fabric documentation][service-fabric-docs] includes a rich set of tutorials and conceptual articles, which serve as a good complement to the samples.
+
+
+
+[service-fabric-programming-models]: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-choose-framework/
+[service-fabric-docs]: http://aka.ms/servicefabricdocs
+[service-fabric-Linux-getting-started]: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-get-started-linux/
diff --git a/samples/OcelotServiceFabric/build.bat b/samples/OcelotServiceFabric/build.bat
new file mode 100644
index 00000000..9905715a
--- /dev/null
+++ b/samples/OcelotServiceFabric/build.bat
@@ -0,0 +1,12 @@
+cd ./src/OcelotApplicationService/
+dotnet restore -s https://api.nuget.org/v3/index.json
+dotnet build
+dotnet publish -o ../../OcelotApplication/OcelotApplicationServicePkg/Code
+cd ../../
+
+cd ./src/OcelotApplicationApiGateway/
+dotnet restore -s https://api.nuget.org/v3/index.json
+dotnet build
+dotnet publish -o ../../OcelotApplication/OcelotApplicationApiGatewayPkg/Code
+cd ../../
+
diff --git a/samples/OcelotServiceFabric/build.sh b/samples/OcelotServiceFabric/build.sh
new file mode 100644
index 00000000..a18f2a4a
--- /dev/null
+++ b/samples/OcelotServiceFabric/build.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+DIR=`dirname $0`
+source $DIR/dotnet-include.sh
+
+cd $DIR/src/OcelotApplicationService/
+dotnet restore -s https://api.nuget.org/v3/index.json
+dotnet build
+dotnet publish -o ../../OcelotApplication/OcelotApplicationServicePkg/Code
+cd -
+
+cd $DIR/src/OcelotApplicationApiGateway/
+dotnet restore -s https://api.nuget.org/v3/index.json
+dotnet build
+dotnet publish -o ../../OcelotApplication/OcelotApplicationApiGatewayPkg/Code
+cd -
diff --git a/samples/OcelotServiceFabric/dotnet-include.sh b/samples/OcelotServiceFabric/dotnet-include.sh
new file mode 100644
index 00000000..a716f3d8
--- /dev/null
+++ b/samples/OcelotServiceFabric/dotnet-include.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+. /etc/os-release
+linuxDistrib=$ID
+if [ $linuxDistrib = "rhel" ]; then
+ source scl_source enable rh-dotnet20
+ exitCode=$?
+ if [ $exitCode != 0 ]; then
+ echo "Failed: source scl_source enable rh-dotnet20 : ExitCode: $exitCode"
+ exit $exitCode
+ fi
+fi
diff --git a/samples/OcelotServiceFabric/install.ps1 b/samples/OcelotServiceFabric/install.ps1
new file mode 100644
index 00000000..662c59e3
--- /dev/null
+++ b/samples/OcelotServiceFabric/install.ps1
@@ -0,0 +1,20 @@
+$AppPath = "$PSScriptRoot\OcelotApplication"
+$sdkInstallPath = (Get-ItemProperty 'HKLM:\Software\Microsoft\Service Fabric SDK').FabricSDKInstallPath
+$sfSdkPsModulePath = $sdkInstallPath + "Tools\PSModule\ServiceFabricSDK"
+Import-Module $sfSdkPsModulePath\ServiceFabricSDK.psm1
+
+$StatefulServiceManifestlocation = $AppPath + "\OcelotApplicationServicePkg\"
+$StatefulServiceManifestlocationLinux = $StatefulServiceManifestlocation + "\ServiceManifest-Linux.xml"
+$StatefulServiceManifestlocationWindows = $StatefulServiceManifestlocation + "\ServiceManifest-Windows.xml"
+$StatefulServiceManifestlocationFinal= $StatefulServiceManifestlocation + "ServiceManifest.xml"
+Copy-Item -Path $StatefulServiceManifestlocationWindows -Destination $StatefulServiceManifestlocationFinal -Force
+
+$WebServiceManifestlocation = $AppPath + "\OcelotApplicationApiGatewayPkg\"
+$WebServiceManifestlocationLinux = $WebServiceManifestlocation + "\ServiceManifest-Linux.xml"
+$WebServiceManifestlocationWindows = $WebServiceManifestlocation + "\ServiceManifest-Windows.xml"
+$WebServiceManifestlocationFinal= $WebServiceManifestlocation + "ServiceManifest.xml"
+Copy-Item -Path $WebServiceManifestlocationWindows -Destination $WebServiceManifestlocationFinal -Force
+
+Copy-ServiceFabricApplicationPackage -ApplicationPackagePath $AppPath -ApplicationPackagePathInImageStore OcelotServiceApplicationType -ImageStoreConnectionString (Get-ImageStoreConnectionStringFromClusterManifest(Get-ServiceFabricClusterManifest)) -TimeoutSec 1800
+Register-ServiceFabricApplicationType OcelotServiceApplicationType
+New-ServiceFabricApplication fabric:/OcelotServiceApplication OcelotServiceApplicationType 1.0.0
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/install.sh b/samples/OcelotServiceFabric/install.sh
new file mode 100644
index 00000000..e8245579
--- /dev/null
+++ b/samples/OcelotServiceFabric/install.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+appPkg="$DIR/OcelotServiceApplication"
+
+WebServiceManifestlocation="$appPkg/OcelotApplicationApiGatewayPkg"
+WebServiceManifestlocationLinux="$WebServiceManifestlocation/ServiceManifest-Linux.xml"
+WebServiceManifestlocationWindows="$WebServiceManifestlocation/ServiceManifest-Windows.xml"
+WebServiceManifestlocation="$WebServiceManifestlocation/ServiceManifest.xml"
+cp $WebServiceManifestlocationLinux $WebServiceManifestlocation
+
+
+StatefulServiceManifestlocation="$appPkg/OcelotApplicationServicePkg"
+StatefulServiceManifestlocationLinux="$StatefulServiceManifestlocation/ServiceManifest-Linux.xml"
+StatefulServiceManifestlocationWindows="$StatefulServiceManifestlocation/ServiceManifest-Windows.xml"
+StatefulServiceManifestlocation="$StatefulServiceManifestlocation/ServiceManifest.xml"
+cp $StatefulServiceManifestlocationLinux $StatefulServiceManifestlocation
+cp dotnet-include.sh ./OcelotServiceApplication/OcelotApplicationServicePkg/Code
+cp dotnet-include.sh ./OcelotServiceApplication/OcelotApplicationApiGatewayPkg/Code
+sfctl application upload --path OcelotServiceApplication --show-progress
+sfctl application provision --application-type-build-path OcelotServiceApplication
+sfctl application create --app-name fabric:/OcelotServiceApplication --app-type OcelotServiceApplicationType --app-version 1.0.0
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.cs b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.cs
new file mode 100644
index 00000000..28ea7abb
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.cs
@@ -0,0 +1,31 @@
+// ------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
+// ------------------------------------------------------------
+
+namespace OcelotApplicationApiGateway
+{
+ using System.Fabric;
+ using Microsoft.ServiceFabric.Services.Communication.Runtime;
+ using Microsoft.ServiceFabric.Services.Runtime;
+ using System.Collections.Generic;
+
+ /// Service that handles front-end web requests and acts as a proxy to the back-end data for the UI web page.
+ /// It is a stateless service that hosts a Web API application on OWIN.
+ internal sealed class OcelotServiceWebService : StatelessService
+ {
+ public OcelotServiceWebService(StatelessServiceContext context)
+ : base(context)
+ { }
+
+ protected override IEnumerable CreateServiceInstanceListeners()
+ {
+ return new[]
+ {
+ new ServiceInstanceListener(
+ initparams => new WebCommunicationListener(string.Empty, initparams),
+ "OcelotServiceWebListener")
+ };
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.csproj b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.csproj
new file mode 100644
index 00000000..1ff69c09
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.csproj
@@ -0,0 +1,22 @@
+
+
+ Stateless Web Service for Stateful OcelotApplicationApiGateway App
+
+ netcoreapp2.0
+ OcelotApplicationApiGateway
+ Exe
+ OcelotApplicationApiGateway
+
+
+
+ PreserveNewest
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/Program.cs b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/Program.cs
new file mode 100644
index 00000000..7da30a50
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/Program.cs
@@ -0,0 +1,51 @@
+// ------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
+// ------------------------------------------------------------
+
+namespace OcelotApplicationApiGateway
+
+{
+ using System;
+ using System.Fabric;
+ using System.Threading;
+ using Microsoft.ServiceFabric.Services.Runtime;
+ using System.Diagnostics.Tracing;
+
+
+ ///
+ /// The service host is the executable that hosts the Service instances.
+ ///
+ public class Program
+ {
+ public static void Main(string[] args)
+ {
+ // Create Service Fabric runtime and register the service type.
+ try
+ {
+
+ //Creating a new event listener to redirect the traces to a file
+ ServiceEventListener listener = new ServiceEventListener("OcelotApplicationApiGateway");
+ listener.EnableEvents(ServiceEventSource.Current, EventLevel.LogAlways, EventKeywords.All);
+
+ // The ServiceManifest.XML file defines one or more service type names.
+ // Registering a service maps a service type name to a .NET type.
+ // When Service Fabric creates an instance of this service type,
+ // an instance of the class is created in this host process.
+ ServiceRuntime
+ .RegisterServiceAsync("OcelotApplicationApiGatewayType", context => new OcelotServiceWebService (context))
+ .GetAwaiter()
+ .GetResult();
+
+
+ // Prevents this host process from terminating so services keep running.
+ Thread.Sleep(Timeout.Infinite);
+ }
+ catch (Exception ex)
+ {
+ ServiceEventSource.Current.ServiceHostInitializationFailed(ex);
+ throw ex;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/Properties/launchSettings.json b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/Properties/launchSettings.json
new file mode 100644
index 00000000..e28c3315
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/Properties/launchSettings.json
@@ -0,0 +1,27 @@
+{
+ "iisSettings": {
+ "windowsAuthentication": false,
+ "anonymousAuthentication": true,
+ "iisExpress": {
+ "applicationUrl": "http://localhost:36034/",
+ "sslPort": 0
+ }
+ },
+ "profiles": {
+ "IIS Express": {
+ "commandName": "IISExpress",
+ "launchBrowser": true,
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ },
+ "OcelotApplicationApiGateway": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ },
+ "applicationUrl": "http://localhost:36035/"
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventListener.cs b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventListener.cs
new file mode 100644
index 00000000..555f9fde
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventListener.cs
@@ -0,0 +1,94 @@
+// ------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
+// ------------------------------------------------------------
+
+namespace OcelotApplicationApiGateway
+{
+ using System;
+ using System.IO;
+ using System.Linq;
+ using System.Diagnostics.Tracing;
+ using System.Fabric;
+ using System.Fabric.Common;
+ using System.Fabric.Common.Tracing;
+ using Microsoft.ServiceFabric.Services.Runtime;
+ using System.Globalization;
+ using System.Text;
+
+ ///
+ /// ServiceEventListener is a class which listens to the eventsources registered and redirects the traces to a file
+ /// Note that this class serves as a template to EventListener class and redirects the logs to /tmp/{appnameyyyyMMddHHmmssffff}.
+ /// You can extend the functionality by writing your code to implement rolling logs for the logs written through this class.
+ /// You can also write your custom listener class and handle the registered evestsources accordingly.
+ ///
+ internal class ServiceEventListener : EventListener
+ {
+ private string fileName;
+ private string filepath = Path.GetTempPath();
+
+ public ServiceEventListener(string appName)
+ {
+ this.fileName = appName + DateTime.Now.ToString("yyyyMMddHHmmssffff");
+ }
+
+ ///
+ /// We override this method to get a callback on every event we subscribed to with EnableEvents
+ ///
+ /// The event arguments that describe the event.
+ protected override void OnEventWritten(EventWrittenEventArgs eventData)
+ {
+ using (StreamWriter writer = new StreamWriter( new FileStream(filepath + fileName, FileMode.Append)))
+ {
+ // report all event information
+ writer.Write(" {0} ", Write(eventData.Task.ToString(),
+ eventData.EventName,
+ eventData.EventId.ToString(),
+ eventData.Level));
+
+ if (eventData.Message != null)
+ {
+ writer.WriteLine(string.Format(CultureInfo.InvariantCulture, eventData.Message, eventData.Payload.ToArray()));
+ }
+ }
+ }
+
+ private static String Write(string taskName, string eventName, string id, EventLevel level)
+ {
+ StringBuilder output = new StringBuilder();
+
+ DateTime now = DateTime.UtcNow;
+ output.Append(now.ToString("yyyy/MM/dd-HH:mm:ss.fff", CultureInfo.InvariantCulture));
+ output.Append(',');
+ output.Append(ConvertLevelToString(level));
+ output.Append(',');
+ output.Append(taskName);
+
+ if (!string.IsNullOrEmpty(eventName))
+ {
+ output.Append('.');
+ output.Append(eventName);
+ }
+
+ if (!string.IsNullOrEmpty(id))
+ {
+ output.Append('@');
+ output.Append(id);
+ }
+
+ output.Append(',');
+ return output.ToString();
+ }
+
+ private static string ConvertLevelToString(EventLevel level)
+ {
+ switch (level)
+ {
+ case EventLevel.Informational:
+ return "Info";
+ default:
+ return level.ToString();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventSource.cs b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventSource.cs
new file mode 100644
index 00000000..c0579955
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventSource.cs
@@ -0,0 +1,86 @@
+// ------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
+// ------------------------------------------------------------
+
+namespace OcelotApplicationApiGateway
+{
+ using System;
+ using System.Diagnostics.Tracing;
+ using System.Fabric;
+ using Microsoft.ServiceFabric.Services.Runtime;
+
+ ///
+ /// Implements methods for logging service related events.
+ ///
+ public class ServiceEventSource : EventSource
+ {
+ public static ServiceEventSource Current = new ServiceEventSource();
+
+ // Define an instance method for each event you want to record and apply an [Event] attribute to it.
+ // The method name is the name of the event.
+ // Pass any parameters you want to record with the event (only primitive integer types, DateTime, Guid & string are allowed).
+ // Each event method implementation should check whether the event source is enabled, and if it is, call WriteEvent() method to raise the event.
+ // The number and types of arguments passed to every event method must exactly match what is passed to WriteEvent().
+ // Put [NonEvent] attribute on all methods that do not define an event.
+ // For more information see https://msdn.microsoft.com/en-us/library/system.diagnostics.tracing.eventsource.aspx
+
+ [NonEvent]
+ public void Message(string message, params object[] args)
+ {
+ if (this.IsEnabled())
+ {
+ var finalMessage = string.Format(message, args);
+ this.Message(finalMessage);
+ }
+ }
+
+ private const int MessageEventId = 1;
+
+ [Event(MessageEventId, Level = EventLevel.Informational, Message = "{0}")]
+ public void Message(string message)
+ {
+ if (this.IsEnabled())
+ {
+ this.WriteEvent(MessageEventId, message);
+ }
+ }
+
+ private const int ServiceTypeRegisteredEventId = 3;
+
+ [Event(ServiceTypeRegisteredEventId, Level = EventLevel.Informational, Message = "Service host process {0} registered service type {1}")]
+ public void ServiceTypeRegistered(int hostProcessId, string serviceType)
+ {
+ this.WriteEvent(ServiceTypeRegisteredEventId, hostProcessId, serviceType);
+ }
+
+ [NonEvent]
+ public void ServiceHostInitializationFailed(Exception e)
+ {
+ this.ServiceHostInitializationFailed(e.ToString());
+ }
+
+ private const int ServiceHostInitializationFailedEventId = 4;
+
+ [Event(ServiceHostInitializationFailedEventId, Level = EventLevel.Error, Message = "Service host initialization failed: {0}")]
+ private void ServiceHostInitializationFailed(string exception)
+ {
+ this.WriteEvent(ServiceHostInitializationFailedEventId, exception);
+ }
+
+ [NonEvent]
+ public void ServiceWebHostBuilderFailed(Exception e)
+ {
+ this.ServiceWebHostBuilderFailed(e.ToString());
+ }
+
+ private const int ServiceWebHostBuilderFailedEventId = 5;
+
+ [Event(ServiceWebHostBuilderFailedEventId, Level = EventLevel.Error, Message = "Service Owin Web Host Builder Failed: {0}")]
+ private void ServiceWebHostBuilderFailed(string exception)
+ {
+ this.WriteEvent(ServiceWebHostBuilderFailedEventId, exception);
+ }
+
+ }
+}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/WebCommunicationListener.cs b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/WebCommunicationListener.cs
new file mode 100644
index 00000000..6685e11f
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/WebCommunicationListener.cs
@@ -0,0 +1,125 @@
+// ------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
+// ------------------------------------------------------------
+
+namespace OcelotApplicationApiGateway
+{
+ using System;
+ using System.Fabric;
+ using System.Fabric.Description;
+ using System.Globalization;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using Microsoft.AspNetCore.Hosting;
+ using Microsoft.ServiceFabric.Services.Communication.Runtime;
+ using Microsoft.Extensions.Logging;
+ using Microsoft.Extensions.Configuration;
+ using Microsoft.AspNetCore.Builder;
+ using Microsoft.Extensions.DependencyInjection;
+ using Ocelot.DependencyInjection;
+ using Ocelot.Middleware;
+
+ public class WebCommunicationListener : ICommunicationListener
+ {
+ private readonly string appRoot;
+ private readonly ServiceContext serviceInitializationParameters;
+ private string listeningAddress;
+ private string publishAddress;
+
+ // OWIN server handle.
+ private IWebHost webHost;
+
+ public WebCommunicationListener(string appRoot, ServiceContext serviceInitializationParameters)
+ {
+ this.appRoot = appRoot;
+ this.serviceInitializationParameters = serviceInitializationParameters;
+ }
+
+ public Task OpenAsync(CancellationToken cancellationToken)
+ {
+ ServiceEventSource.Current.Message("Initialize");
+
+ EndpointResourceDescription serviceEndpoint = this.serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("WebEndpoint");
+ int port = serviceEndpoint.Port;
+
+ this.listeningAddress = string.Format(
+ CultureInfo.InvariantCulture,
+ "http://+:{0}/{1}",
+ port,
+ string.IsNullOrWhiteSpace(this.appRoot)
+ ? string.Empty
+ : this.appRoot.TrimEnd('/') + '/');
+
+ this.publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN);
+
+ ServiceEventSource.Current.Message("Starting web server on {0}", this.listeningAddress);
+
+ try
+ {
+ this.webHost = new WebHostBuilder()
+ .UseKestrel()
+ //.UseStartup()
+ .UseUrls(this.listeningAddress)
+ .ConfigureAppConfiguration((hostingContext, config) =>
+ {
+ config
+ .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
+ .AddJsonFile("appsettings.json", true, true)
+ .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
+ .AddJsonFile("configuration.json")
+ .AddEnvironmentVariables();
+ })
+ .ConfigureLogging((hostingContext, logging) =>
+ {
+ logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
+ logging.AddConsole();
+ })
+ .ConfigureServices(s => {
+ s.AddOcelot();
+ })
+ .Configure(a => {
+ a.UseOcelot().Wait();
+ })
+ .Build();
+
+ this.webHost.Start();
+ }
+ catch (Exception ex)
+ {
+ ServiceEventSource.Current.ServiceWebHostBuilderFailed(ex);
+ }
+
+ return Task.FromResult(this.publishAddress);
+ }
+
+ public Task CloseAsync(CancellationToken cancellationToken)
+ {
+ this.StopAll();
+ return Task.FromResult(true);
+ }
+
+ public void Abort()
+ {
+ this.StopAll();
+ }
+
+ ///
+ /// Stops, cancels, and disposes everything.
+ ///
+ private void StopAll()
+ {
+ try
+ {
+ if (this.webHost != null)
+ {
+ ServiceEventSource.Current.Message("Stopping web server.");
+ this.webHost.Dispose();
+ }
+ }
+ catch (ObjectDisposedException)
+ {
+ }
+ }
+ }
+}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/appsettings.json b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/appsettings.json
new file mode 100644
index 00000000..51d92491
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/appsettings.json
@@ -0,0 +1,10 @@
+{
+ "Logging": {
+ "IncludeScopes": false,
+ "LogLevel": {
+ "Default": "Trace",
+ "System": "Information",
+ "Microsoft": "Information"
+ }
+ }
+}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/configuration.json b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/configuration.json
new file mode 100644
index 00000000..dce3d55e
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/configuration.json
@@ -0,0 +1,22 @@
+{
+ "ReRoutes": [
+ {
+ "DownstreamPathTemplate": "/api/values",
+ "UpstreamPathTemplate": "/EquipmentInterfaces",
+ "UpstreamHttpMethod": [
+ "Get"
+ ],
+ "DownstreamScheme": "http",
+ "ServiceName": "OcelotServiceApplication/OcelotApplicationService",
+ "UseServiceDiscovery" : true
+ }
+ ],
+ "GlobalConfiguration": {
+ "RequestIdKey": "OcRequestId",
+ "ServiceDiscoveryProvider": {
+ "Host": "localhost",
+ "Port": 19081,
+ "Type": "ServiceFabric"
+ }
+ }
+}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/ApiGateway.cs b/samples/OcelotServiceFabric/src/OcelotApplicationService/ApiGateway.cs
new file mode 100644
index 00000000..8c090885
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/ApiGateway.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Fabric;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.ServiceFabric.Services.Communication.AspNetCore;
+using Microsoft.ServiceFabric.Services.Communication.Runtime;
+using Microsoft.ServiceFabric.Services.Runtime;
+using Microsoft.Extensions.Logging;
+
+namespace OcelotApplicationService
+{
+ ///
+ /// The FabricRuntime creates an instance of this class for each service type instance.
+ ///
+ internal sealed class ApiGateway : StatelessService
+ {
+ public ApiGateway(StatelessServiceContext context)
+ : base(context)
+ { }
+
+ ///
+ /// Optional override to create listeners (like tcp, http) for this service instance.
+ ///
+ /// The collection of listeners.
+ protected override IEnumerable CreateServiceInstanceListeners()
+ {
+ return new ServiceInstanceListener[]
+ {
+ new ServiceInstanceListener(serviceContext =>
+ new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
+ {
+ Console.WriteLine($"Starting Kestrel on {url}");
+ ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");
+
+ return new WebHostBuilder()
+ .UseKestrel()
+ .ConfigureServices(
+ services => services
+ .AddSingleton(serviceContext))
+ .UseContentRoot(Directory.GetCurrentDirectory())
+ .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
+ .UseStartup()
+ .UseUrls(url)
+ .ConfigureLogging((hostingContext, logging) =>
+ {
+ logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
+ logging.AddConsole();
+ })
+ .Build();
+ }))
+ };
+ }
+ }
+}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/Controllers/ValuesController.cs b/samples/OcelotServiceFabric/src/OcelotApplicationService/Controllers/ValuesController.cs
new file mode 100644
index 00000000..13e56999
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/Controllers/ValuesController.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Mvc;
+
+namespace OcelotApplicationService.Controllers
+{
+ [Route("api/[controller]")]
+ public class ValuesController : Controller
+ {
+ // GET api/values
+ [HttpGet]
+ public IEnumerable Get()
+ {
+ return new string[] { "value1", "value2" };
+ }
+
+ // GET api/values/5
+ [HttpGet("{id}")]
+ public string Get(int id)
+ {
+ return "value";
+ }
+
+ // POST api/values
+ [HttpPost]
+ public void Post([FromBody]string value)
+ {
+ }
+
+ // PUT api/values/5
+ [HttpPut("{id}")]
+ public void Put(int id, [FromBody]string value)
+ {
+ }
+
+ // DELETE api/values/5
+ [HttpDelete("{id}")]
+ public void Delete(int id)
+ {
+ }
+ }
+}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/OcelotApplicationService.csproj b/samples/OcelotServiceFabric/src/OcelotApplicationService/OcelotApplicationService.csproj
new file mode 100644
index 00000000..34991440
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/OcelotApplicationService.csproj
@@ -0,0 +1,21 @@
+
+
+ Stateless Service Application
+
+ Exe
+ netcoreapp2.0
+ OcelotApplicationService
+ OcelotApplicationService
+ $(PackageTargetFallback)
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/Program.cs b/samples/OcelotServiceFabric/src/OcelotApplicationService/Program.cs
new file mode 100644
index 00000000..b9d7d72e
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/Program.cs
@@ -0,0 +1,38 @@
+using Microsoft.ServiceFabric.Services.Runtime;
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace OcelotApplicationService
+{
+ internal static class Program
+ {
+ ///
+ /// This is the entry point of the service host process.
+ ///
+ private static void Main()
+ {
+ try
+ {
+ // The ServiceManifest.XML file defines one or more service type names.
+ // Registering a service maps a service type name to a .NET type.
+ // When Service Fabric creates an instance of this service type,
+ // an instance of the class is created in this host process.
+
+ ServiceRuntime.RegisterServiceAsync("OcelotApplicationServiceType",
+ context => new ApiGateway(context)).GetAwaiter().GetResult();
+
+ ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(ApiGateway).Name);
+
+ // Prevents this host process from terminating so services keeps running.
+ Thread.Sleep(Timeout.Infinite);
+ }
+ catch (Exception e)
+ {
+ ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
+ throw;
+ }
+ }
+ }
+}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/ServiceEventSource.cs b/samples/OcelotServiceFabric/src/OcelotApplicationService/ServiceEventSource.cs
new file mode 100644
index 00000000..13e2df12
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/ServiceEventSource.cs
@@ -0,0 +1,189 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.Tracing;
+using System.Fabric;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OcelotApplicationService
+{
+ [EventSource(Name = "MyCompany-ServiceOcelotApplication-OcelotService")]
+ internal sealed class ServiceEventSource : EventSource
+ {
+ public static readonly ServiceEventSource Current = new ServiceEventSource();
+
+ static ServiceEventSource()
+ {
+ // A workaround for the problem where ETW activities do not get tracked until Tasks infrastructure is initialized.
+ // This problem will be fixed in .NET Framework 4.6.2.
+ Task.Run(() => { });
+ }
+
+ // Instance constructor is private to enforce singleton semantics
+ private ServiceEventSource() : base() { }
+
+ #region Keywords
+ // Event keywords can be used to categorize events.
+ // Each keyword is a bit flag. A single event can be associated with multiple keywords (via EventAttribute.Keywords property).
+ // Keywords must be defined as a public class named 'Keywords' inside EventSource that uses them.
+ public static class Keywords
+ {
+ public const EventKeywords Requests = (EventKeywords)0x1L;
+ public const EventKeywords ServiceInitialization = (EventKeywords)0x2L;
+ }
+ #endregion
+
+ #region Events
+ // Define an instance method for each event you want to record and apply an [Event] attribute to it.
+ // The method name is the name of the event.
+ // Pass any parameters you want to record with the event (only primitive integer types, DateTime, Guid & string are allowed).
+ // Each event method implementation should check whether the event source is enabled, and if it is, call WriteEvent() method to raise the event.
+ // The number and types of arguments passed to every event method must exactly match what is passed to WriteEvent().
+ // Put [NonEvent] attribute on all methods that do not define an event.
+ // For more information see https://msdn.microsoft.com/en-us/library/system.diagnostics.tracing.eventsource.aspx
+
+ [NonEvent]
+ public void Message(string message, params object[] args)
+ {
+ if (this.IsEnabled())
+ {
+ string finalMessage = string.Format(message, args);
+ Message(finalMessage);
+ }
+ }
+
+ private const int MessageEventId = 1;
+ [Event(MessageEventId, Level = EventLevel.Informational, Message = "{0}")]
+ public void Message(string message)
+ {
+ if (this.IsEnabled())
+ {
+ WriteEvent(MessageEventId, message);
+ }
+ }
+
+ [NonEvent]
+ public void ServiceMessage(ServiceContext serviceContext, string message, params object[] args)
+ {
+ if (this.IsEnabled())
+ {
+
+ string finalMessage = string.Format(message, args);
+ ServiceMessage(
+ serviceContext.ServiceName.ToString(),
+ serviceContext.ServiceTypeName,
+ GetReplicaOrInstanceId(serviceContext),
+ serviceContext.PartitionId,
+ serviceContext.CodePackageActivationContext.ApplicationName,
+ serviceContext.CodePackageActivationContext.ApplicationTypeName,
+ serviceContext.NodeContext.NodeName,
+ finalMessage);
+ }
+ }
+
+ // For very high-frequency events it might be advantageous to raise events using WriteEventCore API.
+ // This results in more efficient parameter handling, but requires explicit allocation of EventData structure and unsafe code.
+ // To enable this code path, define UNSAFE conditional compilation symbol and turn on unsafe code support in project properties.
+ private const int ServiceMessageEventId = 2;
+ [Event(ServiceMessageEventId, Level = EventLevel.Informational, Message = "{7}")]
+ private
+#if UNSAFE
+ unsafe
+#endif
+ void ServiceMessage(
+ string serviceName,
+ string serviceTypeName,
+ long replicaOrInstanceId,
+ Guid partitionId,
+ string applicationName,
+ string applicationTypeName,
+ string nodeName,
+ string message)
+ {
+#if !UNSAFE
+ WriteEvent(ServiceMessageEventId, serviceName, serviceTypeName, replicaOrInstanceId, partitionId, applicationName, applicationTypeName, nodeName, message);
+#else
+ const int numArgs = 8;
+ fixed (char* pServiceName = serviceName, pServiceTypeName = serviceTypeName, pApplicationName = applicationName, pApplicationTypeName = applicationTypeName, pNodeName = nodeName, pMessage = message)
+ {
+ EventData* eventData = stackalloc EventData[numArgs];
+ eventData[0] = new EventData { DataPointer = (IntPtr) pServiceName, Size = SizeInBytes(serviceName) };
+ eventData[1] = new EventData { DataPointer = (IntPtr) pServiceTypeName, Size = SizeInBytes(serviceTypeName) };
+ eventData[2] = new EventData { DataPointer = (IntPtr) (&replicaOrInstanceId), Size = sizeof(long) };
+ eventData[3] = new EventData { DataPointer = (IntPtr) (&partitionId), Size = sizeof(Guid) };
+ eventData[4] = new EventData { DataPointer = (IntPtr) pApplicationName, Size = SizeInBytes(applicationName) };
+ eventData[5] = new EventData { DataPointer = (IntPtr) pApplicationTypeName, Size = SizeInBytes(applicationTypeName) };
+ eventData[6] = new EventData { DataPointer = (IntPtr) pNodeName, Size = SizeInBytes(nodeName) };
+ eventData[7] = new EventData { DataPointer = (IntPtr) pMessage, Size = SizeInBytes(message) };
+
+ WriteEventCore(ServiceMessageEventId, numArgs, eventData);
+ }
+#endif
+ }
+
+ private const int ServiceTypeRegisteredEventId = 3;
+ [Event(ServiceTypeRegisteredEventId, Level = EventLevel.Informational, Message = "Service host process {0} registered service type {1}", Keywords = Keywords.ServiceInitialization)]
+ public void ServiceTypeRegistered(int hostProcessId, string serviceType)
+ {
+ WriteEvent(ServiceTypeRegisteredEventId, hostProcessId, serviceType);
+ }
+
+ private const int ServiceHostInitializationFailedEventId = 4;
+ [Event(ServiceHostInitializationFailedEventId, Level = EventLevel.Error, Message = "Service host initialization failed", Keywords = Keywords.ServiceInitialization)]
+ public void ServiceHostInitializationFailed(string exception)
+ {
+ WriteEvent(ServiceHostInitializationFailedEventId, exception);
+ }
+
+ // A pair of events sharing the same name prefix with a "Start"/"Stop" suffix implicitly marks boundaries of an event tracing activity.
+ // These activities can be automatically picked up by debugging and profiling tools, which can compute their execution time, child activities,
+ // and other statistics.
+ private const int ServiceRequestStartEventId = 5;
+ [Event(ServiceRequestStartEventId, Level = EventLevel.Informational, Message = "Service request '{0}' started", Keywords = Keywords.Requests)]
+ public void ServiceRequestStart(string requestTypeName)
+ {
+ WriteEvent(ServiceRequestStartEventId, requestTypeName);
+ }
+
+ private const int ServiceRequestStopEventId = 6;
+ [Event(ServiceRequestStopEventId, Level = EventLevel.Informational, Message = "Service request '{0}' finished", Keywords = Keywords.Requests)]
+ public void ServiceRequestStop(string requestTypeName, string exception = "")
+ {
+ WriteEvent(ServiceRequestStopEventId, requestTypeName, exception);
+ }
+ #endregion
+
+ #region Private methods
+ private static long GetReplicaOrInstanceId(ServiceContext context)
+ {
+ StatelessServiceContext stateless = context as StatelessServiceContext;
+ if (stateless != null)
+ {
+ return stateless.InstanceId;
+ }
+
+ StatefulServiceContext stateful = context as StatefulServiceContext;
+ if (stateful != null)
+ {
+ return stateful.ReplicaId;
+ }
+
+ throw new NotSupportedException("Context type not supported.");
+ }
+#if UNSAFE
+ private int SizeInBytes(string s)
+ {
+ if (s == null)
+ {
+ return 0;
+ }
+ else
+ {
+ return (s.Length + 1) * sizeof(char);
+ }
+ }
+#endif
+ #endregion
+ }
+}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/Startup.cs b/samples/OcelotServiceFabric/src/OcelotApplicationService/Startup.cs
new file mode 100644
index 00000000..022fcb0e
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/Startup.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+
+namespace OcelotApplicationService
+{
+ public class Startup
+ {
+ public Startup(IConfiguration configuration)
+ {
+ Configuration = configuration;
+ }
+
+ public IConfiguration Configuration { get; }
+
+ // This method gets called by the runtime. Use this method to add services to the container.
+ public void ConfigureServices(IServiceCollection services)
+ {
+ services.AddMvc();
+ }
+
+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
+ {
+ if (env.IsDevelopment())
+ {
+ app.UseDeveloperExceptionPage();
+ }
+
+ app.UseMvc();
+ }
+ }
+}
diff --git a/samples/OcelotServiceFabric/src/global.json b/samples/OcelotServiceFabric/src/global.json
new file mode 100644
index 00000000..8288598a
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/global.json
@@ -0,0 +1,6 @@
+{
+ "projects": [ "../"],
+ "sdk": {
+ "version": "2.1.4"
+ }
+}
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/uninstall.ps1 b/samples/OcelotServiceFabric/uninstall.ps1
new file mode 100644
index 00000000..032ee0e8
--- /dev/null
+++ b/samples/OcelotServiceFabric/uninstall.ps1
@@ -0,0 +1,2 @@
+Remove-ServiceFabricApplication fabric:/OcelotServiceApplication
+Unregister-ServiceFabricApplicationType OcelotServiceApplicationType 1.0.0
\ No newline at end of file
diff --git a/samples/OcelotServiceFabric/uninstall.sh b/samples/OcelotServiceFabric/uninstall.sh
new file mode 100644
index 00000000..45fc561c
--- /dev/null
+++ b/samples/OcelotServiceFabric/uninstall.sh
@@ -0,0 +1,5 @@
+#!/bin/bash -x
+
+sfctl application delete --application-id OcelotServiceApplication
+sfctl application unprovision --application-type-name OcelotServiceApplicationType --application-type-version 1.0.0
+sfctl store delete --content-path OcelotServiceApplication
\ No newline at end of file
diff --git a/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs b/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs
index ffdd1ac6..bd4683d0 100644
--- a/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs
+++ b/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs
@@ -63,4 +63,3 @@ namespace Ocelot.Authentication.Middleware
}
}
}
-
diff --git a/src/Ocelot/Authorisation/ClaimsAuthoriser.cs b/src/Ocelot/Authorisation/ClaimsAuthoriser.cs
index 4db1045c..3ca7809e 100644
--- a/src/Ocelot/Authorisation/ClaimsAuthoriser.cs
+++ b/src/Ocelot/Authorisation/ClaimsAuthoriser.cs
@@ -47,7 +47,8 @@ namespace Ocelot.Authorisation
});
}
}
+
return new OkResponse(true);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs b/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs
index 873c4cf7..3d128b72 100644
--- a/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs
+++ b/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs
@@ -123,7 +123,6 @@ namespace Ocelot.Cache.Middleware
var contentHeaders = response?.Content?.Headers.ToDictionary(v => v.Key, v => v.Value);
-
var cached = new CachedResponse(statusCode, headers, body, contentHeaders);
return cached;
}
diff --git a/src/Ocelot/Cache/RegionCreator.cs b/src/Ocelot/Cache/RegionCreator.cs
index e2ca874b..f5a94c21 100644
--- a/src/Ocelot/Cache/RegionCreator.cs
+++ b/src/Ocelot/Cache/RegionCreator.cs
@@ -4,7 +4,6 @@ using Ocelot.Configuration.File;
namespace Ocelot.Cache
{
-
public class RegionCreator : IRegionCreator
{
public string Create(FileReRoute reRoute)
@@ -21,4 +20,4 @@ namespace Ocelot.Cache
return region;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Cache/Regions.cs b/src/Ocelot/Cache/Regions.cs
index f94cc306..baec6087 100644
--- a/src/Ocelot/Cache/Regions.cs
+++ b/src/Ocelot/Cache/Regions.cs
@@ -8,6 +8,7 @@ namespace Ocelot.Cache
{
Value = value;
}
+
public List Value {get;private set;}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddleware.cs b/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddleware.cs
index 5161b247..48f57834 100644
--- a/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddleware.cs
+++ b/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddleware.cs
@@ -39,6 +39,7 @@ namespace Ocelot.Claims.Middleware
return;
}
}
+
await _next.Invoke(context);
}
}
diff --git a/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs b/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs
index bc860424..5f82f688 100644
--- a/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs
+++ b/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs
@@ -36,7 +36,6 @@ namespace Ocelot.Configuration.Builder
private readonly List _downstreamAddresses;
private string _upstreamHost;
private string _key;
-
public DownstreamReRouteBuilder()
{
_downstreamAddresses = new List();
@@ -216,7 +215,6 @@ namespace Ocelot.Configuration.Builder
return this;
}
-
public DownstreamReRoute Build()
{
return new DownstreamReRoute(
diff --git a/src/Ocelot/Configuration/Builder/ServiceProviderConfigurationBuilder.cs b/src/Ocelot/Configuration/Builder/ServiceProviderConfigurationBuilder.cs
index 0999a47c..b1f4e832 100644
--- a/src/Ocelot/Configuration/Builder/ServiceProviderConfigurationBuilder.cs
+++ b/src/Ocelot/Configuration/Builder/ServiceProviderConfigurationBuilder.cs
@@ -4,6 +4,7 @@ namespace Ocelot.Configuration.Builder
{
private string _serviceDiscoveryProviderHost;
private int _serviceDiscoveryProviderPort;
+ private string _type;
public ServiceProviderConfigurationBuilder WithServiceDiscoveryProviderHost(string serviceDiscoveryProviderHost)
{
@@ -17,9 +18,15 @@ namespace Ocelot.Configuration.Builder
return this;
}
+ public ServiceProviderConfigurationBuilder WithServiceDiscoveryProviderType(string type)
+ {
+ _type = type;
+ return this;
+ }
+
public ServiceProviderConfiguration Build()
{
- return new ServiceProviderConfiguration(_serviceDiscoveryProviderHost,_serviceDiscoveryProviderPort);
+ return new ServiceProviderConfiguration(_type, _serviceDiscoveryProviderHost, _serviceDiscoveryProviderPort);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs b/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs
index fbc58020..a35c7d54 100644
--- a/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs
+++ b/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs
@@ -35,7 +35,6 @@ namespace Ocelot.Configuration.Creator
private readonly IHeaderFindAndReplaceCreator _headerFAndRCreator;
private readonly IDownstreamAddressesCreator _downstreamAddressesCreator;
-
public FileOcelotConfigurationCreator(
IOptions options,
IConfigurationValidator configurationValidator,
diff --git a/src/Ocelot/Configuration/Creator/ServiceProviderConfigurationCreator.cs b/src/Ocelot/Configuration/Creator/ServiceProviderConfigurationCreator.cs
index cfc3e7c7..c104385a 100644
--- a/src/Ocelot/Configuration/Creator/ServiceProviderConfigurationCreator.cs
+++ b/src/Ocelot/Configuration/Creator/ServiceProviderConfigurationCreator.cs
@@ -7,12 +7,14 @@ namespace Ocelot.Configuration.Creator
{
public ServiceProviderConfiguration Create(FileGlobalConfiguration globalConfiguration)
{
+ //todo log or return error here dont just default to something that wont work..
var serviceProviderPort = globalConfiguration?.ServiceDiscoveryProvider?.Port ?? 0;
return new ServiceProviderConfigurationBuilder()
- .WithServiceDiscoveryProviderHost(globalConfiguration?.ServiceDiscoveryProvider?.Host)
- .WithServiceDiscoveryProviderPort(serviceProviderPort)
- .Build();
+ .WithServiceDiscoveryProviderHost(globalConfiguration?.ServiceDiscoveryProvider?.Host)
+ .WithServiceDiscoveryProviderPort(serviceProviderPort)
+ .WithServiceDiscoveryProviderType(globalConfiguration?.ServiceDiscoveryProvider?.Type)
+ .Build();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs b/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs
index 1700472a..833c61db 100644
--- a/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs
+++ b/src/Ocelot/Configuration/Creator/UpstreamTemplatePatternCreator.cs
@@ -67,7 +67,6 @@ namespace Ocelot.Configuration.Creator
return false;
}
-
private bool IsPlaceHolder(string upstreamTemplate, int i)
{
return upstreamTemplate[i] == '{';
diff --git a/src/Ocelot/Configuration/DownstreamHostAndPort.cs b/src/Ocelot/Configuration/DownstreamHostAndPort.cs
index 483e7523..186cce2f 100644
--- a/src/Ocelot/Configuration/DownstreamHostAndPort.cs
+++ b/src/Ocelot/Configuration/DownstreamHostAndPort.cs
@@ -7,6 +7,7 @@
Host = host;
Port = port;
}
+
public string Host { get; private set; }
public int Port { get; private set; }
}
diff --git a/src/Ocelot/Configuration/File/FileConfiguration.cs b/src/Ocelot/Configuration/File/FileConfiguration.cs
index 6d73ce3f..e38ae6cb 100644
--- a/src/Ocelot/Configuration/File/FileConfiguration.cs
+++ b/src/Ocelot/Configuration/File/FileConfiguration.cs
@@ -12,6 +12,7 @@ namespace Ocelot.Configuration.File
}
public List ReRoutes { get; set; }
+
// Seperate field for aggregates because this let's you re-use ReRoutes in multiple Aggregates
public List Aggregates { get;set; }
public FileGlobalConfiguration GlobalConfiguration { get; set; }
diff --git a/src/Ocelot/Configuration/File/FileGlobalConfiguration.cs b/src/Ocelot/Configuration/File/FileGlobalConfiguration.cs
index adbbdce1..8dea9ed6 100644
--- a/src/Ocelot/Configuration/File/FileGlobalConfiguration.cs
+++ b/src/Ocelot/Configuration/File/FileGlobalConfiguration.cs
@@ -1,5 +1,4 @@
-
-namespace Ocelot.Configuration.File
+namespace Ocelot.Configuration.File
{
public class FileGlobalConfiguration
{
diff --git a/src/Ocelot/Configuration/File/FileRateLimitOptions.cs b/src/Ocelot/Configuration/File/FileRateLimitOptions.cs
index b9277a3c..c7f99cb0 100644
--- a/src/Ocelot/Configuration/File/FileRateLimitOptions.cs
+++ b/src/Ocelot/Configuration/File/FileRateLimitOptions.cs
@@ -34,6 +34,4 @@ namespace Ocelot.Configuration.File
///
public int HttpStatusCode { get; set; } = 429;
}
-
-
}
diff --git a/src/Ocelot/Configuration/File/FileRateLimitRule.cs b/src/Ocelot/Configuration/File/FileRateLimitRule.cs
index 55346d2e..5e1616e6 100644
--- a/src/Ocelot/Configuration/File/FileRateLimitRule.cs
+++ b/src/Ocelot/Configuration/File/FileRateLimitRule.cs
@@ -6,7 +6,6 @@ using System.Threading.Tasks;
namespace Ocelot.Configuration.File
{
-
public class FileRateLimitRule
{
public FileRateLimitRule()
@@ -27,6 +26,7 @@ namespace Ocelot.Configuration.File
public string Period { get; set; }
public double PeriodTimespan { get; set; }
+
///
/// Maximum number of requests that a client can make in a defined period
///
@@ -38,6 +38,7 @@ namespace Ocelot.Configuration.File
{
return string.Empty;
}
+
var sb = new StringBuilder();
sb.Append(
$"{nameof(Period)}:{Period},{nameof(PeriodTimespan)}:{PeriodTimespan:F},{nameof(Limit)}:{Limit},{nameof(ClientWhitelist)}:[");
diff --git a/src/Ocelot/Configuration/File/FileServiceDiscoveryProvider.cs b/src/Ocelot/Configuration/File/FileServiceDiscoveryProvider.cs
index f9c370b1..203cc675 100644
--- a/src/Ocelot/Configuration/File/FileServiceDiscoveryProvider.cs
+++ b/src/Ocelot/Configuration/File/FileServiceDiscoveryProvider.cs
@@ -4,5 +4,6 @@ namespace Ocelot.Configuration.File
{
public string Host {get;set;}
public int Port { get; set; }
+ public string Type { get; set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Configuration/QoSOptions.cs b/src/Ocelot/Configuration/QoSOptions.cs
index c518cfec..651bd506 100644
--- a/src/Ocelot/Configuration/QoSOptions.cs
+++ b/src/Ocelot/Configuration/QoSOptions.cs
@@ -14,8 +14,7 @@ namespace Ocelot.Configuration
DurationOfBreak = durationofBreak;
TimeoutValue = timeoutValue;
TimeoutStrategy = timeoutStrategy;
- }
-
+ }
public int ExceptionsAllowedBeforeBreaking { get; private set; }
@@ -24,6 +23,5 @@ namespace Ocelot.Configuration
public int TimeoutValue { get; private set; }
public TimeoutStrategy TimeoutStrategy { get; private set; }
-
}
}
diff --git a/src/Ocelot/Configuration/RateLimitRule.cs b/src/Ocelot/Configuration/RateLimitRule.cs
index d77919ae..9240087c 100644
--- a/src/Ocelot/Configuration/RateLimitRule.cs
+++ b/src/Ocelot/Configuration/RateLimitRule.cs
@@ -17,9 +17,10 @@ namespace Ocelot.Configuration
public string Period { get; private set; }
public double PeriodTimespan { get; private set; }
+
///
/// Maximum number of requests that a client can make in a defined period
///
public long Limit { get; private set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Configuration/ReRouteOptions.cs b/src/Ocelot/Configuration/ReRouteOptions.cs
index 5ec316c3..e3a7a7b1 100644
--- a/src/Ocelot/Configuration/ReRouteOptions.cs
+++ b/src/Ocelot/Configuration/ReRouteOptions.cs
@@ -9,12 +9,12 @@ namespace Ocelot.Configuration
IsCached = isCached;
IsQos = isQos;
EnableRateLimiting = isEnableRateLimiting;
-
}
+
public bool IsAuthenticated { get; private set; }
public bool IsAuthorised { get; private set; }
public bool IsCached { get; private set; }
public bool IsQos { get; private set; }
public bool EnableRateLimiting { get; private set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPoller.cs b/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPoller.cs
index 7e78b3aa..a2780062 100644
--- a/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPoller.cs
+++ b/src/Ocelot/Configuration/Repository/ConsulFileConfigurationPoller.cs
@@ -34,7 +34,6 @@ namespace Ocelot.Configuration.Repository
_polling = true;
await Poll();
_polling = false;
-
}, null, 0, 1000);
}
diff --git a/src/Ocelot/Configuration/Repository/ConsulFileConfigurationRepository.cs b/src/Ocelot/Configuration/Repository/ConsulFileConfigurationRepository.cs
index 91b4bd9d..97bf7c97 100644
--- a/src/Ocelot/Configuration/Repository/ConsulFileConfigurationRepository.cs
+++ b/src/Ocelot/Configuration/Repository/ConsulFileConfigurationRepository.cs
@@ -9,7 +9,6 @@ using Ocelot.ServiceDiscovery;
namespace Ocelot.Configuration.Repository
{
-
public class ConsulFileConfigurationRepository : IFileConfigurationRepository
{
private readonly ConsulClient _consul;
@@ -18,8 +17,8 @@ namespace Ocelot.Configuration.Repository
public ConsulFileConfigurationRepository(Cache.IOcelotCache cache, ServiceProviderConfiguration serviceProviderConfig)
{
- var consulHost = string.IsNullOrEmpty(serviceProviderConfig?.ServiceProviderHost) ? "localhost" : serviceProviderConfig?.ServiceProviderHost;
- var consulPort = serviceProviderConfig?.ServiceProviderPort ?? 8500;
+ var consulHost = string.IsNullOrEmpty(serviceProviderConfig?.Host) ? "localhost" : serviceProviderConfig?.Host;
+ var consulPort = serviceProviderConfig?.Port ?? 8500;
var configuration = new ConsulRegistryConfiguration(consulHost, consulPort, _ocelotConfiguration);
_cache = cache;
_consul = new ConsulClient(c =>
@@ -76,4 +75,4 @@ namespace Ocelot.Configuration.Repository
return new ErrorResponse(new UnableToSetConfigInConsulError($"Unable to set FileConfiguration in consul, response status code from consul was {result.StatusCode}"));
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Configuration/ServiceProviderConfiguraion.cs b/src/Ocelot/Configuration/ServiceProviderConfiguraion.cs
deleted file mode 100644
index 272d2205..00000000
--- a/src/Ocelot/Configuration/ServiceProviderConfiguraion.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-namespace Ocelot.Configuration
-{
- public class ServiceProviderConfiguration
- {
- public ServiceProviderConfiguration(string serviceProviderHost, int serviceProviderPort)
- {
- ServiceProviderHost = serviceProviderHost;
- ServiceProviderPort = serviceProviderPort;
- }
-
- public string ServiceProviderHost { get; private set; }
- public int ServiceProviderPort { get; private set; }
- }
-}
\ No newline at end of file
diff --git a/src/Ocelot/Configuration/ServiceProviderConfiguration.cs b/src/Ocelot/Configuration/ServiceProviderConfiguration.cs
new file mode 100644
index 00000000..aa7c492c
--- /dev/null
+++ b/src/Ocelot/Configuration/ServiceProviderConfiguration.cs
@@ -0,0 +1,16 @@
+namespace Ocelot.Configuration
+{
+ public class ServiceProviderConfiguration
+ {
+ public ServiceProviderConfiguration(string type, string host, int port)
+ {
+ Host = host;
+ Port = port;
+ Type = type;
+ }
+
+ public string Host { get; private set; }
+ public int Port { get; private set; }
+ public string Type { get; private set; }
+ }
+}
\ No newline at end of file
diff --git a/src/Ocelot/Configuration/Setter/FileConfigurationSetter.cs b/src/Ocelot/Configuration/Setter/FileConfigurationSetter.cs
index 71f56277..38a7c1cb 100644
--- a/src/Ocelot/Configuration/Setter/FileConfigurationSetter.cs
+++ b/src/Ocelot/Configuration/Setter/FileConfigurationSetter.cs
@@ -12,7 +12,7 @@ namespace Ocelot.Configuration.Setter
private readonly IOcelotConfigurationCreator _configCreator;
private readonly IFileConfigurationRepository _repo;
- public FileConfigurationSetter(IOcelotConfigurationRepository configRepo,
+ public FileConfigurationSetter(IOcelotConfigurationRepository configRepo,
IOcelotConfigurationCreator configCreator, IFileConfigurationRepository repo)
{
_configRepo = configRepo;
@@ -39,4 +39,4 @@ namespace Ocelot.Configuration.Setter
return new ErrorResponse(config.Errors);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs b/src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs
index 58da7c4f..d0c6de0e 100644
--- a/src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs
+++ b/src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs
@@ -30,7 +30,7 @@ namespace Ocelot.Configuration.Validator
RuleForEach(configuration => configuration.Aggregates)
.Must((config, aggregateReRoute) => AllReRoutesForAggregateExist(aggregateReRoute, config.ReRoutes))
- .WithMessage((config, aggregateReRoute) => $"ReRoutes for {nameof(aggregateReRoute)} {aggregateReRoute.UpstreamPathTemplate} either do not exist or do not have correct Key property");
+ .WithMessage((config, aggregateReRoute) => $"ReRoutes for {nameof(aggregateReRoute)} {aggregateReRoute.UpstreamPathTemplate} either do not exist or do not have correct ServiceName property");
RuleForEach(configuration => configuration.Aggregates)
.Must((config, aggregateReRoute) => DoesNotContainReRoutesWithSpecificRequestIdKeys(aggregateReRoute, config.ReRoutes))
diff --git a/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs b/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs
index b661e065..e90aa218 100644
--- a/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs
+++ b/src/Ocelot/Configuration/Validator/FileValidationFailedError.cs
@@ -9,7 +9,6 @@ namespace Ocelot.Configuration.Validator
{
public FileValidationFailedError(string message) : base(message, OcelotErrorCode.FileValidationFailedError)
{
-
}
}
}
diff --git a/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs b/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs
index f2ebbace..c2f4dc62 100644
--- a/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs
+++ b/src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs
@@ -67,6 +67,7 @@ namespace Ocelot.Configuration.Validator
{
return true;
}
+
var schemes = await _authenticationSchemeProvider.GetAllSchemesAsync();
var supportedSchemes = schemes.Select(scheme => scheme.Name).ToList();
diff --git a/src/Ocelot/DependencyInjection/OcelotBuilder.cs b/src/Ocelot/DependencyInjection/OcelotBuilder.cs
index f4192713..e1ef6b42 100644
--- a/src/Ocelot/DependencyInjection/OcelotBuilder.cs
+++ b/src/Ocelot/DependencyInjection/OcelotBuilder.cs
@@ -99,7 +99,6 @@ namespace Ocelot.DependencyInjection
_services.TryAddSingleton();
_services.TryAddSingleton();
_services.TryAddSingleton();
- _services.TryAddSingleton();
_services.TryAddSingleton();
_services.TryAddSingleton();
_services.TryAddSingleton();
@@ -126,7 +125,7 @@ namespace Ocelot.DependencyInjection
// see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc
// could maybe use a scoped data repository
- _services.TryAddSingleton();
+ _services.TryAddSingleton();
_services.TryAddSingleton();
_services.AddMemoryCache();
_services.TryAddSingleton();
@@ -154,7 +153,6 @@ namespace Ocelot.DependencyInjection
// We add this here so that we can always inject something into the factory for IoC..
_services.AddSingleton();
-
}
public IOcelotAdministrationBuilder AddAdministration(string path, string secret)
@@ -265,8 +263,7 @@ namespace Ocelot.DependencyInjection
var urlFinder = new BaseUrlFinder(_configurationRoot);
var baseSchemeUrlAndPort = urlFinder.Find();
- JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
-
+ JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
_services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(o =>
diff --git a/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs b/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs
index ed04daef..c7696ecf 100644
--- a/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs
+++ b/src/Ocelot/DownstreamRouteFinder/DownstreamRoute.cs
@@ -11,7 +11,8 @@ namespace Ocelot.DownstreamRouteFinder
TemplatePlaceholderNameAndValues = templatePlaceholderNameAndValues;
ReRoute = reRoute;
}
+
public List TemplatePlaceholderNameAndValues { get; private set; }
public ReRoute ReRoute { get; private set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs
index 4b467b95..c9da50a4 100644
--- a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs
+++ b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs
@@ -17,7 +17,6 @@ namespace Ocelot.DownstreamRouteFinder.Middleware
private readonly IOcelotConfigurationProvider _configProvider;
private readonly IMultiplexer _multiplexer;
-
public DownstreamRouteFinderMiddleware(OcelotRequestDelegate next,
IOcelotLoggerFactory loggerFactory,
IDownstreamRouteFinder downstreamRouteFinder,
@@ -60,8 +59,8 @@ namespace Ocelot.DownstreamRouteFinder.Middleware
return;
}
- //todo - put this back in
- // _logger.LogDebug("downstream template is {downstreamRoute.Data.ReRoute.DownstreamPath}", downstreamRoute.Data.ReRoute.DownstreamReRoute.DownstreamPathTemplate);
+ // todo - put this back in
+ //// _logger.LogDebug("downstream template is {downstreamRoute.Data.ReRoute.DownstreamPath}", downstreamRoute.Data.ReRoute.DownstreamReRoute.DownstreamPathTemplate);
context.TemplatePlaceholderNameAndValues = downstreamRoute.Data.TemplatePlaceholderNameAndValues;
diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathPlaceholderNameAndValueFinder.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IPlaceholderNameAndValueFinder.cs
similarity index 96%
rename from src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathPlaceholderNameAndValueFinder.cs
rename to src/Ocelot/DownstreamRouteFinder/UrlMatcher/IPlaceholderNameAndValueFinder.cs
index d2cb4167..678b1081 100644
--- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IUrlPathPlaceholderNameAndValueFinder.cs
+++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/IPlaceholderNameAndValueFinder.cs
@@ -1,10 +1,10 @@
-using System.Collections.Generic;
-using Ocelot.Responses;
-
-namespace Ocelot.DownstreamRouteFinder.UrlMatcher
-{
- public interface IPlaceholderNameAndValueFinder
- {
- Response> Find(string path, string pathTemplate);
- }
-}
+using System.Collections.Generic;
+using Ocelot.Responses;
+
+namespace Ocelot.DownstreamRouteFinder.UrlMatcher
+{
+ public interface IPlaceholderNameAndValueFinder
+ {
+ Response> Find(string path, string pathTemplate);
+ }
+}
diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValue.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/PlaceholderNameAndValue.cs
similarity index 96%
rename from src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValue.cs
rename to src/Ocelot/DownstreamRouteFinder/UrlMatcher/PlaceholderNameAndValue.cs
index e299c770..90099d58 100644
--- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValue.cs
+++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/PlaceholderNameAndValue.cs
@@ -1,13 +1,14 @@
-namespace Ocelot.DownstreamRouteFinder.UrlMatcher
-{
- public class PlaceholderNameAndValue
- {
- public PlaceholderNameAndValue(string name, string value)
- {
- Name = name;
- Value = value;
- }
- public string Name {get;private set;}
- public string Value {get;private set;}
- }
-}
\ No newline at end of file
+namespace Ocelot.DownstreamRouteFinder.UrlMatcher
+{
+ public class PlaceholderNameAndValue
+ {
+ public PlaceholderNameAndValue(string name, string value)
+ {
+ Name = name;
+ Value = value;
+ }
+
+ public string Name {get;private set;}
+ public string Value {get;private set;}
+ }
+}
diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs
index bfbd6fdc..9236ae39 100644
--- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs
+++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlMatch.cs
@@ -6,6 +6,7 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher
{
Match = match;
}
+
public bool Match {get;private set;}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs
index 70cf2272..4471618f 100644
--- a/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs
+++ b/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs
@@ -50,6 +50,7 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher
counterForTemplate = endOfPlaceholder;
}
+
counterForPath++;
}
@@ -90,6 +91,7 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher
return variableName;
}
+
private int GetNextCounterPosition(string urlTemplate, int counterForTemplate, char delimiter)
{
var closingPlaceHolderPositionOnTemplate = urlTemplate.IndexOf(delimiter, counterForTemplate);
@@ -111,4 +113,4 @@ namespace Ocelot.DownstreamRouteFinder.UrlMatcher
return character == '{';
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/DownstreamUrlCreator/IUrlBuilder.cs b/src/Ocelot/DownstreamUrlCreator/IUrlBuilder.cs
index 19fa55a1..9975cec2 100644
--- a/src/Ocelot/DownstreamUrlCreator/IUrlBuilder.cs
+++ b/src/Ocelot/DownstreamUrlCreator/IUrlBuilder.cs
@@ -1,4 +1,5 @@
-using Ocelot.Responses;
+/*
+using Ocelot.Responses;
using Ocelot.Values;
namespace Ocelot.DownstreamUrlCreator
@@ -8,3 +9,4 @@ namespace Ocelot.DownstreamUrlCreator
Response Build(string downstreamPath, string downstreamScheme, ServiceHostAndPort downstreamHostAndPort);
}
}
+*/
diff --git a/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddleware.cs b/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddleware.cs
index 5b5e8346..308daea5 100644
--- a/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddleware.cs
+++ b/src/Ocelot/DownstreamUrlCreator/Middleware/DownstreamUrlCreatorMiddleware.cs
@@ -5,7 +5,10 @@ using Ocelot.Infrastructure.RequestData;
using Ocelot.Logging;
using Ocelot.Middleware;
using System;
+using System.Linq;
using Ocelot.DownstreamRouteFinder.Middleware;
+using Ocelot.Responses;
+using Ocelot.Values;
namespace Ocelot.DownstreamUrlCreator.Middleware
{
@@ -14,16 +17,13 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
private readonly OcelotRequestDelegate _next;
private readonly IDownstreamPathPlaceholderReplacer _replacer;
private readonly IOcelotLogger _logger;
- private readonly IUrlBuilder _urlBuilder;
public DownstreamUrlCreatorMiddleware(OcelotRequestDelegate next,
IOcelotLoggerFactory loggerFactory,
- IDownstreamPathPlaceholderReplacer replacer,
- IUrlBuilder urlBuilder)
+ IDownstreamPathPlaceholderReplacer replacer)
{
_next = next;
_replacer = replacer;
- _urlBuilder = urlBuilder;
_logger = loggerFactory.CreateLogger();
}
@@ -40,11 +40,20 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
return;
}
- var uriBuilder = new UriBuilder(context.DownstreamRequest.RequestUri)
+ UriBuilder uriBuilder;
+
+ if (ServiceFabricRequest(context))
{
- Path = dsPath.Data.Value,
- Scheme = context.DownstreamReRoute.DownstreamScheme
- };
+ uriBuilder = CreateServiceFabricUri(context, dsPath);
+ }
+ else
+ {
+ uriBuilder = new UriBuilder(context.DownstreamRequest.RequestUri)
+ {
+ Path = dsPath.Data.Value,
+ Scheme = context.DownstreamReRoute.DownstreamScheme
+ };
+ }
context.DownstreamRequest.RequestUri = uriBuilder.Uri;
@@ -52,5 +61,38 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
await _next.Invoke(context);
}
+
+ private UriBuilder CreateServiceFabricUri(DownstreamContext context, Response dsPath)
+ {
+ var query = context.DownstreamRequest.RequestUri.Query;
+ var scheme = context.DownstreamReRoute.DownstreamScheme;
+ var host = context.DownstreamRequest.RequestUri.Host;
+ var port = context.DownstreamRequest.RequestUri.Port;
+ var serviceFabricPath = $"/{context.DownstreamReRoute.ServiceName + dsPath.Data.Value}";
+
+ Uri uri;
+
+ if (RequestForStatefullService(query))
+ {
+ uri = new Uri($"{scheme}://{host}:{port}{serviceFabricPath}{query}");
+ }
+ else
+ {
+ var split = string.IsNullOrEmpty(query) ? "?" : "&";
+ uri = new Uri($"{scheme}://{host}:{port}{serviceFabricPath}{query}{split}cmd=instance");
+ }
+
+ return new UriBuilder(uri);
+ }
+
+ private static bool ServiceFabricRequest(DownstreamContext context)
+ {
+ return context.ServiceProviderConfiguration.Type == "ServiceFabric" && context.DownstreamReRoute.UseServiceDiscovery;
+ }
+
+ private static bool RequestForStatefullService(string query)
+ {
+ return query.Contains("PartitionKind") && query.Contains("PartitionKey");
+ }
}
}
diff --git a/src/Ocelot/DownstreamUrlCreator/UrlBuilder.cs b/src/Ocelot/DownstreamUrlCreator/UrlBuilder.cs
index 80f2507d..1c5f284c 100644
--- a/src/Ocelot/DownstreamUrlCreator/UrlBuilder.cs
+++ b/src/Ocelot/DownstreamUrlCreator/UrlBuilder.cs
@@ -1,4 +1,5 @@
-using System;
+/*
+using System;
using System.Collections.Generic;
using Ocelot.Errors;
using Ocelot.Responses;
@@ -25,12 +26,11 @@ namespace Ocelot.DownstreamUrlCreator
return new ErrorResponse(new List { new DownstreamHostNullOrEmptyError() });
}
-
var builder = new UriBuilder
{
Host = downstreamHostAndPort.DownstreamHost,
Path = downstreamPath,
- Scheme = downstreamScheme
+ Scheme = downstreamScheme,
};
if (downstreamHostAndPort.DownstreamPort > 0)
@@ -44,3 +44,4 @@ namespace Ocelot.DownstreamUrlCreator
}
}
}
+*/
diff --git a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamTemplatePathPlaceholderReplacer.cs
similarity index 97%
rename from src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs
rename to src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamTemplatePathPlaceholderReplacer.cs
index dfd70eed..1b744819 100644
--- a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs
+++ b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/DownstreamTemplatePathPlaceholderReplacer.cs
@@ -1,25 +1,25 @@
-using System.Collections.Generic;
-using System.Text;
-using Ocelot.DownstreamRouteFinder.UrlMatcher;
-using Ocelot.Responses;
-using Ocelot.Values;
-
-namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer
-{
- public class DownstreamTemplatePathPlaceholderReplacer : IDownstreamPathPlaceholderReplacer
- {
- public Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues)
- {
- var downstreamPath = new StringBuilder();
-
- downstreamPath.Append(downstreamPathTemplate.Value);
-
- foreach (var placeholderVariableAndValue in urlPathPlaceholderNameAndValues)
- {
- downstreamPath.Replace(placeholderVariableAndValue.Name, placeholderVariableAndValue.Value);
- }
-
- return new OkResponse(new DownstreamPath(downstreamPath.ToString()));
- }
- }
+using System.Collections.Generic;
+using System.Text;
+using Ocelot.DownstreamRouteFinder.UrlMatcher;
+using Ocelot.Responses;
+using Ocelot.Values;
+
+namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer
+{
+ public class DownstreamTemplatePathPlaceholderReplacer : IDownstreamPathPlaceholderReplacer
+ {
+ public Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues)
+ {
+ var downstreamPath = new StringBuilder();
+
+ downstreamPath.Append(downstreamPathTemplate.Value);
+
+ foreach (var placeholderVariableAndValue in urlPathPlaceholderNameAndValues)
+ {
+ downstreamPath.Replace(placeholderVariableAndValue.Name, placeholderVariableAndValue.Value);
+ }
+
+ return new OkResponse(new DownstreamPath(downstreamPath.ToString()));
+ }
+ }
}
\ No newline at end of file
diff --git a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamPathPlaceholderReplacer.cs
similarity index 97%
rename from src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs
rename to src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamPathPlaceholderReplacer.cs
index 9e12b580..46e998d4 100644
--- a/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs
+++ b/src/Ocelot/DownstreamUrlCreator/UrlTemplateReplacer/IDownstreamPathPlaceholderReplacer.cs
@@ -1,12 +1,12 @@
-using System.Collections.Generic;
-using Ocelot.DownstreamRouteFinder.UrlMatcher;
-using Ocelot.Responses;
-using Ocelot.Values;
-
-namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer
-{
- public interface IDownstreamPathPlaceholderReplacer
- {
- Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues);
- }
+using System.Collections.Generic;
+using Ocelot.DownstreamRouteFinder.UrlMatcher;
+using Ocelot.Responses;
+using Ocelot.Values;
+
+namespace Ocelot.DownstreamUrlCreator.UrlTemplateReplacer
+{
+ public interface IDownstreamPathPlaceholderReplacer
+ {
+ Response Replace(PathTemplate downstreamPathTemplate, List urlPathPlaceholderNameAndValues);
+ }
}
\ No newline at end of file
diff --git a/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddleware.cs b/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddleware.cs
index 9b49c84a..2b9e22e2 100644
--- a/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddleware.cs
+++ b/src/Ocelot/Errors/Middleware/ExceptionHandlerMiddleware.cs
@@ -100,6 +100,7 @@ namespace Ocelot.Errors.Middleware
message =
$"{message}, inner exception message {e.InnerException.Message}, inner exception stack {e.InnerException.StackTrace}";
}
+
return $"{message} RequestId: {context.HttpContext.TraceIdentifier}";
}
}
diff --git a/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs b/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs
index 347923ed..cb45ffc3 100644
--- a/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs
+++ b/src/Ocelot/Headers/HttpResponseHeaderReplacer.cs
@@ -26,6 +26,7 @@ namespace Ocelot.Headers
return $"{downstreamUrl}/";
});
}
+
public Response Replace(HttpResponseMessage response, List fAndRs, HttpRequestMessage httpRequestMessage)
{
foreach (var f in fAndRs)
@@ -54,4 +55,4 @@ namespace Ocelot.Headers
return new OkResponse();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Infrastructure/Claims/Parser/ClaimsParser.cs b/src/Ocelot/Infrastructure/Claims/Parser/ClaimsParser.cs
index b3a028b3..1af0acbc 100644
--- a/src/Ocelot/Infrastructure/Claims/Parser/ClaimsParser.cs
+++ b/src/Ocelot/Infrastructure/Claims/Parser/ClaimsParser.cs
@@ -37,7 +37,6 @@
return new OkResponse(value);
}
-
public Response> GetValuesByClaimType(IEnumerable claims, string claimType)
{
List values = new List();
@@ -47,7 +46,6 @@
return new OkResponse>(values);
}
-
private Response GetValue(IEnumerable claims, string key)
{
var claim = claims.FirstOrDefault(c => c.Type == key);
diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs b/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs
index 583b3002..2713d44b 100644
--- a/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs
+++ b/src/Ocelot/LoadBalancer/LoadBalancers/Lease.cs
@@ -9,6 +9,7 @@ namespace Ocelot.LoadBalancer.LoadBalancers
HostAndPort = hostAndPort;
Connections = connections;
}
+
public ServiceHostAndPort HostAndPort { get; private set; }
public int Connections { get; private set; }
}
diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancer.cs b/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancer.cs
index 172909d7..203d1b9d 100644
--- a/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancer.cs
+++ b/src/Ocelot/LoadBalancer/LoadBalancers/NoLoadBalancer.cs
@@ -17,6 +17,7 @@ namespace Ocelot.LoadBalancer.LoadBalancers
public async Task> Lease()
{
+ //todo no point spinning a task up here, also first or default could be null..
var service = await Task.FromResult(_services.FirstOrDefault());
return new OkResponse(service.HostAndPort);
}
diff --git a/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs b/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs
index efc00e5e..26d55b1f 100644
--- a/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs
+++ b/src/Ocelot/LoadBalancer/LoadBalancers/RoundRobin.cs
@@ -17,7 +17,6 @@ namespace Ocelot.LoadBalancer.LoadBalancers
_services = services;
}
-
public async Task> Lease()
{
var services = await _services.Invoke();
diff --git a/src/Ocelot/Logging/IOcelotLoggerFactory.cs b/src/Ocelot/Logging/IOcelotLoggerFactory.cs
index 29b4c9d0..3a145595 100644
--- a/src/Ocelot/Logging/IOcelotLoggerFactory.cs
+++ b/src/Ocelot/Logging/IOcelotLoggerFactory.cs
@@ -6,6 +6,7 @@ namespace Ocelot.Logging
{
IOcelotLogger CreateLogger();
}
+
///
/// Thin wrapper around the DotNet core logging framework, used to allow the scopedDataRepository to be injected giving access to the Ocelot RequestId
///
diff --git a/src/Ocelot/Middleware/DownstreamContext.cs b/src/Ocelot/Middleware/DownstreamContext.cs
index 84ebc77a..1c805deb 100644
--- a/src/Ocelot/Middleware/DownstreamContext.cs
+++ b/src/Ocelot/Middleware/DownstreamContext.cs
@@ -22,8 +22,6 @@ namespace Ocelot.Middleware
public HttpRequestMessage DownstreamRequest { get; set; }
public HttpResponseMessage DownstreamResponse { get; set; }
public List Errors { get;set; }
- //public string RequestId {get;set;}
- //public string PreviousRequestId {get;set;}
public bool IsError => Errors.Count > 0;
}
}
diff --git a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs
index 541a8e93..cda82bef 100644
--- a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs
+++ b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs
@@ -59,9 +59,11 @@
var firstDelegate = pipelineBuilder.Build();
- //inject first delegate into first piece of asp.net middleware..maybe not like this
- //then because we are updating the http context in ocelot it comes out correct for
- //rest of asp.net..
+ /*
+ inject first delegate into first piece of asp.net middleware..maybe not like this
+ then because we are updating the http context in ocelot it comes out correct for
+ rest of asp.net..
+ */
builder.Use(async (context, task) =>
{
diff --git a/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs b/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs
index 3cfded9b..d58b8b09 100644
--- a/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs
+++ b/src/Ocelot/Middleware/OcelotPipelineConfiguration.cs
@@ -37,7 +37,6 @@
///
/// This allows the user to implement there own query string manipulation logic
///
- public Func, Task> PreQueryStringBuilderMiddleware { get; set; }
-
+ public Func, Task> PreQueryStringBuilderMiddleware { get; set; }
}
}
diff --git a/src/Ocelot/Ocelot.csproj b/src/Ocelot/Ocelot.csproj
index 62552bed..89ada54d 100644
--- a/src/Ocelot/Ocelot.csproj
+++ b/src/Ocelot/Ocelot.csproj
@@ -17,6 +17,7 @@
True
false
Tom Pallister
+ ..\..\codeanalysis.ruleset
full
@@ -35,6 +36,9 @@
+
+ all
+
diff --git a/src/Ocelot/Raft/ExcludeFromCoverage.cs b/src/Ocelot/Raft/ExcludeFromCoverageAttribute.cs
similarity index 97%
rename from src/Ocelot/Raft/ExcludeFromCoverage.cs
rename to src/Ocelot/Raft/ExcludeFromCoverageAttribute.cs
index 70d42167..9ea5544a 100644
--- a/src/Ocelot/Raft/ExcludeFromCoverage.cs
+++ b/src/Ocelot/Raft/ExcludeFromCoverageAttribute.cs
@@ -1,7 +1,7 @@
-using System;
-
-namespace Ocelot.Raft
-{
- [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property)]
- public class ExcludeFromCoverageAttribute : Attribute{}
+using System;
+
+namespace Ocelot.Raft
+{
+ [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property)]
+ public class ExcludeFromCoverageAttribute : Attribute{}
}
\ No newline at end of file
diff --git a/src/Ocelot/Raft/FakeCommand.cs b/src/Ocelot/Raft/FakeCommand.cs
index 795ca7a5..45dd1045 100644
--- a/src/Ocelot/Raft/FakeCommand.cs
+++ b/src/Ocelot/Raft/FakeCommand.cs
@@ -8,8 +8,8 @@ namespace Ocelot.Raft
public FakeCommand(string value)
{
this.Value = value;
-
}
+
public string Value { get; private set; }
}
}
diff --git a/src/Ocelot/Raft/FilePeersProvider.cs b/src/Ocelot/Raft/FilePeersProvider.cs
index aeca7b2c..d31dc2ca 100644
--- a/src/Ocelot/Raft/FilePeersProvider.cs
+++ b/src/Ocelot/Raft/FilePeersProvider.cs
@@ -27,16 +27,19 @@ namespace Ocelot.Raft
_finder = finder;
_options = options;
_peers = new List();
+
//todo - sort out async nonsense..
var config = _provider.Get().GetAwaiter().GetResult();
foreach (var item in _options.Value.Peers)
{
var httpClient = new HttpClient();
+
//todo what if this errors?
var httpPeer = new HttpPeer(item.HostAndPort, httpClient, _finder, config.Data, _identityServerConfig);
_peers.Add(httpPeer);
}
}
+
public List Get()
{
return _peers;
diff --git a/src/Ocelot/Raft/HttpPeer.cs b/src/Ocelot/Raft/HttpPeer.cs
index ef76a583..cd5ceef5 100644
--- a/src/Ocelot/Raft/HttpPeer.cs
+++ b/src/Ocelot/Raft/HttpPeer.cs
@@ -28,7 +28,7 @@ namespace Ocelot.Raft
{
_identityServerConfiguration = identityServerConfiguration;
_config = config;
- Id = hostAndPort;
+ Id = hostAndPort;
_hostAndPort = hostAndPort;
_httpClient = httpClient;
_jsonSerializerSettings = new JsonSerializerSettings() {
@@ -68,6 +68,7 @@ namespace Ocelot.Raft
{
SetToken();
}
+
var json = JsonConvert.SerializeObject(appendEntries, _jsonSerializerSettings);
var content = new StringContent(json);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
@@ -88,12 +89,14 @@ namespace Ocelot.Raft
}
}
- public Response Request(T command) where T : ICommand
+ public Response Request(T command)
+ where T : ICommand
{
if(_token == null)
{
SetToken();
}
+
var json = JsonConvert.SerializeObject(command, _jsonSerializerSettings);
var content = new StringContent(json);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
diff --git a/src/Ocelot/Raft/OcelotFiniteStateMachine.cs b/src/Ocelot/Raft/OcelotFiniteStateMachine.cs
index f63695f2..feecd7d7 100644
--- a/src/Ocelot/Raft/OcelotFiniteStateMachine.cs
+++ b/src/Ocelot/Raft/OcelotFiniteStateMachine.cs
@@ -19,7 +19,7 @@ namespace Ocelot.Raft
//todo - handle an error
//hack it to just cast as at the moment we know this is the only command :P
var hack = (UpdateFileConfiguration)log.CommandData;
- _setter.Set(hack.Configuration).GetAwaiter().GetResult();;
+ _setter.Set(hack.Configuration).GetAwaiter().GetResult();
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Raft/SqlLiteLog.cs b/src/Ocelot/Raft/SqlLiteLog.cs
index 098d9c06..aff04bf5 100644
--- a/src/Ocelot/Raft/SqlLiteLog.cs
+++ b/src/Ocelot/Raft/SqlLiteLog.cs
@@ -24,6 +24,7 @@ namespace Ocelot.Raft
FileStream fs = File.Create(_path);
fs.Dispose();
}
+
using(var connection = new SqliteConnection($"Data Source={_path};"))
{
connection.Open();
@@ -59,6 +60,7 @@ namespace Ocelot.Raft
}
}
}
+
return result;
}
}
@@ -88,6 +90,7 @@ namespace Ocelot.Raft
}
}
}
+
return result;
}
}
@@ -113,6 +116,7 @@ namespace Ocelot.Raft
}
}
}
+
return result;
}
}
@@ -129,6 +133,7 @@ namespace Ocelot.Raft
TypeNameHandling = TypeNameHandling.All
};
var data = JsonConvert.SerializeObject(log, jsonSerializerSettings);
+
//todo - sql injection dont copy this..
var sql = $"insert into logs (data) values ('{data}')";
using(var command = new SqliteCommand(sql, connection))
@@ -153,6 +158,7 @@ namespace Ocelot.Raft
using(var connection = new SqliteConnection($"Data Source={_path};"))
{
connection.Open();
+
//todo - sql injection dont copy this..
var sql = $"select data from logs where id = {index};";
using(var command = new SqliteCommand(sql, connection))
@@ -183,6 +189,7 @@ namespace Ocelot.Raft
using(var connection = new SqliteConnection($"Data Source={_path};"))
{
connection.Open();
+
//todo - sql injection dont copy this..
var sql = $"select data from logs where id = {index}";
using(var command = new SqliteCommand(sql, connection))
@@ -207,6 +214,7 @@ namespace Ocelot.Raft
using(var connection = new SqliteConnection($"Data Source={_path};"))
{
connection.Open();
+
//todo - sql injection dont copy this..
var sql = $"select id, data from logs where id >= {index}";
using(var command = new SqliteCommand(sql, connection))
@@ -222,15 +230,13 @@ namespace Ocelot.Raft
};
var log = JsonConvert.DeserializeObject(data, jsonSerializerSettings);
logsToReturn.Add((id, log));
-
}
}
}
}
return logsToReturn;
- }
-
+ }
}
public long GetTermAtIndex(int index)
@@ -241,6 +247,7 @@ namespace Ocelot.Raft
using(var connection = new SqliteConnection($"Data Source={_path};"))
{
connection.Open();
+
//todo - sql injection dont copy this..
var sql = $"select data from logs where id = {index}";
using(var command = new SqliteCommand(sql, connection))
@@ -256,9 +263,11 @@ namespace Ocelot.Raft
}
}
}
+
return result;
}
}
+
public void Remove(int indexOfCommand)
{
lock(_lock)
@@ -266,6 +275,7 @@ namespace Ocelot.Raft
using(var connection = new SqliteConnection($"Data Source={_path};"))
{
connection.Open();
+
//todo - sql injection dont copy this..
var deleteSql = $"delete from logs where id >= {indexOfCommand};";
using(var deleteCommand = new SqliteCommand(deleteSql, connection))
@@ -276,4 +286,4 @@ namespace Ocelot.Raft
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs b/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs
index 0415489c..65a04504 100644
--- a/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs
+++ b/src/Ocelot/RateLimit/ClientRateLimitProcessor.cs
@@ -7,7 +7,6 @@ using System.Threading.Tasks;
namespace Ocelot.RateLimit
{
-
public class ClientRateLimitProcessor
{
private readonly IRateLimitCounterHandler _counterHandler;
@@ -24,7 +23,6 @@ namespace Ocelot.RateLimit
return _core.ProcessRequest(requestIdentity, option);
}
-
public int RetryAfterFrom(DateTime timestamp, RateLimitRule rule)
{
return _core.RetryAfterFrom(timestamp, rule);
@@ -39,7 +37,5 @@ namespace Ocelot.RateLimit
{
return _core.ConvertToTimeSpan(timeSpan);
}
-
}
-
}
diff --git a/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs b/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs
index ddcda184..91f933b7 100644
--- a/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs
+++ b/src/Ocelot/RateLimit/DistributedCacheRateLimitCounterHanlder.cs
@@ -34,6 +34,7 @@ namespace Ocelot.RateLimit
{
return JsonConvert.DeserializeObject(stored);
}
+
return null;
}
diff --git a/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs b/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs
index 064ec54b..4ceb91f8 100644
--- a/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs
+++ b/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs
@@ -31,6 +31,7 @@ namespace Ocelot.RateLimit.Middleware
public async Task Invoke(DownstreamContext context)
{
var options = context.DownstreamReRoute.RateLimitOptions;
+
// check if rate limiting is enabled
if (!context.DownstreamReRoute.EnableEndpointEndpointRateLimiting)
{
@@ -38,6 +39,7 @@ namespace Ocelot.RateLimit.Middleware
await _next.Invoke(context);
return;
}
+
// compute identity from request
var identity = SetIdentity(context.HttpContext, options);
@@ -65,13 +67,14 @@ namespace Ocelot.RateLimit.Middleware
LogBlockedRequest(context.HttpContext, identity, counter, rule, context.DownstreamReRoute);
var retrystring = retryAfter.ToString(System.Globalization.CultureInfo.InvariantCulture);
+
// break execution
await ReturnQuotaExceededResponse(context.HttpContext, options, retrystring);
return;
}
-
}
+
//set X-Rate-Limit headers for the longest period
if (!options.DisableRateLimitHeaders)
{
@@ -103,6 +106,7 @@ namespace Ocelot.RateLimit.Middleware
{
return true;
}
+
return false;
}
@@ -134,8 +138,5 @@ namespace Ocelot.RateLimit.Middleware
return Task.CompletedTask;
}
-
}
-
}
-
diff --git a/src/Ocelot/RateLimit/RateLimitCore.cs b/src/Ocelot/RateLimit/RateLimitCore.cs
index c3455682..82124c85 100644
--- a/src/Ocelot/RateLimit/RateLimitCore.cs
+++ b/src/Ocelot/RateLimit/RateLimitCore.cs
@@ -38,6 +38,7 @@ namespace Ocelot.RateLimit
{
// increment request count
var totalRequests = entry.Value.TotalRequests + 1;
+
// deep copy
counter = new RateLimitCounter(entry.Value.Timestamp, totalRequests);
}
@@ -62,6 +63,7 @@ namespace Ocelot.RateLimit
var expirationTime = ConvertToTimeSpan(rule.Period);
_counterHandler.Set(counterId, counter, expirationTime);
}
+
return counter;
}
@@ -69,6 +71,7 @@ namespace Ocelot.RateLimit
{
var counterId = ComputeCounterKey(requestIdentity, option);
var rule = option.RateLimitRule;
+
// stores: id (string) - timestamp (datetime) - total_requests (long)
_counterHandler.Set(counterId, counter, expirationTime);
}
@@ -92,7 +95,6 @@ namespace Ocelot.RateLimit
rule.Period,
rule.Limit.ToString(),
(DateTime.UtcNow + ConvertToTimeSpan(rule.Period)).ToUniversalTime().ToString("o", DateTimeFormatInfo.InvariantInfo));
-
}
return headers;
@@ -141,7 +143,6 @@ namespace Ocelot.RateLimit
default:
throw new FormatException($"{timeSpan} can't be converted to TimeSpan, unknown type {type}");
}
- }
-
+ }
}
}
diff --git a/src/Ocelot/Request/Mapper/RequestMapper.cs b/src/Ocelot/Request/Mapper/RequestMapper.cs
index a6f22d6d..9af0d08e 100644
--- a/src/Ocelot/Request/Mapper/RequestMapper.cs
+++ b/src/Ocelot/Request/Mapper/RequestMapper.cs
@@ -92,4 +92,3 @@
}
}
}
-
diff --git a/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs b/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs
index 0b146b27..32ee6c68 100644
--- a/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs
+++ b/src/Ocelot/RequestId/Middleware/ReRouteRequestIdMiddleware.cs
@@ -18,7 +18,6 @@ namespace Ocelot.RequestId.Middleware
private readonly IOcelotLogger _logger;
private readonly IRequestScopedDataRepository _requestScopedDataRepository;
-
public ReRouteRequestIdMiddleware(OcelotRequestDelegate next,
IOcelotLoggerFactory loggerFactory,
IRequestScopedDataRepository requestScopedDataRepository)
diff --git a/src/Ocelot/Requester/HttpClientHttpRequester.cs b/src/Ocelot/Requester/HttpClientHttpRequester.cs
index a531d9b9..de9ea1c6 100644
--- a/src/Ocelot/Requester/HttpClientHttpRequester.cs
+++ b/src/Ocelot/Requester/HttpClientHttpRequester.cs
@@ -55,7 +55,6 @@ namespace Ocelot.Requester
{
_cacheHandlers.Set(cacheKey, httpClient, TimeSpan.FromHours(24));
}
-
}
private IHttpClient GetHttpClient(string cacheKey, IHttpClientBuilder builder, DownstreamContext request)
diff --git a/src/Ocelot/Requester/ITracingHandler.cs b/src/Ocelot/Requester/ITracingHandler.cs
new file mode 100644
index 00000000..87593303
--- /dev/null
+++ b/src/Ocelot/Requester/ITracingHandler.cs
@@ -0,0 +1,6 @@
+namespace Ocelot.Requester
+{
+ public interface ITracingHandler
+ {
+ }
+}
diff --git a/src/Ocelot/Requester/MemoryHttpClientCache.cs b/src/Ocelot/Requester/MemoryHttpClientCache.cs
index 3ce1716b..e37a46a3 100644
--- a/src/Ocelot/Requester/MemoryHttpClientCache.cs
+++ b/src/Ocelot/Requester/MemoryHttpClientCache.cs
@@ -41,6 +41,7 @@ namespace Ocelot.Requester
{
connectionQueue.TryDequeue(out client);
}
+
return client;
}
diff --git a/src/Ocelot/Requester/OcelotHttpTracingHandler.cs b/src/Ocelot/Requester/OcelotHttpTracingHandler.cs
index e2658c7f..33bd4caf 100644
--- a/src/Ocelot/Requester/OcelotHttpTracingHandler.cs
+++ b/src/Ocelot/Requester/OcelotHttpTracingHandler.cs
@@ -8,10 +8,6 @@ using Butterfly.OpenTracing;
namespace Ocelot.Requester
{
- public interface ITracingHandler
- {
- }
-
public class OcelotHttpTracingHandler : DelegatingHandler, ITracingHandler
{
private readonly IServiceTracer _tracer;
@@ -35,7 +31,7 @@ namespace Ocelot.Requester
{
request.Headers.Remove(prefix_spanId);
request.Headers.TryAddWithoutValidation(prefix_spanId, span.SpanContext.SpanId);
- };
+ }
span.Tags.Client().Component("HttpClient")
.HttpMethod(request.Method.Method)
@@ -51,7 +47,7 @@ namespace Ocelot.Requester
if (!c.Contains(k))
{
c.Add(k, v);
- };
+ }
});
span.Log(LogField.CreateNew().ClientSend());
diff --git a/src/Ocelot/Responder/HttpContextResponder.cs b/src/Ocelot/Responder/HttpContextResponder.cs
index fbfbc6c2..7bc55d94 100644
--- a/src/Ocelot/Responder/HttpContextResponder.cs
+++ b/src/Ocelot/Responder/HttpContextResponder.cs
@@ -50,7 +50,6 @@ namespace Ocelot.Responder
httpContext.Response.StatusCode = (int)response.StatusCode;
return Task.CompletedTask;
-
}, context);
using (Stream stream = new MemoryStream(content))
diff --git a/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs b/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs
index bac062f8..4bfbad7a 100644
--- a/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs
+++ b/src/Ocelot/Responder/Middleware/ResponderMiddleware.cs
@@ -29,7 +29,6 @@ namespace Ocelot.Responder.Middleware
_responder = responder;
_codeMapper = codeMapper;
_logger = loggerFactory.CreateLogger();
-
}
public async Task Invoke(DownstreamContext context)
diff --git a/src/Ocelot/Responses/ErrorResponse.cs b/src/Ocelot/Responses/ErrorResponse.cs
index 28cd3f02..7a6688e7 100644
--- a/src/Ocelot/Responses/ErrorResponse.cs
+++ b/src/Ocelot/Responses/ErrorResponse.cs
@@ -8,8 +8,9 @@ namespace Ocelot.Responses
public ErrorResponse(Error error) : base(new List{error})
{
}
+
public ErrorResponse(List errors) : base(errors)
{
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Responses/ErrorResponseGeneric.cs b/src/Ocelot/Responses/ErrorResponseGeneric.cs
index 837c2e5d..f57de97f 100644
--- a/src/Ocelot/Responses/ErrorResponseGeneric.cs
+++ b/src/Ocelot/Responses/ErrorResponseGeneric.cs
@@ -3,16 +3,18 @@ using Ocelot.Errors;
namespace Ocelot.Responses
{
+#pragma warning disable SA1649 // File name must match first type name
public class ErrorResponse : Response
+#pragma warning restore SA1649 // File name must match first type name
{
public ErrorResponse(Error error)
: base(new List {error})
- {
-
+ {
}
+
public ErrorResponse(List errors)
: base(errors)
{
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Responses/OkResponseGeneric.cs b/src/Ocelot/Responses/OkResponseGeneric.cs
index 7445d2d9..73fcf1e2 100644
--- a/src/Ocelot/Responses/OkResponseGeneric.cs
+++ b/src/Ocelot/Responses/OkResponseGeneric.cs
@@ -1,9 +1,11 @@
namespace Ocelot.Responses
{
+#pragma warning disable SA1649 // File name must match first type name
public class OkResponse : Response
+#pragma warning restore SA1649 // File name must match first type name
{
public OkResponse(T data) : base(data)
{
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Responses/ResponseGeneric.cs b/src/Ocelot/Responses/ResponseGeneric.cs
index 479dd08d..0b2514e9 100644
--- a/src/Ocelot/Responses/ResponseGeneric.cs
+++ b/src/Ocelot/Responses/ResponseGeneric.cs
@@ -3,7 +3,9 @@ using Ocelot.Errors;
namespace Ocelot.Responses
{
+#pragma warning disable SA1649 // File name must match first type name
public abstract class Response : Response
+#pragma warning restore SA1649 // File name must match first type name
{
protected Response(T data)
{
@@ -14,7 +16,6 @@ namespace Ocelot.Responses
{
}
- public T Data { get; private set; }
-
+ public T Data { get; private set; }
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs b/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs
index 0e75cb1a..86b28a72 100644
--- a/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs
+++ b/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs
@@ -14,11 +14,11 @@ namespace Ocelot.ServiceDiscovery
_factory = factory;
}
- public IServiceDiscoveryProvider Get(ServiceProviderConfiguration serviceConfig, DownstreamReRoute reRoute)
+ public IServiceDiscoveryProvider Get(ServiceProviderConfiguration serviceConfig, DownstreamReRoute reRoute)
{
if (reRoute.UseServiceDiscovery)
{
- return GetServiceDiscoveryProvider(reRoute.ServiceName, serviceConfig.ServiceProviderHost, serviceConfig.ServiceProviderPort);
+ return GetServiceDiscoveryProvider(serviceConfig, reRoute.ServiceName);
}
var services = new List();
@@ -33,9 +33,15 @@ namespace Ocelot.ServiceDiscovery
return new ConfigurationServiceProvider(services);
}
- private IServiceDiscoveryProvider GetServiceDiscoveryProvider(string keyOfServiceInConsul, string providerHostName, int providerPort)
+ private IServiceDiscoveryProvider GetServiceDiscoveryProvider(ServiceProviderConfiguration serviceConfig, string serviceName)
{
- var consulRegistryConfiguration = new ConsulRegistryConfiguration(providerHostName, providerPort, keyOfServiceInConsul);
+ if (serviceConfig.Type == "ServiceFabric")
+ {
+ var config = new ServiceFabricConfiguration(serviceConfig.Host, serviceConfig.Port, serviceName);
+ return new ServiceFabricServiceDiscoveryProvider(config);
+ }
+
+ var consulRegistryConfiguration = new ConsulRegistryConfiguration(serviceConfig.Host, serviceConfig.Port, serviceName);
return new ConsulServiceDiscoveryProvider(consulRegistryConfiguration, _factory);
}
}
diff --git a/src/Ocelot/ServiceDiscovery/ServiceFabricConfiguration.cs b/src/Ocelot/ServiceDiscovery/ServiceFabricConfiguration.cs
new file mode 100644
index 00000000..7522a1e0
--- /dev/null
+++ b/src/Ocelot/ServiceDiscovery/ServiceFabricConfiguration.cs
@@ -0,0 +1,16 @@
+namespace Ocelot.ServiceDiscovery
+{
+ public class ServiceFabricConfiguration
+ {
+ public ServiceFabricConfiguration(string hostName, int port, string serviceName)
+ {
+ HostName = hostName;
+ Port = port;
+ ServiceName = serviceName;
+ }
+
+ public string ServiceName { get; private set; }
+ public string HostName { get; private set; }
+ public int Port { get; private set; }
+ }
+}
diff --git a/src/Ocelot/ServiceDiscovery/ServiceFabricServiceDiscoveryProvider.cs b/src/Ocelot/ServiceDiscovery/ServiceFabricServiceDiscoveryProvider.cs
new file mode 100644
index 00000000..28f9bb65
--- /dev/null
+++ b/src/Ocelot/ServiceDiscovery/ServiceFabricServiceDiscoveryProvider.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Ocelot.Values;
+
+namespace Ocelot.ServiceDiscovery
+{
+ public class ServiceFabricServiceDiscoveryProvider : IServiceDiscoveryProvider
+ {
+ private readonly ServiceFabricConfiguration _configuration;
+
+ public ServiceFabricServiceDiscoveryProvider(ServiceFabricConfiguration configuration)
+ {
+ _configuration = configuration;
+ }
+
+ public async Task> Get()
+ {
+ return new List
+ {
+ new Service(_configuration.ServiceName,
+ new ServiceHostAndPort(_configuration.HostName, _configuration.Port),
+ "doesnt matter with service fabric",
+ "doesnt matter with service fabric",
+ new List())
+ };
+ }
+ }
+}
diff --git a/src/Ocelot/Values/Service.cs b/src/Ocelot/Values/Service.cs
index 1acb26e6..abf5449b 100644
--- a/src/Ocelot/Values/Service.cs
+++ b/src/Ocelot/Values/Service.cs
@@ -16,6 +16,7 @@ namespace Ocelot.Values
Version = version;
Tags = tags;
}
+
public string Id { get; private set; }
public string Name { get; private set; }
diff --git a/test/Ocelot.AcceptanceTests/AggregateTests.cs b/test/Ocelot.AcceptanceTests/AggregateTests.cs
index c0ed2de2..3944adfc 100644
--- a/test/Ocelot.AcceptanceTests/AggregateTests.cs
+++ b/test/Ocelot.AcceptanceTests/AggregateTests.cs
@@ -15,7 +15,6 @@ namespace Ocelot.AcceptanceTests
public class AggregateTests : IDisposable
{
private IWebHost _serviceOneBuilder;
- private IWebHost _serviceTwoBuilder;
private readonly Steps _steps;
private string _downstreamPathOne;
private string _downstreamPathTwo;
@@ -229,7 +228,6 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
-
[Fact]
public void should_be_thread_safe()
{
@@ -365,7 +363,6 @@ namespace Ocelot.AcceptanceTests
public void Dispose()
{
_serviceOneBuilder?.Dispose();
- _serviceTwoBuilder?.Dispose();
_steps.Dispose();
}
}
diff --git a/test/Ocelot.AcceptanceTests/AuthorisationTests.cs b/test/Ocelot.AcceptanceTests/AuthorisationTests.cs
index aaa4faff..06fee4ef 100644
--- a/test/Ocelot.AcceptanceTests/AuthorisationTests.cs
+++ b/test/Ocelot.AcceptanceTests/AuthorisationTests.cs
@@ -177,7 +177,7 @@ namespace Ocelot.AcceptanceTests
AuthenticationOptions = new FileAuthenticationOptions
{
AuthenticationProviderKey = "Test",
- AllowedScopes = new List{ "api", "api.readOnly", "openid", "offline_access" },
+ AllowedScopes = new List{ "api", "api.readOnly", "openid", "offline_access" },
},
}
}
@@ -218,7 +218,7 @@ namespace Ocelot.AcceptanceTests
AuthenticationOptions = new FileAuthenticationOptions
{
AuthenticationProviderKey = "Test",
- AllowedScopes = new List{ "api", "openid", "offline_access" },
+ AllowedScopes = new List{ "api", "openid", "offline_access" },
},
}
}
@@ -356,7 +356,6 @@ namespace Ocelot.AcceptanceTests
"CustomerId", "LocationId", "UserType", "UserId"
}
},
-
})
.AddInMemoryClients(new List
{
@@ -437,7 +436,6 @@ namespace Ocelot.AcceptanceTests
"CustomerId", "LocationId", "UserType", "UserId", "Role"
}
},
-
})
.AddInMemoryClients(new List
{
@@ -450,7 +448,6 @@ namespace Ocelot.AcceptanceTests
AccessTokenType = tokenType,
Enabled = true,
RequireClientSecret = false,
-
}
})
.AddTestUsers(users);
diff --git a/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs b/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs
index 84346985..a7411ebe 100644
--- a/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs
+++ b/test/Ocelot.AcceptanceTests/ButterflyTracingTests.cs
@@ -52,7 +52,7 @@ namespace Ocelot.AcceptanceTests
UpstreamHttpMethod = new List { "Get" },
HttpHandlerOptions = new FileHttpHandlerOptions
{
- UseTracing = true
+ UseTracing = true
},
QoSOptions = new FileQoSOptions
{
@@ -77,7 +77,7 @@ namespace Ocelot.AcceptanceTests
UpstreamHttpMethod = new List { "Get" },
HttpHandlerOptions = new FileHttpHandlerOptions
{
- UseTracing = true
+ UseTracing = true
},
QoSOptions = new FileQoSOptions
{
@@ -104,7 +104,6 @@ namespace Ocelot.AcceptanceTests
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Tom"))
.BDDfy();
-
var commandOnAllStateMachines = WaitFor(5000).Until(() => _butterflyCalled == 4);
commandOnAllStateMachines.ShouldBeTrue();
diff --git a/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs b/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs
index a4dfcac6..e555ade7 100644
--- a/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs
+++ b/test/Ocelot.AcceptanceTests/CannotStartOcelotTests.cs
@@ -1,19 +1,14 @@
-
using System;
using System.Collections.Generic;
-using Microsoft.AspNetCore.Hosting;
using Ocelot.Configuration.File;
using Shouldly;
-using TestStack.BDDfy;
using Xunit;
namespace Ocelot.AcceptanceTests
{
public class CannotStartOcelotTests : IDisposable
{
- private IWebHost _builder;
private readonly Steps _steps;
- private string _downstreamPath;
public CannotStartOcelotTests()
{
@@ -51,8 +46,7 @@ namespace Ocelot.AcceptanceTests
public void Dispose()
{
- _builder?.Dispose();
_steps.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs b/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs
index b8c1a59e..f73a360e 100644
--- a/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs
+++ b/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs
@@ -156,7 +156,7 @@ namespace Ocelot.AcceptanceTests
{
new ApiResource
{
- Name = apiName,
+ Name = apiName,
Description = "My API",
Enabled = true,
DisplayName = "test",
diff --git a/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs b/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs
index 11ec83b1..dc9d5eef 100644
--- a/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs
+++ b/test/Ocelot.AcceptanceTests/ClientRateLimitTests.cs
@@ -20,13 +20,11 @@ namespace Ocelot.AcceptanceTests
private readonly Steps _steps;
private int _counterOne;
-
public ClientRateLimitTests()
{
_steps = new Steps();
}
-
public void Dispose()
{
_builder?.Dispose();
@@ -56,7 +54,7 @@ namespace Ocelot.AcceptanceTests
UpstreamHttpMethod = new List { "Get" },
RequestIdKey = _steps.RequestIdKey,
- RateLimitOptions = new FileRateLimitRule()
+ RateLimitOptions = new FileRateLimitRule()
{
EnableRateLimiting = true,
ClientWhitelist = new List(),
@@ -75,7 +73,6 @@ namespace Ocelot.AcceptanceTests
QuotaExceededMessage = "",
RateLimitCounterPrefix = "",
HttpStatusCode = 428
-
},
RequestIdKey ="oceclientrequest"
}
@@ -93,7 +90,6 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
-
[Fact]
public void should_call_middleware_withWhitelistClient()
{
@@ -117,7 +113,7 @@ namespace Ocelot.AcceptanceTests
UpstreamHttpMethod = new List { "Get" },
RequestIdKey = _steps.RequestIdKey,
- RateLimitOptions = new FileRateLimitRule()
+ RateLimitOptions = new FileRateLimitRule()
{
EnableRateLimiting = true,
ClientWhitelist = new List() { "ocelotclient1"},
@@ -148,7 +144,6 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
-
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath)
{
_builder = new WebHostBuilder()
@@ -172,7 +167,5 @@ namespace Ocelot.AcceptanceTests
_builder.Start();
}
-
-
}
}
diff --git a/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs b/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs
index db617718..7c9ac239 100644
--- a/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs
+++ b/test/Ocelot.AcceptanceTests/ConfigurationInConsulTests.cs
@@ -175,7 +175,6 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
-
[Fact]
public void should_load_configuration_out_of_consul_if_it_is_changed()
{
@@ -307,8 +306,7 @@ namespace Ocelot.AcceptanceTests
var kvp = new FakeConsulGetResponse(base64);
await context.Response.WriteJsonAsync(new FakeConsulGetResponse[] { kvp });
- }
-
+ }
else if (context.Request.Method.ToLower() == "put" && context.Request.Path.Value == "/v1/kv/OcelotConfiguration")
{
try
diff --git a/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs b/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs
index 0f30ba73..341986fe 100644
--- a/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs
+++ b/test/Ocelot.AcceptanceTests/CustomMiddlewareTests.cs
@@ -25,7 +25,7 @@ namespace Ocelot.AcceptanceTests
public CustomMiddlewareTests()
{
_counter = 0;
- _steps = new Steps();;
+ _steps = new Steps();
_configurationPath = "configuration.json";
}
@@ -286,7 +286,6 @@ namespace Ocelot.AcceptanceTests
.And(x => x.ThenTheCounterIs(1))
.BDDfy();
}
-
[Fact(Skip = "This is just an example to show how you could hook into Ocelot pipeline with your own middleware. At the moment you must use Response.OnCompleted callback and cannot change the response :( I will see if this can be changed one day!")]
public void should_fix_issue_237()
@@ -352,14 +351,13 @@ namespace Ocelot.AcceptanceTests
app.UsePathBase(basePath);
app.Run(context =>
{
-
if(string.IsNullOrEmpty(basePath))
{
context.Response.StatusCode = statusCode;
}
else if(context.Request.Path.Value != basePath)
{
- context.Response.StatusCode = 404;;
+ context.Response.StatusCode = 404;
}
return Task.CompletedTask;
diff --git a/test/Ocelot.AcceptanceTests/HeaderTests.cs b/test/Ocelot.AcceptanceTests/HeaderTests.cs
index e0bd67c8..b5a2711e 100644
--- a/test/Ocelot.AcceptanceTests/HeaderTests.cs
+++ b/test/Ocelot.AcceptanceTests/HeaderTests.cs
@@ -186,7 +186,6 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
-
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string headerKey)
{
_builder = new WebHostBuilder()
diff --git a/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs b/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs
index bb2a43df..c54294cd 100644
--- a/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs
+++ b/test/Ocelot.AcceptanceTests/HttpDelegatingHandlersTests.cs
@@ -70,8 +70,7 @@ namespace Ocelot.AcceptanceTests
}
class FakeHandler : DelegatingHandler
- {
-
+ {
public DateTime TimeCalled { get; private set; }
protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
@@ -111,6 +110,5 @@ namespace Ocelot.AcceptanceTests
_builder.Start();
}
-
}
}
diff --git a/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs b/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs
index a5c5e07c..d67e7e41 100644
--- a/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs
+++ b/test/Ocelot.AcceptanceTests/LoadBalancerTests.cs
@@ -159,8 +159,7 @@ namespace Ocelot.AcceptanceTests
catch (System.Exception exception)
{
await context.Response.WriteAsync(exception.StackTrace);
- }
-
+ }
});
})
.Build();
diff --git a/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj b/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj
index 396eb403..90d5bc64 100644
--- a/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj
+++ b/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj
@@ -1,48 +1,53 @@
-
-
- 0.0.0-dev
- netcoreapp2.0
- 2.0.0
- Ocelot.AcceptanceTests
- Exe
- Ocelot.AcceptanceTests
- true
- osx.10.11-x64;osx.10.12-x64;win7-x64;win10-x64
- false
- false
- false
-
-
-
- PreserveNewest
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+
+ 0.0.0-dev
+ netcoreapp2.0
+ 2.0.0
+ Ocelot.AcceptanceTests
+ Exe
+ Ocelot.AcceptanceTests
+ true
+ osx.10.11-x64;osx.10.12-x64;win7-x64;win10-x64
+ false
+ false
+ false
+ ..\..\codeanalysis.ruleset
+
+
+
+
+ PreserveNewest
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ all
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/Ocelot.AcceptanceTests/QoSTests.cs b/test/Ocelot.AcceptanceTests/QoSTests.cs
index e4f8a026..d11721b8 100644
--- a/test/Ocelot.AcceptanceTests/QoSTests.cs
+++ b/test/Ocelot.AcceptanceTests/QoSTests.cs
@@ -51,8 +51,7 @@ namespace Ocelot.AcceptanceTests
ExceptionsAllowedBeforeBreaking = 1,
TimeoutValue = 500,
DurationOfBreak = 1000
- },
-
+ },
}
}
};
diff --git a/test/Ocelot.AcceptanceTests/RoutingTests.cs b/test/Ocelot.AcceptanceTests/RoutingTests.cs
index ea748a04..0a16e565 100644
--- a/test/Ocelot.AcceptanceTests/RoutingTests.cs
+++ b/test/Ocelot.AcceptanceTests/RoutingTests.cs
@@ -543,7 +543,6 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
-
[Fact]
public void should_return_response_200_with_complex_url_that_starts_with_placeholder()
{
@@ -578,7 +577,6 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
-
[Fact]
public void should_not_add_trailing_slash_to_downstream_url()
{
@@ -834,7 +832,6 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
-
[Fact]
public void should_fix_145()
{
diff --git a/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs b/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs
index 572c7126..97e104c4 100644
--- a/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs
+++ b/test/Ocelot.AcceptanceTests/ServiceDiscoveryTests.cs
@@ -359,8 +359,7 @@ namespace Ocelot.AcceptanceTests
catch (System.Exception exception)
{
await context.Response.WriteAsync(exception.StackTrace);
- }
-
+ }
});
})
.Build();
@@ -406,4 +405,4 @@ namespace Ocelot.AcceptanceTests
_steps.Dispose();
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.AcceptanceTests/ServiceFabricTests.cs b/test/Ocelot.AcceptanceTests/ServiceFabricTests.cs
new file mode 100644
index 00000000..3f79a801
--- /dev/null
+++ b/test/Ocelot.AcceptanceTests/ServiceFabricTests.cs
@@ -0,0 +1,148 @@
+using System.Linq;
+using Microsoft.Extensions.Primitives;
+
+namespace Ocelot.AcceptanceTests
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Net;
+ using Microsoft.AspNetCore.Builder;
+ using Microsoft.AspNetCore.Hosting;
+ using Microsoft.AspNetCore.Http;
+ using Ocelot.Configuration.File;
+ using Shouldly;
+ using TestStack.BDDfy;
+ using Xunit;
+
+ public class ServiceFabricTests : IDisposable
+ {
+ private IWebHost _builder;
+ private readonly Steps _steps;
+ private string _downstreamPath;
+
+ public ServiceFabricTests()
+ {
+ _steps = new Steps();
+ }
+
+ [Fact]
+ public void should_support_service_fabric_naming_and_dns_service_stateless_and_guest()
+ {
+ var configuration = new FileConfiguration
+ {
+ ReRoutes = new List
+ {
+ new FileReRoute
+ {
+ DownstreamPathTemplate = "/api/values",
+ DownstreamScheme = "http",
+ UpstreamPathTemplate = "/EquipmentInterfaces",
+ UpstreamHttpMethod = new List { "Get" },
+ UseServiceDiscovery = true,
+ ServiceName = "OcelotServiceApplication/OcelotApplicationService"
+ }
+ },
+ GlobalConfiguration = new FileGlobalConfiguration
+ {
+ ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
+ {
+ Host = "localhost",
+ Port = 19081,
+ Type = "ServiceFabric"
+ }
+ }
+ };
+
+ this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:19081", "/OcelotServiceApplication/OcelotApplicationService/api/values", 200, "Hello from Laura", "cmd=instance"))
+ .And(x => _steps.GivenThereIsAConfiguration(configuration))
+ .And(x => _steps.GivenOcelotIsRunning())
+ .When(x => _steps.WhenIGetUrlOnTheApiGateway("/EquipmentInterfaces"))
+ .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
+ .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
+ .BDDfy();
+ }
+
+ [Fact]
+ public void should_support_service_fabric_naming_and_dns_service_statefull_and_actors()
+ {
+ var configuration = new FileConfiguration
+ {
+ ReRoutes = new List
+ {
+ new FileReRoute
+ {
+ DownstreamPathTemplate = "/api/values",
+ DownstreamScheme = "http",
+ UpstreamPathTemplate = "/EquipmentInterfaces",
+ UpstreamHttpMethod = new List { "Get" },
+ UseServiceDiscovery = true,
+ ServiceName = "OcelotServiceApplication/OcelotApplicationService"
+ }
+ },
+ GlobalConfiguration = new FileGlobalConfiguration
+ {
+ ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
+ {
+ Host = "localhost",
+ Port = 19081,
+ Type = "ServiceFabric"
+ }
+ }
+ };
+
+ this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:19081", "/OcelotServiceApplication/OcelotApplicationService/api/values", 200, "Hello from Laura", "PartitionKind=test&PartitionKey=1"))
+ .And(x => _steps.GivenThereIsAConfiguration(configuration))
+ .And(x => _steps.GivenOcelotIsRunning())
+ .When(x => _steps.WhenIGetUrlOnTheApiGateway("/EquipmentInterfaces?PartitionKind=test&PartitionKey=1"))
+ .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
+ .And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
+ .BDDfy();
+ }
+
+ private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody, string expectedQueryString)
+ {
+ _builder = new WebHostBuilder()
+ .UseUrls(baseUrl)
+ .UseKestrel()
+ .UseContentRoot(Directory.GetCurrentDirectory())
+ .UseIISIntegration()
+ .Configure(app =>
+ {
+ app.UsePathBase(basePath);
+ app.Run(async context =>
+ {
+ _downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;
+
+ if(_downstreamPath != basePath)
+ {
+ context.Response.StatusCode = statusCode;
+ await context.Response.WriteAsync("downstream path didnt match base path");
+ }
+ else
+ {
+ if (context.Request.QueryString.Value.Contains(expectedQueryString))
+ {
+ context.Response.StatusCode = statusCode;
+ await context.Response.WriteAsync(responseBody);
+ }
+ else
+ {
+ context.Response.StatusCode = statusCode;
+ await context.Response.WriteAsync("downstream path didnt match base path");
+ }
+ }
+ });
+ })
+ .Build();
+
+ _builder.Start();
+ }
+
+ public void Dispose()
+ {
+ _builder?.Dispose();
+ _steps.Dispose();
+ }
+ }
+}
diff --git a/test/Ocelot.AcceptanceTests/Steps.cs b/test/Ocelot.AcceptanceTests/Steps.cs
index 6a6fa3c4..61a01059 100644
--- a/test/Ocelot.AcceptanceTests/Steps.cs
+++ b/test/Ocelot.AcceptanceTests/Steps.cs
@@ -1,7 +1,5 @@
using System;
-using System.Collections.Concurrent;
using System.Collections.Generic;
-using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
@@ -19,15 +17,11 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Ocelot.Configuration.File;
-using Ocelot.Configuration.Repository;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
-using Ocelot.ServiceDiscovery;
using Shouldly;
using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder;
using Ocelot.AcceptanceTests.Caching;
-using Butterfly.Client.AspNetCore;
-using Butterfly.Client.Tracing;
namespace Ocelot.AcceptanceTests
{
@@ -42,11 +36,9 @@ namespace Ocelot.AcceptanceTests
public string RequestIdKey = "OcRequestId";
private readonly Random _random;
private IWebHostBuilder _webHostBuilder;
- private readonly string _baseUrl;
public Steps()
{
- _baseUrl = "http://localhost:5000";
_random = new Random();
}
@@ -144,6 +136,7 @@ namespace Ocelot.AcceptanceTests
_ocelotClient = _ocelotServer.CreateClient();
}
+
/*
public void GivenIHaveAddedXForwardedForHeader(string value)
{
diff --git a/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs b/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs
index 16e123a7..a6a495a1 100644
--- a/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs
+++ b/test/Ocelot.AcceptanceTests/UpstreamHostTests.cs
@@ -58,7 +58,6 @@ namespace Ocelot.AcceptanceTests
.BDDfy();
}
-
[Fact]
public void should_return_response_200_with_simple_url_and_hosts_match_multiple_re_routes()
{
diff --git a/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj b/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj
index 00e25330..8c63914c 100644
--- a/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj
+++ b/test/Ocelot.Benchmarks/Ocelot.Benchmarks.csproj
@@ -11,6 +11,7 @@
false
false
false
+ ..\..\codeanalysis.ruleset
@@ -19,6 +20,9 @@
+
+ all
+
diff --git a/test/Ocelot.Benchmarks/Program.cs b/test/Ocelot.Benchmarks/Program.cs
index 231a816b..56b87404 100644
--- a/test/Ocelot.Benchmarks/Program.cs
+++ b/test/Ocelot.Benchmarks/Program.cs
@@ -8,7 +8,6 @@ namespace Ocelot.Benchmarks
{
var switcher = new BenchmarkSwitcher(new[] {
typeof(UrlPathToUrlPathTemplateMatcherBenchmarks),
-
});
switcher.Run(args);
diff --git a/test/Ocelot.IntegrationTests/AdministrationTests.cs b/test/Ocelot.IntegrationTests/AdministrationTests.cs
index 3b2f6a35..763d642c 100644
--- a/test/Ocelot.IntegrationTests/AdministrationTests.cs
+++ b/test/Ocelot.IntegrationTests/AdministrationTests.cs
@@ -124,7 +124,6 @@ namespace Ocelot.IntegrationTests
{
Host = "127.0.0.1",
}
-
},
ReRoutes = new List()
{
@@ -485,7 +484,6 @@ namespace Ocelot.IntegrationTests
app.UseOcelot().Wait();
});
-
_builderTwo = _webHostBuilderTwo.Build();
_builderTwo.Start();
diff --git a/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj b/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj
index 6e1fdb4b..8dc250b2 100644
--- a/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj
+++ b/test/Ocelot.IntegrationTests/Ocelot.IntegrationTests.csproj
@@ -11,6 +11,7 @@
false
false
false
+ ..\..\codeanalysis.ruleset
@@ -18,29 +19,32 @@
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ all
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/Ocelot.IntegrationTests/RaftTests.cs b/test/Ocelot.IntegrationTests/RaftTests.cs
index e93e9ee4..b8c24d5a 100644
--- a/test/Ocelot.IntegrationTests/RaftTests.cs
+++ b/test/Ocelot.IntegrationTests/RaftTests.cs
@@ -45,6 +45,7 @@ namespace Ocelot.IntegrationTests
_builders = new List();
_threads = new List();
}
+
public void Dispose()
{
foreach (var builder in _builders)
@@ -194,7 +195,6 @@ namespace Ocelot.IntegrationTests
var stopwatch = Stopwatch.StartNew();
while(stopwatch.ElapsedMilliseconds < 10000)
{
-
}
}
@@ -204,10 +204,9 @@ namespace Ocelot.IntegrationTests
var stopwatch = Stopwatch.StartNew();
while(stopwatch.ElapsedMilliseconds < 2000)
{
-
}
- bool CommandCalledOnAllStateMachines()
+ bool CommandCalledOnAllStateMachines()
{
try
{
@@ -225,6 +224,7 @@ namespace Ocelot.IntegrationTests
index.ShouldBe(1);
}
}
+
_httpClientForAssertions.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.AccessToken);
var result = _httpClientForAssertions.GetAsync($"{peer.HostAndPort}/administration/configuration").Result;
var json = result.Content.ReadAsStringAsync().Result;
@@ -248,6 +248,7 @@ namespace Ocelot.IntegrationTests
response.ReRoutes[i].UpstreamPathTemplate.ShouldBe(expecteds.Configuration.ReRoutes[i].UpstreamPathTemplate);
response.ReRoutes[i].UpstreamHttpMethod.ShouldBe(expecteds.Configuration.ReRoutes[i].UpstreamHttpMethod);
}
+
passed++;
}
@@ -384,7 +385,6 @@ namespace Ocelot.IntegrationTests
var stopwatch = Stopwatch.StartNew();
while(stopwatch.ElapsedMilliseconds < 20000)
{
-
}
}
}
diff --git a/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs b/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs
index f8533a04..e61fa63b 100644
--- a/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs
+++ b/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs
@@ -195,6 +195,7 @@ namespace Ocelot.IntegrationTests
result.Result.ShouldBe(result.Random);
}
}
+
public void Dispose()
{
_builder?.Dispose();
@@ -208,7 +209,6 @@ namespace Ocelot.IntegrationTests
{
Result = result;
Random = random;
-
}
public int Result { get; private set; }
diff --git a/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj b/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj
index 7ec84c3d..ed0e2cb8 100644
--- a/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj
+++ b/test/Ocelot.ManualTest/Ocelot.ManualTest.csproj
@@ -9,6 +9,7 @@
Exe
Ocelot.ManualTest
osx.10.11-x64;osx.10.12-x64;win7-x64;win10-x64
+ ..\..\codeanalysis.ruleset
@@ -38,6 +39,9 @@
+
+ all
+
diff --git a/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs b/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs
index 07368127..e5cb64ae 100644
--- a/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs
+++ b/test/Ocelot.UnitTests/Authentication/AuthenticationMiddlewareTests.cs
@@ -6,24 +6,17 @@ namespace Ocelot.UnitTests.Authentication
using System.Collections.Generic;
using System.IO;
using System.Text;
- using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Authentication.Middleware;
using Ocelot.Configuration.Builder;
- using Ocelot.DownstreamRouteFinder;
- using Ocelot.DownstreamRouteFinder.Middleware;
- using Ocelot.DownstreamRouteFinder.UrlMatcher;
using Ocelot.Logging;
- using Ocelot.Responses;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
public class AuthenticationMiddlewareTests
{
- private OkResponse _downstreamRoute;
private AuthenticationMiddleware _middleware;
private Mock _factory;
private Mock _logger;
@@ -49,7 +42,7 @@ namespace Ocelot.UnitTests.Authentication
.BDDfy();
}
- private void WhenICallTheMiddleware()
+ private void WhenICallTheMiddleware()
{
_next = async (context) => {
byte[] byteArray = Encoding.ASCII.GetBytes("The user is authenticated");
@@ -89,7 +82,7 @@ namespace Ocelot.UnitTests.Authentication
{
string text = reader.ReadToEnd();
return text;
- };
+ }
}
}
}
diff --git a/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs b/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs
index 0333268b..e2990864 100644
--- a/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs
+++ b/test/Ocelot.UnitTests/Authorization/ClaimsAuthoriserTests.cs
@@ -28,7 +28,6 @@ namespace Ocelot.UnitTests.Authorization
this.Given(x => x.GivenAClaimsPrincipal(new ClaimsPrincipal(new ClaimsIdentity(new List
{
new Claim("UserType", "registered"),
-
}))))
.And(x => x.GivenARouteClaimsRequirement(new Dictionary
{
diff --git a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareRealCacheTests.cs b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareRealCacheTests.cs
index 4e9ef04d..c0a76b2a 100644
--- a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareRealCacheTests.cs
+++ b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareRealCacheTests.cs
@@ -1,5 +1,4 @@
using Ocelot.Errors;
-using Ocelot.Infrastructure.RequestData;
using Ocelot.Middleware;
namespace Ocelot.UnitTests.Cache
@@ -11,26 +10,19 @@ namespace Ocelot.UnitTests.Cache
using Shouldly;
using System.Collections.Generic;
using System.Net.Http;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Cache;
using Ocelot.Cache.Middleware;
using Ocelot.Configuration;
using Ocelot.Configuration.Builder;
- using Ocelot.DownstreamRouteFinder;
- using Ocelot.DownstreamRouteFinder.UrlMatcher;
using Ocelot.Logging;
- using Ocelot.Responses;
using TestStack.BDDfy;
using Xunit;
- using Ocelot.DownstreamRouteFinder.Middleware;
using Microsoft.AspNetCore.Http;
public class OutputCacheMiddlewareRealCacheTests
{
private IOcelotCache _cacheManager;
- private CachedResponse _response;
private OutputCacheMiddleware _middleware;
private DownstreamContext _downstreamContext;
private OcelotRequestDelegate _next;
diff --git a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs
index 42c1e695..31cc11a8 100644
--- a/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs
+++ b/test/Ocelot.UnitTests/Cache/OutputCacheMiddlewareTests.cs
@@ -110,7 +110,6 @@ namespace Ocelot.UnitTests.Cache
private void GivenThereAreNoErrors()
{
_downstreamContext.Errors = new List();
-
}
private void ThenTheCacheGetIsCalledCorrectly()
diff --git a/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs b/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs
index ac60ee8b..33ff1e06 100644
--- a/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs
+++ b/test/Ocelot.UnitTests/Claims/AddClaimsToRequestTests.cs
@@ -93,7 +93,6 @@ namespace Ocelot.UnitTests.Claims
.BDDfy();
}
-
private void GivenClaimsToThings(List configuration)
{
_claimsToThings = configuration;
@@ -129,7 +128,6 @@ namespace Ocelot.UnitTests.Claims
private void ThenTheResultIsError()
{
-
_result.IsError.ShouldBe(true);
}
diff --git a/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs b/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs
index be266f9e..f6bf052c 100644
--- a/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs
+++ b/test/Ocelot.UnitTests/Claims/ClaimsBuilderMiddlewareTests.cs
@@ -15,12 +15,10 @@ namespace Ocelot.UnitTests.Claims
using Ocelot.Responses;
using TestStack.BDDfy;
using Xunit;
- using Ocelot.DownstreamRouteFinder.Middleware;
public class ClaimsBuilderMiddlewareTests
{
private readonly Mock _addHeaders;
- private Response _downstreamRoute;
private Mock _loggerFactory;
private Mock _logger;
private readonly ClaimsBuilderMiddleware _middleware;
@@ -68,7 +66,6 @@ namespace Ocelot.UnitTests.Claims
_middleware.Invoke(_downstreamContext).GetAwaiter().GetResult();
}
-
private void GivenTheDownStreamRouteIs(DownstreamRoute downstreamRoute)
{
_downstreamContext.TemplatePlaceholderNameAndValues = downstreamRoute.TemplatePlaceholderNameAndValues;
diff --git a/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs
index 656fe5dc..522d853f 100644
--- a/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs
+++ b/test/Ocelot.UnitTests/Configuration/ClaimsToThingCreatorTests.cs
@@ -79,6 +79,7 @@ namespace Ocelot.UnitTests.Configuration
{
_result.Count.ShouldBeGreaterThan(0);
}
+
private void GivenTheFollowingDictionary(Dictionary claimsToThings)
{
_claimsToThings = claimsToThings;
@@ -107,4 +108,4 @@ namespace Ocelot.UnitTests.Configuration
.Verify(x => x.Extract(_claimsToThings.First().Key, _claimsToThings.First().Value), Times.Once);
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.UnitTests/Configuration/ConfigurationFluentValidationTests.cs b/test/Ocelot.UnitTests/Configuration/ConfigurationFluentValidationTests.cs
index e7e56178..d33bb6f4 100644
--- a/test/Ocelot.UnitTests/Configuration/ConfigurationFluentValidationTests.cs
+++ b/test/Ocelot.UnitTests/Configuration/ConfigurationFluentValidationTests.cs
@@ -328,7 +328,7 @@ namespace Ocelot.UnitTests.Configuration
this.Given(x => x.GivenAConfiguration(configuration))
.When(x => x.WhenIValidateTheConfiguration())
.Then(x => x.ThenTheResultIsNotValid())
- .And(x => x.ThenTheErrorMessageAtPositionIs(0, "ReRoutes for aggregateReRoute / either do not exist or do not have correct Key property"))
+ .And(x => x.ThenTheErrorMessageAtPositionIs(0, "ReRoutes for aggregateReRoute / either do not exist or do not have correct ServiceName property"))
.BDDfy();
}
@@ -588,7 +588,8 @@ namespace Ocelot.UnitTests.Configuration
AuthenticationOptions = new FileAuthenticationOptions()
{
AuthenticationProviderKey = "Test"
- } }
+ }
+ }
}
}))
.When(x => x.WhenIValidateTheConfiguration())
@@ -869,7 +870,6 @@ namespace Ocelot.UnitTests.Configuration
.BDDfy();
}
-
[Theory]
[InlineData(null)]
[InlineData("")]
@@ -981,7 +981,8 @@ namespace Ocelot.UnitTests.Configuration
.And(x => x.ThenTheErrorMessageAtPositionIs(0, "When not using service discovery DownstreamHostAndPorts must be set and not empty or Ocelot cannot find your service!"))
.BDDfy();
}
- [Fact]
+
+ [Fact]
public void configuration_is_not_valid_when_host_and_port_is_empty()
{
this.Given(x => x.GivenAConfiguration(new FileConfiguration
@@ -1007,7 +1008,6 @@ namespace Ocelot.UnitTests.Configuration
.BDDfy();
}
-
private void GivenAConfiguration(FileConfiguration fileConfiguration)
{
_fileConfiguration = fileConfiguration;
diff --git a/test/Ocelot.UnitTests/Configuration/ConsulFileConfigurationPollerTests.cs b/test/Ocelot.UnitTests/Configuration/ConsulFileConfigurationPollerTests.cs
index 64104871..4a6faba2 100644
--- a/test/Ocelot.UnitTests/Configuration/ConsulFileConfigurationPollerTests.cs
+++ b/test/Ocelot.UnitTests/Configuration/ConsulFileConfigurationPollerTests.cs
@@ -12,7 +12,6 @@ using Xunit;
using Shouldly;
using static Ocelot.UnitTests.Wait;
-
namespace Ocelot.UnitTests.Configuration
{
public class ConsulFileConfigurationPollerTests : IDisposable
@@ -34,6 +33,7 @@ namespace Ocelot.UnitTests.Configuration
_repo.Setup(x => x.Get()).ReturnsAsync(new OkResponse(_fileConfig));
_poller = new ConsulFileConfigurationPoller(_factory.Object, _repo.Object, _setter.Object);
}
+
public void Dispose()
{
_poller.Dispose();
@@ -49,7 +49,6 @@ namespace Ocelot.UnitTests.Configuration
[Fact]
public void should_call_setter_when_gets_new_config()
{
-
var newConfig = new FileConfiguration {
ReRoutes = new List
{
@@ -84,7 +83,7 @@ namespace Ocelot.UnitTests.Configuration
_setter.Verify(x => x.Set(fileConfig), Times.Once);
return true;
}
- catch(Exception ex)
+ catch(Exception)
{
return false;
}
diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs
index 8bb0ecd2..4de07053 100644
--- a/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs
+++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationCreatorTests.cs
@@ -502,7 +502,6 @@ namespace Ocelot.UnitTests.Configuration
.WithUseServiceDiscovery(false)
.Build();
-
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
{
ReRoutes = new List
@@ -545,7 +544,6 @@ namespace Ocelot.UnitTests.Configuration
.WithUpstreamTemplatePattern(new UpstreamPathTemplate("(?i)/api/products/.*/$", 1))
.Build();
-
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
{
ReRoutes = new List
@@ -823,8 +821,7 @@ namespace Ocelot.UnitTests.Configuration
result.DownstreamReRoute[0].ClaimsToClaims.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToClaims.Count);
result.DownstreamReRoute[0].ClaimsToHeaders.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToHeaders.Count);
result.DownstreamReRoute[0].ClaimsToQueries.Count.ShouldBe(expected.DownstreamReRoute[0].ClaimsToQueries.Count);
- result.DownstreamReRoute[0].RequestIdKey.ShouldBe(expected.DownstreamReRoute[0].RequestIdKey);
-
+ result.DownstreamReRoute[0].RequestIdKey.ShouldBe(expected.DownstreamReRoute[0].RequestIdKey);
}
}
@@ -916,7 +913,6 @@ namespace Ocelot.UnitTests.Configuration
.Setup(x => x.Create(It.IsAny())).Returns(serviceProviderConfiguration);
}
-
private void GivenTheFollowingRegionIsReturned(string region)
{
_regionCreator
diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs
index be3df6cc..506da50c 100644
--- a/test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs
+++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs
@@ -38,8 +38,6 @@ namespace Ocelot.UnitTests.Configuration
.BDDfy();
}
-
-
private void GivenTheConfigurationIs(FileConfiguration fileConfiguration)
{
_fileConfiguration = fileConfiguration;
@@ -59,4 +57,4 @@ namespace Ocelot.UnitTests.Configuration
.Verify(x => x.Get(), Times.Once);
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs
index e74d0067..15dd3729 100644
--- a/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs
+++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs
@@ -111,7 +111,7 @@ namespace Ocelot.UnitTests.Configuration
}
}
- private void GivenTheConfigurationIs(FileConfiguration fileConfiguration)
+ private void GivenTheConfigurationIs(FileConfiguration fileConfiguration)
{
var configurationPath = $"{AppContext.BaseDirectory}/configuration{(string.IsNullOrEmpty(_environmentName) ? string.Empty : ".")}{_environmentName}.json";
diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs
index 60365661..e16148f2 100644
--- a/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs
+++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs
@@ -48,7 +48,6 @@ namespace Ocelot.UnitTests.Configuration
.BDDfy();
}
-
[Fact]
public void should_return_error_if_unable_to_set_file_configuration()
{
@@ -110,4 +109,4 @@ namespace Ocelot.UnitTests.Configuration
.Verify(x => x.AddOrReplace(_configuration.Data), Times.Once);
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs
index 76c3c47f..37ee8957 100644
--- a/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs
+++ b/test/Ocelot.UnitTests/Configuration/HeaderFindAndReplaceCreatorTests.cs
@@ -33,13 +33,11 @@ namespace Ocelot.UnitTests.Configuration
UpstreamHeaderTransform = new Dictionary
{
{"Test", "Test, Chicken"},
-
{"Moop", "o, a"}
},
DownstreamHeaderTransform = new Dictionary
{
{"Pop", "West, East"},
-
{"Bop", "e, r"}
}
};
@@ -86,7 +84,6 @@ namespace Ocelot.UnitTests.Configuration
.BDDfy();
}
-
[Fact]
public void should_use_base_url_partial_placeholder()
{
@@ -155,4 +152,4 @@ namespace Ocelot.UnitTests.Configuration
}
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs
index 3821ef6b..b0b11bfc 100644
--- a/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs
+++ b/test/Ocelot.UnitTests/Configuration/HttpHandlerOptionsCreatorTests.cs
@@ -7,7 +7,6 @@ using Xunit;
namespace Ocelot.UnitTests.Configuration
{
-
public class HttpHandlerOptionsCreatorTests
{
private readonly IHttpHandlerOptionsCreator _httpHandlerOptionsCreator;
diff --git a/test/Ocelot.UnitTests/Configuration/ServiceProviderCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/ServiceProviderCreatorTests.cs
index c0a35696..8b0cc078 100644
--- a/test/Ocelot.UnitTests/Configuration/ServiceProviderCreatorTests.cs
+++ b/test/Ocelot.UnitTests/Configuration/ServiceProviderCreatorTests.cs
@@ -30,13 +30,15 @@ namespace Ocelot.UnitTests.Configuration
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
{
Host = "127.0.0.1",
- Port = 1234
+ Port = 1234,
+ Type = "ServiceFabric"
}
};
var expected = new ServiceProviderConfigurationBuilder()
.WithServiceDiscoveryProviderHost("127.0.0.1")
.WithServiceDiscoveryProviderPort(1234)
+ .WithServiceDiscoveryProviderType("ServiceFabric")
.Build();
this.Given(x => x.GivenTheFollowingReRoute(reRoute))
@@ -63,8 +65,8 @@ namespace Ocelot.UnitTests.Configuration
private void ThenTheConfigIs(ServiceProviderConfiguration expected)
{
- _result.ServiceProviderHost.ShouldBe(expected.ServiceProviderHost);
- _result.ServiceProviderPort.ShouldBe(expected.ServiceProviderPort);
+ _result.Host.ShouldBe(expected.Host);
+ _result.Port.ShouldBe(expected.Port);
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs
index ab7fba4a..9dce0e50 100644
--- a/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs
+++ b/test/Ocelot.UnitTests/Configuration/UpstreamTemplatePatternCreatorTests.cs
@@ -35,7 +35,6 @@ namespace Ocelot.UnitTests.Configuration
.BDDfy();
}
-
[Fact]
public void should_match_forward_slash_or_no_forward_slash_if_template_end_with_forward_slash()
{
@@ -70,7 +69,7 @@ namespace Ocelot.UnitTests.Configuration
[Fact]
public void should_create_template_pattern_that_matches_anything_to_end_of_string()
{
- var fileReRoute = new FileReRoute
+ var fileReRoute = new FileReRoute
{
UpstreamPathTemplate = "/api/products/{productId}",
ReRouteIsCaseSensitive = true
@@ -181,4 +180,4 @@ namespace Ocelot.UnitTests.Configuration
_result.Priority.ShouldBe(v);
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs b/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs
index 0d95f0ea..c0ae8b87 100644
--- a/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs
+++ b/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs
@@ -111,7 +111,6 @@ namespace Ocelot.UnitTests.Controllers
.BDDfy();
}
-
private void ThenTheNodeIsCalledCorrectly()
{
_node.Verify(x => x.Accept(It.IsAny()), Times.Once);
diff --git a/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs b/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs
index 6f256d7f..c2f35990 100644
--- a/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs
+++ b/test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs
@@ -15,7 +15,6 @@ using Ocelot.DependencyInjection;
using Ocelot.Requester;
using Ocelot.UnitTests.Requester;
using Shouldly;
-using System;
using IdentityServer4.AccessTokenValidation;
using TestStack.BDDfy;
using Xunit;
@@ -38,6 +37,7 @@ namespace Ocelot.UnitTests.DependencyInjection
_services.AddSingleton(_configRoot);
_maxRetries = 100;
}
+
private Exception _ex;
[Fact]
@@ -69,7 +69,6 @@ namespace Ocelot.UnitTests.DependencyInjection
.BDDfy();
}
-
[Fact]
public void should_set_up_cache_manager()
{
@@ -102,9 +101,7 @@ namespace Ocelot.UnitTests.DependencyInjection
[Fact]
public void should_set_up_administration_with_identity_server_options()
{
- Action options = o => {
-
- };
+ Action options = o => {};
this.Given(x => WhenISetUpOcelotServices())
.When(x => WhenISetUpAdministration(options))
@@ -152,7 +149,6 @@ namespace Ocelot.UnitTests.DependencyInjection
.BDDfy();
}
-
[Fact]
public void should_set_up_without_passing_in_config()
{
diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs
index b7761c60..cb5c2a67 100644
--- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs
+++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs
@@ -35,7 +35,6 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
_downstreamRouteFinder = new Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder(_mockMatcher.Object, _finder.Object);
}
-
[Fact]
public void should_return_highest_priority_when_first()
{
@@ -182,7 +181,6 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
.BDDfy();
}
-
[Fact]
public void should_not_append_slash_to_upstream_url_path()
{
@@ -598,7 +596,6 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
.BDDfy();
}
-
[Fact]
public void should_return_route_when_host_matches_but_null_host_on_same_path_first()
{
diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs
index afd1b3ae..29bc8fcd 100644
--- a/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs
+++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs
@@ -30,7 +30,6 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
.BDDfy();
}
-
[Fact]
public void can_match_down_stream_url_with_nothing_then_placeholder_no_value_is_blank()
{
@@ -264,4 +263,4 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
_result = _finder.Find(_downstreamUrlPath, _downstreamPathTemplate);
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs b/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs
index ec4829a7..0d678a7b 100644
--- a/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs
+++ b/test/Ocelot.UnitTests/DownstreamUrlCreator/DownstreamUrlCreatorMiddlewareTests.cs
@@ -1,4 +1,5 @@
-using Ocelot.Middleware;
+using Ocelot.Configuration;
+using Ocelot.Middleware;
namespace Ocelot.UnitTests.DownstreamUrlCreator
{
@@ -27,7 +28,6 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator
public class DownstreamUrlCreatorMiddlewareTests
{
private readonly Mock _downstreamUrlTemplateVariableReplacer;
- private readonly Mock _urlBuilder;
private OkResponse _downstreamPath;
private Mock _loggerFactory;
private Mock _logger;
@@ -42,7 +42,6 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator
_logger = new Mock();
_loggerFactory.Setup(x => x.CreateLogger()).Returns(_logger.Object);
_downstreamUrlTemplateVariableReplacer = new Mock();
- _urlBuilder = new Mock();
_downstreamContext.DownstreamRequest = new HttpRequestMessage(HttpMethod.Get, "https://my.url/abc/?q=123");
_next = async context => {
//do nothing
@@ -58,6 +57,9 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator
.WithDownstreamScheme("https")
.Build();
+ var config = new ServiceProviderConfigurationBuilder()
+ .Build();
+
this.Given(x => x.GivenTheDownStreamRouteIs(
new DownstreamRoute(
new List(),
@@ -66,15 +68,141 @@ namespace Ocelot.UnitTests.DownstreamUrlCreator
.WithUpstreamHttpMethod(new List { "Get" })
.Build())))
.And(x => x.GivenTheDownstreamRequestUriIs("http://my.url/abc?q=123"))
+ .And(x => GivenTheServiceProviderConfigIs(config))
.And(x => x.GivenTheUrlReplacerWillReturn("/api/products/1"))
.When(x => x.WhenICallTheMiddleware())
.Then(x => x.ThenTheDownstreamRequestUriIs("https://my.url:80/api/products/1?q=123"))
.BDDfy();
}
+ [Fact]
+ public void should_not_create_service_fabric_url()
+ {
+ var downstreamReRoute = new DownstreamReRouteBuilder()
+ .WithDownstreamPathTemplate("any old string")
+ .WithUpstreamHttpMethod(new List { "Get" })
+ .WithDownstreamScheme("https")
+ .Build();
+
+ var config = new ServiceProviderConfigurationBuilder()
+ .WithServiceDiscoveryProviderType("ServiceFabric")
+ .WithServiceDiscoveryProviderHost("localhost")
+ .WithServiceDiscoveryProviderPort(19081)
+ .Build();
+
+ this.Given(x => x.GivenTheDownStreamRouteIs(
+ new DownstreamRoute(
+ new List(),
+ new ReRouteBuilder()
+ .WithDownstreamReRoute(downstreamReRoute)
+ .WithUpstreamHttpMethod(new List { "Get" })
+ .Build())))
+ .And(x => x.GivenTheDownstreamRequestUriIs("http://my.url/abc?q=123"))
+ .And(x => GivenTheServiceProviderConfigIs(config))
+ .And(x => x.GivenTheUrlReplacerWillReturn("/api/products/1"))
+ .When(x => x.WhenICallTheMiddleware())
+ .Then(x => x.ThenTheDownstreamRequestUriIs("https://my.url:80/api/products/1?q=123"))
+ .BDDfy();
+ }
+
+ [Fact]
+ public void should_create_service_fabric_url()
+ {
+ var downstreamReRoute = new DownstreamReRouteBuilder()
+ .WithDownstreamScheme("http")
+ .WithServiceName("Ocelot/OcelotApp")
+ .WithUseServiceDiscovery(true)
+ .Build();
+
+ var downstreamRoute = new DownstreamRoute(
+ new List(),
+ new ReRouteBuilder()
+ .WithDownstreamReRoute(downstreamReRoute)
+ .Build());
+
+ var config = new ServiceProviderConfigurationBuilder()
+ .WithServiceDiscoveryProviderType("ServiceFabric")
+ .WithServiceDiscoveryProviderHost("localhost")
+ .WithServiceDiscoveryProviderPort(19081)
+ .Build();
+
+ this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
+ .And(x => GivenTheServiceProviderConfigIs(config))
+ .And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:19081"))
+ .And(x => x.GivenTheUrlReplacerWillReturn("/api/products/1"))
+ .When(x => x.WhenICallTheMiddleware())
+ .Then(x => x.ThenTheDownstreamRequestUriIs("http://localhost:19081/Ocelot/OcelotApp/api/products/1?cmd=instance"))
+ .BDDfy();
+ }
+
+ [Fact]
+ public void should_create_service_fabric_url_with_query_string_for_stateless_service()
+ {
+ var downstreamReRoute = new DownstreamReRouteBuilder()
+ .WithDownstreamScheme("http")
+ .WithServiceName("Ocelot/OcelotApp")
+ .WithUseServiceDiscovery(true)
+ .Build();
+
+ var downstreamRoute = new DownstreamRoute(
+ new List(),
+ new ReRouteBuilder()
+ .WithDownstreamReRoute(downstreamReRoute)
+ .Build());
+
+ var config = new ServiceProviderConfigurationBuilder()
+ .WithServiceDiscoveryProviderType("ServiceFabric")
+ .WithServiceDiscoveryProviderHost("localhost")
+ .WithServiceDiscoveryProviderPort(19081)
+ .Build();
+
+ this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
+ .And(x => GivenTheServiceProviderConfigIs(config))
+ .And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:19081?Tom=test&laura=1"))
+ .And(x => x.GivenTheUrlReplacerWillReturn("/api/products/1"))
+ .When(x => x.WhenICallTheMiddleware())
+ .Then(x => x.ThenTheDownstreamRequestUriIs("http://localhost:19081/Ocelot/OcelotApp/api/products/1?Tom=test&laura=1&cmd=instance"))
+ .BDDfy();
+ }
+
+ [Fact]
+ public void should_create_service_fabric_url_with_query_string_for_stateful_service()
+ {
+ var downstreamReRoute = new DownstreamReRouteBuilder()
+ .WithDownstreamScheme("http")
+ .WithServiceName("Ocelot/OcelotApp")
+ .WithUseServiceDiscovery(true)
+ .Build();
+
+ var downstreamRoute = new DownstreamRoute(
+ new List(),
+ new ReRouteBuilder()
+ .WithDownstreamReRoute(downstreamReRoute)
+ .Build());
+
+ var config = new ServiceProviderConfigurationBuilder()
+ .WithServiceDiscoveryProviderType("ServiceFabric")
+ .WithServiceDiscoveryProviderHost("localhost")
+ .WithServiceDiscoveryProviderPort(19081)
+ .Build();
+
+ this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
+ .And(x => GivenTheServiceProviderConfigIs(config))
+ .And(x => x.GivenTheDownstreamRequestUriIs("http://localhost:19081?PartitionKind=test&PartitionKey=1"))
+ .And(x => x.GivenTheUrlReplacerWillReturn("/api/products/1"))
+ .When(x => x.WhenICallTheMiddleware())
+ .Then(x => x.ThenTheDownstreamRequestUriIs("http://localhost:19081/Ocelot/OcelotApp/api/products/1?PartitionKind=test&PartitionKey=1"))
+ .BDDfy();
+ }
+
+ private void GivenTheServiceProviderConfigIs(ServiceProviderConfiguration config)
+ {
+ _downstreamContext.ServiceProviderConfiguration = config;
+ }
+
private void WhenICallTheMiddleware()
{
- _middleware = new DownstreamUrlCreatorMiddleware(_next, _loggerFactory.Object, _downstreamUrlTemplateVariableReplacer.Object, _urlBuilder.Object);
+ _middleware = new DownstreamUrlCreatorMiddleware(_next, _loggerFactory.Object, _downstreamUrlTemplateVariableReplacer.Object);
_middleware.Invoke(_downstreamContext).GetAwaiter().GetResult();
}
diff --git a/test/Ocelot.UnitTests/DownstreamUrlCreator/UrlBuilderTests.cs b/test/Ocelot.UnitTests/DownstreamUrlCreator/UrlBuilderTests.cs
deleted file mode 100644
index 20dfa1a1..00000000
--- a/test/Ocelot.UnitTests/DownstreamUrlCreator/UrlBuilderTests.cs
+++ /dev/null
@@ -1,122 +0,0 @@
-using System;
-using Ocelot.DownstreamUrlCreator;
-using Ocelot.Responses;
-using Ocelot.Values;
-using Shouldly;
-using TestStack.BDDfy;
-using Xunit;
-
-namespace Ocelot.UnitTests.DownstreamUrlCreator
-{
- public class UrlBuilderTests
- {
- private readonly IUrlBuilder _urlBuilder;
- private string _dsPath;
- private string _dsScheme;
- private string _dsHost;
- private int _dsPort;
-
- private Response _result;
-
- public UrlBuilderTests()
- {
- _urlBuilder = new UrlBuilder();
- }
-
- [Fact]
- public void should_return_error_when_downstream_path_is_null()
- {
- this.Given(x => x.GivenADownstreamPath(null))
- .When(x => x.WhenIBuildTheUrl())
- .Then(x => x.ThenThereIsAnErrorOfType())
- .BDDfy();
- }
-
- [Fact]
- public void should_return_error_when_downstream_scheme_is_null()
- {
- this.Given(x => x.GivenADownstreamScheme(null))
- .And(x => x.GivenADownstreamPath("test"))
- .When(x => x.WhenIBuildTheUrl())
- .Then(x => x.ThenThereIsAnErrorOfType())
- .BDDfy();
- }
-
- [Fact]
- public void should_return_error_when_downstream_host_is_null()
- {
- this.Given(x => x.GivenADownstreamScheme(null))
- .And(x => x.GivenADownstreamPath("test"))
- .And(x => x.GivenADownstreamScheme("test"))
- .When(x => x.WhenIBuildTheUrl())
- .Then(x => x.ThenThereIsAnErrorOfType())
- .BDDfy();
- }
-
- [Fact]
- public void should_not_use_port_if_zero()
- {
- this.Given(x => x.GivenADownstreamPath("/api/products/1"))
- .And(x => x.GivenADownstreamScheme("http"))
- .And(x => x.GivenADownstreamHost("127.0.0.1"))
- .And(x => x.GivenADownstreamPort(0))
- .When(x => x.WhenIBuildTheUrl())
- .Then(x => x.ThenTheUrlIsReturned("http://127.0.0.1/api/products/1"))
- .And(x => x.ThenTheUrlIsWellFormed())
- .BDDfy();
- }
-
- [Fact]
- public void should_build_well_formed_uri()
- {
- this.Given(x => x.GivenADownstreamPath("/api/products/1"))
- .And(x => x.GivenADownstreamScheme("http"))
- .And(x => x.GivenADownstreamHost("127.0.0.1"))
- .And(x => x.GivenADownstreamPort(5000))
- .When(x => x.WhenIBuildTheUrl())
- .Then(x => x.ThenTheUrlIsReturned("http://127.0.0.1:5000/api/products/1"))
- .And(x => x.ThenTheUrlIsWellFormed())
- .BDDfy();
- }
-
- private void ThenThereIsAnErrorOfType()
- {
- _result.Errors[0].ShouldBeOfType();
- }
-
- private void GivenADownstreamPath(string dsPath)
- {
- _dsPath = dsPath;
- }
-
- private void GivenADownstreamScheme(string dsScheme)
- {
- _dsScheme = dsScheme;
- }
-
- private void GivenADownstreamHost(string dsHost)
- {
- _dsHost = dsHost;
- }
-
- private void GivenADownstreamPort(int dsPort)
- {
- _dsPort = dsPort;
- }
-
- private void WhenIBuildTheUrl()
- {
- _result = _urlBuilder.Build(_dsPath, _dsScheme, new ServiceHostAndPort(_dsHost, _dsPort));
- }
-
- private void ThenTheUrlIsReturned(string expected)
- {
- _result.Data.Value.ShouldBe(expected);
- }
-
- private void ThenTheUrlIsWellFormed()
- {
- Uri.IsWellFormedUriString(_result.Data.Value, UriKind.Absolute).ShouldBeTrue();
- }
- }
-}
diff --git a/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs b/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs
index c5180f74..89eaaa38 100644
--- a/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs
+++ b/test/Ocelot.UnitTests/Errors/ExceptionHandlerMiddlewareTests.cs
@@ -29,7 +29,6 @@ namespace Ocelot.UnitTests.Errors
private DownstreamContext _downstreamContext;
private OcelotRequestDelegate _next;
-
public ExceptionHandlerMiddlewareTests()
{
_provider = new Mock();
@@ -135,7 +134,7 @@ namespace Ocelot.UnitTests.Errors
private void GivenTheConfigThrows()
{
- var ex = new Exception("outer", new Exception("inner"));
+ var ex = new Exception("outer", new Exception("inner"));
_provider
.Setup(x => x.Get()).ThrowsAsync(ex);
}
@@ -174,7 +173,6 @@ namespace Ocelot.UnitTests.Errors
.Setup(x => x.Get()).ReturnsAsync(response);
}
-
private void GivenAnExceptionWillNotBeThrownDownstream()
{
_shouldThrowAnException = false;
@@ -192,7 +190,6 @@ namespace Ocelot.UnitTests.Errors
private void ThenTheResponseIsError()
{
-
_downstreamContext.HttpContext.Response.StatusCode.ShouldBe(500);
}
diff --git a/test/Ocelot.UnitTests/Headers/AddHeadersToRequestTests.cs b/test/Ocelot.UnitTests/Headers/AddHeadersToRequestTests.cs
index f69c6b9e..0a8290bc 100644
--- a/test/Ocelot.UnitTests/Headers/AddHeadersToRequestTests.cs
+++ b/test/Ocelot.UnitTests/Headers/AddHeadersToRequestTests.cs
@@ -130,7 +130,6 @@ namespace Ocelot.UnitTests.Headers
private void ThenTheResultIsError()
{
-
_result.IsError.ShouldBe(true);
}
diff --git a/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs b/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs
index 90a24eaa..0a69bf89 100644
--- a/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs
+++ b/test/Ocelot.UnitTests/Headers/HttpHeadersTransformationMiddlewareTests.cs
@@ -80,7 +80,6 @@ namespace Ocelot.UnitTests.Headers
_downstreamContext.TemplatePlaceholderNameAndValues = dR.TemplatePlaceholderNameAndValues;
_downstreamContext.DownstreamReRoute = dR.ReRoute.DownstreamReRoute[0];
-
}
private void ThenTheIHttpContextRequestHeaderReplacerIsCalledCorrectly()
diff --git a/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs b/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs
index de8161c9..95ae6e6d 100644
--- a/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs
+++ b/test/Ocelot.UnitTests/Headers/HttpResponseHeaderReplacerTests.cs
@@ -22,6 +22,7 @@ namespace Ocelot.UnitTests.Headers
{
_replacer = new HttpResponseHeaderReplacer();
}
+
[Fact]
public void should_replace_headers()
{
@@ -97,7 +98,6 @@ namespace Ocelot.UnitTests.Headers
.BDDfy();
}
-
[Fact]
public void should_replace_downstream_base_url_with_ocelot_base_url_and_path()
{
@@ -232,4 +232,4 @@ namespace Ocelot.UnitTests.Headers
}
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs b/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs
index df5068d3..c9f66009 100644
--- a/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs
+++ b/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs
@@ -21,13 +21,14 @@ namespace Ocelot.UnitTests.Infrastructure
_httpDataRepository = new HttpDataRepository(_httpContextAccessor);
}
- //TODO - Additional tests -> Type mistmatch aka Add string, request int
- //TODO - Additional tests -> HttpContent null. This should never happen
+ /*
+ TODO - Additional tests -> Type mistmatch aka Add string, request int
+ TODO - Additional tests -> HttpContent null. This should never happen
+ */
[Fact]
public void get_returns_correct_key_from_http_context()
{
-
this.Given(x => x.GivenAHttpContextContaining("key", "string"))
.When(x => x.GetIsCalledWithKey("key"))
.Then(x => x.ThenTheResultIsAnOkResponse("string"))
@@ -83,6 +84,5 @@ namespace Ocelot.UnitTests.Infrastructure
_result.ShouldBeOfType>();
((OkResponse)_result).Data.ShouldBe(resultValue);
}
-
}
}
diff --git a/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs b/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs
index 1d476db3..08f6a46d 100644
--- a/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs
+++ b/test/Ocelot.UnitTests/Infrastructure/ScopesAuthoriserTests.cs
@@ -35,7 +35,6 @@ namespace Ocelot.UnitTests.Infrastructure
.BDDfy();
}
-
[Fact]
public void should_return_ok_if_null_allowed_scopes()
{
@@ -121,4 +120,4 @@ namespace Ocelot.UnitTests.Infrastructure
{
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs
index e372ac4e..687f8f40 100644
--- a/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs
+++ b/test/Ocelot.UnitTests/LoadBalancer/LeastConnectionTests.cs
@@ -91,7 +91,6 @@ namespace Ocelot.UnitTests.LoadBalancer
hostAndPortTwo.Data.DownstreamHost.ShouldBe("127.0.0.2");
_leastConnection.Release(hostAndPortOne.Data);
_leastConnection.Release(hostAndPortTwo.Data);
-
}
private async Task LeaseDelayAndRelease()
diff --git a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs
index f5604ab1..e8808f17 100644
--- a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs
+++ b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerHouseTests.cs
@@ -17,9 +17,7 @@ namespace Ocelot.UnitTests.LoadBalancer
private DownstreamReRoute _reRoute;
private ILoadBalancer _loadBalancer;
private readonly LoadBalancerHouse _loadBalancerHouse;
- private Response _addResult;
private Response _getResult;
- private string _key;
private readonly Mock _factory;
private ServiceProviderConfiguration _serviceProviderConfig;
@@ -116,7 +114,6 @@ namespace Ocelot.UnitTests.LoadBalancer
_factory.Verify(x => x.Get(_reRoute, _serviceProviderConfig), Times.Once);
}
-
private void GivenThereIsALoadBalancer(DownstreamReRoute reRoute, ILoadBalancer loadBalancer)
{
_reRoute = reRoute;
diff --git a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs
index 310c1818..242463a2 100644
--- a/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs
+++ b/test/Ocelot.UnitTests/LoadBalancer/LoadBalancerMiddlewareTests.cs
@@ -4,15 +4,10 @@ namespace Ocelot.UnitTests.LoadBalancer
{
using System.Collections.Generic;
using System.Net.Http;
- using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Configuration;
using Ocelot.Configuration.Builder;
- using Ocelot.Configuration.Provider;
- using Ocelot.DownstreamRouteFinder;
- using Ocelot.DownstreamRouteFinder.Middleware;
using Ocelot.Errors;
using Ocelot.LoadBalancer.LoadBalancers;
using Ocelot.LoadBalancer.Middleware;
@@ -28,7 +23,6 @@ namespace Ocelot.UnitTests.LoadBalancer
private readonly Mock _loadBalancerHouse;
private readonly Mock _loadBalancer;
private ServiceHostAndPort _hostAndPort;
- private OkResponse _downstreamRoute;
private ErrorResponse _getLoadBalancerHouseError;
private ErrorResponse _getHostAndPortError;
private HttpRequestMessage _downstreamRequest;
@@ -188,7 +182,6 @@ namespace Ocelot.UnitTests.LoadBalancer
{
_downstreamContext.IsError.ShouldBeTrue();
_downstreamContext.Errors.ShouldBe(_getHostAndPortError.Errors);
-
}
private void ThenTheDownstreamUrlIsReplacedWith(string expectedUri)
diff --git a/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs b/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs
index 8a0e5670..adef00d5 100644
--- a/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs
+++ b/test/Ocelot.UnitTests/Middleware/MultiplexerTests.cs
@@ -58,7 +58,6 @@ namespace Ocelot.UnitTests.Middleware
private void WhenIMultiplex()
{
_multiplexer.Multiplex(_context, _reRoute, _pipeline).GetAwaiter().GetResult();
-
}
private void ThePipelineIsCalled(int expected)
diff --git a/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs b/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs
index dbb0ae63..988d0b21 100644
--- a/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs
+++ b/test/Ocelot.UnitTests/Middleware/OcelotPiplineBuilderTests.cs
@@ -1,6 +1,5 @@
namespace Ocelot.UnitTests.Middleware
{
- using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Internal;
@@ -17,9 +16,7 @@
public class OcelotPiplineBuilderTests
{
private readonly IServiceCollection _services;
- private IServiceProvider _serviceProvider;
private readonly IConfiguration _configRoot;
- private IOcelotBuilder _ocelotBuilder;
private DownstreamContext _downstreamContext;
private int _counter;
diff --git a/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs b/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs
index b5fabaee..27d1b7e0 100644
--- a/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs
+++ b/test/Ocelot.UnitTests/Middleware/SimpleJsonResponseAggregatorTests.cs
@@ -42,7 +42,6 @@ namespace Ocelot.UnitTests.Middleware
.WithDownstreamReRoutes(downstreamReRoutes)
.Build();
-
var billDownstreamContext = new DownstreamContext(new DefaultHttpContext())
{
DownstreamResponse =
diff --git a/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj b/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj
index fcc2c7e2..80084a4d 100644
--- a/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj
+++ b/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj
@@ -12,6 +12,7 @@
false
false
false
+ ..\..\codeanalysis.ruleset
@@ -37,6 +38,9 @@
+
+ all
+
diff --git a/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs b/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs
index 168781bc..57d2fdc8 100644
--- a/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs
+++ b/test/Ocelot.UnitTests/RateLimit/ClientRateLimitMiddlewareTests.cs
@@ -19,7 +19,6 @@ namespace Ocelot.UnitTests.RateLimit
using Microsoft.Extensions.Caching.Memory;
using System.IO;
-
public class ClientRateLimitMiddlewareTests
{
private int _responseStatusCode;
diff --git a/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs b/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs
index 5661ace6..2bd26a4b 100644
--- a/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs
+++ b/test/Ocelot.UnitTests/Request/DownstreamRequestInitialiserMiddlewareTests.cs
@@ -36,7 +36,6 @@ namespace Ocelot.UnitTests.Request
public DownstreamRequestInitialiserMiddlewareTests()
{
-
_httpContext = new Mock();
_httpRequest = new Mock();
_requestMapper = new Mock();
diff --git a/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs b/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs
index 40276547..f6bf4eb7 100644
--- a/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs
+++ b/test/Ocelot.UnitTests/RequestId/ReRouteRequestIdMiddlewareTests.cs
@@ -4,7 +4,6 @@ namespace Ocelot.UnitTests.RequestId
{
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
- using Ocelot.DownstreamRouteFinder.Middleware;
using Ocelot.Infrastructure.RequestData;
using System;
using System.Collections.Generic;
@@ -24,7 +23,6 @@ namespace Ocelot.UnitTests.RequestId
public class ReRouteRequestIdMiddlewareTests
{
private readonly HttpRequestMessage _downstreamRequest;
- private Response _downstreamRoute;
private string _value;
private string _key;
private Mock _loggerFactory;
@@ -165,7 +163,6 @@ namespace Ocelot.UnitTests.RequestId
_repo.Verify(x => x.Update("RequestId", _value), Times.Once);
}
-
private void GivenTheDownStreamRouteIs(DownstreamRoute downstreamRoute)
{
_downstreamContext.TemplatePlaceholderNameAndValues = downstreamRoute.TemplatePlaceholderNameAndValues;
diff --git a/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs b/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs
index e6942681..c63e04d2 100644
--- a/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs
+++ b/test/Ocelot.UnitTests/Requester/DelegatingHandlerHandlerProviderFactoryTests.cs
@@ -41,7 +41,6 @@ namespace Ocelot.UnitTests.Requester
.Returns(qosProvider);
}
-
[Fact]
public void should_all_from_all_routes_provider_and_qos()
{
diff --git a/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs b/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs
index 545e956e..a53487a3 100644
--- a/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs
+++ b/test/Ocelot.UnitTests/Requester/FakeDelegatingHandler.cs
@@ -9,13 +9,13 @@ namespace Ocelot.UnitTests.Requester
{
public FakeDelegatingHandler()
{
-
}
public FakeDelegatingHandler(int order)
{
Order = order;
}
+
public int Order {get;private set;}
public DateTime TimeCalled {get;private set;}
@@ -25,4 +25,4 @@ namespace Ocelot.UnitTests.Requester
return new HttpResponseMessage();
}
}
-}
\ No newline at end of file
+}
diff --git a/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs b/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs
index b5d7e1e6..b788c826 100644
--- a/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs
+++ b/test/Ocelot.UnitTests/Requester/HttpClientBuilderTests.cs
@@ -17,7 +17,6 @@ namespace Ocelot.UnitTests.Requester
private readonly HttpClientBuilder _builder;
private readonly Mock _house;
private readonly Mock _provider;
- private IHttpClientBuilder _builderResult;
private IHttpClient _httpClient;
private HttpResponseMessage _response;
private DownstreamReRoute _request;
diff --git a/test/Ocelot.UnitTests/Requester/QosProviderHouseTests.cs b/test/Ocelot.UnitTests/Requester/QosProviderHouseTests.cs
index 487a3509..ae027143 100644
--- a/test/Ocelot.UnitTests/Requester/QosProviderHouseTests.cs
+++ b/test/Ocelot.UnitTests/Requester/QosProviderHouseTests.cs
@@ -13,7 +13,6 @@ namespace Ocelot.UnitTests.Requester
{
private IQoSProvider _qoSProvider;
private readonly QosProviderHouse _qosProviderHouse;
- private Response _addResult;
private Response _getResult;
private DownstreamReRoute _reRoute;
private readonly Mock _factory;
@@ -111,7 +110,6 @@ namespace Ocelot.UnitTests.Requester
_getResult.Data.ShouldBe(_qoSProvider);
}
-
private void GivenThereIsAQoSProvider(DownstreamReRoute reRoute, IQoSProvider qoSProvider)
{
_reRoute = reRoute;
diff --git a/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs b/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs
index 9922df6a..9800ffef 100644
--- a/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs
+++ b/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs
@@ -42,10 +42,9 @@ namespace Ocelot.UnitTests.Responder
[InlineData(OcelotErrorCode.RequestTimedOutError)]
public void should_return_service_unavailable(OcelotErrorCode errorCode)
{
- ShouldMapErrorToStatusCode(OcelotErrorCode.RequestTimedOutError, HttpStatusCode.ServiceUnavailable);
+ ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.ServiceUnavailable);
}
-
[Theory]
[InlineData(OcelotErrorCode.CannotAddDataError)]
[InlineData(OcelotErrorCode.CannotFindDataError)]
diff --git a/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs b/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs
index fb0720b4..54b795a2 100644
--- a/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs
+++ b/test/Ocelot.UnitTests/Responder/ResponderMiddlewareTests.cs
@@ -4,7 +4,6 @@ using Ocelot.Middleware;
namespace Ocelot.UnitTests.Responder
{
using Microsoft.AspNetCore.Http;
- using Ocelot.DownstreamRouteFinder.Middleware;
using System.Net.Http;
using Moq;
using Ocelot.DownstreamRouteFinder.Finder;
@@ -12,7 +11,6 @@ namespace Ocelot.UnitTests.Responder
using Ocelot.Logging;
using Ocelot.Responder;
using Ocelot.Responder.Middleware;
- using Ocelot.Responses;
using TestStack.BDDfy;
using Xunit;
@@ -20,14 +18,12 @@ namespace Ocelot.UnitTests.Responder
{
private readonly Mock _responder;
private readonly Mock _codeMapper;
- private OkResponse _response;
private Mock _loggerFactory;
private Mock _logger;
private readonly ResponderMiddleware _middleware;
private readonly DownstreamContext _downstreamContext;
private OcelotRequestDelegate _next;
-
public ResponderMiddlewareTests()
{
_responder = new Mock();
diff --git a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceFabricServiceDiscoveryProviderTests.cs b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceFabricServiceDiscoveryProviderTests.cs
new file mode 100644
index 00000000..39deb681
--- /dev/null
+++ b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceFabricServiceDiscoveryProviderTests.cs
@@ -0,0 +1,58 @@
+namespace Ocelot.UnitTests.ServiceDiscovery
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Text;
+ using Consul;
+ using Microsoft.AspNetCore.Builder;
+ using Microsoft.AspNetCore.Hosting;
+ using Microsoft.AspNetCore.Http;
+ using Moq;
+ using Ocelot.Logging;
+ using Ocelot.ServiceDiscovery;
+ using Ocelot.Values;
+ using Xunit;
+ using TestStack.BDDfy;
+ using Shouldly;
+
+ public class ServiceFabricServiceDiscoveryProviderTests
+ {
+ private ServiceFabricServiceDiscoveryProvider _provider;
+ private ServiceFabricConfiguration _config;
+ private string _host;
+ private string _serviceName;
+ private int _port;
+ private List _services;
+
+ [Fact]
+ public void should_return_service_fabric_naming_service()
+ {
+ this.Given(x => GivenTheFollowing())
+ .When(x => WhenIGet())
+ .Then(x => ThenTheServiceFabricNamingServiceIsRetured())
+ .BDDfy();
+ }
+
+ private void GivenTheFollowing()
+ {
+ _host = "localhost";
+ _serviceName = "OcelotServiceApplication/OcelotApplicationService";
+ _port = 19081;
+ }
+
+ private void WhenIGet()
+ {
+ _config = new ServiceFabricConfiguration(_host, _port, _serviceName);
+ _provider = new ServiceFabricServiceDiscoveryProvider(_config);
+ _services = _provider.Get().GetAwaiter().GetResult();
+ }
+
+ private void ThenTheServiceFabricNamingServiceIsRetured()
+ {
+ _services.Count.ShouldBe(1);
+ _services[0].HostAndPort.DownstreamHost.ShouldBe(_host);
+ _services[0].HostAndPort.DownstreamPort.ShouldBe(_port);
+ }
+ }
+}
diff --git a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceProviderFactoryTests.cs b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceProviderFactoryTests.cs
index f8c60bb7..021b9efb 100644
--- a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceProviderFactoryTests.cs
+++ b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceProviderFactoryTests.cs
@@ -77,6 +77,24 @@ namespace Ocelot.UnitTests.ServiceDiscovery
.BDDfy();
}
+ [Fact]
+ public void should_return_service_fabric_provider()
+ {
+ var reRoute = new DownstreamReRouteBuilder()
+ .WithServiceName("product")
+ .WithUseServiceDiscovery(true)
+ .Build();
+
+ var serviceConfig = new ServiceProviderConfigurationBuilder()
+ .WithServiceDiscoveryProviderType("ServiceFabric")
+ .Build();
+
+ this.Given(x => x.GivenTheReRoute(serviceConfig, reRoute))
+ .When(x => x.WhenIGetTheServiceProvider())
+ .Then(x => x.ThenTheServiceProviderIs())
+ .BDDfy();
+ }
+
private void ThenTheFollowingServicesAreReturned(List downstreamAddresses)
{
var result = (ConfigurationServiceProvider)_result;
diff --git a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs
index 8a41fe7e..1079f201 100644
--- a/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs
+++ b/test/Ocelot.UnitTests/ServiceDiscovery/ServiceRegistryTests.cs
@@ -131,8 +131,7 @@ namespace Ocelot.UnitTests.ServiceDiscovery
else
{
_registeredServices[serviceNameAndAddress.Name] = new List(){ serviceNameAndAddress };
- }
-
+ }
}
}
}
diff --git a/test/Ocelot.UnitTests/Wait.cs b/test/Ocelot.UnitTests/Wait.cs
new file mode 100644
index 00000000..d8fd3a88
--- /dev/null
+++ b/test/Ocelot.UnitTests/Wait.cs
@@ -0,0 +1,10 @@
+namespace Ocelot.UnitTests
+{
+ public class Wait
+ {
+ public static Waiter WaitFor(int milliSeconds)
+ {
+ return new Waiter(milliSeconds);
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/Ocelot.UnitTests/Waiter.cs b/test/Ocelot.UnitTests/Waiter.cs
index 8fb51ae5..8847c5b9 100644
--- a/test/Ocelot.UnitTests/Waiter.cs
+++ b/test/Ocelot.UnitTests/Waiter.cs
@@ -3,14 +3,6 @@ using System.Diagnostics;
namespace Ocelot.UnitTests
{
- public class Wait
- {
- public static Waiter WaitFor(int milliSeconds)
- {
- return new Waiter(milliSeconds);
- }
- }
-
public class Waiter
{
private readonly int _milliSeconds;
@@ -52,4 +44,4 @@ namespace Ocelot.UnitTests
return passed;
}
}
-}
\ No newline at end of file
+}