Problem:Can’t realize updating of a file from the APPLET. QUESTION 1:How I can look at examples? Like this http://localhost:8080/alfresco/service/api/uploadI don't know as to look at examples to which references of this kind refer because they are absent. I have received on demand a tooling Alfresco_SDK_Extentsion_Example_1..3.zip, but there these examples aren't present. QUESTION 2:What parameters format I should use for REST API http://localhost:8080/alfresco/service/api/upload in my request. At realization of function of updating of a file I have faced that there is no due, clear description REST API for this functionality. Despite a seeming considerable quantity of the information, by more detailed consideration absence of the necessary information on this question is found out. this my code, but this don't work. I get right ticket but I can't automatic authorization ( I get popup window for enter login and password ).And next server response to my applet error with code = 500. Any ideas? public class MyApplet extends Applet //implements ActionListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
public void start(){
getUrl();
String response = authorization("admin","123");
String ticket = getTicket( response );
uploadDocs( ticket );
}
private String getTicket(String authResp){
System.out.println(authResp);
int indxLast=authResp.lastIndexOf('"');
String strTic = "TICKET";
int indxFirst=authResp.lastIndexOf('_')+1;
String strTicket = authResp.substring(indxFirst,indxLast);
System.out.println(strTicket);
return strTicket;
}
public String uploadDocs( String ticket ){
String urlString= "http://localhost:8080/alfresco/service/api/upload";
String fileId = "413f2b83-6fa3-454e-bc01-82473225e2e5";
URL url;
HttpURLConnection connection = null;
try
{
String urlParameters = "{ \"ticket\" : \""+ticket+"\", \"protocol\" : \"workspace\", \"upload-id\" : \"" + fileId +"\", \"man_assigned_id\" : \"myFistCont\" }";
url = new URL(urlString);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
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);
// Send request
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.writeBytes("My content");
wr.flush();
wr.close();
// Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while ((line = rd.readLine()) != null)
{
response.append(line);
response.append('\r');
}
rd.close();
String _jsonResponse = response.toString();
System.out.println(_jsonResponse);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
finally
{
if (connection != null)
{
connection.disconnect();
}
}
return "";
}
public String authorization(String _userName, String _password)
{
URL url;
HttpURLConnection connection = null;
String _jsonResponse;
try
{
String urlParameters = "{ \"username\" : \"" + _userName +"\", \"password\" : \"" + _password +"\" }";
url = new URL("http://localhost:8080/alfresco/service/api/login");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
// Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while ((line = rd.readLine()) != null)
{
response.append(line);
response.append('\r');
}
rd.close();
_jsonResponse = response.toString();
System.out.println(_jsonResponse);
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
finally
{
if (connection != null)
{
connection.disconnect();
}
}
return _jsonResponse;
}
private String getTicket(String authResp){
System.out.println(authResp);
int indxLast=authResp.lastIndexOf('"');
String strTic = "TICKET";
int indxFirst=authResp.lastIndexOf('_')+1;
String strTicket = authResp.substring(indxFirst,indxLast);
System.out.println(strTicket);
return strTicket;
}
}