View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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.submit.filters;
14  
15  import com.eviware.soapui.impl.wsdl.WsdlRequest;
16  import com.eviware.soapui.impl.wsdl.submit.RequestFilter;
17  import com.eviware.soapui.model.iface.SubmitContext;
18  
19  /***
20   * RequestFilter that expands scripts in request content - not used for now, we need to fix validations first
21   * 
22   * @author Ole.Matzura
23   */
24  
25  public class ScriptExpansionRequestFilter implements RequestFilter
26  {
27  	public void filterRequest(SubmitContext context, WsdlRequest wsdlRequest)
28  	{
29  	/*	String content = (String) context.getProperty( BaseHttpRequestTransport.REQUEST_CONTENT );
30  	
31  		content = expandScripts(context, content);
32  		if( content != null )
33  			context.setProperty( BaseHttpRequestTransport.REQUEST_CONTENT, content );
34  			*/
35  	}
36  
37  	public static String expandScripts(SubmitContext context, String content)
38  	{
39  		return content;
40  		
41  		/*try
42  		{
43  			XmlObject obj = XmlObject.Factory.parse(content);
44  			XmlCursor cursor = obj.newCursor();
45  			boolean replaced = false;
46  			
47  			while (!cursor.isEnddoc())
48  			{
49  				Node node = cursor.getDomNode();
50  				if ( node.getNodeType() == Node.ELEMENT_NODE)
51  				{
52  					if( node.getNamespaceURI().equals( "http://www.soapui.org/wsp" ) && node.getNodeName().equals( "script"))
53  					{
54  						GroovyShell shell = ScriptingSupport.createGroovyShell( null );
55  						String type = ((Element)node).getAttribute( "type" );
56  						String result = shell.evaluate( cursor.getTextValue() ).toString();
57  						
58  						if( type == null || type.length() == 0 || type.equals( "content"))
59  						{
60  							cursor.removeXml();
61  							cursor.insertChars( result );
62  						}
63  						else if( type.equals( "markup" ))
64  						{
65  							Node parent = node.getParentNode();
66  							XmlOptions options = new XmlOptions();
67  							Map map = new HashMap();
68  							cursor.getAllNamespaces( map );
69  							
70  							StringBuffer buf = new StringBuffer();
71  							buf.append( "<result" );
72  							
73  							for( Iterator i = map.keySet().iterator(); i.hasNext(); )
74  							{
75  								buf.append( " xmlns" );
76  								String next = (String) i.next();
77  								if( next.length() > 0 )
78  									buf.append( ':' ).append( next);
79  
80  								buf.append( "=\"" ).append( map.get( next )).append( "\"" );
81  							}
82  							
83  							buf.append( ">" ).append( result ).append( "</result>" );
84  							result = buf.toString();
85  							
86  							XmlObject newObj = XmlObject.Factory.parse( result );
87  							Element docElm = ((Document)newObj.getDomNode()).getDocumentElement();
88  							
89  							parent.replaceChild( parent.getOwnerDocument().importNode( docElm.getFirstChild(), true ), node );
90  						}
91  						
92  						replaced = true;
93  					}
94  				}
95  
96  				cursor.toNextToken();
97  			}
98  			
99  			return replaced ? obj.toString() : null;
100 		}
101 		catch (Exception e)
102 		{
103 			UISupport.logError( e );
104 			return null;
105 		}		*/
106 	}
107 }