Coverage Report - org.apache.xbean.terminal.telnet.TelnetShell
 
Classes in this File Line Coverage Branch Coverage Complexity
TelnetShell
0%
0/22
0%
0/8
2.667
 
 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.xbean.terminal.telnet;
 18  
 
 19  
 import java.io.IOException;
 20  
 import java.io.InputStream;
 21  
 import java.io.OutputStream;
 22  
 import java.io.PrintStream;
 23  
 import java.net.Socket;
 24  
 
 25  
 import org.apache.xbean.command.CommandShell;
 26  
 
 27  
 public class TelnetShell {
 28  
 
 29  
     private final String serverName;
 30  
 
 31  0
     public TelnetShell(String serverName) {
 32  0
         this.serverName = serverName;
 33  0
     }
 34  
 
 35  
     public void service(Socket socket) throws IOException {
 36  
 
 37  
         try {
 38  0
             service(socket.getInputStream(), socket.getOutputStream());
 39  0
         } catch (IOException e) {
 40  0
             e.printStackTrace();
 41  
         } finally {
 42  0
             if (socket != null) socket.close();
 43  
         }
 44  0
     }
 45  
 
 46  
     public void service(InputStream in, OutputStream out) throws IOException {
 47  0
         InputStream telnetIn = null;
 48  0
         PrintStream telnetOut = null;
 49  
         try {
 50  0
             telnetIn = new TelnetInputStream(in, out);
 51  0
             telnetOut = new TelnetPrintStream(out);
 52  
 
 53  0
             telnetOut.println(serverName + " Console");
 54  0
             telnetOut.println("type \'help\' for a list of commands");
 55  
 
 56  
             // TODO:1: Login
 57  
             //...need a security service first
 58  
 
 59  0
             CommandShell shell = new CommandShell(serverName);
 60  0
             shell.main(new String[]{}, telnetIn, telnetOut);
 61  
 
 62  0
         } catch (Throwable t) {
 63  
             // TODO: log this
 64  
         } finally {
 65  0
             if (telnetIn != null){
 66  0
                 telnetIn.close();
 67  
             }
 68  0
             if (telnetOut != null) {
 69  0
                 telnetOut.close();
 70  
             }
 71  
         }
 72  0
     }
 73  
 }