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);
Content from pre 2016 and from language groups that have been closed.
Content is read-only.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.