응답관리 인코딩 처리 추가
This commit is contained in:
@@ -14,5 +14,4 @@ public class ElinkTestMaster {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ElinkTestMaster.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,12 +7,7 @@ import com.eactive.testmaster.api.entity.MockCondition;
|
||||
import com.eactive.testmaster.api.entity.MockResponse;
|
||||
import com.eactive.testmaster.api.entity.MockRoute;
|
||||
import com.eactive.testmaster.api.service.MockRouteService;
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -21,6 +16,14 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
public class MockApiController {
|
||||
|
||||
@@ -66,9 +69,20 @@ public class MockApiController {
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
matchingResponse.getHeaders().forEach(responseHeaders::set);
|
||||
|
||||
String encodingCharset = StringUtils.isNotEmpty(matchingResponse.getEncodingCharset()) ? matchingResponse.getEncodingCharset() : System.getProperty("file.encoding");
|
||||
|
||||
if (!responseHeaders.containsKey(HttpHeaders.CONTENT_TYPE)) {
|
||||
responseHeaders.add(HttpHeaders.CONTENT_TYPE, "text/plain; charset=" + encodingCharset);
|
||||
} else {
|
||||
String contentType = responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
|
||||
if (!contentType.contains("charset")) {
|
||||
responseHeaders.set(HttpHeaders.CONTENT_TYPE, contentType + "; charset=" + encodingCharset);
|
||||
}
|
||||
}
|
||||
|
||||
request.getParams().putAll(pathVariables);
|
||||
|
||||
return new ResponseEntity<>(replaceParams(matchingResponse.getBody(), request.getParams()), responseHeaders, HttpStatus.valueOf(matchingResponse.getStatusCode()));
|
||||
return new ResponseEntity<>(replaceParams(matchingResponse.getBody(), request.getParams(), encodingCharset), responseHeaders, HttpStatus.valueOf(matchingResponse.getStatusCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,11 +91,13 @@ public class MockApiController {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Not Found");
|
||||
}
|
||||
|
||||
private String replaceParams(String responseBody, Map<String, String> params) {
|
||||
private String replaceParams(String responseBody, Map<String, String> params, String encodingCharset) throws UnsupportedEncodingException {
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||
responseBody = responseBody.replace("{" + entry.getKey() + "}", entry.getValue());
|
||||
}
|
||||
return responseBody;
|
||||
|
||||
byte[] sourceBytes = responseBody.getBytes(encodingCharset);
|
||||
return new String(sourceBytes, encodingCharset);
|
||||
}
|
||||
|
||||
private boolean isRouteMatch(MockRoute mockRoute, MockRequest request) {
|
||||
|
||||
@@ -18,6 +18,9 @@ public class MockResponseDTO {
|
||||
private String defaultResponse;
|
||||
|
||||
private List<MockConditionDTO> conditions;
|
||||
|
||||
private String encodingCharset;
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
@@ -65,4 +68,12 @@ public class MockResponseDTO {
|
||||
public void setDefaultResponse(String defaultResponse) {
|
||||
this.defaultResponse = defaultResponse;
|
||||
}
|
||||
|
||||
public String getEncodingCharset() {
|
||||
return encodingCharset;
|
||||
}
|
||||
|
||||
public void setEncodingCharset(String encodingCharset) {
|
||||
this.encodingCharset = encodingCharset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ public class MockResponse {
|
||||
@OneToMany(mappedBy = "mockResponse", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<MockCondition> conditions = new ArrayList<>();
|
||||
|
||||
private String encodingCharset;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -113,4 +115,12 @@ public class MockResponse {
|
||||
public void setDefaultResponse(boolean defaultResponse) {
|
||||
this.defaultResponse = defaultResponse;
|
||||
}
|
||||
|
||||
public String getEncodingCharset() {
|
||||
return encodingCharset;
|
||||
}
|
||||
|
||||
public void setEncodingCharset(String encodingCharset) {
|
||||
this.encodingCharset = encodingCharset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@ public class ApiRequestMigrationService {
|
||||
apiRequestRepository.save(apiRequest);
|
||||
});
|
||||
|
||||
String fileEncoding = System.getProperty("file.encoding");
|
||||
System.out.println(fileEncoding);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
<input type="number" th:field="*{responses[__${status.index}__].statusCode}" required/>
|
||||
<textarea th:field="*{responses[__${status.index}__].body}"></textarea>
|
||||
<input type="number" th:field="*{responses[__${status.index}__].delay}" required/>
|
||||
<input type="text" th:field="*{responses[__${status.index}__].encodingCharset}" />
|
||||
<input type="hidden" th:field="*{responses[__${status.index}__].defaultResponse}" />
|
||||
<ul class="response_conditions">
|
||||
<li th:each="condition, status: *{responses[__${status.index}__].conditions}">
|
||||
@@ -158,6 +159,10 @@
|
||||
<input class="form-control" type="number" name="delay" required/>
|
||||
<label class="form-label must">응답 지연 시간(ms)</label>
|
||||
</div>
|
||||
<div class="form-floating mt-1">
|
||||
<input class="form-control" type="text" name="encodingCharset"/>
|
||||
<label class="form-label must">문자 Set</label>
|
||||
</div>
|
||||
<label class="form-label mt-1">응답 Body</label>
|
||||
<div class="response_body" style="width:100%;height:250px;border:1px solid grey;"></div>
|
||||
<textarea class="form-control" style="display: none;" name="body"></textarea>
|
||||
@@ -282,6 +287,7 @@
|
||||
//statusCode, delay, defaultResponse, body 로 끝나는 항목을 찾음
|
||||
response.statusCode = $(this).find('input[name$="statusCode"]').val();
|
||||
response.delay = $(this).find('input[name$="delay"]').val();
|
||||
response.encodingCharset = $(this).find('input[name$="encodingCharset"]').val();
|
||||
response.defaultResponse = $(this).find('input[name$="defaultResponse"]').val()==='true';
|
||||
response.body = $(this).find('textarea[name$="body"]').val();
|
||||
|
||||
@@ -389,11 +395,13 @@
|
||||
nodeCopy.find('input[name="statusCode"]').attr('name', 'responses[' + i + '].statusCode');
|
||||
nodeCopy.find('input[name="defaultResponse"]').attr('name', 'responses[' + i + '].defaultResponse');
|
||||
nodeCopy.find('input[name="delay"]').attr('name', 'responses[' + i + '].delay');
|
||||
nodeCopy.find('input[name="encodingCharset"]').attr('name', 'responses[' + i + '].encodingCharset');
|
||||
nodeCopy.find('textarea[name="body"]').attr('name', 'responses[' + i + '].body');
|
||||
|
||||
nodeCopy.find('input[name="responses[' + i + '].statusCode"]').val(model.responses[i].statusCode);
|
||||
nodeCopy.find('input[name="responses[' + i + '].defaultResponse"]').val(model.responses[i].defaultResponse);
|
||||
nodeCopy.find('input[name="responses[' + i + '].delay"]').val(model.responses[i].delay);
|
||||
nodeCopy.find('input[name="responses[' + i + '].encodingCharset"]').val(model.responses[i].encodingCharset);
|
||||
|
||||
let me = this;
|
||||
|
||||
@@ -421,6 +429,10 @@
|
||||
model.responses[i].delay = $(this).val();
|
||||
});
|
||||
|
||||
nodeCopy.find('input[name="responses[' + i + '].encodingCharset"]').on('input', function () {
|
||||
model.responses[i].encodingCharset = $(this).val();
|
||||
});
|
||||
|
||||
$('#responseTabContent').append(nodeCopy);
|
||||
if(view.currentIdx >= model.responses.length){
|
||||
view.currentIdx = model.responses.length - 1;
|
||||
|
||||
Reference in New Issue
Block a user