List of usage examples for org.springframework.http HttpHeaders setAccept
public void setAccept(List<MediaType> acceptableMediaTypes)
From source file:com.royclarkson.springagram.RestUtils.java
public static HttpEntity<Void> getRequestEntity() { if (requestEntity == null) { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAccept(Collections.singletonList(new MediaType("application", "hal+json"))); requestEntity = new HttpEntity<Void>(requestHeaders); }//from w w w. j a v a 2s .c om return requestEntity; }
From source file:edu.infsci2560.LoginHelper.java
public static ResponseEntity<String> login(TestRestTemplate template, String route, String userName, String password) {//from w w w . j a va2s .c o m HttpHeaders headers = getHeaders(template, route); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); form.set("username", userName); form.set("password", password); ResponseEntity<String> entity = template.exchange(route, HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class); return entity; }
From source file:com.hatta.consumer.App.java
private static HttpHeaders getHeaders() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); return headers; }
From source file:org.messic.android.util.RestJSONClient.java
/** * Rest GET petition to the server at the url param, sending all the post parameters defiend at formData. This post * return an object (json marshalling) of class defined at clazz parameter. You should register a * {@link RestListener} in order to obtain the returned object, this is because the petition is done in an async * process./*from www.j a v a2 s. c om*/ * * @param url {@link string} URL to attack * @param clazz Class<T/> class that you will marshall to a json object * @param rl {@link RestListener} listener to push the object returned */ public static <T> void get(final String url, final Class<T> clazz, final RestListener<T> rl) { final RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); // Populate the MultiValueMap being serialized and headers in an HttpEntity object to use for the request final HttpEntity<MultiValueMap<?, ?>> requestEntity = new HttpEntity<MultiValueMap<?, ?>>( new LinkedMultiValueMap<String, Object>(), requestHeaders); AsyncTask<Void, Void, Void> at = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, clazz); rl.response(response.getBody()); } catch (Exception e) { rl.fail(e); } return null; } }; at.execute(); }
From source file:org.messic.android.util.RestJSONClient.java
/** * Rest POST petition to the server at the url param, sending all the post parameters defiend at formData. This post * return an object (json marshalling) of class defined at clazz parameter. You should register a * {@link RestListener} in order to obtain the returned object, this is because the petition is done in an async * process./* w w w . j av a 2 s .co m*/ * * @param url {@link string} URL to attack * @param formData {@link MultiValueMap}<?,?/> map of parameters to send * @param clazz Class<T/> class that you will marshall to a json object * @param rl {@link RestListener} listener to push the object returned */ public static <T> void post(final String url, MultiValueMap<?, ?> formData, final Class<T> clazz, final RestListener<T> rl) { final RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); // Sending multipart/form-data requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); // Populate the MultiValueMap being serialized and headers in an HttpEntity object to use for the request final HttpEntity<MultiValueMap<?, ?>> requestEntity = new HttpEntity<MultiValueMap<?, ?>>(formData, requestHeaders); AsyncTask<Void, Void, Void> at = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, clazz); rl.response(response.getBody()); } catch (Exception e) { rl.fail(e); } return null; } }; at.execute(); }
From source file:de.codecentric.boot.admin.services.ApplicationRegistrator.java
private static HttpHeaders createHttpHeaders() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); return HttpHeaders.readOnlyHttpHeaders(headers); }
From source file:com.logaritex.hadoop.configuration.manager.SimpleHttpService.java
private static HttpHeaders createHttpHeaders(String username, String password) { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("Accept-Encoding", "gzip"); httpHeaders.set("Authorization", getBasicAuthHeaderValue(username, password)); httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); return httpHeaders; }
From source file:net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImpl.java
private static HttpHeaders buildHttpHeaders(final String confluenceAuthentication) { final HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", String.format("Basic %s", confluenceAuthentication)); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON_UTF8)); headers.setContentType(MediaType.APPLICATION_JSON_UTF8); return headers; }
From source file:com.opensearchserver.hadse.cluster.ClusterTest.java
@Test public void t01_get() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); RestTemplate template = new RestTemplate(); ResponseEntity<NodeItem[]> entity = template.exchange("http://localhost:8080/_cluster", HttpMethod.GET, null, NodeItem[].class); assertTrue(entity.getBody().length >= 1); assertEquals(HttpStatus.OK, entity.getStatusCode()); }
From source file:ai.emot.api.impl.EmotionTemplate.java
@Override public EmotionProfile getFaceImageEmotionProfile(BufferedImage image) { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.IMAGE_JPEG); HttpEntity<BufferedImage> entity = new HttpEntity<BufferedImage>(image, headers); ResponseEntity<EmotionProfile> response = restTemplate.exchange(apiBaseUrl + "/face/emotion", HttpMethod.POST, entity, EmotionProfile.class); return response.getBody(); }