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


Java HttpMethod.getResponseBodyAsStream方法代码示例

本文整理汇总了Java中org.apache.commons.httpclient.HttpMethod.getResponseBodyAsStream方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.getResponseBodyAsStream方法的具体用法?Java HttpMethod.getResponseBodyAsStream怎么用?Java HttpMethod.getResponseBodyAsStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.httpclient.HttpMethod的用法示例。


在下文中一共展示了HttpMethod.getResponseBodyAsStream方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doService

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
private void doService(HttpMethod method, HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
    outputRequestLog(req);

    InputStream iStream = null;
    ServletOutputStream oStream = null;
    try {
        long threadID = Thread.currentThread().getId();
        log.debug("[" + threadID + "] forwarded to " + distributer.getRedirectUrl(req));
        HttpClient client = new HttpClient();
        log.debug("[" + threadID + "]send request.");
        int resultCode = client.executeMethod(method);
        log.debug("[" + threadID + "]got response: result code is " + resultCode);
        res.setStatus(resultCode);
        for (Header header : method.getResponseHeaders()) {
            res.setHeader(header.getName(), header.getValue());
        }
        iStream = method.getResponseBodyAsStream();
        oStream = res.getOutputStream();

        writeOutputStream(iStream, oStream);

        log.debug("[" + threadID + "] response sent to client.");
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new ServletException(e.getMessage(), e);
    } finally {
        if (iStream != null) {
            iStream.close();
        }
        if (oStream != null) {
            oStream.close();
        }
    }
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:36,代码来源:ForwarderServlet.java

示例2: decryptResponseBody

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public byte[] decryptResponseBody(HttpMethod method) throws IOException
{
    // TODO fileoutputstream if content is especially large?
    InputStream body = method.getResponseBodyAsStream();
    if(body != null)
    {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        FileCopyUtils.copy(body, out);

        AlgorithmParameters params = decodeAlgorithmParameters(method);
        if(params != null)
        {
            byte[] decrypted = encryptor.decrypt(KeyProvider.ALIAS_SOLR, params, out.toByteArray());
            return decrypted;
        }
        else
        {
            throw new AlfrescoRuntimeException("Unable to decrypt response body, missing encryption algorithm parameters");
        }
    }
    else
    {
        return null;
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:30,代码来源:DefaultEncryptionUtils.java

示例3: retrieve

import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
@Override
   public Object retrieve(IDataSource snDataSource, Object object) throws RetrieverException {
                               
       HttpClient client = (HttpClient)snDataSource.connect();
       
       // We should use an encoded query in this case because URL parameters do not support the full semantics of a filter.        
       String serviceUrl     = AppProperties.getProperty("service_url");
       String restPath       = AppProperties.getProperty("rest_path");
       String resultLimit    = AppProperties.getProperty("result_limit");
       String period_of_time = AppProperties.getProperty("period_of_time");
       String url1           = "?sysparm_query=active%3Dtrue%5Estate!%3D6%5Esys_created_onRELATIVEGE%40hour%40ago%40" + period_of_time;
       String url2           = "%5Eassignment_group%3D81db147e2b5c79444dde23f119da153b&sysparm_display_value=true&sysparm_fields=sys_id%2Cnumber%2Cshort_description%2Cdescription&sysparm_limit=" + resultLimit;
       
       String finalUrl = serviceUrl + restPath + url1 + url2;
       
       HttpMethod method = new GetMethod(finalUrl);
       method.addRequestHeader("Accept", "application/json");
       String message = "";
       try {
           int status = client.executeMethod(method);
           log.info("Status:" + status);
           BufferedReader rd = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));     
           message = org.apache.commons.io.IOUtils.toString(rd);
       } catch (IOException ioe) {
           throw new RetrieverException(ioe.toString());
       }
       
       // remove leading and ending "{"
       int index = message.indexOf("\"result\":");
       message = message.substring(index+9, message.length()-1);
       
Gson gson = new Gson(); 
       ServiceNowTicket[] wrapper = null;
       try {
           wrapper = gson.fromJson(message, ServiceNowTicket[].class);   
       } catch (Exception e) {
           log.error(e.toString());
       }
       
       if (wrapper == null) {
           log.error("Problem retrieving information from ServiceNow");
           return null;
       }
       log.info("number of fetched tickets: " + wrapper.length);
       List<ServiceNowTicket> ticketList = Arrays.asList(wrapper);  
       
       for (Iterator<ServiceNowTicket> it = ticketList.iterator(); it.hasNext();) {
           ServiceNowTicket ticket = it.next();
           log.info("Fetching IP address and date");
           String source    = StringUtils.substringBetween(ticket.getDescription(), "<Source>", "</Source>");
           String timeStamp = StringUtils.substringBetween(source, "<TimeStamp>", "</TimeStamp>");
           String ipAddress = StringUtils.substringBetween(source, "<IP_Address>", "</IP_Address>");
           log.info("--------------------------");
           log.info("Sys_Id:    " + ticket.getSysId());
           log.info("Number:    " + ticket.getNumber());
           log.info("Timestamp: " + timeStamp);
           log.info("IPAddress: " + ipAddress);      
           log.info("--------------------------");
           log.info("");
           ClaimService service = new ClaimService();
           try {
               // fixing timestamp
               timeStamp = fixTimeStampFormat(timeStamp);
               
               // Sends data to ElasticSearch to find CWL
               IDataSource esDataSource = new ElasticSearchDataSource();
               esDataSource.connect();
               
               // Sends data to CWL database to find email address, first and last name
               
               
               
               
               // save data in the database
               service.addTicket(ticket.getNumber(), ticket.getDescription(), java.sql.Timestamp.valueOf(timeStamp), ipAddress);
           } catch (Exception de) {
               log.error(de.toString());
           }
       }
       return null;
   }
 
开发者ID:armenak,项目名称:uDetective,代码行数:82,代码来源:ServiceNowRetriever.java


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