Search code examples
javajsonrestpostmanspring-annotations

Error 405: Request method POST not supported


Initially my request object for calling rest service was:-

public class RequestParamDto {
   private String tokenID;
   private String taxID;
   private String affiliateID;
   private long planID;
   private String participantId;
   private String[] participantIdArr;
}

and corresponding JSON request object is:-

{
   "tokenID": "12356446",
   "taxID": "123456",
   "planID": 123456,
   "affiliateID": "7876675901282905002"
}

I am passing some parameters in header section of POSTMAN CLIENT-

x-username:abc126
x-enterpriseid:F1111
x-uniqueid:4T5646464
x-ris-audienceview:emplabc
Content-Type:application/json
Accept:application/json

Above request is working fine with POSTMAN CLIENT.

Right now my request object contains list of custom objects.It will look like this:

public class ContributionsRequestParamDto {

  private String tokenID;
  private String taxID;
  private String affiliateID;
  private long planID;
  private String accountNumber;
  private String bankAccountNumber;
  private String transitId;
  private BigDecimal eftAmt;
  private Date ppeDate;
  private String taxYear;
  private Short planType;
  private List<ParticipantsDeferralDto> participantsDeferrals;
  private List<EmployersContributionDto> employersContributions;
}   

and its corresponding JSON request object is:

   {
      "tokenID" : "123456789",
      "taxID" : "123456",
      "affiliateID" : "123456789",
      "planID" : 123456,
      "ppeDate" : "2017-10-24",
      "taxYear" : "2017",
      "planType" : 1,
      "participantsDeferrals" : [ {
        "taxId" : "555555",
        "participantDeferralAmt" : 22.00
      } ],
      "employersContributions" : [ {
        "taxId" : "555555",
        "employerContributionAmt" : 22.00
      } ]
    }

For above request I am passing same parameters in header section. I am getting Error 405: Request method &#39;POST&#39; not supported error. I am trying to hit this request with http://api100.abc.xyz.com:9080/abcd/api/sscws/v1/saveContributions URL. Am I doing anything wrong for this request or I missed something? Thanks!

EDIT - My REST function that I want to call is-

@Transactional
@RestController
@RequestMapping("/v1")
@Api(value="v1", description="")
public class SscRestController {
    @RequestMapping(value="/saveContributions", 
            method=RequestMethod.POST, produces={MediaType.APPLICATION_JSON_VALUE}, consumes={MediaType.APPLICATION_JSON_VALUE})
    @ApiOperation(value="Returns the saved contributions object")
    public String saveContributions(@RequestBody ContributionsRequestParam contributionsParam) throws Exception {
        return "success";
    }
}

Solution

  • In "ContributionsRequestParamDto.java" I have declared ppeDate as Date. I have changed it to String and it is working for me.