【发布时间】:2013-06-24 13:48:47
【问题描述】:
在 Spring 3.2 上尝试使用 RestTemplate 发布对象时,我的平均响应时间为 8 秒
使用卷曲
time curl -X POST -H "Content-Type: application/xml" -T request.xml https://x.y.com:20000/rest
平均时间约为 4 秒。我不明白为什么。
我的配置:
<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>x.y.z.Request</value>
<value>x.y.z.Response</value>
<value>x.y.z.AnotherRequest</value>
<value>x.y.z.AnotherResponse</value>
</list>
</property>
</bean>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"
scope="prototype">
<constructor-arg>
<bean
class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
<property name="readTimeout" value="${application.urlReadTimeout}" />
<property name="connectTimeout" value="${application.urlConnectionTimeout}" />
</bean>
</constructor-arg>
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="jaxb2Marshaller" />
<property name="unmarshaller" ref="jaxb2Marshaller" />
</bean>
<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean
class="org.springframework.http.converter.StringHttpMessageConverter" />
</list>
</property>
</bean>
然后我简单地自动装配它:
@Autowired
RestTemplate restTemplate;
public Response getXml(Request request){
Response response = restTemplate.postForObject(httpUrl,request, Response.class);
}
P.S:作为替代方案,我尝试使用 JaxB 解析请求/响应对象并使用 org.apache.http.client.HttpClient 发送它,平均时间约为 7 秒,这远非好。
【问题讨论】:
-
request.xml 的实际大小是多少?
-
@ZagorulkinDmitry,大约 1000 个字符长。
标签: java spring web-services rest