sonarlint 수정
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
package com.eactive.httpmockserver;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -20,9 +24,6 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
|
||||
@Controller
|
||||
public class ApiController {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
@@ -33,6 +34,9 @@ public class ApiController {
|
||||
@Autowired
|
||||
private ApiService apiService;
|
||||
|
||||
/** one random instance */
|
||||
Random random = new Random();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
//@RequestMapping(value = "/mock-api/**")
|
||||
@RequestMapping(value = "/{_:^(?!plugins|dist|favicon.ico).*$}/**")
|
||||
@@ -42,16 +46,15 @@ public class ApiController {
|
||||
logger.debug("==================================================");
|
||||
logger.debug(request.getServletPath());
|
||||
logger.debug("--------------------------------------------------");
|
||||
logger.debug("httpEntity.getHeaders().toString()=" + httpEntity.getHeaders().toString());
|
||||
logger.debug("httpEntity.getHeaders().toString()= {}", httpEntity.getHeaders());
|
||||
logger.debug("--------------------------------------------------");
|
||||
logger.debug("httpEntity.getBody()=" + httpEntity.getBody());
|
||||
logger.debug("httpEntity.getBody()={}", httpEntity.getBody());
|
||||
logger.debug("--------------------------------------------------");
|
||||
|
||||
Map<String, String[]> paramMap = request.getParameterMap();
|
||||
for (String key : paramMap.keySet()) {
|
||||
String[] values = paramMap.get(key);
|
||||
for (String value : values) {
|
||||
logger.debug(String.format("%s=%s", key, value));
|
||||
for (Entry<String, String[]> entry : paramMap.entrySet()) {
|
||||
for (String value : entry.getValue()) {
|
||||
logger.debug("{}={}", entry.getKey(), value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,14 +77,14 @@ public class ApiController {
|
||||
}
|
||||
|
||||
// sleep Àû¿ë
|
||||
if(api.getSleepSeconds() != null) {
|
||||
if (api.getSleepSeconds() != null) {
|
||||
int sleepSeconds = api.getSleepSeconds().intValue();
|
||||
if (sleepSeconds > 0) {
|
||||
try {
|
||||
logger.debug("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
logger.debug("Start Sleep {} Seconds.", sleepSeconds);
|
||||
logger.debug("...");
|
||||
Thread.sleep(sleepSeconds * 1000);
|
||||
Thread.sleep(sleepSeconds * 1000l);
|
||||
logger.debug("......");
|
||||
logger.debug("Finished Sleep {} Seconds.", sleepSeconds);
|
||||
logger.debug("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||
@@ -104,7 +107,7 @@ public class ApiController {
|
||||
int responseStatusCode = 200;
|
||||
if (api.getResponseStatusCode() != null) {
|
||||
responseStatusCode = api.getResponseStatusCode().intValue();
|
||||
System.out.println("Response Status Code=" + responseStatusCode);
|
||||
logger.debug("Response Status Code={}", responseStatusCode);
|
||||
}
|
||||
|
||||
return new ResponseEntity<String>(assignResponseBody(api), responseHeaders, responseStatusCode);
|
||||
@@ -163,7 +166,7 @@ public class ApiController {
|
||||
return serviceValue;
|
||||
} else {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
|
||||
String.format("Unsuported ServiceType(ServiceType=%s, ServiceKey)", serviceType, serviceKey));
|
||||
String.format("Unsuported ServiceType(ServiceType=%s, ServiceKey=%s)", serviceType, serviceKey));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +178,6 @@ public class ApiController {
|
||||
if (StringUtils.isBlank(api.getResponseBody2())) {
|
||||
return api.getResponseBody1();
|
||||
} else {
|
||||
Random random = new Random();
|
||||
if (random.nextInt(2) == 0) {
|
||||
return api.getResponseBody2();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user