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