本文整理汇总了Java中org.apache.commons.httpclient.HttpMethodBase.releaseConnection方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethodBase.releaseConnection方法的具体用法?Java HttpMethodBase.releaseConnection怎么用?Java HttpMethodBase.releaseConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.HttpMethodBase
的用法示例。
在下文中一共展示了HttpMethodBase.releaseConnection方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shutdown
import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
private void shutdown(HttpMethodBase method) {
if (method != null) {
method.releaseConnection();
}
if (!externalConnectionManager) {
((SimpleHttpConnectionManager) httpConnectionManager).shutdown();
}
}
示例2: debugMethod
import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
public static void debugMethod(HttpMethodBase method)
{
HttpClient client = new HttpClient();
InputStream is = null;
try {
System.out.println(method.getName() + " "
+ method.getURI() + " HTTP/1.1");
client.executeMethod(method);
System.out.println(method.getStatusLine());
boolean len = false;
for ( Header header : method.getResponseHeaders() )
{
if ( header.getName().equals("Content-Length") ) { len = true; }
System.out.print(header.toExternalForm());
}
String body = method.getResponseBodyAsString();
if ( body == null ) { return; }
if (!len) { System.out.println("Content-Length: " + body.length());}
is = getInputStream(method);
dumpInputStream(is, System.out);
}
catch (IOException e) {
e.printStackTrace();
}
finally { IOUtils.closeQuietly(is); method.releaseConnection(); }
}
示例3: handleRequest
import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
private boolean handleRequest(String url, NegotiationContext ctx)
{
HttpMethodBase m = newMethod(url, ctx.getMimetype());
ctx.printMethodRequest(m);
int code;
try {
try {
code = ctx.getClient().executeMethod(m);
}
catch (Exception e) { ctx.newCannotConnect(url, e); return false; }
ctx.printMethodResponse(m);
if ( isRspOK(code) ) { return handleInfoResource(m, ctx); }
if ( isRspRedirect(code) ) { return handleRedirect(m, ctx); }
}
finally { m.releaseConnection(); }
ctx.newUnresolvableError(url, code);
return true;
}
示例4: createConnectionReleasingInputStream
import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
private InputStream createConnectionReleasingInputStream(final HttpMethodBase method) throws IOException {
return new FilterInputStream(method.getResponseBodyAsStream()) {
public void close() throws IOException {
try {
super.close();
} finally {
method.releaseConnection();
}
}
};
}
示例5: releaseConnection
import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
/**
* Release both connection and the HttpMethodBase reference to the given thread name
*
* @param method HttpMethodBase to release
* @param threadName thread name to use
*/
public static void releaseConnection(final HttpMethodBase method, final String threadName) {
_logger.debug("releaseConnection: {} = {}", threadName, method);
// clear HttpMethodBase and release connection once:
HttpMethodThreadMap.release(threadName);
// release connection back to pool:
if (method != null) {
method.releaseConnection();
}
}
示例6: getObservationsForStation
import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
/**
* Gets all the observations for a particular station
* @param stationId The station ID to limit the filter to
* @param startDate The start date in the form 'YYYY-mm-DD'
* @param endDate The end date in the form 'YYYY-mm-DD'
* @return
*/
public List<GeodesyObservation> getObservationsForStation(String wfsUrl, String stationId, String startDate, String endDate) throws PortalServiceException {
GeodesyObservationsFilter filter = new GeodesyObservationsFilter(stationId, startDate, endDate);
HttpMethodBase method = null;
List<GeodesyObservation> allObservations = new ArrayList<GeodesyObservation>();
try {
//Make our request
method = this.generateWFSRequest(wfsUrl, "geodesy:station_observations", null, filter.getFilterStringAllRecords(), null, null, ResultType.Results);
InputStream response = httpServiceCaller.getMethodResponseAsStream(method);
//Parse it into a DOM doc
GeodesyNamespaceContext nc = new GeodesyNamespaceContext();
Document domDoc = DOMUtil.buildDomFromStream(response);
//Parse the dom doc into observation POJOs
XPathExpression exprStationId = DOMUtil.compileXPathExpr("geodesy:station_id", nc);
XPathExpression exprDate = DOMUtil.compileXPathExpr("geodesy:ob_date", nc);
XPathExpression exprUrl = DOMUtil.compileXPathExpr("geodesy:url", nc);
NodeList observationNodes = (NodeList) DOMUtil.compileXPathExpr("wfs:FeatureCollection/gml:featureMembers/geodesy:station_observations", nc).evaluate(domDoc, XPathConstants.NODESET);
for (int i = 0; i < observationNodes.getLength(); i++) {
Node observationNode = observationNodes.item(i);
String parsedId = (String) exprStationId.evaluate(observationNode, XPathConstants.STRING);
String parsedDate = (String) exprDate.evaluate(observationNode, XPathConstants.STRING);
String parsedUrl = (String) exprUrl.evaluate(observationNode, XPathConstants.STRING);
allObservations.add(new GeodesyObservation(parsedId, parsedDate, parsedUrl));
}
} catch (Exception ex) {
throw new PortalServiceException(method);
} finally {
if (method != null) {
method.releaseConnection();
}
}
return allObservations;
}
示例7: executeMethod
import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
/**
* 执行post或者get方法
*
* @param method post或者get方法
* @return
* @throws java.io.IOException
*/
private static String executeMethod(HttpMethodBase method) throws IOException {
HttpClient httpClient = new HttpClient();
try {
int statusCode = httpClient.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
throw new IOException("Method failed: " + method.getStatusLine());
}
// get response stream.
InputStream stream = method.getResponseBodyAsStream();
// charset
String charset = method.getRequestCharSet();
String response;
try {
// try to turn stream to bytes.
byte[] responseBytes = IOUtils.toByteArray(stream);
// decode with the reponse charset.
if (StringUtils.isNotBlank(charset)) {
try {
response = new String(responseBytes, charset);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
response = new String(responseBytes);
}
} else {
// decode with default charset.
response = new String(responseBytes);
}
return response;
} finally {
// close stream.
IOUtils.closeQuietly(stream);
}
} finally {
// release connection.
method.releaseConnection();
}
}
示例8: doInvoke
import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Object doInvoke(Context context) throws Exception {
String lowUrl = url.toLowerCase();
if (!lowUrl.startsWith("http://") && !lowUrl.startsWith("https://")) {
url = "http://" + url;
}
HttpClient client = new HttpClient();
final HttpMethodBase m;
if ("post".equalsIgnoreCase(method)) {
m = setPostBody(new PostMethod(url));
} else if ("get".equalsIgnoreCase(method)) {
m = new GetMethod(url);
} else {
throw new PaxmlRuntimeException("Unknown method: " + method);
}
setHeader(m);
setQueryString(m);
// Provide custom retry handler is necessary
m.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(maxRetry, false));
onBeforeSend(m);
// method.setr
try {
// Execute the method.
final int statusCode = client.executeMethod(m);
if (responseless) {
return statusCode;
}
// Read the response body.
Map<String, Object> result = new LinkedHashMap<String, Object>();
result.put("code", statusCode);
result.put("body", m.getResponseBodyAsString());
result.put("all", m);
return result;
} finally {
// Release the connection.
m.releaseConnection();
}
}
示例9: processResponse
import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
protected void processResponse(HttpMethodBase httpMethod,
MessageContext msgContext)
throws IOException {
obtainHTTPHeaderInformation(httpMethod, msgContext);
InputStream in = httpMethod.getResponseBodyAsStream();
if (in == null) {
if (hasResponseBodyForHTTPStatusCode(httpMethod.getStatusCode())) {
throw new AxisFault(Messages.getMessage("canNotBeNull", "InputStream"));
} else {
in = new ByteArrayInputStream("".getBytes());
}
}
Header contentEncoding =
httpMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
if (contentEncoding != null) {
if (contentEncoding.getValue().
equalsIgnoreCase(HTTPConstants.COMPRESSION_GZIP)) {
in = new GZIPInputStream(in);
// If the content-encoding is identity we can basically ignore it.
} else if (!"identity".equalsIgnoreCase(contentEncoding.getValue())) {
throw new AxisFault("HTTP :" + "unsupported content-encoding of '"
+ contentEncoding.getValue() + "' found");
}
}
if (httpMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
Header contentLength = httpMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_LENGTH);
boolean acceptedContainsBody = false;
if (in.available() > 0 || (contentLength != null && Integer.parseInt(contentLength.getValue()) > 0)) {
acceptedContainsBody = true;
} else {
Header transferEncoding = httpMethod.getResponseHeader(HTTPConstants.HEADER_TRANSFER_ENCODING);
if (transferEncoding != null && transferEncoding.getValue().equals(
HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)) {
String responseBody = httpMethod.getResponseBodyAsString();
if (responseBody.length() > 0) {
acceptedContainsBody = true;
in = IOUtils.toInputStream(responseBody, "UTF-8");
}
}
}
if (!acceptedContainsBody) {
/*
* For HTTP 202 Accepted code, if the body is empty string then release connection.
*/
httpMethod.releaseConnection();
return;
}
}
OperationContext opContext = msgContext.getOperationContext();
if (opContext != null) {
opContext.setProperty(MessageContext.TRANSPORT_IN, in);
}
}
示例10: handleResponse
import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
/**
* Used to handle the HTTP Response
*
* @param msgContext - The MessageContext of the message
* @param method - The HTTP method used
* @throws IOException - Thrown in case an exception occurs
*/
private void handleResponse(MessageContext msgContext,
HttpMethodBase method) throws IOException {
int statusCode = method.getStatusCode();
HTTPStatusCodeFamily family = getHTTPStatusCodeFamily(statusCode);
log.trace("Handling response - " + statusCode);
Set<Integer>nonErrorCodes = (Set<Integer>) msgContext.getProperty(HTTPConstants.NON_ERROR_HTTP_STATUS_CODES);
Set<Integer> errorCodes = new HashSet<Integer>();
String strRetryErrorCodes = (String) msgContext.getProperty(HTTPConstants.ERROR_HTTP_STATUS_CODES); // Fixing
// ESBJAVA-3178
if (strRetryErrorCodes != null && !strRetryErrorCodes.trim().equals("")) {
for (String strRetryErrorCode : strRetryErrorCodes.split(",")) {
try {
errorCodes.add(Integer.valueOf(strRetryErrorCode));
} catch (NumberFormatException e) {
log.warn(strRetryErrorCode + " is not a valid status code");
}
}
}
if (HTTPStatusCodeFamily.SUCCESSFUL.equals(family)) {
// Save the HttpMethod so that we can release the connection when cleaning up
// HTTP 202 Accepted should support body based on ESBJAVA-4370 as spec does not strictly enforce
// no-entity-body with 202 Accepted response.
msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
processResponse(method, msgContext);
} else if (!errorCodes.contains(statusCode)
&& (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR
|| statusCode == HttpStatus.SC_BAD_REQUEST || statusCode == HttpStatus.SC_CONFLICT)) {
// Save the HttpMethod so that we can release the connection when cleaning up
msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
Header contenttypeHeader =
method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
String value = null;
if (contenttypeHeader != null) {
value = contenttypeHeader.getValue();
}
OperationContext opContext = msgContext.getOperationContext();
if(opContext!=null){
MessageContext inMessageContext =
opContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
if(inMessageContext!=null){
inMessageContext.setProcessingFault(true);
}
}
if (value != null) {
processResponse(method, msgContext);
}
if (org.apache.axis2.util.Utils.isClientThreadNonBlockingPropertySet(msgContext)) {
throw new AxisFault(Messages.getMessage("transportError",
String.valueOf(statusCode),
method.getStatusText()));
}
} else if (nonErrorCodes != null && nonErrorCodes.contains(statusCode)) {
msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
processResponse(method, msgContext);
return;
} else {
// Since we don't process the response, we must release the connection immediately
method.releaseConnection();
//solving CARBON-16056
msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_CODE, method.getStatusCode());
AxisFault axisFault = new AxisFault(
Messages.getMessage("transportError", String.valueOf(statusCode), method.getStatusText()),
msgContext);
axisFault.setFaultCode(String.valueOf(method.getStatusCode()));
throw axisFault;
}
}
示例11: makeGetAvailableOMRequest
import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
/**
* Makes a pressure DB getAvailableOM request, parses the response and returns it as a formatted POJO.
*
* @param wellID
* @param serviceUrl
* @return
* @throws Exception
*/
public AvailableOMResponse makeGetAvailableOMRequest(String wellID, String serviceUrl) throws PortalServiceException {
//Generate and then make the request
HttpMethodBase method = null;
Document doc = null;
try {
method = methodMaker.makeGetAvailableOMMethod(serviceUrl, wellID);
InputStream stream = httpServiceCaller.getMethodResponseAsStream(method);
doc = DOMUtil.buildDomFromStream(stream, false);
} catch (Exception ex) {
throw new PortalServiceException(method, "Unable to make/parse response", ex);
} finally {
if (method != null) {
method.releaseConnection();
}
}
//ensure we don't have an error response
PressureDBExceptionParser.checkForExceptionResponse(doc);
//Parse the XML document into a AvailableOMResponse
AvailableOMResponse response = new AvailableOMResponse();
try {
response.setWellID((String) DOMUtil.compileXPathExpr("AvailableOM/Observations/@Well__Id").evaluate(doc, XPathConstants.STRING));
response.setOmUrl((String) DOMUtil.compileXPathExpr("AvailableOM/Observations/omUrl").evaluate(doc, XPathConstants.STRING));
response.setObsTemperature(extractBooleanXPath("AvailableOM/Observations/temperature", doc));
response.setObsPressureData(extractBooleanXPath("AvailableOM/Observations/pressureData", doc));
response.setObsSalinity(extractBooleanXPath("AvailableOM/Observations/salinity", doc));
response.setPressureRft(extractBooleanXPath("AvailableOM/PressureFeature/rft", doc));
response.setPressureDst(extractBooleanXPath("AvailableOM/PressureFeature/dst", doc));
response.setPressureFitp(extractBooleanXPath("AvailableOM/PressureFeature/fitp", doc));
response.setSalinityTds(extractBooleanXPath("AvailableOM/SalinityFeature/tds", doc));
response.setSalinityNacl(extractBooleanXPath("AvailableOM/SalinityFeature/nacl", doc));
response.setSalinityCl(extractBooleanXPath("AvailableOM/SalinityFeature/cl", doc));
response.setTemperatureT(extractBooleanXPath("AvailableOM/TemperatureFeature/t", doc));
} catch (Exception e) {
throw new PortalServiceException(method, "Unable to parse <AvailableOM> XML response", e);
}
return response;
}