Skip to content

Commit

Permalink
print body
Browse files Browse the repository at this point in the history
  • Loading branch information
robberphex committed May 31, 2023
1 parent 1b174ba commit 986ce97
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions mse-simple-demo/A/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.io.IOUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
Expand All @@ -22,18 +23,21 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.ExecutionException;

@Api(value = "/", tags = {"入口应用"})
@RestController
class AController {
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(AController.class);

@Autowired
@Qualifier("loadBalancedRestTemplate")
Expand Down Expand Up @@ -83,8 +87,14 @@ private void init() {
}

@ApiOperation(value = "HTTP 全链路灰度入口", tags = {"入口应用"})
@GetMapping("/a")
@RequestMapping("/a")
public String a(HttpServletRequest request) throws ExecutionException, InterruptedException {
try {
String body = IOUtils.toString(request.getInputStream(), Charset.defaultCharset());
log.info("body is {}", body);
} catch (Throwable e) {
log.warn("get body error", e);
}
StringBuilder headerSb = new StringBuilder();
//枚举创建完后无法更改
Enumeration<String> enumeration = request.getHeaderNames();
Expand Down

0 comments on commit 986ce97

Please sign in to comment.