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.support.editor.inspectors.wsrm;
14  
15  import java.beans.PropertyChangeEvent;
16  import java.beans.PropertyChangeListener;
17  
18  import org.apache.log4j.Logger;
19  import org.apache.xmlbeans.XmlException;
20  import org.apache.xmlbeans.XmlObject;
21  import org.apache.xmlbeans.XmlOptions;
22  
23  import com.eviware.soapui.impl.wsdl.WsdlRequest;
24  import com.eviware.soapui.model.iface.Submit;
25  import com.eviware.soapui.model.iface.SubmitContext;
26  import com.eviware.soapui.model.iface.SubmitListener;
27  import com.eviware.soapui.support.editor.xml.XmlInspector;
28  
29  public class WsdlRequestWsrmPiggybackInspector extends AbstractWsrmInspector implements XmlInspector,
30  		PropertyChangeListener, SubmitListener
31  {
32  
33  	private final WsdlRequest request;
34  
35  	protected WsdlRequestWsrmPiggybackInspector( WsdlRequest request )
36  	{
37  		super( request );
38  		request.addSubmitListener( this );
39  		this.request = request;
40  	}
41  
42  	public void propertyChange( PropertyChangeEvent arg0 )
43  	{
44  		// TODO Auto-generated method stub
45  
46  	}
47  
48  	public void afterSubmit( Submit submit, SubmitContext context )
49  	{
50  
51  		if( request.getWsrmConfig().isWsrmEnabled() )
52  		{
53  			String content = submit.getResponse().getContentAsString();
54  			XmlOptions options = new XmlOptions();
55  			try
56  			{
57  				XmlObject xml = XmlObject.Factory.parse( content );
58  
59  				String namespaceDeclaration = "declare namespace wsrm='" + request.getWsrmConfig().getVersionNameSpace()
60  						+ "';";
61  				XmlObject result[] = xml.selectPath( namespaceDeclaration + "//wsrm:AcknowledgementRange", options );
62  
63  				if( result.length > 0 )
64  				{
65  					for( int i = 0; i < result.length; i++ )
66  					{
67  						String upper = result[i].selectAttribute( null, "Upper" ).getDomNode().getNodeValue();
68  						String lower = result[i].selectAttribute( null, "Lower" ).getDomNode().getNodeValue();
69  
70  						if( lower == upper )
71  						{
72  							Logger.getLogger( "wsrm" ).info(
73  									"Acknowledgment for message " + upper + " received for identifier: "
74  											+ request.getWsrmConfig().getSequenceIdentifier() );
75  						}
76  						else
77  						{
78  							Logger.getLogger( "wsrm" ).info(
79  									"Acknowledgment for messages " + lower + " to " + upper + " received for identifier: "
80  											+ request.getWsrmConfig().getSequenceIdentifier() );
81  						}
82  					}
83  				}
84  			}
85  			catch( XmlException e )
86  			{
87  				// TODO Auto-generated catch block
88  				e.printStackTrace();
89  			}
90  		}
91  
92  	}
93  
94  	public boolean beforeSubmit( Submit submit, SubmitContext context )
95  	{
96  
97  		return true;
98  	}
99  
100 }