在我们的REST服务之一的一些负载测试中,我们开始看到这几样的日志,用于Spring的REST模板当负载增加时:弹簧安置模板接受头
下一个并发负载和3-4小时后, http请求的Accept报头变得
DEBUG: org.springframework.web.client.RestTemplate - Setting request Accept header to [text/plain, application/json, application/*+json, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain, text/plain,<and so on>, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, */*, <and so on>]
最终所有的呼叫,使用RestTemplate开始400错误(错误的请求)未
被调用时的REST服务接受字符串作为输入,并具有以下这种服务签名
@RequestMapping(value = "/findRecordById", method = {RequestMethod.POST, RequestMethod.GET })
@ResponseBody
public String findRecordById(@RequestBody String id) {//method body}
我们发送POST类型的请求到这个服务,请求内容形式为“someId”,例如, “123”
在轻负载下,在调用服务时没有问题。
最让人费解的是text/plain,*/*,它们不断被添加到REST模板的接受标头列表中。为什么会发生?
其余模板bean声明是这样的:
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<constructor-arg>
<bean class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
<property name="readTimeout">
<value>90000</value>
</property>
<property name="httpClient" ref="restHttpClient" />
</bean>
</constructor-arg>
</bean>
<bean id="restHttpClient" class="org.apache.http.impl.client.DefaultHttpClient">
<constructor-arg>
<bean class="org.apache.http.impl.conn.PoolingClientConnectionManager">
<property name="defaultMaxPerRoute">
<value>100000</value>
</property>
<property name="maxTotal">
<value>100000</value>
</property>
</bean>
</constructor-arg>
</bean>
被如何创建请求:
String postParams = "\"" + id + "\"";
String postResp = restTemplate.postForObject("findRecordById",postParams, String.class);
请告诉我们您做用'RestTemplate'的请求的例子.. – 2014-11-05 02:16:03
编辑的问题来说明如何请求是 – 2014-11-05 03:04:04
所以你直接从'ApplicationContext'获得'restTemplate'而没有额外的修改?你发送像上面这么多的请求吗? – 2014-11-05 03:22:28