Coder Social home page Coder Social logo

dystudio / route-service-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tomaslin/route-service-example

0.0 1.0 0.0 127 KB

An example Cloud Foundry Route Service, implemented with Spring Boot.

License: Apache License 2.0

Java 100.00%

route-service-example's Introduction

Cloud Foundry Route Service Example

This project is an example of a Cloud Foundry Route Service written with Spring Boot. This application does the following to each request:

  1. Intercepts an incoming request
  2. Logs information about that incoming request
  3. Transforms the incoming request to an outgoing request
  4. Logs information about that outgoing request
  5. Forwards the request and response

Requirements

Java, Maven

The application is written in Java 8 and packaged as a self executable JAR file. This enables it to run anywhere that Java is available.

Deployment

The following instructions assume that you have created an account and installed the cf command line tool.

In order to automate the deployment process as much as possible, the project contains a Cloud Foundry manifest. To deploy run the following commands:

$ ./mvnw clean package
$ cf push

Next, create a user provided service that contains the route service configuration information. To do this, run the following command, substituting the address that the route service is listening on:

$ cf create-user-provided-service test-route-service -r https://<ROUTE-SERVICE-ADDRESS>

The next step assumes that you have an application already running that you'd like to bind this route service to. To do this, run the following command, substituting the domain and hostname bound to that application:

$ cf bind-route-service <APPLICATION-DOMAIN> test-route-service --hostname <APPLICATION-HOST>

In order to view the interception of the requests, you will need to stream the logs of the route service. To do this, run the following command:

$ cf logs route-service-example

Finally, start making requests against your test application. The route service's logs should start returning results that look similar to the following:

INFO  Incoming Request:  PATCH http://localhost/route-service/patch, {WebTestClient-Request-Id=[1], X-CF-Forwarded-Url=[http://localhost:51751/original/patch], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature], Content-Type=[text/plain;charset=UTF-8], Content-Length=[9]}
INFO  Outgoing Request:  PATCH http://localhost:51751/original/patch, {WebTestClient-Request-Id=[1], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature], Content-Type=[text/plain;charset=UTF-8], Content-Length=[9]}
INFO  Outgoing Response: 200, {Content-Type=[text/plain], Content-Length=[9]}
INFO  Incoming Request:  DELETE http://localhost/route-service/delete, {WebTestClient-Request-Id=[1], X-CF-Forwarded-Url=[http://localhost:51755/original/delete], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature]}
INFO  Outgoing Request:  DELETE http://localhost:51755/original/delete, {WebTestClient-Request-Id=[1], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature]}
INFO  Outgoing Response: 200, {Content-Length=[0]}
INFO  Incoming Request:  HEAD http://localhost/route-service/head, {WebTestClient-Request-Id=[1], X-CF-Forwarded-Url=[http://localhost:51757/original/head], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature]}
INFO  Outgoing Request:  HEAD http://localhost:51757/original/head, {WebTestClient-Request-Id=[1], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature]}
INFO  Outgoing Response: 200, {Content-Length=[0]}
INFO  Incoming Request:  PUT http://localhost/route-service/put, {WebTestClient-Request-Id=[1], X-CF-Forwarded-Url=[http://localhost:51759/original/put], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature], Content-Type=[text/plain;charset=UTF-8], Content-Length=[9]}
INFO  Outgoing Request:  PUT http://localhost:51759/original/put, {WebTestClient-Request-Id=[1], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature], Content-Type=[text/plain;charset=UTF-8], Content-Length=[9]}
INFO  Outgoing Response: 200, {Content-Type=[text/plain], Content-Length=[9]}
INFO  Incoming Request:  POST http://localhost/route-service/post, {WebTestClient-Request-Id=[1], X-CF-Forwarded-Url=[http://localhost:51761/original/post], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature], Content-Type=[text/plain;charset=UTF-8], Content-Length=[9]}
INFO  Outgoing Request:  POST http://localhost:51761/original/post, {WebTestClient-Request-Id=[1], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature], Content-Type=[text/plain;charset=UTF-8], Content-Length=[9]}
INFO  Outgoing Response: 200, {Content-Type=[text/plain], Content-Length=[9]}
INFO  Incoming Request:  GET http://localhost/route-service/get, {WebTestClient-Request-Id=[1], X-CF-Forwarded-Url=[http://localhost:51763/original/get], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature]}
INFO  Outgoing Request:  GET http://localhost:51763/original/get, {WebTestClient-Request-Id=[1], X-CF-Proxy-Metadata=[test-proxy-metadata], X-CF-Proxy-Signature=[test-proxy-signature]}
INFO  Outgoing Response: 200, {Content-Type=[text/plain], Content-Length=[9]}

Developing

The project is set up as a Maven project and doesn't have any special requirements beyond that. It has been created using IntelliJ and contains configuration information for that environment, but should work with other IDEs.

License

The project is released under version 2.0 of the Apache License.

route-service-example's People

Contributors

nebhale avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.