Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uploaded 1.0.0-SNAPSHOT of full project source
- Loading branch information
Matthew Gallina
authored and
Matthew Gallina
committed
Aug 2, 2017
1 parent
01ec7c8
commit 28fe45b
Showing
112 changed files
with
8,122 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
logs | ||
project/project | ||
project/target | ||
target | ||
tmp | ||
.history | ||
dist | ||
/.idea | ||
/*.iml | ||
/out | ||
/.idea_modules | ||
/.classpath | ||
/.project | ||
/RUNNING_PID | ||
/.settings | ||
/.target | ||
.DS_Store | ||
.cache | ||
/bin | ||
*.pid | ||
src/main/main.iml | ||
binary/lib/smockin-*-SNAPSHOT.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Constants | ||
# | ||
|
||
ADMIN_PORT=8000 | ||
ADMIN_BASE_URL="http://localhost:$ADMIN_PORT" | ||
|
||
|
||
|
||
|
||
# | ||
# ADD SAMPLE DATA | ||
# | ||
|
||
printf "\n" | ||
printf "Installing sample data..." | ||
printf "\n\n" | ||
|
||
# Get All Homes example | ||
DEF_RESPONSE_BODY_1='"[{\"id\" : 1,\"line1\":\"1 Privet Drive\",\"line2\":\"\",\"city\":\"Martins Heron\",\"county\":\"Berkshire\",\"postcode\":\"RG40 1ZZ\",\"country\":\"GB\"},{\"id\" : 2,\"line1\":\"2 Privet Drive\",\"line2\":\"\",\"city\":\"Martins Heron\",\"county\":\"Berkshire\",\"postcode\":\"RG40 1ZZ\",\"country\":\"GB\"}]"' | ||
DEFINITIONS_1="[{\"extId\":null,\"orderNo\":1,\"responseContentType\":\"application/json\",\"httpStatusCode\":200,\"responseBody\":$DEF_RESPONSE_BODY_1,\"responseHeaders\":{}}]" | ||
REQ_DATA_1="{\"path\":\"/homes\",\"method\":\"GET\",\"status\":\"ACTIVE\",\"mockType\":\"SEQ\",\"definitions\":$DEFINITIONS_1,\"rules\":[]}" | ||
curl -i -H "Content-Type: application/json" -X POST "$ADMIN_BASE_URL/restmock" -d "$REQ_DATA_1" | ||
|
||
|
||
# Sequenced example | ||
DEF_RESPONSE_BODY_2='"{\"id\" : 1,\"line1\":\"1 Privet Drive\",\"line2\":\"\",\"city\":\"Martins Heron\",\"county\":\"Berkshire\",\"postcode\":\"RG40 1ZZ\",\"country\":\"GB\"}"' | ||
DEF_RESPONSE_BODY_3='"{\"id\" : 2,\"line1\":\"2 Privet Drive\",\"line2\":\"\",\"city\":\"Martins Heron\",\"county\":\"Berkshire\",\"postcode\":\"RG40 1ZZ\",\"country\":\"GB\"}"' | ||
DEF_RESPONSE_BODY_4='"{\"id\" : 3,\"line1\":\"3 Privet Drive\",\"line2\":\"\",\"city\":\"Martins Heron\",\"county\":\"Berkshire\",\"postcode\":\"RG40 1ZZ\",\"country\":\"GB\"}"' | ||
DEFINITIONS_2="[{\"extId\":\"de8ed629-2ce3-46ca-a85c-e6a0fbb1ff0e\",\"orderNo\":1,\"httpStatusCode\":200,\"responseContentType\":\"application/json\",\"responseBody\":$DEF_RESPONSE_BODY_2,\"responseHeaders\":{}},{\"extId\":\"e81e44d5-d2aa-4e7a-8e8a-d530ec40362e\",\"orderNo\":2,\"httpStatusCode\":200,\"responseContentType\":\"application/json\",\"responseBody\":$DEF_RESPONSE_BODY_3,\"responseHeaders\":{}},{\"extId\":\"0bc0d0a2-9cf3-4a25-b141-5bdf3ed99052\",\"orderNo\":3,\"httpStatusCode\":200,\"responseContentType\":\"application/json\",\"responseBody\":$DEF_RESPONSE_BODY_4,\"responseHeaders\":{}}]" | ||
REQ_DATA_2="{\"path\":\"/homes/seq\",\"method\":\"GET\",\"status\":\"ACTIVE\",\"mockType\":\"SEQ\",\"definitions\":$DEFINITIONS_2,\"rules\":[]}" | ||
curl -i -H "Content-Type: application/json" -X POST "$ADMIN_BASE_URL/restmock" -d "$REQ_DATA_2" | ||
|
||
|
||
# Rules example | ||
RULE_RESPONSE_BODY_1='"{\"id\" : 1,\"line1\":\"1 Privet Drive\",\"line2\":\"\",\"city\":\"Martins Heron\",\"county\":\"Berkshire\",\"postcode\":\"RG40 1ZZ\",\"country\":\"GB\"}"' | ||
RULE_RESPONSE_BODY_2='"{\"id\" : 2,\"line1\":\"2 Privet Drive\",\"line2\":\"\",\"city\":\"Martins Heron\",\"county\":\"Berkshire\",\"postcode\":\"RG40 1ZZ\",\"country\":\"GB\"}"' | ||
RULE_RESPONSE_BODY_3='"{\"id\" : 3,\"line1\":\"3 Privet Drive\",\"line2\":\"\",\"city\":\"Martins Heron\",\"county\":\"Berkshire\",\"postcode\":\"RG40 1ZZ\",\"country\":\"GB\"}"' | ||
RULES_1="[{\"extId\":null,\"orderNo\":1,\"httpStatusCode\":200,\"responseContentType\":\"application/json\",\"responseBody\":$RULE_RESPONSE_BODY_1,\"responseHeaders\":{},\"groups\":[{\"extId\":null,\"orderNo\":1,\"conditions\":[{\"extId\":null,\"ruleMatchingType\":\"PATH_VARIABLE\",\"field\":\"id\",\"comparator\":\"EQUALS\",\"dataType\":\"NUMERIC\",\"caseSensitive\":false,\"value\":\"1\"}]}]},{\"extId\":null,\"orderNo\":2,\"httpStatusCode\":200,\"responseContentType\":\"application/json\",\"responseBody\":$RULE_RESPONSE_BODY_2,\"responseHeaders\":{},\"groups\":[{\"extId\":null,\"orderNo\":1,\"conditions\":[{\"extId\":null,\"ruleMatchingType\":\"PATH_VARIABLE\",\"field\":\"id\",\"comparator\":\"EQUALS\",\"dataType\":\"NUMERIC\",\"caseSensitive\":false,\"value\":\"2\"}]}]},{\"extId\":null,\"orderNo\":3,\"responseContentType\":\"application/json\",\"httpStatusCode\":200,\"responseBody\":$RULE_RESPONSE_BODY_3,\"responseHeaders\":{},\"groups\":[{\"extId\":null,\"orderNo\":1,\"conditions\":[{\"extId\":null,\"ruleMatchingType\":\"PATH_VARIABLE\",\"field\":\"id\",\"comparator\":\"EQUALS\",\"dataType\":\"NUMERIC\",\"caseSensitive\":false,\"value\":\"3\"}]}]}]" | ||
DEFINITIONS_3="[{\"extId\":null,\"orderNo\":1,\"responseContentType\":\"application/json\",\"httpStatusCode\":404,\"responseBody\":null,\"responseHeaders\":{}}]" | ||
REQ_DATA_3="{\"path\":\"/home/:id\",\"method\":\"GET\",\"status\":\"ACTIVE\",\"mockType\":\"RULE\",\"definitions\":$DEFINITIONS_3,\"rules\":$RULES_1}" | ||
curl -i -H "Content-Type: application/json" -X POST "$ADMIN_BASE_URL/restmock" -d "$REQ_DATA_3" | ||
|
||
|
||
# Get Auth token example | ||
DEF_RESPONSE_BODY_5='"{\"token\":\"7cf05e96-70cc-440e-9b4d-33633b88c5cc\",\"timestamp\":1500385109565}"' | ||
DEFINITIONS_4="[{\"extId\":null,\"orderNo\":1,\"responseContentType\":\"application/json\",\"httpStatusCode\":200,\"responseBody\":$DEF_RESPONSE_BODY_5,\"responseHeaders\":{}}]" | ||
REQ_DATA_4="{\"path\":\"/auth\",\"method\":\"POST\",\"status\":\"ACTIVE\",\"mockType\":\"SEQ\",\"definitions\":$DEFINITIONS_4,\"rules\":[]}" | ||
curl -i -H "Content-Type: application/json" -X POST "$ADMIN_BASE_URL/restmock" -d "$REQ_DATA_4" | ||
|
||
|
||
# Using Auth token example | ||
RULE_RESPONSE_BODY_4='"{\"id\" : 101,\"line1\":\"101 Privet Drive\",\"line2\":\"\",\"city\":\"Martins Heron\",\"county\":\"Berkshire\",\"postcode\":\"RG40 1ZZ\",\"country\":\"GB\"}"' | ||
RULES_2="[{\"extId\":\"3881a247-6b92-49cb-8e32-4cbd7407d89a\",\"orderNo\":1,\"httpStatusCode\":401,\"responseContentType\":\"application/json\",\"responseBody\":\"\",\"responseHeaders\":{},\"groups\":[{\"extId\":\"8cec8e54-0652-4606-a6bc-08a93a9e343d\",\"orderNo\":1,\"conditions\":[{\"extId\":null,\"ruleMatchingType\":\"REQUEST_HEADER\",\"field\":\"Authorization\",\"comparator\":\"IS_MISSING\",\"dataType\":\"TEXT\",\"caseSensitive\":false,\"value\":null}]}]},{\"extId\":\"d68d715b-6e79-4e77-80e7-bc2c415d64bd\",\"orderNo\":2,\"httpStatusCode\":200,\"responseContentType\":\"application/json\",\"responseBody\":$RULE_RESPONSE_BODY_4,\"responseHeaders\":{\"Wildcard-Home\":\"true\"},\"groups\":[{\"extId\":\"d70b6e29-5a58-4b6a-8eb5-3a0c764f2617\",\"orderNo\":1,\"conditions\":[{\"extId\":null,\"ruleMatchingType\":\"REQUEST_HEADER\",\"field\":\"Authorization\",\"comparator\":\"CONTAINS\",\"dataType\":\"TEXT\",\"caseSensitive\":false,\"value\":\"7cf05e96-70cc-440e-9b4d-33633b88c5cc\"}]}]}]" | ||
DEFINITIONS_5="[{\"extId\":null,\"orderNo\":1,\"responseContentType\":\"application/json\",\"httpStatusCode\":401,\"responseBody\":null,\"responseHeaders\":{}}]" | ||
REQ_DATA_5="{\"path\":\"/home/*/secure\",\"method\":\"GET\",\"status\":\"ACTIVE\",\"mockType\":\"RULE\",\"definitions\":$DEFINITIONS_5,\"rules\":$RULES_2}" | ||
curl -i -H "Content-Type: application/json" -X POST "$ADMIN_BASE_URL/restmock" -d "$REQ_DATA_5" | ||
|
||
printf "\n\n\n" | ||
|
||
|
||
|
||
# | ||
# (Re)Start Mocking Server | ||
# | ||
printf "Stopping Mock Server...\n" | ||
./mockserver/shutdown_rest_mock_server.sh | ||
printf "\n" | ||
printf "Starting Mock Server..." | ||
printf "\n" | ||
./mockserver/start_rest_mock_server.sh | ||
|
||
|
||
printf "\n\n" | ||
printf "\n\n" | ||
|
||
printf "Examples of cURL client calls to mocked endpoints:\n\n" | ||
|
||
printf " curl -i -X GET http://localhost:8001/homes\n\n" | ||
printf " curl -i -X GET http://localhost:8001/homes/seq\n\n" | ||
printf " curl -i -X GET http://localhost:8001/home/1\n\n" | ||
printf " curl -i -X POST '{}' http://localhost:8001/auth\n\n" | ||
printf ' curl -i -H "Authorization: Bearer 7cf05e96-70cc-440e-9b4d-33633b88c5cc" -X GET http://localhost:8001/home/1/secure' | ||
|
||
printf "\n\n\n" | ||
|
||
printf "Completed sample data installation" | ||
|
||
printf "\n\n" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
PORT=8000 | ||
BASE_URL="http://localhost:$PORT" | ||
|
||
curl -i -X POST -H "Content-Type: application/json" -d '{}' $BASE_URL/mockedserver/rest/stop | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
PORT=8000 | ||
BASE_URL="http://localhost:$PORT" | ||
|
||
curl -i -H "Content-Type: application/json" -X POST -d '{}' "$BASE_URL/mockedserver/rest/start" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@echo off | ||
|
||
set APP_DIR_PATH=%userprofile%\.smockin | ||
set DB_DIR_PATH=%APP_DIR_PATH%\db | ||
set DB_DRIVER_DIR_PATH=%DB_DIR_PATH%\driver | ||
set DB_DATA_DIR_PATH=%DB_DIR_PATH%\data | ||
|
||
set H2_JAR_NAME=h2-1.4.194.jar | ||
set DB_PROPS_FILE=db.properties | ||
set APP_PROPS_FILE=app.properties | ||
|
||
IF EXIST %DB_DIR_PATH% ( | ||
|
||
echo Smockin is already installed : '%APP_DIR_PATH%' | ||
|
||
) ELSE ( | ||
|
||
echo Installing .smockin config directory to user home... | ||
|
||
mkdir %DB_DRIVER_DIR_PATH% | ||
echo - Created directory %DB_DRIVER_DIR_PATH% | ||
mkdir %DB_DATA_DIR_PATH% | ||
echo - Created directory %DB_DATA_DIR_PATH% | ||
|
||
copy install\%H2_JAR_NAME% %DB_DRIVER_DIR_PATH%\%H2_JAR_NAME% | ||
echo - Added file %DB_DRIVER_DIR_PATH\%H2_JAR_NAME% | ||
copy install\%DB_PROPS_FILE% %DB_DIR_PATH%\%DB_PROPS_FILE% | ||
echo - Added file %DB_DIR_PATH%\%DB_PROPS_FILE% | ||
copy install\%APP_PROPS_FILE% %APP_DIR_PATH% | ||
echo - Added file %APP_DIR_PATH%\%APP_PROPS_FILE% | ||
|
||
echo The default H2 DB has been installed | ||
|
||
echo Please run start.sh to launch the Smockin Application | ||
|
||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# | ||
# PLEASE LEAVE A SPACE AROUND THE EQUALS SYMBOL LIKE SO: KEY = VALUE | ||
|
||
H2_PORT = 9092 | ||
APP_PORT = 8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# | ||
# PLEASE LEAVE A SPACE AROUND THE EQUALS SYMBOL LIKE SO: KEY = VALUE | ||
|
||
DB_USERNAME = smockin | ||
DB_PASSWORD = smockin | ||
DRIVER_CLASS = org.h2.Driver | ||
JDBC_URL = jdbc:h2:tcp://localhost:{H2.PORT}/{USER.HOME}/.smockin/db/data/smockin_db | ||
HIBERNATE_DIALECT = org.hibernate.dialect.H2Dialect | ||
MAX_POOL_SIZE = 10 | ||
MIN_POOL_SIZE = 10 | ||
|
||
# | ||
# Common Vendor Examples | ||
|
||
# MySQL | ||
#DRIVER_CLASS = com.mysql.jdbc.Driver | ||
#JDBC_URL = jdbc:mysql://localhost:3306/MYSQL_DB_NAME | ||
#HIBERNATE_DIALECT = org.hibernate.dialect.MySQLDialect | ||
|
||
# Oracle 10g | ||
#DRIVER_CLASS = oracle.jdbc.driver.OracleDriver | ||
#JDBC_URL = jdbc:oracle:thin:@HOST:1521:SID_OR_SERVICE_NAME | ||
#HIBERNATE_DIALECT = org.hibernate.dialect.Oracle10gDialect | ||
|
||
# PostgreSQL | ||
#DRIVER_CLASS = org.postgresql.Driver | ||
#JDBC_URL = jdbc:postgresql://HOST:5432/POSTGRESQL_DB_NAME | ||
#HIBERNATE_DIALECT = org.hibernate.dialect.PostgreSQLDialect |
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.smockin; | ||
|
||
import com.smockin.admin.persistence.CoreDataSet; | ||
import com.smockin.admin.service.MockedServerEngineService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.domain.EntityScan; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
/** | ||
* Created by mgallina. | ||
*/ | ||
@SpringBootApplication | ||
@ComponentScan({ "com.smockin.admin", "com.smockin.mockserver" }) | ||
@EnableJpaRepositories("com.smockin.admin.persistence.dao") | ||
@EntityScan("com.smockin.admin.persistence.entity") | ||
class SmockinConfig { | ||
|
||
@Autowired | ||
private CoreDataSet coreDataSet; | ||
|
||
@Autowired | ||
private MockedServerEngineService mockedServerEngineService; | ||
|
||
@PostConstruct | ||
public void after() { | ||
|
||
coreDataSet.exec(); | ||
|
||
mockedServerEngineService.handleServerAutoStart(); | ||
|
||
} | ||
|
||
} | ||
|
||
public class SmockinApp { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SmockinConfig.class, args); | ||
} | ||
|
||
|
||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/smockin/admin/controller/ExceptionHandlerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.smockin.admin.controller; | ||
|
||
import com.smockin.admin.exception.RecordNotFoundException; | ||
import com.smockin.admin.exception.ValidationException; | ||
import com.smockin.mockserver.exception.MockServerException; | ||
import org.springframework.dao.DataIntegrityViolationException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
/** | ||
* Created by mgallina. | ||
*/ | ||
@ControllerAdvice | ||
public class ExceptionHandlerController { | ||
|
||
@ResponseStatus(value= HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(DataIntegrityViolationException.class) | ||
public void badRequest() { | ||
|
||
} | ||
|
||
@ResponseStatus(value= HttpStatus.NOT_FOUND) | ||
@ExceptionHandler(RecordNotFoundException.class) | ||
public void notFound() { | ||
|
||
} | ||
|
||
@ResponseStatus(value= HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(ValidationException.class) | ||
public String ValidationBadRequest(ValidationException ex) { | ||
return ex.getMessage(); | ||
} | ||
|
||
@ResponseStatus(value= HttpStatus.INTERNAL_SERVER_ERROR) | ||
@ExceptionHandler(MockServerException.class) | ||
public void internalServerError(MockServerException ex) { | ||
|
||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/com/smockin/admin/controller/MockedServerEngineController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.smockin.admin.controller; | ||
|
||
import com.smockin.admin.exception.RecordNotFoundException; | ||
import com.smockin.admin.exception.ValidationException; | ||
import com.smockin.admin.persistence.enums.ServerTypeEnum; | ||
import com.smockin.admin.service.MockedServerEngineService; | ||
import com.smockin.mockserver.dto.MockServerState; | ||
import com.smockin.mockserver.dto.MockedServerConfigDTO; | ||
import com.smockin.mockserver.exception.MockServerException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* Created by mgallina. | ||
*/ | ||
@Controller | ||
public class MockedServerEngineController { | ||
|
||
@Autowired | ||
private MockedServerEngineService mockedServerEngineService; | ||
|
||
@RequestMapping(path="/mockedserver/rest/start", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public @ResponseBody ResponseEntity<?> startRest() throws ValidationException, MockServerException { | ||
return new ResponseEntity<MockedServerConfigDTO>(mockedServerEngineService.startRest(), HttpStatus.OK); | ||
} | ||
|
||
@RequestMapping(path="/mockedserver/rest/stop", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public @ResponseBody ResponseEntity<?> stopRest() throws MockServerException { | ||
mockedServerEngineService.shutdownRest(); | ||
return new ResponseEntity<String>(HttpStatus.NO_CONTENT); | ||
} | ||
|
||
@RequestMapping(path="/mockedserver/rest/restart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public @ResponseBody ResponseEntity<?> restartRest() throws MockServerException { | ||
return new ResponseEntity<MockedServerConfigDTO>(mockedServerEngineService.restartRest(), HttpStatus.OK); | ||
} | ||
|
||
@RequestMapping(path="/mockedserver/rest/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public @ResponseBody ResponseEntity<MockServerState> restStatus() throws MockServerException { | ||
return new ResponseEntity<MockServerState>(mockedServerEngineService.getRestServerState(), HttpStatus.OK); | ||
} | ||
|
||
@RequestMapping(path="/mockedserver/config/{serverType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public @ResponseBody ResponseEntity<?> getServerConfig(@PathVariable("serverType") final String serverType) throws ValidationException, RecordNotFoundException { | ||
final ServerTypeEnum type = convertServerType(serverType); | ||
return new ResponseEntity<MockedServerConfigDTO>(mockedServerEngineService.loadServerConfig(type), HttpStatus.OK); | ||
} | ||
|
||
@RequestMapping(path="/mockedserver/config/{serverType}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) | ||
public @ResponseBody ResponseEntity<?> putServerConfig(@PathVariable("serverType") final String serverType, @RequestBody final MockedServerConfigDTO dto) throws ValidationException { | ||
mockedServerEngineService.saveServerConfig(convertServerType(serverType), dto); | ||
return new ResponseEntity<String>(HttpStatus.NO_CONTENT); | ||
} | ||
|
||
ServerTypeEnum convertServerType(final String serverType) throws ValidationException { | ||
|
||
try { | ||
return ServerTypeEnum.valueOf(serverType); | ||
} catch (Throwable ex) { | ||
throw new ValidationException("Invalid serverType value: " + serverType); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.