09-30-2009 04:52 AM
09-30-2009 09:39 AM
09-30-2009 10:40 AM
private void authenticateUser() {
client = new HttpClient();
// Add authentication preferences as Basic
List authPrefs = new ArrayList(2);
authPrefs.add(AuthPolicy.BASIC);
String userName="admin";
String password="admin";
String host="localhost";
String port="8080";
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
authPrefs);
// Use preemptive authentication
Credentials defaultcreds = new UsernamePasswordCredentials(userName,
password);
// set credentials
client.getState().setCredentials(
new AuthScope(host, Integer.parseInt(port)), defaultcreds);
}
private void postMethod(HttpServletRequest request,HttpServletResponse response) {
String filePath=request.getParameter("filePath");
System.out.println("File Path: "+filePath);
authenticateUser();
String url = "http://localhost:8080/alfresco/service/api/upload";
NameValuePair[] data = {new NameValuePair("filename", filePath),
new NameValuePair("mimetype", "pdf"),
new NameValuePair("containerId", "7018a7e3-d366-4389-84c6-bd79d793c270")}; //Company Homes' Id
postMethodUpload(url,data);
}
public void postMethodUpload(String url, NameValuePair[] data) {
PostMethod post = new PostMethod(url);
post.setRequestBody(data);
try {
int statusCode = client.executeMethod(post);
System.out.println(statusCode);
if(statusCode==401)
{
System.out.println("Getting Exception……………");
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
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.