List of usage examples for org.springframework.http HttpMethod POST
HttpMethod POST
To view the source code for org.springframework.http HttpMethod POST.
Click Source Link
From source file:org.client.two.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(// w ww.j a v a 2s . c o m MessageFormat.format( "{0}/oauth/authorize?" + "client_id={1}&response_type=code&redirect_uri={2}&scope=WRITE", 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:org.appverse.web.framework.backend.test.util.frontfacade.mvc.tests.predefined.BasicAuthEndPointsServiceEnabledPredefinedTests.java
@Test public void basicAuthenticationRemoteLogServiceEnabledWithoutCsrfTokenTest() throws Exception { RemoteLogRequestVO logRequestVO = new RemoteLogRequestVO(); logRequestVO.setMessage("Test mesage!"); logRequestVO.setLogLevel("DEBUG"); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic " + new String(Base64.encode((getUsername() + ":" + getPassword()).getBytes("UTF-8")))); HttpEntity<RemoteLogRequestVO> entity = new HttpEntity<RemoteLogRequestVO>(logRequestVO, headers); UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl("http://localhost:" + port + baseApiPath + remoteLogEndpointPath); ResponseEntity<String> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, entity, String.class); assertEquals(HttpStatus.FORBIDDEN, responseEntity.getStatusCode()); }
From source file:com.orange.ngsi.client.NotifyContextRequestTest.java
@Test public void notifyContextRequestOK_XML() throws Exception { ngsiClient.protocolRegistry.registerHost(baseUrl); String responseBody = xml(xmlConverter, createNotifyContextResponseTempSensor()); this.mockServer.expect(requestTo(baseUrl + "/ngsi10/notifyContext")).andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", MediaType.APPLICATION_XML_VALUE)) .andExpect(header("Accept", MediaType.APPLICATION_XML_VALUE)) .andExpect(xpath("notifyContextRequest/subscriptionId").string("1")) .andExpect(xpath("notifyContextRequest/originator").string("http://iotAgent")) .andExpect(xpath("notifyContextRequest/contextResponseList/contextElementResponse[*]").nodeCount(1)) .andExpect(xpath(/*from ww w . j av a 2 s.c o m*/ "notifyContextRequest/contextResponseList/contextElementResponse/contextElement/entityId/id") .string("S1")) .andExpect(xpath( "notifyContextRequest/contextResponseList/contextElementResponse/contextElement/entityId/@type") .string("TempSensor")) .andExpect(xpath( "notifyContextRequest/contextResponseList/contextElementResponse/contextElement/entityId/@isPattern") .string("false")) .andExpect(xpath( "notifyContextRequest/contextResponseList/contextElementResponse/contextElement/contextAttributeList/contextAttribute[*]") .nodeCount(1)) .andExpect(xpath( "notifyContextRequest/contextResponseList/contextElementResponse/contextElement/contextAttributeList/contextAttribute/name") .string("temp")) .andExpect(xpath( "notifyContextRequest/contextResponseList/contextElementResponse/contextElement/contextAttributeList/contextAttribute/type") .string("float")) .andExpect(xpath( "notifyContextRequest/contextResponseList/contextElementResponse/contextElement/contextAttributeList/contextAttribute/contextValue") .string("15.5")) .andRespond(withSuccess(responseBody, MediaType.APPLICATION_XML)); NotifyContextResponse response = ngsiClient.notifyContext(baseUrl, null, createNotifyContextTempSensor(0)) .get(); this.mockServer.verify(); Assert.assertEquals(CodeEnum.CODE_200.getLabel(), response.getResponseCode().getCode()); }
From source file:com.golonzovsky.oauth2.google.security.GoogleTokenServices.java
private Map<String, Object> postForMap(String path, MultiValueMap<String, String> formData, HttpHeaders headers) {//from w w w .java 2 s.co m if (headers.getContentType() == null) { headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); } ParameterizedTypeReference<Map<String, Object>> map = new ParameterizedTypeReference<Map<String, Object>>() { }; return restTemplate.exchange(path, HttpMethod.POST, new HttpEntity<>(formData, headers), map).getBody(); }
From source file:fragment.web.AccessDecisionTest.java
@Test public void testOwnerUrls() { Object[][] valid = { { HttpMethod.GET, "/portal/portal/" }, { HttpMethod.GET, "/portal/portal/home" }, { HttpMethod.GET, "/portal/portal/profile" }, { HttpMethod.GET, "/portal/portal/profile/edit" }, { HttpMethod.POST, "/portal/portal/profile" }, { HttpMethod.POST, "/portal/portal/acceptCookies" }, { HttpMethod.GET, "/portal/portal/users" }, { HttpMethod.GET, "/portal/portal/users/new" }, { HttpMethod.POST, "/portal/portal/users" }, { HttpMethod.GET, "/portal/portal/users/1/myprofile" }, { HttpMethod.GET, "/portal/portal/tenants/1/edit" }, { HttpMethod.GET, "/portal/portal/tasks/" }, { HttpMethod.GET, "/portal/portal/tasks/1/" }, { HttpMethod.GET, "/portal/portal/tasks/approval-task/1" }, { HttpMethod.POST, "/portal/portal/tasks/approval-task" } }; Object[][] invalid = { { HttpMethod.GET, "/portal/portal/tenants" }, { HttpMethod.POST, "/portal/portal/tenants" }, { HttpMethod.GET, "/portal/portal/tenants/new" }, }; User user = getDefaultTenant().getOwner(); Authentication auth = createAuthenticationToken(user); verify(auth, valid, invalid);/* ww w .j a v a 2 s . co m*/ }
From source file:com.orange.ngsi.client.UpdateContextSubscriptionTest.java
@Test public void updateContextSubscriptionRequestOK_XML() throws Exception { ngsiClient.protocolRegistry.registerHost(baseUrl); String responseBody = xml(xmlConverter, createUpdateContextSubscriptionResponseTemperature()); this.mockServer.expect(requestTo(baseUrl + "/ngsi10/updateContextSubscription")) .andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", MediaType.APPLICATION_XML_VALUE)) .andExpect(header("Accept", MediaType.APPLICATION_XML_VALUE)) .andExpect(xpath("updateContextSubscriptionRequest/subscriptionId").string("12345678")) .andExpect(xpath("updateContextSubscriptionRequest/duration").string("P1M")) .andExpect(xpath("updateContextSubscriptionRequest/throttling").string("PT1S")) .andExpect(xpath("updateContextSubscriptionRequest/restriction/attributeExpression") .string("xpath/expression")) .andExpect(xpath("updateContextSubscriptionRequest/restriction/scope/operationScope/scopeType") .string("type")) .andExpect(xpath("updateContextSubscriptionRequest/restriction/scope/operationScope/scopeValue") .string("value")) .andRespond(withSuccess(responseBody, MediaType.APPLICATION_XML)); UpdateContextSubscriptionResponse response = ngsiClient .updateContextSubscription(baseUrl, null, createUpdateContextSubscriptionTemperature()).get(); this.mockServer.verify(); Assert.assertNull(response.getSubscribeError()); Assert.assertEquals("12345678", response.getSubscribeResponse().getSubscriptionId()); Assert.assertEquals("P1M", response.getSubscribeResponse().getDuration()); }
From source file:de.zib.gndms.gndmc.AbstractClient.java
/** * Executes a POST on a url.// w w w . j ava2 s. c o m * * The request header contains a given user name and workflow id, the body of the request contains * a given object of type P. * * @param <T> The body type of the response. * @param <P> The body type of the request. * @param clazz The type of the return value. * @param parm The body of the request. * @param url The url of the request. * @param dn The user name. * @param wid The workflow id. * @return The response as entity. */ protected final <T, P> ResponseEntity<T> unifiedPost(final Class<T> clazz, final P parm, final String url, final String dn, final String wid) { return unifiedX(HttpMethod.POST, clazz, parm, url, dn, wid); }
From source file:com.brightcove.zencoder.client.ZencoderClient.java
/** * Creates a VOD transcode job.// w w w. jav a 2 s . c om * * @see https://app.zencoder.com/docs/api/jobs/create * @param job * @return ZencoderJobResponse * @throws ZencoderClientException */ public ZencoderCreateJobResponse createZencoderJob(ZencoderCreateJobRequest job) throws ZencoderClientException { String url = api_url + "/jobs"; String body = null; try { body = mapper.writeValueAsString(job); } catch (Exception e) { throw new ZencoderClientException("Unable to serialize ZencoderCreateJobRequest as JSON", e); } HttpHeaders headers = getHeaders(); @SuppressWarnings("rawtypes") HttpEntity entity = new HttpEntity<String>(body, headers); ResponseEntity<String> response = null; try { response = rt.exchange(url, HttpMethod.POST, entity, String.class, new HashMap<String, Object>()); } catch (HttpClientErrorException hcee) { throw new ZencoderClientException(hcee.getResponseBodyAsString(), hcee); } ZencoderCreateJobResponse zencoderJobResponse = null; try { zencoderJobResponse = mapper.readValue(response.getBody(), ZencoderCreateJobResponse.class); } catch (Exception e) { throw new ZencoderClientException("Unable to deserialize ZencoderCreateJobResponse as JSON", e); } return zencoderJobResponse; }
From source file:com.ggk.hrms.authentication.CustomTokenServices.java
private Map<String, Object> postForMap(String path, MultiValueMap<String, String> formData, HttpHeaders headers) {/*from ww w . j a v a 2 s . co m*/ if (headers.getContentType() == null) { headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); } ParameterizedTypeReference<Map<String, Object>> map = new ParameterizedTypeReference<Map<String, Object>>() { }; return restTemplate.exchange(path, HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(formData, headers), map).getBody(); }
From source file:org.cloudfoundry.identity.uaa.login.SamlRemoteUaaController.java
@RequestMapping(value = "/oauth/token", method = RequestMethod.POST, params = "grant_type=password") @ResponseBody// w ww. ja va 2s . co m public ResponseEntity<byte[]> tokenEndpoint(HttpServletRequest request, HttpEntity<byte[]> entity, @RequestParam Map<String, String> parameters, Map<String, Object> model, Principal principal) throws Exception { // Request has a password. Owner password grant with a UAA password if (null != request.getParameter("password")) { return passthru(request, entity, model); } else { // MultiValueMap<String, String> requestHeadersForClientInfo = new LinkedMultiValueMap<String, String>(); requestHeadersForClientInfo.add(AUTHORIZATION, request.getHeader(AUTHORIZATION)); ResponseEntity<byte[]> clientInfoResponse = getDefaultTemplate().exchange( getUaaBaseUrl() + "/clientinfo", HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(null, requestHeadersForClientInfo), byte[].class); if (clientInfoResponse.getStatusCode() == HttpStatus.OK) { String path = extractPath(request); MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.setAll(parameters); if (principal != null) { map.set("source", "login"); map.set("client_id", getClientId(clientInfoResponse.getBody())); map.setAll(getLoginCredentials(principal)); map.remove("credentials"); // legacy vmc might break otherwise } else { throw new BadCredentialsException("No principal found in authorize endpoint"); } HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.putAll(getRequestHeaders(requestHeaders)); requestHeaders.remove(AUTHORIZATION.toLowerCase()); requestHeaders.remove(ACCEPT.toLowerCase()); requestHeaders.remove(CONTENT_TYPE.toLowerCase()); requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); requestHeaders.remove(COOKIE); requestHeaders.remove(COOKIE.toLowerCase()); ResponseEntity<byte[]> response = getAuthorizationTemplate().exchange(getUaaBaseUrl() + "/" + path, HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(map, requestHeaders), byte[].class); saveCookie(response.getHeaders(), model); byte[] body = response.getBody(); if (body != null) { HttpHeaders outgoingHeaders = getResponseHeaders(response.getHeaders()); return new ResponseEntity<byte[]>(response.getBody(), outgoingHeaders, response.getStatusCode()); } throw new IllegalStateException("Neither a redirect nor a user approval"); } else { throw new BadCredentialsException(new String(clientInfoResponse.getBody())); } } }