List of usage examples for org.springframework.http HttpHeaders setAccept
public void setAccept(List<MediaType> acceptableMediaTypes)
From source file:org.apigw.authserver.AuthorizationCodeProviderIntegrationtest.java
@Test public void testUserDeniesConfirmation() throws Exception { log.debug("testUserDeniesConfirmation"); String cookie = helper.loginAndGetConfirmationPage(CLIENT_ID, REDIRECT_URL, SCOPE); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); headers.set("Cookie", cookie); MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("user_oauth_approval", "false"); ResponseEntity<Void> result = serverRunning.postForStatus("/apigw-auth-server-web/oauth/authorize", headers, formData);/*from w ww.j a v a2 s. c om*/ assertEquals(HttpStatus.FOUND, result.getStatusCode()); String location = result.getHeaders().getFirst("Location"); assertTrue(location.startsWith(REDIRECT_URL)); assertTrue(location.substring(location.indexOf('?')).contains("error=access_denied")); assertTrue(location.contains("state=gzzFqB!!!")); }
From source file:org.cloudfoundry.identity.uaa.integration.ClientAdminEndpointsIntegrationTests.java
private OAuth2AccessToken getClientCredentialsAccessToken(String scope) throws Exception { String clientId = testAccounts.getAdminClientId(); String clientSecret = testAccounts.getAdminClientSecret(); MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("grant_type", "client_credentials"); formData.add("client_id", clientId); formData.add("scope", scope); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.set("Authorization", "Basic " + new String(Base64.encode(String.format("%s:%s", clientId, clientSecret).getBytes()))); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap("/oauth/token", formData, headers); assertEquals(HttpStatus.OK, response.getStatusCode()); @SuppressWarnings("unchecked") OAuth2AccessToken accessToken = DefaultOAuth2AccessToken.valueOf(response.getBody()); return accessToken; }
From source file:org.apigw.authserver.AuthorizationCodeProviderIntegrationtest.java
@Test public void testAuthorizationRequestRedirectsToLogin() throws Exception { log.debug("testAuthorizationRequestRedirectsToLogin"); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); String location = helper.getAuthorizeUrl(CLIENT_ID, REDIRECT_URL, SCOPE); ResponseEntity<Void> result = serverRunning.getForResponse(location, headers); assertEquals(HttpStatus.FOUND, result.getStatusCode()); location = result.getHeaders().getLocation().toString(); if (result.getHeaders().containsKey("Set-Cookie")) { String cookie = result.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); }/*from w w w .j a v a2s . c om*/ ResponseEntity<String> response = serverRunning.getForString(location, headers); // should be directed to the login screen... assertTrue(response.getBody().contains("/login.do")); assertTrue(response.getBody().contains("j_username")); assertTrue(response.getBody().contains("j_password")); }
From source file:cz.muni.fi.mushroomhunter.restclient.MushroomCreateSwingWorker.java
@Override protected Void doInBackground() throws Exception { MushroomDto mushroomDto = new MushroomDto(); mushroomDto.setName(restClient.getTfMushroomName().getText()); mushroomDto.setType(cz.fi.muni.pa165.mushroomhunter.api.Type .valueOf(restClient.getComboBoxMushroomType().getSelectedItem().toString())); //to create date object only month is used, day and year are fixed values String dateInString = restClient.getComboBoxMushroomStartOfOccurence().getSelectedItem().toString() + " 1, 2000"; SimpleDateFormat formatter = new SimpleDateFormat("MMMM d, yyyy", new Locale("en_US")); mushroomDto.setStartOfOccurence(formatter.parse(dateInString)); //to create date object only month is used, day and year are fixed values dateInString = restClient.getComboBoxMushroomEndOfOccurence().getSelectedItem().toString() + " 1, 2000"; mushroomDto.setEndOfOccurence(formatter.parse(dateInString)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); List<MediaType> mediaTypeList = new ArrayList<>(); mediaTypeList.add(MediaType.ALL);// w w w. java 2 s.co m headers.setAccept(mediaTypeList); ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(mushroomDto); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); headers.add("Authorization", "Basic " + base64Creds); HttpEntity request = new HttpEntity(json, headers); RestTemplate restTemplate = new RestTemplate(); Long[] result = restTemplate.postForObject(RestClient.SERVER_URL + "pa165/rest/mushroom", request, Long[].class); System.out.println("Id of the created mushroom: " + result[0]); RestClient.getMushroomIDs().add(result[0]); return null; }
From source file:khs.trouble.service.impl.TroubleService.java
public String exception(String serviceName, String instanceId, String ltoken) { if (token != ltoken) { throw new RuntimeException("Invalid Access Token"); }//from w w w.ja va 2 s .co m String url = FormatUrl.url(serviceInstanceURL(serviceName, instanceId) + "/trouble/exception", ssl); // invoke kill api... RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_PLAIN)); headers.add("token", token); HttpEntity<String> entity = new HttpEntity<String>("parameters", headers); try { restTemplate.exchange(url, HttpMethod.GET, entity, String.class); eventService.exception(serviceName, url); } catch (Exception e) { eventService.attempted("Attempted to throw exception at service " + serviceName + " at " + url + " Failed due to exception " + e.getMessage()); } return serviceName; }
From source file:com.orange.ngsi.client.NgsiClient.java
/** * The default HTTP request headers used for the requests. * @return the HTTP request headers. */// w w w. j av a 2 s . c o m public HttpHeaders getRequestHeaders() { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(MediaType.APPLICATION_XML); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); return requestHeaders; }
From source file:khs.trouble.service.impl.TroubleService.java
public String memory(String serviceName, String instanceId, String ltoken) { if (token != ltoken) { throw new RuntimeException("Invalid Access Token"); }/*from w ww . j av a2 s . c o m*/ String url = FormatUrl.url(serviceInstanceURL(serviceName, instanceId) + "/trouble/memory", ssl); // invoke memory api... RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_PLAIN)); headers.add("token", token); headers.add("timeout", "" + timeout); HttpEntity<String> entity = new HttpEntity<String>("parameters", headers); try { restTemplate.exchange(url, HttpMethod.GET, entity, String.class); eventService.memory(serviceName, url); } catch (Exception e) { eventService.attempted("Attempted to consume memory at service " + serviceName + " at " + url + " Failed due to exception " + e.getMessage()); } return serviceName; }
From source file:khs.trouble.service.impl.TroubleService.java
public String kill(String serviceName, String instanceId, String ltoken) { if (token != ltoken) { throw new RuntimeException("Invalid Access Token"); }//from w w w. j a va 2s . c o m String url = FormatUrl.url(serviceInstanceURL(serviceName, instanceId) + "trouble/kill", ssl); // invoke kill api... RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_PLAIN)); headers.add("token", token); HttpEntity<String> entity = new HttpEntity<String>("parameters", headers); try { // int instanceCount = registry.instanceCount(serviceName); ResponseEntity<String> result = restTemplate.exchange(url, HttpMethod.GET, entity, String.class); if (result.getStatusCode() == HttpStatus.OK) { eventService.killed(serviceName, url); // monitorServiceRecovery(serviceName, instanceCount); } } catch (Exception e) { eventService.attempted("Attempted to Kill service " + serviceName + " at " + url + " Failed due to exception " + e.getMessage()); } return serviceName; }
From source file:com.hpe.elderberry.Taxii10Template.java
private <T> HttpEntity<T> wrapRequest(T body) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(APPLICATION_XML); headers.setAccept(singletonList(APPLICATION_XML)); headers.add("X-TAXII-Services", VID_TAXII_SERVICES_10); headers.add("X-TAXII-Content-Type", VID_TAXII_XML_10); String binding = conn.getDiscoveryUrl().getScheme().endsWith("s") ? VID_TAXII_HTTPS_10 : VID_TAXII_HTTP_10; headers.add("X-TAXII-Protocol", binding); return new HttpEntity<>(body, headers); }
From source file:org.cloudfoundry.identity.uaa.integration.ClientInfoEndpointIntegrationTests.java
@Test public void testUnauthenticated() throws Exception { HttpHeaders headers = new HttpHeaders(); ResourceOwnerPasswordResourceDetails app = testAccounts.getDefaultResourceOwnerPasswordResource(); headers.set("Authorization", testAccounts.getAuthorizationHeader(app.getClientId(), "bogus")); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.getForObject("/clientinfo", Map.class, headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); assertEquals("unauthorized", response.getBody().get("error")); }