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:it.reply.orchestrator.command.NotifyCommandTest.java
@Test @DatabaseSetup("/data/database-init.xml") public void doexecuteSuccesfully() throws Exception { mockServer.expect(requestTo("http://test-server.com")).andExpect(method(HttpMethod.POST)) .andRespond(withSuccess());// w w w . ja v a 2 s .c o m CommandContext ctx = TestCommandHelper.buildCommandContext() .withParam(WorkflowConstants.WF_PARAM_DEPLOYMENT_ID, "mmd34483-d937-4578-bfdb-ebe196bf82dd").get(); boolean result = (boolean) notifyCommand.execute(ctx).getData(Constants.RESULT); assertEquals(true, result); mockServer.verify(); }
From source file:org.messic.android.util.RestJSONClient.java
/** * Rest POST petition to the server at the url param, sending all the post parameters defiend at formData. This post * return an object (json marshalling) of class defined at clazz parameter. You should register a * {@link RestListener} in order to obtain the returned object, this is because the petition is done in an async * process./*from ww w . jav a 2s .co m*/ * * @param url {@link string} URL to attack * @param formData {@link MultiValueMap}<?,?/> map of parameters to send * @param clazz Class<T/> class that you will marshall to a json object * @param rl {@link RestListener} listener to push the object returned */ public static <T> void post(final String url, MultiValueMap<?, ?> formData, final Class<T> clazz, final RestListener<T> rl) { final RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter()); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); // Sending multipart/form-data requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); // Populate the MultiValueMap being serialized and headers in an HttpEntity object to use for the request final HttpEntity<MultiValueMap<?, ?>> requestEntity = new HttpEntity<MultiValueMap<?, ?>>(formData, requestHeaders); AsyncTask<Void, Void, Void> at = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { try { ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, clazz); rl.response(response.getBody()); } catch (Exception e) { rl.fail(e); } return null; } }; at.execute(); }
From source file:top.zhacker.ms.reactor.spring.function.Client.java
public void createPerson() { URI uri = URI.create(String.format("http://%s:%d/person", Server.HOST, Server.PORT)); Person jack = new Person("Jack Doe", 16); ClientRequest request = ClientRequest.method(HttpMethod.POST, uri).body(BodyInserters.fromObject(jack)) .build();// w w w .j a v a 2 s . co m Mono<ClientResponse> response = exchange.exchange(request); System.out.println(response.block().statusCode()); }
From source file:com.allogy.amazonaws.elasticbeanstalk.worker.simulator.application.WorkerApplication.java
public HttpStatus forward(MessageWrapper messageWrapper) { Message message = messageWrapper.getMessage(); HttpEntity<String> messageEntity = createHttpEntity(messageWrapper, message); logger.info("Forwarding message: messageId={}", messageWrapper.getMessage().getMessageId()); try {//from w w w. java 2 s. c o m ResponseEntity<String> responseEntity = restTemplate.exchange(targetUrl, HttpMethod.POST, messageEntity, String.class); return responseEntity.getStatusCode(); } catch (HttpStatusCodeException ex) { HttpStatus statusCode = ex.getStatusCode(); logger.error("The HTTP Worker Application returned a non successful error code. statusCode={}", statusCode); return statusCode; } catch (RestClientException ex) { logger.error("Unable to connect to the HTTP Worker Application."); return HttpStatus.NOT_FOUND; } }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppRecordCreatingStep.java
public AppRouteCreatingStep createAppRecord(String spaceGuid, String appName) throws EnginePublicationException { LOGGER.info("Creating app record for " + appName + " in space " + spaceGuid); String requestBody = createAppRecordBody(spaceGuid, appName); ResponseEntity<String> response = cfRestTemplate.exchange(cfAppsUrl, HttpMethod.POST, HttpCommunication.postRequest(requestBody), String.class); try {//from w w w .j a v a2 s .c o m String appGuid = JsonDataFetcher.getStringValue(response.getBody(), APP_GUID_JSON_PATH); return new AppRouteCreatingStep(cfRestTemplate, cfApiUrl, appGuid); } catch (IOException e) { throw new EnginePublicationException("Unable to create CloudFoundry app record:", e); } }
From source file:org.zalando.github.spring.UsersTemplateTest.java
@Test public void addEmails() throws Exception { mockServer.expect(requestTo("https://api.github.com/user/emails")).andExpect(method(HttpMethod.POST)) // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN")) .andRespond(withSuccess(new ClassPathResource("addEmails.json", getClass()), MediaType.APPLICATION_JSON)); List<Email> emailList = usersTemplate.addEmails("octocat@github.com", "support@github.com"); Assertions.assertThat(emailList).isNotNull(); Assertions.assertThat(emailList.size()).isEqualTo(2); }
From source file:cz.sohlich.workstack.SecurityConfig.java
@Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable().exceptionHandling().and().anonymous().and().servletApi().and().headers() .cacheControl().and().authorizeRequests().antMatchers("/api/task/**").authenticated() .antMatchers(HttpMethod.POST, "/security/login").permitAll().and() .addFilterBefore(new StatelessLoginFilter("/security/login", tokenAuthenticationService, userDetailService, authenticationManager), UsernamePasswordAuthenticationFilter.class) .addFilterBefore(new StatelessAuthenticationFilter(tokenAuthenticationService), UsernamePasswordAuthenticationFilter.class); // .exceptionHandling().authenticationEntryPoint(entryPoint); // .formLogin();//.loginPage("/security/login"); }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaAuthenticationManagerTests.java
@Test public void testAuthenticate() throws Exception { responseHeaders.setLocation(new URI("https://uaa.cloudfoundry.com/")); Map<String, String> response = new HashMap<String, String>(); response.put("username", "marissa"); @SuppressWarnings("rawtypes") ResponseEntity<Map> expectedResponse = new ResponseEntity<Map>(response, responseHeaders, HttpStatus.OK); when(restTemplate.exchange(endsWith("/authenticate"), eq(HttpMethod.POST), any(HttpEntity.class), eq(Map.class))).thenReturn(expectedResponse); Authentication result = authenticationManager .authenticate(new UsernamePasswordAuthenticationToken("marissa", "foo")); assertEquals("marissa", result.getName()); assertTrue(result.isAuthenticated()); }
From source file:com.cisco.cta.taxii.adapter.RequestFactory.java
/** * Create the TAXII request.//from w w w . j av a 2s .co m * * @param feed The TAXII feed name. * @return TAXII poll request. * @throws Exception When any error occurs. */ public ClientHttpRequest createFulfillmentRequest(String messageId, TaxiiStatus.Feed feed, String resultId, Integer resultPartNumber) throws Exception { ClientHttpRequest req = httpRequestFactory.createRequest(pollEndpoint.toURI(), HttpMethod.POST); httpHeadersAppender.appendTo(req.getHeaders()); httpBodyWriter.write(messageId, feed, resultId, resultPartNumber, req.getBody()); return req; }
From source file:at.ac.univie.isc.asio.security.HttpMethodRestrictionFilterTest.java
@Test public void should_ignore_non__GET__request() throws Exception { final TestingAuthenticationToken token = new TestingAuthenticationToken("user", "secret"); setAuthentication(token);/*from w ww .j ava2 s .c o m*/ request.setMethod(HttpMethod.POST.name()); subject.doFilter(request, response, chain); assertThat(getAuthentication(), Matchers.<Authentication>sameInstance(token)); }