Snippets

Jonathan Hult WebCenter Content - Execute GET_FILE within a ServiceHandler

Created by Jonathan Hult last modified
private static final String IDC_SERVICE = "IdcService";
private static final String FORCE_DOWNLOAD_STREAM_TO_FILE_PATH = "ForceDownloadStreamToFilepath";
private static final String GET_FILE = "GET_FILE";
private static final String D_ID = "dID";

public FileService executeFileService(final DataBinder serviceBinder, final Service m_service) throws DataException, ServiceException {
    final String serviceName = serviceBinder.getLocal(IDC_SERVICE);
    final ServiceData serviceData = ServiceManager.getFullService(serviceName);
    final FileService service = (FileService) ServiceManager.createService(serviceData.m_classID, m_service.getWorkspace(), m_service.getOutput(), serviceBinder, serviceData);
    service.setConditionVar(FORCE_DOWNLOAD_STREAM_TO_FILE_PATH, true);
    service.initDelegatedObjects();
    m_service.getRequestImplementor().doRequestInternalEx(service, m_service.getUserData(), false);
    return service;
}

public void runGetFile() {
    DataBinder serviceBinder = new DataBinder();
    serviceBinder.putLocal(IDC_SERVICE, GET_FILE);
    serviceBinder.putlocal(D_ID, "923415");
    executeFileService(serviceBinder, m_service);

    final DataStreamWrapper streamWrapper = m_service.getDownloadStream(false);
    final String filePath = streamWrapper.m_filePath;

    // Do whatever we want with the file

    // Remove this zip file after we exit this service (this assumes we did what we wanted with the file above)
    m_binder.m_tempFiles.remove(zipFilePath);
}

Comments (1)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.