AnsweredAssumed Answered

Get the URL of a folder or document

Question asked by chicco0386 on Sep 21, 2010
Hi all,
I'm looking how to retrive the URL of a folder or content.

I'm try with this peace of code
public static String getDownloadUrl(Reference reference) {
        ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
        String url = "";
        try {
            Content[] contents = contentService.read(new Predicate(new Reference[] { reference }, reference.getStore(), null), Constants.PROP_CONTENT);
            if (contents.length > 0) {
                if (log.isDebugEnabled()) {
                    log.debug("getDownloadUrl, trovati [" + contents.length + "] documento/i");
                }
                url = contents[0].getUrl();
                log.info("getDownloadUrl, url in uscita ["+url+"]");
                url = ContentUtils.getContentAsString(contents[0]);
                log.info("getDownloadUrl, url in uscita ["+url+"]");
            }
        } catch (ContentFault e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        log.info("getDownloadUrl, url in uscita ["+url+"]");
        return url;

    }

but the first:
url = contents[0].getUrl();
                log.info("getDownloadUrl, url in uscita ["+url+"]");
return null.

And the second method:
url = ContentUtils.getContentAsString(contents[0]);
                log.info("getDownloadUrl, url in uscita ["+url+"]");

give me this exception:
2010-09-21 11:50:17,462 ERROR [STDERR] org.alfresco.webservice.util.WebServiceException: Unable to get content as string.
2010-09-21 11:50:17,462 ERROR [STDERR]     at org.alfresco.webservice.util.ContentUtils.getContentAsString(ContentUtils.java:104)
2010-09-21 11:50:17,462 ERROR [STDERR]     at it.mytria.soa.esb.alfresco.utils.RepositoryUtils.getDownloadUrl(RepositoryUtils.java:75)
2010-09-21 11:50:17,462 ERROR [STDERR]     at it.mytria.soa.esb.alfresco.utils.RepositoryUtils.createContent(RepositoryUtils.java:226)
2010-09-21 11:50:17,462 ERROR [STDERR]     at it.mytria.soa.esb.alfresco.action.InsertContentAction.insertMail(InsertContentAction.java:116)
2010-09-21 11:50:17,478 ERROR [STDERR]     at it.mytria.soa.esb.alfresco.action.InsertContentAction.process(InsertContentAction.java:60)
2010-09-21 11:50:17,478 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2010-09-21 11:50:17,478 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
2010-09-21 11:50:17,478 ERROR [STDERR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
2010-09-21 11:50:17,478 ERROR [STDERR]     at java.lang.reflect.Method.invoke(Method.java:597)
2010-09-21 11:50:17,478 ERROR [STDERR]     at org.jboss.soa.esb.listeners.message.ActionProcessorMethodInfo.processMethods(ActionProcessorMethodInfo.java:102)
2010-09-21 11:50:17,493 ERROR [STDERR]     at org.jboss.soa.esb.listeners.message.OverriddenActionLifecycleProcessor.process(OverriddenActionLifecycleProcessor.java:74)
2010-09-21 11:50:17,493 ERROR [STDERR]     at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.processPipeline(ActionProcessingPipeline.java:520)
2010-09-21 11:50:17,493 ERROR [STDERR]     at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.process(ActionProcessingPipeline.java:392)
2010-09-21 11:50:17,493 ERROR [STDERR]     at org.jboss.soa.esb.listeners.message.MessageAwareListener$TransactionalRunner.run(MessageAwareListener.java:538)
2010-09-21 11:50:17,493 ERROR [STDERR]     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
2010-09-21 11:50:17,493 ERROR [STDERR]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
2010-09-21 11:50:17,509 ERROR [STDERR]     at java.lang.Thread.run(Thread.java:619)
2010-09-21 11:50:17,509 ERROR [STDERR] Caused by: java.net.MalformedURLException: no protocol: null?ticket=TICKET_c0522b4859797df9c0183c3fe82e2115b64fc0fa
2010-09-21 11:50:17,509 ERROR [STDERR]     at java.net.URL.<init>(URL.java:567)
2010-09-21 11:50:17,509 ERROR [STDERR]     at java.net.URL.<init>(URL.java:464)
2010-09-21 11:50:17,509 ERROR [STDERR]     at java.net.URL.<init>(URL.java:413)
2010-09-21 11:50:17,509 ERROR [STDERR]     at org.alfresco.webservice.util.ContentUtils.getContentAsString(ContentUtils.java:84)
2010-09-21 11:50:17,509 ERROR [STDERR]     … 16 more


PLEASE, CAN YOU HELP ME?

THANK YOU

Outcomes