com.atlassian.sal.api.net.Response.getResponseBodyAsStream()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中com.atlassian.sal.api.net.Response.getResponseBodyAsStream方法的一些代码示例,展示了Response.getResponseBodyAsStream的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getResponseBodyAsStream方法的具体详情如下:
包路径:com.atlassian.sal.api.net.Response
类名称:Response
方法名:getResponseBodyAsStream

Response.getResponseBodyAsStream介绍

暂无

代码示例

代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-module

public InputStream getResponseBodyAsStream()
    throws ResponseException {
  return delegateResponse.getResponseBodyAsStream();
}

代码示例来源:origin: com.atlassian.cpji/cpji-jira-plugin

public static String getResponseAsTrimmedString(Response response, final long max_length) throws ResponseException {
  final BufferedReader reader = new BufferedReader(new InputStreamReader(response.getResponseBodyAsStream()));
  final int buffer_length = DEFAULT_BUFFER_LENGTH > max_length ? (int)max_length : DEFAULT_BUFFER_LENGTH;
  try{
    final StringBuilder stringBuilder = new StringBuilder();
    char[] buffer = new char[buffer_length];
    int len = 0;
    while(( len = reader.read(buffer)) != -1){
      stringBuilder.append(buffer, 0, len);
      if(stringBuilder.length() > max_length){
        log.error("Response body exceeded maximum permitted length ({}). Please contact support for assistance.", max_length);
        return stringBuilder.toString();
      }
    }
    return stringBuilder.toString();
  } catch(IOException e){
    throw new ResponseException(e);
  } finally {
    IOUtils.closeQuietly(reader);
  }
}

代码示例来源:origin: com.atlassian.jira.plugins/jira-workflow-sharing-plugin

@Override
  public void handle(com.atlassian.sal.api.net.Response response) throws ResponseException
  {
    try
    {
      String pluginsJson = IOUtils.toString(response.getResponseBodyAsStream());
      holder.setJson(pluginsJson);
    }
    catch (IOException e)
    {
      throw new ResponseException(e);
    }
  }
});

代码示例来源:origin: com.atlassian.jira.plugins/jira-workflow-sharing-plugin

@Override
  public void handle(com.atlassian.sal.api.net.Response response) throws ResponseException
  {
    try
    {
      String pluginsJson = IOUtils.toString(response.getResponseBodyAsStream());
      holder.setJson(pluginsJson);
    }
    catch (IOException e)
    {
      throw new ResponseException(e);
    }
  }
});

代码示例来源:origin: com.marvelution.jira.plugins/jira-jenkins-plugin

public RestResponse(Response response) {
  statusCode = response.getStatusCode();
  statusMessage = response.getStatusText();
  successful = response.isSuccessful();
  try {
    responseBody = IOUtils.toString(response.getResponseBodyAsStream(), "UTF-8");
    json = new JSONObject(responseBody);
  } catch (JSONException e) {
    json = null;
    errors.add("Failed to parse server response as JSON: " + e.getMessage());
  } catch (Throwable e) {
    errors.add("Failed to retrieve the response from Jenkins: " + e.getMessage());
  }
}

代码示例来源:origin: com.marvelution.atlassian.suite.plugins/atlassian-sonarqube-common

/**
 * Constructor
 *
 * @param response the Response to get the data from
 */
public RestResponse(Response response) {
  statusCode = response.getStatusCode();
  statusMessage = response.getStatusText();
  headers = response.getHeaders();
  successful = response.isSuccessful();
  try {
    responseBody = IOUtils.toString(response.getResponseBodyAsStream());
    json = new JSONObject(responseBody);
  } catch (JSONException e) {
    json = null;
    // Ignoring this, probably not needed for the request that was send
  } catch (Throwable e) {
    errors.add("Failed to retrieve the response from SonarQube: " + e.getMessage());
  }
}

代码示例来源:origin: com.atlassian.applinks/applinks-plugin

private String getTruncatedBody(@Nonnull Response response) {
  try (Reader contents = new InputStreamReader(response.getResponseBodyAsStream(), getContentEncoding(response))) {
    return StringTruncator.forInput(contents)
        .maxLines(MAX_RESPONSE_SIZE)
        .maxCharsInLine(MAX_RESPONSE_SIZE)
        .truncate();
  } catch (Exception e) {
    // at this stage we're already constructing an error (that was likely due a connection problem), so it is
    // somewhat expected that reading the response contents may fail
    log.debug("Could not retrieve response body", e);
    return "<Could not retrieve response body>";
  }
}

代码示例来源:origin: com.atlassian.jira/jira-issue-link-confluence-plugin

private static String getResponseBodyAsString(final Response response) throws ResponseException
{
  // Avoids a warning in the logs about buffering a response of unknown length.
  // TODO: This is a DoS vector, but considered relatively safe for now, as remote JIRA must be applinked.
  final InputStream responseBodyStream = response.getResponseBodyAsStream();
  final String charset = getCharset(response);
  try
  {
    return IOUtil.toString(responseBodyStream, charset);
  }
  catch (final IOException exception)
  {
    throw new ResponseException("Failed to read remote JIRA issue", exception);
  }
}

代码示例来源:origin: com.atlassian.jira/jira-issue-link-remote-jira-plugin

private static String getResponseBodyAsString(final Response response) throws ResponseException
{
  // Avoids a warning in the logs about buffering a response of unknown length.
  // TODO: This is a DoS vector, but considered relatively safe for now, as remote JIRA must be applinked.
  final InputStream responseBodyStream = response.getResponseBodyAsStream();
  final String charset = getCharset(response);
  try
  {
    return IOUtil.toString(responseBodyStream, charset);
  }
  catch (final IOException exception)
  {
    throw new ResponseException("Failed to read remote JIRA issue", exception);
  }
}

代码示例来源:origin: com.atlassian.jira/jira-issue-link-confluence-plugin

private static String getResponseBodyAsString(final Response response) throws ResponseException
{
  // Avoids a warning in the logs about buffering a response of unknown length.
  // TODO: This is a DoS vector, but considered relatively safe for now, as remote JIRA must be applinked.
  final InputStream responseBodyStream = response.getResponseBodyAsStream();
  final String charset = getCharset(response);
  try
  {
    return IOUtil.toString(responseBodyStream, charset);
  }
  catch (final IOException exception)
  {
    throw new ResponseException("Failed to read remote JIRA issue", exception);
  }
}

代码示例来源:origin: com.atlassian.applinks/applinks-common

final Document doc = docBuilder.parse(response.getResponseBodyAsStream());

代码示例来源:origin: com.atlassian.jira.plugins/jira-fisheye-plugin

public ServerInfo handle(final Response response) throws ResponseException
  {
    if (log.isTraceEnabled())
    {
      log.trace("Server response is: {}", response.getResponseBodyAsString());
    }
    // the fact that this resource doesn't exist tells us that this is a Standalone instance
    if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND)
    {
      log.debug("Request to '{}' returned 404. Assuming Crucible standalone", url);
      return ServerInfo.crucibleStandalone();
    }
    if (response.isSuccessful())
    {
      InputStream inputStream = response.getResponseBodyAsStream();
      try
      {
        ServerInfo serverInfo = ServerInfo.fromXML(inputStream);
        log.debug("Request to '{}' returned {}", url, serverInfo);
        return serverInfo;
      }
      finally
      {
        IOUtils.closeQuietly(inputStream);
      }
    }
    log.warn("Request to '{}' returned status code {}. Assuming FishEye+Crucible both available", url, response.getStatusCode());
    return ServerInfo.fisheyeAndCrucible();
  }
});

代码示例来源:origin: com.atlassian.jira.plugins/jira-fisheye-plugin

private Document extractDocumentFrom(Response response) throws ResponseException
  Reader responseReader = new BufferedReader(new InputStreamReader(response.getResponseBodyAsStream(), charset == null ? charsetHelper.defaultCharset() : charset));
  try

代码示例来源:origin: com.atlassian.jira.plugins/jira-fisheye-plugin

private Document extractDocumentFrom(Response response) throws ResponseException
  Reader responseReader = new BufferedReader(new InputStreamReader(response.getResponseBodyAsStream(), charset == null ? charsetHelper.defaultCharset() : charset));
  try

代码示例来源:origin: com.atlassian.jira.plugins/jira-fisheye-plugin

public ServerInfo handle(final Response response) throws ResponseException
  {
    if (log.isTraceEnabled())
    {
      log.trace("Server response is: {}", response.getResponseBodyAsString());
    }
    // the fact that this resource doesn't exist tells us that this is a Standalone instance
    if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND)
    {
      log.debug("Request to '{}' returned 404. Assuming Crucible standalone", url);
      return ServerInfo.crucibleStandalone();
    }
    if (response.isSuccessful())
    {
      InputStream inputStream = response.getResponseBodyAsStream();
      try
      {
        ServerInfo serverInfo = ServerInfo.fromXML(inputStream);
        log.debug("Request to '{}' returned {}", url, serverInfo);
        return serverInfo;
      }
      finally
      {
        IOUtils.closeQuietly(inputStream);
      }
    }
    log.warn("Request to '{}' returned status code {}. Assuming FishEye+Crucible both available", url, response.getStatusCode());
    return ServerInfo.fisheyeAndCrucible();
  }
});

代码示例来源:origin: com.atlassian.jira.plugins/jira-fisheye-plugin

respJson = IOUtils.toString(response.getResponseBodyAsStream(), "UTF-8");
} catch (IOException e) {
  problems.add(new IntegrationProblem(stashLink,

代码示例来源:origin: com.atlassian.stash/stash-java-client-applinks

public T handle(Response response) {
    try {
      HttpResponse coreResponse = new HttpResponse(response.getStatusCode(), response.getStatusText(),
          response.getHeaders(), response.getResponseBodyAsStream());
      return responseProcessor.process(coreResponse);
    } catch (IOException | ResponseException e) {
      throw new StashException(e);
    }
  }
}

代码示例来源:origin: com.atlassian.confluence.plugins/confluence-jira3-plugin

public Object handle(Response resp) throws ResponseException
{
  try
  {
    if("ERROR".equals(resp.getHeader("X-Seraph-Trusted-App-Status")))
    {
      String taError = resp.getHeader("X-Seraph-Trusted-App-Error");
      throw new TrustedAppsException(taError);
    }
    checkForErrors(resp.isSuccessful(), resp.getStatusCode(), resp.getStatusText());
    responseHandler.handleJiraResponse(resp.getResponseBodyAsStream(), null);
  }
  catch (IOException e)
  {
    throw new ResponseException(e);
  }
  return null;
}

代码示例来源:origin: com.atlassian.stash.plugins/stash-source-annotation-support

@Override
public Void handle(Response response) throws ResponseException {
  try {
    if (!response.isSuccessful()) {
      throw new ResponseException("Unexpected error response: " + response.getStatusCode() + ": "
          + response.getResponseBodyAsString());
    }
    if (isEmpty(response)) {
      throw new EmptyResponseException();
    }
    // transfer the body if available
    InputStream responseStream = response.getResponseBodyAsStream();
    if (responseStream != null) {
      copyInputStreamToFile(responseStream, output);
    }
    return null;
  } catch (IOException e) {
    throw new ResponseException(e);
  }
}

代码示例来源:origin: com.atlassian.bitbucket.server.plugin/source-annotation-support

@Override
public Void handle(Response response) throws ResponseException {
  try {
    if (!response.isSuccessful()) {
      throw new ResponseException("Unexpected error response: " + response.getStatusCode() + ": "
          + response.getResponseBodyAsString());
    }
    if (isEmpty(response)) {
      throw new EmptyResponseException();
    }
    // transfer the body if available
    InputStream responseStream = response.getResponseBodyAsStream();
    if (responseStream != null) {
      copyInputStreamToFile(responseStream, output);
    } else {
      throw new EmptyResponseException();
    }
    return null;
  } catch (IOException e) {
    throw new ResponseException(e);
  }
}

相关文章