1

I have a little problem with the MuleSoft CMIS connector. I have an application that uploads and downloads files from Alfresco. I connect to Alfresco through AtomPub and use CMIS for all actions towards the Alfresco.

The problem is this: I used to get the object from the repository and it worked fine. In my flow I added one component that takes the object from the flow, which is of type DocumentImpl, get InputStream, cast it to an Object and return it. The browser starts the download of the file but it has no idea what the file is because it has no extension attached to it.

And finally the question: How do I attach the extension to the file being downloaded?

EDIT some code added

@Override public Object onCall(MuleEventContext eventContext) throws Exception {

    MuleMessage mes = eventContext.getMessage();
    System.out.println("Message is :" +mes);

    DocumentImpl doc = mes.getPayload(DocumentImpl.class);

    HttpResponse res = new HttpResponse();
    InputStream a = doc.getContentStream().getStream();
    String m = doc.getContentStreamMimeType();
    String n = doc.getContentStreamFileName();

    res.setBody(mes);


    return a;
}
Loshmeey
  • 341
  • 1
  • 5
  • 18
  • 1
    Just thinking out loud here...if you get the mime-type using `DocumentImpl.getContentStreamMimeType()` and then use that value to set the response to the browser before you start to stream it back? ie `response.setContentType('your-mime-type')` – billerby Jan 30 '13 at 19:54
  • Yep i was thinking the same thing, but i just can not implement it! I keep going around and around and i can not seem to find the solution, and there must be one! – Loshmeey Jan 31 '13 at 09:03
  • Could you show us some code? – billerby Jan 31 '13 at 09:50
  • So i added the code.. it is pretty simple and probably missing the one little thing that i cannot find! Thanks for your responses! – Loshmeey Jan 31 '13 at 11:12
  • Well as far as I know you must set the contentType in the response header, something like this: `String mimeType = doc.getContentStreamMimeType(); String filename = doc.getContentStreamFileName(); response.setContentType( mimeType ); response.setHeader( "Content-Disposition", "attachment;filename=" + filename );` Anyway you are not using the response so this will have no effect at all. I have not worked with Mule so I am not familiar with how those things are configured :( – billerby Jan 31 '13 at 15:42
  • No problems, thank you for your answers very much! When you say response, you mean http response right? – Loshmeey Jan 31 '13 at 15:44
  • Yes, thats correct. How is your flow defined? – billerby Feb 01 '13 at 07:50

1 Answers1

1

Ok i solved the problem. Basically the best way to do this is to change the flow to this:

    <set-payload value ="#[payload.getContentStream()]" />

    <set-variable value="#[payload.getMimeType()]" variableName="mime" doc:name="Variable" />
    <set-variable value="#[payload.getFileName()]" variableName="name" doc:name="Variable" />

    <!-- Set Content-Type to stored mimetype -->        
    <set-property value="#[flowVars['mime']]" propertyName="Content-Type" />
    <set-property propertyName="File-Name" value="#[flowVars['name']]"/>
    <set-property value="attachment; filename=#[flowVars['name']]" propertyName="Content-Disposition" />

this should be in the Mule Flow after

This takes mime type and file name from the payload and returns it!

Loshmeey
  • 341
  • 1
  • 5
  • 18