cancel
Showing results for 
Search instead for 
Did you mean: 

How to communicate between sevlet and applet ?

zengqingyi12
Champ in-the-making
Champ in-the-making
Right now, I want to read a pdf from alfresco repository and then I can modify the pdf with applet, after that i will push back the modified document.
How can i  do to achieve this ?
9 REPLIES 9

mikeh
Star Contributor
Star Contributor
You'd need to POST the updated PDF back to the repository using the /api/upload webscript. http://localhost:8080/alfresco/service/script/org/alfresco/repository/upload/upload.post

Thanks,
Mike

zengqingyi12
Champ in-the-making
Champ in-the-making
but how can i retrieve a file ?
i use this code:
java.io.BufferedInputStream in = new java.io.BufferedInputStream(new

java.net.URL("http://localhost:8080/share/proxy/alfresco/api/node/content/workspace/SpacesStore/8063a1ad-b458-42f2...").openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream("d:/a.txt");
java.io.BufferedOutputStream bout = new java.io.BufferedOutputStream(fos,1024);
byte data[] = new byte[1024];
while((count = in.read(data,0,1024)) != 0)
{
bout.write(data,0,count);
}
bout.close();
//out.close();
in.close();


and want to retrieve a file, but it results at throw a exception,
what can i do to retrieve a file from Java code?

mrogers
Star Contributor
Star Contributor
Please post the exception, how are we to help without it?
Your URL looks suspicious in particular the 'share/proxy' part.
You probably need to worry about the character set as well.

zengqingyi12
Champ in-the-making
Champ in-the-making
The reason is that I can not get a session to download the code in java code.
what can i do to get a session ????

zengqingyi12
Champ in-the-making
Champ in-the-making
Right now i want to write a java application to download a file in alfresco:
let's say the file's path is :
http://localhost:8080/share/proxy/alfresco/api/node/content/workspace/SpacesStore/1c72a80b-b9d7-4b04...

I write this code to download that file:

       int count;
        // Authenticator.setDefault(new MyAuthenticator());
          try {

              java.net.URL url = new java.net.URL("http://localhost:8080/share/proxy/alfresco/api/node/content/workspace/SpacesStore/1c72a80b-b9d7-4b04...");

             //  String userPassword = "admin" + ":" + "mangocreativcde";
             //  String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());

//              URLConnection uc = url.openConnection();
//              uc.setRequestProperty ("Authorization", "Basic " + encoding);
//              uc.connect();
              java.io.BufferedInputStream in = new java.io.BufferedInputStream(url.openStream());
              java.io.FileOutputStream fos = new java.io.FileOutputStream("d:/a.jpg");
              java.io.BufferedOutputStream bout = new java.io.BufferedOutputStream(fos);
              byte data[] = new byte[1024];
              while ((count = in.read(data)) != -1) {
                  bout.write(data, 0, count);
              }
              bout.close();
//out.close();
              in.close();

          } catch (java.io.IOException e) {
              System.out.println(e.getMessage());
          }
But it throw such a exception:
Server returned HTTP response code: 401 for URL: http://localhost:8080/share/proxy/alfresco/api/node/content/workspace/SpacesStore/1c72a80b-b9d7-4b04...

I also use
AuthenticationUtils.startSession(USERNAME, PASSWORD);
to start a session, but it still doesn't work.
What can i do ?

mikeh
Star Contributor
Star Contributor
No need for a new topic here.

You need to get the document from the Repository, not via the Share proxy.

Change your URL to:
http://localhost:8080/alfresco/service/api/node/content/workspace/SpacesStore/1c72a80b-b9d7-4b04-bdb...

Thanks,
Mike

zengqingyi12
Champ in-the-making
Champ in-the-making
Thank you very much,it works.
Why it should use such a proxy to download the file in  alfresco share ?
What's the function is the proxy ?
thanks in advance.

mikeh
Star Contributor
Star Contributor
The Share proxy is used so that the Repository can be firewalled off and Share is the only public point of entry from a web client.

The proxy handles authentication sessions between Share and the Repository, renewing the auth ticket if required.

Thanks,
Mike

isloat
Champ in-the-making
Champ in-the-making