List of usage examples for org.springframework.http HttpHeaders add
@Override public void add(String headerName, @Nullable String headerValue)
From source file:org.venice.beachfront.bfapi.services.PiazzaService.java
/** * Creates Basic Auth headers with the Piazza API Key * /*from ww w . ja va2 s .c o m*/ * @param piazzaApiKey * The Piazza API Key * @return Basic Auth Headers for Piazza */ private HttpHeaders createPiazzaHeaders(String piazzaApiKey) { String plainCreds = piazzaApiKey + ":"; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); headers.setContentType(MediaType.APPLICATION_JSON); return headers; }
From source file:philharmonic.utilities.MessageSender.java
private MultiValueMap createHeaders(String component) { String plainCreds = parser.getAuthorizationForComponent(component); if (plainCreds != null && !plainCreds.isEmpty()) { byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); return headers; }/* ww w. ja v a 2 s.c o m*/ return null; }
From source file:rusch.megan5client.connector.Megan5ServerConnector.java
/** * Create connection and apply authentication. * <p/>//from www. j av a 2 s . co m * !this method doesn't test the connection. So things can still go wrong later! * * @param url * @param userName * @param password */ public Megan5ServerConnector(String url, String userName, String password) { String plainCreds = userName + ":" + password; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + base64Creds); request = new HttpEntity<>(headers); restTemplate = new RestTemplate(); if (url.endsWith("/")) { this.url = url; } else { this.url = url + "/"; } }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.AbstractPipedStreamRestSynchronizerImpl.java
private void addKeepAliveConnectionHeader(ClientHttpRequest clientHttpRequest) { log.debug("Set the Connection Header to keep-alive"); HttpHeaders headers = clientHttpRequest.getHeaders(); headers.add(HttpHeaders.CONNECTION, "keep-alive"); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestUtils.java
public static void addAuthorizationHeader(HttpHeaders headers, Authentication authentication) { headers.add(HttpHeaders.AUTHORIZATION, encodeCredentialsForBasicAuthorization(authentication)); }
From source file:ua.aits.Carpath.controller.AjaxController.java
@RequestMapping(value = { "/system/contentByType/", "/system/contentByType", "/Carpath/system/contentByType/", "/Carpath/system/contentByType" }, method = RequestMethod.GET) public @ResponseBody ResponseEntity<String> contentByType(HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding("UTF-8"); String username = request.getParameter("username"); String type = request.getParameter("type"); String value = request.getParameter("value"); int countPage = Integer.parseInt(request.getParameter("count")); int page = Integer.parseInt(request.getParameter("page")); List<ArticleModel> tempC = content.getAllContentByType(username, type, value); String returnHTML = ""; String pagination = "<tr><td colspan=\"10\" class=\"pagination\">"; int first = (countPage * page) - countPage; int second = countPage * page; if (countPage * page > tempC.size()) { first = (page - 1) * countPage;/*from w ww . j av a 2 s . c om*/ second = tempC.size(); } Integer count = tempC.size() - (first); List<ArticleModel> tempS = tempC.subList(first, second); for (ArticleModel temp : tempS) { String ur = "article/full/"; if (temp.type == 2) { ur = "map/markers/"; } String check = "checked"; String is_publish = "publish"; String temp_title = temp.title; if (temp.title.length() > 36) { temp_title = temp.title.substring(0, 36) + "..."; } if (temp.publish == 0) { check = ""; is_publish = ""; } returnHTML = returnHTML + "<tr><td>" + count.toString() + "</td>" + " <td class=\"admin-table-cell date-cell\">" + temp.date + "</td>" + " <td class=\"admin-table-cell-title\"><a href=\"http://www.carpathianroad.com/ua/" + ur + temp.id + ";jsessionid=" + request.getSession().getId() + "\" target=\"_blank\">" + temp_title + "</a></td>" + " <td class=\"admin-table-cell\">" + temp.public_country + "</td>" + " <td class=\"article-type admin-table-cell\">" + temp.textType + "</td>" + " <td class=\"catID admin-table-cell\">" + temp.menuText + "</td>" + " <td class=\"admin-table-cell\">" + temp.author + "</td>" + " <td class=\"article-publish " + is_publish + "\"><input type=\"checkbox\" data-size=\"mini\" class=\"publish-checkbox\" data-id=\"" + temp.id + "\" name=\"my-checkbox\" " + check + "></td>" + "<td class=\"" + is_publish + "\">" + " <a class=\"edit-button\" href=\"/Carpath/system/articles/edit/" + temp.id + ";jsessionid=" + request.getSession().getId() + "\"><img class=\"edit-delete\" src=\"" + Constants.URL + "img/edit.png\" /></a>" + " </td>" + " <td class=\"" + is_publish + "\">" + " <a href=\"/Carpath/system/articles/delete/" + temp.id + ";jsessionid=" + request.getSession().getId() + "\"><img class=\"edit-delete\" src=\"" + Constants.URL + "img/delete.png\" /></a>" + " </td>" + " </tr>"; count--; } Double x = Math.ceil((double) tempC.size() / countPage); int pages = x.intValue(); System.out.println(x + "///" + count / countPage + "///" + pages + "///" + count + "////" + countPage); for (int i = 1; i <= pages; i++) { pagination = pagination + "<a>" + i + "</a>"; } returnHTML = returnHTML + pagination + "</td></tr>"; HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/json; charset=utf-8"); return new ResponseEntity<>(returnHTML, responseHeaders, HttpStatus.CREATED); }
From source file:ua.aits.Carpath.controller.AjaxController.java
@RequestMapping(value = { "/system/routesByType/", "/system/routesByType", "/Carpath/system/routesByType/", "/Carpath/system/routesByType" }, method = RequestMethod.GET) public @ResponseBody ResponseEntity<String> routesByType(HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding("UTF-8"); String type = request.getParameter("type"); String value = request.getParameter("value"); int countPage = Integer.parseInt(request.getParameter("count")); int page = Integer.parseInt(request.getParameter("page")); List<RouteModel> tempRoutes = routes.getAllRoutesSystem(type, value); String returnHTML = ""; String pagination = "<tr><td colspan=\"10\" class=\"pagination\">"; int first = (countPage * page) - countPage; int second = countPage * page; if (countPage * page > tempRoutes.size()) { first = (page - 1) * countPage;//ww w .j a v a 2 s . co m second = tempRoutes.size(); } Integer count = tempRoutes.size() - (first); List<RouteModel> tempS = tempRoutes.subList(first, second); for (RouteModel temp : tempS) { String check = "checked"; String is_publish = "publish"; System.out.println(temp.id); if (temp.publish == 0) { check = ""; is_publish = ""; } returnHTML = returnHTML + "<tr><td class=\"admin-table-count\">" + count.toString() + "</td>" + " <td class=\"admin-table-cell-title\"><a href=\"http://www.carpathianroad.com/en/routes/" + temp.id + "\" target=\"_blank\">" + temp.title + "</a></td>" + " <td class=\"admin-table-cell\">" + temp.public_country + "</td>" + " <td class=\"article-type admin-table-cell\">" + temp.textType + "</td>" + " <td class=\"article-publish " + is_publish + "\"><input type=\"checkbox\" data-size=\"mini\" class=\"publish-checkbox\" data-id=\"" + temp.id + "\" name=\"my-checkbox\" " + check + "></td>" + "<td class=\"" + is_publish + "\">" + " <a class=\"edit-button\" href=\"" + Constants.URL + "system/routes/edit/" + temp.id + "\"><img class=\"edit-delete\" src=\"" + Constants.URL + "img/edit.png\" /></a>" + " </td>" + " <td class=\"" + is_publish + "\">" + " <a href=\"" + Constants.URL + "system/routes/delete/" + temp.id + "\"><img class=\"edit-delete\" src=\"" + Constants.URL + "img/delete.png\" /></a>" + " </td>" + " </tr>"; count--; } Double x = Math.ceil((double) tempRoutes.size() / countPage); int pages = x.intValue(); System.out.println(x + "///" + count / countPage + "///" + pages + "///" + count + "////" + countPage); for (int i = 1; i <= pages; i++) { pagination = pagination + "<a>" + i + "</a>"; } returnHTML = returnHTML + pagination + "</td></tr>"; HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/json; charset=utf-8"); return new ResponseEntity<>(returnHTML, responseHeaders, HttpStatus.CREATED); }
From source file:ua.aits.Carpath.controller.AjaxController.java
@RequestMapping(value = { "/build/menu/", "/build/menu", "/Carpath/build/menu/", "/Carpath/build/menu" }, method = RequestMethod.GET) public @ResponseBody ResponseEntity<String> returnMenuHtml(HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding("UTF-8"); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/json; charset=utf-8"); return new ResponseEntity<>(helpers.getRowHtml(request.getParameter("lang"), "0"), responseHeaders, HttpStatus.CREATED);/*from www . j a v a 2 s . c o m*/ }
From source file:ua.aits.Carpath.controller.AjaxController.java
@RequestMapping(value = { "/articles/loadcontent", "/Carpath/articles/loadcontent" }, method = RequestMethod.GET) public @ResponseBody ResponseEntity<String> load_content(HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding("UTF-8"); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/json; charset=utf-8"); String lan = request.getParameter("lan"); String country = request.getParameter("country"); String type = request.getParameter("type"); String menuCat = request.getParameter("menuCat"); int countPage = Integer.parseInt(request.getParameter("count")); int countNeed = countPage + 9; List<ArticleModel> tempw = content.getArticleByFilters(lan, country, type, menuCat); if (tempw == null) { return new ResponseEntity<>("", responseHeaders, HttpStatus.CREATED); }//from w w w . j a v a 2 s . c om String styleForMore = ""; if (tempw.size() < countNeed) { countNeed = tempw.size(); styleForMore = "doNotShow"; } List<ArticleModel> tempC = tempw.subList(countPage, countNeed); String returnHTML = ""; for (ArticleModel temp : tempC) { String lanURL = Constants.URL + lan + "/"; if (temp.type == 2 || temp.type == 3) { lanURL += "map/markers/"; } else { lanURL += "article/full/"; } if (!"".equals(temp.avatar) && temp.avatar != null) { temp.setImage(temp.avatar); } String[] tempImg = temp.image.split(","); returnHTML = returnHTML + "<div class=\"s-cell article-block\">\n" + " <div class=\"s-block newsHeight\">\n" + " <div class=\"newsImage\">\n" + " <a href=\"" + lanURL + temp.id + "\">\n" + " <div class=\"imageHover\">\n" + " <div class=\"imageHoverDate\">\n" + " " + temp.date + "\n" + " </div>\n" + " <div class=\"imageHoverCountry\">\n" + " <div class=\"newsCountryText\">" + temp.country + "</div><img src=\"" + Constants.URL + "img/newsImageHover.png\">\n" + " </div>\n" + " </div>\n" + " <img src=\"" + Constants.URL + tempImg[0] + "\" />\n" + " </a>\n" + " </div>\n" + "\n" + " <img class=\"newsImageUnderline\" src=\"" + Constants.URL + "img/newsLine.png\">\n" + " <div class=\"news_text_box\">\n" + " <div class=\"news_title\"><a href=\"" + lanURL + temp.id + "\">" + temp.title + "</a></div>\n" + " <a href=\"" + lanURL + temp.id + "\">\n" + " <div class=\"news_text\">" + temp.textEN + "</div></a>\n" + " </div>\n" + " </div>\n" + " </div> "; } returnHTML += "<div class=\"load-more-content " + styleForMore + "\"><a count=\"" + countNeed + "\" class=\"btn btn-theme detailsButton\"> " + "<span class=\"glyphicon glyphicon-refresh\" aria-hidden=\"true\"></span>" + "<span class=\"load-text\">LOAD MORE</span>" + "</a></div>"; return new ResponseEntity<>(returnHTML, responseHeaders, HttpStatus.CREATED); //return returnHTML; }
From source file:ua.aits.Carpath.controller.AjaxController.java
@RequestMapping(value = { "/articles/load?ontentforsearch", "/Carpath/articles/load?ontentforsearch" }, method = RequestMethod.GET) public @ResponseBody ResponseEntity<String> load_content_for_search(HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding("UTF-8"); HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.add("Content-Type", "application/json; charset=utf-8"); String lan = request.getParameter("lan"); String find = request.getParameter("find"); int countPage = Integer.parseInt(request.getParameter("count")); int countNeed = countPage + 9; String lang = lan + "/"; if (countPage == 0) { lang = ""; }//from w ww . ja va 2s . co m List<ArticleModel> tempw = content.getSearchResult(lan, find); if (tempw == null) { return new ResponseEntity<>("", responseHeaders, HttpStatus.CREATED); } String styleForMore = ""; if (tempw.size() < countNeed) { countNeed = tempw.size(); styleForMore = "doNotShow"; } List<ArticleModel> tempC = tempw.subList(countPage, countNeed); String returnHTML = ""; for (ArticleModel temp : tempC) { String lanURL = Constants.URL + lang + "article/full/"; if (temp.type == 2) { lanURL = Constants.URL + lang + "map/markers/"; } else { } if (!"".equals(temp.avatar) && temp.avatar != null) { temp.setImage(temp.avatar); } String[] tempImg = temp.image.split(","); returnHTML = returnHTML + "<div class=\"s-cell\">\n" + " <div class=\"s-block newsHeight\">\n" + " <div class=\"newsImage\">\n" + " <a href=\"" + lanURL + temp.id + "\">\n" + " <div class=\"imageHover\">\n" + " <div class=\"imageHoverDate\">\n" + " " + temp.date + "\n" + " </div>\n" + " <div class=\"imageHoverCountry\">\n" + " <div class=\"newsCountryText\">" + temp.country + "</div><img src=\"" + Constants.URL + "img/newsImageHover.png\">\n" + " </div>\n" + " </div>\n" + " <img src=\"" + Constants.URL + tempImg[0] + "\" />\n" + " </a>\n" + " </div>\n" + "\n" + " <img class=\"newsImageUnderline\" src=\"" + Constants.URL + "img/newsLine.png\">\n" + " <div class=\"news_text_box\">\n" + " <div class=\"news_title\"><a href=\"" + lanURL + temp.id + "\">" + temp.title + "</a></div>\n" + " <a href=\"" + lanURL + temp.id + "\">\n" + " <div class=\"news_text\">" + temp.textEN + "</div></a>\n" + " </div>\n" + " </div>\n" + " </div> "; } returnHTML += "<div class=\"load-more-content " + styleForMore + "\"><a count=\"" + countNeed + "\" class=\"btn btn-theme detailsButton\"> " + "<span class=\"glyphicon glyphicon-refresh\" aria-hidden=\"true\"></span>" + "<span class=\"load-text\">LOAD MORE</span>" + "</a></div>"; return new ResponseEntity<>(returnHTML, responseHeaders, HttpStatus.CREATED); //return returnHTML; }