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.cloudfoundry.identity.statsd.integration.UaaMetricsEmitterIT.java
@Test public void testStatsDClientEmitsMetricsCollectedFromUAA() throws InterruptedException, IOException { RestTemplate template = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set(headers.ACCEPT, MediaType.TEXT_HTML_VALUE); ResponseEntity<String> loginResponse = template.exchange(UAA_BASE_URL + "/login", HttpMethod.GET, new HttpEntity<>(null, headers), String.class); if (loginResponse.getHeaders().containsKey("Set-Cookie")) { for (String cookie : loginResponse.getHeaders().get("Set-Cookie")) { headers.add("Cookie", cookie); }/*from w ww . j av a 2 s . c om*/ } String csrf = IntegrationTestUtils.extractCookieCsrf(loginResponse.getBody()); LinkedMultiValueMap<String, String> body = new LinkedMultiValueMap<>(); body.add("username", TEST_USERNAME); body.add("password", TEST_PASSWORD); body.add(CookieBasedCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME, csrf); loginResponse = template.exchange(UAA_BASE_URL + "/login.do", HttpMethod.POST, new HttpEntity<>(body, headers), String.class); assertEquals(HttpStatus.FOUND, loginResponse.getStatusCode()); assertNotNull(getMessage("uaa.audit_service.user_authentication_count:1", 5000)); }
From source file:cec.easyshop.storefront.filters.StorefrontFilterTest.java
@Test public void shouldNotStoreOriginalRefererOnPOST() throws IOException, ServletException { Mockito.when(request.getMethod()).thenReturn(HttpMethod.POST.toString()); filter.doFilterInternal(request, response, filterChain); Mockito.verify(session, Mockito.never()).setAttribute(StorefrontFilter.ORIGINAL_REFERER, REQUESTEDURL); }
From source file:org.zalando.github.spring.StatusesTemplateTest.java
@Test public void createStatuses() throws Exception { mockServer.expect(requestTo("https://api.github.com/repos/zalando-stups/blub/statuses/abcdefgh1234567")) .andExpect(method(HttpMethod.POST)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(withSuccess(jsonResource("status"), APPLICATION_JSON)); StatusRequest request = StatusRequest.pendingStatusRequest(); request.setTargetUrl("https://ci.example.com/1000/output"); request.setDescription("Build started"); request.setContext("continuous-integration/whatever"); Status status = statusesTemplate.createStatus("zalando-stups", "blub", "abcdefgh1234567", request); Assertions.assertThat(status).isNotNull(); Assertions.assertThat(status.getId()).isEqualTo(1); Assertions.assertThat(status.getUrl()) .isEqualTo("https://api.github.com/repos/octocat/Hello-World/statuses/1"); }
From source file:com.tce.oauth2.spring.client.controller.OAuthController.java
@RequestMapping("/oauth2callback") public String callback(@RequestParam("code") String authorizationCode, HttpServletRequest request) { // call OAuth Server with response code to get the access token UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(OAUTH_URL + "/oauth/token") .queryParam("grant_type", "authorization_code").queryParam("code", authorizationCode) .queryParam("redirect_uri", OAUTH_REDIRECT_URI); ResponseEntity<OAuthToken> response = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, new HttpEntity<>(createHeaders(OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET)), OAuthToken.class); if (response.getStatusCode().is4xxClientError()) { return "redirect:/login"; }//from w w w . j a v a 2s. c o m // get the access token OAuthToken oauthToken = response.getBody(); // set access token to the session request.getSession().setAttribute("access_token", oauthToken.getAccessToken()); // get the user information return "redirect:/userinfo"; }
From source file:comsat.sample.ui.method.SampleMethodSecurityApplicationTests.java
@Test public void testLogin() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); form.set("username", "admin"); form.set("password", "admin"); getCsrf(form, headers);/*from w w w . j av a 2 s. com*/ ResponseEntity<String> entity = new TestRestTemplate().exchange("http://localhost:" + this.port + "/login", HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class); assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertEquals("http://localhost:" + this.port + "/", entity.getHeaders().getLocation().toString()); }
From source file:com.cloudera.nav.sdk.client.NavApiCient.java
/** * Registers a given set of metadata models * * @param model/* w w w .jav a 2 s .co m*/ */ public MetadataModel registerModels(MetadataModel model) { String url = joinUrlPath(getApiUrl(), "models"); return sendRequest(url, HttpMethod.POST, MetadataModel.class, model); }
From source file:io.github.restdocsext.jersey.operation.preprocess.BinaryPartPlaceholderOperationPreprocessorTest.java
@Test public void replace_binary_multipart_content_with_default_placeholder() { OperationRequestPart part1 = this.partFactory.create("field1", "file1.png", "BinaryContent".getBytes(), new HttpHeaders()); OperationRequestPart part2 = this.partFactory.create("field2", null, "TextContent".getBytes(), new HttpHeaders()); final OperationRequest request = this.requestFactory.create(URI.create("http://localhost"), HttpMethod.POST, null, new HttpHeaders(), new Parameters(), Arrays.asList(part1, part2)); this.preprocessor.field("field1"); final OperationRequest preprocessed = this.preprocessor.preprocess(request); final Collection<OperationRequestPart> parts = preprocessed.getParts(); assertThat(hasPart(parts, "field1", "<<binary data>>"), is(true)); assertThat(hasPart(parts, "field2", "TextContent"), is(true)); }
From source file:org.openschedule.api.impl.EventTemplate.java
public void addEventComment(String shortName, Comment comment) { Log.v(TAG, "addEventComment : enter"); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(new MediaType("application", "json")); HttpEntity<Comment> requestEntity = new HttpEntity<Comment>(comment, requestHeaders); restTemplate.exchange("public/" + shortName + "/comments", HttpMethod.POST, requestEntity, String.class, shortName).getBody();/*w ww . j a va 2 s . c o m*/ Log.v(TAG, "addEventComment : exit"); }
From source file:org.cloudfoundry.identity.uaa.login.integration.AutologinContollerIntegrationTests.java
@Test public void testGetCodeWithFormEncodedRequest() { headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>(); request.set("username", testAccounts.getUserName()); request.set("password", testAccounts.getPassword()); @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = serverRunning.getRestTemplate().exchange(serverRunning.getUrl("/autologin"), HttpMethod.POST, new HttpEntity<MultiValueMap>(request, headers), Map.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); @SuppressWarnings("unchecked") Map<String, Object> result = (Map<String, Object>) entity.getBody(); assertNotNull(result.get("code")); }
From source file:com.cisco.cta.taxii.adapter.httpclient.BasicAuthHttpRequestFactoryTest.java
@Test public void tryConnectWithBasicAuthentication() throws Exception { try {//w w w. j a v a 2s .c o m ClientHttpRequest req = factory.createRequest(connSettings.getPollEndpoint().toURI(), HttpMethod.POST); req.execute(); fail("connection must fail"); } catch (Throwable e) { assertThat(e, instanceOf(HttpHostConnectException.class)); } verifyLog(mockAppender, "Re-using cached 'basic' auth scheme for http://localhost:80"); }