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;
14  
15  import com.eviware.soapui.SoapUI;
16  import com.eviware.soapui.config.*;
17  import com.eviware.soapui.impl.WsdlInterfaceFactory;
18  import com.eviware.soapui.impl.support.AbstractHttpRequest;
19  import com.eviware.soapui.impl.support.AbstractInterface;
20  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
21  import com.eviware.soapui.impl.wsdl.support.PathUtils;
22  import com.eviware.soapui.impl.wsdl.support.soap.SoapMessageBuilder;
23  import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
24  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
25  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlLoader;
26  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils;
27  import com.eviware.soapui.impl.wsdl.teststeps.BeanPathPropertySupport;
28  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
29  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
30  import com.eviware.soapui.model.ModelItem;
31  import com.eviware.soapui.model.iface.Operation;
32  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils;
33  import com.eviware.soapui.settings.WsaSettings;
34  import com.eviware.soapui.settings.WsdlSettings;
35  import com.eviware.soapui.support.StringUtils;
36  import com.eviware.soapui.support.UISupport;
37  import com.eviware.soapui.support.resolver.ResolveContext;
38  import com.eviware.soapui.support.types.StringList;
39  import org.apache.log4j.Logger;
40  import org.w3.x2007.x05.addressing.metadata.AddressingDocument.Addressing;
41  import org.w3.x2007.x05.addressing.metadata.AnonymousResponsesDocument.AnonymousResponses;
42  import org.w3.x2007.x05.addressing.metadata.NonAnonymousResponsesDocument.NonAnonymousResponses;
43  import org.xmlsoap.schemas.ws.x2004.x09.policy.Policy;
44  
45  import javax.wsdl.*;
46  import javax.xml.namespace.QName;
47  import java.io.File;
48  import java.net.MalformedURLException;
49  import java.util.*;
50  
51  /***
52   * WSDL implementation of Interface, maps to a WSDL Binding
53   *
54   * @author Ole.Matzura
55   */
56  
57  public class WsdlInterface extends AbstractInterface<WsdlInterfaceConfig>
58  {
59     public static final String STYLE_DOCUMENT = "Document";
60     public static final String STYLE_RPC = "RPC";
61  
62     public static final String JBOSSWS_ACTIONS = "jbossws";
63     public static final String WSTOOLS_ACTIONS = "wstools";
64     public static final String XML_ACTIONS = "xml";
65  
66     private final static Logger log = Logger.getLogger( WsdlInterface.class );
67     private List<WsdlOperation> operations = new ArrayList<WsdlOperation>();
68     private WsdlProject project;
69     private SoapMessageBuilder soapMessageBuilder;
70     private WsdlContext wsdlContext;
71     private boolean updating = false;
72     private BeanPathPropertySupport definitionProperty;
73  
74     public WsdlInterface( WsdlProject project, WsdlInterfaceConfig interfaceConfig )
75     {
76        super( interfaceConfig, project, "/interface2.gif" );
77  
78        if( !interfaceConfig.isSetWsaVersion() )
79           interfaceConfig.setWsaVersion( WsaVersionTypeConfig.NONE );
80  
81        this.project = project;
82  
83        List<OperationConfig> operationConfigs = interfaceConfig.getOperationList();
84        for( int i = 0; i < operationConfigs.size(); i++ )
85        {
86           operations.add( new WsdlOperation( this, operationConfigs.get( i ) ) );
87        }
88  
89        definitionProperty = new BeanPathPropertySupport( this, "definition" );
90     }
91  
92     public WsdlOperation getOperationAt( int index )
93     {
94        return operations.get( index );
95     }
96  
97     public int getOperationCount()
98     {
99        return operations.size();
100    }
101 
102    public WsdlOperation addNewOperation( BindingOperation operation )
103    {
104       WsdlOperation operationImpl = new WsdlOperation( this, getConfig().addNewOperation() );
105       operations.add( operationImpl );
106 
107       operationImpl.initFromBindingOperation( operation );
108       fireOperationAdded( operationImpl );
109       return operationImpl;
110    }
111 
112    public WsdlProject getProject()
113    {
114       return project;
115    }
116 
117    public void setDefinition( String wsdlUrl ) throws Exception
118    {
119       setDefinition( wsdlUrl, true );
120    }
121 
122    public void setDefinition( String wsdlUrl, boolean updateCache ) throws Exception
123    {
124       String old = definitionProperty.set( wsdlUrl, false );
125 
126       if( wsdlContext != null )
127       {
128          wsdlContext.setDefinition( definitionProperty.expandUrl(), updateCache );
129       }
130 
131       notifyPropertyChanged( DEFINITION_PROPERTY, old, wsdlUrl );
132       notifyPropertyChanged( UPDATING_PROPERTY, true, false );
133    }
134 
135    public DefinitionCacheConfig cacheDefinition( WsdlLoader loader ) throws Throwable
136    {
137       log.debug( "Caching definition for [" + loader.getBaseURI() + "]" );
138       if( getConfig().isSetDefinitionCache() )
139          getConfig().unsetDefinitionCache();
140 
141       DefinitionCacheConfig definitionCache = null;
142       try
143       {
144          definitionCache = getConfig().addNewDefinitionCache();
145          definitionCache.set( WsdlUtils.cacheWsdl( loader ) );
146       }
147       catch( Throwable e )
148       {
149          getConfig().unsetDefinitionCache();
150          throw e;
151       }
152 
153       return definitionCache;
154    }
155 
156    public String getDefinition()
157    {
158       if( !getConfig().isSetDefinition() )
159          return null;
160 
161       String result = definitionProperty.get();
162 
163       if( PathUtils.isFilePath( result ) && !PathUtils.isRelativePath( result ) && !result.startsWith( "file:" )
164               && !result.startsWith( "$" ) )
165       {
166          try
167          {
168             result = new File( result ).toURI().toURL().toString();
169          }
170          catch( MalformedURLException e )
171          {
172             e.printStackTrace();
173          }
174       }
175 
176       return result;
177    }
178 
179    public String getType()
180    {
181       return WsdlInterfaceFactory.WSDL_TYPE;
182    }
183 
184    public boolean isDefinitionShareble()
185    {
186       return true;
187    }
188 
189    public synchronized WsdlContext getWsdlContext()
190    {
191       if( wsdlContext == null )
192       {
193          wsdlContext = new WsdlContext( PathUtils.expandPath( getDefinition(), this ), this );
194       }
195 
196       return wsdlContext;
197    }
198 
199    /***
200     * Used by importer so we dont need to reload the context after importing..
201     *
202     * @param wsdlContext
203     */
204 
205    public void setWsdlContext( WsdlContext wsdlContext )
206    {
207       this.wsdlContext = wsdlContext;
208       this.wsdlContext.setInterface( this );
209 
210       if( soapMessageBuilder != null )
211          soapMessageBuilder.setWsdlContext( wsdlContext );
212    }
213 
214    public SoapMessageBuilder getMessageBuilder()
215    {
216       if( soapMessageBuilder == null )
217       {
218          try
219          {
220             soapMessageBuilder = new SoapMessageBuilder( this );
221          }
222          catch( Exception e )
223          {
224             SoapUI.logError( e );
225          }
226       }
227       return soapMessageBuilder;
228    }
229 
230    public void setSoapMessageBuilder( SoapMessageBuilder builder )
231    {
232       soapMessageBuilder = builder;
233       soapMessageBuilder.setInterface( this );
234    }
235 
236    public QName getBindingName()
237    {
238       return getConfig().getBindingName() == null ? null : QName.valueOf( getConfig().getBindingName() );
239    }
240 
241    public void setBindingName( QName name )
242    {
243       getConfig().setBindingName( name.toString() );
244    }
245 
246    public SoapVersion getSoapVersion()
247    {
248       if( getConfig().getSoapVersion() == SoapVersionTypesConfig.X_1_2 )
249          return SoapVersion.Soap12;
250 
251       return SoapVersion.Soap11;
252    }
253 
254    public void setSoapVersion( SoapVersion version )
255    {
256       if( version == SoapVersion.Soap11 )
257          getConfig().setSoapVersion( SoapVersionTypesConfig.X_1_1 );
258       else if( version == SoapVersion.Soap12 )
259          getConfig().setSoapVersion( SoapVersionTypesConfig.X_1_2 );
260       else
261          throw new RuntimeException( "Unknown soapVersion [" + version + "], must be 1.1 or 1.2" );
262    }
263 
264    public boolean updateDefinition( String url, boolean createRequests ) throws Exception
265    {
266       WsdlContext.uncache( url );
267 
268       WsdlContext newContext = new WsdlContext( url, (WsdlInterface) null );
269       if( !newContext.load() )
270       {
271          return false;
272       }
273 
274       BindingTuple tuple = findBinding( newContext );
275       if( tuple == null )
276          return false;
277 
278       setBindingName( tuple.binding.getQName() );
279 
280       // update name
281       if( getSettings().getBoolean( WsdlSettings.NAME_WITH_BINDING ) )
282          setName( tuple.binding.getQName().getLocalPart() );
283 
284       // update context
285       setWsdlContext( newContext );
286 
287       transferOperations( tuple.binding, createRequests );
288 
289       setDefinition( url, false );
290 
291       transferEndpoints( tuple.port );
292 
293       getProject().fireInterfaceUpdated( this );
294 
295       return true;
296    }
297 
298    public BindingTuple prepareUpdateDefinition( String url ) throws Exception
299    {
300       WsdlContext newContext = new WsdlContext( url, (WsdlInterface) null );
301       if( !newContext.load() )
302       {
303          return null;
304       }
305 
306       BindingTuple tuple = findBinding( newContext );
307       return tuple;
308    }
309 
310    public void updateDefinition( BindingTuple tuple ) throws Exception
311    {
312       setBindingName( tuple.binding.getQName() );
313 
314       if( getConfig().isSetDefinitionCache() )
315          getConfig().unsetDefinitionCache();
316 
317       // update name
318       if( getSettings().getBoolean( WsdlSettings.NAME_WITH_BINDING ) )
319          setName( tuple.binding.getQName().getLocalPart() );
320 
321       // update context
322       wsdlContext = tuple.context;
323       if( soapMessageBuilder != null )
324          soapMessageBuilder.setWsdlContext( wsdlContext );
325    }
326 
327    public BindingOperation findBindingOperation(
328            Definition definition, String bindingOperationName, String inputName,
329            String outputName
330    )
331    {
332       Binding binding = definition.getBinding( getBindingName() );
333       return WsdlUtils.findBindingOperation( binding, bindingOperationName, inputName, outputName );
334    }
335 
336    public Binding getBinding()
337    {
338       try
339       {
340          return findBinding( getWsdlContext() ).binding;
341       }
342       catch( Exception e )
343       {
344          SoapUI.logError( e );
345          return null;
346       }
347    }
348 
349    @SuppressWarnings( "unchecked" )
350    private BindingTuple findBinding( WsdlContext newContext ) throws Exception
351    {
352       BindingTuple tuple = new BindingTuple();
353       tuple.context = newContext;
354 
355       // start by finding the old binding in the new definition
356       Definition definition = newContext.getDefinition();
357       Map serviceMap = definition.getAllServices();
358       Iterator<String> i = serviceMap.keySet().iterator();
359       while( i.hasNext() )
360       {
361          tuple.service = (Service) serviceMap.get( i.next() );
362          Map portMap = tuple.service.getPorts();
363 
364          Iterator i2 = portMap.keySet().iterator();
365          while( i2.hasNext() )
366          {
367             tuple.port = (Port) portMap.get( i2.next() );
368             if( tuple.port.getBinding().getQName().equals( getBindingName() ) )
369             {
370                tuple.binding = tuple.port.getBinding();
371             }
372          }
373 
374          if( tuple.binding != null )
375             break;
376          tuple.service = null;
377       }
378 
379       if( tuple.service == null && tuple.binding == null )
380       {
381          tuple.binding = definition.getBinding( getBindingName() );
382       }
383 
384       // missing matching binding, prompt for new one to use instead (will
385       // happen if binding has been renamed)
386       if( tuple.binding == null )
387       {
388          Map bindings = definition.getAllBindings();
389 
390          Object retval = UISupport.prompt( "Missing matching binding [" + getBindingName()
391                  + "] in definition, select new\nbinding to map to", "Map Binding", bindings.keySet().toArray() );
392 
393          if( retval == null )
394             return null;
395 
396          tuple.binding = (Binding) bindings.get( retval );
397       }
398 
399       return tuple;
400    }
401 
402    @SuppressWarnings( "unchecked" )
403    public void transferOperations( Binding binding, boolean createRequests )
404    {
405       // prepare for transfer of operations/requests
406       List<BindingOperation> newOperations = new ArrayList<BindingOperation>( binding.getBindingOperations() );
407       Map<String, WsdlOperation> oldOperations = new HashMap<String, WsdlOperation>();
408       for( int c = 0; c < operations.size(); c++ )
409          oldOperations.put( operations.get( c ).getBindingOperationName(), operations.get( c ) );
410 
411       // clear existing from both collections
412       for( int c = 0; c < newOperations.size(); c++ )
413       {
414          BindingOperation newOperation = newOperations.get( c );
415          String bindingOperationName = newOperation.getName();
416          if( oldOperations.containsKey( bindingOperationName ) )
417          {
418             log.info( "Synchronizing existing operation [" + bindingOperationName + "]" );
419             WsdlOperation wsdlOperation = oldOperations.get( bindingOperationName );
420             wsdlOperation.initFromBindingOperation( newOperation );
421             fireOperationUpdated( wsdlOperation );
422 
423             oldOperations.remove( bindingOperationName );
424             newOperations.remove( c );
425             c--;
426          }
427       }
428 
429       // remove leftover operations
430       Iterator<String> i = oldOperations.keySet().iterator();
431       while( i.hasNext() )
432       {
433          String name = i.next();
434 
435          if( newOperations.size() > 0 )
436          {
437             List<String> list = new ArrayList<String>();
438             list.add( "none - delete operation" );
439             for( int c = 0; c < newOperations.size(); c++ )
440                list.add( newOperations.get( c ).getName() );
441 
442             String retval = (String) UISupport.prompt( "Binding operation [" + name
443                     + "] not found in new interface, select new\nbinding operation to map to", "Map Operation", list
444                     .toArray(), "none/cancel - delete operation" );
445 
446             int ix = retval == null ? -1 : list.indexOf( retval ) - 1;
447 
448             // delete operation?
449             if( ix < 0 )
450             {
451                deleteOperation( name );
452             }
453             // change operation?
454             else
455             {
456                BindingOperation newOperation = newOperations.get( ix );
457                WsdlOperation wsdlOperation = oldOperations.get( name );
458                wsdlOperation.initFromBindingOperation( newOperation );
459                fireOperationUpdated( wsdlOperation );
460                newOperations.remove( ix );
461             }
462 
463             oldOperations.remove( name );
464          }
465          else
466          {
467             deleteOperation( name );
468             oldOperations.remove( name );
469          }
470 
471          i = oldOperations.keySet().iterator();
472       }
473 
474       // add leftover new operations
475       if( newOperations.size() > 0 )
476       {
477          for( int c = 0; c < newOperations.size(); c++ )
478          {
479             BindingOperation newOperation = newOperations.get( c );
480             WsdlOperation wsdlOperation = addNewOperation( newOperation );
481 
482             if( createRequests )
483             {
484                WsdlRequest request = wsdlOperation.addNewRequest( "Request 1" );
485                try
486                {
487                   request.setRequestContent( wsdlOperation.createRequest( true ) );
488                }
489                catch( Exception e )
490                {
491                   SoapUI.logError( e );
492                }
493             }
494          }
495       }
496    }
497 
498    public void transferEndpoints( Port port )
499    {
500       if( port != null )
501       {
502          String endpoint = WsdlUtils.getSoapEndpoint( port );
503          if( endpoint != null )
504          {
505             StringList list = new StringList( getEndpoints() );
506 
507             // expand properties..
508             for( int c = 0; c < list.size(); c++ )
509                list.set( c, PropertyExpansionUtils.expandProperties( this, list.get( c ) ) );
510 
511             if( !list.contains( endpoint ) )
512             {
513                if( UISupport.confirm( "Update existing requests with new endpoint\n[" + endpoint + "]",
514                        "Update Definition" ) )
515                {
516                   for( int c = 0; c < getOperationCount(); c++ )
517                   {
518                      Operation operation = getOperationAt( c );
519 
520                      for( int ix = 0; ix < operation.getRequestCount(); ix++ )
521                      {
522                         operation.getRequestAt( ix ).setEndpoint( endpoint );
523                      }
524                   }
525                }
526 
527                addEndpoint( endpoint );
528             }
529          }
530       }
531    }
532 
533    public void deleteOperation( String bindingOperationName )
534    {
535       for( int c = 0; c < operations.size(); c++ )
536       {
537          WsdlOperation wsdlOperation = operations.get( c );
538          if( wsdlOperation.getBindingOperationName().equals( bindingOperationName ) )
539          {
540             log.info( "deleting operation [" + bindingOperationName + "]" );
541 
542             // remove requests first (should this be done by some listener?)
543             while( wsdlOperation.getRequestCount() > 0 )
544                wsdlOperation.removeRequest( wsdlOperation.getRequestAt( 0 ) );
545 
546             operations.remove( c );
547 
548             try
549             {
550                fireOperationRemoved( wsdlOperation );
551             }
552             finally
553             {
554                wsdlOperation.release();
555                getConfig().removeOperation( c );
556             }
557 
558             return;
559          }
560       }
561    }
562 
563    public void removeOperation( WsdlOperation wsdlOperation )
564    {
565       int c = operations.indexOf( wsdlOperation );
566       if( c < 0 )
567          throw new IllegalArgumentException( wsdlOperation.getName() + " not found" );
568 
569       log.info( "deleting operation [" + wsdlOperation.getName() + "]" );
570 
571       // remove requests first (should this be done by some listener?)
572       while( wsdlOperation.getRequestCount() > 0 )
573          wsdlOperation.removeRequest( wsdlOperation.getRequestAt( 0 ) );
574 
575       operations.remove( c );
576 
577       try
578       {
579          fireOperationRemoved( wsdlOperation );
580       }
581       finally
582       {
583          wsdlOperation.release();
584          getConfig().removeOperation( c );
585       }
586    }
587 
588    public WsdlOperation getOperationByName( String name )
589    {
590       return (WsdlOperation) getWsdlModelItemByName( operations, name );
591    }
592 
593    public Map<String, Operation> getOperations()
594    {
595       Map<String, Operation> result = new HashMap<String, Operation>();
596       for( Operation operation : operations )
597          result.put( operation.getName(), operation );
598 
599       return result;
600 
601    }
602 
603    public boolean isCached()
604    {
605       return getConfig().isSetDefinitionCache() || ( wsdlContext != null && wsdlContext.isCached() );
606    }
607 
608    // public WsdlLoader createWsdlLoader()
609    // {
610    // return isCached() ? new CachedWsdlLoader(getConfig().getDefinitionCache())
611    // : new UrlWsdlLoader(definitionProperty.expandUrl());
612    // }
613 
614    public String getStyle()
615    {
616       if( wsdlContext == null || !wsdlContext.isLoaded() )
617          return "<not loaded>";
618 
619       try
620       {
621          Binding binding = wsdlContext.getDefinition().getBinding( getBindingName() );
622          if( binding == null )
623             return "<missing binding>";
624 
625          if( WsdlUtils.isRpc( binding ) )
626          {
627             return STYLE_RPC;
628          }
629          else
630          {
631             return STYLE_DOCUMENT;
632          }
633       }
634       catch( Exception e )
635       {
636          SoapUI.logError( e );
637          return "<error>";
638       }
639    }
640 
641    @Override
642    public void release()
643    {
644       super.release();
645 
646       for( WsdlOperation operation : operations )
647          operation.release();
648 
649       if( wsdlContext != null )
650          wsdlContext.release();
651    }
652 
653    public List<Operation> getOperationList()
654    {
655       return new ArrayList<Operation>( operations );
656    }
657 
658    public static class BindingTuple
659    {
660       public WsdlContext context = null;
661       public Service service = null;
662       public Port port = null;
663       public Binding binding = null;
664    }
665 
666    public boolean isUpdating()
667    {
668       return updating;
669    }
670 
671    public void setUpdating( boolean updating )
672    {
673       if( this.updating == updating )
674          return;
675 
676       if( updating )
677       {
678          List<AbstractWsdlModelItem<?>> messages = getAllMessages();
679          for( AbstractWsdlModelItem<?> modelItem : messages )
680          {
681             modelItem.beforeSave();
682          }
683       }
684 
685       boolean oldValue = this.updating;
686       this.updating = updating;
687 
688       notifyPropertyChanged( UPDATING_PROPERTY, oldValue, updating );
689    }
690 
691    public List<AbstractWsdlModelItem<?>> getAllMessages()
692    {
693       ArrayList<AbstractWsdlModelItem<?>> list = new ArrayList<AbstractWsdlModelItem<?>>();
694       getAllMessages( getProject(), list );
695       return list;
696    }
697 
698    private void getAllMessages( ModelItem modelItem, List<AbstractWsdlModelItem<?>> list )
699    {
700       if( modelItem instanceof AbstractHttpRequest )
701       {
702          AbstractHttpRequest wsdlRequest = (AbstractHttpRequest) modelItem;
703          if( wsdlRequest.getOperation().getInterface() == this )
704             list.add( wsdlRequest );
705       }
706       else if( modelItem instanceof WsdlTestRequestStep )
707       {
708          WsdlTestRequestStep testRequestStep = (WsdlTestRequestStep) modelItem;
709          WsdlTestRequest testRequest = testRequestStep.getTestRequest();
710          if( testRequest.getOperation().getInterface() == this )
711             list.add( testRequest );
712       }
713       else if( modelItem instanceof WsdlMockResponse )
714       {
715          WsdlMockResponse mockResponse = (WsdlMockResponse) modelItem;
716          if( mockResponse.getMockOperation() != null && mockResponse.getMockOperation().getOperation() != null
717                  && mockResponse.getMockOperation().getOperation().getInterface() == this )
718             list.add( mockResponse );
719       }
720 
721       // Traverse the ModelItem hierarchy.
722       for( ModelItem child : modelItem.getChildren() )
723       {
724          getAllMessages( child, list );
725       }
726    }
727 
728    @SuppressWarnings( "unchecked" )
729    @Override
730    public void resolve( ResolveContext context )
731    {
732       super.resolve( context );
733 
734       String definition = definitionProperty.expandUrl();
735       if( !isCached() && definition.startsWith( "file:" ) )
736       {
737          try
738          {
739             File file = new File( definition.substring( 5 ) );
740             if( !file.exists() )
741             {
742                if( context.hasThisModelItem( this, "Missing WSDL file", definition ) )
743                   return;
744                context.addPathToResolve( this, "Missing WSDL file", definition, new ResolveContext.FileResolver(
745                        "Select WSDL File", "wsdl", "WSDL Files (*.wsdl)", file.getParent() )
746                {
747 
748                   @Override
749                   public boolean apply( File newFile )
750                   {
751                      try
752                      {
753                         setDefinition( newFile.toURI().toURL().toString() );
754                         return true;
755                      }
756                      catch( Exception e )
757                      {
758                         log.error( "Invalid URL for new Definition", e );
759                         return false;
760                      }
761                   }
762                } );
763             }
764             else
765             {
766                if( context.hasThisModelItem( this, "Missing WSDL file", definition ) )
767                   context.getPath( this, "Missing WSDL file", definition ).setSolved( true );
768             }
769          }
770          catch( Exception e )
771          {
772             e.printStackTrace();
773          }
774       }
775    }
776 
777    public String getInterfaceType()
778    {
779       return WsdlInterfaceFactory.WSDL_TYPE;
780    }
781 
782    public String getTechnicalId()
783    {
784       return getBindingName().toString();
785    }
786 
787    public String getWsaVersion()
788    {
789       if( getConfig().getWsaVersion().equals( WsaVersionTypeConfig.X_200408 ) )
790       {
791          return WsaVersionTypeConfig.X_200408.toString();
792       }
793       else if( getConfig().getWsaVersion().equals( WsaVersionTypeConfig.X_200508 ) )
794       {
795          return WsaVersionTypeConfig.X_200508.toString();
796       }
797 
798       return WsaVersionTypeConfig.NONE.toString();
799    }
800 
801    public void setWsaVersion( String wsAddressing )
802    {
803       if( wsAddressing.equals( WsaVersionTypeConfig.X_200508.toString() ) )
804          getConfig().setWsaVersion( WsaVersionTypeConfig.X_200508 );
805       else if( wsAddressing.equals( WsaVersionTypeConfig.X_200408.toString() ) )
806          getConfig().setWsaVersion( WsaVersionTypeConfig.X_200408 );
807       else
808          getConfig().setWsaVersion( WsaVersionTypeConfig.NONE );
809 
810    }
811 
812    public void setAnonymous( String anonymous )
813    {
814       if( anonymous.equals( AnonymousTypeConfig.REQUIRED.toString() ) )
815          getConfig().setAnonymous( AnonymousTypeConfig.REQUIRED );
816       else if( anonymous.equals( AnonymousTypeConfig.PROHIBITED.toString() ) )
817          getConfig().setAnonymous( AnonymousTypeConfig.PROHIBITED );
818       else
819          getConfig().setAnonymous( AnonymousTypeConfig.OPTIONAL );
820 
821    }
822 
823    public String getAnonymous()
824    {
825       // return WsdlUtils.getAnonymous(this);
826       if( getConfig().isSetAnonymous() )
827       {
828          if( getConfig().getAnonymous().equals( AnonymousTypeConfig.PROHIBITED ) )
829          {
830             return AnonymousTypeConfig.PROHIBITED.toString();
831          }
832          else if( getConfig().getAnonymous().equals( AnonymousTypeConfig.REQUIRED ) )
833          {
834             return AnonymousTypeConfig.REQUIRED.toString();
835          }
836       }
837 
838       return AnonymousTypeConfig.OPTIONAL.toString();
839    }
840 
841    @Override
842    public WsdlContext getDefinitionContext()
843    {
844       return getWsdlContext();
845    }
846 
847    // need to fix removing mock response and test cases.
848    private void replace( WsdlOperation wsdlOperation, OperationConfig reloadedOperation )
849    {
850       int index = operations.indexOf( wsdlOperation );
851 
852       int c = operations.indexOf( wsdlOperation );
853       if( c < 0 )
854          throw new IllegalArgumentException( wsdlOperation.getName() + " not found" );
855 
856       log.info( "deleting operation [" + wsdlOperation.getName() + "]" );
857 
858       // remove requests first (should this be done by some listener?)
859       while( wsdlOperation.getRequestCount() > 0 )
860          wsdlOperation.removeRequest( wsdlOperation.getRequestAt( 0 ) );
861 
862       operations.remove( c );
863 
864       try
865       {
866          fireOperationRemoved( wsdlOperation );
867       }
868       finally
869       {
870          wsdlOperation.release();
871          getConfig().removeOperation( c );
872       }
873 
874       OperationConfig newConfig = (OperationConfig) getConfig().addNewOperation().set( reloadedOperation ).changeType(
875               OperationConfig.type );
876       WsdlOperation newOperation = new WsdlOperation( this, newConfig );
877       operations.add( index, newOperation );
878       newOperation.afterLoad();
879       fireOperationAdded( newOperation );
880 
881    }
882 
883    /***
884     * Method for processing policy on interface level it should include
885     * processing of all types of policies, but for now there's only Addressing
886     * policy implemented
887     *
888     * @param policy
889     * @return this interface changed in a proper way indicated by the policy
890     */
891    public WsdlInterface processPolicy( Policy policy ) throws Exception
892    {
893 
894       // default is optional
895       // String anonymous = AnonymousTypeConfig.OPTIONAL.toString();
896       String wsaVersion = WsaVersionTypeConfig.NONE.toString();
897       setAnonymous( AnonymousTypeConfig.OPTIONAL.toString() );
898 
899       if( policy != null )
900       {
901          List<Addressing> addressingList = policy.getAddressingList();
902          for( Addressing addressing : addressingList )
903          {
904             String optional = addressing.getOptional().toString();
905             if( StringUtils.isNullOrEmpty( optional ) || optional.equals( "false" )
906                     || ( optional.equals( "true" ) && SoapUI.getSettings().getBoolean( WsaSettings.ENABLE_FOR_OPTIONAL ) ) )
907             {
908                wsaVersion = WsaVersionTypeConfig.X_200508.toString();
909             }
910             Policy innerPolicy = addressing.getPolicy();
911             if( innerPolicy != null )
912             {
913                List<AnonymousResponses> anonymousList = innerPolicy.getAnonymousResponsesList();
914                List<NonAnonymousResponses> nonAnonymousList = innerPolicy.getNonAnonymousResponsesList();
915                if( anonymousList.size() > 0 && nonAnonymousList.size() > 0 )
916                {
917                   throw new Exception(
918                           "Wrong addressing policy, anonymousResponses and nonAnonymousResponses can not be specified together" );
919                }
920                if( anonymousList.size() > 0 )
921                {
922                   AnonymousResponses anonResp = anonymousList.get( 0 );
923                   setAnonymous( AnonymousTypeConfig.REQUIRED.toString() );
924                }
925                else
926                {
927                   if( nonAnonymousList.size() > 0 )
928                   {
929                      NonAnonymousResponses nonAnonResp = nonAnonymousList.get( 0 );
930                      setAnonymous( AnonymousTypeConfig.PROHIBITED.toString() );
931                   }
932                }
933             }
934          }
935       }
936       setWsaVersion( wsaVersion );
937 		return this;
938 	}
939 
940 }