@Nonnull public <T> T getEntity(Class<T> entityClass) throws ResponseException { checkException(); if (responseEntity == null) { throw new AssertionError("Entity was requested, but not provided"); } if (!entityClass.isInstance(responseEntity)) { throw new ResponseException(String.format("Provided entity: %s, but requested %s", responseEntity.getClass().getName(), entityClass.getName())); } return entityClass.cast(responseEntity); }
@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); } } });
@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); } } });
/** * Extracts a ServerInfo from a FishEye server's XML response. * * @param serverResponse an InputStream containing the server's XML response * @return a ServerInfo */ public static ServerInfo fromXML(InputStream serverResponse) throws ResponseException { try { SAXReader xmlReader = SecureDom4jFactory.newSaxReader(); Document document = xmlReader.read(serverResponse); return new ServerInfo(document); } catch (Exception e) { throw new ResponseException(format("Error parsing response [%s]", serverResponse), e); } }
/** * Extracts a ServerInfo from a FishEye server's XML response. * * @param serverResponse an InputStream containing the server's XML response * @return a ServerInfo */ public static ServerInfo fromXML(InputStream serverResponse) throws ResponseException { try { SAXReader xmlReader = SecureDom4jFactory.newSaxReader(); Document document = xmlReader.read(serverResponse); return new ServerInfo(document); } catch (Exception e) { throw new ResponseException(format("Error parsing response [%s]", serverResponse), e); } }
private HipChatLink getDefaultHipChatLink() throws ResponseException { logger.debug("Checking for HipChat links."); final Option<HipChatLink> link = hipchatLinkProvider.getDefaultLink(); if (!link.isDefined()) { logger.error("No hipChat link defined"); throw new ResponseException("No hipchat link currently configured"); } return link.get(); }
public Object credentialsRequired(Response response) throws ResponseException { throw new ResponseException(new CredentialsRequiredException(requestFactory, "")); // return null; } });
public Boolean handle(final Response response) throws ResponseException { if (response.getStatusCode() == 200) { // deleted reciprocal link, continue return false; } else { throw new ResponseException(String.format("Received %s - %s", response.getStatusCode(), response.getStatusText() )); } }
public void handle(final Response response) throws ResponseException { if (response.getStatusCode() == 200) { // deleted reciprocal link, continue } else { throw new ResponseException(String.format("Received %s - %s", response.getStatusCode(), response.getStatusText() )); } } });
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() )); } } });
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())); } } });
public Document handle(Response response) throws ResponseException { log(response); alreadyTriedURLs.add(nextTryURL.get()); if (!response.isSuccessful()) { throw new ResponseException(String.format("Received status code %d (%s)", response.getStatusCode(), response.getStatusText())); } // update the redirect info if (REDIRECT_STATUS_CODES.contains(response.getStatusCode())) { String location = response.getHeader("location"); if (location == null) { throw new ResponseException(String.format("Received status code %d (%s) but no location was specified", response.getStatusCode(), response.getStatusText())); } nextTryURL.set(location); return null; } return extractDocumentFrom(response); }
@Override public void handle(Response response) throws ResponseException { if (!response.isSuccessful()) { throw new ResponseException("Registration failed, received " + response.getStatusCode() + " " + response.getStatusText() + " from peer."); } } });
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); } }
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); } }
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); } }
@Override protected void signRequest() throws ResponseException { final com.atlassian.oauth.Request oAuthRequest = createUnsignedRequest(); final com.atlassian.oauth.Request signedRequest = consumerService.sign(oAuthRequest, serviceProvider, consumerToken); final OAuthMessage oAuthMessage = OAuthHelper.asOAuthMessage(signedRequest); try { wrappedRequest.setHeader("Authorization", oAuthMessage.getAuthorizationHeader(null)); } catch (IOException e) { throw new ResponseException("Unable to generate OAuth Authorization request header.", e); } } }
protected void signRequest() throws ResponseException { final com.atlassian.oauth.Request oAuthRequest = createUnsignedRequest(); final com.atlassian.oauth.Request signedRequest = consumerService.sign(oAuthRequest, serviceProvider); final OAuthMessage oAuthMessage = OAuthHelper.asOAuthMessage(signedRequest); try { wrappedRequest.setHeader("Authorization", oAuthMessage.getAuthorizationHeader(null)); } catch (IOException e) { throw new ResponseException("Unable to generate OAuth Authorization request header.", e); } }
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; }
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 { checkStatusOk(response); try { manifestHolder.set(asManifest(response.getEntity(ManifestEntity.class))); } catch (Exception ex) { exception.set(new ResponseContentException(response, ex)); } } } });