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 );
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       if( wsdlContext != null && wsdlContext.isCached() )
606       {
607          return true;
608       }
609 
610       DefinitionCacheConfig cacheConfig = getConfig().getDefinitionCache();
611       if( cacheConfig == null || cacheConfig.getRootPart() == null ||  cacheConfig.sizeOfPartArray() == 0 )
612             return false;
613 
614       return true;
615    }
616 
617    public String getStyle()
618    {
619       if( wsdlContext == null || !wsdlContext.isLoaded() )
620          return "<not loaded>";
621 
622       try
623       {
624          Binding binding = wsdlContext.getDefinition().getBinding( getBindingName() );
625          if( binding == null )
626             return "<missing binding>";
627 
628          if( WsdlUtils.isRpc( binding ) )
629          {
630             return STYLE_RPC;
631          }
632          else
633          {
634             return STYLE_DOCUMENT;
635          }
636       }
637       catch( Exception e )
638       {
639          SoapUI.logError( e );
640          return "<error>";
641       }
642    }
643 
644    @Override
645    public void release()
646    {
647       super.release();
648 
649       for( WsdlOperation operation : operations )
650          operation.release();
651 
652       if( wsdlContext != null )
653          wsdlContext.release();
654    }
655 
656    public List<Operation> getOperationList()
657    {
658       return new ArrayList<Operation>( operations );
659    }
660 
661    public static class BindingTuple
662    {
663       public WsdlContext context = null;
664       public Service service = null;
665       public Port port = null;
666       public Binding binding = null;
667    }
668 
669    public boolean isUpdating()
670    {
671       return updating;
672    }
673 
674    public void setUpdating( boolean updating )
675    {
676       if( this.updating == updating )
677          return;
678 
679       if( updating )
680       {
681          List<AbstractWsdlModelItem<?>> messages = getAllMessages();
682          for( AbstractWsdlModelItem<?> modelItem : messages )
683          {
684             modelItem.beforeSave();
685          }
686       }
687 
688       boolean oldValue = this.updating;
689       this.updating = updating;
690 
691       notifyPropertyChanged( UPDATING_PROPERTY, oldValue, updating );
692    }
693 
694    public List<AbstractWsdlModelItem<?>> getAllMessages()
695    {
696       ArrayList<AbstractWsdlModelItem<?>> list = new ArrayList<AbstractWsdlModelItem<?>>();
697       getAllMessages( getProject(), list );
698       return list;
699    }
700 
701    private void getAllMessages( ModelItem modelItem, List<AbstractWsdlModelItem<?>> list )
702    {
703       if( modelItem instanceof AbstractHttpRequest )
704       {
705          AbstractHttpRequest wsdlRequest = (AbstractHttpRequest) modelItem;
706          if( wsdlRequest.getOperation().getInterface() == this )
707             list.add( wsdlRequest );
708       }
709       else if( modelItem instanceof WsdlTestRequestStep )
710       {
711          WsdlTestRequestStep testRequestStep = (WsdlTestRequestStep) modelItem;
712          WsdlTestRequest testRequest = testRequestStep.getTestRequest();
713          if( testRequest.getOperation().getInterface() == this )
714             list.add( testRequest );
715       }
716       else if( modelItem instanceof WsdlMockResponse )
717       {
718          WsdlMockResponse mockResponse = (WsdlMockResponse) modelItem;
719          if( mockResponse.getMockOperation() != null && mockResponse.getMockOperation().getOperation() != null
720                  && mockResponse.getMockOperation().getOperation().getInterface() == this )
721             list.add( mockResponse );
722       }
723 
724       // Traverse the ModelItem hierarchy.
725       for( ModelItem child : modelItem.getChildren() )
726       {
727          getAllMessages( child, list );
728       }
729    }
730 
731    @SuppressWarnings( "unchecked" )
732    @Override
733    public void resolve( ResolveContext context )
734    {
735       super.resolve( context );
736 
737       String definition = definitionProperty.expandUrl();
738       if( !isCached() && definition.startsWith( "file:" ) )
739       {
740          try
741          {
742             File file = new File( definition.substring( 5 ) );
743             if( !file.exists() )
744             {
745                if( context.hasThisModelItem( this, "Missing WSDL file", definition ) )
746                   return;
747                context.addPathToResolve( this, "Missing WSDL file", definition, new ResolveContext.FileResolver(
748                        "Select WSDL File", "wsdl", "WSDL Files (*.wsdl)", file.getParent() )
749                {
750 
751                   @Override
752                   public boolean apply( File newFile )
753                   {
754                      try
755                      {
756                         setDefinition( newFile.toURI().toURL().toString() );
757                         return true;
758                      }
759                      catch( Exception e )
760                      {
761                         log.error( "Invalid URL for new Definition", e );
762                         return false;
763                      }
764                   }
765                } );
766             }
767             else
768             {
769                if( context.hasThisModelItem( this, "Missing WSDL file", definition ) )
770                   context.getPath( this, "Missing WSDL file", definition ).setSolved( true );
771             }
772          }
773          catch( Exception e )
774          {
775             e.printStackTrace();
776          }
777       }
778    }
779 
780    public String getInterfaceType()
781    {
782       return WsdlInterfaceFactory.WSDL_TYPE;
783    }
784 
785    public String getTechnicalId()
786    {
787       return getBindingName().toString();
788    }
789 
790    public String getWsaVersion()
791    {
792       if( getConfig().getWsaVersion().equals( WsaVersionTypeConfig.X_200408 ) )
793       {
794          return WsaVersionTypeConfig.X_200408.toString();
795       }
796       else if( getConfig().getWsaVersion().equals( WsaVersionTypeConfig.X_200508 ) )
797       {
798          return WsaVersionTypeConfig.X_200508.toString();
799       }
800 
801       return WsaVersionTypeConfig.NONE.toString();
802    }
803 
804    public void setWsaVersion( String wsAddressing )
805    {
806       if( wsAddressing.equals( WsaVersionTypeConfig.X_200508.toString() ) )
807          getConfig().setWsaVersion( WsaVersionTypeConfig.X_200508 );
808       else if( wsAddressing.equals( WsaVersionTypeConfig.X_200408.toString() ) )
809          getConfig().setWsaVersion( WsaVersionTypeConfig.X_200408 );
810       else
811          getConfig().setWsaVersion( WsaVersionTypeConfig.NONE );
812 
813    }
814 
815    public void setAnonymous( String anonymous )
816    {
817       if( anonymous.equals( AnonymousTypeConfig.REQUIRED.toString() ) )
818          getConfig().setAnonymous( AnonymousTypeConfig.REQUIRED );
819       else if( anonymous.equals( AnonymousTypeConfig.PROHIBITED.toString() ) )
820          getConfig().setAnonymous( AnonymousTypeConfig.PROHIBITED );
821       else
822          getConfig().setAnonymous( AnonymousTypeConfig.OPTIONAL );
823 
824    }
825 
826    public String getAnonymous()
827    {
828       // return WsdlUtils.getAnonymous(this);
829       if( getConfig().isSetAnonymous() )
830       {
831          if( getConfig().getAnonymous().equals( AnonymousTypeConfig.PROHIBITED ) )
832          {
833             return AnonymousTypeConfig.PROHIBITED.toString();
834          }
835          else if( getConfig().getAnonymous().equals( AnonymousTypeConfig.REQUIRED ) )
836          {
837             return AnonymousTypeConfig.REQUIRED.toString();
838          }
839       }
840 
841       return AnonymousTypeConfig.OPTIONAL.toString();
842    }
843 
844    @Override
845    public WsdlContext getDefinitionContext()
846    {
847       return getWsdlContext();
848    }
849 
850    // need to fix removing mock response and test cases.
851    private void replace( WsdlOperation wsdlOperation, OperationConfig reloadedOperation )
852    {
853       int index = operations.indexOf( wsdlOperation );
854 
855       int c = operations.indexOf( wsdlOperation );
856       if( c < 0 )
857          throw new IllegalArgumentException( wsdlOperation.getName() + " not found" );
858 
859       log.info( "deleting operation [" + wsdlOperation.getName() + "]" );
860 
861       // remove requests first (should this be done by some listener?)
862       while( wsdlOperation.getRequestCount() > 0 )
863          wsdlOperation.removeRequest( wsdlOperation.getRequestAt( 0 ) );
864 
865       operations.remove( c );
866 
867       try
868       {
869          fireOperationRemoved( wsdlOperation );
870       }
871       finally
872       {
873          wsdlOperation.release();
874          getConfig().removeOperation( c );
875       }
876 
877       OperationConfig newConfig = (OperationConfig) getConfig().addNewOperation().set( reloadedOperation ).changeType(
878               OperationConfig.type );
879       WsdlOperation newOperation = new WsdlOperation( this, newConfig );
880       operations.add( index, newOperation );
881       newOperation.afterLoad();
882       fireOperationAdded( newOperation );
883 
884    }
885 
886    /***
887     * Method for processing policy on interface level it should include
888     * processing of all types of policies, but for now there's only Addressing
889     * policy implemented
890     *
891     * @param policy
892     * @return this interface changed in a proper way indicated by the policy
893     */
894    public WsdlInterface processPolicy( Policy policy ) throws Exception
895    {
896 
897       // default is optional
898       // String anonymous = AnonymousTypeConfig.OPTIONAL.toString();
899       String wsaVersion = WsaVersionTypeConfig.NONE.toString();
900       setAnonymous( AnonymousTypeConfig.OPTIONAL.toString() );
901 
902       if( policy != null )
903       {
904          List<Addressing> addressingList = policy.getAddressingList();
905          for( Addressing addressing : addressingList )
906          {
907             String optional = addressing.getOptional().toString();
908             if( StringUtils.isNullOrEmpty( optional ) || optional.equals( "false" )
909                     || ( optional.equals( "true" ) && SoapUI.getSettings().getBoolean( WsaSettings.ENABLE_FOR_OPTIONAL ) ) )
910             {
911                wsaVersion = WsaVersionTypeConfig.X_200508.toString();
912             }
913             Policy innerPolicy = addressing.getPolicy();
914             if( innerPolicy != null )
915             {
916                List<AnonymousResponses> anonymousList = innerPolicy.getAnonymousResponsesList();
917                List<NonAnonymousResponses> nonAnonymousList = innerPolicy.getNonAnonymousResponsesList();
918                if( anonymousList.size() > 0 && nonAnonymousList.size() > 0 )
919                {
920                   throw new Exception(
921                           "Wrong addressing policy, anonymousResponses and nonAnonymousResponses can not be specified together" );
922                }
923                if( anonymousList.size() > 0 )
924                {
925                   AnonymousResponses anonResp = anonymousList.get( 0 );
926                   setAnonymous( AnonymousTypeConfig.REQUIRED.toString() );
927                }
928                else
929                {
930                   if( nonAnonymousList.size() > 0 )
931                   {
932                      NonAnonymousResponses nonAnonResp = nonAnonymousList.get( 0 );
933                      setAnonymous( AnonymousTypeConfig.PROHIBITED.toString() );
934                   }
935                }
936             }
937          }
938       }
939       setWsaVersion( wsaVersion );
940 		return this;
941 	}
942 
943 }