Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
ADDED: minor changes for debugging and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
AleixMT committed Jan 22, 2024
1 parent cb0d400 commit 4fd4a6f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<relativePath />
</parent>
<groupId>net.unir.missi.desarrollowebfullstack.bookabook</groupId>
<artifactId>gateway-filters</artifactId>
<artifactId>gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>gateway</name>
<description>Gateway o Proxy Inverso con filtros</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ public Mono<Void> filter(
log.info("Request does not have a content type or is not a POST request");
return exchange.getResponse().setComplete();
} else {
return DataBufferUtils.join(exchange.getRequest().getBody())
.flatMap(dataBuffer -> {
return DataBufferUtils
.join(exchange.getRequest().getBody())
.flatMap(dataBuffer ->
{
GatewayRequest request = requestBodyExtractor.getRequest(exchange, dataBuffer);
ServerHttpRequest mutatedRequest = requestDecoratorFactory.getDecorator(request);
//RouteToRequestUrlFilter writes the URI to the exchange attributes *before* any global filters run.
exchange.getAttributes().put(ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR, mutatedRequest.getURI());
log.info("Proxying request: {} {}", mutatedRequest.getMethod(), mutatedRequest.getURI());

return chain.filter(exchange.mutate().request(mutatedRequest).build());
});
}
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/com/unir/gateway/model/GatewayRequest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.unir.gateway.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.util.LinkedMultiValueMap;
Expand Down Expand Up @@ -46,4 +43,16 @@ public class GatewayRequest {
*/
@JsonIgnore
private HttpHeaders headers;


@Override
public String toString() {
return "GatewayRequest{" +
"targetMethod=" + targetMethod +
", queryParams=" + queryParams +
", body=" + body +
", exchange=" + exchange +
", headers=" + headers +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import reactor.core.publisher.Flux;

import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Logger;

/**
* This class is responsible for extracting the body of the request and converting it into a GatewayRequest object.
Expand Down Expand Up @@ -46,12 +47,16 @@ public GatewayRequest getRequest(ServerWebExchange exchange, DataBuffer buffer)
GatewayRequest request = objectMapper.readValue(rawRequest, GatewayRequest.class);
request.setExchange(exchange);

Logger.getGlobal().info(request.toString());

// Set headers -- Needed: https://github.com/spring-cloud/spring-cloud-gateway/issues/894
HttpHeaders headers = new HttpHeaders();
headers.putAll(exchange.getRequest().getHeaders());
headers.remove(HttpHeaders.CONTENT_LENGTH);
headers.set(HttpHeaders.TRANSFER_ENCODING, "chunked");
request.setHeaders(headers);
Logger.getGlobal().info(request.toString());

return request;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spring.profiles.default = prod



server.port=8762
server.port=8763

## Classic Eureka configuration
eureka.instance.preferIpAddress=true
Expand Down

0 comments on commit 4fd4a6f

Please sign in to comment.