05-09-2012 02:58 AM
String _userName = username;
String _password = password;
String _firstName = fristname;
String _lastName = lastname;
String _mail = mail;
String _disableAccount = "false";
String _quota = "-1";
String urlParameters = "{ \"username\" : \"" + _userName +"\", \"password\" : \"" + _password +"\"" +
",\"firstName\" : \"" + _firstName +"\", \"lastName\" : \"" + _lastName +"\"" +
",\"email\" : " + _mail +
",\"disableAccount\" : false , \"quota\" : -1 ,\"groups\":[] }";
//System.out.println("——-> " + urlParameters);
// {"userName":"jack","password":"1111","firstName":"jack","lastName":"den","email":"test@test.net","disableAccount":false,"quota":-1,"groups":[]};
//urlParameters ="{\"username\":\"jack\",\"password\":\"jack\",\"firstName\":\"jack\",\"lastName\":\"jack\",\"email\":jack@jack.it,\"disableAccount\":false,\"quota\":-1,\"groups\":[]};";
int _resultCode = 0;
String _userNameLogin = "admin";
String _passwordLogin = "admin";
URL url;
HttpURLConnection connection = null;
try
{
//JSON che verrà inviato alla post per la login
//String urlParameters = "{ \"username\" : \"" + _userName +"\", \"password\" : \"" + _password +"\" }";
// Apri la connessione
url = new URL("http://localhost:8080/alfresco/service/api/people");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
//Imposto autenticazione
BASE64Encoder enc = new sun.misc.BASE64Encoder();
String userpassword = _userNameLogin + ":" + _passwordLogin;
String encodedAuthorization = enc.encode( userpassword.getBytes() );
connection.setRequestProperty("Authorization", "Basic "+ encodedAuthorization);
// String ticket = this.autorizathionUser(_userNameLogin, _passwordLogin);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
// connection.setRequestProperty("ticket", ticket);
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
// Invia la richiesta
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
// OutputStreamWriter osw = new OutputStreamWriter(connection.getOutputStream());
// osw.write(urlParameters);
// osw.close();
connection.connect();
_resultCode = connection.getResponseCode();
}
catch (Exception e)
{
e.printStackTrace();
return _resultCode;
}
finally
{
if (connection != null)
{
connection.disconnect();
}
}
return _resultCode;
}
05-21-2012 08:57 AM
10-09-2012 06:52 AM
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.