/* * Copyright 2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.springframework.kotlin.coroutine.web.client import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Deferred import org.springframework.core.ParameterizedTypeReference import org.springframework.http.HttpEntity import org.springframework.http.HttpHeaders import org.springframework.http.HttpMethod import org.springframework.http.RequestEntity import org.springframework.http.ResponseEntity import org.springframework.kotlin.coroutine.NewThreadCoroutineDispatcher import org.springframework.kotlin.coroutine.proxy.DeferredCoroutineProxyConfig import org.springframework.kotlin.coroutine.proxy.createCoroutineProxy import org.springframework.web.client.RequestCallback import org.springframework.web.client.ResponseExtractor import org.springframework.web.client.RestOperations import org.springframework.web.client.RestTemplate import java.net.URI import kotlin.coroutines.CoroutineContext interface DeferredRestOperations { fun postForObject(url: String, request: Any?, responseType: Class?, vararg uriVariables: Any?): Deferred fun postForObject(url: String, request: Any?, responseType: Class?, uriVariables: Map): Deferred fun postForObject(url: URI, request: Any?, responseType: Class?): Deferred fun put(url: String, request: Any?, vararg uriVariables: Any?): Deferred fun put(url: String, request: Any?, uriVariables: Map): Deferred fun put(url: URI, request: Any?): Deferred fun exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: Class?, vararg uriVariables: Any?): Deferred> fun exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: Class?, uriVariables: Map): Deferred> fun exchange(url: URI, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: Class?): Deferred> fun exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: ParameterizedTypeReference, vararg uriVariables: Any?): Deferred> fun exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: ParameterizedTypeReference, uriVariables: Map): Deferred> fun exchange(url: URI, method: HttpMethod, requestEntity: HttpEntity<*>?, responseType: ParameterizedTypeReference): Deferred> fun exchange(requestEntity: RequestEntity<*>?, responseType: Class?): Deferred> fun exchange(requestEntity: RequestEntity<*>?, responseType: ParameterizedTypeReference): Deferred> fun getForEntity(url: String, responseType: Class?, vararg uriVariables: Any?): Deferred> fun getForEntity(url: String, responseType: Class?, uriVariables: Map): Deferred> fun getForEntity(url: URI, responseType: Class?): Deferred> fun headForHeaders(url: String, vararg uriVariables: Any?): Deferred fun headForHeaders(url: String, uriVariables: Map): Deferred fun headForHeaders(url: URI): Deferred fun getForObject(url: String, responseType: Class?, vararg uriVariables: Any?): Deferred fun getForObject(url: String, responseType: Class?, uriVariables: Map): Deferred fun getForObject(url: URI, responseType: Class?): Deferred fun execute(url: String, method: HttpMethod, requestCallback: RequestCallback?, responseExtractor: ResponseExtractor?, vararg uriVariables: Any?): Deferred fun execute(url: String, method: HttpMethod, requestCallback: RequestCallback?, responseExtractor: ResponseExtractor?, uriVariables: Map): Deferred fun execute(url: URI, method: HttpMethod, requestCallback: RequestCallback?, responseExtractor: ResponseExtractor?): Deferred fun postForEntity(url: String, request: Any?, responseType: Class?, vararg uriVariables: Any?): Deferred> fun postForEntity(url: String, request: Any?, responseType: Class?, uriVariables: Map): Deferred> fun postForEntity(url: URI, request: Any?, responseType: Class?): Deferred> fun optionsForAllow(url: String, vararg uriVariables: Any?): Deferred> fun optionsForAllow(url: String, uriVariables: Map): Deferred> fun optionsForAllow(url: URI): Deferred> fun patchForObject(url: String, request: Any?, responseType: Class?, vararg uriVariables: Any?): Deferred fun patchForObject(url: String, request: Any?, responseType: Class?, uriVariables: Map): Deferred fun patchForObject(url: URI, request: Any?, responseType: Class?): Deferred fun postForLocation(url: String, request: Any?, vararg uriVariables: Any?): Deferred fun postForLocation(url: String, request: Any?, uriVariables: Map): Deferred fun postForLocation(url: URI, request: Any?): Deferred fun delete(url: String, vararg uriVariables: Any?): Deferred fun delete(url: String, uriVariables: Map): Deferred fun delete(url: URI): Deferred companion object { operator fun invoke(restOperations: RestOperations = RestTemplate(), start: CoroutineStart = CoroutineStart.DEFAULT, context: CoroutineContext = NewThreadCoroutineDispatcher): DeferredRestOperations = createCoroutineProxy(DeferredRestOperations::class.java, restOperations, DeferredCoroutineProxyConfig(start, context)) } }