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