View Javadoc

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