diff --git a/pom.xml b/pom.xml
index 77c4f5d..d95b055 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
in.erail
api-framework
- 2.4
+ 2.4.1
jar
diff --git a/src/main/java/in/erail/model/ReqestEvent.java b/src/main/java/in/erail/model/ReqestEvent.java
new file mode 100644
index 0000000..aeea867
--- /dev/null
+++ b/src/main/java/in/erail/model/ReqestEvent.java
@@ -0,0 +1,131 @@
+package in.erail.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.google.common.io.BaseEncoding;
+import io.vertx.core.http.HttpMethod;
+import java.util.Map;
+
+/**
+ *
+ * @author vinay
+ */
+@JsonInclude(Include.NON_NULL)
+public class ReqestEvent {
+
+ private String mResource;
+ private String mPath;
+ private HttpMethod mHttpMethod;
+ private Map mHeaders;
+ private Map mMultiValueHeaders;
+ private Map mQueryStringParameters;
+ private Map mMultiValueQueryStringParameters;
+ private Map mPathParameters;
+ private Map mStageVariables;
+ private Map mRequestContext;
+ private byte[] mBody = new byte[0];
+ private boolean mIsBase64Encoded = false;
+
+ public String getResource() {
+ return mResource;
+ }
+
+ public void setResource(String pResource) {
+ this.mResource = pResource;
+ }
+
+ public String getPath() {
+ return mPath;
+ }
+
+ public void setPath(String pPath) {
+ this.mPath = pPath;
+ }
+
+ public HttpMethod getHttpMethod() {
+ return mHttpMethod;
+ }
+
+ public void setHttpMethod(HttpMethod pHttpMethod) {
+ this.mHttpMethod = pHttpMethod;
+ }
+
+ public Map getHeaders() {
+ return mHeaders;
+ }
+
+ public void setHeaders(Map pHeaders) {
+ this.mHeaders = pHeaders;
+ }
+
+ public Map getMultiValueHeaders() {
+ return mMultiValueHeaders;
+ }
+
+ public void setMultiValueHeaders(Map pMultiValueHeaders) {
+ this.mMultiValueHeaders = pMultiValueHeaders;
+ }
+
+ public Map getQueryStringParameters() {
+ return mQueryStringParameters;
+ }
+
+ public void setQueryStringParameters(Map pQueryStringParameters) {
+ this.mQueryStringParameters = pQueryStringParameters;
+ }
+
+ public Map getMultiValueQueryStringParameters() {
+ return mMultiValueQueryStringParameters;
+ }
+
+ public void setMultiValueQueryStringParameters(Map pMultiValueQueryStringParameters) {
+ this.mMultiValueQueryStringParameters = pMultiValueQueryStringParameters;
+ }
+
+ public Map getPathParameters() {
+ return mPathParameters;
+ }
+
+ public void setPathParameters(Map pPathParameters) {
+ this.mPathParameters = pPathParameters;
+ }
+
+ public Map getStageVariables() {
+ return mStageVariables;
+ }
+
+ public void setStageVariables(Map pStageVariables) {
+ this.mStageVariables = pStageVariables;
+ }
+
+ public Map getRequestContext() {
+ return mRequestContext;
+ }
+
+ public void setRequestContext(Map pRequestContext) {
+ this.mRequestContext = pRequestContext;
+ }
+
+ public boolean isIsBase64Encoded() {
+ return mIsBase64Encoded;
+ }
+
+ public void setIsBase64Encoded(boolean pIsBase64Encoded) {
+ this.mIsBase64Encoded = pIsBase64Encoded;
+ }
+
+ public byte[] getBody() {
+ return mBody;
+ }
+
+ public void setBody(byte[] pBody) {
+ this.mBody = pBody;
+ }
+
+ public String bodyAsString(){
+ if(isIsBase64Encoded()){
+ return new String(BaseEncoding.base64().decode(new String(getBody())));
+ }
+ return new String(getBody());
+ }
+}
diff --git a/src/main/java/in/erail/model/ResponseEvent.java b/src/main/java/in/erail/model/ResponseEvent.java
new file mode 100644
index 0000000..b42f3c5
--- /dev/null
+++ b/src/main/java/in/erail/model/ResponseEvent.java
@@ -0,0 +1,82 @@
+package in.erail.model;
+
+import com.google.common.net.HttpHeaders;
+import com.google.common.net.MediaType;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * @author vinay
+ */
+public class ResponseEvent {
+
+ private Map[] mCookies;
+ private boolean mIsBase64Encoded = true;
+ private int mStatusCode = 200;
+ private Map mHeaders;
+ private Map mMultiValueHeaders;
+ private byte[] mBody = new byte[0];
+
+ public boolean isIsBase64Encoded() {
+ return mIsBase64Encoded;
+ }
+
+ public void setIsBase64Encoded(boolean pIsBase64Encoded) {
+ this.mIsBase64Encoded = pIsBase64Encoded;
+ }
+
+ public int getStatusCode() {
+ return mStatusCode;
+ }
+
+ public void setStatusCode(int pStatusCode) {
+ this.mStatusCode = pStatusCode;
+ }
+
+ public Map getHeaders() {
+ if (mHeaders == null) {
+ mHeaders = new HashMap<>();
+ }
+ return mHeaders;
+ }
+
+ public void setHeaders(Map pHeaders) {
+ this.mHeaders = pHeaders;
+ }
+
+ public byte[] getBody() {
+ return mBody;
+ }
+
+ public void setBody(byte[] pBody) {
+ this.mBody = pBody;
+ }
+
+ public Map getMultiValueHeaders() {
+ if (mMultiValueHeaders == null) {
+ mMultiValueHeaders = new HashMap<>();
+ }
+ return mMultiValueHeaders;
+ }
+
+ public void setMultiValueHeaders(Map pMultiValueHeaders) {
+ this.mMultiValueHeaders = pMultiValueHeaders;
+ }
+
+ public Map[] getCookies() {
+ return mCookies;
+ }
+
+ public void setCookies(Map[] pCookies) {
+ this.mCookies = pCookies;
+ }
+
+ public void addHeader(String pHeaderName, String pMediaType) {
+ getHeaders().put(HttpHeaders.CONTENT_TYPE, pMediaType);
+ }
+
+ public void addHeader(String pHeaderName, MediaType pMediaType) {
+ getHeaders().put(HttpHeaders.CONTENT_TYPE, pMediaType.toString());
+ }
+}
diff --git a/src/main/java/in/erail/route/OpenAPI3RouteBuilder.java b/src/main/java/in/erail/route/OpenAPI3RouteBuilder.java
index bc7e890..390504c 100644
--- a/src/main/java/in/erail/route/OpenAPI3RouteBuilder.java
+++ b/src/main/java/in/erail/route/OpenAPI3RouteBuilder.java
@@ -13,6 +13,8 @@
import static in.erail.common.FrameworkConstants.RoutingContext.Json;
import in.erail.glue.annotation.StartService;
+import in.erail.model.ReqestEvent;
+import in.erail.model.ResponseEvent;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.eventbus.DeliveryOptions;
@@ -113,22 +115,20 @@ public void process(RoutingContext pRequestContext, String pServiceUniqueId) {
*/
public JsonObject serialiseRoutingContext(RoutingContext pContext) {
- JsonObject result = new JsonObject();
+ ReqestEvent request = new ReqestEvent();
+ request.setHttpMethod(pContext.request().method());
- if (pContext.request().method() == HttpMethod.POST) {
- result.put(Json.BODY, pContext.getBody().getDelegate().getBytes());
- } else {
- result.put(Json.BODY, new byte[]{});
+ if (request.getHttpMethod() == HttpMethod.POST
+ || request.getHttpMethod() == HttpMethod.PUT
+ || request.getHttpMethod() == HttpMethod.PATCH) {
+ request.setBody(pContext.getBody().getDelegate().getBytes());
}
- JsonObject headers = new JsonObject(convertMultiMapIntoMap(pContext.request().headers()));
- result.put(Json.HEADERS, headers);
+ request.setHeaders(convertMultiMapIntoMap(pContext.request().headers()));
+ request.setQueryStringParameters(convertMultiMapIntoMap(pContext.queryParams()));
+ request.setPathParameters(convertMultiMapIntoMap(pContext.request().params()));
- JsonObject query = new JsonObject(convertMultiMapIntoMap(pContext.queryParams()));
- result.put(Json.QUERY_STRING_PARAM, query);
-
- JsonObject params = new JsonObject(convertMultiMapIntoMap(pContext.request().params()));
- result.put(Json.PATH_PARAM, params);
+ JsonObject result = JsonObject.mapFrom(request);
getLog().debug(() -> "Context to JSON:" + result.toString());
@@ -136,7 +136,8 @@ public JsonObject serialiseRoutingContext(RoutingContext pContext) {
}
/**
- * All response content is written in binary. If Content type is not provided then application/octet-stream content type is set.
+ * All response content is written in binary. If Content type is not provided
+ * then application/octet-stream content type is set.
*
* @param pReplyResponse Service Body
* @param pContext Routing Context
@@ -144,49 +145,44 @@ public JsonObject serialiseRoutingContext(RoutingContext pContext) {
*/
public HttpServerResponse buildResponseFromReply(JsonObject pReplyResponse, RoutingContext pContext) {
- JsonObject headers = pReplyResponse.getJsonObject(Json.HEADERS, new JsonObject());
- String statusCode = pReplyResponse.getString(Json.STATUS_CODE, HttpResponseStatus.OK.codeAsText().toString());
+ ResponseEvent response = pReplyResponse.mapTo(ResponseEvent.class);
- if (!headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
- headers.put(HttpHeaders.CONTENT_TYPE, MediaType.OCTET_STREAM.toString());
+ if (!response.getHeaders().containsKey(HttpHeaders.CONTENT_TYPE)) {
+ response.getHeaders().put(HttpHeaders.CONTENT_TYPE, MediaType.OCTET_STREAM.toString());
}
- headers
- .fieldNames()
+ response
+ .getHeaders()
+ .entrySet()
.stream()
- .forEach((field) -> {
- pContext.response().putHeader(field, headers.getString(field, ""));
+ .forEach((kv) -> {
+ pContext.response().putHeader(kv.getKey(), kv.getValue());
});
- pContext.response().setStatusCode(HttpResponseStatus.parseLine(statusCode).code());
-
- Optional cookies = Optional.ofNullable(pReplyResponse.getJsonArray(Json.COOKIES));
-
- cookies.ifPresent((cooky) -> {
- for (Iterator