BAEL-5294 added form-url-encoded data code (#13545)
This commit is contained in:
committed by
GitHub
parent
b161aeec27
commit
075540af10
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.core.client;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.cloud.openfeign.support.SpringEncoder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import com.baeldung.core.defaulterrorhandling.model.FormData;
|
||||
|
||||
import feign.codec.Encoder;
|
||||
import feign.form.spring.SpringFormEncoder;
|
||||
|
||||
@FeignClient(name = "form-client", url = "http://localhost:8085/api", configuration = FormFeignEncoderConfig.class)
|
||||
public interface FormClient {
|
||||
|
||||
@PostMapping(value = "/form", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
void postFormData(@RequestBody FormData data);
|
||||
|
||||
@PostMapping(value = "/form/map", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
void postFormMapData(Map<String, ?> data);
|
||||
|
||||
}
|
||||
|
||||
class FormFeignEncoderConfig {
|
||||
|
||||
@Bean
|
||||
public Encoder encoder(ObjectFactory<HttpMessageConverters> converters) {
|
||||
return new SpringFormEncoder(new SpringEncoder(converters));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.core.defaulterrorhandling.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class FormData {
|
||||
|
||||
int id;
|
||||
String name;
|
||||
}
|
||||
Reference in New Issue
Block a user