sonar 대응
This commit is contained in:
@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -51,7 +52,9 @@ public class MockApiController {
|
||||
try {
|
||||
Thread.sleep(matchingResponse.getDelay());
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
logger.error("Error while delaying response", e);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error processing request due to interruption.");
|
||||
}
|
||||
}
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
@@ -84,7 +87,7 @@ public class MockApiController {
|
||||
|
||||
MockResponse defaultResponse = mockRoute.getResponses().stream().filter(MockResponse::isDefaultResponse).findFirst().orElse(null);
|
||||
List<MockResponse> responses = mockRoute.getResponses().stream().filter(response -> !response.isDefaultResponse()).collect(Collectors.toList());
|
||||
if(defaultResponse!=null){
|
||||
if (defaultResponse != null) {
|
||||
responses.add(defaultResponse);
|
||||
}
|
||||
|
||||
@@ -101,34 +104,27 @@ public class MockApiController {
|
||||
if (conditions == null) {
|
||||
return true;
|
||||
}
|
||||
List<Boolean> results = new ArrayList<>();
|
||||
|
||||
for (MockCondition condition : conditions) {
|
||||
switch (condition.getType().toLowerCase()) {
|
||||
case "query":
|
||||
if (!isQueryMatching(condition, request)) {
|
||||
return false;
|
||||
}
|
||||
results.add(isQueryMatching(condition, request));
|
||||
break;
|
||||
case "header":
|
||||
if (!isHeaderMatching(condition, request)) {
|
||||
return false;
|
||||
}
|
||||
results.add(isHeaderMatching(condition, request));
|
||||
break;
|
||||
case "path":
|
||||
if (!isPathMatching(condition, pathVariables)) {
|
||||
return false;
|
||||
}
|
||||
results.add(isPathMatching(condition, pathVariables));
|
||||
break;
|
||||
case "jsonpath":
|
||||
if (!isJsonPathMatching(condition, request)) {
|
||||
return false;
|
||||
}
|
||||
results.add(isJsonPathMatching(condition, request));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return !results.contains(false);
|
||||
}
|
||||
|
||||
private boolean isQueryMatching(MockCondition condition, MockRequest request) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
public class ApiClientController {
|
||||
@@ -26,13 +27,9 @@ public class ApiClientController {
|
||||
|
||||
@PostMapping("/mgmt/api/test.do")
|
||||
@ResponseBody
|
||||
public ApiResponse handleApiRequest(@RequestBody ApiRequestDTO request) {
|
||||
public ApiResponse handleApiRequest(@RequestBody ApiRequestDTO request) throws InterruptedException, ExecutionException {
|
||||
|
||||
try {
|
||||
return nettyApiClient.handleRequest(request).get();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return nettyApiClient.handleRequest(request).get();
|
||||
}
|
||||
|
||||
@GetMapping("/mgmt/api_tester.do")
|
||||
|
||||
@@ -49,15 +49,11 @@ public class NettyApiClient {
|
||||
.option(ChannelOption.TCP_NODELAY, true)
|
||||
.handler(new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
public void initChannel(Channel ch) {
|
||||
public void initChannel(Channel ch) throws SSLException {
|
||||
if (server.getScheme().equalsIgnoreCase("https")) {
|
||||
try {
|
||||
final SslContext sslCtx = SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
|
||||
ch.pipeline().addLast(sslCtx.newHandler(ch.alloc(), host, port));// Add SSL handler
|
||||
} catch (SSLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
final SslContext sslCtx = SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
|
||||
ch.pipeline().addLast(sslCtx.newHandler(ch.alloc(), host, port));// Add SSL handler
|
||||
}
|
||||
|
||||
ch.pipeline().addLast(new HttpClientCodec());
|
||||
@@ -91,7 +87,7 @@ public class NettyApiClient {
|
||||
if (!apiRequest.getHeaders().isEmpty()) {
|
||||
HttpHeaders customHeaders = new DefaultHttpHeaders();
|
||||
apiRequest.getHeaders().stream().filter(ApiRequestKeyValueDTO::isEnabled).forEach(header -> {
|
||||
if(StringUtils.isNotEmpty(header.getKey()) && StringUtils.isNotEmpty(header.getValue())){
|
||||
if (StringUtils.isNotEmpty(header.getKey()) && StringUtils.isNotEmpty(header.getValue())) {
|
||||
customHeaders.set(header.getKey(), header.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user