why spring boot webservice response count is not match with request count
up vote
0
down vote
favorite
I finish a simple spring boot webservice , here is the controller 's code
package com.example.ly.FirstWebService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RestController
public class HelloController {
Logger logger = LoggerFactory.getLogger(HelloController.class);
@RequestMapping("/")
public String index() {
//logger.trace("This is a TRACE message.");
//logger.debug("This is a DEBUG message.");
//logger.info("This is an INFO message.");
//logger.warn("This is a WARN message.");
//logger.error("You guessed it, an ERROR message.");
return "Greetings from Spring Boot!";
}
@RequestMapping(value = { "/ocs_new" })
@ResponseBody
public Map<String, Object> getRoute(@RequestParam("sid") String id,@RequestParam("calling") String calling,@RequestParam("called") String called,@RequestParam("trunk_in") String trunk_in) {
logger.info("ocs_new command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("duration", 120);
Map<String,Object> map1 = new HashMap<String,Object>();
map1.put("nap","nap256");
map1.put("src","60133878300");
map1.put("dst","800113803088900");
Map<String,Object> map2 = new HashMap<String,Object>();
map2.put("nap","nap369");
map2.put("src","60133878399");
map2.put("dst","800213803088999");
List<Map> jsonObjects = new ArrayList<Map>();
jsonObjects.add(map1);
jsonObjects.add(map2);
mRet.put("routetable",jsonObjects);
mRet.put("next_update_time", 120);
mRet.put("cmd", "ocs_new");
mRet.put("sid", id);
mRet.put("result", 0);
mRet.put("msg", null);
return mRet;
}
@RequestMapping(value = { "/ocs_start" })
@ResponseBody
public Map<String, Object> callstart(@RequestParam("sid") String id,@RequestParam("a_setup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_setup_time,@RequestParam("a_connect_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_connect_time,@RequestParam("b_setup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_setup_time,@RequestParam("b_connect_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_connect_time,@RequestParam("connected_trunk") String connected_trunk) {
logger.info("ocs_start command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("cmd", "ocs_start");
mRet.put("result", 0);
mRet.put("sid", id);
mRet.put("msg", "queued for processing");
return mRet;
}
@RequestMapping(value = { "/ocs_end" })
@ResponseBody
public Map<String, Object> callend(@RequestParam("sid") String id,@RequestParam("duration_a") int duration_a,@RequestParam("duration_b") int duration_b,@RequestParam("a_hangup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_hangup_time,@RequestParam("b_hangup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_hangup_time) {
logger.info("ocs_end command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("cmd", "ocs_end");
mRet.put("result", 0);
mRet.put("sid", id);
mRet.put("msg", "queued for processing");
return mRet;
}
}
for client side , I use a c# program which use multi thread to send http request to server , because I log every request when it income
logger.info("ocs_new command income with sid ." + id);
the response count should be same with request count , but I find sometimes response is greater than request . say if I send 5000 requests , maybe response count is 5003 .
Does any problem with my controller?
I also log request count in client side when it send to server , I am sure client send exactly 5000 request .
web-services spring-boot
add a comment |
up vote
0
down vote
favorite
I finish a simple spring boot webservice , here is the controller 's code
package com.example.ly.FirstWebService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RestController
public class HelloController {
Logger logger = LoggerFactory.getLogger(HelloController.class);
@RequestMapping("/")
public String index() {
//logger.trace("This is a TRACE message.");
//logger.debug("This is a DEBUG message.");
//logger.info("This is an INFO message.");
//logger.warn("This is a WARN message.");
//logger.error("You guessed it, an ERROR message.");
return "Greetings from Spring Boot!";
}
@RequestMapping(value = { "/ocs_new" })
@ResponseBody
public Map<String, Object> getRoute(@RequestParam("sid") String id,@RequestParam("calling") String calling,@RequestParam("called") String called,@RequestParam("trunk_in") String trunk_in) {
logger.info("ocs_new command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("duration", 120);
Map<String,Object> map1 = new HashMap<String,Object>();
map1.put("nap","nap256");
map1.put("src","60133878300");
map1.put("dst","800113803088900");
Map<String,Object> map2 = new HashMap<String,Object>();
map2.put("nap","nap369");
map2.put("src","60133878399");
map2.put("dst","800213803088999");
List<Map> jsonObjects = new ArrayList<Map>();
jsonObjects.add(map1);
jsonObjects.add(map2);
mRet.put("routetable",jsonObjects);
mRet.put("next_update_time", 120);
mRet.put("cmd", "ocs_new");
mRet.put("sid", id);
mRet.put("result", 0);
mRet.put("msg", null);
return mRet;
}
@RequestMapping(value = { "/ocs_start" })
@ResponseBody
public Map<String, Object> callstart(@RequestParam("sid") String id,@RequestParam("a_setup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_setup_time,@RequestParam("a_connect_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_connect_time,@RequestParam("b_setup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_setup_time,@RequestParam("b_connect_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_connect_time,@RequestParam("connected_trunk") String connected_trunk) {
logger.info("ocs_start command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("cmd", "ocs_start");
mRet.put("result", 0);
mRet.put("sid", id);
mRet.put("msg", "queued for processing");
return mRet;
}
@RequestMapping(value = { "/ocs_end" })
@ResponseBody
public Map<String, Object> callend(@RequestParam("sid") String id,@RequestParam("duration_a") int duration_a,@RequestParam("duration_b") int duration_b,@RequestParam("a_hangup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_hangup_time,@RequestParam("b_hangup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_hangup_time) {
logger.info("ocs_end command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("cmd", "ocs_end");
mRet.put("result", 0);
mRet.put("sid", id);
mRet.put("msg", "queued for processing");
return mRet;
}
}
for client side , I use a c# program which use multi thread to send http request to server , because I log every request when it income
logger.info("ocs_new command income with sid ." + id);
the response count should be same with request count , but I find sometimes response is greater than request . say if I send 5000 requests , maybe response count is 5003 .
Does any problem with my controller?
I also log request count in client side when it send to server , I am sure client send exactly 5000 request .
web-services spring-boot
You are counting the requests and responses at the client side (in your C++ program)? You might like to check and ensure that the counting logic is capable of handling multithreaded logic. And secondly, you can write a custom Spring MVC HandlerInterceptor and do the counting in thepostHandle
method there. Do ensure that the counting code should be fully capable of handling multi-threaded logic. More information regarding this here - baeldung.com/spring-mvc-handlerinterceptor .
– Arun Patra
Nov 11 at 3:14
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I finish a simple spring boot webservice , here is the controller 's code
package com.example.ly.FirstWebService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RestController
public class HelloController {
Logger logger = LoggerFactory.getLogger(HelloController.class);
@RequestMapping("/")
public String index() {
//logger.trace("This is a TRACE message.");
//logger.debug("This is a DEBUG message.");
//logger.info("This is an INFO message.");
//logger.warn("This is a WARN message.");
//logger.error("You guessed it, an ERROR message.");
return "Greetings from Spring Boot!";
}
@RequestMapping(value = { "/ocs_new" })
@ResponseBody
public Map<String, Object> getRoute(@RequestParam("sid") String id,@RequestParam("calling") String calling,@RequestParam("called") String called,@RequestParam("trunk_in") String trunk_in) {
logger.info("ocs_new command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("duration", 120);
Map<String,Object> map1 = new HashMap<String,Object>();
map1.put("nap","nap256");
map1.put("src","60133878300");
map1.put("dst","800113803088900");
Map<String,Object> map2 = new HashMap<String,Object>();
map2.put("nap","nap369");
map2.put("src","60133878399");
map2.put("dst","800213803088999");
List<Map> jsonObjects = new ArrayList<Map>();
jsonObjects.add(map1);
jsonObjects.add(map2);
mRet.put("routetable",jsonObjects);
mRet.put("next_update_time", 120);
mRet.put("cmd", "ocs_new");
mRet.put("sid", id);
mRet.put("result", 0);
mRet.put("msg", null);
return mRet;
}
@RequestMapping(value = { "/ocs_start" })
@ResponseBody
public Map<String, Object> callstart(@RequestParam("sid") String id,@RequestParam("a_setup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_setup_time,@RequestParam("a_connect_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_connect_time,@RequestParam("b_setup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_setup_time,@RequestParam("b_connect_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_connect_time,@RequestParam("connected_trunk") String connected_trunk) {
logger.info("ocs_start command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("cmd", "ocs_start");
mRet.put("result", 0);
mRet.put("sid", id);
mRet.put("msg", "queued for processing");
return mRet;
}
@RequestMapping(value = { "/ocs_end" })
@ResponseBody
public Map<String, Object> callend(@RequestParam("sid") String id,@RequestParam("duration_a") int duration_a,@RequestParam("duration_b") int duration_b,@RequestParam("a_hangup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_hangup_time,@RequestParam("b_hangup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_hangup_time) {
logger.info("ocs_end command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("cmd", "ocs_end");
mRet.put("result", 0);
mRet.put("sid", id);
mRet.put("msg", "queued for processing");
return mRet;
}
}
for client side , I use a c# program which use multi thread to send http request to server , because I log every request when it income
logger.info("ocs_new command income with sid ." + id);
the response count should be same with request count , but I find sometimes response is greater than request . say if I send 5000 requests , maybe response count is 5003 .
Does any problem with my controller?
I also log request count in client side when it send to server , I am sure client send exactly 5000 request .
web-services spring-boot
I finish a simple spring boot webservice , here is the controller 's code
package com.example.ly.FirstWebService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RestController
public class HelloController {
Logger logger = LoggerFactory.getLogger(HelloController.class);
@RequestMapping("/")
public String index() {
//logger.trace("This is a TRACE message.");
//logger.debug("This is a DEBUG message.");
//logger.info("This is an INFO message.");
//logger.warn("This is a WARN message.");
//logger.error("You guessed it, an ERROR message.");
return "Greetings from Spring Boot!";
}
@RequestMapping(value = { "/ocs_new" })
@ResponseBody
public Map<String, Object> getRoute(@RequestParam("sid") String id,@RequestParam("calling") String calling,@RequestParam("called") String called,@RequestParam("trunk_in") String trunk_in) {
logger.info("ocs_new command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("duration", 120);
Map<String,Object> map1 = new HashMap<String,Object>();
map1.put("nap","nap256");
map1.put("src","60133878300");
map1.put("dst","800113803088900");
Map<String,Object> map2 = new HashMap<String,Object>();
map2.put("nap","nap369");
map2.put("src","60133878399");
map2.put("dst","800213803088999");
List<Map> jsonObjects = new ArrayList<Map>();
jsonObjects.add(map1);
jsonObjects.add(map2);
mRet.put("routetable",jsonObjects);
mRet.put("next_update_time", 120);
mRet.put("cmd", "ocs_new");
mRet.put("sid", id);
mRet.put("result", 0);
mRet.put("msg", null);
return mRet;
}
@RequestMapping(value = { "/ocs_start" })
@ResponseBody
public Map<String, Object> callstart(@RequestParam("sid") String id,@RequestParam("a_setup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_setup_time,@RequestParam("a_connect_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_connect_time,@RequestParam("b_setup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_setup_time,@RequestParam("b_connect_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_connect_time,@RequestParam("connected_trunk") String connected_trunk) {
logger.info("ocs_start command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("cmd", "ocs_start");
mRet.put("result", 0);
mRet.put("sid", id);
mRet.put("msg", "queued for processing");
return mRet;
}
@RequestMapping(value = { "/ocs_end" })
@ResponseBody
public Map<String, Object> callend(@RequestParam("sid") String id,@RequestParam("duration_a") int duration_a,@RequestParam("duration_b") int duration_b,@RequestParam("a_hangup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime a_hangup_time,@RequestParam("b_hangup_time") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime b_hangup_time) {
logger.info("ocs_end command income with sid ." + id);
Map<String, Object> mRet = new HashMap<String, Object>();
mRet.put("cmd", "ocs_end");
mRet.put("result", 0);
mRet.put("sid", id);
mRet.put("msg", "queued for processing");
return mRet;
}
}
for client side , I use a c# program which use multi thread to send http request to server , because I log every request when it income
logger.info("ocs_new command income with sid ." + id);
the response count should be same with request count , but I find sometimes response is greater than request . say if I send 5000 requests , maybe response count is 5003 .
Does any problem with my controller?
I also log request count in client side when it send to server , I am sure client send exactly 5000 request .
web-services spring-boot
web-services spring-boot
asked Nov 11 at 1:13
yangl
1031215
1031215
You are counting the requests and responses at the client side (in your C++ program)? You might like to check and ensure that the counting logic is capable of handling multithreaded logic. And secondly, you can write a custom Spring MVC HandlerInterceptor and do the counting in thepostHandle
method there. Do ensure that the counting code should be fully capable of handling multi-threaded logic. More information regarding this here - baeldung.com/spring-mvc-handlerinterceptor .
– Arun Patra
Nov 11 at 3:14
add a comment |
You are counting the requests and responses at the client side (in your C++ program)? You might like to check and ensure that the counting logic is capable of handling multithreaded logic. And secondly, you can write a custom Spring MVC HandlerInterceptor and do the counting in thepostHandle
method there. Do ensure that the counting code should be fully capable of handling multi-threaded logic. More information regarding this here - baeldung.com/spring-mvc-handlerinterceptor .
– Arun Patra
Nov 11 at 3:14
You are counting the requests and responses at the client side (in your C++ program)? You might like to check and ensure that the counting logic is capable of handling multithreaded logic. And secondly, you can write a custom Spring MVC HandlerInterceptor and do the counting in the
postHandle
method there. Do ensure that the counting code should be fully capable of handling multi-threaded logic. More information regarding this here - baeldung.com/spring-mvc-handlerinterceptor .– Arun Patra
Nov 11 at 3:14
You are counting the requests and responses at the client side (in your C++ program)? You might like to check and ensure that the counting logic is capable of handling multithreaded logic. And secondly, you can write a custom Spring MVC HandlerInterceptor and do the counting in the
postHandle
method there. Do ensure that the counting code should be fully capable of handling multi-threaded logic. More information regarding this here - baeldung.com/spring-mvc-handlerinterceptor .– Arun Patra
Nov 11 at 3:14
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244982%2fwhy-spring-boot-webservice-response-count-is-not-match-with-request-count%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You are counting the requests and responses at the client side (in your C++ program)? You might like to check and ensure that the counting logic is capable of handling multithreaded logic. And secondly, you can write a custom Spring MVC HandlerInterceptor and do the counting in the
postHandle
method there. Do ensure that the counting code should be fully capable of handling multi-threaded logic. More information regarding this here - baeldung.com/spring-mvc-handlerinterceptor .– Arun Patra
Nov 11 at 3:14