List of usage examples for org.springframework.http.converter FormHttpMessageConverter FormHttpMessageConverter
public FormHttpMessageConverter()
From source file:org.geoserver.importer.rest.ImportTaskControllerTest.java
private Integer putZipAsURL(String zip) throws Exception { MockHttpServletResponse resp = postAsServletResponse(RestBaseController.ROOT_PATH + "/imports", ""); assertEquals(201, resp.getStatus()); assertNotNull(resp.getHeader("Location")); String[] split = resp.getHeader("Location").split("/"); Integer id = Integer.parseInt(split[split.length - 1]); ImportContext context = importer.getContext(id); MockHttpServletRequest req = createRequest(RestBaseController.ROOT_PATH + "/imports/" + id + "/tasks/"); MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>(1); form.add("url", new File(zip).getAbsoluteFile().toURI().toString()); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final HttpHeaders headers = new HttpHeaders(); new FormHttpMessageConverter().write(form, MediaType.APPLICATION_FORM_URLENCODED, new HttpOutputMessage() { @Override/*from w w w. jav a 2 s . co m*/ public OutputStream getBody() throws IOException { return stream; } @Override public HttpHeaders getHeaders() { return headers; } }); req.setContent(stream.toByteArray()); req.setMethod("POST"); req.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE); req.addHeader("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); resp = dispatch(req); assertEquals(201, resp.getStatus()); context = importer.getContext(context.getId()); assertNull(context.getData()); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertTrue(task.getData() instanceof SpatialFile); return id; }
From source file:org.springframework.samples.portfolio.web.tomcat.IntegrationPortfolioTests.java
private static void loginAndSaveJsessionIdCookie(final String user, final String password, final HttpHeaders headersToUpdate) { String url = "http://localhost:" + port + "/login.html"; new RestTemplate().execute(url, HttpMethod.POST, new RequestCallback() { @Override/*w w w .j a va 2 s .c om*/ public void doWithRequest(ClientHttpRequest request) throws IOException { MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); map.add("username", user); map.add("password", password); new FormHttpMessageConverter().write(map, MediaType.APPLICATION_FORM_URLENCODED, request); } }, new ResponseExtractor<Object>() { @Override public Object extractData(ClientHttpResponse response) throws IOException { headersToUpdate.add("Cookie", response.getHeaders().getFirst("Set-Cookie")); return null; } }); }
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.AbstractOwncloudRestServiceImpl.java
private void configureRestTemplate(URL locationURL) throws MalformedURLException { String rootUri = OwncloudRestUtils.appendDefaultPath(locationURL, DEFAULT_PATH); log.info("Create the REST-Template to URI {} to be used with the authenticated User", rootUri); restTemplate = restTemplateBuilder.additionalMessageConverters(new FormHttpMessageConverter()) .errorHandler(responseErrorHandler).rootUri(rootUri).build(); Validate.notNull(restTemplate);/*from w ww . j ava 2s . c o m*/ }