View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.model.support;
14  
15  import javax.servlet.http.HttpServletRequest;
16  import javax.servlet.http.HttpServletResponse;
17  
18  import com.eviware.soapui.impl.wsdl.mock.DispatchException;
19  import com.eviware.soapui.model.mock.MockResult;
20  import com.eviware.soapui.model.mock.MockRunner;
21  
22  public abstract class AbstractMockRunner implements MockRunner
23  {
24  
25  	public MockResult dispatchGetRequest( HttpServletRequest request, HttpServletResponse response )
26  			throws DispatchException
27  	{
28  		throw new DispatchException( "Unsupported HTTP Method: GET" );
29  	}
30  
31  	public MockResult dispatchPostRequest( HttpServletRequest request, HttpServletResponse response )
32  			throws DispatchException
33  	{
34  		throw new DispatchException( "Unsupported HTTP Method: POST" );
35  	}
36  
37  	public MockResult dispatchHeadRequest( HttpServletRequest request, HttpServletResponse response )
38  			throws DispatchException
39  	{
40  		throw new DispatchException( "Unsupported HTTP Method: HEAD" );
41  	}
42  
43  	public MockResult dispatchPutRequest( HttpServletRequest request, HttpServletResponse response )
44  			throws DispatchException
45  	{
46  		throw new DispatchException( "Unsupported HTTP Method: PUT" );
47  	}
48  
49  	public MockResult dispatchDeleteRequest( HttpServletRequest request, HttpServletResponse response )
50  			throws DispatchException
51  	{
52  		throw new DispatchException( "Unsupported HTTP Method: DELETE" );
53  	}
54  
55  	public MockResult dispatchRequest( HttpServletRequest request, HttpServletResponse response )
56  			throws DispatchException
57  	{
58  		String method = request.getMethod();
59  
60  		if( method.equals( "POST" ) )
61  			return dispatchPostRequest( request, response );
62  		else if( method.equals( "GET" ) )
63  			return dispatchGetRequest( request, response );
64  		else if( method.equals( "HEAD" ) )
65  			return dispatchHeadRequest( request, response );
66  		else if( method.equals( "PUT" ) )
67  			return dispatchPutRequest( request, response );
68  		else if( method.equals( "DELETE" ) )
69  			return dispatchDeleteRequest( request, response );
70  
71  		throw new DispatchException( "Unsupported HTTP Method: " + method );
72  	}
73  }