gpt4 book ai didi

java - 如何在 Java 中将字符串转换为 SOAPMessage?

转载 作者:太空狗 更新时间:2023-10-29 22:37:48 25 4
gpt4 key购买 nike

我想知道有什么方法可以将字符串转换为 SOAPMessage 吗?

假设我有一个字符串如下:

String send = "<soap:Envelope xmlns:mrns0=\"http://sdp.SOMETHING.com/mapping/TSO\" xmlns:sdp=\"http://sdp.SOMETHING.com.tr/mapping/generated\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
+ "<soap:Header>"
+ "<sdp:token>"
+ "<sdp:sessionId>" + sessionId + "</sdp:sessionId>"
+ "</sdp:token>"
+ "<sdp:transaction-list>"
+ "<sdp:transaction-id>" + 11 + "</sdp:transaction-id>"
+ "</sdp:transaction-list>"
+ "</soap:Header>"
+ "<soap:Body>"
+ "<sdp:SendSMSInput>"
+ "<sdp:EXPIRY_DATE>" + extime + "</sdp:EXPIRY_DATE>"
+ "<sdp:MESSAGE_CLASS>0</sdp:MESSAGE_CLASS>"
+ "<sdp:S_DATE>" + time + "</sdp:S_DATE>"
+ "<sdp:SHORT_NUMBER>1905</sdp:SHORT_NUMBER>"
+ "<sdp:SRC_MSISDN>" + numSend + "</sdp:SRC_MSISDN>"
+ "<sdp:TO_RECEIVERS>"
+ "<sdp:msisdn>" + numSend + "</sdp:msisdn>"
+ "</sdp:TO_RECEIVERS>"
+ "<sdp:MESSAGE_BODY>"
+ "<sdp:message>Message body here.</sdp:message>"
+ "</sdp:MESSAGE_BODY>"
+ "</sdp:SendSMSInput>"
+ "</soap:Body>"
+ "</soap:Envelope>";

如何转换字符串?

最佳答案

将字符串转换为输入流,然后将其读入 SOAP 消息工厂。

InputStream is = new ByteArrayInputStream(send.getBytes());
SOAPMessage request = MessageFactory.newInstance().createMessage(null, is);

You can read about how to do this here.

关于java - 如何在 Java 中将字符串转换为 SOAPMessage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13614508/

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