I wrote REST client using springs RestTemplate
in java and in groovy using 'HTTPBuilder'. Both invocation took 10 second on my computer. In Postman and other tools this kind the same post request it took 300 ms.
This is simple invocation in groovy script. Essential is between BEGIN REST invocation
and END REST invocation
:
@Grapes(
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7')
)
import groovy.json.JsonOutput
import groovy.json.internal.LazyMap
import groovy.transform.ToString
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.JSON
import static groovyx.net.http.Method.POST
HTTPBuilder http = new HTTPBuilder()
Forechart forechart = new Forechart(dayInterval: 3, adultCount: 1, childCount: 0,
flightList: [new Flight(departureStation: "WAW", arrivalStation: "CRL", date: new Date(2018, 06, 02))
,new Flight(departureStation: "CRL", arrivalStation: "WAW", date: new Date(2018, 10, 26))])
def jsonRequest = JsonOutput.toJson( forechart )
LazyMap jsonResponse
//BEGIN REST invocation
println "Request: " + JsonOutput.prettyPrint(jsonRequest)
long start = System.nanoTime()
http.request( 'https://be.wizzair.com/7.15/Api/asset/farechart', POST, JSON ) { req ->
body = jsonRequest
headers.Accept = 'application/json'
response.success = { resp, json ->
assert resp.statusLine.statusCode == 200
jsonResponse = json
}
response.'404' = {
println 'Not found'
}
}
long end = System.nanoTime() - start
//println "Response: $jsonResponse"
println "\nDuration: " + end / 1_000_000_000 + " seconds"
//END REST invocation
ForechartFlights forechartFlights = new ForechartFlights(jsonResponse)
//Data Objects
@ToString(includePackage = false)
class Forechart {
boolean wdc
List<Flight> flightList
int dayInterval
int adultCount
int childCount
boolean isRescueFare
}
@ToString(includePackage = false)
class Flight {
String departureStation
String arrivalStation
Date date
}
//response
@ToString(includePackage = false)
class ForechartFlights {
List<ForechartFlight> outboundFlights
List<ForechartFlight> returnFlights
}
@ToString(includePackage = false)
class ForechartFlight {
String departureStation
String arrivalStation
String priceType
String classOfService
boolean hasMacFlight
Date date
Price price;
}
@ToString(includePackage = false)
class Price {
BigDecimal amount
String currencyCode
}
What is reason?