10-12-2010 10:43 AM
package com.download;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
public class DownloadAlfrescoFile {
public static void main(String[] args) {
Credentials creds = new UsernamePasswordCredentials("theadmin", "thepassword");
HttpClient httpClient = new HttpClient();
//httpClient.getParams().setAuthenticationPreemptive(true);
httpClient.getState().setCredentials(
new AuthScope(AuthScope.ANY_HOST, 8080, AuthScope.ANY_REALM), creds);
GetMethod getMethod = new GetMethod(
"http://alfresco:8080/alfresco/d/a/workspace/SpacesStore/86d4cf1a-1c66-4628-a934-e7a759556aec/Alfresc...");
getMethod.setDoAuthentication(true);
try {
// execute the GET
int status = httpClient.executeMethod(getMethod);
// print the status and response
System.out.println("get result:" + status);
InputStream instream = getMethod.getResponseBodyAsStream();
int l;
byte[] tmp = new byte[2048];
File tmpFile = new File("/tmp/Alfresco_user_guide.odt");
OutputStream os = new FileOutputStream(tmpFile);
while ((l = instream.read(tmp)) != -1) {
os.write(tmp, 0, l);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// release any connection resources used by the method
getMethod.releaseConnection();
}
}
}
httpClient.getParams().setAuthenticationPreemptive(true);10-14-2010 12:03 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.