001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.submit.filters;
014:
015: import com.eviware.soapui.impl.wsdl.WsdlRequest;
016: import com.eviware.soapui.impl.wsdl.submit.RequestFilter;
017: import com.eviware.soapui.model.iface.SubmitContext;
018:
019: /**
020: * RequestFilter that expands scripts in request content - not used for now, we need to fix validations first
021: *
022: * @author Ole.Matzura
023: */
024:
025: public class ScriptExpansionRequestFilter implements RequestFilter {
026: public void filterRequest(SubmitContext context,
027: WsdlRequest wsdlRequest) {
028: /* String content = (String) context.getProperty( BaseHttpRequestTransport.REQUEST_CONTENT );
029:
030: content = expandScripts(context, content);
031: if( content != null )
032: context.setProperty( BaseHttpRequestTransport.REQUEST_CONTENT, content );
033: */
034: }
035:
036: public static String expandScripts(SubmitContext context,
037: String content) {
038: return content;
039:
040: /*try
041: {
042: XmlObject obj = XmlObject.Factory.parse(content);
043: XmlCursor cursor = obj.newCursor();
044: boolean replaced = false;
045:
046: while (!cursor.isEnddoc())
047: {
048: Node node = cursor.getDomNode();
049: if ( node.getNodeType() == Node.ELEMENT_NODE)
050: {
051: if( node.getNamespaceURI().equals( "http://www.soapui.org/wsp" ) && node.getNodeName().equals( "script"))
052: {
053: GroovyShell shell = ScriptingSupport.createGroovyShell( null );
054: String type = ((Element)node).getAttribute( "type" );
055: String result = shell.evaluate( cursor.getTextValue() ).toString();
056:
057: if( type == null || type.length() == 0 || type.equals( "content"))
058: {
059: cursor.removeXml();
060: cursor.insertChars( result );
061: }
062: else if( type.equals( "markup" ))
063: {
064: Node parent = node.getParentNode();
065: XmlOptions options = new XmlOptions();
066: Map map = new HashMap();
067: cursor.getAllNamespaces( map );
068:
069: StringBuffer buf = new StringBuffer();
070: buf.append( "<result" );
071:
072: for( Iterator i = map.keySet().iterator(); i.hasNext(); )
073: {
074: buf.append( " xmlns" );
075: String next = (String) i.next();
076: if( next.length() > 0 )
077: buf.append( ':' ).append( next);
078:
079: buf.append( "=\"" ).append( map.get( next )).append( "\"" );
080: }
081:
082: buf.append( ">" ).append( result ).append( "</result>" );
083: result = buf.toString();
084:
085: XmlObject newObj = XmlObject.Factory.parse( result );
086: Element docElm = ((Document)newObj.getDomNode()).getDocumentElement();
087:
088: parent.replaceChild( parent.getOwnerDocument().importNode( docElm.getFirstChild(), true ), node );
089: }
090:
091: replaced = true;
092: }
093: }
094:
095: cursor.toNextToken();
096: }
097:
098: return replaced ? obj.toString() : null;
099: }
100: catch (Exception e)
101: {
102: UISupport.logError( e );
103: return null;
104: } */
105: }
106: }
|