当前位置: 首页>>代码示例>>Java>>正文


Java ClientHttpResponse.close方法代码示例

本文整理汇总了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

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,代码来源:AsyncRestTemplate.java

示例2: doExecute

import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
/**
 * Execute the given method on the provided URI.
 * <p>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> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback,
		ResponseExtractor<T> 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,代码来源:RestTemplate.java

示例3: pingAndUpdateJvmState

import org.springframework.http.client.ClientHttpResponse; //导入方法依赖的package包/类
@Async("jvmTaskExecutor")
public Future<CurrentState<Jvm, JvmState>> 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<Jvm, JvmState> 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,代码来源:JvmStateResolverWorker.java

示例4: pingAndUpdateJvmState

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,代码来源:JvmServiceImpl.java

示例5: pingWebServer

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,代码来源:WebServerStateSetterWorker.java


注:本文中的org.springframework.http.client.ClientHttpResponse.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。