1 17 package org.apache.activemq.console; 18 19 import org.apache.activemq.broker.util.CommandHandler; 20 import org.apache.activemq.console.command.ShellCommand; 21 import org.apache.activemq.console.formatter.GlobalWriter; 22 import org.apache.activemq.console.formatter.CommandShellOutputFormatter; 23 24 import javax.jms.TextMessage ; 25 import java.util.List ; 26 import java.util.ArrayList ; 27 import java.util.StringTokenizer ; 28 import java.io.ByteArrayOutputStream ; 29 30 35 public class ConsoleCommandHandler implements CommandHandler { 36 37 private ShellCommand command = new ShellCommand(true); 38 39 public void processCommand(TextMessage request, TextMessage response) throws Exception { 40 41 ByteArrayOutputStream out = new ByteArrayOutputStream (); 42 GlobalWriter.instantiate(new CommandShellOutputFormatter(out)); 43 44 String requestText = request.getText(); 46 47 List tokens = tokenize(requestText); 48 command.execute(tokens); 49 50 out.flush(); 51 byte[] bytes = out.toByteArray(); 52 53 String answer = new String (bytes); 54 55 response.setText(answer); 56 } 57 58 protected List tokenize(String text) { 59 List answer = new ArrayList (); 60 StringTokenizer iter = new StringTokenizer (text); 61 while (iter.hasMoreTokens()) { 62 answer.add(iter.nextToken()); 63 } 64 return answer; 65 } 66 } 67 | Popular Tags |