我对 SOAP 还很陌生,并且正在努力创建对服务器的 SOAP POST 请求。我有以下示例请求:-
POST /sso/ArtifactResolver/metaAlias/assert-idp
HTTP/1.1
Host:xxx
Content-Type: text/xml
Content-Length:
SOAPAction:http://....
这是我的 SOAP 信封
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<samlp:ArtifactResolve
xmlns:samlp="xxxxxxxxxxxxxx"
xmlns="xxxxxxxxxxx"
ID="_6c3a4f8b9c2d"
25 March 2014 Page 30
(APPROVED – Version 1.1)
Version="2.0"
IssueInstant="2012-05-21T00:39:45Z">
<Issuer>https://www.xxxxxxxxxxxxxx</Issuer>
<Artifact>
AAQAABWFTOPhANZhf21nl9DmXsAkiSM0ocx7GdxUfXFttmS954 BP6Vb01I0=
</Artifact>
</samlp:ArtifactResolve>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
下面是我尝试使用的 java 代码:-
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapMsg = factory.createMessage();
SOAPPart part = soapMsg.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
SOAPBodyElement element = body.addBodyElement(envelope.createName("ArtifactResolve", "sampl", "xxxxxxxxxxxx"));
element.addChildElement("Issuer").addTextNode("xxxxxxxxxxx");
element.addChildElement("Artifact").addTextNode("xxxxxxxxxxxx");
element.setAttribute("xmlns", "xxxxxxxxxxxxx");
element.setAttribute("ID", "xxxxxxxxx");
element.setAttribute("Version", "2.0");
element.setAttribute("IssueInstant", "xxxxxxxxxx");
PostMethod post = new PostMethod("PUT Server Url");
// Request content will be retrieved directly from the input stream
post.setRequestEntity(entity);
// consult documentation for your web service
post.setRequestHeader("SOAPAction", "**what to put here????**");
// Get HTTP client
HttpClient httpclient = new HttpClient();
try {
int result = httpclient.executeMethod(post);
System.out.println(post.getResponseBodyAsString());
} finally {
// Release current connection to the connection pool once you are done
post.releaseConnection();
}
现在在上面的代码中哪里指定服务器 url? 其次是如何将完整的soap XML传递给post请求? 如何传递给定的顶部 POST 数据? SOAP 作用要给予什么?
抱歉,这些人买了,我对此完全陌生,所以不知道。 我尝试在互联网上寻找此内容,但没有帮助。
请帮帮我
谢谢...
最佳答案
按照示例中的建议,URL 端点位于 new PostMethod("xxx")
中。
该请求是使用 SOAPBodyElement element = body...
构建的。
SOAP 操作在您的 WSDL 中描述为绑定(bind)。
我建议你查看这个帖子SOAP request to WebService with java
关于java - 在 JAVA 中创建 SOAP POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33532841/