List of usage examples for org.springframework.http HttpHeaders set
@Override public void set(String headerName, @Nullable String headerValue)
From source file:edu.mayo.cts2.framework.plugin.service.bprdf.dao.rest.BioportalRestClient.java
protected String doCallBioportal(String url) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", "application/xml"); if (log.isDebugEnabled()) { log.debug(url);/*from w ww. j a v a 2 s .c o m*/ } ResponseEntity<String> response = this.restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<Void>(headers), String.class); return response.getBody(); }
From source file:org.client.one.service.OAuthAuthenticationService.java
public String getAuthorizationCode(String accessTokenA, String redirectUri, String appTokenClientTwo) { RestOperations rest = new RestTemplate(); HttpHeaders headersA = new HttpHeaders(); headersA.set("Authorization", "Bearer " + accessTokenA); ResponseEntity<String> resAuth2 = rest .exchange(//from w w w . jav a2s.com MessageFormat.format( "{0}/oauth/authorize?" + "client_id={1}&response_type=code&scope=WRITE&redirect_uri={2}", oauthServerBaseURL, appTokenClientTwo, redirectUri), HttpMethod.POST, new HttpEntity<String>(headersA), String.class); String sessionId = resAuth2.getHeaders().get("Set-Cookie").get(0); int p1 = sessionId.indexOf("=") + 1; int p2 = sessionId.indexOf(";"); sessionId = sessionId.substring(p1, p2); headersA.add("Cookie", "JSESSIONID=" + sessionId); resAuth2 = rest.exchange( MessageFormat.format("{0}/oauth/authorize?" + "user_oauth_approval=true&authorize=Authorize", oauthServerBaseURL), HttpMethod.POST, new HttpEntity<String>(headersA), String.class); String code = resAuth2.getHeaders().get("location").get(0); p1 = code.lastIndexOf("=") + 1; code = code.substring(p1); return code; }
From source file:fr.treeptik.cloudunit.cli.rest.RestUtils.java
/** * sendPostCommand/*from www .jav a 2s . c o m*/ * * @param url * @param parameters * @return * @throws ClientProtocolException */ public Map<String, Object> sendPostForUpload(String url, Map<String, Object> parameters) { RestTemplate restTemplate = new RestTemplate(); List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters(); mc.add(new MappingJacksonHttpMessageConverter()); restTemplate.setMessageConverters(mc); MultiValueMap<String, Object> postParams = new LinkedMultiValueMap<String, Object>(); postParams.setAll(parameters); Map<String, Object> response = new HashMap<String, Object>(); HttpHeaders headers = new HttpHeaders(); headers.set("Content-Type", "multipart/form-data"); headers.set("Accept", "application/json"); headers.add("Cookie", "JSESSIONID=" + localContext.getCookieStore().getCookies().get(0).getValue()); org.springframework.http.HttpEntity<Object> request = new org.springframework.http.HttpEntity<Object>( postParams, headers); ResponseEntity<?> result = restTemplate.exchange(url, HttpMethod.POST, request, String.class); String body = result.getBody().toString(); MediaType contentType = result.getHeaders().getContentType(); HttpStatus statusCode = result.getStatusCode(); response.put("content-type", contentType); response.put("statusCode", statusCode); response.put("body", body); return response; }
From source file:com.bailen.radioOnline.recursos.REJA.java
public Cancion[] favourites(String apiKey) throws IOException { HttpHeaders header = new HttpHeaders(); header.set("Authorization", apiKey); HttpEntity entity = new HttpEntity(header); String lista = new String(); HttpEntity<String> response; response = new RestTemplate().exchange("http://ceatic.ujaen.es:8075/radioapi/v2/favourites", HttpMethod.GET, entity, String.class, lista); String canc = response.getBody(); StringTokenizer st = new StringTokenizer(canc, "[", true); st.nextToken();/*w w w .ja v a 2 s . co m*/ st.nextToken(); canc = "[" + st.nextToken(); try { ObjectMapper a = new ObjectMapper(); Item[] listilla = a.readValue(canc, Item[].class); Vector<Integer> ids = new Vector<>(); for (int i = 0; i < listilla.length; ++i) { ids.add(listilla[i].getId()); } return jamendo.canciones(ids); } catch (Exception e) { throw new IOException("no se han recibido canciones"); } }
From source file:com.bailen.radioOnline.recursos.REJA.java
public Cancion[] recommendations(String apiKey) throws IOException { HttpHeaders header = new HttpHeaders(); header.set("Authorization", apiKey); HttpEntity entity = new HttpEntity(header); String lista = new String(); HttpEntity<String> response; response = new RestTemplate().exchange("http://ceatic.ujaen.es:8075/radioapi/v2/recommendations", HttpMethod.GET, entity, String.class, lista); String canc = response.getBody(); StringTokenizer st = new StringTokenizer(canc, "[", true); st.nextToken();/*from w w w.jav a2 s .c o m*/ st.nextToken(); canc = "[" + st.nextToken(); try { ObjectMapper a = new ObjectMapper(); itemRadios[] listilla = a.readValue(canc, itemRadios[].class); Vector<Integer> ids = new Vector<>(); for (int i = 0; i < listilla.length; ++i) { ids.add(listilla[i].getIdItem()); } return jamendo.canciones(ids); } catch (Exception e) { throw new IOException("no se han recibido canciones"); } }
From source file:com.bailen.radioOnline.recursos.REJA.java
public Cancion[] artistFav(String apiKey) throws IOException { HttpHeaders header = new HttpHeaders(); header.set("Authorization", apiKey); HttpEntity entity = new HttpEntity(header); String lista = new String(); HttpEntity<String> response; response = new RestTemplate().exchange("http://ceatic.ujaen.es:8075/radioapi/v2/favouriteArtists", HttpMethod.GET, entity, String.class, lista); String canc = response.getBody(); StringTokenizer st = new StringTokenizer(canc, "[", true); st.nextToken();//from w w w . j ava 2 s. c o m st.nextToken(); canc = "[" + st.nextToken(); try { ObjectMapper a = new ObjectMapper(); Item[] listilla = a.readValue(canc, Item[].class); Vector<Integer> ids = new Vector<>(); for (int i = 0; i < listilla.length; ++i) { ids.add(listilla[i].getId()); } return jamendo.canciones(ids); } catch (Exception e) { throw new IOException("no se han recibido canciones"); } }
From source file:com.mobileman.projecth.web.controller.ExportController.java
private ResponseEntity<String> generateCsv(String data) { HttpHeaders responseHeaders = new HttpHeaders(); responseHeaders.set("Content-Type", "application/octet-stream"); responseHeaders.set("Content-disposition", "attachment; filename=export.csv"); return new ResponseEntity<String>(data, responseHeaders, HttpStatus.OK); }
From source file:com.bailen.radioOnline.recursos.REJA.java
public Cancion[] random(String apiKey) throws IOException { HttpHeaders header = new HttpHeaders(); header.set("Authorization", apiKey); HttpEntity entity = new HttpEntity(header); String lista = new String(); HttpEntity<String> response; response = new RestTemplate().exchange("http://ceatic.ujaen.es:8075/radioapi/v2/random", HttpMethod.GET, entity, String.class, lista); String canc = response.getBody(); StringTokenizer st = new StringTokenizer(canc, "[", true); st.nextToken();//from w ww . j ava 2s . co m st.nextToken(); canc = "[" + st.nextToken(); try { ObjectMapper a = new ObjectMapper(); Item[] listilla = a.readValue(canc, Item[].class); Vector<Integer> ids = new Vector<>(); for (int i = 0; i < listilla.length; ++i) { ids.add(listilla[i].getId()); } return jamendo.canciones(ids); } catch (Exception e) { //return null; throw new IOException("no se han recibido canciones"); } }
From source file:org.appverse.web.framework.backend.test.util.frontfacade.mvc.tests.predefined.BasicAuthEndPointsServiceEnabledPredefinedTests.java
@Test public void basicAuthenticationServiceTestInvalidCredentials() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic " + new String(Base64.encode("user:badpassword".getBytes("UTF-8")))); HttpEntity<String> entity = new HttpEntity<String>("headers", headers); ResponseEntity<AuthorizationData> responseEntity = restTemplate.exchange( "http://localhost:" + port + baseApiPath + basicAuthenticationEndpointPath, HttpMethod.POST, entity, AuthorizationData.class); assertEquals(HttpStatus.UNAUTHORIZED, responseEntity.getStatusCode()); }