#1023 - [Scala] Use status family during response processing (#1024)

* #1023 - [Scala] Use status family during response processing

* #1023 - [Scala] Use status family during response processing - adding REDIRECTION & INFORMATIONAL support
This commit is contained in:
Igor Luzhanov
2019-03-31 13:06:39 +02:00
committed by William Cheng
parent 822234dd76
commit c81c09b941
9 changed files with 519 additions and 26 deletions

View File

@@ -1 +1 @@
4.0.0-SNAPSHOT
4.0.0-SNAPSHOT

View File

@@ -25,12 +25,13 @@ import com.sun.jersey.multipart.file.FileDataBodyPart
import com.wordnik.swagger.client._
import com.wordnik.swagger.client.ClientResponseReaders.Json4sFormatsReader._
import com.wordnik.swagger.client.RequestWriters.Json4sFormatsWriter._
import javax.ws.rs.core.Response.Status.Family
import java.net.URI
import java.io.File
import java.util.Date
import java.util.TimeZone
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.{MediaType, Response}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
@@ -309,7 +310,11 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -331,7 +336,11 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -348,7 +357,11 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -365,7 +378,11 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -381,7 +398,11 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -397,7 +418,11 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -416,7 +441,11 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -435,7 +464,11 @@ class PetApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}

View File

@@ -23,12 +23,13 @@ import com.sun.jersey.multipart.file.FileDataBodyPart
import com.wordnik.swagger.client._
import com.wordnik.swagger.client.ClientResponseReaders.Json4sFormatsReader._
import com.wordnik.swagger.client.RequestWriters.Json4sFormatsWriter._
import javax.ws.rs.core.Response.Status.Family
import java.net.URI
import java.io.File
import java.util.Date
import java.util.TimeZone
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.{MediaType, Response}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
@@ -193,7 +194,11 @@ class StoreApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extend
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -208,7 +213,11 @@ class StoreApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extend
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -224,7 +233,11 @@ class StoreApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extend
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -240,7 +253,11 @@ class StoreApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extend
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}

View File

@@ -23,12 +23,13 @@ import com.sun.jersey.multipart.file.FileDataBodyPart
import com.wordnik.swagger.client._
import com.wordnik.swagger.client.ClientResponseReaders.Json4sFormatsReader._
import com.wordnik.swagger.client.RequestWriters.Json4sFormatsWriter._
import javax.ws.rs.core.Response.Status.Family
import java.net.URI
import java.io.File
import java.util.Date
import java.util.TimeZone
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.{MediaType, Response}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent._
@@ -299,7 +300,11 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -315,7 +320,11 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -331,7 +340,11 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -349,7 +362,11 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -367,7 +384,11 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -389,7 +410,11 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -404,7 +429,11 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}
@@ -424,7 +453,11 @@ class UserApiAsyncHelper(client: TransportClient, config: SwaggerConfig) extends
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp =>
process(reader.read(resp))
val status = Response.Status.fromStatusCode(resp.statusCode)
status.getFamily match {
case Family.SUCCESSFUL | Family.REDIRECTION | Family.INFORMATIONAL => process(reader.read(resp))
case _ => throw new ApiException(resp.statusCode, resp.statusText)
}
}
}