View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.monitor;
14  
15  import org.mortbay.jetty.bio.SocketConnector;
16  import org.mortbay.jetty.servlet.Context;
17  import org.mortbay.jetty.servlet.ServletHolder;
18  
19  import com.eviware.soapui.impl.wsdl.monitor.jettyproxy.ProxyServlet;
20  import com.eviware.soapui.impl.wsdl.monitor.jettyproxy.Server;
21  import com.eviware.soapui.support.UISupport;
22  
23  public class SoapMonitorEngineImpl implements SoapMonitorEngine {
24  
25  	Server server = new Server();
26  	SocketConnector connector = new SocketConnector();
27  
28  	public boolean isRunning() {
29  		return server.isRunning();
30  	}
31  
32  	public void start(SoapMonitor soapMonitor, int localPort) {
33  		
34  		connector.setPort(localPort);
35  		server.addConnector(connector);
36  		Context context = new Context(server, "/", 0);
37  		context.addServlet(new ServletHolder(new ProxyServlet(soapMonitor)), "/");
38  		
39  			try
40  			{
41  				server.start();
42  			}
43  			catch (Exception e)
44  			{
45  				UISupport.showErrorMessage("Error starting monitor: " + e.getMessage());
46  			}
47  
48  	}
49  
50  	public void stop() {
51  		
52  		try {
53  			if( server != null ) {
54  				server.stop();
55  			}
56  		} catch (Exception e) {
57  			e.printStackTrace();
58  		} finally {
59  			if ( server != null ) { 
60  				server.destroy();
61  			}
62  		}
63  
64  	}
65  
66  }