Comment incorporation

Missing file commit
This commit is contained in:
mokhan 2017-07-23 14:44:52 +05:30
parent 75ac7de5cd
commit 879bedf205
3 changed files with 41 additions and 2 deletions

View File

@ -208,6 +208,7 @@
<module>spring-zuul</module>
<module>spring-reactor</module>
<module>spring-vertx</module>
<module>spring-rest-logging</module>
<module>testing</module>
<module>testng</module>

View File

@ -0,0 +1,38 @@
package com.baeldung.rest.log.util;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.IOUtils;
import org.springframework.web.util.ContentCachingRequestWrapper;
import org.springframework.web.util.WebUtils;
public class RequestLoggingUtil {
public static String getStringFromInputStream(InputStream is) {
StringWriter writer = new StringWriter();
String encoding = "UTF-8";
try {
IOUtils.copy(is, writer, encoding);
} catch (IOException e) {
e.printStackTrace();
}
return writer.toString();
}
public static String readPayload(final HttpServletRequest request) throws IOException {
String payloadData = null;
ContentCachingRequestWrapper contentCachingRequestWrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class);
if (null != contentCachingRequestWrapper) {
byte[] buf = contentCachingRequestWrapper.getContentAsByteArray();
if (buf.length > 0) {
payloadData = new String(buf, 0, buf.length, contentCachingRequestWrapper.getCharacterEncoding());
}
}
return payloadData;
}
}

View File

@ -15,14 +15,14 @@ public class TestTaxiFareController {
private static final String URL = "http://localhost:" + 9090 + "/rest-log/taxifare/";
@Test
public void given_taxi_fare_get() {
public void givenRequest_thenfetchTaxiFareRateCard() {
TestRestTemplate testRestTemplate = new TestRestTemplate();
ResponseEntity<String> response = testRestTemplate.getForEntity(URL + "get/", String.class);
assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
}
@Test
public void given_taxi_ride_get_fare() {
public void givenTaxiRide_thenGetCalculatedFare() {
TestRestTemplate testRestTemplate = new TestRestTemplate();
TaxiRide taxiRide = new TaxiRide(true,10l);
String fare = testRestTemplate.postForObject(URL + "calculate/", taxiRide,String.class);