@GET public final Response get(@Context UriInfo uriInfo, @Context HttpHeaders headers, @PathParam("path") String path) { final URI uri = buildUri(path, uriInfo.getQueryParameters()); logger.info("Getting URI: '{}'", uri); final Request<?, com.atlassian.sal.api.net.Response> salRequest = buildSalRequest(uri, headers.getRequestHeaders()); try { return salRequest.executeAndReturn(new JaxRsResponseHandler()); } catch (ResponseException e) { return Response.serverError().entity(e.getMessage()).build(); } }
@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); }
if (e.getCause() instanceof ConnectException) { return new RestResponse("Unable to connect to Jenkins. Connection timed out."); } else { return new RestResponse("Failed to execute request: " + e.getMessage());
exception.set((Throwable) ObjectUtils.defaultIfNull(re.getCause(), re));
} catch (ResponseException e) { resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); resp.getWriter().write(e.toString()); return;
exception.set((Throwable) ObjectUtils.defaultIfNull(re.getCause(), re)); } finally { Thread.currentThread().setContextClassLoader(currentContextClassloader);
private Response listEntities(final String applicationId, final boolean useAnonymousAccess) { final ApplicationLink link; try { link = applicationLinkService.getApplicationLink(new ApplicationId(applicationId)); } catch (TypeNotInstalledException e) { return badRequest(String.format("Failed to load application %s as the %s type is not installed", applicationId, e.getType())); } Response response; if (link == null) { response = notFound("No application link found with id: " + applicationId); } else { try { if (useAnonymousAccess) { response = ok(new ReferenceEntityList(entityRetriever.getEntitiesForAnonymousAccess(link))); } else { response = ok(new ReferenceEntityList(entityRetriever.getEntities(link))); } } catch (CredentialsRequiredException e) { response = credentialsRequired(i18nResolver); } catch (ResponseException e) { response = serverError(e.toString()); } } return response; }
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); } }
resp.sendError(404, "A credentials error occurred when executing a request to the remote application"); } catch (ResponseException e) { log.error("doGet - Caught a response exception:" + e.getMessage()); resp.sendError(404, "An error occurred when executing a request to the remote application");
if (e.getCause() instanceof ConnectException) { return new RestResponse("Unable to connect to Jenkins. Connection timed out."); } else { return new RestResponse("Failed to execute request: " + e.getMessage());
Throwable t = e.getCause(); if (t != null && t instanceof IOException)
@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); } } });
private void addOrRemoveConsumer(final ApplicationLink applicationLink, final boolean enabled, final Map<String, String> fieldErrorMessages) throws IOException { if (enabled) { try { final Consumer consumer = OAuthHelper.fetchConsumerInformation(applicationLink); serviceProviderStoreService.addConsumer(consumer, applicationLink); } catch (ResponseException e) { LOG.error("Error occurred when trying to fetch the consumer information from the remote application for application link '" + applicationLink + "'", e); fieldErrorMessages.put(COMMUNICATION_CONTEXT_PARAM, i18nResolver.getText("auth.oauth.config.error.communication.consumer", e.getMessage())); } catch (Exception e) { LOG.error("Error occurred when trying to store consumer information for application link '" + applicationLink + "'", e); fieldErrorMessages.put(COMMUNICATION_CONTEXT_PARAM, i18nResolver.getText("auth.oauth.config.error.consumer.add", e.getMessage())); } } else { try { serviceProviderStoreService.removeConsumer(applicationLink); } catch (Exception e) { LOG.error("Error occurred when trying to remove consumer from application link '" + applicationLink + "'.", e); fieldErrorMessages.put(COMMUNICATION_CONTEXT_PARAM, i18nResolver.getText("auth.oauth.config.error.consumer.remove", e.getMessage())); } } }
@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); } } });
/** * We send the message to the partitions * * @param message the message * @param partition the partition * @param roomMap the map with each room information */ private void sendMessageToCurrentPartition(String message, List<String> partition, Map<String, Result<ExpandedRoom>> roomMap) { int errorCount = 0; for (String room : partition) { try { Result<ExpandedRoom> expandedRoom = roomMap.get(room); if (expandedRoom.isSuccess() && !expandedRoom.success().getIsGuestAccessible()) { api.notifyRoom(room, message, HipChatNotificationOptions.GREEN); } } catch (ResponseException e) { logger.error(" Error while sending message to HipChat", e.getMessage()); errorCount++; // If we reached 3 errors, then we break this partition, and wait for the other if (errorCount >= RETRIES) { break; } } } }
/** * 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); } }
log.info("Error connecting to server: " + e.getMessage(), e); addError("url", getText("editinstances.errors.connection"));
/** * 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); } }
connectionErrors.add("Unexpected error when connecting to '" + applicationLink.getName() + "' (" + ex.getMessage() + ")");
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(); }