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 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.config.WsrmVersionTypeConfig;
24  import com.eviware.soapui.impl.wsdl.WsdlInterface;
25  import com.eviware.soapui.impl.wsdl.WsdlRequest;
26  import com.eviware.soapui.impl.wsdl.support.wsmc.WsmcInjection;
27  import com.eviware.soapui.impl.wsdl.support.wsrm.WsrmContainer;
28  import com.eviware.soapui.impl.wsdl.support.wsrm.WsrmSequence;
29  import com.eviware.soapui.impl.wsdl.support.wsrm.WsrmUtils;
30  import com.eviware.soapui.model.iface.Submit;
31  import com.eviware.soapui.model.iface.SubmitContext;
32  import com.eviware.soapui.model.iface.SubmitListener;
33  import com.eviware.soapui.support.components.SimpleBindingForm;
34  import com.eviware.soapui.support.editor.xml.XmlInspector;
35  
36  /*
37   *  soapUI, copyright (C) 2004-2010 eviware.com 
38   *
39   *  soapUI is free software; you can redistribute it and/or modify it under the 
40   *  terms of version 2.1 of the GNU Lesser General Public License as published by 
41   *  the Free Software Foundation.
42   *
43   *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
44   *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
45   *  See the GNU Lesser General Public License for more details at gnu.org.
46   */
47  
48  public class WsdlRequestWsrmInspector extends AbstractWsrmInspector implements XmlInspector, PropertyChangeListener,
49  		SubmitListener
50  {
51  	private final WsdlRequest request;
52  
53  	public WsdlRequestWsrmInspector( WsdlRequest request )
54  	{
55  		super( request );
56  
57  		request.addSubmitListener( this );
58  		this.request = request;
59  	}
60  
61  	public void buildContent( SimpleBindingForm form )
62  	{
63  		form.addSpace( 5 );
64  		form.appendCheckBox( "wsrmEnabled", "Enable WS-Reliable Messaging", "Enable/Disable WS-Reliable Messaging" );
65  		form.addSpace( 5 );
66  
67  		form.appendComboBox( "version", "WS-RM Version", new String[] { WsrmVersionTypeConfig.X_1_0.toString(),
68  				WsrmVersionTypeConfig.X_1_1.toString(), WsrmVersionTypeConfig.X_1_2.toString() },
69  				"The  property for managing WS-RM version" );
70  
71  		form.appendTextField( "ackTo", "Acknowledgment to",
72  				"The acknowledgment endpoint reference, will be generated if left empty" );
73  
74  		form.addSpace( 5 );
75  	}
76  
77  	public void propertyChange( PropertyChangeEvent arg0 )
78  	{
79  		// TODO Auto-generated method stub
80  
81  	}
82  
83  	public void afterSubmit( Submit submit, SubmitContext context )
84  	{
85  		WsrmContainer container = ( WsrmContainer )submit.getRequest();
86  		if( request.getWsrmConfig().isWsrmEnabled() && submit.getResponse() != null )
87  		{
88  			String content = submit.getResponse().getContentAsString();
89  			XmlOptions options = new XmlOptions();
90  			try
91  			{
92  				XmlObject xml = XmlObject.Factory.parse( content );
93  
94  				String namespaceDeclaration = "declare namespace wsrm='" + request.getWsrmConfig().getVersionNameSpace()
95  						+ "';";
96  				XmlObject result[] = xml.selectPath( namespaceDeclaration + "//wsrm:AcknowledgementRange", options );
97  
98  				if( result.length > 0 )
99  				{
100 					for( int i = 0; i < result.length; i++ )
101 					{
102 						String upper = result[i].selectAttribute( null, "Upper" ).getDomNode().getNodeValue();
103 						String lower = result[i].selectAttribute( null, "Lower" ).getDomNode().getNodeValue();
104 
105 						if( lower == upper )
106 						{
107 							Logger.getLogger( "wsrm" ).info(
108 									"Acknowledgment for message " + upper + " received for identifier: "
109 											+ request.getWsrmConfig().getSequenceIdentifier() );
110 						}
111 						else
112 						{
113 							Logger.getLogger( "wsrm" ).info(
114 									"Acknowledgment for messages " + lower + " to " + upper + " received for identifier: "
115 											+ request.getWsrmConfig().getSequenceIdentifier() );
116 						}
117 					}
118 				}
119 			}
120 			catch( XmlException e )
121 			{
122 				// TODO Auto-generated catch block
123 				e.printStackTrace();
124 			}
125 		}
126 		
127 		if( container.getWsrmConfig().isWsrmEnabled() )
128 		{
129 			WsdlInterface iface = request.getOperation().getInterface();
130 			WsrmUtils utils = new WsrmUtils( iface.getSoapVersion() );
131 			utils.closeSequence( request.getEndpoint(), iface.getSoapVersion(), request.getWsrmConfig()
132 					.getVersionNameSpace(), request.getWsrmConfig().getUuid(), request.getWsrmConfig()
133 					.getSequenceIdentifier(), 1l, request.getOperation() );
134 		}
135 	}
136 
137 	public boolean beforeSubmit( Submit submit, SubmitContext context )
138 	{
139 		WsrmContainer container = ( WsrmContainer )submit.getRequest();
140 		if( container.getWsrmConfig().isWsrmEnabled() )
141 		{
142 			WsdlInterface iface = request.getOperation().getInterface();
143 			WsrmUtils utils = new WsrmUtils( iface.getSoapVersion() );
144 
145 			WsrmSequence sequence = utils.createSequence( request.getEndpoint(), iface.getSoapVersion(), request
146 					.getWsrmConfig().getVersionNameSpace(), request.getWsrmConfig().getAckTo(), 0l, request.getOperation(),
147 					( ( WsdlRequest )submit.getRequest() ).getWsaConfig().getTo() );
148 
149 			request.getWsrmConfig().setSequenceIdentifier( sequence.getIdentifier() );
150 			request.getWsrmConfig().setUuid( sequence.getUuid() );
151 
152 			if( request.getWsrmConfig().getVersion() != WsrmVersionTypeConfig.X_1_0.toString() )
153 			{
154 				WsmcInjection receiveInjection = new WsmcInjection( request.getEndpoint(), request.getOperation(), iface
155 						.getSoapVersion(), request.getWsrmConfig().getUuid() );
156 				request.setAfterRequestInjection( receiveInjection );
157 			}
158 
159 		}
160 		return true;
161 	}
162 
163 }