View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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.beans.PropertyChangeEvent;
16  import java.beans.PropertyChangeListener;
17  import java.io.File;
18  import java.io.IOException;
19  import java.util.ArrayList;
20  import java.util.Arrays;
21  import java.util.HashSet;
22  import java.util.List;
23  import java.util.Set;
24  
25  import javax.swing.ImageIcon;
26  import javax.wsdl.BindingOperation;
27  import javax.wsdl.Message;
28  import javax.xml.namespace.QName;
29  
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  import org.apache.xmlbeans.SchemaGlobalElement;
33  import org.apache.xmlbeans.SchemaType;
34  
35  import com.eviware.soapui.config.AttachmentConfig;
36  import com.eviware.soapui.config.CallConfig;
37  import com.eviware.soapui.config.CredentialsConfig;
38  import com.eviware.soapui.impl.actions.ShowDesktopPanelAction;
39  import com.eviware.soapui.impl.wsdl.actions.operation.AddToMockServiceAction;
40  import com.eviware.soapui.impl.wsdl.actions.request.AddRequestToTestCaseAction;
41  import com.eviware.soapui.impl.wsdl.actions.request.CloneRequestAction;
42  import com.eviware.soapui.impl.wsdl.actions.request.DeleteRequestAction;
43  import com.eviware.soapui.impl.wsdl.actions.request.RenameRequestAction;
44  import com.eviware.soapui.impl.wsdl.actions.support.ShowOnlineHelpAction;
45  import com.eviware.soapui.impl.wsdl.submit.RequestTransportRegistry;
46  import com.eviware.soapui.impl.wsdl.submit.filters.PropertyExpansionRequestFilter;
47  import com.eviware.soapui.impl.wsdl.submit.transports.http.AttachmentUtils;
48  import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
49  import com.eviware.soapui.impl.wsdl.support.FileAttachment;
50  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
51  import com.eviware.soapui.impl.wsdl.support.ModelItemIconAnimator;
52  import com.eviware.soapui.impl.wsdl.support.RequestFileAttachment;
53  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
54  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils;
55  import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils.SoapHeader;
56  import com.eviware.soapui.model.iface.Attachment;
57  import com.eviware.soapui.model.iface.Interface;
58  import com.eviware.soapui.model.iface.MessagePart;
59  import com.eviware.soapui.model.iface.Request;
60  import com.eviware.soapui.model.iface.Submit;
61  import com.eviware.soapui.model.iface.SubmitContext;
62  import com.eviware.soapui.model.iface.SubmitListener;
63  import com.eviware.soapui.model.support.InterfaceListenerAdapter;
64  import com.eviware.soapui.settings.WsdlSettings;
65  import com.eviware.soapui.support.UISupport;
66  import com.eviware.soapui.support.action.ActionSupport;
67  import com.eviware.soapui.support.types.StringToStringMap;
68  
69  /***
70   * Request implementation holding a SOAP request
71   * 
72   * @author Ole.Matzura
73   */
74  
75  public class WsdlRequest extends AbstractWsdlModelItem<CallConfig> implements Request, AttachmentContainer
76  {
77  	public static final String RESPONSE_PROPERTY = WsdlRequest.class.getName() + "@response";
78  	public static final String RESPONSE_CONTENT_PROPERTY = WsdlRequest.class.getName() + "@response-content";
79  	public static final String ATTACHMENTS_PROPERTY = WsdlRequest.class.getName() + "@attachments";
80  	public static final String INLINE_RESPONSE_ATTACHMENTS = WsdlRequest.class.getName() + "@inline-response-attachments";
81  	public static final String EXPAND_MTOM_RESPONSE_ATTACHMENTS = WsdlRequest.class.getName() + "@expand-mtom-attachments";
82  	public static final String STRIP_WHITESPACES = WsdlRequest.class.getName() + "@strip-whitespaces";
83  	public static final String REQUEST_HEADERS_PROPERTY = WsdlRequest.class.getName() + "@request-headers";
84  	public static final String DISABLE_MULTIPART_ATTACHMENTS = WsdlRequest.class.getName() + "@disable-multipart-attachments";
85  	
86  	public final static String PW_TYPE_NONE="None";
87     public final static String PW_TYPE_DIGEST="PasswordDigest";
88     public final static String PW_TYPE_TEXT="PasswordText";
89     
90     private final WsdlOperation operation;
91     private WsdlResponse response;
92     private final static Log log = LogFactory.getLog( WsdlRequest.class );
93  	
94  
95     protected List<FileAttachment> attachments = new ArrayList<FileAttachment>();
96     
97  	private RequestIconAnimator iconAnimator;
98     private Set<SubmitListener> listeners = new HashSet<SubmitListener>();
99  	private List<WsdlAttachmentPart> definedAttachmentParts;
100 	
101 	private InternalInterfaceListener interfaceListener = new InternalInterfaceListener();
102 
103    public WsdlRequest( WsdlOperation operation, CallConfig callConfig )
104    {
105    	super( callConfig, operation, null );
106    	
107       this.operation = operation;
108       
109       initActions();
110       initEndpoints();
111       initAttachments();
112       
113       iconAnimator = initIconAnimator();
114       
115       // ensure encoding
116       if( callConfig.getEncoding() == null || callConfig.getEncoding().length() == 0 )
117       {
118       	callConfig.setEncoding( "UTF-8" );
119       }
120       
121       addSubmitListener( iconAnimator );
122     
123       operation.getInterface().addPropertyChangeListener( interfaceListener );
124       operation.getInterface().addInterfaceListener( interfaceListener );
125    }
126    
127    private void initAttachments()
128 	{
129 		for( AttachmentConfig ac : getConfig().getAttachmentList() )
130 		{
131 			FileAttachment attachment = new RequestFileAttachment( ac, this );
132 			attachments.add( attachment);
133 		}
134 	}
135 
136 	public void updateConfig(CallConfig request)
137 	{
138 		setConfig( request );
139 	}
140    
141    public ModelItemIconAnimator getIconAnimator()
142    {
143    	return iconAnimator;
144    }
145 
146    protected RequestIconAnimator initIconAnimator()
147    {
148    	return new RequestIconAnimator();
149    }
150 
151    protected void initEndpoints()
152    {
153    	if( getEndpoint() == null )
154    	{
155 	      String[] endpoints = operation.getInterface().getEndpoints();
156 	      if( endpoints.length > 0 )
157 	      {
158 	         setEndpoint( endpoints[0] );
159 	      }
160    	}
161    }
162 
163    protected void initActions()
164    {
165       addAction( new ShowDesktopPanelAction( "Open Request Editor", "Opens the Request Editor for this request", this ));
166       addAction( ActionSupport.SEPARATOR_ACTION );
167       addAction( new AddRequestToTestCaseAction( this ));
168 //      addAction( new AddAsMockResponseStepAction( this ));
169       addAction( new AddToMockServiceAction( this ));
170       addAction( new CloneRequestAction( this ));
171       addAction( ActionSupport.SEPARATOR_ACTION );
172       addAction( new RenameRequestAction( this ));
173       addAction( new DeleteRequestAction( this ));
174       addAction( ActionSupport.SEPARATOR_ACTION );
175       addAction( new ShowOnlineHelpAction( HelpUrls.REQUEST_HELP_URL ));
176    }
177 
178    public String getRequestContent()
179    {
180      return getConfig().getRequest();
181    }
182    
183    public void setEndpoint(String endpoint)
184    {
185       String old = getEndpoint();
186       if( old != null && old.equals( endpoint ))
187       	return;
188       
189       getConfig().setEndpoint( endpoint );
190       notifyPropertyChanged( ENDPOINT_PROPERTY, old, endpoint);
191    }
192 
193    public String getEndpoint()
194    {
195       return getConfig().getEndpoint();
196    }
197 
198    public String getEncoding()
199    {
200       return getConfig().getEncoding();
201    }
202 
203    public void setEncoding(String encoding)
204    {
205       String old = getEncoding();
206       getConfig().setEncoding( encoding );
207       notifyPropertyChanged( ENCODING_PROPERTY, old, encoding );
208    }
209    
210    public StringToStringMap getRequestHeaders()
211    {
212    	return StringToStringMap.fromXml( getSettings().getString( REQUEST_HEADERS_PROPERTY, null ));
213    }
214    
215    public void setRequestHeaders( StringToStringMap map )
216    {
217    	StringToStringMap old = getRequestHeaders();
218    	getSettings().setString( REQUEST_HEADERS_PROPERTY, map.toXml() );
219    	notifyPropertyChanged( REQUEST_HEADERS_PROPERTY, old, map );
220    }
221    
222    public boolean isInlineResponseAttachments()
223    {
224    	return getSettings().getBoolean( INLINE_RESPONSE_ATTACHMENTS );
225    }
226    
227    public void setInlineResponseAttachments( boolean inlineResponseAttachments )
228    {
229    	boolean old = getSettings().getBoolean( INLINE_RESPONSE_ATTACHMENTS );
230    	getSettings().setBoolean( INLINE_RESPONSE_ATTACHMENTS, inlineResponseAttachments );
231    	notifyPropertyChanged( INLINE_RESPONSE_ATTACHMENTS, old, inlineResponseAttachments );
232    }
233    
234    public boolean isStripWhitespaces()
235    {
236    	return getSettings().getBoolean( STRIP_WHITESPACES );
237    }
238    
239    public void setStripWhitespaces( boolean stripWhitespaces )
240    {
241    	boolean old = getSettings().getBoolean( STRIP_WHITESPACES );
242    	getSettings().setBoolean( STRIP_WHITESPACES, stripWhitespaces );
243    	notifyPropertyChanged( STRIP_WHITESPACES, old, stripWhitespaces );
244    }
245    
246    public boolean isExpandMtomResponseAttachments()
247    {
248    	return getSettings().getBoolean( EXPAND_MTOM_RESPONSE_ATTACHMENTS );
249    }
250    
251    public void setExpandMtomResponseAttachments( boolean expandMtomResponseAttachments )
252    {
253    	boolean old = getSettings().getBoolean( EXPAND_MTOM_RESPONSE_ATTACHMENTS );
254    	getSettings().setBoolean( EXPAND_MTOM_RESPONSE_ATTACHMENTS, expandMtomResponseAttachments );
255    	notifyPropertyChanged( EXPAND_MTOM_RESPONSE_ATTACHMENTS, old, expandMtomResponseAttachments );
256    }
257    
258    /***
259     * Use getResponse().getContentAsString();
260     * @deprecated
261     */
262    
263    public String getResponseContent()
264    {
265       return response == null ? null : response.getContentAsString();
266    }
267 
268    public WsdlResponse getResponse()
269    {
270    	return response;
271    }
272    
273    public WsdlOperation getOperation()
274    {
275       return operation;
276    }
277 
278    public void setRequestContent(String request)
279    {
280       String old = getRequestContent();
281       if( request.equals( old ))
282       	return;
283       getConfig().setRequest( request );
284       definedAttachmentParts = null;
285       notifyPropertyChanged( REQUEST_PROPERTY, old, request );
286    }
287    
288    public void setResponse( WsdlResponse response, SubmitContext context )
289    {
290    	WsdlResponse oldResponse = (WsdlResponse) getResponse();
291 		this.response = response;
292 		
293       notifyPropertyChanged( RESPONSE_PROPERTY, oldResponse, response );
294    }
295 
296    public ImageIcon getIcon()
297    {
298    	return iconAnimator.getIcon();
299    }
300 
301    public String getUsername()
302    {
303    	CredentialsConfig credentialsConfig = getConfig().getCredentials();
304    	if( credentialsConfig == null ) return null;
305    	
306    	return credentialsConfig.getUsername();
307    }
308    
309    public String getPassword()
310    {
311    	CredentialsConfig credentialsConfig = getConfig().getCredentials();
312    	if( credentialsConfig == null ) return null;
313    	
314    	return credentialsConfig.getPassword();
315    }
316    
317    public String getDomain()
318    {
319    	CredentialsConfig credentialsConfig = getConfig().getCredentials();
320    	if( credentialsConfig == null ) return null;
321    	
322    	return credentialsConfig.getDomain();
323    }
324    
325    public void setUsername( String username )
326    {
327    	CredentialsConfig credentialsConfig = getConfig().getCredentials();
328    	if( credentialsConfig == null ) 
329    		credentialsConfig = getConfig().addNewCredentials();
330    	
331    	credentialsConfig.setUsername( username );
332    }
333    
334    public void setPassword( String password )
335    {
336    	CredentialsConfig credentialsConfig = getConfig().getCredentials();
337    	if( credentialsConfig == null ) 
338    		credentialsConfig = getConfig().addNewCredentials();
339    	
340    	credentialsConfig.setPassword( password );
341    }
342    
343    public void setDomain( String domain )
344    {
345    	CredentialsConfig credentialsConfig = getConfig().getCredentials();
346    	if( credentialsConfig == null ) 
347    		credentialsConfig = getConfig().addNewCredentials();
348    	
349    	credentialsConfig.setDomain( domain );
350    }
351    
352    public void addSubmitListener(SubmitListener listener) 
353 	{
354 		listeners.add( listener );
355 	}
356 
357 	public void removeSubmitListener(SubmitListener listener) 
358 	{
359 		listeners.remove( listener );
360 	}
361 
362 	public Submit submit( SubmitContext submitContext, boolean async ) throws SubmitException
363 	{
364       String endpoint = PropertyExpansionRequestFilter.expandProperties( submitContext, getEndpoint());
365 		if( endpoint == null || endpoint.trim().length() == 0 )
366       {
367       	UISupport.showErrorMessage( "Missing endpoint for request [" + getName() + "]" );
368       	return null;
369       }
370 		
371 		try
372 		{
373 			WsdlSubmit submitter = new WsdlSubmit(this, (SubmitListener[]) listeners.toArray(new SubmitListener[listeners
374 					.size()]), RequestTransportRegistry.getTransport(endpoint, submitContext));
375 			submitter.submitRequest(submitContext, async);
376 			return submitter;
377 		}
378 		catch( Exception e )
379 		{
380 			throw new SubmitException( e.toString() );
381 		}
382 	}
383 	
384 	private class InternalInterfaceListener extends InterfaceListenerAdapter implements PropertyChangeListener
385 	{
386 		public void propertyChange(PropertyChangeEvent evt)
387 		{
388 			if( evt.getPropertyName().equals( Interface.ENDPOINT_PROPERTY ))
389 			{
390 				String endpoint = getEndpoint();
391 				if( evt.getOldValue() != null && evt.getOldValue().equals( endpoint ))
392 				{
393 					setEndpoint( (String) evt.getNewValue() );
394 				}
395 			}
396 		}
397 	}
398 
399 	public String getWssPasswordType()
400 	{
401 		return getConfig().getWssPasswordType();
402 	}
403 
404 	public void setWssPasswordType(String wssPasswordType)
405 	{
406 		getConfig().setWssPasswordType( wssPasswordType );
407 	}
408 
409 	/* (non-Javadoc)
410 	 * @see com.eviware.soapui.impl.wsdl.AttachmentContainer#attachFile(java.io.File, boolean)
411 	 */
412 	public Attachment attachFile( File file, boolean cache )
413 	{
414 		try
415 		{
416 			FileAttachment fileAttachment = new RequestFileAttachment( file, cache, this );
417 			attachments.add( fileAttachment );
418 			notifyPropertyChanged(ATTACHMENTS_PROPERTY, null, fileAttachment );
419 			return fileAttachment;
420 		}
421 		catch (IOException e)
422 		{
423 			UISupport.showErrorMessage( e );
424 			return null;
425 		}
426 	}
427 	
428 	/* (non-Javadoc)
429 	 * @see com.eviware.soapui.impl.wsdl.AttachmentContainer#getAttachmentCount()
430 	 */
431 	public int getAttachmentCount()
432 	{
433 		return attachments.size();
434 	}
435 	
436 	/* (non-Javadoc)
437 	 * @see com.eviware.soapui.impl.wsdl.AttachmentContainer#getAttachmentAt(int)
438 	 */
439 	public Attachment getAttachmentAt( int index )
440 	{
441 		return attachments.get( index );
442 	}
443 	
444 	/* (non-Javadoc)
445 	 * @see com.eviware.soapui.impl.wsdl.AttachmentContainer#getAttachmentsForPart(java.lang.String)
446 	 */
447 	public Attachment [] getAttachmentsForPart( String partName )
448 	{
449 		List<Attachment> result = new ArrayList<Attachment>();
450 		
451 		for( Attachment attachment : attachments )
452 		{
453 			if( attachment.getPart().equals( partName ))
454 				result.add( attachment );
455 		}
456 		
457 		return result.toArray( new Attachment[result.size()]);
458 	}
459 	
460 	/* (non-Javadoc)
461 	 * @see com.eviware.soapui.impl.wsdl.AttachmentContainer#removeAttachment(com.eviware.soapui.model.iface.Attachment)
462 	 */
463 	public void removeAttachment( Attachment attachment )
464 	{
465 		int ix = attachments.indexOf( attachment );
466 		attachments.remove( ix );
467 		
468 		try
469 		{
470 			notifyPropertyChanged(ATTACHMENTS_PROPERTY, attachment, null );
471 		}
472 		finally
473 		{
474 			getConfig().removeAttachment( ix);
475 		}
476 	}
477 	
478 	/* (non-Javadoc)
479 	 * @see com.eviware.soapui.impl.wsdl.AttachmentContainer#getAttachments()
480 	 */
481 	public Attachment[] getAttachments()
482 	{
483 		return attachments.toArray( new Attachment[attachments.size()] );
484 	}
485 	
486 	/* (non-Javadoc)
487 	 * @see com.eviware.soapui.impl.wsdl.AttachmentContainer#getDefinedAttachmentParts()
488 	 */
489 	public WsdlAttachmentPart [] getDefinedAttachmentParts()
490 	{
491 		if( definedAttachmentParts == null )
492 		{
493 			try
494 			{
495 				UISupport.setHourglassCursor();
496 				definedAttachmentParts = AttachmentUtils.extractAttachmentParts( 
497 							(WsdlOperation)getOperation(), getRequestContent(), true );
498 			}
499 			catch (Exception e)
500 			{
501 				log.warn( e.toString() );
502 			}
503 			finally 
504 			{
505 				UISupport.resetCursor();
506 			}
507 		}
508 		
509 		return definedAttachmentParts.toArray( new WsdlAttachmentPart[definedAttachmentParts.size()] );
510 	}
511 	
512 	/* (non-Javadoc)
513 	 * @see com.eviware.soapui.impl.wsdl.AttachmentContainer#getAttachmentPart(java.lang.String)
514 	 */
515 	public WsdlAttachmentPart getAttachmentPart( String partName )
516 	{
517 		WsdlAttachmentPart[] parts = getDefinedAttachmentParts();
518 		for( WsdlAttachmentPart part : parts )
519 		{
520 			if( part.getName().equals( partName ))
521 				return part;
522 		}
523 		
524 		return null;
525 	}
526 
527 	public void copyAttachmentsTo(WsdlRequest newRequest)
528 	{
529 		if( getAttachmentCount() > 0 )
530       {
531 			try
532 			{
533 				UISupport.setHourglassCursor();
534 				for (int c = 0; c < getAttachmentCount(); c++)
535 				{
536 					try
537 					{
538 						Attachment attachment = getAttachmentAt(c);
539 						newRequest.addAttachment( attachment );
540 					}
541 					catch (Exception e)
542 					{
543 						e.printStackTrace();
544 					}					
545 				}
546 			}
547 			finally 
548 			{
549 				UISupport.resetCursor();
550 			}      	
551       }
552 	}
553 
554 	private Attachment addAttachment(Attachment attachment)
555 	{
556 		if( attachment instanceof FileAttachment )
557 		{
558 			AttachmentConfig oldConfig = ((FileAttachment)attachment).getConfig();
559 			AttachmentConfig newConfig = (AttachmentConfig) getConfig().addNewAttachment().set( oldConfig );
560 			FileAttachment newAttachment = new RequestFileAttachment( newConfig, this );
561 			attachments.add( newAttachment);
562 			return newAttachment;
563 		}
564 		else log.error( "Unkown attachment type: " + attachment );
565 		
566 		return null;
567 	}
568 
569 	public void copyTo(WsdlRequest newRequest)
570 	{
571       newRequest.setEncoding( getEncoding() );
572       newRequest.setEndpoint( getEndpoint() );
573       newRequest.setRequestContent( getRequestContent() );
574       newRequest.setWssPasswordType( getWssPasswordType() );
575       
576       CredentialsConfig credentials = getConfig().getCredentials();
577       if( credentials != null)
578       	newRequest.getConfig().setCredentials( (CredentialsConfig) credentials.copy() );
579 
580       copyAttachmentsTo( newRequest );
581       
582       newRequest.setRequestHeaders( getRequestHeaders() );
583 	}
584 	
585 	/* (non-Javadoc)
586 	 * @see com.eviware.soapui.impl.wsdl.AttachmentContainer#isMtomEnabled()
587 	 */
588 	public boolean isMtomEnabled()
589 	{
590 		return getSettings().getBoolean( WsdlSettings.ENABLE_MTOM );
591 	}
592 	
593 	public void setMtomEnabled( boolean mtomEnabled )
594 	{
595 		getSettings().setBoolean( WsdlSettings.ENABLE_MTOM, mtomEnabled );
596 		definedAttachmentParts = null;
597 	}
598 
599 	public void release()
600 	{
601 		super.release();
602 		
603 		getOperation().getInterface().removeInterfaceListener( interfaceListener );
604 		getOperation().getInterface().removePropertyChangeListener( interfaceListener );
605 	}
606 
607 	public MessagePart[] getRequestParts()
608 	{
609 		try
610 		{
611 			// init
612 			List<MessagePart> result = new ArrayList<MessagePart>();
613 			WsdlOperation op = (WsdlOperation) getOperation();
614 			WsdlContext wsdlContext = op.getInterface().getWsdlContext();
615 			BindingOperation bindingOperation = op.findBindingOperation(wsdlContext.getDefinition());
616 			
617 			if( bindingOperation == null )
618 				return new MessagePart[0];
619 			
620 			// header parts
621 			List<SoapHeader> headers = WsdlUtils.getSoapHeaders( bindingOperation.getBindingInput()
622 		            .getExtensibilityElements());
623 
624 	      for (int i = 0; i < headers.size(); i++)
625 	      {
626 	      	SoapHeader header = headers.get( i );
627 	         
628 	         Message message = wsdlContext.getDefinition().getMessage( header.getMessage() );
629 	         if( message == null )
630 	         {
631 	         	log.error( "Missing message for header: " + header.getMessage() );
632 	         	continue;
633 	         }
634 	         
635 				javax.wsdl.Part part = message.getPart( header.getPart() );
636 
637 	         if( part != null )
638 	         {
639 	         	SchemaType schemaType = getSchemaTypeForPart( wsdlContext, part );
640 					if( schemaType != null )
641 						result.add( new WsdlHeaderPart( part.getName(), schemaType, part.getElementName(), this ));
642 	         }
643 	         else
644 	         	log.error( "Missing part for header; " + header.getPart() );
645 	      }
646 	
647 			// content parts
648 			javax.wsdl.Part[] parts = WsdlUtils.getInputParts( bindingOperation );
649 			
650 			for( int i = 0; i < parts.length; i++ )
651 	      {
652 	      	javax.wsdl.Part part = parts[i];
653 	      	
654 				if( !WsdlUtils.isAttachmentInputPart( part, bindingOperation ))
655 	      	{
656 					SchemaType schemaType = getSchemaTypeForPart( wsdlContext, part );
657 					if( schemaType != null )
658 						result.add( new WsdlContentPart( part.getName(), schemaType, part.getElementName(), this ));
659       	   }
660 	      }
661 			
662 			result.addAll( Arrays.asList( getDefinedAttachmentParts()) );
663 			
664 			return result.toArray( new MessagePart[result.size()] );
665 		}
666 		catch (Exception e)
667 		{
668 			e.printStackTrace();
669 			return new MessagePart [0];
670 		}		
671 	}
672 	
673 	public SchemaType getSchemaTypeForPart( WsdlContext wsdlContext, javax.wsdl.Part part) throws Exception
674 	{
675 		SchemaType schemaType = null;
676 		QName elementName = part.getElementName();
677 		
678 		if( elementName != null )
679 		{
680 		   SchemaGlobalElement elm = wsdlContext.getSchemaTypeLoader().findElement(elementName);
681 		   if( elm != null )
682 		   {
683 		   	schemaType = elm.getType();
684 		   }
685 		   else log.error( "Could not find element [" + elementName + "] specified in part [" + part.getName() + "]" );
686 		}
687 		else 
688 		{
689 			QName typeName = part.getTypeName();
690 			
691 		   if( typeName != null  )
692 		   {
693 		      schemaType = wsdlContext.getSchemaTypeLoader().findType( typeName );
694 		      
695 		      if( schemaType == null )
696 		      {
697 		      	log.error( "Could not find type [" + typeName + "] specified in part [" + part.getName() + "]" );
698 		      }
699 		   }
700 		}
701 		return schemaType;
702 	}
703 
704 	public MessagePart[] getResponseParts()
705 	{
706 		try
707 		{
708 			// init
709 			List<MessagePart> result = new ArrayList<MessagePart>();
710 			WsdlOperation op = (WsdlOperation) getOperation();
711 			WsdlContext wsdlContext = op.getInterface().getWsdlContext();
712 			BindingOperation bindingOperation = op.findBindingOperation(wsdlContext.getDefinition());
713 			
714 			if( bindingOperation == null )
715 				return new MessagePart[0];
716 			
717 			// header parts
718 			List<SoapHeader> headers = WsdlUtils.getSoapHeaders( bindingOperation.getBindingOutput()
719 			            .getExtensibilityElements());
720 
721 	      for (int i = 0; i < headers.size(); i++)
722 	      {
723 	      	SoapHeader header = headers.get( i );
724 	         
725 	         Message message = wsdlContext.getDefinition().getMessage( header.getMessage() );
726 	         if( message == null )
727 	         {
728 	         	log.error( "Missing message for header: " + header.getMessage() );
729 	         	continue;
730 	         }
731 	         
732 				javax.wsdl.Part part = message.getPart( header.getPart() );
733 
734 	         if( part != null )
735 	         {
736 	         	SchemaType schemaType = getSchemaTypeForPart( wsdlContext, part );
737 					if( schemaType != null )
738 						result.add( new WsdlHeaderPart( part.getName(), schemaType, part.getElementName(), this ));
739 	         }
740 	         else
741 	         	log.error( "Missing part for header; " + header.getPart() );
742 	      }
743 	
744 			// content parts
745 			javax.wsdl.Part[] parts = WsdlUtils.getOutputParts( bindingOperation );
746 			
747 			for( int i = 0; i < parts.length; i++ )
748 	      {
749 	      	javax.wsdl.Part part = parts[i];
750 	      	
751 				if( !WsdlUtils.isAttachmentOutputPart( part, bindingOperation ))
752 	      	{
753 					SchemaType schemaType = getSchemaTypeForPart( wsdlContext, part );
754 					if( schemaType != null )
755 						result.add( new WsdlContentPart( part.getName(), schemaType, part.getElementName(), this ));
756       	   }
757 	      }
758 			
759 			result.addAll( Arrays.asList( getDefinedAttachmentParts()) );
760 			
761 			return result.toArray( new MessagePart[result.size()] );
762 		}
763 		catch (Exception e)
764 		{
765 			e.printStackTrace();
766 			return new MessagePart [0];
767 		}		
768 	}
769 	
770 	protected class RequestIconAnimator extends ModelItemIconAnimator implements SubmitListener
771 	{
772 		public RequestIconAnimator()
773 		{
774 			super( WsdlRequest.this, "/request.gif", 
775 						new String[] {"/exec_request_1.gif", "/exec_request_2.gif",
776 						"/exec_request_3.gif", "/exec_request_4.gif"} );
777 		}
778 		
779 		public boolean beforeSubmit(Submit submit, SubmitContext context) 
780 		{
781 			if( isEnabled() && submit.getRequest() == getTarget() )
782 				start();
783 	      return true;
784 		}
785 
786 		public void afterSubmit(Submit submit, SubmitContext context) 
787 		{
788 			if( submit.getRequest() == getTarget() )
789 				stop();
790 		}
791 	}
792 
793 	public boolean isMultipartEnabled()
794 	{
795 		return !getSettings().getBoolean( DISABLE_MULTIPART_ATTACHMENTS );
796 	}
797 	
798 	public void setMultipartEnabled( boolean multipartEnabled )
799 	{
800 		getSettings().setBoolean( DISABLE_MULTIPART_ATTACHMENTS, multipartEnabled );
801 	}
802 }