Tuesday, July 21, 2009

HttpClient uploading large files

When using HTTPClient to upload large files I was getting the following exception:

org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: socket write error
org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: Retrying request
java.lang.Exception: Unbuffered entity enclosing request can not be repeated.

I had the following code:

PutMethod method = new PutMethod(url + "/" + file.getName());
RequestEntity requestEntity = new InputStreamRequestEntity(new FileInputStream(file));
method.setRequestEntity(requestEntity);
client.executeMethod(method);

I replaced the code as follows:

String filename = url + "/" + file.getName();
PutMethod method = new PutMethod(filename);
method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
Part[] parts = { new FilePart(file.getName(), file) };
method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
client.executeMethod(method);

In my case I am uploading (PUTMETHOD) to a WebDAV folder. But I noticed that this issue is happening for other protocols too.
Basically using MultiPart and setting the parameter USE_EXPECT_CONTINUE to true solved the problem.
The problem is due to the authentication. When the post has a big file it opens the transfer multiple times. And I guess the socket will be closed or not authenticated when there is the second transfer.

Monday, July 20, 2009

Find empty tables in SQL Server 2005

To find all the empty tables in your SQL Server 2005 you can use the following query:

SELECT o.name, sum(s.row_count)
FROM sys.objects o
JOIN sys.dm_db_partition_stats s
ON o.object_id=s.object_id
WHERE o.type='U'
GROUP BY o.name
HAVING sum(s.row_count) = 0
ORDER BY sum(s.row_count) desc

where 'U' stands for User Table

Just in case one wants to find out if a table is used in stored procedures, triggers and so on... one can use the following SQL:

SELECT o.name,o.xtype,m.definition
FROM sys.sql_modules m
INNER JOIN sysobjects o ON m.object_id=o.id
WHERE [definition] LIKE '%TABLE_NAME%'

Thursday, July 16, 2009

WebDAV problems

If you have problems with WebDAV this is a great link to troubleshoot WebDAV problems

Wednesday, July 15, 2009

Problem with AspectJ and Eclipse using maven

Having problems with AspectJ dependencies missing in the generated Eclipse .classpath file (mvn eclipse:eclipse) . The solution is to set:
ajdtVersion to "none"
Here is how to set it in the POM file:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<ajdtVersion>none</ajdtVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>org.thirdparty</groupId>
<artifactId>jar-containing-external-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
<weaveDependencies>
<weaveDependency>
<groupId>org.mycompany</groupId>
<artifactId>jar-to-weave-with-aspects-in-this-library</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
</plugin>