當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpMethodBase.releaseConnection方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:bingoohuang,項目名稱:javacode-demo,代碼行數:9,代碼來源:HttpReq.java

示例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(); }
}
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:32,代碼來源:HttpUtils.java

示例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;
}
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:23,代碼來源:NegotiationValidator.java

示例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();
                }
            }
        };
}
 
開發者ID:JockiHendry,項目名稱:ireport-fork,代碼行數:12,代碼來源:CommonsHTTPSender.java

示例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();
    }
}
 
開發者ID:JMMC-OpenDev,項目名稱:jMCS,代碼行數:18,代碼來源:Http.java

示例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;
}
 
開發者ID:AuScope,項目名稱:detcrc-portal,代碼行數:46,代碼來源:GeodesyService.java

示例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();
    }
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:50,代碼來源:HttpClientUtils.java

示例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();
    }
}
 
開發者ID:niuxuetao,項目名稱:paxml,代碼行數:47,代碼來源:HttpTag.java

示例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);
    }
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:57,代碼來源:AbstractHTTPSender.java

示例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;
    }
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:77,代碼來源:HTTPSender.java

示例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;
}
 
開發者ID:AuScope,項目名稱:detcrc-portal,代碼行數:54,代碼來源:PressureDBService.java


注:本文中的org.apache.commons.httpclient.HttpMethodBase.releaseConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。