使用Axis2 java客户端访问.NET服务:SecurityContextToken不包含任何sp:IncludeToken属性

时间:2018-01-24 12:44:29

标签: java .net wcf axis2

我已经获得了wsdl并运行了axis2的bin / wsdl2java.sh来生成客户端存根。然后我按照文档通过

实例化存根
    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(ClientRepo, AxisConfig);

    IMSFeedManagerStub feed = new IMSFeedManagerStub(ctx, ServiceUrl);


    ServiceClient sc = feed._getServiceClient();

    sc.engageModule("rampart");

    Options options = sc.getOptions();
    options.setUserName("apache");
    options.setPassword("password");

(显然用户/密码是伪造的......)。

从我能解决的问题来看,这是好的。 WSDL声明应该有这样的令牌         <sp:SecureConversationToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">

根据我的理解,我需要使用wsHttpbinding(应该由rampart处理)和TransportWithMessageCredential,其中一部分包括获取&amp;在请求上传递令牌(我......想..我对WCF一般都是新手)。

但我得到的例外是

java.lang.IllegalArgumentException:SecurityContextToken不包含任何sp:IncludeToken属性     在org.apache.ws.secpolicy11.builders.SecureConversationTokenBuilder.build(SecureConversationTokenBuilder.java:39)〜[rampart-policy-1.7.1.jar:1.7.1]     在org.apache.ws.secpolicy11.builders.SecureConversationTokenBuilder.build(SecureConversationTokenBuilder.java:31)〜[rampart-policy-1.7.1.jar:1.7.1]     在org.apache.neethi.AssertionBuilderFactoryImpl.invokeBuilder(AssertionBuilderFactoryImpl.java:138)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.AssertionBuilderFactoryImpl.build(AssertionBuilderFactoryImpl.java:117)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:224)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyBuilder.getPolicyOperator(PolicyBuilder.java:174)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyBuilder.getPolicy(PolicyBuilder.java:124)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyEngine.getPolicy(PolicyEngine.java:100)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.ws.secpolicy11.builders.SupportingTokensBuilder.build(SupportingTokensBuilder.java:62)〜[rampart-policy-1.7.1.jar:1.7.1]     在org.apache.ws.secpolicy11.builders.SupportingTokensBuilder.build(SupportingTokensBuilder.java:39)〜[rampart-policy-1.7.1.jar:1.7.1]     在org.apache.neethi.AssertionBuilderFactoryImpl.invokeBuilder(AssertionBuilderFactoryImpl.java:138)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.AssertionBuilderFactoryImpl.build(AssertionBuilderFactoryImpl.java:117)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:224)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyBuilder.getAllOperator(PolicyBuilder.java:184)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:217)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyBuilder.getExactlyOneOperator(PolicyBuilder.java:180)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:215)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyBuilder.getPolicyOperator(PolicyBuilder.java:174)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyBuilder.getPolicy(PolicyBuilder.java:124)〜[neethi-3.0.3.jar:3.0.3]     在org.apache.neethi.PolicyEngine.getPolicy(PolicyEngine.java:111)〜[neethi-3.0.3.jar:3.0.3]

1 个答案:

答案 0 :(得分:0)

我相信我已经找到了答案:事实证明,WSDL的块在wsdl2java.sh生成的代码中保存为xml字符串。

然后在执行时重新解析这些(从我可以解决的问题)并将其作为Policy对象传递给更深层次的东西。问题是&#39; sp:IncludeToken&#39;属性没有从WSDL进入这个罐装字符串(或者在我的情况下没有),所以当它被解析(再次)时,找不到属性。

我的hacky解决方案是使用快速sed / find + replace将缺少的attr重新添加到字符串中。似乎现在更进一步。它还在破碎,但在一些完全不同的东西上:P