Skip to content

Commit e33e357

Browse files
author
harshbhardwaj
committed
Fixed transaction service, updated integration test suite
1 parent f875fd5 commit e33e357

22 files changed

+145
-110
lines changed

request-proxy-service/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ dependencies {
4545
testCompile(group: 'org.mockito', name: 'mockito-core', version: '2.18.0')
4646

4747
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
48-
implementation 'com.squareup.okhttp3:okhttp:3.14.6'
48+
compile group: 'org.json', name: 'json', version: '20200518'
49+
4950

5051

5152
}
5253

5354
test {
5455
useJUnitPlatform()
56+
testLogging {
57+
events "passed", "skipped", "failed"
58+
}
5559
}

request-proxy-service/src/main/java/com/freshworks/requestproxy/constant/MessageConstants.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ public interface MessageConstants {
66
public static final String MALFORMED_URL_STRUCTURE = "The Requested URL is not allowed as per the RFC protocol";
77
public static final String MISSING_REQUEST_PARAMS = "Required Parameters are missing in a request";
88
public static final String MAX_LIMIT_REACHED = "Maximum limit is reached to request the resource, please re-try after 1 minute";
9-
public static final String SUCCESS = "Success";
10-
public static final String FAILURE = "Failure";
9+
public static final String REQUEST_TIMEOUT = "The Request has Timed Out";
10+
public static final String CONNECTION_FAILED = "Connection failed, requesting url might not exist or refused to set up connection";
11+
public static final String EXCEPTION = "Exception Occur while executing the request on the URL";
12+
public static final String SUCCESS = "The request is successful";
13+
public static final String FAILURE = "The request has failed";
1114
}

request-proxy-service/src/main/java/com/freshworks/requestproxy/entity/requestEntity/CommonRequest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
package com.freshworks.requestproxy.entity.requestEntity;
22

3-
import com.google.gson.JsonObject;
3+
import io.swagger.annotations.ApiModel;
4+
import io.swagger.annotations.ApiModelProperty;
45
import lombok.Data;
6+
import org.json.JSONObject;
57

68
import java.io.Serializable;
79

810
@Data
11+
@ApiModel(description = "A common request entity for incoming request to replay by the system")
912
public class CommonRequest implements Serializable {
1013

14+
@ApiModelProperty(value = "A client Id could be unique identifier for a requesting client")
1115
private Long clientId;
16+
17+
@ApiModelProperty(value = "A Url where the HTTPS request has to be made")
1218
private String url;
13-
private JsonObject headers;
19+
20+
@ApiModelProperty(value = "Header that need to be sent along with URL")
21+
private JSONObject headers;
22+
23+
@ApiModelProperty(value = "A request type, eg. GET, POST, PUT, DELETE, PATCH")
1424
private String request;
25+
26+
@ApiModelProperty(value = "A Body that has to be sent along with the URL")
1527
private String body;
1628

1729
public CommonRequest() {
1830
}
1931

20-
public CommonRequest(Long clientId, String url, JsonObject headers, String request, String body) {
32+
public CommonRequest(Long clientId, String url, JSONObject headers, String request, String body) {
2133
this.clientId = clientId;
2234
this.url = url;
2335
this.headers = headers;

request-proxy-service/src/main/java/com/freshworks/requestproxy/exception/InvalidUrlException.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

request-proxy-service/src/main/java/com/freshworks/requestproxy/exception/MaxLimitExceededException.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

request-proxy-service/src/main/java/com/freshworks/requestproxy/exception/ValidationFailureException.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

request-proxy-service/src/main/java/com/freshworks/requestproxy/model/SupportedRequestTypes.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.freshworks.requestproxy.model;
22

33
public enum SupportedRequestTypes {
4+
45
POST("POST"),
5-
GET("GET");
6+
GET("GET"),
7+
PUT("PUT"),
8+
DELETE("DELETE"),
9+
PATCH("PATCH");
610

711
private String requestType;
812

request-proxy-service/src/main/java/com/freshworks/requestproxy/model/Transaction.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package com.freshworks.requestproxy.model;
22

3+
import io.swagger.annotations.ApiModel;
4+
import io.swagger.annotations.ApiModelProperty;
35
import lombok.Data;
46

57
import java.util.Date;
68

79
@Data
10+
@ApiModel("An Entity to capture or trace client activing on the proxy system")
811
public class Transaction {
912

13+
@ApiModelProperty(value = "Represents time when client access the system last")
1014
private Date accessTime;
1115

16+
@ApiModelProperty(value = "Represents the count, client requested the system already")
1217
private Integer accessCount;
1318

1419
public Transaction() {

request-proxy-service/src/main/java/com/freshworks/requestproxy/resource/RequestProxyResource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.freshworks.requestproxy.constant.CommonConstants;
44
import com.freshworks.requestproxy.entity.requestEntity.CommonRequest;
55
import com.freshworks.requestproxy.entity.responseEntity.CommonResponse;
6+
import com.freshworks.requestproxy.exception.RequestParseException;
67
import com.freshworks.requestproxy.exception.RequestTimeoutException;
78
import com.freshworks.requestproxy.service.ExecutionService;
89
import org.springframework.beans.factory.annotation.Autowired;
@@ -26,7 +27,7 @@ public RequestProxyResource(ExecutionService executionService) {
2627
}
2728

2829
@PostMapping
29-
public CommonResponse<?> processRequest(@RequestBody CommonRequest commonRequest) throws RequestTimeoutException, IOException, URISyntaxException {
30+
public CommonResponse<?> processRequest(@RequestBody CommonRequest commonRequest) throws RequestTimeoutException, URISyntaxException, IOException, RequestParseException {
3031
return executionService.executeRequest(commonRequest);
3132
}
3233

request-proxy-service/src/main/java/com/freshworks/requestproxy/service/ExecutionService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import com.freshworks.requestproxy.entity.requestEntity.CommonRequest;
44
import com.freshworks.requestproxy.entity.responseEntity.CommonResponse;
5+
import com.freshworks.requestproxy.exception.RequestParseException;
56
import com.freshworks.requestproxy.exception.RequestTimeoutException;
67

78
import java.io.IOException;
8-
import java.net.MalformedURLException;
99
import java.net.URISyntaxException;
1010

11+
/**
12+
* executeRequest method is used to execute the incoming request to replay with the Common request format
13+
*/
1114
public interface ExecutionService {
1215

13-
public CommonResponse<?> executeRequest(CommonRequest commonRequest) throws RequestTimeoutException, IOException, URISyntaxException;
16+
public CommonResponse<?> executeRequest(CommonRequest commonRequest) throws RequestTimeoutException, IOException, URISyntaxException, RequestParseException;
1417
}

0 commit comments

Comments
 (0)