Thursday, September 20, 2012

Get File from UCM using RIDC client

import oracle.stellent.ridc.convenience.adf.connection.AdfConnectionFacade;
import oracle.stellent.ridc.IdcClient;
import oracle.stellent.ridc.IdcClientException;
import oracle.stellent.ridc.IdcClientManager;
import oracle.stellent.ridc.IdcContext;
import oracle.stellent.ridc.model.DataBinder;
import oracle.stellent.ridc.protocol.ServiceResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import oracle.adf.share.logging.ADFLogger;

private static ADFLogger log= ADFLogger.createADFLogger(getFile.class);

public void getFile(FacesContext context,OutputStream outputStream) {

   try {
        IdcClientManager manager = new IdcClientManager();                    
        AdfConnectionFacade facade = new AdfConnectionFacade("UcmConnection");
        IdcClient idcClient = facade.getIdcClient();
                           
        IdcContext userContext;
                            
        if(adfCtx.getSessionScope().get("IdcContext")==null) {
           userContext = new IdcContext(facade.getUserCredentials("user"));
           adfCtx.getSessionScope().put("IdcContext",userContext);
          }
        else {
           userContext=(IdcContext)adfCtx.getSessionScope().get("IdcContext");
        }
        DataBinder dataBinder = idcClient.createBinder();   
        dataBinder.putLocal("IdcService", "GET_FILE");        
        dataBinder.putLocal("dID",docID);        
            
        responseString =idcClient.sendRequest(userContext, dataBinder);             
        InputStream  inputStream = responseString.getResponseStream();  

        byte[] buf = new byte[1024 * 256];
        long i = 0;
        int len;

        log.severe("Downloading File from UCM Server"); 

        while (true) {
                i++;
                len = inputStream.read(buf);
                if (len == -1) {
                    break;
               }
             outputStream.write(buf, 0, len);
            }
             outputStream.flush(); 
             inputStream.close();
             outputStream.close();
             context.responseComplete();
        } catch (IdcClientException ice) {
                 log.severe("IDC Client Exception occured. Exception message: " + ice.getMessage());
        } catch (IOException ioe) {
                 log.severe("IO Exception occurred. Unable to retrieve file. Message: " + ioe.getMessage()); 
        } catch (Exception ex) {
                 log.severe("Exception message: " + ex.getMessage() );
        }               
    }
}

7 comments:

  1. how to get file content Type while downloading?

    ReplyDelete
    Replies
    1. You can try following code snippet:

      responseString =idcClient.sendRequest(userContext, dataBinder);
      String contentType = responseString.getHeader("Content-Type");
      InputStream inputStream = responseString.getResponseStream();

      Rgds,
      W!nkle

      Delete
  2. how to download multiple files from server?

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi,i am trying to upload a file to UCM ,all file types and of different size are getting uploaded except doc or docx file type having size less than 100kb more than 100kb are getting successfully uploaded.Pls can anyone suggest me the solution for it.
    Thanks

    ReplyDelete
  5. Why do you want to disable select on the blog?

    ReplyDelete

Provide your thoughts !