Coverage Report - org.apache.camel.component.file.remote.SftpEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
SftpEndpoint
10% 
N/A 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.component.file.remote;
 19  
 
 20  
 import com.jcraft.jsch.ChannelSftp;
 21  
 import com.jcraft.jsch.JSch;
 22  
 import com.jcraft.jsch.JSchException;
 23  
 import com.jcraft.jsch.Session;
 24  
 import com.jcraft.jsch.UserInfo;
 25  
 import org.apache.camel.Processor;
 26  
 
 27  0
 public class SftpEndpoint extends RemoteFileEndpoint<RemoteFileExchange> {
 28  
     public SftpEndpoint(String uri, RemoteFileComponent remoteFileComponent, RemoteFileConfiguration configuration) {
 29  3
         super(uri, remoteFileComponent, configuration);
 30  3
     }
 31  
 
 32  
     public SftpProducer createProducer() throws Exception {
 33  0
         return new SftpProducer(this, createChannelSftp());
 34  
     }
 35  
 
 36  
     public SftpConsumer createConsumer(Processor processor) throws Exception {
 37  0
         final SftpConsumer consumer = new SftpConsumer(this, processor, createChannelSftp());
 38  0
         configureConsumer(consumer);
 39  0
         return consumer;
 40  
     }
 41  
 
 42  
     protected ChannelSftp createChannelSftp() throws JSchException {
 43  0
         final JSch jsch = new JSch();
 44  0
         final Session session = jsch.getSession(getConfiguration().getUsername(), getConfiguration().getHost());
 45  
         // TODO there's got to be a better way to deal with accepting new hosts...
 46  0
         session.setUserInfo(new UserInfo() {
 47  
             public String getPassphrase() {
 48  0
                 return null;
 49  
             }
 50  
 
 51  
             public String getPassword() {
 52  0
                 return SftpEndpoint.this.getConfiguration().getPassword();
 53  
             }
 54  
 
 55  
             public boolean promptPassword(String string) {
 56  0
                 return true;
 57  
             }
 58  
 
 59  
             public boolean promptPassphrase(String string) {
 60  0
                 return true;
 61  
             }
 62  
 
 63  
             public boolean promptYesNo(String string) {
 64  0
                 return true;
 65  
             }
 66  
 
 67  0
             public void showMessage(String string) {
 68  0
             }
 69  
         });
 70  0
         session.connect();
 71  0
         final ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
 72  0
         channel.connect();
 73  0
         return channel;
 74  
     }
 75  
 }