Socket Echo 기능 추가
This commit is contained in:
@@ -26,7 +26,7 @@ public class ApiManageController {
|
||||
|
||||
@GetMapping("/manage/findAllApis")
|
||||
public String getAllApis(Pageable pageable, Model model) {
|
||||
model.addAttribute("apiInfoList", apiService.findAllApis(pageable));
|
||||
//model.addAttribute("apiInfoList", apiService.findAllApis(pageable));
|
||||
return "page/list-api";
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ public class ApiServiceImpl implements ApiService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
|
||||
public void delete(Long id) {
|
||||
apiDao.deleteById(id);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.eactive.httpmockserver.socket;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
@@ -14,7 +15,9 @@ import javax.persistence.JoinColumn;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OrderBy;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Positive;
|
||||
import javax.validation.constraints.PositiveOrZero;
|
||||
|
||||
@@ -36,6 +39,7 @@ public class BytesMessageSpec implements Serializable {
|
||||
private String llFieldLengthInclude;
|
||||
|
||||
@Positive
|
||||
@NotNull
|
||||
private Integer llFieldLength;
|
||||
|
||||
private Integer llFieldLengthAlpha;
|
||||
@@ -50,6 +54,7 @@ public class BytesMessageSpec implements Serializable {
|
||||
private String encode;
|
||||
|
||||
@Positive
|
||||
@NotNull
|
||||
private Integer port;
|
||||
|
||||
@Positive
|
||||
@@ -62,10 +67,11 @@ public class BytesMessageSpec implements Serializable {
|
||||
@Column(length = 1)
|
||||
private String useYn;
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||
@Valid
|
||||
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
@JoinColumn(name = "BYTE_MESSAGE_SPEC_ID")
|
||||
@OrderBy("position")
|
||||
private List<EchoReplaceString> EchoReplaceStringList;
|
||||
private List<EchoReplaceString> echoReplaceStringList = new ArrayList<EchoReplaceString>();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@@ -172,11 +178,11 @@ public class BytesMessageSpec implements Serializable {
|
||||
}
|
||||
|
||||
public List<EchoReplaceString> getEchoReplaceStringList() {
|
||||
return EchoReplaceStringList;
|
||||
return echoReplaceStringList;
|
||||
}
|
||||
|
||||
public void setEchoReplaceStringList(List<EchoReplaceString> echoReplaceStringList) {
|
||||
EchoReplaceStringList = echoReplaceStringList;
|
||||
this.echoReplaceStringList = echoReplaceStringList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -186,6 +192,6 @@ public class BytesMessageSpec implements Serializable {
|
||||
+ ", llFieldLengthAlpha=" + llFieldLengthAlpha + ", llFieldOffset=" + llFieldOffset + ", llFieldType="
|
||||
+ llFieldType + ", encode=" + encode + ", port=" + port + ", sleepSeconds=" + sleepSeconds
|
||||
+ ", responseBody=" + responseBody + ", useYn=" + useYn + ", EchoReplaceStringList="
|
||||
+ EchoReplaceStringList + "]";
|
||||
+ echoReplaceStringList + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
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,5 +1,27 @@
|
||||
package com.eactive.httpmockserver.socket;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
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,6 +1,13 @@
|
||||
package com.eactive.httpmockserver.socket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
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;
|
||||
@@ -15,4 +22,66 @@ public class BytesMessageSpecServiceImpl implements BytesMessageSpecService {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.PositiveOrZero;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@@ -17,8 +18,8 @@ public class EchoReplaceString implements Serializable {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@NotBlank
|
||||
@PositiveOrZero
|
||||
@NotNull
|
||||
@Column(nullable = false)
|
||||
private Integer position;
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class EchoSocketServer {
|
||||
workerGroup.shutdownGracefully().sync();
|
||||
channelFuture.channel().closeFuture().sync();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,35 @@
|
||||
package com.eactive.httpmockserver.socket;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.ExampleMatcher;
|
||||
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatcher;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.eactive.httpmockserver.ApiManageRestController;
|
||||
import com.eactive.httpmockserver.datatables.DataTablesRequest;
|
||||
import com.eactive.httpmockserver.datatables.DataTablesResponse;
|
||||
|
||||
@Controller
|
||||
public class SocketServerManageController {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
@@ -20,6 +39,89 @@ public class SocketServerManageController {
|
||||
|
||||
private EchoSocketServer echoSocketServer;
|
||||
|
||||
@GetMapping("/manage/findAllBytesMessageSpecs")
|
||||
public String getAllBytesMessageSpecs(Pageable pageable, Model model) {
|
||||
return "page/list-bytes-message-spec";
|
||||
}
|
||||
|
||||
@GetMapping(path = { "/manage/getBytesMessageSpecForm", "/manage/getBytesMessageSpecForm/{id}" })
|
||||
public String getBytesMessageSpecForm(Model model, @PathVariable Optional<Long> id) {
|
||||
if (id.isPresent()) {
|
||||
Optional<BytesMessageSpec> optional = specService.findById(id.get());
|
||||
if (optional.isPresent()) {
|
||||
model.addAttribute("bytesMessageSpec", optional.get());
|
||||
} else {
|
||||
throw new IllegalArgumentException("No data, id: " + id.get());
|
||||
}
|
||||
} else {
|
||||
BytesMessageSpec spec = new BytesMessageSpec();
|
||||
model.addAttribute("bytesMessageSpec", spec);
|
||||
}
|
||||
|
||||
return "page/add-edit-bytes-message-spec";
|
||||
}
|
||||
|
||||
@PostMapping("/manage/saveBytesMessageSpec")
|
||||
public String saveBytesMessageSpec(@Valid BytesMessageSpec spec, BindingResult result, Model model) {
|
||||
if (result.hasErrors()) {
|
||||
return "page/add-edit-bytes-message-spec";
|
||||
}
|
||||
|
||||
if (spec.getId() == null) {
|
||||
specService.save(spec);
|
||||
} else {
|
||||
specService.update(spec);
|
||||
}
|
||||
|
||||
if (BooleanUtils.toBoolean(spec.getUseYn())) {
|
||||
// 기존서버 중지
|
||||
stop();
|
||||
|
||||
// 기존설정 useYn=N으로 수정
|
||||
specService.setUnuseOthers(spec.getId());
|
||||
|
||||
// 서버 기동
|
||||
start();
|
||||
}
|
||||
|
||||
return "redirect:/manage/findAllBytesMessageSpecs";
|
||||
}
|
||||
|
||||
@PostMapping("/manage/rest/bytesMessageSpecs")
|
||||
@ResponseBody
|
||||
public DataTablesResponse<BytesMessageSpec> getAllApisForDatatables(@RequestBody DataTablesRequest req) {
|
||||
Pageable pageable = ApiManageRestController.assignJpaPageable(req);
|
||||
|
||||
// search option
|
||||
Example<BytesMessageSpec> example = null;
|
||||
if (StringUtils.isNotBlank(req.getSearch().getValue())) {
|
||||
BytesMessageSpec spec = new BytesMessageSpec();
|
||||
spec.setSpecName(req.getSearch().getValue());
|
||||
|
||||
ExampleMatcher matcher = ExampleMatcher.matchingAny().withMatcher("specName",
|
||||
new GenericPropertyMatcher().contains().ignoreCase());
|
||||
example = Example.of(spec, matcher);
|
||||
}
|
||||
|
||||
DataTablesResponse<BytesMessageSpec> res = new DataTablesResponse<BytesMessageSpec>(
|
||||
specService.findAllBytesMessageSpecs(example, pageable));
|
||||
res.setRecordsFiltered(specService.getRecordsCount(example));
|
||||
res.setRecordsTotal(specService.getRecordsCount(null));
|
||||
res.setDraw(req.getDraw());
|
||||
return res;
|
||||
}
|
||||
|
||||
@RequestMapping("/manage/deleteBytesMessageSpec/{id}")
|
||||
public String deleteBytesMessageSpec(@PathVariable Long id) {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("No data, id: " + id);
|
||||
}
|
||||
|
||||
specService.delete(id);
|
||||
|
||||
return "redirect:/manage/findAllBytesMessageSpecs";
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void start() {
|
||||
logger.info("EchoSocketServer starting..");
|
||||
|
||||
Reference in New Issue
Block a user