public void write(OAuth2Exception t, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { MultiValueMap<String, String> data = new LinkedMultiValueMap<String, String>(); data.add(OAuth2Exception.ERROR, t.getOAuth2ErrorCode()); data.add(OAuth2Exception.DESCRIPTION, t.getMessage()); Map<String, String> additionalInformation = t.getAdditionalInformation(); if(additionalInformation != null) { for(Map.Entry<String,String> entry : additionalInformation.entrySet()) { data.add(entry.getKey(), entry.getValue()); } } delegateMessageConverter.write(data, contentType, outputMessage); }
public void doWithRequest(ClientHttpRequest request) throws IOException { request.getHeaders().putAll(this.headers); request.getHeaders().setAccept( Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED)); if (logger.isDebugEnabled()) { logger.debug("Encoding and sending form: " + form); } FORM_MESSAGE_CONVERTER.write(this.form, MediaType.APPLICATION_FORM_URLENCODED, request); } }
@Test public void multipartFileResource() throws IOException { String name = "file"; String disposition = "form-data; name=\"" + name + "\"; filename=\"myFile.txt\""; StandardMultipartHttpServletRequest request = requestWithPart(name, disposition, "myBody"); MultipartFile multipartFile = request.getFile(name); assertNotNull(multipartFile); MultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); map.add(name, multipartFile.getResource()); MockHttpOutputMessage output = new MockHttpOutputMessage(); new FormHttpMessageConverter().write(map, null, output); assertThat(output.getBodyAsString(StandardCharsets.UTF_8), containsString( "Content-Disposition: form-data; name=\"file\"; filename=\"myFile.txt\"\r\n" + "Content-Type: text/plain\r\n" + "Content-Length: 6\r\n" + "\r\n" + "myBody\r\n")); }
@Test public void writeForm() throws IOException { MultiValueMap<String, String> body = new LinkedMultiValueMap<>(); body.set("name 1", "value 1"); body.add("name 2", "value 2+1"); body.add("name 2", "value 2+2"); body.add("name 3", null); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); this.converter.write(body, MediaType.APPLICATION_FORM_URLENCODED, outputMessage); assertEquals("Invalid result", "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3", outputMessage.getBodyAsString(StandardCharsets.UTF_8)); assertEquals("Invalid content-type", "application/x-www-form-urlencoded;charset=UTF-8", outputMessage.getHeaders().getContentType().toString()); assertEquals("Invalid content-length", outputMessage.getBodyAsBytes().length, outputMessage.getHeaders().getContentLength()); }
@Override protected void writeInternal(AutologinRequest t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { MultiValueMap<String, String> map = new LinkedMaskingMultiValueMap<String, String>("password"); if (t.getUsername() != null) { map.set("username", t.getUsername()); } if (t.getPassword() != null) { map.set("password", t.getPassword()); } formConverter.write(map, MediaType.APPLICATION_FORM_URLENCODED, outputMessage); } }
this.converter.write(parts, new MediaType("multipart", "form-data", StandardCharsets.UTF_8), outputMessage);
this.converter.write(parts, new MediaType("multipart", "form-data", StandardCharsets.UTF_8), outputMessage);
public void write(Map<String, String> t, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { MultiValueMap<String, String> mvm = new LinkedMultiValueMap<String, String>(); mvm.setAll(t); delegate.write(mvm, contentType, outputMessage); }
@Override public void write(MultiValueMap<String, ?> map, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { // only do special escaping if this is a non-multipart request if (!isMultipart(map, contentType)) { super.write(map, contentType, new TwitterEscapingHttpOutputMessage(outputMessage)); } else { super.write(map, contentType, outputMessage); } }
public void write(Map<String, String> t, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { MultiValueMap<String, String> mvm = new LinkedMultiValueMap<String, String>(); mvm.setAll(t); delegate.write(mvm, contentType, outputMessage); }
@Override public void write(MultiValueMap<String, ?> map, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { // only do special escaping if this is a non-multipart request if (!isMultipart(map, contentType)) { super.write(map, contentType, new TwitterEscapingHttpOutputMessage(outputMessage)); } else { super.write(map, contentType, outputMessage); } }
public void write(OAuth2Exception t, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { MultiValueMap<String, String> data = new LinkedMultiValueMap<String, String>(); data.add(OAuth2Exception.ERROR, t.getOAuth2ErrorCode()); data.add(OAuth2Exception.DESCRIPTION, t.getMessage()); Map<String, String> additionalInformation = t.getAdditionalInformation(); if(additionalInformation != null) { for(Map.Entry<String,String> entry : additionalInformation.entrySet()) { data.add(entry.getKey(), entry.getValue()); } } delegateMessageConverter.write(data, contentType, outputMessage); }
public void doWithRequest(ClientHttpRequest request) throws IOException { request.getHeaders().putAll(this.headers); request.getHeaders().setAccept( Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED)); if (logger.isDebugEnabled()) { logger.debug("Encoding and sending form: " + form); } FORM_MESSAGE_CONVERTER.write(this.form, MediaType.APPLICATION_FORM_URLENCODED, request); } }
private synchronized void buildContentData() { if (this.contentData != null) { return; } try { MultiValueMap<String, Object> builder = RequestContentDataExtractor.extract(this.request); FormHttpOutputMessage data = new FormHttpOutputMessage(); this.contentType = MediaType.valueOf(this.request.getContentType()); data.getHeaders().setContentType(this.contentType); FormBodyWrapperFilter.this.formHttpMessageConverter.write(builder, this.contentType, data); // copy new content type including multipart boundary this.contentType = data.getHeaders().getContentType(); byte[] input = data.getInput(); this.contentLength = input.length; this.contentData = input; } catch (Exception e) { throw new IllegalStateException("Cannot convert form data", e); } }