You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2006/05/20 15:16:57 UTC
svn commit: r407994 -
/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/util/BeanShellClient.java
Author: sebb
Date: Sat May 20 06:16:57 2006
New Revision: 407994
URL: http://svn.apache.org/viewvc?rev=407994&view=rev
Log:
BeanShell client for sending scripts to the server
Added:
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/util/BeanShellClient.java (with props)
Added: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/util/BeanShellClient.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/util/BeanShellClient.java?rev=407994&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/util/BeanShellClient.java (added)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/util/BeanShellClient.java Sat May 20 06:16:57 2006
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2003-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.util;
+
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.Socket;
+
+
+/**
+ * Implements a client that can talk to the JMeter BeanShell server.
+ */
+public class BeanShellClient {
+
+ private static final int MINARGS = 3;
+
+ public static void main(String [] args) throws Exception{
+ if (args.length < MINARGS){
+ System.out.println("Please provide "+MINARGS+" or more arguments:");
+ System.out.println("serverhost serverport filename [arg1 arg2 ...]");
+ System.out.println("e.g. ");
+ System.out.println("localhost 9000 extras/remote.bsh apple blake 7");
+ System.exit(1);
+ }
+ String host=args[0];
+ String portString = args[1];
+ String file=args[2];
+
+ int port=Integer.parseInt(portString)+1;// convert to telnet port
+
+ System.out.println("Connecting to BSH server on "+host+":"+portString);
+
+ Socket sock = new Socket(host,port);
+ InputStream is = sock.getInputStream();
+
+ OutputStream os = sock.getOutputStream();
+
+ InputStreamReader fis = new FileReader(file);
+
+ new SockRead(is).start();
+
+ sendLine("String [] args={",os);
+ for (int i=MINARGS; i<args.length;i++){
+ sendLine("\""+args[i]+"\",\n",os);
+ }
+ sendLine("};",os);
+
+ int b;
+ while ((b=fis.read()) != -1){
+ os.write(b);
+ }
+ os.flush();
+ sock.shutdownOutput(); // Tell server that we are done
+ }
+
+ private static void sendLine( String line, OutputStream outPipe )
+ throws IOException
+ {
+ outPipe.write( line.getBytes() );
+ outPipe.flush();
+ }
+
+ private static class SockRead extends Thread {
+
+ private final InputStream is;
+
+ public SockRead(InputStream _is) {
+ this.is=_is;
+ //this.setDaemon(true);
+ }
+
+ public void run(){
+ System.out.println("Reading responses from server ...");
+ int x = 0;
+ try {
+ while ((x = is.read()) > -1) {
+ char c = (char) x;
+ System.out.print(c);
+ }
+ } catch (IOException e) {
+ } finally {
+ System.out.println("... disconnected from server.");
+ try {
+ is.close();
+ } catch (IOException e) {
+ }
+ }
+
+ }
+
+ }
+}
Propchange: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/util/BeanShellClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/util/BeanShellClient.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision
Propchange: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/util/BeanShellClient.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org