0

I looked at the other posts on SO and have not found the answer.

I created a Spring Boot application that currently only has 3 GET web services. I do not have any POST methods.

When I run the application, the console warning keeps looping over and over.

o.s.web.servlet.PageNotFound : Request method 'POST' not supported

Is this something I need to be concerned about? Or is it only showing because I did not implement any POST services?

Project Structure - Application.java Controller -> Manager/ManagerImpl -> DAO/DAOImpl.

When I make a call to the webservice, it is simply reading from a Oracle DB using JDBC and spitting them back out in JSON.

Controller Code -

@RestController
@RequestMapping(value = "/forms")
public class FormController {

    @Autowired
    private FormManager formManager;

    @RequestMapping(value = "/{formId}", method = RequestMethod.GET)
    public FormObj getFormForFormId(@PathVariable int formId) throws Exception {

        FormObj forms = new FormObj();

        try {
            forms = formManager.getFormForFormId(formId);
        } catch (Exception e){
            throw new RemoteException("Error getting forms for formId- " + formId + " " + e.getMessage());
        }

        return forms;
    }

    @RequestMapping(method = RequestMethod.GET)
    public List<FormObj> getFormsforUserId(@RequestParam(value="userId", defaultValue="0") int userId) throws Exception {

        List<FormObj> forms = new ArrayList<>();

        try {
            forms = formManager.getFormForUserId(userId);
        } catch (Exception e){
            throw new RemoteException("Error getting forms for UserId- " + userId + " " + e.getMessage());
        }

        return forms;
    }

    @RequestMapping(value = "/time", method = RequestMethod.GET)
    public long greeting(@RequestParam(value="name", defaultValue="World") String name) {
        return Calendar.getInstance().getTimeInMillis();
    }
}
Alan
  • 9,331
  • 14
  • 52
  • 97
  • 1
    Add more details about your project structure and controllers. Are you sending some sort of request to some URL? – Ali Dehghani May 10 '16 at 20:46
  • Is any of your client end code making any post requests? It seems from the error that it is trying to resolve some post request but is not getting any method mapped to it. – Sajib Acharya May 10 '16 at 21:07
  • @AliDehghani I have added more detail. I am not sending requests to some URL. – Alan May 10 '16 at 21:26
  • @SajibAcharya I am not making any post requests at all. – Alan May 10 '16 at 21:26
  • Help me with two informations. 1) Is the application working normally when deployed without any errors on the client end? 2) In your `getFormsForUserId()` and `greeting()` methods, are the @RequestParams properly coming as appended to the end of the request URL? Right now my guess is that since `@RequestParams` also work with POST, maybe it is trying to find the equivalent POST method when the proper GET methods are failing for some reason. Do check. – Sajib Acharya May 11 '16 at 06:11
  • 1
    _"I am not making any post requests at all."_ Someone is. – a better oliver May 11 '16 at 08:49
  • @SajibAcharya Yes, all three services are working as intended with no errors. As you expected, it seems that `@RequestParam` was the culprit even though the GET methods were functioning. I removed `@RequestParam` from `greeting` and I am no longer getting an error. Do you happen to know why? Also, if you would like to provide the response as an answer, I will accept it. Thanks for narrowing it down! – Alan May 11 '16 at 15:43

1 Answers1

0

As asked by the OP, I am posting my answer.

@RequestParam works with both GET and POST methods. You can also find more information on this SO post.

Like @zeroflagL commented, someone is making a POST request. My best bet is the that the @RequestParamis at fault, which is true, as you say. Now, I cannot tell you exactly why or what is happening in there since I do not have your entire codebase to look into (Spring has a lot of moving parts as we know). Maybe there is some client-end code that is sending a POST request to the backend without your knowledge. I am more focused on the client-end since, the problem you are facing is that an unknown POST request is being made to the backend, which Spring cannot map to any methods, and this can only be done from the client side.

The next steps that you could do:

  1. Remove the @RequestParam usages one at a time and see which one creates the problem. Like you said, when you did remove the @RequestParam from the greeting() method, the error was gone. Maybe that is the problem. Yet try with the other methods too, in this case, getFormsForUserId() method.
  2. Once you do have the method that creates the problem, check the corresponding client end code for that request and see if you find any anomaly there. Maybe the problem is there after all!

Hope this helps. :)

P.S. if you find the reason behind the problem, do let me know. Feels good to learn new stuff.

moffeltje
  • 4,521
  • 4
  • 33
  • 57
Sajib Acharya
  • 1,666
  • 5
  • 29
  • 54