1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.impl.wsdl.support.wsmc;
13
14 import org.apache.xmlbeans.XmlCursor;
15 import org.apache.xmlbeans.XmlException;
16 import org.apache.xmlbeans.XmlObject;
17
18 import com.eviware.soapui.SoapUI;
19 import com.eviware.soapui.config.HttpRequestConfig;
20 import com.eviware.soapui.config.WsaConfigConfig;
21 import com.eviware.soapui.config.WsrmConfigConfig;
22 import com.eviware.soapui.impl.support.wsa.WsaRequest;
23 import com.eviware.soapui.impl.wsdl.WsdlOperation;
24 import com.eviware.soapui.impl.wsdl.WsdlSubmitContext;
25 import com.eviware.soapui.impl.wsdl.submit.transports.http.support.methods.IAfterRequestInjection;
26 import com.eviware.soapui.impl.wsdl.support.soap.SoapMessageBuilder;
27 import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
28 import com.eviware.soapui.impl.wsdl.support.wsa.WsaConfig;
29 import com.eviware.soapui.impl.wsdl.support.wsa.WsaContainer;
30 import com.eviware.soapui.impl.wsdl.support.wsa.WsaContainerImpl;
31 import com.eviware.soapui.impl.wsdl.support.wsa.WsaUtils;
32 import com.eviware.soapui.impl.wsdl.support.wsrm.WsrmConfig;
33 import com.eviware.soapui.model.iface.Request.SubmitException;
34 import com.eviware.soapui.model.propertyexpansion.DefaultPropertyExpansionContext;
35
36 public class WsmcInjection implements IAfterRequestInjection
37 {
38
39 private static final String WSMC_ACTION = "http://docs.oasis-open.org/ws-rx/wsmc/200702/MakeConnection";
40 private static final String WSMC_NAMESPACE = "http://docs.oasis-open.org/ws-rx/wsmc/200702";
41
42 private String endpoint;
43 private WsdlOperation operation;
44 private SoapVersion soapVersion;
45 private String uuid;
46
47 public WsmcInjection( String endpoint, WsdlOperation operation, SoapVersion soapVersion, String uuid )
48 {
49 this.endpoint = endpoint;
50 this.operation = operation;
51 this.soapVersion = soapVersion;
52 this.uuid = uuid;
53 }
54
55 public String executeAfterRequest()
56 {
57
58 HttpRequestConfig httpRequestConfig = ( HttpRequestConfig )( XmlObject.Factory.newInstance()
59 .changeType( HttpRequestConfig.type ) );
60 httpRequestConfig.setEndpoint( endpoint );
61
62 WsaConfigConfig wsaConfigConfig = ( WsaConfigConfig )( XmlObject.Factory.newInstance()
63 .changeType( WsaConfigConfig.type ) );
64 WsaContainer wsaContainer = new WsaContainerImpl();
65 wsaContainer.setOperation( operation );
66 WsaConfig wsaConfig = new WsaConfig( wsaConfigConfig, wsaContainer );
67
68 WsrmConfigConfig wsrmConfigConfig = ( WsrmConfigConfig )( XmlObject.Factory.newInstance()
69 .changeType( WsrmConfigConfig.type ) );
70 WsrmConfig wsrmConfig = new WsrmConfig( wsrmConfigConfig, null );
71
72 WsaRequest makeConnectionRequest = new WsaRequest( httpRequestConfig, wsaConfig, wsrmConfig, false );
73 makeConnectionRequest.setOperation( operation );
74
75 String content = SoapMessageBuilder.buildEmptyMessage( soapVersion );
76
77 makeConnectionRequest.getWsaConfig().setWsaEnabled( true );
78 makeConnectionRequest.getWsaConfig().setAction( WSMC_ACTION );
79 makeConnectionRequest.getWsaConfig().setAddDefaultTo( true );
80 makeConnectionRequest.getWsaConfig().setGenerateMessageId( true );
81
82 try
83 {
84 XmlObject object = XmlObject.Factory.parse( content );
85 XmlCursor cursor = object.newCursor();
86
87 cursor.toFirstContentToken();
88 cursor.toFirstChild();
89 cursor.toNextSibling();
90
91 cursor.toNextToken();
92 cursor.insertNamespace( "wsmc", WSMC_NAMESPACE );
93
94 cursor.beginElement( "MakeConnection", WSMC_NAMESPACE );
95 cursor.beginElement( "Address", WSMC_NAMESPACE );
96 cursor.insertChars( WsaUtils.getNamespace( makeConnectionRequest.getWsaConfig().getVersion() ) + "/anonymous"
97 + "?id=" + uuid );
98
99 cursor.dispose();
100
101 makeConnectionRequest.getOperation().setAction( "" );
102 makeConnectionRequest.setRequestContent( object.xmlText() );
103
104 WsaUtils wsaUtils = new WsaUtils( object.xmlText(), soapVersion, makeConnectionRequest.getOperation(),
105 new DefaultPropertyExpansionContext( makeConnectionRequest ) );
106 content = wsaUtils.addWSAddressingRequest( makeConnectionRequest );
107
108 makeConnectionRequest.setRequestContent( content );
109 }
110 catch( XmlException e )
111 {
112
113 e.printStackTrace();
114 }
115
116 try
117 {
118 makeConnectionRequest.submit( new WsdlSubmitContext( null ), true );
119
120 }
121 catch( SubmitException e1 )
122 {
123 SoapUI.logError( e1 );
124 }
125
126 return null;
127 }
128
129 }