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