A Java-based application that forwards incoming HTTP GET requests to multiple backend servers in parallel. Built using Maven, Logback for logging, and Apache HttpClient for making HTTP requests.
- Features
- Prerequisites
- Setup
- Usage
- Logs
- Configuration
- Dependencies
- Project Structure
- Contributing
- Author
- Acknowledgments
- Forwards incoming HTTP GET requests to multiple backend servers.
- Logs requests and responses to both the console and a daily rolling log file.
- Configurable backend servers and server port via application.properties.
- Handles timeouts for backend requests.
- Uses multi-threading to ensure that slow or unresponsive backend servers do not block others.
- Java 11 or later.
- Maven 3.x or later.
-
Clone the Repository:
Run the following command to clone the repository: git clone https://github.com/codecarver/request-forwarder.git cd request-forwarder -
Build the Project:
Build the project using Maven: mvn clean install -
Configure Backend Servers: Edit the application.properties file in the src/main/resources directory to specify the backend servers and server port:
# Server configuration server.port=8080 # Backend servers with paths/endpoints (comma-separated list) backend.servers=http://192.168.1.101:8080/api,http://192.168.1.102:8080/api,http://192.168.1.103:8080/api -
Run the Application: Run the application using the following command:
java -jar target/request-forwarder.jar
Send a GET request to the application:
curl "http://localhost:8080/resource?param1=value1¶m2=value2"
The application will:
- Log the request details.
- Forward the request to all configured backend servers.
- Log the responses from the backend servers.
- Return a confirmation message to the client.
- Logs are written to the logs/app.log file in the project directory.
- Logs are also printed to the console (sysout).
- Log files are rolled daily, and old logs are kept for 30 days.
application.properties:
- server.port: The port on which the application listens for incoming requests.
- backend.servers: A comma-separated list of backend server URLs.
logback.xml:
- Configures logging behavior, including log file location, rolling policy, and log format.
- Apache HttpClient: For making HTTP requests to backend servers.
- Logback: For logging requests and responses.
- SLF4J: Logging facade.
- Apache Commons Configuration: For reading the application.properties file.
request-forwarder/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── example/
│ │ │ └── RequestForwarder.java
│ │ └── resources/
│ │ ├── application.properties
│ │ └── logback.xml
│ └── test/
│ └── java/
├── target/
├── logs/
├── pom.xml
└── README
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (git checkout -b feature/your-feature).
- Commit your changes (git commit -m 'Add some feature').
- Push to the branch (git push origin feature/your-feature).
- Open a pull request.
Siwi (https://github.com/codecarver)
- Apache HttpClient (https://hc.apache.org/httpcomponents-client-ga/)
- Logback (https://logback.qos.ch/)
- SLF4J (https://www.slf4j.org/)
- Apache Commons Configuration (https://commons.apache.org/proper/commons-configuration/)