spring-restcontroller

@JsonProperty not working for Content-Type : application/x-www-form-urlencoded

感情迁移 提交于 2019-12-20 02:39:13
问题 The REST API takes input content type : application/x-www-form-urlencoded, when it is mapped to a Java Object, like public class MyRequest { @JsonProperty("my_name") private String myName; @JsonProperty("my_phone") private String myPhone; //Getters and Setters of myName and myPhone. } In form input request, I am setting values of my_name and my_phone but the MyRequest object comes with myName and myPhone as null. I am using Jackson-annotations 2.3 jar Any Suggestions what may be wrong ? 回答1:

Map parameter as GET param in Spring REST controller

北城余情 提交于 2019-12-20 02:15:55
问题 How I can pass a Map parameter as a GET param in url to Spring REST controller ? 回答1: There are different ways ( but a simple @RequestParam('myMap')Map<String,String> does not work) The (IMHO) easiest solution is to use a command object then you could use [key] in the url to specifiy the map key: @Controller @RequestMapping("/demo") public class DemoController { public static class Command{ private Map<String, String> myMap; public Map<String, String> getMyMap() {return myMap;} public void

Could not verify the provided CSRF token because your session was not found in spring security

こ雲淡風輕ζ 提交于 2019-12-18 12:05:07
问题 I am using spring security along with java config @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/api/*").hasRole("ADMIN") .and() .addFilterAfter(new CsrfTokenResponseHeaderBindingFilter(), CsrfFilter.class) .exceptionHandling() .authenticationEntryPoint(restAuthenticationEntryPoint) .and() .formLogin() .successHandler(authenticationSuccessHandler) .failureHandler(new SimpleUrlAuthenticationFailureHandler()); I am using PostMan

Could not verify the provided CSRF token because your session was not found in spring security

余生颓废 提交于 2019-12-18 12:04:14
问题 I am using spring security along with java config @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/api/*").hasRole("ADMIN") .and() .addFilterAfter(new CsrfTokenResponseHeaderBindingFilter(), CsrfFilter.class) .exceptionHandling() .authenticationEntryPoint(restAuthenticationEntryPoint) .and() .formLogin() .successHandler(authenticationSuccessHandler) .failureHandler(new SimpleUrlAuthenticationFailureHandler()); I am using PostMan

Spring throwing HttpMediaTypeNotAcceptableException: Could not find acceptable representation due to dot in url path [duplicate]

我们两清 提交于 2019-12-18 11:21:44
问题 This question already has answers here : HttpMediaTypeNotAcceptableException: Could not find acceptable representation in exceptionhandler (2 answers) Closed 2 years ago . Final Edit So after researching this because the answer's didn't quite make since with what I was seeing, I found out that Spring does some weird stuff with extension matching. If I submit a request like this byNameOrAtlName/myStringHere.1 or this byNameOrAtlName/myStringHere.12 everything is fine, but byNameOrAtlName

SpringFox Docket per controller not working in spring boot

送分小仙女□ 提交于 2019-12-18 07:23:40
问题 In my spring boot application, I have multiple Rest Controllers and need to generate swagger for each controller seperately. By using below Docket config for each controller in my spring boot application class, i am able to download controller specific swagger by going to /v2/api-docs?group=ai where i = 1 to n However in swagger-ui.html, when i select a1(/v2/api-docs?group=a1), it shows path as "/api/a1/a1", while selecting a2(/v2/api-docs?greoup=a2), it shows correct path i.e. /api/a2 I have

Get XML in plain text

喜你入骨 提交于 2019-12-14 03:43:44
问题 I have this endpoint for Spring Rest API: @PostMapping(value = "/v1/", consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) public PaymentResponse handleMessage(@RequestBody PaymentTransaction transaction, HttpServletRequest request) throws Exception { // get here plain XML } XML model. @XmlRootElement(name = "payment_transaction") @XmlAccessorType(XmlAccessType.FIELD) public class

No table is being created neither the RestController Url is working

依然范特西╮ 提交于 2019-12-14 02:23:33
问题 please tell what I am doing wrong, the code is running with no errors but I am getting no tables or the working restcontroller url whatsoever import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.usere.entity.UserEntity; @RestController @RequestMapping("/usr") public class Ucontroller { @RequestMapping("/showall") public UserEntity showall() { return new UserEntity("abc",29); } } pojo or model for rest import

spring security with angular2 giving 403 forbidden error only on POST,PUT and delete

本小妞迷上赌 提交于 2019-12-13 06:59:52
问题 I have spring mvc(rest), spring security(4.x) and angular2 application. App is deployed in weblogic and it takes care of SAML authentication, so my app is just using authorization piece only. To do that we are using custom request header authentication filter where we validate custom request header and based on that loads user from db with granted authority. All this works fine. Now I am implementing CSRF protection where my server is adding CSRF token cookie and since angular2 is has out of

Unable to start embedded container; nested exception is java.lang.NoClassDefFoundError: java/nio/charset/StandardCharsets

一个人想着一个人 提交于 2019-12-13 06:04:45
问题 I created an starter project from spring tool suite with config shown below when I run the App with changing of @SpringBootApplication @RestController public class FirstApplication { public static void main(String[] args) { SpringApplication.run(FirstApplication.class, args); } @RequestMapping("/greet") public String helloGreeting() { return "Salam REST"; } } it crashes saying . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | |