List of usage examples for org.springframework.http HttpHeaders setAccept
public void setAccept(List<MediaType> acceptableMediaTypes)
From source file:org.cloudfoundry.identity.uaa.login.feature.ImplicitGrantIT.java
@Test public void testInvalidScopes() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>(); postBody.add("client_id", "cf"); postBody.add("redirect_uri", "https://uaa.cloudfoundry.com/redirect/cf"); postBody.add("response_type", "token"); postBody.add("source", "credentials"); postBody.add("username", testAccounts.getUserName()); postBody.add("password", testAccounts.getPassword()); postBody.add("scope", "read"); ResponseEntity<Void> responseEntity = restOperations.exchange(baseUrl + "/oauth/authorize", HttpMethod.POST, new HttpEntity<>(postBody, headers), Void.class); Assert.assertEquals(HttpStatus.FOUND, responseEntity.getStatusCode()); System.out.println(/*from ww w . ja va2s . c om*/ "responseEntity.getHeaders().getLocation() = " + responseEntity.getHeaders().getLocation()); UriComponents locationComponents = UriComponentsBuilder.fromUri(responseEntity.getHeaders().getLocation()) .build(); Assert.assertEquals("uaa.cloudfoundry.com", locationComponents.getHost()); Assert.assertEquals("/redirect/cf", locationComponents.getPath()); MultiValueMap<String, String> params = parseFragmentParams(locationComponents); Assert.assertThat(params.getFirst("error"), is("invalid_scope")); Assert.assertThat(params.getFirst("access_token"), isEmptyOrNullString()); Assert.assertThat(params.getFirst("credentials"), isEmptyOrNullString()); }
From source file:com.crazyacking.learn.spring.actuator.SampleActuatorApplicationTests.java
@Test public void testHtmlErrorPage() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<?> request = new HttpEntity<Void>(headers); ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/foo", HttpMethod.GET, request, String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); String body = entity.getBody(); assertThat(body).as("Body was null").isNotNull(); assertThat(body).contains("This application has no explicit mapping for /error"); }
From source file:com.cloudbees.jenkins.plugins.demo.actuator.SampleActuatorApplicationTests.java
@Test public void testHtmlErrorPage() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<?> request = new HttpEntity<Void>(headers); ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) .exchange("http://localhost:" + this.port + "/foo", HttpMethod.GET, request, String.class); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); String body = entity.getBody(); assertNotNull("Body was null", body); assertTrue("Wrong body: " + body, body.contains("This application has no explicit mapping for /error")); }
From source file:de.pentasys.playground.springbootexample.SampleActuatorApplicationTests.java
@Test public void testHtmlErrorPage() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); HttpEntity<?> request = new HttpEntity<Void>(headers); ResponseEntity<String> entity = new TestRestTemplate("admin", getPassword()) .exchange("http://localhost:" + this.port + "/foo", HttpMethod.GET, request, String.class); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); String body = entity.getBody(); assertNotNull("Body was null", body); assertTrue("Wrong body: " + body, body.contains("This application has no explicit mapping for /error")); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.TestCredentials.java
@Override protected UserInfo doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("tmp_username", null); String password = credentials.getString("tmp_password", null); String url = credentials.getString("tmp_url", null) + Values.SERVICE_USER + "login"; setState(RUNNING, R.string.working_ws_credentials); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try {/*from www.j av a2 s . com*/ // Make the network request Log.d(TAG, url); ResponseEntity<UserInfo> userInfo = restTemplate.exchange(url, HttpMethod.GET, entity, UserInfo.class); return (Values.user = userInfo.getBody()); } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); return null; } finally { setState(DONE); } }
From source file:com.salmon.security.xacml.demo.springmvc.rest.HTTPPopulatorsTest.java
private HttpHeaders getHeaders(String auth) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); byte[] encodedAuthorisation = Base64.encode(auth.getBytes()); headers.add("Authorization", "Basic " + new String(encodedAuthorisation)); return headers; }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateArtifact.java
/** * Method, where artifact information is pushed to server in order to create user. * All heavy lifting is made here./*from www.ja v a 2s. c o m*/ * * @param artifacts only one Artifact object is accepted * @return information about created artifact */ @Override protected Artifact doInBackground(Artifact... artifacts) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_ARTIFACTS; setState(RUNNING, R.string.working_ws_create_artifact); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); requestHeaders.setContentType(MediaType.APPLICATION_XML); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); Artifact artifact = artifacts[0]; try { Log.d(TAG, url); HttpEntity<Artifact> entity = new HttpEntity<Artifact>(artifact, requestHeaders); // Make the network request return restTemplate.postForObject(url, entity, Artifact.class); } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return null; }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateDigitization.java
/** * Method, where digitization information is pushed to server in order to create user. * All heavy lifting is made here.//w w w.j a v a 2 s . co m * * @param digitizations only one Digitization object is accepted * @return information about created digitization */ @Override protected Digitization doInBackground(Digitization... digitizations) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_DIGITIZATIONS; setState(RUNNING, R.string.working_ws_create_digitization); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); requestHeaders.setContentType(MediaType.APPLICATION_XML); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); Digitization digitization = digitizations[0]; try { Log.d(TAG, url); HttpEntity<Digitization> entity = new HttpEntity<Digitization>(digitization, requestHeaders); // Make the network request return restTemplate.postForObject(url, entity, Digitization.class); } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return null; }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateDisease.java
/** * Method, where Disease information is pushed to server in order to create user. * All heavy lifting is made here./*from ww w . ja v a 2 s . c om*/ * * @param diseases only one Disease object is accepted * @return information about created disease */ @Override protected Disease doInBackground(Disease... diseases) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_DISEASES; setState(RUNNING, R.string.working_ws_create_disease); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); requestHeaders.setContentType(MediaType.APPLICATION_XML); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); Disease disease = diseases[0]; try { Log.d(TAG, url); HttpEntity<Disease> entity = new HttpEntity<Disease>(disease, requestHeaders); // Make the network request return restTemplate.postForObject(url, entity, Disease.class); } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return null; }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateElectrodeFix.java
/** * Method, where electrode fix information is pushed to server in order to create user. * All heavy lifting is made here./*from w w w . j a va 2s. c om*/ * * @param electrodeFixes only one ElectrodeFix object is accepted * @return information about created electrode fix */ @Override protected ElectrodeFix doInBackground(ElectrodeFix... electrodeFixes) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_ELECTRODE_FIXLIST; setState(RUNNING, R.string.working_ws_create_electrode_fix); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); requestHeaders.setContentType(MediaType.APPLICATION_XML); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); ElectrodeFix fix = electrodeFixes[0]; try { Log.d(TAG, url); HttpEntity<ElectrodeFix> entity = new HttpEntity<ElectrodeFix>(fix, requestHeaders); // Make the network request return restTemplate.postForObject(url, entity, ElectrodeFix.class); } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return null; }