ClassNotFoundException in reading Axis2 config file

1.3k views Asked by At

I am trying to make a Web Service client connection using Axis2. To set UserameToken I must use PasswordCallBack.

Here is my client code:

ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("src/main/resources/axis", "src/main/resources/axis/conf/axis2.xml");

            TransactionProcessorStub stub = new TransactionProcessorStub(ctx, SERVER_URL);
            ServiceClient client = stub._getServiceClient();
            Options clientOptions = client.getOptions();
            clientOptions.setProperty(WSHandlerConstants.USER, request.getMerchantID());

Here is my conf structure:

enter image description here

And within axis2.xml I set my Password Callback using samples from javaranch

Here is a snippet of code:

<phaseOrder type="InFlow">
        <!--  System pre-defined phases       -->
         <phase name="Transport">
            <handler name="RequestURIBasedDispatcher"
                     class="org.apache.axis2.engine.RequestURIBasedDispatcher">
                <order phase="Transport"/>
            </handler>
            <handler name="SOAPActionBasedDispatcher"
                     class="org.apache.axis2.engine.SOAPActionBasedDispatcher">
                <order phase="Transport"/>
            </handler>
        </phase>
        <phase name="Security"/>
        <phase name="PreDispatch"/>
        <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase">
            <handler name="AddressingBasedDispatcher"
                     class="org.apache.axis2.engine.AddressingBasedDispatcher">
                <order phase="Dispatch"/>
            </handler>

            <handler name="SOAPMessageBodyBasedDispatcher"
                     class="org.apache.axis2.engine.SOAPMessageBodyBasedDispatcher">
                <order phase="Dispatch"/>
            </handler>
            <handler name="InstanceDispatcher"
                     class="org.apache.axis2.engine.InstanceDispatcher">
                <order phase="Dispatch"/>
            </handler>
        </phase>
        <!--  System pre defined phases       -->
        <!--   After Postdispatch phase module author or or service author can add any phase he want      -->
        <phase name="OperationInPhase"/>
    </phaseOrder>

I am using Maven to generate client code and and everything is going well with that.

The problem is when application tries to create ConfigurationContext in this line:

ConfigurationContextFactory.createConfigurationContextFromFileSystem("src/main/resources/axis", "src/main/resources/axis/conf/axis2.xml");

I get ClassNotFoundException as below:

org.apache.axis2.deployment.DeploymentException: org.apache.axis2.engine.RequestURIBasedDispatcher at org.apache.axis2.deployment.util.Utils.loadHandler(Utils.java:147) at org.apache.axis2.deployment.AxisConfigBuilder.processPhaseList(AxisConfigBuilder.java:575) at org.apache.axis2.deployment.AxisConfigBuilder.processPhaseOrders(AxisConfigBuilder.java:606) at org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisConfigBuilder.java:149) at org.apache.axis2.deployment.DeploymentEngine.populateAxisConfiguration(DeploymentEngine.java:629) at org.apache.axis2.deployment.FileSystemConfigurator.getAxisConfiguration(FileSystemConfigurator.java:116) at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:64) at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContextFromFileSystem(ConfigurationContextFactory.java:210) at au.com.jaycar.gateway.cybersourceClient.Sample.main(Sample.java:96) Caused by: java.lang.ClassNotFoundException: org.apache.axis2.engine.RequestURIBasedDispatcher at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at org.apache.axis2.util.Loader.loadClass(Loader.java:261) at org.apache.axis2.util.Loader.loadClass(Loader.java:229) at org.apache.axis2.deployment.util.Utils.loadHandler(Utils.java:114) ... 8 more

I am not sure it is about missing library or configuration. Because I am sure it is in axis2-kernel which is in my maven dependencies, Otherwise source code wont be compiled.

Is there any issue with my configuration or classpath.

1

There are 1 answers

0
Mehdi On

I could fix the issue. I didn't need to load axis2.xml and also server module. I removed both of them and I used policy.xml from the first sample code from rampart samples and load it into Client Options:

ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("src/main/resources/axis", null); TransactionProcessorStub stub = new TransactionProcessorStub(ctx, SERVER_URL); ServiceClient client = stub._getServiceClient(); Options clientOptions = client.getOptions(); clientOptions.setProperty(WSHandlerConstants.USER, request.getMerchantID()); StAXOMBuilder builder = new StAXOMBuilder("src/main/resources/axis/conf/policy.xml"); Policy policy = PolicyEngine.getPolicy(builder.getDocumentElement()); clientOptions.setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy); client.setOptions(clientOptions); client.engageModule("rampart"); stub._setServiceClient(client); ReplyMessageDocument response = stub.runTransaction(document);