|
16 | 16 | import cz.abclinuxu.datoveschranky.common.entities.Message;
|
17 | 17 | import cz.abclinuxu.datoveschranky.common.entities.MessageEnvelope;
|
18 | 18 | import cz.abclinuxu.datoveschranky.common.entities.content.FileContent;
|
| 19 | +import cz.abclinuxu.datoveschranky.common.interfaces.AttachmentStorer; |
19 | 20 |
|
20 | 21 | /**
|
21 | 22 | * Created by jludvice on 17.2.17.
|
@@ -56,25 +57,9 @@ protected int poll() throws Exception {
|
56 | 57 | exchange.getIn().setHeaders(getMessageHeaders(env));
|
57 | 58 |
|
58 | 59 | if (endpoint.isZfo()) {
|
59 |
| - log.info("Downloading message {} in binary pkcs signed zfo stream.", env.getMessageID()); |
60 |
| - // download data to this output stream |
61 |
| - OutputStream os = new ByteArrayOutputStream(); |
62 |
| - endpoint.getDataBoxManager().getDataBoxDownloadService().downloadSignedMessage(env, os); |
63 |
| - exchange.getIn().setBody(os); |
64 |
| - // assume saving exchange to file and by default fill proper filename header |
65 |
| - exchange.getIn().setHeader(Exchange.FILE_NAME, env.getMessageID() + ".zfo"); |
| 60 | + downloadZFO(exchange, env, endpoint); |
66 | 61 | } else {
|
67 |
| - log.info("Downloading message {} in unmarshalled Message instance.", env.getMessageID()); |
68 |
| - Message m = endpoint.getDataBoxManager() |
69 |
| - .getDataBoxDownloadService() |
70 |
| - .downloadMessage(env, storer); |
71 |
| - exchange.getIn().setBody(m); |
72 |
| - // map attachments to camel |
73 |
| - for (Attachment a : m.getAttachments()) { |
74 |
| - // get attachment file and create data handler from it |
75 |
| - FileContent fc = (FileContent) a.getContent(); |
76 |
| - exchange.getIn().addAttachment(a.getDescription(), createDataHandler(fc.getFile())); |
77 |
| - } |
| 62 | + downloadMessage(exchange, env, endpoint, storer); |
78 | 63 | }
|
79 | 64 |
|
80 | 65 | if (endpoint.isMarkDownloaded()) {
|
@@ -103,4 +88,36 @@ public void onComplete(Exchange exchange) {
|
103 | 88 | // number of messages polled
|
104 | 89 | return envelopes.size();
|
105 | 90 | }
|
| 91 | + |
| 92 | + static void downloadMessage(Exchange exchange, MessageEnvelope env, ISDSEndpoint endpoint, AttachmentStorer storer) { |
| 93 | + log.info("Downloading message {} in unmarshalled Message instance.", env.getMessageID()); |
| 94 | + Message m = endpoint.getDataBoxManager() |
| 95 | + .getDataBoxDownloadService() |
| 96 | + .downloadMessage(env, storer); |
| 97 | + |
| 98 | + exchange.getIn().setBody(m); |
| 99 | + // map attachments to camel |
| 100 | + for (Attachment a : m.getAttachments()) { |
| 101 | + // get attachment file and create data handler from it |
| 102 | + FileContent fc = (FileContent) a.getContent(); |
| 103 | + exchange.getIn().addAttachment(a.getDescription(), createDataHandler(fc.getFile())); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Download message in zfo format and store it as OutputStream in Exchange body and set Camel file name header. |
| 109 | + * |
| 110 | + * @param exchange store message to exchange body |
| 111 | + * @param env envelope of requested message |
| 112 | + * @param endpoint endpoint providing databox manager instance |
| 113 | + */ |
| 114 | + static void downloadZFO(Exchange exchange, MessageEnvelope env, ISDSEndpoint endpoint) { |
| 115 | + log.info("Downloading message {} in binary pkcs signed zfo stream.", env.getMessageID()); |
| 116 | + // download data to this output stream |
| 117 | + OutputStream os = new ByteArrayOutputStream(); |
| 118 | + endpoint.getDataBoxManager().getDataBoxDownloadService().downloadSignedMessage(env, os); |
| 119 | + exchange.getIn().setBody(os); |
| 120 | + // assume saving exchange to file and by default fill proper filename header |
| 121 | + exchange.getIn().setHeader(Exchange.FILE_NAME, env.getMessageID() + ".zfo"); |
| 122 | + } |
106 | 123 | }
|
0 commit comments