gpt4 book ai didi

使用 Axiom 发送 SOAP 时出现 javax.xml.stream.XMLStreamException

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:18:14 26 4
gpt4 key购买 nike

我有以下代码

    final String METHOD="test";
final String PARAM1_VAL="Hello";
final String TARGET_EPR="http://bhanuka-TECRA-M11:8280/services/SoapToRestProxy";

SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
OMNamespace samplesNamespace = factory.createOMNamespace("http://services.samples/xsd", "m");
SOAPEnvelope envelope = factory.getDefaultEnvelope();


OMElement requestElement = factory.createOMElement("request", samplesNamespace);
OMElement methodElement = factory.createOMElement("method",samplesNamespace);
OMElement param1 = factory.createOMElement("val",samplesNamespace);

param1.setText(PARAM1_VAL);
methodElement.setText(METHOD);
requestElement.addChild(methodElement);
requestElement.addChild(param1);
envelope.getBody().addChild(requestElement);

try {
ServiceClient serviceClient = new ServiceClient();
Options options = new Options();
options.setTo(new EndpointReference(TARGET_EPR));
serviceClient.setOptions(options);

OMElement response = serviceClient.sendReceive(envelope);
System.out.println(response);
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
}

我正在做的是制作一个 SOAP 信封并将其发送到特定的端点。但是在 sendReceive 方法中,它抛出一个

javax.xml.stream.XMLStreamException: Can not output XML declaration, after other output has already been done.

我在这里做错了什么?有人请帮助我。

最佳答案

ServiceClient#sendReceive(OMElement) 不期望将 SOAPEnvelope 作为输入,而是 SOAP 主体的内容。您应该传递 requestElement,而不是传递给它 envelope

关于使用 Axiom 发送 SOAP 时出现 javax.xml.stream.XMLStreamException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32181860/

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