读取Axis2配置文件

时间:2017-09-18 08:05:34

标签: axis2 rampart

我正在尝试使用Axis2建立Web服务客户端连接。要设置UserameToken,我必须使用PasswordCallBack。

这是我的客户代码:

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());

这是我的conf结构:

enter image description here

在axis2.xml中,我使用javaranch

中的样本设置了我的密码回调

以下是一段代码:

<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>

我正在使用Maven生成客户端代码,而且一切顺利。

问题是当应用程序尝试在此行中创建ConfigurationContext时:

ConfigurationContextFactory.createConfigurationContextFromFileSystem(&#34; SRC /主/资源/轴&#34 ;, &#34; SRC /主/资源/轴/ CONF / axis2.xml&#34);

我得到如下的ClassNotFoundException:

  

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)     在   org.apache.axis2.deployment.AxisConfigBuilder.processPhaseOrders(AxisConfigBuilder.java:606)     在   org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisConfigBuilder.java:149)     在   org.apache.axis2.deployment.DeploymentEngine.populateAxisConfiguration(DeploymentEngine.java:629)     在   org.apache.axis2.deployment.FileSystemConfigurator.getAxisConfiguration(FileSystemConfigurator.java:116)     在   org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:64)     在   org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContextFromFileSystem(ConfigurationContextFactory.java:210)     在   au.com.jaycar.gateway.cybersourceClient.Sample.main(Sample.java:96)   引起: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 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 at   org.apache.axis2.util.Loader.loadClass(Loader.java:229)at   org.apache.axis2.deployment.util.Utils.loadHandler(Utils.java:114)     ......还有8个

我不确定它是否缺少库或配置。因为我确信它位于我的maven依赖项中的axis2-kernel中,否则源代码将不会被编译。

我的配置或类路径是否有任何问题。

1 个答案:

答案 0 :(得分:0)

我可以解决这个问题。我不需要加载axis2.xml和服务器模块。我删除了它们并使用了来自rampart样本的第一个示例代码中的policy.xml并将其加载到客户端选项中:

  

ConfigurationContext ctx =   ConfigurationContextFactory.createConfigurationContextFromFileSystem( “SRC /主/资源/轴”,   空值); TransactionProcessorStub stub = new   TransactionProcessorStub(ctx,SERVER_URL); ServiceClient客户端=   stub._getServiceClient();选项clientOptions = client.getOptions();   clientOptions.setProperty(WSHandlerConstants.USER,   request.getMerchantID()); StAXOMBuilder builder = new   StAXOMBuilder( “SRC /主/资源/轴/ CONF /的policy.xml”);政策   policy = PolicyEngine.getPolicy(builder.getDocumentElement());   clientOptions.setProperty(RampartMessageData.KEY_RAMPART_POLICY,   政策); client.setOptions(clientOptions);   client.engageModule( “垒”); stub._setServiceClient(客户端);   ReplyMessageDocument response = stub.runTransaction(document);