本文整理了Java中com.atlassian.sal.api.net.Response
类的一些代码示例,展示了Response
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response
类的具体详情如下:
包路径:com.atlassian.sal.api.net.Response
类名称:Response
暂无
代码示例来源: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.studio/studio-theme-jira-plugin
/**
* Printing details about HttpRequest for error logging.
*
* @param url
* @param response
* @return
*/
private String getHttpCallDetails(final String url, final Response response)
{
try
{
return "\nRequest url: DELETE " + url +
"\nHTTP Response code: " + response.getStatusCode() +
"\nResponse body: " + response.getResponseBodyAsString();
}
catch (final ResponseException e)
{
return "\nRequest url: DELETE " + url +
"\nHTTP Response code: " + response.getStatusCode();
}
}
代码示例来源:origin: com.atlassian.applinks/applinks-common
private boolean hasLocation(final Response response) {
final String location = response.getHeader("location");
if (isBlank(location)) {
log.warn("HTTP response returned redirect code {} but did not provide a location header",
response.getStatusCode());
}
return isNotBlank(location);
}
代码示例来源:origin: com.marvelution.jira.plugins/jira-jenkins-plugin
@Override
public ApplicationStatus handle(final Response response) throws ResponseException {
return response.isSuccessful() || (response.getStatusCode() == HttpStatus.SC_FORBIDDEN) || (response.getStatusCode()
== HttpStatus.SC_UNAUTHORIZED) ? ApplicationStatus.AVAILABLE : ApplicationStatus.UNAVAILABLE;
}
代码示例来源:origin: com.atlassian.applinks/applinks-plugin
public ErrorListEntity handle(final Response response) throws ResponseException {
// 201 means we created a new application link.
// 200 means there already is an application link and we just updated this one.
return !response.isSuccessful() ?
response.getEntity(ErrorListEntity.class) :
null;
}
});
代码示例来源: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.applinks/applinks-plugin-core
public String handle(final Response response) throws ResponseException
{
if (!response.isSuccessful())
{
throw new ResponseStatusException("Unexpected response received. Status code: " + response.getStatusCode(), response);
}
return response.getResponseBodyAsString();
}
}
代码示例来源:origin: com.atlassian.refapp/atlassian-refapp-applinks-plugin
public Void handle(final Response response) throws ResponseException {
if (response.isSuccessful()) {
final String body = response.getResponseBodyAsString();
if (body == null || "".equals(body)) {
status.set(AuthenticationStatus.ANONYMOUS);
} else {
username.set(body);
status.set(AuthenticationStatus.ACCEPTED);
}
} else {
status.set(AuthenticationStatus.COMMUNICATION_ERROR);
errorMessage.set(String.format("%s: %s", response.getStatusCode(), response.getStatusText()));
}
return null;
}
代码示例来源:origin: com.atlassian.applinks/applinks-plugin
public void handle(final Response createLinkBackResponse) throws ResponseException {
if (createLinkBackResponse.getStatusCode() == 201) {
// cool! created reciprocal link, continue
} else {
throw new ResponseException(String.format("Received %s - %s",
createLinkBackResponse.getStatusCode(),
createLinkBackResponse.getStatusText()
));
}
}
});
代码示例来源:origin: com.atlassian.jwt/jwt-plugin
@Override
public void handle(Response response) throws ResponseException
{
if (!response.isSuccessful())
{
throw new ResponseException("Registration failed, received " +
response.getStatusCode() + " " + response.getStatusText() +
" from peer.");
}
}
});
代码示例来源:origin: com.atlassian.applinks/applinks-oauth-plugin
public void handle(final Response response) throws ResponseException {
responseHolder.set(response);
if (response.isSuccessful()) {
try {
List<OAuth.Parameter> parameters = OAuth.decodeForm(response.getResponseBodyAsString());
Map<String, String> map = OAuth.newMap(parameters);
oauthParametersHolder.set(map);
} catch (Exception e) {
throw new ResponseException("Failed to get token from service provider. Couldn't parse response body " + response.getResponseBodyAsString() + "'", e);
final String authHeader = response.getHeader("WWW-Authenticate");
if (authHeader != null && authHeader.startsWith("OAuth")) {
final List<OAuth.Parameter> parameters = OAuthMessage.decodeAuthorization(authHeader);
throw new ResponseException("Failed to get token from service provider. Response status code is '" + response.getStatusCode() + "'");
代码示例来源:origin: com.atlassian.applinks/applinks-plugin-core
public void handle(Response response) throws ResponseException
{
// this means the response indicates a redirection.
if (response.getStatusCode() >= 300 && response.getStatusCode() < 400)
{
final String location = response.getHeader("Location");
if (location == null)
{
throw new ResponseException("manifest not found");
}
LOG.info("Manifest request got redirected to '" + location + "'.");
exception.set(new ManifestGotRedirectedException("manifest got redirected", location));
}
else if (response.isSuccessful())
{
try
{
manifestHolder.set(asManifest(response.getEntity(ManifestEntity.class)));
}
catch (Exception ex)
{
exception.set(ex);
}
}
}
});
代码示例来源:origin: com.atlassian.applinks/applinks-plugin
public PermissionCode handle(final com.atlassian.sal.api.net.Response response) throws ResponseException {
if (response.getStatusCode() == 200) {
try {
return response.getEntity(PermissionCodeEntity.class).getCode();
} catch (Exception e) {
throw new ResponseException(
String.format("Permission check failed, exception " +
"encountered processing response: %s", e));
}
} else if (response.getStatusCode() == 401) {
ApplicationLinkRequestFactory authenticatedRequestFactory = applicationLink.createImpersonatingAuthenticatedRequestFactory();
if (authenticatedRequestFactory == null) {
authenticatedRequestFactory = applicationLink.createNonImpersonatingAuthenticatedRequestFactory();
}
if (authenticatedRequestFactory != null) {
LOG.warn("Authentication failed for application link " +
applicationLink + ". Response headers: " + response.getHeaders().toString() +
" body: " + response.getResponseBodyAsString());
} else if (LOG.isDebugEnabled()) {
LOG.debug("Authentication failed for application link " +
applicationLink + ". Response headers: " + response.getHeaders().toString() +
" body: " + response.getResponseBodyAsString());
}
return AUTHENTICATION_FAILED;
} else {
throw new ResponseException(String.format("Permission check failed, received %s",
response.getStatusCode()));
}
}
});
代码示例来源:origin: com.atlassian.refapp/platform-ctk-plugin
@Override
public void handle(Response response) throws ResponseException {
assertEquals(200, response.getStatusCode());
}
});
代码示例来源:origin: com.atlassian.hipchat.plugins/hipchat-core-plugin
@Override
public Response handle(com.atlassian.sal.api.net.Response response) throws ResponseException
{
final Response.ResponseBuilder responseBuilder = Response.status(response.getStatusCode()).entity(response.getResponseBodyAsString());
for (Map.Entry<String, String> h : filter(response.getHeaders().entrySet(), not(BLACKLISTED_HEADERS)))
{
logger.debug("adding header {}:{}", h.getKey(), h.getValue());
responseBuilder.header(h.getKey(), h.getValue());
}
return responseBuilder.build();
}
}
代码示例来源:origin: com.atlassian.applinks/applinks-plugin-core
public ApplicationStatus handle(final Response response) throws ResponseException
{
return response.isSuccessful() ?
ApplicationStatus.AVAILABLE :
ApplicationStatus.UNAVAILABLE;
}
});
代码示例来源:origin: com.atlassian.applinks/applinks-plugin
public void handle(final com.atlassian.sal.api.net.Response response) throws ResponseException {
// 201 means we created a new application link.
// 200 means there already is an application link and we just updated this one.
if (!response.isSuccessful()) {
try {
final ErrorListEntity listEntity = response.getEntity(ErrorListEntity.class);
warnings.addAll(listEntity.getErrors());
} catch (RuntimeException re) {
LOG.warn("Could not parse the peer's response to " +
"upgrade application link \"" + oldApplicationLink.getName() +
"\" to a bi-directional link. Status code: " +
response.getStatusCode() + ".");
throw re;
}
}
}
});
代码示例来源:origin: com.atlassian.applinks/applinks-tests
@Override
public Response credentialsRequired(final Response response) throws ResponseException {
responseBodyHolder[0] = response.getResponseBodyAsString();
return response;
}
代码示例来源:origin: com.atlassian.applinks/applinks-plugin
public void handle(final Response response) throws ResponseException {
if (response.getStatusCode() == 200) {
Iterables.addAll(entities, response.getEntity(ReferenceEntityList.class).getEntities(typeAccessor));
} else {
throw new ResponseException(String.format("Failed to retrieve entity list, received %s response: %s",
response.getStatusCode(), response.getStatusText()));
}
}
});
代码示例来源:origin: com.atlassian.applinks/applinks-common
public void handle(Response response) throws ResponseException {
if (response.getStatusCode() != Status.OK.getStatusCode()) {
throw new ResponseException("Server responded with an error");
final String contentTypeHeader = response.getHeader("Content-Type");
if (contentTypeHeader != null && !contentTypeHeader.toLowerCase().startsWith("application/xml")) {
throw new ResponseException("Server sent an invalid response");
final Document doc = docBuilder.parse(response.getResponseBodyAsStream());
内容来源于网络,如有侵权,请联系作者删除!