Coverage Report - org.mule.transport.sftp.SftpMessageRequester
 
Classes in this File Line Coverage Branch Coverage Complexity
SftpMessageRequester
0%
0/14
0%
0/2
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.transport.sftp;
 8  
 
 9  
 import org.mule.api.MuleMessage;
 10  
 import org.mule.api.endpoint.InboundEndpoint;
 11  
 import org.mule.transport.AbstractMessageRequester;
 12  
 import org.mule.transport.sftp.notification.SftpNotifier;
 13  
 
 14  
 import java.io.InputStream;
 15  
 
 16  
 /**
 17  
  * <code>SftpMessageRequester</code> polls files on request (e.g. from a
 18  
  * quartz-inbound-endpoint) from an sftp service on request using jsch. This
 19  
  * requester produces an InputStream payload, which can be materialized in a
 20  
  * MessageDispatcher or Component.
 21  
  */
 22  
 public class SftpMessageRequester extends AbstractMessageRequester
 23  
 {
 24  
 
 25  0
     private SftpReceiverRequesterUtil sftpRRUtil = null;
 26  
 
 27  
     public SftpMessageRequester(InboundEndpoint endpoint)
 28  
     {
 29  0
         super(endpoint);
 30  
 
 31  0
         sftpRRUtil = new SftpReceiverRequesterUtil(endpoint);
 32  
 
 33  0
     }
 34  
 
 35  
     @Override
 36  
     protected MuleMessage doRequest(long timeout) throws Exception
 37  
     {
 38  0
         String[] files = sftpRRUtil.getAvailableFiles(true);
 39  
 
 40  0
         if (files.length == 0) return null;
 41  
 
 42  0
         String path = files[0];
 43  
         // TODO. ML FIX. Can't we figure out the current service (for logging/audit
 44  
         // purpose)???
 45  0
         SftpNotifier notifier = new SftpNotifier((SftpConnector) connector, createNullMuleMessage(),
 46  
             endpoint, endpoint.getName());
 47  
 
 48  0
         InputStream inputStream = sftpRRUtil.retrieveFile(path, notifier);
 49  
 
 50  0
         logger.debug("Routing file: " + path);
 51  
 
 52  0
         MuleMessage message = createMuleMessage(inputStream);
 53  0
         message.setOutboundProperty(SftpConnector.PROPERTY_ORIGINAL_FILENAME, path);
 54  
 
 55  
         // Now we can update the notifier with the message
 56  0
         notifier.setMessage(message);
 57  0
         return message;
 58  
     }
 59  
 
 60  
 }