MockMVC test Status expected:<201> but was:<404> - java

import com.google.gson.Gson;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import preproject.underdog.answer.dto.answer.AnswerPostDto;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
#WebMvcTest(value = AnswerController.class)
//#AutoConfigureRestDocs
#MockBean(JpaMetamodelMappingContext.class)
public class AnswerController {
#Autowired
private MockMvc mockMvc;
#Autowired
private Gson gson;
#Test
#DisplayName("답변 글 작성 테스트")
void postAnswer() throws Exception {
AnswerPostDto post = new AnswerPostDto("테스트", 1L, 1L);
String content = gson.toJson(post);
ResultActions actions =
mockMvc.perform(
post("/answers")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(content)
);
actions
.andExpect(status().isCreated());
}
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import preproject.underdog.answer.dto.answer.AnswerPostDto;
import preproject.underdog.answer.dto.answer.AnswerRespDto;
import preproject.underdog.answer.mapper.AnswerMapper;
import preproject.underdog.answer.service.AnswerService;
import javax.validation.Valid;
import java.time.LocalDateTime;
#RestController
#RequestMapping("/answers")
#Validated
#RequiredArgsConstructor
public class AnswerController {
private final AnswerService answerService;
private final AnswerMapper answerMapper;
#PostMapping
public ResponseEntity postAnswer(#Valid #RequestBody AnswerPostDto answerPostDto) {
AnswerRespDto answerRespDto = new AnswerRespDto(1L,"테스트",1L,1L,1L, LocalDateTime.of(2023, 4, 3, 3, 3, 0),LocalDateTime.of(2023, 4, 3, 3, 3, 0));
return new ResponseEntity<>(answerRespDto, HttpStatus.CREATED);
}
Here's my codes first,
I tried make Rest Docs first, but I faced a lot of errors, so I just started to try pass the MockMVC test first.
So I gotta got 201 response from that, but I only got 404 error
here's my log.
MockHttpServletRequest:
HTTP Method = POST
Request URI = /answers
Parameters = {}
Headers = [Content-Type:"application/json;charset=UTF-8", Accept:"application/json", Content-Length:"49"]
Body = {"content":"테스트","userId":1,"questionId":1}
Session Attrs = {}
Handler:
Type = org.springframework.web.servlet.resource.ResourceHttpRequestHandler
Async:
Async started = false
Async result = null
Resolved Exception:
Type = null
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 404
Error message = null
Headers = [Vary:"Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers"]
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
#PostMapping
public ResponseEntity postAnswer(#Valid #RequestBody AnswerPostDto answerPostDto) {
return new ResponseEntity<>(HttpStatus.CREATED);
}
I even tried to changed the code to get only 201 response like this
but it still gave me 404 error
What should I do?? thanks

Related

RestTemplate::exchange() - com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60))

Getting the following exception while executing a GET against RestTemplate::exchange(). It's a pretty simple public endpoint. I have included the controller and the DTO. The exception notes 'content type [text/html]' - I have read in other articles that this may be related to error response in XML rather than a response JSON. I have looked a little deeper into exception with no success ... again a pretty simple GET endpoint ?? Any help is appreciated.
Public Endpoint
http://catfact.ninja/fact
Exception
2022-01-07 11:18:40.896 ERROR 22564 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in
context with path [] threw exception [Request processing failed; nested exception
is org.springframework.web.client.RestClientException: Error while extracting response
for type [class com.example.demo.CatDTO] and content type [text/html]; nested exception
is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number,
Array, Object or token 'null', 'true' or 'false'); nested exception
is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)):
expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (PushbackInputStream); line: 1, column: 2]] with root cause
DTO Class
public class CatDTO {
public String fact;
public int length;
}
Controller Class
package com.example.demo;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.*;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
#RestController
public class CatWebServiceController {
#Autowired
RestTemplate restTemplate;
String url = "http://catfact.ninja/fact";
#RequestMapping(value = "/cat")
public ResponseEntity<CatDTO> getCatFact() throws IOException {
System.out.println("Inside: CatWebServiceController::getCatFact()");
CatDTO catDTO;
String urlTemplate = UriComponentsBuilder.fromHttpUrl(url)
.encode()
.toUriString();
// Just a little test
ObjectMapper mapper = new ObjectMapper();
File f = new File("C:\\macgowan\\project\\test\\demo\\response.json");
CatDTO catDTO2 = mapper.readValue(f, CatDTO.class);
// Create the headers
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<String>(headers);
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
//Add the Jackson Message converter
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
// Note: here we are making this converter to process any kind of response,
// not only application/*json, which is the default behaviour
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
messageConverters.add(converter);
restTemplate.setMessageConverters(messageConverters);
ResponseEntity<CatDTO> r = null;
try
{
r = restTemplate.exchange(urlTemplate,
HttpMethod.GET,
entity,
CatDTO.class);
System.out.println("Inside: It worked");
}
catch (HttpClientErrorException exc)
{
String errorMessage = exc.getResponseBodyAsString();
System.out.println("Inside: HttpClientErrorException");
}
catch (Exception exc)
{
String errorMessage = exc.getMessage();
System.out.println("Inside: Exception");
}
return r;
}
}
Spring Init
package com.example.demo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
#SpringBootApplication
public class DemoApplication
{
public static void main(String[] args)
{
SpringApplication.run(DemoApplication.class, args);
}
#Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
}
Try https://catfact.ninja/fact instead of http://catfact.ninja/fact
What you are receiving is literally:
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.20.1</center>
</body>
</html>
so you where right that your error is related to a response in XML
to quickly find out, you can intercept the response:
restTemplate.getInterceptors().add((httpRequest, bytes, clientHttpRequestExecution) -> {
ClientHttpResponse response=clientHttpRequestExecution.execute(httpRequest, bytes);
String text = new String(response.getBody().readAllBytes(), StandardCharsets.UTF_8);
System.out.println(text);
return response;
});

POST method test in spring. Code 400 instead of 201

I am creating an application where I can create a car object.
Car class without setters and getters:
package github.KarolXX.demo.model;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;
#Entity
#Table(name = "cars")
public class Car {
#Id
#GeneratedValue(generator = "inc")
#GenericGenerator(name = "inc", strategy = "increment")
private int id;
#NotBlank(message = "car name`s must be not empty")
private String name;
private LocalDateTime productionYear;
private boolean tested;
public Car() {
}
public Car(#NotBlank(message = "car name`s must be not empty") String name, LocalDateTime productionYear) {
this.name = name;
this.productionYear = productionYear;
}
}
I would like to know how to test the POST method in Spring. Below is a code snippet for the POST method which just create Java object named Car (first snippet)
#PostMapping("/cars")
ResponseEntity<Car> createCar(#RequestBody #Valid Car newCar) {
logger.info("Creating new car");
var result = repository.save(newCar);
return ResponseEntity.created(URI.create("/" + result.getId())).body(result);
}
I am trying to test it this way:
package github.KarolXX.demo.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import github.KarolXX.demo.TestConfiguration;
import github.KarolXX.demo.model.Car;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import java.time.LocalDateTime;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
#SpringBootTest
#AutoConfigureMockMvc
#ActiveProfiles("integration")
class CarControllerIntegrationServerSideTest {
#Autowired
private MockMvc mockMvc;
#Test
public void httpPost_createsNewCar_returnsCreatedCar() throws Exception {
//given
Car car = new Car("second server side test", LocalDateTime.parse("2021-01-02T13:34:54"));
//when + then
mockMvc.perform(post("/cars")
.content(asJsonString(car))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isCreated());
}
public static String asJsonString(final Car objectCar) {
try {
return new ObjectMapper().writeValueAsString(objectCar);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}
}
I did it based on this article
Unfortunately my test does not pass. Although in the logs I can see that the request body and the request headers are set correctly, I get the status 400
2021-03-26 12:05:01.532 WARN 10696 --- [ main] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Expected array or string.; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string.
at [Source: (PushbackInputStream); line: 1, column: 59] (through reference chain: github.KarolXX.demo.model.Car["productionYear"])]
MockHttpServletRequest:
HTTP Method = POST
Request URI = /cars
Parameters = {}
Headers = [Content-Type:"application/json;charset=UTF-8", Accept:"application/json", Content-Length:"279"]
Body = {"id":0,"name":"second server side test","productionYear":{"month":"JANUARY","dayOfWeek":"SATURDAY","dayOfYear":2,"nano":0,"year":2021,"monthValue":1,"dayOfMonth":2,"hour":13,"minute":34,"second":54,"chronology":{"id":"ISO","calendarType":"iso8601"}},"tested":false,"brand":null}
Session Attrs = {}
Handler:
Type = github.KarolXX.demo.controller.CarController
Method = github.KarolXX.demo.controller.CarController#createCar(Car)
Async:
Async started = false
Async result = null
Resolved Exception:
Type = org.springframework.http.converter.HttpMessageNotReadableException
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 400
Error message = null
Headers = []
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
MockHttpServletRequest:
HTTP Method = POST
Request URI = /cars
Parameters = {}
Headers = [Content-Type:"application/json;charset=UTF-8", Accept:"application/json", Content-Length:"279"]
Body = {"id":0,"name":"second server side test","productionYear":{"month":"JANUARY","dayOfWeek":"SATURDAY","dayOfYear":2,"nano":0,"year":2021,"monthValue":1,"dayOfMonth":2,"hour":13,"minute":34,"second":54,"chronology":{"id":"ISO","calendarType":"iso8601"}},"tested":false,"brand":null}
Session Attrs = {}
Handler:
Type = github.KarolXX.demo.controller.CarController
Method = github.KarolXX.demo.controller.CarController#createCar(Car)
Async:
Async started = false
Async result = null
Resolved Exception:
Type = org.springframework.http.converter.HttpMessageNotReadableException
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 400
Error message = null
Headers = []
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
java.lang.AssertionError: Status expected:<201> but was:<400>
Expected :201
Actual :400
I have no idea what could be wrong but when I change this line of code mockMvc.perform(post("/cars") to this one mockMvc.perform(post("/") then I got status 404
I have solved the problem, but I don't know why the previous version is not working. I removed the static method from the test class and changed the POST method checking: namely I created a variable holding JSON as a String and passed it to the content method. In previous version this String was returned by ObjectMapper().writeValueAsString() in static method. My modified test class:
#Test
public void httpPost_createsNewCar_returnsCreatedCar() throws Exception {
//given
//Car car = new Car("second server side test", LocalDateTime.parse("2021-01-02T13:34:54"));
String id = String.valueOf(repo.getSize());
String jsonString = new JSONObject()
.put("id", id)
.put("tested", false)
.put("productionYear", "2017-06-18T12:12:12")
.put("name", "Toyota")
.toString();
//when + then
mockMvc.perform(post("/cars")
.content(jsonString)
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isCreated());
}

o.s.web.servlet.PageNotFound No mapping for GET

friend, I'm using RestController from spring data to consume data from external API.
When I use PostMan to get data, I get this 404 error code.
But if I use direct URL with a header on POSTMAN I get the correct data and response code 200
Could you please help me
Console Intelij
2018-11-13 17:30:42.334 WARN 11820 --- [nio-8080-exec-2] o.s.web.servlet.PageNotFound : No mapping for GET /toto
This my Controller Class
package com.controller;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.json.Json;
#RestController
#CrossOrigin("*") // pour gere les erreu d'ente ex: Orig
public class FlightRestServives {
private static Logger logger = Logger.getLogger(FlightRestServives.class.getName());
#Autowired
private RestTemplate restTemplate;
String serviceURL = "https://api.klm.com/opendata/flightoffers/reference-data?country=NL";
public FlightRestServives() {
}
//Consuming a service by GET method
// #GetMapping("/test")
#RequestMapping(
value = "/toto",
headers = {
"api-key=xmc3vburw886j9zqcsfrdu2t",
"AFKL-TRAVEL-Country=NL",
"AFKL-TRAVEL-Host=KL",
"X-Originating-IP=46.193.67.48"}
/*produces = "application/json",
consumes = "application/json",
headers = {
"api-key=xmc3vburw886j9zqcsfrdu2t",
"AFKL-TRAVEL-Country=NL",
"AFKL-TRAVEL-Host=KL",
"X-Originating-IP=46.193.67.48"}*/
)
public Json getAvailableOperations() {
logger.debug("Flight");
HttpHeaders headers = new HttpHeaders();
headers.add("api-key", "Keyyy");
headers.add("AFKL-TRAVEL-Country", "NL");
headers.add("AFKL-TRAVEL-Host", "KL");
headers.add("X-Originating-IP", "46.193.67.48");
HttpEntity requestEntity = new HttpEntity(headers);
logger.debug("request entities are: " + requestEntity);
return restTemplate.getForObject(serviceURL, Json.class);
/*return restTemplate
.exchange(
serviceURL,
HttpMethod.GET,
requestEntity,
Json.class
);*/
}
}

Rest client data into Java object. Getting com.fasterxml.jackson.databind.exc.MismatchedInputException

I have a sample backend response coming as below:
When I try to map this response into the java object, I am getting following error.
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of com.mc.membersphere.model.MemberSummaryLabel[] out of START_OBJECT token
Seems like the issue with the body tag coming from API. Which has array of objects. I need help, how to handle this body tag arrays value in Java mapping?
Backend API Response:
{
"body": [{
"pcp": "KASSAM, Far",
"er12M": "0",
"ipAdmits12M": "0",
"ipReAdmits12M": "0",
"rx12M": "0",
"pastMedicalHistory": " ",
"erCost12M": "0.0"
}
]
}
Java Program to get the Rest data into the Java objects is as below.
import java.util.Collections;
import java.util.Properties;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import com.mc.membersphere.model.MemberSummaryLabel;
import com.mc.membersphere.utility.PropertyUtil;
public class TestRestclient implements CommandLineRunner{
public static void main(String[] args) {
SpringApplication.run(TestApi.class, args); }
private static Properties prop = PropertyUtil.getProperties();
#Override
public void run(String... args) throws Exception {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<String>(headers);
String getMVPSummaryUrl = prop.getProperty("getmvpmembersummary.url");
String url = getMVPSummaryUrl+"/"+"CA";
ResponseEntity<MemberSummaryLabel[]> response = restTemplate.exchange(url, HttpMethod.GET,entity, MemberSummaryLabel[].class);
if(response.getStatusCode()== HttpStatus.OK) {
for(MemberSummaryLabel memberSummaryLabel : response.getBody())
{
System.out.println(memberSummaryLabel.pcp);
}
//System.out.println("Print response" + response);
}
else {
System.out.println("Error");
}
}
}
MemberSummaryLabel is as below.
import com.fasterxml.jackson.annotation.JsonProperty;
public class MemberSummaryLabel {
#JsonProperty("pcp")
public String pcp;
#JsonProperty("er12M")
public Integer er12M;
#JsonProperty("ipAdmits12M")
public Integer ipAdmits12M;
#JsonProperty("ipReAdmits12M")
public Integer ipReAdmits12M;
#JsonProperty("rx12M")
public Integer rx12M;
#JsonProperty("pastMedicalHistory")
public String pastMedicalHistory;
#JsonProperty("erCost12M")
public Double erCost12M;
}
I see, its an issue with your mapping. Your response is in "body" and body contains list of MemberSummaryLabel. So, you need to have one more class as mentioned below,
public class Body{
#JsonProperty("body")
public List<MemberSummaryLabel> memberSummaryLabelList;
}
And your exchange method should return NewClass.
ResponseEntity<Body> response = restTemplate.exchange(url, HttpMethod.GET,entity, Body.class);
And for, iteration use,
for(MemberSummaryLabel memberSummaryLabel : response.getBody().getMemberSummaryLabelList()){
}

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.

Categories

Resources