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


Java InputStreamResponseHandler类代码示例

本文整理汇总了Java中me.chanjar.weixin.common.util.http.InputStreamResponseHandler的典型用法代码示例。如果您正苦于以下问题:Java InputStreamResponseHandler类的具体用法?Java InputStreamResponseHandler怎么用?Java InputStreamResponseHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InputStreamResponseHandler类属于me.chanjar.weixin.common.util.http包,在下文中一共展示了InputStreamResponseHandler类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import me.chanjar.weixin.common.util.http.InputStreamResponseHandler; //导入依赖的package包/类
@Override
public File execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, 
    WxMpQrCodeTicket ticket) throws WxErrorException, IOException {
  if (ticket != null) {
    if (uri.indexOf('?') == -1) {
      uri += '?';
    }
    uri += uri.endsWith("?") 
        ? "ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8") 
        : "&ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8");
  }
  
  HttpGet httpGet = new HttpGet(uri);
  if (httpProxy != null) {
    RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
    httpGet.setConfig(config);
  }

  try (CloseableHttpResponse response = httpclient.execute(httpGet);
      InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);) {
    Header[] contentTypeHeader = response.getHeaders("Content-Type");
    if (contentTypeHeader != null && contentTypeHeader.length > 0) {
      // 出错
      if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
        String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
        throw new WxErrorException(WxError.fromJson(responseContent));
      }
    }
    return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
  } finally {
    httpGet.releaseConnection();
  }

}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:35,代码来源:QrCodeRequestExecutor.java

示例2: execute

import me.chanjar.weixin.common.util.http.InputStreamResponseHandler; //导入依赖的package包/类
@Override
public InputStream execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, IOException {
  HttpPost httpPost = new HttpPost(uri);
  if (httpProxy != null) {
    RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
    httpPost.setConfig(config);
  }

  Map<String, String> params = new HashMap<>();
  params.put("media_id", materialId);
  httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
  try (CloseableHttpResponse response = httpclient.execute(httpPost);
      InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);){
    // 下载媒体文件出错
    byte[] responseContent = IOUtils.toByteArray(inputStream);
    String responseContentString = new String(responseContent, "UTF-8");
    if (responseContentString.length() < 100) {
      try {
        WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);
        if (wxError.getErrorCode() != 0) {
          throw new WxErrorException(wxError);
        }
      } catch (com.google.gson.JsonSyntaxException ex) {
        return new ByteArrayInputStream(responseContent);
      }
    }
    return new ByteArrayInputStream(responseContent);
  }finally {
    httpPost.releaseConnection();
  }
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:32,代码来源:MaterialVoiceAndImageDownloadRequestExecutor.java

示例3: execute

import me.chanjar.weixin.common.util.http.InputStreamResponseHandler; //导入依赖的package包/类
@Override
public InputStream execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, String materialId) throws WxErrorException, IOException {
  HttpPost httpPost = new HttpPost(uri);
  if (httpProxy != null) {
    RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
    httpPost.setConfig(config);
  }

  Map<String, String> params = new HashMap<String, String>();
  params.put("media_id", materialId);
  httpPost.setEntity(new StringEntity(WxGsonBuilder.create().toJson(params)));
  CloseableHttpResponse response = httpclient.execute(httpPost);
  InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
  try {
    // 下载媒体文件出错
    byte[] responseContent = IOUtils.toByteArray(inputStream);
    String responseContentString = new String(responseContent, "UTF-8");
    if (responseContentString.length() < 100) {
      try {
        WxError wxError = WxGsonBuilder.create().fromJson(responseContentString, WxError.class);
        if (wxError.getErrorCode() != 0) {
          throw new WxErrorException(wxError);
        }
      } catch (com.google.gson.JsonSyntaxException ex) {
        return new ByteArrayInputStream(responseContent);
      }
    }
    return new ByteArrayInputStream(responseContent);
  }finally {
    IOUtils.closeQuietly(inputStream);
    IOUtils.closeQuietly(response);
    httpPost.releaseConnection();
  }
}
 
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:35,代码来源:MaterialVoiceAndImageDownloadRequestExecutor.java

示例4: execute

import me.chanjar.weixin.common.util.http.InputStreamResponseHandler; //导入依赖的package包/类
@Override
public File execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, 
    WxMpQrCodeTicket ticket) throws WxErrorException, IOException {
  if (ticket != null) {
    if (uri.indexOf('?') == -1) {
      uri += '?';
    }
    uri += uri.endsWith("?") 
        ? "ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8") 
        : "&ticket=" + URLEncoder.encode(ticket.getTicket(), "UTF-8");
  }
  
  HttpGet httpGet = new HttpGet(uri);
  if (httpProxy != null) {
    RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
    httpGet.setConfig(config);
  }

  CloseableHttpResponse response = httpclient.execute(httpGet);
  InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
  try {
    Header[] contentTypeHeader = response.getHeaders("Content-Type");
    if (contentTypeHeader != null && contentTypeHeader.length > 0) {
      // 出错
      if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
        String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
        throw new WxErrorException(WxError.fromJson(responseContent));
      }
    }
    return FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), "jpg");
  } finally {
    IOUtils.closeQuietly(inputStream);
    IOUtils.closeQuietly(response);
    httpGet.releaseConnection();
  }

}
 
开发者ID:binarywang,项目名称:weixin-java-tools-for-JDK6,代码行数:38,代码来源:QrCodeRequestExecutor.java


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