gpt4 book ai didi

java - 非法参数异常 : ProtectionToken is not a element

转载 作者:行者123 更新时间:2023-11-30 04:56:30 25 4
gpt4 key购买 nike

几个小时以来,我一直在努力解决 Axis2 和 Rampart 的问题。我已经在谷歌上进行了广泛的搜索,但尚未找到解决方案。我什至查看了源代码并使用调试器单步调试它。尽管这让我了解了错误及其原因,但它并没有让我更接近解决方案。

发生的错误是

java.lang.IllegalArgumentException: {http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}ProtectionToken is not a <wsp:Policy> element.
at org.apache.neethi.PolicyBuilder.getPolicyOperator(PolicyBuilder.java:177)
at org.apache.neethi.PolicyBuilder.getPolicy(PolicyBuilder.java:125)
at org.apache.neethi.PolicyEngine.getPolicy(PolicyEngine.java:102)
at org.apache.ws.secpolicy11.builders.SymmetricBindingBuilder.build(SymmetricBindingBuilder.java:41)
at org.apache.ws.secpolicy11.builders.SymmetricBindingBuilder.build(SymmetricBindingBuilder.java:36)
at org.apache.neethi.AssertionBuilderFactoryImpl.invokeBuilder(AssertionBuilderFactoryImpl.java:129)
at org.apache.neethi.AssertionBuilderFactoryImpl.build(AssertionBuilderFactoryImpl.java:110)
at org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:225)
at org.apache.neethi.PolicyBuilder.getAllOperator(PolicyBuilder.java:185)
at org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:218)
at org.apache.neethi.PolicyBuilder.getExactlyOneOperator(PolicyBuilder.java:181)
at org.apache.neethi.PolicyBuilder.processOperationElement(PolicyBuilder.java:216)
at org.apache.neethi.PolicyBuilder.getPolicyOperator(PolicyBuilder.java:175)
at org.apache.neethi.PolicyBuilder.getPolicy(PolicyBuilder.java:114)
at org.apache.neethi.PolicyBuilder.getPolicy(PolicyBuilder.java:100)
at org.apache.neethi.PolicyEngine.getPolicy(PolicyEngine.java:80)
at com.geometryit.blis.ablis.contentManagement.ContentManagementServiceStub.getPolicy(ContentManagementServiceStub.java:413)
at com.geometryit.blis.ablis.contentManagement.ContentManagementServiceStub.populateAxisService(ContentManagementServiceStub.java:57)
at com.geometryit.blis.ablis.contentManagement.ContentManagementServiceStub.<init>(ContentManagementServiceStub.java:108)
at com.geometryit.blis.ablis.contentManagement.ContentManagementServiceStub.<init>(ContentManagementServiceStub.java:97)
at com.geometryit.blis.production.Publish.init(Publish.java:214)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1133)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1087)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:996)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4834)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5155)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5150)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

虽然我以前使用过 Axis2,但我并不是这方面的专家,更不是 Rampart 方面的专家。我有一个现有的 Web 应用程序,它已被扩展以引入用于 Web 服务交互的客户端。我按照说明安装了 Axis2 v1.6.1 和 Rampart v1.6.1。我使用 WSDL2Java 脚本构建了客户端 Java 类,并将生成的类捆绑到一个 jar 中。然后,我将适当的 jar 和 Axis2 存储库添加到 Web 应用程序。 WSDL 和 XSD 包含在 http://mail-archives.apache.org/mod_mbox/axis-java-user/201112.mbox/%3C4B95BC7335A13A42AD0D23462F91AE6F615D057F41%40echo.geometryit.com%3E 的 wsdl.zip 附件中。(Axis2 用户邮件列表)附件位于页面底部。

初始化 Web 服务客户端的代码部分是

try
{
ConfigurationContext context = ConfigurationContextFactory.createConfigurationContextFromFileSystem(this.getWebInfPath() + "repository" );

**ablisContentManagementService = new ContentManagementServiceStub( context, "http://services.ablis.uat.business.gov.au/ContentManagement.svc" );

ServiceClient ablisContentManagementServiceClient = ablisContentManagementService._getServiceClient();

ablisContentManagementServiceClient.engageModule( "addressing" );
ablisContentManagementServiceClient.engageModule( "rampart" );

ablisAxisFault = null;
}
catch ( AxisFault af )
{
ablisContentManagementService = null;
ablisAxisFault = af;
af.printStackTrace();
}
catch ( Throwable t )
{
t.printStackTrace();
}

我知道 Rampart 未正确配置,但错误是在突出显示的行 (**) 处引发的。如果完成的话,这是在进行 Rampart 配置之前。

在调试中,我注意到 XML 作为 OMElement 实例传递给 SymmetricBindingBuilder.build() (请参阅堆栈跟踪)(为简洁起见,进行了删减)

<wsp:Policy>
<sp:ProtectionToken>
.
.
.
</sp:ProtectionToken>
.
.
.
</wsp:Policy>

从 SymmetricBindingBuilder.build() 中的代码来看,我认为 XML 应该是:

<sp:SymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:ProtectionToken>
.
.
.
</sp:ProtectionToken>
.
.
.
</wsp:Policy>
</sp:SymmetricBinding>

对传递的 XML 进行更改可以修复错误,但如何完成此操作。

为了简短起见,我的言论或行为可能有错误或遗漏。如果缺少重要细节,请突出显示这些细节。我熟悉 Axis2,但完全不熟悉 Rampart,因此非常感谢您的帮助。我很乐意回答问题。非常感谢任何帮助。

最佳答案

我猜您已经解决了这个问题。但对我来说,这是一个新鲜的、生硬的、发痒的伤口。经过几个小时的努力解决几乎完全相同的问题,我终于找到了解决方案。

在生成的客户端代码中,例如 ClientStub,有一个静态 getPolicy() 函数需要对此进行调整(调整空格以提高可读性):

private static org.apache.neethi.Policy getPolicy (java.lang.String policyString) 
{
java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(policyString.getBytes());
return org.apache.neethi.PolicyEngine.getPolicy(bais);
}

对此:

private static org.apache.neethi.Policy getPolicy (java.lang.String policyString) 
{
java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(policyString.getBytes());
try
{
StAXOMBuilder builder = new StAXOMBuilder(bais);
OMElement documentElement = builder.getDocumentElement();
return org.apache.neethi.PolicyEngine.getPolicy(documentElement);
}
catch (XMLStreamException e)
{
e.printStackTrace();
}
return null;
}

我在 this mail thread 中遇到了这个解决方案.

。托弗

关于java - 非法参数异常 : ProtectionToken is not a <wsp:Policy> element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8364193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com