Score:0

Testing Spring Boot API results in HTTP 405 (Method not Allowed) on PUT

in flag

I created an API which I deployed to Tomcat Server. During development, I would start the application from Eclipse and test the end point using Postman. From Eclipse, the application runs fine. I would see my bot (created with Selenium WebDriver) starting, hitting the targeted pages, clicking the scripted elements, and finishing the process.

I modified the POM to build a WAR file which I manually deployed using Tomcat Manager App page. The WAR deployed and it is running fine as far as I can tell. I decided to run the same test using Postman; obviously changing "localhost" to the actual IP address and port. Unfortunately, I get this HTTP 405 error and I do not know why. I assume that something needs to be configured in Tomcat but I have no clue as to what specifically I need to do.

I configured Tomcat according to this and still no luck: http://www.codereye.com/2010/12/configure-tomcat-to-accept-http-put.html

us flag
Need more details on the 405 error - looks like the call might be faulty. Call and response messages would also help with debugging.
hfontanez avatar
in flag
I have no more details to give.
Score:0
in flag

Tomcat by default is not enabled for HTTP PUT command.

I had to configure Tomcat by modifying the web.xml and the tomcat-users.xml files.

Changes to web.xml file

  1. Needed to add readonly=false parameter
<init-param>
    <param-name>readonly</param-name>
    <param-value>false</param-value>
</init-param>
  1. Needed to add a security constraint for the role
<security-constraint>
    <web-resource-collection>
        <web-resource-name>Demo App</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>PUT</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>#####</role-name>
    </auth-constraint>
</security-constraint>

Changes to the tomcat-users.xml file

  1. Needed to add a user and role to match the added security constraint
<user name="#####" password="#####" roles="#####" />
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.