forked from pflooky/data-caterer
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add in data validation for HTTP requests and responses
- Loading branch information
Showing
18 changed files
with
209 additions
and
47 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
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
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
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
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
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
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
58 changes: 58 additions & 0 deletions
58
...main/scala/io/github/datacatering/datacaterer/core/sink/http/model/HttpResultModels.scala
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,58 @@ | ||
package io.github.datacatering.datacaterer.core.sink.http.model | ||
|
||
import io.github.datacatering.datacaterer.core.util.HttpUtil.getHeadersAsMap | ||
import org.asynchttpclient.{Request, Response} | ||
|
||
case class HttpRequest( | ||
method: String = "", | ||
url: String = "", | ||
headers: Map[String, String] = Map(), | ||
body: String = "" | ||
) | ||
|
||
object HttpRequest { | ||
|
||
def fromRequest(request: Request): HttpRequest = { | ||
HttpRequest( | ||
request.getMethod, | ||
request.getUri.toString, | ||
getHeadersAsMap(request.getHeaders), | ||
request.getStringData | ||
) | ||
} | ||
} | ||
|
||
case class HttpResponse( | ||
contentType: String = "", | ||
headers: Map[String, String] = Map(), | ||
body: String = "", | ||
statusCode: Int = 200, | ||
statusText: String = "" | ||
) | ||
|
||
object HttpResponse { | ||
|
||
def fromResponse(response: Response): HttpResponse = { | ||
//response body contains new line characters | ||
HttpResponse( | ||
response.getContentType, | ||
getHeadersAsMap(response.getHeaders), | ||
response.getResponseBody, | ||
response.getStatusCode, | ||
response.getStatusText | ||
) | ||
} | ||
} | ||
|
||
case class HttpResult(request: HttpRequest = HttpRequest(), response: HttpResponse = HttpResponse()) | ||
|
||
object HttpResult { | ||
|
||
def fromRequest(request: Request): HttpResult = { | ||
HttpResult(HttpRequest.fromRequest(request)) | ||
} | ||
|
||
def fromRequestAndResponse(request: Request, response: Response): HttpResult = { | ||
HttpResult(HttpRequest.fromRequest(request), HttpResponse.fromResponse(response)) | ||
} | ||
} |
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
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
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
7 changes: 7 additions & 0 deletions
7
app/src/main/scala/io/github/datacatering/datacaterer/core/util/ValidationUtil.scala
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,7 @@ | ||
package io.github.datacatering.datacaterer.core.util | ||
|
||
object ValidationUtil { | ||
|
||
def cleanValidationIdentifier(identifier: String): String = identifier.replaceAll("[{}]", "") | ||
|
||
} |
Oops, something went wrong.