As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
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(); } }