Friday, December 6, 2013

Alfresco Share webscript Connection timeout


Recently We faced HTTP connection timeout issue in Alfresco share webscript while calling repository webscrtipt.
This timeout occurs for several reasons like high load on server or custom logical operation on huge amount of data so alfresco explorer takes too much time to respond etc.
So sometimes you might need to change this timeout parameters used by Share remote client. Here I will describe how we can change them.

Initially, this parameters was hard coded, now you can set them through configuration in newer version of alfresco.
Connection timeout default value is 10s.

Need to follow below steps

Step 1:
Locate spring-webscript-application-context.xml. This settings are defined in this file.

This file is in spring-webscripts-1.2.0-SNAPSHOT.jar [tomcat\webapps\alfresco\WEB-INF\lib] and go to org/springframework/extensions/webscripts/.

Step 2:
Search for "connector.remoteclient.abstract" and copy entire bean definition.

<bean id="connector.remoteclient.abstract" abstract="true">
<!-- name of authentication ticket that can be optionally applied to proxied URLs -->
<!-- the ticket value is set programmatically by the connector making use of the RemoteClient instance -->
<property name="ticketName"><value>alf_ticket</value></property>
<!-- default encoding to use when decoded responses when none is set in the response - set to null for platform default -->
<property name="defaultEncoding"><null/></property>
<!-- default Content-Type header value to use for PUT or POST responses when none is supplied -->
<property name="defaultContentType"><value>application/octet-stream</value></property>
<!-- size of the internal byte buffer used when proxying responses -->
<property name="bufferSize"><value>4096</value></property>
<!-- the http.connection.timeout value in milliseconds to apply to HTTP connections -->
<property name="connectTimeout"><value>15000</value></property>
<!-- the http.socket.timeout value in milliseconds to apply to HTTP connections -->
<property name="readTimeout"><value>120000</value></property>
<!-- the maximum number of redirects to process from a GET request while maintaining cookies -->
<property name="maxRedirects"><value>10</value></property>
<!-- the RemoteClient will automatically use an HTTP proxy if the JVM property 'http.proxyHost' is set
but this feature can be disabled by setting this bean property to false -->
<property name="allowHttpProxy"><value>true</value></property>
<!-- the RemoteClient will automatically use an HTTPS proxy if the JVM property 'https.proxyHost' is set
but this feature can be disabled by setting this bean property to false -->
<property name="allowHttpsProxy"><value>true</value></property>
<!-- the set of headers to remove when proxying a request from a client to a remote endpoint -->
<property name="removeRequestHeaders">
<set>
<value>Cookie</value>
</set>
</property>
<!-- the set of headers to remove when proxying a response from a remote endpoint to a client -->
<property name="removeResponseHeaders">
<set>
<value>Set-Cookie</value>
</set>
</property>
<!-- http.tcp.nodelay setting - default is true -->
<property name="httpTcpNodelay"><value>true</value></property>
<!-- http.connection.stalecheck setting - default is true -->
<property name="httpConnectionStalecheck"><value>true</value></property>
</bean>

Step 3:
Go to tomcat\shared\classes\alfresco\web-extension and create custom-slingshot-application-context.xml if you don't have else modify this file.

Copy remoteclient bean defination into this and update "connectTimeout" value as per your requirement.

Step 4:
Restart server and verify.

You can increase logs to debug if any issue.
log4j.logger.org.springframework.extensions.webscripts.connector.RemoteClient=debug

NOTE: This might affect your system performance. So till possible rectify your code which is causing this issue.

Alfresco version: 4.2

Hope this helps!

1 comment: