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 .










share|improve this question






















  • 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















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 .










share|improve this question






















  • 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













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 .










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 1:13









yangl

1061215




1061215












  • 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
















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)