3030import org .apache .axis2 .client .ServiceClient ;
3131import org .apache .axis2 .client .Stub ;
3232import org .apache .axis2 .context .ConfigurationContext ;
33- import org .apache .axis2 .context .ConfigurationContextFactory ;
34- import org .junit .rules .ExternalResource ;
3533
36- public class ClientHelper extends ExternalResource {
34+ public class ClientHelper extends AbstractConfigurationContextRule {
3735 private final AbstractAxis2Server server ;
38- private final String repositoryPath ;
39- private ConfigurationContext configurationContext ;
4036
4137 public ClientHelper (AbstractAxis2Server server , String repositoryPath ) {
38+ super (repositoryPath );
4239 this .server = server ;
43- this .repositoryPath = repositoryPath ;
4440 }
4541
4642 public ClientHelper (AbstractAxis2Server server ) {
@@ -49,21 +45,15 @@ public ClientHelper(AbstractAxis2Server server) {
4945
5046 @ Override
5147 protected final void before () throws Throwable {
52- configurationContext =
53- ConfigurationContextFactory .createConfigurationContextFromFileSystem (repositoryPath );
48+ super .before ();
5449 SSLContext sslContext = server .getClientSSLContext ();
5550 if (sslContext != null ) {
56- configurationContext .setProperty (SSLContext .class .getName (), sslContext );
51+ getConfigurationContext () .setProperty (SSLContext .class .getName (), sslContext );
5752 }
5853 }
5954
60- @ Override
61- protected final void after () {
62- configurationContext = null ;
63- }
64-
6555 public final ServiceClient createServiceClient (String serviceName ) throws Exception {
66- ServiceClient serviceClient = new ServiceClient (configurationContext , null );
56+ ServiceClient serviceClient = new ServiceClient (getConfigurationContext () , null );
6757 serviceClient .getOptions ().setTo (server .getEndpointReference (serviceName ));
6858 configureServiceClient (serviceClient );
6959 return serviceClient ;
@@ -84,7 +74,7 @@ protected URLConnection openConnection(URL url) throws IOException {
8474 } else {
8575 handler = null ;
8676 }
87- ServiceClient serviceClient = new ServiceClient (configurationContext ,
77+ ServiceClient serviceClient = new ServiceClient (getConfigurationContext () ,
8878 new URL (null , server .getEndpoint (serviceName ) + "?wsdl" , handler ), wsdlServiceName , portName );
8979 configureServiceClient (serviceClient );
9080 return serviceClient ;
@@ -93,7 +83,7 @@ protected URLConnection openConnection(URL url) throws IOException {
9383 public final <T extends Stub > T createStub (Class <T > type , String serviceName ) throws Exception {
9484 T stub = type
9585 .getConstructor (ConfigurationContext .class , String .class )
96- .newInstance (configurationContext , server .getEndpoint (serviceName ));
86+ .newInstance (getConfigurationContext () , server .getEndpoint (serviceName ));
9787 configureServiceClient (stub ._getServiceClient ());
9888 return stub ;
9989 }
0 commit comments