sonar 대응
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package com.eactive.httpmockserver.client.service;
|
||||
|
||||
import com.eactive.httpmockserver.client.dto.ApiRequestKeyValueDTO;
|
||||
import com.eactive.httpmockserver.client.dto.ApiRequestDTO;
|
||||
import com.eactive.httpmockserver.client.dto.ApiRequestKeyValueDTO;
|
||||
import com.eactive.httpmockserver.client.dto.ApiResponse;
|
||||
import com.eactive.httpmockserver.common.exception.ServerNotFoundException;
|
||||
import com.eactive.httpmockserver.server.entity.Server;
|
||||
import com.eactive.httpmockserver.server.entity.ServerRepository;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
@@ -24,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.net.ssl.SSLException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Service
|
||||
@@ -32,9 +34,9 @@ public class NettyApiClient {
|
||||
@Autowired
|
||||
ServerRepository serverRepository;
|
||||
|
||||
public CompletableFuture<ApiResponse> handleRequest(ApiRequestDTO apiRequest) throws Exception {
|
||||
public CompletableFuture<ApiResponse> handleRequest(ApiRequestDTO apiRequest) throws InterruptedException {
|
||||
|
||||
Server server = serverRepository.findById(apiRequest.getServer()).orElseThrow(() -> new Exception("Server not found"));
|
||||
Server server = serverRepository.findById(apiRequest.getServer()).orElseThrow(() -> new ServerNotFoundException("Server not found"));
|
||||
String host = server.getHostname();
|
||||
int port = server.getPort();
|
||||
|
||||
@@ -74,12 +76,9 @@ public class NettyApiClient {
|
||||
}
|
||||
|
||||
String basePath = server.getBasePath();
|
||||
if(!apiRequest.getPath().startsWith("/")){
|
||||
basePath = basePath + "/";
|
||||
}
|
||||
String fullPath = Paths.get(basePath, apiRequest.getPath()).toString();
|
||||
|
||||
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(apiRequest.getMethod()),
|
||||
(basePath + apiRequest.getPath()).replaceAll("//", "/"), content);
|
||||
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(apiRequest.getMethod()), fullPath, content);
|
||||
|
||||
request.headers().set("Host", host);
|
||||
request.headers().set("Connection", HttpHeaderValues.CLOSE);
|
||||
@@ -89,9 +88,9 @@ public class NettyApiClient {
|
||||
request.headers().set(HttpHeaderNames.CONTENT_LENGTH, content.readableBytes());
|
||||
}
|
||||
|
||||
if (apiRequest.getHeaders().size() > 0) {
|
||||
if (!apiRequest.getHeaders().isEmpty()) {
|
||||
HttpHeaders customHeaders = new DefaultHttpHeaders();
|
||||
apiRequest.getHeaders().stream().filter(ApiRequestKeyValueDTO::isEnabled).forEach((header) -> {
|
||||
apiRequest.getHeaders().stream().filter(ApiRequestKeyValueDTO::isEnabled).forEach(header -> {
|
||||
if(StringUtils.isNotEmpty(header.getKey()) && StringUtils.isNotEmpty(header.getValue())){
|
||||
customHeaders.set(header.getKey(), header.getValue());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user