불필요 파일 삭제
This commit is contained in:
@@ -1,55 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.datatables;
|
|
||||||
|
|
||||||
public class Column {
|
|
||||||
private String data;
|
|
||||||
private String name;
|
|
||||||
private Boolean searchable;
|
|
||||||
private Boolean orderable;
|
|
||||||
private Search search;
|
|
||||||
|
|
||||||
public String getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(String data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getSearchable() {
|
|
||||||
return searchable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSearchable(Boolean searchable) {
|
|
||||||
this.searchable = searchable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getOrderable() {
|
|
||||||
return orderable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrderable(Boolean orderable) {
|
|
||||||
this.orderable = orderable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Search getSearch() {
|
|
||||||
return search;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSearch(Search search) {
|
|
||||||
this.search = search;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Column [data=" + data + ", name=" + name + ", searchable=" + searchable + ", orderable=" + orderable
|
|
||||||
+ ", search=" + search + "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.datatables;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DataTablesRequest {
|
|
||||||
private int start;
|
|
||||||
private int length;
|
|
||||||
private int draw;
|
|
||||||
private List<Order> order;
|
|
||||||
private List<Column> columns;
|
|
||||||
private Search search;
|
|
||||||
|
|
||||||
public int getStart() {
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStart(int start) {
|
|
||||||
this.start = start;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLength() {
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLength(int length) {
|
|
||||||
this.length = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDraw() {
|
|
||||||
return draw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDraw(int draw) {
|
|
||||||
this.draw = draw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Order> getOrder() {
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrder(List<Order> order) {
|
|
||||||
this.order = order;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Column> getColumns() {
|
|
||||||
return columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColumns(List<Column> columns) {
|
|
||||||
this.columns = columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Search getSearch() {
|
|
||||||
return search;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSearch(Search search) {
|
|
||||||
this.search = search;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "DataTablesRequest [start=" + start + ", length=" + length + ", draw=" + draw + ", order=" + order
|
|
||||||
+ ", columns=" + columns + ", search=" + search + "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.datatables;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DataTablesResponse<T> {
|
|
||||||
public DataTablesResponse(List<T> data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<T> data;
|
|
||||||
private long recordsFiltered;
|
|
||||||
private long recordsTotal;
|
|
||||||
private int draw;
|
|
||||||
private String error;
|
|
||||||
|
|
||||||
public List<T> getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(List<T> data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getRecordsFiltered() {
|
|
||||||
return recordsFiltered;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRecordsFiltered(long recordsFiltered) {
|
|
||||||
this.recordsFiltered = recordsFiltered;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getRecordsTotal() {
|
|
||||||
return recordsTotal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRecordsTotal(long recordsTotal) {
|
|
||||||
this.recordsTotal = recordsTotal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDraw() {
|
|
||||||
return draw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDraw(int draw) {
|
|
||||||
this.draw = draw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getError() {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setError(String error) {
|
|
||||||
this.error = error;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "DataTablesResponse [data=" + data + ", recordsFiltered=" + recordsFiltered + ", recordsTotal="
|
|
||||||
+ recordsTotal + ", draw=" + draw + ", error=" + error + "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.datatables;
|
|
||||||
|
|
||||||
public enum Direction {
|
|
||||||
asc, desc;
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.datatables;
|
|
||||||
|
|
||||||
public class Order {
|
|
||||||
private Integer column;
|
|
||||||
private Direction dir;
|
|
||||||
|
|
||||||
public Integer getColumn() {
|
|
||||||
return column;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setColumn(Integer column) {
|
|
||||||
this.column = column;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Direction getDir() {
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDir(Direction dir) {
|
|
||||||
this.dir = dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Order [column=" + column + ", dir=" + dir + "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.datatables;
|
|
||||||
|
|
||||||
public class Search {
|
|
||||||
private String value;
|
|
||||||
private String regexp;
|
|
||||||
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRegexp() {
|
|
||||||
return regexp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRegexp(String regexp) {
|
|
||||||
this.regexp = regexp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Search [value=" + value + ", regexp=" + regexp + "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,186 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.socket;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import javax.validation.constraints.Positive;
|
|
||||||
import javax.validation.constraints.PositiveOrZero;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
@Entity
|
|
||||||
public class BytesMessageSpec implements Serializable {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Column(length = 100, nullable = false)
|
|
||||||
private String specName;
|
|
||||||
|
|
||||||
@Column(length = 1)
|
|
||||||
private String llFieldInclude;
|
|
||||||
|
|
||||||
@Column(length = 1)
|
|
||||||
private String llFieldLengthInclude;
|
|
||||||
|
|
||||||
@Positive
|
|
||||||
@NotNull
|
|
||||||
private Integer llFieldLength;
|
|
||||||
|
|
||||||
private Integer llFieldLengthAlpha;
|
|
||||||
|
|
||||||
@PositiveOrZero
|
|
||||||
private Integer llFieldOffset;
|
|
||||||
|
|
||||||
@Column(length = 20)
|
|
||||||
private String llFieldType;
|
|
||||||
|
|
||||||
@Column(length = 20)
|
|
||||||
private String encode;
|
|
||||||
|
|
||||||
@Positive
|
|
||||||
@NotNull
|
|
||||||
private Integer port;
|
|
||||||
|
|
||||||
@Positive
|
|
||||||
private Integer sleepSeconds;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
@Lob
|
|
||||||
private String responseBody;
|
|
||||||
|
|
||||||
@Column(length = 1)
|
|
||||||
private String useYn;
|
|
||||||
|
|
||||||
@Valid
|
|
||||||
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
|
|
||||||
@JoinColumn(name = "BYTE_MESSAGE_SPEC_ID")
|
|
||||||
@OrderBy("position")
|
|
||||||
private List<EchoReplaceString> echoReplaceStringList = new ArrayList<EchoReplaceString>();
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSpecName() {
|
|
||||||
return specName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSpecName(String specName) {
|
|
||||||
this.specName = specName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLlFieldInclude() {
|
|
||||||
return llFieldInclude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLlFieldInclude(String llFieldInclude) {
|
|
||||||
this.llFieldInclude = llFieldInclude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLlFieldLengthInclude() {
|
|
||||||
return llFieldLengthInclude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLlFieldLengthInclude(String llFieldLengthInclude) {
|
|
||||||
this.llFieldLengthInclude = llFieldLengthInclude;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getLlFieldLength() {
|
|
||||||
return llFieldLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLlFieldLength(Integer llFieldLength) {
|
|
||||||
this.llFieldLength = llFieldLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getLlFieldLengthAlpha() {
|
|
||||||
return llFieldLengthAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLlFieldLengthAlpha(Integer llFieldLengthAlpha) {
|
|
||||||
this.llFieldLengthAlpha = llFieldLengthAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getLlFieldOffset() {
|
|
||||||
return llFieldOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLlFieldOffset(Integer llFieldOffset) {
|
|
||||||
this.llFieldOffset = llFieldOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLlFieldType() {
|
|
||||||
return llFieldType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLlFieldType(String llFieldType) {
|
|
||||||
this.llFieldType = llFieldType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEncode() {
|
|
||||||
return encode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEncode(String encode) {
|
|
||||||
this.encode = encode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getPort() {
|
|
||||||
return port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPort(Integer port) {
|
|
||||||
this.port = port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getSleepSeconds() {
|
|
||||||
return sleepSeconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSleepSeconds(Integer sleepSeconds) {
|
|
||||||
this.sleepSeconds = sleepSeconds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getResponseBody() {
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResponseBody(String responseBody) {
|
|
||||||
this.responseBody = responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUseYn() {
|
|
||||||
return useYn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUseYn(String useYn) {
|
|
||||||
this.useYn = useYn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<EchoReplaceString> getEchoReplaceStringList() {
|
|
||||||
return echoReplaceStringList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEchoReplaceStringList(List<EchoReplaceString> echoReplaceStringList) {
|
|
||||||
this.echoReplaceStringList = echoReplaceStringList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "BytesMessageSpec [id=" + id + ", specName=" + specName + ", llFieldInclude=" + llFieldInclude
|
|
||||||
+ ", llFieldLengthInclude=" + llFieldLengthInclude + ", llFieldLength=" + llFieldLength
|
|
||||||
+ ", llFieldLengthAlpha=" + llFieldLengthAlpha + ", llFieldOffset=" + llFieldOffset + ", llFieldType="
|
|
||||||
+ llFieldType + ", encode=" + encode + ", port=" + port + ", sleepSeconds=" + sleepSeconds
|
|
||||||
+ ", responseBody=" + responseBody + ", useYn=" + useYn + ", EchoReplaceStringList="
|
|
||||||
+ echoReplaceStringList + "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.socket;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.Modifying;
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface BytesMessageSpecDao extends JpaRepository<BytesMessageSpec, Long> {
|
|
||||||
BytesMessageSpec findFirstByUseYn(String useYn);
|
|
||||||
|
|
||||||
@Modifying
|
|
||||||
@Query(value = "update BytesMessageSpec b set b.useYn='N' where b.id <> ?1")
|
|
||||||
void updateUnuseOthers(Long id);
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.socket;
|
|
||||||
|
|
||||||
import org.springframework.data.domain.Example;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface BytesMessageSpecService {
|
|
||||||
public BytesMessageSpec findActiveBytesMessageSpec();
|
|
||||||
|
|
||||||
public List<BytesMessageSpec> findAllBytesMessageSpecs(Pageable pageable);
|
|
||||||
|
|
||||||
public List<BytesMessageSpec> findAllBytesMessageSpecs(Example<BytesMessageSpec> example, Pageable pageable);
|
|
||||||
|
|
||||||
public long getRecordsCount(Example<BytesMessageSpec> example);
|
|
||||||
|
|
||||||
public Optional<BytesMessageSpec> findById(Long id);
|
|
||||||
|
|
||||||
public BytesMessageSpec save(BytesMessageSpec spec);
|
|
||||||
|
|
||||||
public BytesMessageSpec update(BytesMessageSpec spec);
|
|
||||||
|
|
||||||
public void delete(Long id);
|
|
||||||
|
|
||||||
public void setUnuseOthers(Long id);
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.socket;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.domain.Example;
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Transactional(propagation = Propagation.SUPPORTS)
|
|
||||||
public class BytesMessageSpecServiceImpl implements BytesMessageSpecService {
|
|
||||||
@Autowired
|
|
||||||
private BytesMessageSpecDao dao;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BytesMessageSpec findActiveBytesMessageSpec() {
|
|
||||||
return dao.findFirstByUseYn("Y");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<BytesMessageSpec> findAllBytesMessageSpecs(Pageable pageable) {
|
|
||||||
Page<BytesMessageSpec> pagedResult = dao.findAll(pageable);
|
|
||||||
if (pagedResult.hasContent()) {
|
|
||||||
return pagedResult.getContent();
|
|
||||||
} else {
|
|
||||||
return new ArrayList<BytesMessageSpec>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<BytesMessageSpec> findAllBytesMessageSpecs(Example<BytesMessageSpec> example, Pageable pageable) {
|
|
||||||
if (example == null) {
|
|
||||||
return findAllBytesMessageSpecs(pageable);
|
|
||||||
}
|
|
||||||
|
|
||||||
Page<BytesMessageSpec> pagedResult = dao.findAll(example, pageable);
|
|
||||||
if (pagedResult.hasContent()) {
|
|
||||||
return pagedResult.getContent();
|
|
||||||
} else {
|
|
||||||
return new ArrayList<BytesMessageSpec>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<BytesMessageSpec> findById(Long id) {
|
|
||||||
return dao.findById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getRecordsCount(Example<BytesMessageSpec> example) {
|
|
||||||
if (example == null) {
|
|
||||||
return dao.count();
|
|
||||||
} else {
|
|
||||||
return dao.count(example);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
|
|
||||||
public BytesMessageSpec save(BytesMessageSpec spec) {
|
|
||||||
return dao.save(spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
|
|
||||||
public BytesMessageSpec update(BytesMessageSpec spec) {
|
|
||||||
return dao.save(spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
|
|
||||||
public void delete(Long id) {
|
|
||||||
dao.deleteById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
|
|
||||||
public void setUnuseOthers(Long id) {
|
|
||||||
dao.updateUnuseOthers(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.socket;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import javax.validation.constraints.PositiveOrZero;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
@Entity
|
|
||||||
public class EchoReplaceString implements Serializable {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@PositiveOrZero
|
|
||||||
@NotNull
|
|
||||||
@Column(nullable = false)
|
|
||||||
private Integer position;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
@Column(length = 5000, nullable = false)
|
|
||||||
private String replaceString;
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getPosition() {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPosition(Integer position) {
|
|
||||||
this.position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getReplaceString() {
|
|
||||||
return replaceString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReplaceString(String replaceString) {
|
|
||||||
this.replaceString = replaceString;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "EchoReplaceString [id=" + id + ", position=" + position + ", replaceString=" + replaceString + "]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.socket;
|
|
||||||
|
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
|
||||||
import io.netty.channel.*;
|
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
|
||||||
import io.netty.channel.socket.SocketChannel;
|
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
import javax.persistence.NoResultException;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class EchoSocketServer {
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
||||||
|
|
||||||
private BytesMessageSpec spec;
|
|
||||||
|
|
||||||
EventLoopGroup bossGroup;
|
|
||||||
EventLoopGroup workerGroup;
|
|
||||||
ChannelFuture channelFuture;
|
|
||||||
|
|
||||||
public EchoSocketServer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public EchoSocketServer(BytesMessageSpec spec) {
|
|
||||||
this.spec = spec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() throws Exception {
|
|
||||||
if (spec == null) {
|
|
||||||
throw new NoResultException();
|
|
||||||
}
|
|
||||||
|
|
||||||
int port = (spec.getPort() == null ? 38181 : spec.getPort().intValue());
|
|
||||||
bossGroup = new NioEventLoopGroup();
|
|
||||||
workerGroup = new NioEventLoopGroup();
|
|
||||||
try {
|
|
||||||
ServerBootstrap server = new ServerBootstrap();
|
|
||||||
// @formatter:off
|
|
||||||
server.group(bossGroup, workerGroup)
|
|
||||||
.channel(NioServerSocketChannel.class)
|
|
||||||
.childHandler(new ChannelInitializer<SocketChannel>() {
|
|
||||||
@Override
|
|
||||||
protected void initChannel(SocketChannel ch) throws Exception {
|
|
||||||
ChannelPipeline pipeline = ch.pipeline();
|
|
||||||
pipeline.addLast(new LengthHeaderFrameDecoder(spec));
|
|
||||||
pipeline.addLast(new EchoSocketServerHandler(spec));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.option(ChannelOption.SO_BACKLOG, 128)
|
|
||||||
.childOption(ChannelOption.SO_KEEPALIVE, false);
|
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
channelFuture = server.bind(port).sync();
|
|
||||||
channelFuture.channel().closeFuture().sync().channel();
|
|
||||||
logger.info(port + " port bounded");
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
bossGroup.shutdownGracefully();
|
|
||||||
workerGroup.shutdownGracefully();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreDestroy
|
|
||||||
public void stop() {
|
|
||||||
try {
|
|
||||||
bossGroup.shutdownGracefully().sync();
|
|
||||||
workerGroup.shutdownGracefully().sync();
|
|
||||||
channelFuture.channel().closeFuture().sync();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.socket;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.ByteBufUtil;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import io.netty.channel.ChannelHandler.Sharable;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Sharable
|
|
||||||
public class EchoSocketServerHandler extends ChannelInboundHandlerAdapter {
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
||||||
|
|
||||||
private BytesMessageSpec spec;
|
|
||||||
|
|
||||||
public EchoSocketServerHandler() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public EchoSocketServerHandler(BytesMessageSpec spec) {
|
|
||||||
this.spec = spec;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handlerAdded(ChannelHandlerContext ctx) {
|
|
||||||
logger.info("EchoSocketServer handlerAdded");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void channelActive(ChannelHandlerContext ctx) {
|
|
||||||
logger.info("Remote Address: " + ctx.channel().remoteAddress().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
|
||||||
logger.info("EchoSocketServer channelRead");
|
|
||||||
|
|
||||||
try {
|
|
||||||
spec.setEncode(StringUtils.defaultIfBlank(spec.getEncode(), "euc-kr"));
|
|
||||||
String message = new String(ByteBufUtil.getBytes((ByteBuf) msg), spec.getEncode());
|
|
||||||
logger.info("==================================================");
|
|
||||||
logger.info("Received Message=" + message);
|
|
||||||
logger.info("==================================================");
|
|
||||||
|
|
||||||
// length + content
|
|
||||||
String responseMsg = assignResponseMessage(message);
|
|
||||||
logger.info("==================================================");
|
|
||||||
logger.info("Response Message=" + responseMsg);
|
|
||||||
logger.info("==================================================");
|
|
||||||
|
|
||||||
// sleep
|
|
||||||
if (spec.getSleepSeconds() != null) {
|
|
||||||
int sleepSeconds = spec.getSleepSeconds().intValue();
|
|
||||||
if (sleepSeconds > 0) {
|
|
||||||
logger.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
||||||
logger.info("Start Sleep {} Seconds.", sleepSeconds);
|
|
||||||
logger.info("...");
|
|
||||||
Thread.sleep(sleepSeconds * 1000l);
|
|
||||||
logger.info("......");
|
|
||||||
logger.info("Finished Sleep {} Seconds.", sleepSeconds);
|
|
||||||
logger.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.write(Unpooled.wrappedBuffer(responseMsg.getBytes(spec.getEncode())));
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String assignResponseMessage(String body) throws UnsupportedEncodingException {
|
|
||||||
int llFieldLength = (spec.getLlFieldLength() == null ? 8 : spec.getLlFieldLength().intValue());
|
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(spec.getResponseBody())) {
|
|
||||||
return appendLengthField(StringUtils.substring(spec.getResponseBody(), llFieldLength), spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spec.getEchoReplaceStringList() != null) {
|
|
||||||
byte[] bytes = body.getBytes(spec.getEncode());
|
|
||||||
for (EchoReplaceString echoReplaceString : spec.getEchoReplaceStringList()) {
|
|
||||||
bytes = replaceString(bytes, echoReplaceString.getPosition().intValue(),
|
|
||||||
echoReplaceString.getReplaceString().getBytes(spec.getEncode()), llFieldLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
body = new String(bytes, spec.getEncode());
|
|
||||||
}
|
|
||||||
|
|
||||||
return appendLengthField(body, spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] replaceString(byte[] bytes, int position, byte[] replaceBytes, int llFieldLength) {
|
|
||||||
int idx = position - llFieldLength;
|
|
||||||
if (idx < 0 || bytes.length < idx) {
|
|
||||||
logger.warn("//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**");
|
|
||||||
logger.warn("//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**");
|
|
||||||
logger.warn("invalid postion(MessageSize={}, postion={})", bytes.length + llFieldLength, position);
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bytes.length < idx + replaceBytes.length) {
|
|
||||||
byte[] newBytes = new byte[idx + replaceBytes.length];
|
|
||||||
System.arraycopy(bytes, 0, newBytes, 0, idx);
|
|
||||||
System.arraycopy(replaceBytes, 0, newBytes, idx, replaceBytes.length);
|
|
||||||
return newBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
System.arraycopy(replaceBytes, 0, bytes, idx, replaceBytes.length);
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String appendLengthField(String body, BytesMessageSpec spec) throws UnsupportedEncodingException {
|
|
||||||
int llFieldLength = (spec.getLlFieldLength() == null ? 8 : spec.getLlFieldLength().intValue());
|
|
||||||
int length = body.getBytes(spec.getEncode()).length;
|
|
||||||
if (BooleanUtils.toBoolean(spec.getLlFieldLengthInclude())) {
|
|
||||||
length += llFieldLength;
|
|
||||||
}
|
|
||||||
return String.format("%0" + llFieldLength + "d%s", length, body);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
|
||||||
logger.info("EchoSocketServer channelReadComplete");
|
|
||||||
ctx.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handlerRemoved(ChannelHandlerContext ctx) {
|
|
||||||
logger.info("EchoSocketServer handlerRemoved");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
|
||||||
ctx.close();
|
|
||||||
cause.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.socket;
|
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.ByteBufUtil;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import io.netty.handler.codec.ReplayingDecoder;
|
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class LengthHeaderFrameDecoder extends ReplayingDecoder<Void> {
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
||||||
|
|
||||||
private boolean readLength;
|
|
||||||
private int length;
|
|
||||||
private BytesMessageSpec spec;
|
|
||||||
|
|
||||||
public LengthHeaderFrameDecoder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public LengthHeaderFrameDecoder(BytesMessageSpec spec) {
|
|
||||||
this.spec = spec;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
|
|
||||||
int llFieldLength = (spec.getLlFieldLength() == null ? 8 : spec.getLlFieldLength().intValue());
|
|
||||||
|
|
||||||
if (!readLength) {
|
|
||||||
ByteBuf lengthFrame = buf.readBytes(llFieldLength);
|
|
||||||
length = assignMessageLength(ByteBufUtil.getBytes(lengthFrame));
|
|
||||||
readLength = true;
|
|
||||||
logger.info("MessageLength = " + length);
|
|
||||||
checkpoint();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (readLength) {
|
|
||||||
int contentLength = (BooleanUtils.toBoolean(spec.getLlFieldLengthInclude()) ? length - llFieldLength
|
|
||||||
: length);
|
|
||||||
ByteBuf frame = buf.readBytes(contentLength);
|
|
||||||
readLength = false;
|
|
||||||
checkpoint();
|
|
||||||
out.add(frame);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int assignMessageLength(byte[] bytes) {
|
|
||||||
String lengthStr = new String(bytes);
|
|
||||||
return NumberUtils.toInt(lengthStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.script.dynamic;
|
|
||||||
import com.eactive.httpmockserver.script.Script;
|
|
||||||
//IMPORT 클래스는 여기에 정의해 주세요
|
|
||||||
|
|
||||||
public class implements Script{
|
|
||||||
/**
|
|
||||||
* Script Process Function
|
|
||||||
* @param requestMessage 수신 받은 요청 메시지
|
|
||||||
* @param responseMessage 정의된 응답 메시지
|
|
||||||
* @return 스크립트 수행 후 응답 할 메시지
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public String postProcess(String requestMessage, String responseMessage) throws Exception {
|
|
||||||
return responseMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user