List of usage examples for org.springframework.http HttpEntity HttpEntity
public HttpEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers)
From source file:org.cloudfoundry.identity.uaa.login.feature.AutologinIT.java
@Test public void testAutologinFlow() throws Exception { webDriver.get(baseUrl + "/logout.do"); HttpHeaders headers = getAppBasicAuthHttpHeaders(); Map<String, String> requestBody = new HashMap<>(); requestBody.put("username", testAccounts.getUserName()); requestBody.put("password", testAccounts.getPassword()); ResponseEntity<Map> autologinResponseEntity = restOperations.exchange(baseUrl + "/autologin", HttpMethod.POST, new HttpEntity<>(requestBody, headers), Map.class); String autologinCode = (String) autologinResponseEntity.getBody().get("code"); String authorizeUrl = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/oauth/authorize") .queryParam("redirect_uri", appUrl).queryParam("response_type", "code") .queryParam("scope", "openid").queryParam("client_id", "app").queryParam("code", autologinCode) .build().toUriString();/*from w w w . ja v a2 s . co m*/ webDriver.get(authorizeUrl); webDriver.get(baseUrl); assertEquals(testAccounts.getUserName(), webDriver.findElement(By.cssSelector(".header .nav")).getText()); }
From source file:org.trustedanalytics.metricsprovider.rest.MetricsDownloadTasks.java
private HttpEntity<String> setAuthToken(AuthTokenRetriever tokenRetriever) { SecurityContext context = SecurityContextHolder.getContext(); OAuth2Authentication auth = (OAuth2Authentication) context.getAuthentication(); String token = tokenRetriever.getAuthToken(auth); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "bearer " + token); return new HttpEntity<>("params", headers); }
From source file:com.ge.predix.test.utils.PrivilegeHelper.java
public BaseSubject putSubject(final OAuth2RestTemplate acsTemplate, final BaseSubject subject, final String endpoint, final HttpHeaders headers, final Attribute... attributes) throws UnsupportedEncodingException { subject.setAttributes(new HashSet<>(Arrays.asList(attributes))); URI subjectUri = URI.create( endpoint + ACS_SUBJECT_API_PATH + URLEncoder.encode(subject.getSubjectIdentifier(), "UTF-8")); acsTemplate.put(subjectUri, new HttpEntity<>(subject, headers)); return subject; }
From source file:com.logaritex.hadoop.configuration.manager.http.AndroidHttpService.java
public <R> R delete(String url, Object request, Class<R> responseType, Object... uriVariables) { R response = restTemplate.exchange(baseUrl + url, HttpMethod.DELETE, new HttpEntity<Object>(request, httpHeaders), responseType, uriVariables).getBody(); return response; }
From source file:com.allogy.amazonaws.elasticbeanstalk.worker.simulator.application.WorkerApplication.java
private HttpEntity<String> createHttpEntity(MessageWrapper messageWrapper, Message message) { String messageId = message.getMessageId(); HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", "aws-sqsd/1.1 (simulated bridge)"); headers.set("X-Aws-Sqsd-Msgid", messageId); headers.set("X-Aws-Sqsd-Queue", messageWrapper.getQueueName()); headers.set("X-Aws-Sqsd-Receive-Count", Integer.toString(messageWrapper.getMessageCount())); headers.setContentType(MediaType.APPLICATION_JSON); return new HttpEntity<>(message.getBody(), headers); }
From source file:org.craftercms.commerce.client.AbstractRestCRUDService.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public ServiceResponse<T> save(T entity) throws CrafterCommerceException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("About to save entity: " + entity.toString()); }/*from w w w . j av a2 s . c o m*/ try { String restUrl = crafterCommerceServerUrl + TypeToPathMapper.path(getTypeArgument()) + CrafterCommerceConstants.SAVE_ACTION_REST_MAPPING + CrafterCommerceConstants.JSON_EXTENSION; HttpEntity<T> httpEntity = new HttpEntity<T>(entity, httpHeaders); ResponseEntity<? extends ServiceResponse> responseEntity = restTemplate.postForEntity(restUrl, httpEntity, new ServiceResponse<T>().getClass()); ServiceResponse<T> response = responseEntity.getBody(); if (response.isSuccess() == false) { throw new CrafterCommerceException(response.getMessage()); } return response; } catch (Exception e) { throw new CrafterCommerceException(e); } }
From source file:net.paslavsky.springrest.SpringRestClientMethodInterceptor.java
@Override public Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); RestMethodMetadata metadata = annotationPreprocessor.parse(method.getDeclaringClass(), method); Object[] arguments = invocation.getArguments(); URI uri = new UriBuilder(baseUrl, arguments).build(metadata); Object body = getRequestBody(metadata, arguments); HttpHeaders headers = helper.getHttpHeaders(metadata.getRequestHeaderParameters(), arguments); if (authenticationManager != null) { headers.putAll(authenticationManager.getAuthenticationHeaders()); }/*from w w w.java 2 s .c o m*/ HttpEntity<?> httpEntity = new HttpEntity<Object>(body, headers); ResponseEntity<?> responseEntity = restTemplate.exchange(uri, metadata.getHttpMethod(), httpEntity, metadata.getResponseClass()); if (metadata.getMethodReturnType() == ResponseEntity.class) { return responseEntity; } else { return responseEntity.getBody(); } }
From source file:org.avidj.zuul.client.ZuulRestClient.java
@Override public boolean lock(String sessionId, List<String> path, LockType type, LockScope scope) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); HttpEntity<String> entity = new HttpEntity<String>("parameters", headers); Map<String, String> parameters = new HashMap<>(); parameters.put("id", sessionId); // set the session id UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(serviceUrl + lockPath(path)) .queryParam("t", type(type)).queryParam("s", scope(scope)); ResponseEntity<String> result = restTemplate.exchange(uriBuilder.build().encode().toUri(), HttpMethod.PUT, entity, String.class); LOG.info(result.toString());// w ww .j a va 2 s . c om HttpStatus code = result.getStatusCode(); return code.equals(HttpStatus.CREATED); }
From source file:com.tce.oauth2.spring.client.services.TodoService.java
public Todo add(String accessToken, Todo todo) { // Set the headers HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + accessToken); headers.add("Content-Type", "application/json"); // Post request HttpEntity<Todo> request = new HttpEntity<Todo>(todo, headers); Todo todoAdded = restTemplate.postForObject(OAUTH_RESOURCE_SERVER_URL + "/rest/todos/add", request, Todo.class); return todoAdded; }