简体   繁体   中英

restcontroller post method 405 method not allowed

I have a restcontroller with post method with following url and json request. http://server/member/sc/v1/limited-liability/medicare

package com.dckr.microsvc.medicaredtls.controller;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
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.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;


@RestController
public class UpdMedicareDtlsController {

    private static final Logger logger = LoggerFactory.getLogger(UpdMedicareDtlsController.class);

    @Autowired
    private UpdMedicareLLRecService updMedicareLLRecService;

    @Autowired
    ExceptionObjFactory expObjFactory;


    @RequestMapping(value = UpdMedicareLLConstants.UPD_MEDICARE_LL_URL, method = RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public InlineResponse200 updateMedicareLLRec(@RequestBody MedicareRequest updateMedicareRequest, 
            @RequestHeader(value=UpdMedicareLLConstants.META_TRANSID) String metatransid)
            throws Exception {

        long startTime = System.currentTimeMillis();
        logger.info("Entering UpdMedicareDtlsController -- updateMedicareLLRec(@Request MedicareRequest updateMedicareReq)");

        InlineResponse200 response = null;
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();


        logger.info( updateMedicareRequest.toString());

        if(null!=updateMedicareRequest)
        if ((null!=updateMedicareRequest.getMbruid()&&StringUtils.hasText(updateMedicareRequest.getMbruid()))
        &&(null!=updateMedicareRequest.getMedicare()&&null!=updateMedicareRequest.getMedicare().getPrime()
        &&StringUtils.hasText(updateMedicareRequest.getMedicare().getPrime()))
        &&(null!=updateMedicareRequest.getMedicare()&&null!=updateMedicareRequest.getMedicare().getQualifiedReason()
                &&StringUtils.hasText(updateMedicareRequest.getMedicare().getQualifiedReason()))
        &&(null!=updateMedicareRequest.getLlSeqNum()&&StringUtils.hasText(updateMedicareRequest.getLlSeqNum()))
        &&(null!=updateMedicareRequest.getMedicare()&&null!=updateMedicareRequest.getMedicare().getPartA()
                &&null!=updateMedicareRequest.getMedicare().getPartA().getPrimary()
                &&StringUtils.hasText(updateMedicareRequest.getMedicare().getPartA().getPrimary()))
        &&(null!=updateMedicareRequest.getMedicare()&&null!=updateMedicareRequest.getMedicare().getPartB()
        &&null!=updateMedicareRequest.getMedicare().getPartB().getPrimary()
        &&StringUtils.hasText(updateMedicareRequest.getMedicare().getPartB().getPrimary()))) {
            response = updMedicareLLRecService.updateLLRecord(updateMedicareRequest, metatransid);
        } else {
            throw expObjFactory.createNewAppexception("3002", UpdMedicareLLConstants.MISSING_MANDATORY_DATA);
        }
        else {
            throw expObjFactory.createNewAppexception("3002", UpdMedicareLLConstants.MISSING_MANDATORY_DATA);
        }

        stopWatch.stop();

        logger.info("Exiting UpdMedicareDtlsController -- updateMedicareLLRec() time taken : "+ stopWatch.getTotalTimeMillis());
        return response;

    }
}

While triggering the request in local with post method and json request, getting proper response. but running as spring boot app in docker is throwing exception as method not allowed. Initially i deployed this docker service as put method. now i have moved to post method. If i change my method back to put method. this is working fine.

response: Date Mon, 04 Jun 2018 09:30:16 GMT Content-Length 0

status# HTTP/1.1 405 Method Not Allowed

Allow POST Connection keep-alive X-Application-Context scupdatemedicaredtls:sit Server nginx/1.13.10

Anybody please suggest appropriate response.

Your runtime jar isn't deployed with a post method corresponding with your path and parameters. Double check your deployment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM