spring-restcontroller

@RequestBody is getting null values

孤街浪徒 提交于 2019-11-28 11:56:10
I have created a simple REST service (POST). But when i call this service from postman @RequestBody is not receiving any values. import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; @RestController public class Add_Policy { @ResponseBody

415 Unsupported MediaType for POST request in spring application

时光毁灭记忆、已成空白 提交于 2019-11-28 11:05:12
I have a very simple Spring Application (NOT spring boot). I have implemented a GET and POST controller methods. the GET method works fine. But the POST is throwing 415 Unsupported MediaType . Steps to reproduce are available below ServiceController. java package com.example.myApp.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody;

Spring Rest Controller Return Specific Fields

£可爱£侵袭症+ 提交于 2019-11-28 09:49:55
I've been going through my head the best way to design a JSON API using Spring MVC. As we all know IO is expensive, and thus I don't want to make the client make several API calls to get what they need. However at the same time I don't necessarily want to return the kitchen sink. As an example I was working on a game API similar to IMDB but for video games instead. If I returned everything connected to Game it would look something like this. /api/game/1 { "id": 1, "title": "Call of Duty Advanced Warfare", "release_date": "2014-11-24", "publishers": [ { "id": 1, "name": "Activision" } ],

How to create a Spring Interceptor for Spring RESTful web services

倾然丶 夕夏残阳落幕 提交于 2019-11-27 22:55:25
I have some Spring RESTful (RestControllers) web services with no web.xml and I am using Spring boot to start the services. I want to add authorization layer for the web services and wanted to route all the http requests to one front controller before actually calling the web service itself. (I have a code to simulate sessions behavior at the autherisation layer, to validate a user based on a generated key that I send with each of the httpRequest from the client). Is there any Standard Spring solution on routing all the requests to a filter /front controller? Thanks in advance, Praneeth Edit:

upload file springboot Required request part 'file' is not present

送分小仙女□ 提交于 2019-11-27 14:39:03
问题 I want to add an upload function to my spring boot application; this is my upload Rest Controller package org.sid.web; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletContext; import org.springframework.beans.factory.annotation.Autowired; import org

@RequestBody is getting null values

百般思念 提交于 2019-11-27 06:43:51
问题 I have created a simple REST service (POST). But when i call this service from postman @RequestBody is not receiving any values. import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org

Spring Rest Controller Return Specific Fields

自闭症网瘾萝莉.ら 提交于 2019-11-27 03:14:05
问题 I've been going through my head the best way to design a JSON API using Spring MVC. As we all know IO is expensive, and thus I don't want to make the client make several API calls to get what they need. However at the same time I don't necessarily want to return the kitchen sink. As an example I was working on a game API similar to IMDB but for video games instead. If I returned everything connected to Game it would look something like this. /api/game/1 { "id": 1, "title": "Call of Duty

How to create a Spring Interceptor for Spring RESTful web services

自作多情 提交于 2019-11-26 22:17:56
问题 I have some Spring RESTful (RestControllers) web services with no web.xml and I am using Spring boot to start the services. I want to add authorization layer for the web services and wanted to route all the http requests to one front controller before actually calling the web service itself. (I have a code to simulate sessions behavior at the autherisation layer, to validate a user based on a generated key that I send with each of the httpRequest from the client). Is there any Standard Spring

415 Unsupported MediaType for POST request in spring application

a 夏天 提交于 2019-11-26 21:36:36
问题 I have a very simple Spring Application (NOT spring boot). I have implemented a GET and POST controller methods. the GET method works fine. But the POST is throwing 415 Unsupported MediaType . Steps to reproduce are available below ServiceController. java package com.example.myApp.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web