java


How to troubleshoot message=Request method 'POST' not supported as “application/json”


I am building a Spring Boot application that allows the user to save documents to the sever that they create and edit through Tinymce.
But when I click the save button I get this error regarding POST:
Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
...
Request method 'POST' not supported
status=405, error=Method Not Allowed, exception=org.springframework.web.HttpRequestMethodNotSupportedException, message=Request method 'POST' not supported, path=/docs}] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
From my Controller for Docs
#ResponseBody
#RequestMapping(value = "/{name}", method = RequestMethod.POST, produces="text/html", consumes={"application/json","application/xml"} )
public String addTodos(#PathVariable("name") String name) {
docsService.addDocs(name);
return "200 OK";
}
#ResponseBody
#RequestMapping(value = "/{name}", method = RequestMethod.PUT, produces="text/html", consumes = {"application/json","application/xml"})
public String updateComplated(#PathVariable("name") String name) {
docsService.updateComplated(name);
return "200 OK";
}
What I do not understand about this error is that I clearly specify how to handle the POST method, yet it says it does not exist.
Can someone please guide me on how to troubleshoot this?
Here is a screenshot from Firefox developer tools showing Response and Request headers
The params look like this:
Well, didn't expect to figure this out but here it is.
First, I instead set up a "fixed" URI for HTTP POST. I just took out the value portion of the RequestMapping.
Second, as I took out the value section of RequestMapping, I also took out the #PathVariable. Instead as you see, I pointed #RequestBody at String name, and then specified the target entity.
After doing this, I received a 415 error instead of a 405. This means that the POST method was recognized, but the mediatype was incorrect. Despite what you may read in other posts, you can keep #RequetBody in and specify application/x-www-form-urlencoded; charset=UTF-8 as the content type to be consumed.
#ResponseBody
#RequestMapping(method = RequestMethod.POST, produces = "text/html", consumes = {"application/x-www-form-urlencoded; charset=UTF-8"})
public String handle(#RequestBody String name, Docs docs) {
docsService.addDocs(name);
return "200 OK";
}
FYI this took me hours upon hours to fix. Hope the answer helps.

Related Links

Implementing a bloomfilter with expiring elements for streaming data
add a string to the beginning of every file in java
LibGDX unProject returns wrong values
Passing ArrayList to getData for RecyclerView use
HOW DO YOU CHOOSE WHICH DESIGN PATTERN TO USE? [closed]
Why JFrame.EXIT_ON_CLOSE vs EXIT_ON_CLOSE?
Creating array of data, for line graphs in Android?
Maven runs all tests with keyword “Test”
SSL Certificate unable to find, even though it's in the keystore
Hibernate sql query to criteria
How to create star graph?
Parsing int from string produces incorrect result
Showing a liste of alias recorded in AndroidKeyStore
Java error: org.apache.jasper.JasperException: Unable to compile class for JSP:
Single instance of PicketLink for multiple applications
Call not thread-safe DLL function from Java's multi threads in parallel

Categories

HOME
sendgrid
pdf
wso2-am
cloud
keras
omnet++
reflection
drivers
plone
tesseract
filtering
spring-cloud-stream
jgroups
fsm
acquia
opengl-es-2.0
qt-creator
worldwind
predix
swiftlint
clickonce
bootstrap-tour
rundeck
opennlp
pepper
intel-pin
fgetcsv
entitlements
maxmind
assistant
replaceall
dbclient
gsmcomm
delicious-api
nat
key-value-observing
event-driven
hue
unoconv
grid.mvc
core-plot
netcdf4
thin
react-scripts
qsslsocket
ionicons
datastax-startup
dropbox-php
firmata
home-directory
asp.net-4.5
gstreamer-0.10
superstack
whois
ptrace
associative-array
system.management
graph-drawing
sailfish-os
generic-programming
cisco-ios
unity3d-gui
cdt
aapt
uitouch
fluentautomation
sitemesh
spring-io
coverflow
cassini-dev
word-processor
windows-phone-7.1.1
enter
postgresql-performance
php-parser
subgurim-maps
invite
mongomapper
createwindow
rescale
iweb
javap
noscript
nerddinner
sector
defensive-programming
w3wp

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile