View Javadoc

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