本文整理匯總了Java中org.springframework.http.client.ClientHttpResponse.close方法的典型用法代碼示例。如果您正苦於以下問題:Java ClientHttpResponse.close方法的具體用法?Java ClientHttpResponse.close怎麽用?Java ClientHttpResponse.close使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.http.client.ClientHttpResponse的用法示例。
在下文中一共展示了ClientHttpResponse.close方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: adapt
點讚 3
import org.springframework.http.client.ClientHttpResponse; //導入方法依賴的package包/類
@Override
protected final T adapt(ClientHttpResponse response) throws ExecutionException {
try {
if (!getErrorHandler().hasError(response)) {
logResponseStatus(this.method, this.url, response);
}
else {
handleResponseError(this.method, this.url, response);
}
return convertResponse(response);
}
catch (IOException ex) {
throw new ExecutionException(ex);
}
finally {
if (response != null) {
response.close();
}
}
}
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,
示例2: doExecute
點讚 2
import org.springframework.http.client.ClientHttpResponse; //導入方法依賴的package包/類
/**
* Execute the given method on the provided URI.
*
The {@link ClientHttpRequest} is processed using the {@link RequestCallback};
* the response with the {@link ResponseExtractor}.
* @param url the fully-expanded URL to connect to
* @param method the HTTP method to execute (GET, POST, etc.)
* @param requestCallback object that prepares the request (can be {@code null})
* @param responseExtractor object that extracts the return value from the response (can be {@code null})
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
*/
protected T doExecute(URI url, HttpMethod method, RequestCallback requestCallback,
ResponseExtractor responseExtractor) throws RestClientException {
Assert.notNull(url, "'url' must not be null");
Assert.notNull(method, "'method' must not be null");
ClientHttpResponse response = null;
try {
ClientHttpRequest request = createRequest(url, method);
if (requestCallback != null) {
requestCallback.doWithRequest(request);
}
response = request.execute();
if (!getErrorHandler().hasError(response)) {
logResponseStatus(method, url, response);
}
else {
handleResponseError(method, url, response);
}
if (responseExtractor != null) {
return responseExtractor.extractData(response);
}
else {
return null;
}
}
catch (IOException ex) {
throw new ResourceAccessException("I/O error on " + method.name() +
" request for \"" + url + "\":" + ex.getMessage(), ex);
}
finally {
if (response != null) {
response.close();
}
}
}
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:46,
示例3: pingAndUpdateJvmState
點讚 2
import org.springframework.http.client.ClientHttpResponse; //導入方法依賴的package包/類
@Async("jvmTaskExecutor")
public Future> pingAndUpdateJvmState(final Jvm jvm, final JvmStateService jvmStateService) {
LOGGER.debug("The reverse heartbeat has kicked in! This means that we're not receiving any states from Jvm {}@{}.",
jvm.getJvmName(), jvm.getHostName());
LOGGER.debug("+++ pingAndUpdateJvmState");
ClientHttpResponse response = null;
CurrentState currentState = null;
// if the jvm was just created do not check its state
if (jvm.getState().equals(JvmState.JVM_NEW)){
return new AsyncResult<>(new CurrentState<>(jvm.getId(), jvm.getState(), DateTime.now(), StateType.JVM));
}
try {
response = clientFactoryHelper.requestGet(jvm.getStatusUri());
LOGGER.debug("Response = {} from JVM {}", response.getStatusCode(), jvm.getJvmName());
jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STARTED, StringUtils.EMPTY);
currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STARTED, DateTime.now(), StateType.JVM);
} catch (final IOException ioe) {
LOGGER.warn("{} {} {}", jvm.getJvmName(), ioe.getMessage(), "Setting JVM state to STOPPED.", ioe);
jvmStateService.updateNotInMemOrStaleState(jvm, JvmState.JVM_STOPPED, StringUtils.EMPTY);
currentState = new CurrentState<>(jvm.getId(), JvmState.JVM_STOPPED, DateTime.now(), StateType.JVM);
} catch (final RuntimeException rte) {
// This method is executed asynchronously and we do not want to interrupt the thread's lifecycle so we
// just catch and log runtime exceptions instead of rethrowing it
LOGGER.error(rte.getMessage(), rte);
} finally {
if (response != null) {
response.close();
LOGGER.debug("response closed");
}
LOGGER.debug("--- pingAndUpdateJvmState");
}
return new AsyncResult<>(currentState);
}
開發者ID:cerner,項目名稱:jwala,代碼行數:36,
示例4: pingAndUpdateJvmState
點讚 2
import org.springframework.http.client.ClientHttpResponse; //導入方法依賴的package包/類
@Override
@Transactional
public JvmHttpRequestResult pingAndUpdateJvmState(final Jvm jvm) {
ClientHttpResponse response = null;
JvmState jvmState = jvm.getState();
String responseDetails = StringUtils.EMPTY;
try {
response = clientFactoryHelper.requestGet(jvm.getStatusUri());
LOGGER.info(">>> Response = {} from jvm {}", response.getStatusCode(), jvm.getId().getId());
jvmState = JvmState.JVM_STARTED;
if (response.getStatusCode() == HttpStatus.OK) {
jvmStateService.updateState(jvm, jvmState, StringUtils.EMPTY);
} else {
// As long as we get a response even if it's not a 200 it means that the JVM is alive
jvmStateService.updateState(jvm, jvmState, StringUtils.EMPTY);
responseDetails = MessageFormat.format("Request {0} sent expecting a response code of {1} but got {2} instead",
jvm.getStatusUri(), HttpStatus.OK.value(), response.getRawStatusCode());
}
} catch (final IOException ioe) {
LOGGER.info(ioe.getMessage(), ioe);
jvmStateService.updateState(jvm, JvmState.JVM_STOPPED, StringUtils.EMPTY);
responseDetails = MessageFormat.format("Request {0} sent and got: {1}", jvm.getStatusUri(), ioe.getMessage());
jvmState = JvmState.JVM_STOPPED;
} catch (RuntimeException rte) {
LOGGER.error(rte.getMessage(), rte);
} finally {
if (response != null) {
response.close();
}
}
return new JvmHttpRequestResult(jvmState, responseDetails);
}
開發者ID:cerner,項目名稱:jwala,代碼行數:34,
示例5: pingWebServer
點讚 2
import org.springframework.http.client.ClientHttpResponse; //導入方法依賴的package包/類
/**
* Ping the web server via http get.
*
* @param webServer the web server to ping.
*/
@Async("webServerTaskExecutor")
public void pingWebServer(final WebServer webServer) {
if (!webServerCanBePinged(webServer)) {
return;
}
synchronized (webServersToPing) {
if (webServersToPing.contains(webServer.getId())) {
LOGGER.debug("List of web servers currently being pinged: {}", webServersToPing);
LOGGER.debug("Cannot ping web server {} since it is currently being pinged", webServer.getName(),
webServer);
return;
}
webServersToPing.add(webServer.getId());
}
LOGGER.debug("Requesting {} for web server {}", webServer.getStatusUri(), webServer.getName());
ClientHttpResponse response = null;
try {
final ClientHttpRequest request;
request = httpRequestFactory.createRequest(webServer.getStatusUri(), HttpMethod.GET);
response = request.execute();
LOGGER.debug("Web server {} status code = {}", webServer.getName(), response.getStatusCode());
if (HttpStatus.OK.equals(response.getStatusCode())) {
setState(webServer, WebServerReachableState.WS_REACHABLE, StringUtils.EMPTY);
} else {
setState(webServer, WebServerReachableState.WS_UNREACHABLE,
MessageFormat.format(RESPONSE_NOT_OK_MSG, webServer.getStatusUri(), response.getStatusCode()));
}
} catch (final IOException e) {
if (!WebServerReachableState.WS_UNREACHABLE.equals(webServer.getState())) {
LOGGER.warn("Failed to ping {}!", webServer.getName(), e);
setState(webServer, WebServerReachableState.WS_UNREACHABLE, StringUtils.EMPTY);
}
} finally {
if (response != null) {
response.close();
}
webServersToPing.remove(webServer.getId());
}
}
開發者ID:cerner,項目名稱:jwala,代碼行數:50,
注:本文中的org.springframework.http.client.ClientHttpResponse.close方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。