List of usage examples for org.springframework.http HttpStatus getReasonPhrase
public String getReasonPhrase()
From source file:net.longfalcon.newsj.service.TraktService.java
public TraktEpisodeResult getEpisode(long traktId, int season, int episode) { try {// w ww . ja va2 s.c o m String traktApiUrl = config.getTraktApiUrl(); String traktAppId = config.getTraktAppId(); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("Content-type", "application/json"); httpHeaders.set("trakt-api-key", traktAppId); httpHeaders.set("trakt-api-version", "2"); HttpEntity<?> requestEntity = new HttpEntity(httpHeaders); UriComponents uriComponents = UriComponentsBuilder .fromUriString( traktApiUrl + "/shows/" + traktId + "/seasons/" + season + "/episodes/" + episode) .queryParam("extended", "full").build(); ResponseEntity<TraktEpisodeResult> responseEntity = restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, requestEntity, TraktEpisodeResult.class); HttpStatus statusCode = responseEntity.getStatusCode(); if (statusCode.is2xxSuccessful() || statusCode.is3xxRedirection()) { return responseEntity.getBody(); } else { _log.error(String.format("Trakt Search request: \n%s\n failed with HTTP code %s : %s", uriComponents.toString(), statusCode.toString(), statusCode.getReasonPhrase())); return null; } } catch (Exception e) { _log.error(e.toString(), e); } return null; }
From source file:nl.ellipsis.webdav.server.methods.AbstractMethod.java
/** * Send a multistatus element containing a complete error report to the client. * If the errorList contains only one error, send the error directly without * wrapping it in a multistatus message. * /*from w ww. j a v a 2 s. c om*/ * @param req * Servlet request * @param resp * Servlet response * @param errorList * List of error to be displayed */ protected static void sendReport(HttpServletRequest req, HttpServletResponse resp, Hashtable<String, Integer> errorList) throws IOException { if (errorList.size() == 1) { int code = errorList.elements().nextElement(); HttpStatus s = HttpStatus.valueOf(code); String status = s.getReasonPhrase(); if (status != null && !status.isEmpty()) { resp.sendError(code, status); } else { resp.sendError(code); } } else { resp.setStatus(HttpStatus.MULTI_STATUS.value()); String absoluteUri = req.getRequestURI(); // String relativePath = getRelativePath(req); XMLWriter generatedXML = new XMLWriter(); generatedXML.writeXMLHeader(); generatedXML.writeElement(NS_DAV_PREFIX, NS_DAV_FULLNAME, WebDAVConstants.XMLTag.MULTISTATUS, XMLWriter.OPENING); Enumeration<String> pathList = errorList.keys(); while (pathList.hasMoreElements()) { String errorPath = (String) pathList.nextElement(); int errorCode = ((Integer) errorList.get(errorPath)).intValue(); generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.RESPONSE, XMLWriter.OPENING); generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.HREF, XMLWriter.OPENING); String toAppend = null; if (absoluteUri.endsWith(errorPath)) { toAppend = absoluteUri; } else if (absoluteUri.contains(errorPath)) { int endIndex = absoluteUri.indexOf(errorPath) + errorPath.length(); toAppend = absoluteUri.substring(0, endIndex); } if (StringUtils.isEmpty(toAppend)) { toAppend = CharsetUtil.FORWARD_SLASH; } else if (!toAppend.startsWith(CharsetUtil.FORWARD_SLASH) && !toAppend.startsWith(PROTOCOL_HTTP)) { toAppend = CharsetUtil.FORWARD_SLASH + toAppend; } generatedXML.writeText(errorPath); generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.HREF, XMLWriter.CLOSING); generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.STATUS, XMLWriter.OPENING); HttpStatus s = HttpStatus.valueOf(errorCode); generatedXML.writeText("HTTP/1.1 " + errorCode + " " + s.getReasonPhrase()); generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.STATUS, XMLWriter.CLOSING); generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.RESPONSE, XMLWriter.CLOSING); } generatedXML.writeElement(NS_DAV_PREFIX, WebDAVConstants.XMLTag.MULTISTATUS, XMLWriter.CLOSING); Writer writer = resp.getWriter(); writer.write(generatedXML.toString()); writer.close(); } }
From source file:org.craftercms.studio.impl.v1.deployment.PreviewDeployerImpl.java
@EventListener(EVENT_PREVIEW_SYNC) public void onPreviewSync(PreviewEventContext context) { String site = context.getSite(); String requestUrl = getDeployTargetUrl(site); HttpPost postRequest = new HttpPost(requestUrl); if (context.isWaitTillDeploymentIsDone()) { String requestBody = getDeployTargetRequestBody(true); HttpEntity requestEntity = new StringEntity(requestBody, ContentType.APPLICATION_JSON); postRequest.setEntity(requestEntity); }// w ww . j a va 2s . c o m // TODO: DB: add all required params to post method try { CloseableHttpResponse response = httpClient.execute(postRequest); HttpStatus httpStatus = HttpStatus.valueOf(response.getStatusLine().getStatusCode()); if (!httpStatus.is2xxSuccessful()) { logger.error("Preview sync request for site " + site + " returned status " + httpStatus + " (" + httpStatus.getReasonPhrase() + ")"); } } catch (IOException e) { logger.error("Error while sending preview sync request for site " + site, e); } finally { postRequest.releaseConnection(); } }
From source file:org.finra.dm.service.helper.DmErrorInformationExceptionHandler.java
/** * Gets a new error information based on the specified message. * * @param httpStatus the status of the error. * @param exception the exception whose message will be used. * * @return the error information./*from ww w. j av a 2 s . com*/ */ private ErrorInformation getErrorInformation(HttpStatus httpStatus, Throwable exception) { ErrorInformation errorInformation = new ErrorInformation(); errorInformation.setStatusCode(httpStatus.value()); errorInformation.setStatusDescription(httpStatus.getReasonPhrase()); String errorMessage = exception.getMessage(); if (StringUtils.isEmpty(errorMessage)) { errorMessage = exception.getClass().getName(); } errorInformation.setMessage(errorMessage); List<String> messageDetails = new ArrayList<>(); Throwable causeException = exception.getCause(); while (causeException != null) { messageDetails.add(causeException.getMessage()); causeException = causeException.getCause(); } errorInformation.setMessageDetails(messageDetails); return errorInformation; }