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