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.zalando.boot.etcd.EtcdClientTest.java
@Test public void create() throws EtcdException { server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample")) .andExpect(MockRestRequestMatchers.method(HttpMethod.POST)) .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED)) .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")).andRespond( MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"), MediaType.APPLICATION_JSON)); EtcdResponse response = client.create("sample", "Hello world"); Assert.assertNotNull("response", response); server.verify();/*w w w . j av a 2 s .co m*/ }
From source file:com.orange.ngsi.client.UpdateContextRequestTest.java
@Test public void performPostWith200() throws Exception { protocolRegistry.unregisterHost(brokerUrl); HttpHeaders httpHeaders = ngsiClient.getRequestHeaders(brokerUrl); Assert.assertEquals("application/json", httpHeaders.getFirst("Content-Type")); Assert.assertEquals("application/json", httpHeaders.getFirst("Accept")); httpHeaders.add("Fiware-Service", serviceName); httpHeaders.add("Fiware-ServicePath", servicePath); String responseBody = json(jsonConverter, createUpdateContextResponseTempSensor()); this.mockServer.expect(requestTo(brokerUrl + "/ngsi10/updateContext")).andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE)) .andExpect(header("Accept", MediaType.APPLICATION_JSON_VALUE)) .andExpect(header("Fiware-Service", serviceName)) .andExpect(header("Fiware-ServicePath", servicePath)) .andExpect(jsonPath("$.updateAction").value(UpdateAction.UPDATE.getLabel())) .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON)); ngsiClient.updateContext(brokerUrl, httpHeaders, createUpdateContextTempSensor(0)).get(); this.mockServer.verify(); }
From source file:org.openbaton.nse.beans.connectivitymanageragent.ConnectivityManagerRequestor.java
public AddQueue addQueue(AddQueue add) { String url = configuration.getBaseUrl() + "/queue"; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> postEntity = new HttpEntity<>(mapper.toJson(add, AddQueue.class), headers); ResponseEntity<String> addResp = template.exchange(url, HttpMethod.POST, postEntity, String.class); logger.debug("posted " + add.toString() + " and returned " + addResp.getBody()); if (!addResp.getStatusCode().is2xxSuccessful()) { return null; } else {/*from w w w. j a va 2s. c o m*/ return mapper.fromJson(addResp.getBody(), AddQueue.class); } }
From source file:com.orange.ngsi.client.QueryContextRequestTest.java
@Test public void queryContextRequestOK_XML() throws Exception { ngsiClient.protocolRegistry.registerHost(baseUrl); String responseBody = xml(xmlConverter, createQueryContextResponseTemperature()); this.mockServer.expect(requestTo(baseUrl + "/ngsi10/queryContext")).andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", MediaType.APPLICATION_XML_VALUE)) .andExpect(header("Accept", MediaType.APPLICATION_XML_VALUE)) .andExpect(xpath("queryContextRequest/entityIdList/entityId[*]").nodeCount(1)) .andExpect(xpath("queryContextRequest/entityIdList/entityId/id").string("S*")) .andExpect(xpath("queryContextRequest/entityIdList/entityId/@type").string("TempSensor")) .andExpect(xpath("queryContextRequest/entityIdList/entityId/@isPattern").string("true")) .andExpect(xpath("queryContextRequest/attributeList/*").nodeCount(1)) .andExpect(xpath("queryContextRequest/attributeList/attribute").string("temp")) .andExpect(xpath("queryContextRequest/restriction").doesNotExist()) .andRespond(withSuccess(responseBody, MediaType.APPLICATION_XML)); QueryContextResponse response = ngsiClient.queryContext(baseUrl, null, createQueryContextTemperature()) .get();/*from w w w .jav a 2 s.co m*/ this.mockServer.verify(); Assert.assertEquals(1, response.getContextElementResponses().size()); Assert.assertEquals(CodeEnum.CODE_200.getLabel(), response.getContextElementResponses().get(0).getStatusCode().getCode()); Assert.assertEquals("S1", response.getContextElementResponses().get(0).getContextElement().getEntityId().getId()); Assert.assertEquals("TempSensor", response.getContextElementResponses().get(0).getContextElement().getEntityId().getType()); Assert.assertEquals(false, response.getContextElementResponses().get(0).getContextElement().getEntityId().getIsPattern()); Assert.assertEquals(1, response.getContextElementResponses().get(0).getContextElement().getContextAttributeList().size()); Assert.assertEquals("temp", response.getContextElementResponses().get(0).getContextElement() .getContextAttributeList().get(0).getName()); Assert.assertEquals("float", response.getContextElementResponses().get(0).getContextElement() .getContextAttributeList().get(0).getType()); Assert.assertEquals("15.5", response.getContextElementResponses().get(0).getContextElement() .getContextAttributeList().get(0).getValue()); }
From source file:org.cloudfoundry.identity.uaa.login.feature.InvitationsIT.java
private String generateCode() { String token = testClient.getOAuthAccessToken("login", "loginsecret", "client_credentials", "password.write,scim.write"); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + token); RestTemplate uaaTemplate = new RestTemplate(); String userEmail = "user" + new SecureRandom().nextInt() + "@example.com"; ScimUser scimUser = new ScimUser(); scimUser.setUserName(userEmail);// w ww. jav a 2s. c o m ScimUser.Email email = new ScimUser.Email(); email.setPrimary(true); email.setValue(userEmail); scimUser.setEmails(Arrays.asList(email)); scimUser.setOrigin(Origin.UAA); HttpEntity<ScimUser> request = new HttpEntity<>(scimUser, headers); ResponseEntity<ScimUser> response = uaaTemplate.exchange(uaaUrl + "/Users", HttpMethod.POST, request, ScimUser.class); Timestamp expiry = new Timestamp(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(System.currentTimeMillis() + 24 * 3600, TimeUnit.MILLISECONDS)); ExpiringCode expiringCode = new ExpiringCode(null, expiry, "{\"client_id\":\"app\", \"user_id\":\"" + response.getBody().getId() + "\", \"email\":\"user@example.com\"}"); HttpEntity<ExpiringCode> expiringCodeRequest = new HttpEntity<>(expiringCode, headers); ResponseEntity<ExpiringCode> expiringCodeResponse = uaaTemplate.exchange(uaaUrl + "/Codes", HttpMethod.POST, expiringCodeRequest, ExpiringCode.class); expiringCode = expiringCodeResponse.getBody(); return expiringCode.getCode(); }
From source file:com.zhm.config.MyAuthorizationCodeAccessTokenProvider.java
public String obtainAuthorizationCode(OAuth2ProtectedResourceDetails details, AccessTokenRequest request) throws UserRedirectRequiredException, UserApprovalRequiredException, AccessDeniedException, OAuth2AccessDeniedException { AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails) details; HttpHeaders headers = getHeadersForAuthorizationRequest(request); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); if (request.containsKey(OAuth2Utils.USER_OAUTH_APPROVAL)) { form.set(OAuth2Utils.USER_OAUTH_APPROVAL, request.getFirst(OAuth2Utils.USER_OAUTH_APPROVAL)); for (String scope : details.getScope()) { form.set(scopePrefix + scope, request.getFirst(OAuth2Utils.USER_OAUTH_APPROVAL)); }//from w ww . j ava 2 s . c o m } else { form.putAll(getParametersForAuthorizeRequest(resource, request)); } authorizationRequestEnhancer.enhance(request, resource, form, headers); final AccessTokenRequest copy = request; final ResponseExtractor<ResponseEntity<Void>> delegate = getAuthorizationResponseExtractor(); ResponseExtractor<ResponseEntity<Void>> extractor = new ResponseExtractor<ResponseEntity<Void>>() { @Override public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException { if (response.getHeaders().containsKey("Set-Cookie")) { copy.setCookie(response.getHeaders().getFirst("Set-Cookie")); } return delegate.extractData(response); } }; // Instead of using restTemplate.exchange we use an explicit response extractor here so it can be overridden by // subclasses ResponseEntity<Void> response = getRestTemplate().execute(resource.getUserAuthorizationUri(), HttpMethod.POST, getRequestCallback(resource, form, headers), extractor, form.toSingleValueMap()); if (response.getStatusCode() == HttpStatus.OK) { // Need to re-submit with approval... throw getUserApprovalSignal(resource, request); } URI location = response.getHeaders().getLocation(); String query = location.getQuery(); Map<String, String> map = OAuth2Utils.extractMap(query); if (map.containsKey("state")) { request.setStateKey(map.get("state")); if (request.getPreservedState() == null) { String redirectUri = resource.getRedirectUri(request); if (redirectUri != null) { request.setPreservedState(redirectUri); } else { request.setPreservedState(new Object()); } } } String code = map.get("code"); if (code == null) { throw new UserRedirectRequiredException(location.toString(), form.toSingleValueMap()); } request.set("code", code); return code; }
From source file:jp.go.aist.six.util.core.web.spring.Http.java
/** * HTTP POST: Reads the contents from the specified stream and sends them to the URL. * * @return/*w w w . j ava 2s. c o m*/ * the location, as an URI, where the resource is created. * @throws HttpException * when an exceptional condition occurred during the HTTP method execution. */ public static String postFrom(final URL to_url, final InputStream from_stream, final MediaType media_type) { InputStreamRequestCallback callback = new InputStreamRequestCallback(from_stream, media_type); String location = _execute(to_url, HttpMethod.POST, callback, new LocationHeaderResponseExtractor()); return location; }
From source file:com.cisco.cta.taxii.adapter.AdapterTaskIT.java
private void nextRequestResponse(int count) throws IOException { when(httpResp.getRawStatusCode()).thenReturn(200); when(httpResp.getBody()).thenReturn(taxiiPollRespBodyNext); task.run();//w ww.j av a2 s . c o m verify(httpRequestFactory, times(count)).createRequest(pollServiceUri, HttpMethod.POST); verify(httpReq, times(count)).execute(); assertThat(httpReqHeaders, hasAllTaxiiHeaders()); assertThat(httpReqBody, is(nextPollRequest("123", "collection_name", "2000-12-24T01:02:03.004+01:00"))); httpReqBody.reset(); }
From source file:com.projectx.mvc.servicehandler.quickregister.QuickRegisterHandler.java
@Override public QuickRegisterSavedEntityDTO addNewCustomer(QuickRegisterEntity customerQuickRegisterEntity) throws QuickRegisterDetailsAlreadyPresentException { HttpEntity<QuickRegisterEntity> entity = new HttpEntity<QuickRegisterEntity>(customerQuickRegisterEntity); ResponseEntity<QuickRegisterSavedEntityDTO> result = restTemplate.exchange( env.getProperty("rest.host") + "/customer/quickregister", HttpMethod.POST, entity, QuickRegisterSavedEntityDTO.class); if (result.getStatusCode() == HttpStatus.CREATED) return result.getBody(); else if (result.getStatusCode() == HttpStatus.NOT_ACCEPTABLE) throw new ValidationFailedException(); else if (result.getStatusCode() == HttpStatus.ALREADY_REPORTED) throw new QuickRegisterDetailsAlreadyPresentException(); throw new ResourceNotFoundException(); }
From source file:io.syndesis.runtime.BaseITCase.java
protected <T> ResponseEntity<T> post(String url, Object body, Class<T> responseClass, String token, HttpStatus expectedStatus) {/*w w w.j a v a 2s .com*/ return http(HttpMethod.POST, url, body, responseClass, token, expectedStatus); }