This commit is contained in:
현성필
2023-05-12 11:47:09 +09:00
parent ac5f4146f4
commit c47320f56c
24 changed files with 444 additions and 30 deletions
@@ -0,0 +1,60 @@
package com.eactive.httpmockserver.client.entity;
import com.eactive.httpmockserver.user.entity.StaffUser;
import javax.persistence.*;
import java.util.List;
@Entity
@Table(name = "API_COLLECTION")
public class ApiCollection {
@Id
private String id; //uuid
private String name;
@ManyToOne
@JoinColumn(name = "USER_ID")
private StaffUser owner;
@ManyToMany
@JoinTable(
name = "API_COLLECTION_API_REQUEST_INFO",
joinColumns = @JoinColumn(name = "API_COLLECTION_ID"),
inverseJoinColumns = @JoinColumn(name = "API_REQUEST_INFO_ID")
)
private List<ApiRequestInfo> apis;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<ApiRequestInfo> getApis() {
return apis;
}
public void setApis(List<ApiRequestInfo> apis) {
this.apis = apis;
}
public StaffUser getOwner() {
return owner;
}
public void setOwner(StaffUser owner) {
this.owner = owner;
}
}
@@ -0,0 +1,116 @@
package com.eactive.httpmockserver.client.entity;
import com.eactive.httpmockserver.user.entity.StaffUser;
import org.hibernate.annotations.Type;
import javax.persistence.*;
import java.time.LocalDateTime;
public class ApiRequestHistory {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@ManyToOne
@JoinColumn(name = "SERVER_ID")
private Server server;
@ManyToOne
@JoinColumn(name = "USER_ID")
private StaffUser owner;
private String method;
private String uri;
private String requestHeaders;
private String requestBody;
private String responseBody;
private String responseHeaders;
@Type(type = "org.hibernate.type.LocalDateTimeType")
private LocalDateTime requestTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Server getServer() {
return server;
}
public void setServer(Server server) {
this.server = server;
}
public StaffUser getOwner() {
return owner;
}
public void setOwner(StaffUser owner) {
this.owner = owner;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getRequestHeaders() {
return requestHeaders;
}
public void setRequestHeaders(String requestHeaders) {
this.requestHeaders = requestHeaders;
}
public String getRequestBody() {
return requestBody;
}
public void setRequestBody(String requestBody) {
this.requestBody = requestBody;
}
public String getResponseBody() {
return responseBody;
}
public void setResponseBody(String responseBody) {
this.responseBody = responseBody;
}
public String getResponseHeaders() {
return responseHeaders;
}
public void setResponseHeaders(String responseHeaders) {
this.responseHeaders = responseHeaders;
}
public LocalDateTime getRequestTime() {
return requestTime;
}
public void setRequestTime(LocalDateTime requestTime) {
this.requestTime = requestTime;
}
}
@@ -0,0 +1,96 @@
package com.eactive.httpmockserver.client.entity;
import com.eactive.httpmockserver.user.entity.StaffUser;
import javax.persistence.*;
@Entity
@Table(name = "API_REQUEST_INFO")
public class ApiRequestInfo {
@Id
private String id; //uuid
@ManyToOne
@JoinColumn(name = "SERVER_ID")
private Server server;
@ManyToOne
@JoinColumn(name = "USER_ID")
private StaffUser owner;
private String method;
private String path;
private String headers;
private String queryParams;
private String requestBody;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Server getServer() {
return server;
}
public void setServer(Server server) {
this.server = server;
}
public StaffUser getOwner() {
return owner;
}
public void setOwner(StaffUser owner) {
this.owner = owner;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getHeaders() {
return headers;
}
public void setHeaders(String headers) {
this.headers = headers;
}
public String getQueryParams() {
return queryParams;
}
public void setQueryParams(String queryParams) {
this.queryParams = queryParams;
}
public String getRequestBody() {
return requestBody;
}
public void setRequestBody(String requestBody) {
this.requestBody = requestBody;
}
}
@@ -16,6 +16,8 @@ public class Server {
private String hostname;
private String basePath;
private int port;
public Long getId() {
@@ -50,6 +52,14 @@ public class Server {
this.hostname = hostname;
}
public String getBasePath() {
return basePath;
}
public void setBasePath(String basePath) {
this.basePath = basePath;
}
public int getPort() {
return port;
}
@@ -60,6 +70,6 @@ public class Server {
@Transient
public String getHostAddress() {
return scheme + "://" + hostname + ":" + port;
return scheme + "://" + hostname;
}
}
@@ -0,0 +1,13 @@
package com.eactive.httpmockserver.client.repository;
import com.eactive.httpmockserver.client.entity.ApiCollection;
import com.eactive.httpmockserver.user.entity.StaffUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
public interface ApiCollectionRepository extends JpaRepository<ApiCollection, String>, JpaSpecificationExecutor<ApiCollection> {
List<ApiCollection> findAllByOwner(StaffUser owner);
}
@@ -0,0 +1,8 @@
package com.eactive.httpmockserver.client.repository;
import com.eactive.httpmockserver.client.entity.ApiRequestInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface ApiRequestRepository extends JpaRepository<ApiRequestInfo, String>, JpaSpecificationExecutor<ApiRequestInfo> {
}
@@ -0,0 +1,25 @@
package com.eactive.httpmockserver.client.service;
import com.eactive.httpmockserver.client.entity.ApiCollection;
import com.eactive.httpmockserver.client.repository.ApiCollectionRepository;
import com.eactive.httpmockserver.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.List;
@Service
@Transactional
public class ApiTesterService {
@Autowired
private UserService userService;
@Autowired
ApiCollectionRepository apiCollectionRepository;
public List<ApiCollection> findMyCollections(String esntlId) {
return apiCollectionRepository.findAllByOwner(userService.findByEsntlId(esntlId));
}
}
@@ -73,8 +73,13 @@ public class NettyApiClient {
content = Unpooled.EMPTY_BUFFER;
}
String basePath = server.getBasePath();
if(!apiRequest.getPath().startsWith("/")){
basePath = basePath + "/";
}
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(apiRequest.getMethod()),
apiRequest.getPath(), content);
(basePath + apiRequest.getPath()).replaceAll("//", "/"), content);
request.headers().set("Host", host);
request.headers().set("Connection", HttpHeaderValues.CLOSE);