soap 相关问题

简单对象访问协议(SOAP)是用于在Web服务的实现中交换结构化信息的协议规范。

从 Oracle pl/sql 调用 Soap Web 服务出现错误

当我调用 SOAP 服务时,出现“ORA-29266:已到达正文末尾”错误。我使用公共测试 api 测试我的脚本”,例如 http://www.dataaccess.com/webservicesserver/NumberConversion.wso&qu...

回答 1 投票 0

将SoapHeader添加到org.springframework.ws.WebServiceMessage

如何将对象添加到 org.springframework.ws.WebServiceMessage 的肥皂头中 这是我希望最终得到的结构: 如何将对象添加到org.springframework.ws.WebServiceMessage的soap标头中 这是我希望最终得到的结构: <soap:Header> <credentials xmlns="http://example.com/auth"> <username>username</username> <password>password</password> </credentials> </soap:Header> 基本上,您需要在客户端中使用 WebServiceMessageCallback 在消息创建之后、发送之前修改消息。 @skaffman 已经非常准确地描述了其余代码,因此整个内容可能如下所示: public void marshalWithSoapActionHeader(MyObject o) { webServiceTemplate.marshalSendAndReceive(o, new WebServiceMessageCallback() { public void doWithMessage(WebServiceMessage message) { try { SoapMessage soapMessage = (SoapMessage)message; SoapHeader header = soapMessage.getSoapHeader(); StringSource headerSource = new StringSource("<credentials xmlns=\"http://example.com/auth\">\n + <username>"+username+"</username>\n + <password>"+password"+</password>\n + </credentials>"); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(headerSource, header.getResult()); } catch (Exception e) { // exception handling } } }); } 就我个人而言,我发现 Spring-WS 很难满足这样的基本需求,他们应该修复 SWS-479。 您可以执行以下操作: public class SoapRequestHeaderModifier implements WebServiceMessageCallback { private final String userName = "user"; private final String passWd = "passwd"; @Override public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException { if (message instanceof SaajSoapMessage) { SaajSoapMessage soapMessage = (SaajSoapMessage) message; MimeHeaders mimeHeader = soapMessage.getSaajMessage().getMimeHeaders(); mimeHeader.setHeader("Authorization", getB64Auth(userName, passWd)); } } private String getB64Auth(String login, String pass) { String source = login + ":" + pass; String retunVal = "Basic " + Base64.getUrlEncoder().encodeToString(source.getBytes()); return retunVal; } } 然后 Object response = getWebServiceTemplate().marshalSendAndReceive(request, new SoapRequestHeaderModifier()); 您需要将 WebServiceMessage 转换为 SoapMessage,其中有一个 getSoapHeader() 方法可用于修改标题。反过来,SoapHeader有各种添加元素的方法,包括getResult()(可以用作Transformer.transform()操作的输出)。 I tried many options and finally below one worked for me if you have to send soap header with authentication(Provided authentication object created by wsimport) and also need to set soapaction. public Response callWebService(String url, Object request) { Response res = null; log.info("The request object is " + request.toString()); try { res = (Response) getWebServiceTemplate().marshalSendAndReceive(url, request,new WebServiceMessageCallback() { @Override public void doWithMessage(WebServiceMessage message) { try { // get the header from the SOAP message SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader(); // create the header element ObjectFactory factory = new ObjectFactory(); Authentication auth = factory.createAuthentication(); auth.setUser("****"); auth.setPassword("******"); ((SoapMessage) message).setSoapAction( "soapAction"); JAXBElement<Authentication> headers = factory.createAuthentication(auth); // create a marshaller JAXBContext context = JAXBContext.newInstance(Authentication.class); Marshaller marshaller = context.createMarshaller(); // marshal the headers into the specified result marshaller.marshal(headers, soapHeader.getResult()); } catch (Exception e) { log.error("error during marshalling of the SOAP headers", e); } } }); } catch (Exception e) { e.printStackTrace(); } return res; } 您也可以通过创建子元素的键值映射来实现: final Map<String, String> elements = new HashMap<>(); elements.put("username", "username"); elements.put("password", "password"); 在soap标头中设置子元素的命名空间和前缀: final String LOCAL_NAME = "credentials"; final String PREFIX = ""; final String NAMESPACE = "http://example.com/auth"; 然后,您可以调用 WebServiceTemplate 的方法 marshalSendAndReceive,在其中重写 WebServiceMessageCallback 的方法 doWithMessage,如下所示: Object response = getWebServiceTemplate().marshalSendAndReceive(request, (message) -> { if (message instanceof SaajSoapMessage) { SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message; SOAPMessage soapMessage = saajSoapMessage.getSaajMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); if (Objects.nonNull(elements)) { try { SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPHeader soapHeader = soapEnvelope.getHeader(); Name headerElementName = soapEnvelope.createName( LOCAL_NAME, PREFIX, NAMESPACE ); SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(headerElementName); elements.forEach((key, value) -> { try { SOAPElement element = soapHeaderElement.addChildElement(key, PREFIX); element.addTextNode(value); } catch (SOAPException e) { // error handling } }); soapMessage.saveChanges(); } catch (SOAPException e) { // error handling } } } }); 上述步骤导致: <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> <env:Header> <credentials xmlns="http://example.com/auth"> <password>password</password> <username>username</username> </credentials> </env:Header> <env:Body> <!-- your payload --> </env:Body> </env:Envelope> Response response = (Response)getWebServiceTemplate() .marshalSendAndReceive(request, new HeaderModifier()); 创建类 HeaderModifier 并重写 doWithMessage public class HeaderModifier implements WebServiceMessageCallback { private static PrintStream out = System.out; @Override public void doWithMessage(WebServiceMessage message) throws IOException { SaajSoapMessage soapMessage = (SaajSoapMessage) message; SoapEnvelope soapEnvelope = soapMessage.getEnvelope(); SoapHeader soapHeader = soapEnvelope.getHeader(); //Initialize QName for Action and To QName action = new QName("{uri}","Action","{actionname}"); QName to = new QName("{uri}","To","{actionname}"); soapHeader.addNamespaceDeclaration("{actionname}", "{uri}"); SoapHeaderElement soapHeaderElementAction = soapHeader.addHeaderElement(action); SoapHeaderElement soapHeaderElementTo = soapHeader.addHeaderElement(to); soapHeaderElementAction.setText("{text inside the tags}"); soapHeaderElementTo.setText("{text inside the tags}"); soapMessage.setSoapAction("{add soap action uri}"); soapMessage.writeTo(out); } }

回答 6 投票 0

哈希值不匹配

我得到回复:哈希值不匹配。 我有以下代码: 公共字符串SignSoapMessageVersion(字符串soapRequest,X509Certificate2证书) { RSA 私钥 = 证书。

回答 1 投票 0

让 REST 与 SOAP 通信

我有两个系统,一个(我们称之为 S1)公开 RESTful API(我们称之为 WS1),另一个系统(我们称之为 S2)公开 SOAP API(我们称之为 WS2)。 我正在尝试找出一个...

回答 2 投票 0

使用 Postman 的 SuiteTalk 条目未设置自定义字段

当使用 NetSuite 中的 SuiteTalk SOAP Web 服务创建记录时,我尝试使用用户事件脚本测试某些功能。我需要将一些值传递给一些自定义 fi...

回答 1 投票 0

CRUD 应用程序始终是网络世界中的 API 吗?

因为在大约 99.9% 的教程、帖子和论坛中,每当 CRUD 这个词出现时,“API”这个词就会立即跟随它,我无法找到我的疑问的答案:是每个网络

回答 1 投票 0

OpenAPI 3 显示 SOAP Web 服务

我目前正在编写 OpenAPI,以将 SOAP API 作为 REST API 显示在 swagger 上。 我目前正在使用公共 SOAP Web 服务并尝试使用 Java 应用程序进行转换...

回答 1 投票 0

将 Soap XML 响应转换为对象

我是使用 SOAP API 的新手 我有来自 API 的肥皂响应 我是 SOAP API 的新手 我有来自 API 的肥皂响应 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <LoginResponse xmlns="http://test.org/ADMail_Service"> <LoginResult> <ErrorMessage>Successful login</ErrorMessage> <Status>true</Status> </LoginResult> </LoginResponse> </soapenv:Body> </soapenv:Envelope> 我正在尝试将其转换为一个对象。 通过在线阅读文章,我尝试使用 JAXB 来执行此操作,但我的对象是空的。 这是读取响应的代码。我将响应写入 xml 文件以进行测试: try { XMLInputFactory xif = XMLInputFactory.newFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("input.xml")); xsr.nextTag(); // Advance to Envelope tag xsr.nextTag(); // Advance to Body tag xsr.nextTag(); xsr.nextTag(); JAXBContext jc = JAXBContext.newInstance(LoginResult.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); JAXBElement<LoginResult> je = unmarshaller.unmarshal(xsr, LoginResult.class); System.out.println(je.getName()); System.out.println(je.getValue()); } catch (XMLStreamException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } LoginResult班: public class LoginResult { private String errorMessage; private String status; public String getErrorMessage() { return errorMessage; } public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } } 提前致谢! 您可以使用此代码检索 POJO,还可以将 @XmlRootElement 作为标头添加到 POJO。 (我没有测试下面的代码) XMLInputFactory xif = XMLInputFactory.newFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("input.xml")); xsr.nextTag(); // Advance to Envelope tag xsr.nextTag(); // Advance to Body tag xsr.nextTag(); xsr.nextTag(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); StringWriter stringWriter = new StringWriter(); transformer.transform(new StAXSource(xsr), new StreamResult(stringWriter)); StringReader sr = new StringReader(stringWriter.toString()); JAXBContext jaxbContext = JAXBContext.newInstance(LoginResult.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); LoginResult loginResult = (LoginResult) unmarshaller.unmarshal(sr); 编辑: 我为你找到了解决方案: @XmlRootElement(name = "LoginResult", namespace = "http://test.org/ADMail_Service") @XmlAccessorType(XmlAccessType.FIELD) public class LoginResult { @XmlElement(name = "ErrorMessage", namespace = "http://test.org/ADMail_Service") private String errorMessage; @XmlElement(name = "Status", namespace = "http://test.org/ADMail_Service") private String status; public String getErrorMessage() { return errorMessage; } public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } } public static void main(String[] args) { try { XMLInputFactory xif = XMLInputFactory.newFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("input.xml")); xsr.nextTag(); // Advance to Envelope tag xsr.nextTag(); // Advance to Body tag xsr.nextTag(); xsr.nextTag(); JAXBContext jc = JAXBContext.newInstance(LoginResult.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); JAXBElement<LoginResult> je = unmarshaller.unmarshal(xsr, LoginResult.class); System.out.println(je.getName()); System.out.println(je.getValue()); System.out.println(je.getValue().getErrorMessage()); } catch (XMLStreamException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } } IMO,您应该考虑使用工具来处理 SOAP 消息,而不是自己处理。 示例: Java EE 5 教程:使用 JAX-WS 创建简单的 Web 服务和客户端 Spring Boot:使用 SOAP 消息 编辑 关于您的评论有一些话要说,所以我将我的答案放在这里。 首先, 我与 API 无关,我所做的只是发出 POST 请求... 您与 API 没有任何关系,但您向 API 发出 POST 请求。 我觉得这是一个比喻吧?... 并且没有 wsdl.... 通过这个小技巧,您几乎总能获得 SOAP Web 服务的 WSDL。只需在 SOAP Web 服务 URL 末尾添加 ?wsdl。 示例: 这是网络上 SOAP Web 服务的 URL(真实的):http://www.webservicex.com/stockquote.asmx 您可以像这样获取它的 WSDL :http://www.webservicex.com/stockquote.asmx?wsdl 所以唯一的选择是解析响应 IMO,软件开发中的问题几乎总是有不止一种解决方案。 有时,我发现了这段用于将soapxml对象解析为java对象的代码。 private <T> T getJavaObjectFromSoapXml(String responseFilePath, Class<T> clazz) { try { XMLInputFactory xif = XMLInputFactory.newFactory(); StreamSource xml = new StreamSource(getClass().getResourceAsStream(responseFilePath)); XMLStreamReader xsr = xif.createXMLStreamReader(xml); xsr.nextTag(); while (!xsr.getLocalName().equalsIgnoreCase(clazz.getSimpleName())) { xsr.nextTag(); } JAXBContext jc = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = jc.createUnmarshaller(); JAXBElement<T> je = unmarshaller.unmarshal(xsr, clazz); return je.getValue(); } catch (Exception e) { e.printStackTrace(); return null; } } public <T> T getJavaObjectFromSoapXml(String response, Class<T> clazz) { try { XMLInputFactory xif = XMLInputFactory.newFactory(); StreamSource xml = new StreamSource(response); XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(response)); xsr.nextTag(); while (!xsr.getLocalName().equalsIgnoreCase(clazz.getSimpleName())) { log.info("TAG :{}",xsr.nextTag()); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); StringWriter stringWriter = new StringWriter(); transformer.transform(new StAXSource(xsr), new StreamResult(stringWriter)); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(stringWriter.toString()))); JAXBContext jaxbContext = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); T t = (T) unmarshaller.unmarshal(document); return t; } catch (Exception e) { e.printStackTrace(); return null; } } public static <T> T unmarshallSoapResponse(final byte[] soapMessage, Class<T> clazz) throws IOException, SOAPException, JAXBException { SOAPMessage message = MessageFactory.newInstance().createMessage(null, new ByteArrayInputStream(soapMessage)); Unmarshaller unmarshaller = JAXBContext.newInstance(clazz).createUnmarshaller(); return (T) unmarshaller.unmarshal(message.getSOAPBody().extractContentAsDocument()); }

回答 5 投票 0

如何使用 ZEEP 更改 SOAP 请求中的端点地址

我正在使用 ZEEP 发出 SOAP 请求,它很简单并且效果很好。 问题在于端点 URL(在 WSDL 中)不正确。 我可以通过直接编辑 WSDL 来解决问题,但是......

回答 2 投票 0

如何使用Karate框架进行SOAP GET api调用?

如何使用Karate框架进行SOAP GET api调用? 我正在尝试寻找 KARATE 框架的示例来进行 GET SOAP api 调用。特征文件和步骤定义。 (我没有那么多

回答 1 投票 0

如何在Spring Boot中使用SOAP API?

我正在使用Springboot框架和eclipse。 我有相关服务的架构 xsd 和 wsdl 文件。 我从 xsd 和 wsdl 创建了 JAXB 类。 食用...的最佳方法是什么

回答 1 投票 0

如何从 WSDL 文件中提取soap:address?

我可以检查一下,如何使用Java从https://www.dataaccess.com/webservicesserver/NumberConversion.wso?WSDL检索soap:address元素? 我可以检查一下,如何使用Java从https://www.dataaccess.com/webservicesserver/NumberConversion.wso?WSDL?检索soap:address元素 <port name="NumberConversionSoap" binding="tns:NumberConversionSoapBinding"> **<soap:address location="https://www.dataaccess.com/webservicesserver/NumberConversion.wso"/>** </port> 我尝试使用javax.wsdl.Definition检查变量以查看soap:address的存储位置,但找不到它。 有人可以建议吗? 我目前正在使用 java 将 SOAP WS 转换为 REST OpenAPI 格式,使用 https://github.com/wso2/soap-to-rest 我设法在此网页中找到答案:https://vvratha.blogspot.com/2013/11/get-wsdl-service-address-with-wsdl4j.html 希望对其他人有用。

回答 1 投票 0

如何将 UPS API 集成从 Soap 转换为 Rest API?有人有一对一的对象映射吗?

我正在将 UPS API 的集成从soap 转换为rest API。 以前有人这样做过!

回答 1 投票 0

是否有使用 Spring、JSF、PrimeFaces、SOAP 和 MySQL 的现成模板项目? [已关闭]

这个问题说明了一切。因为我已经花了几周时间尝试在 Tomcat 或 Jetty 服务器中查看某些内容来尝试完成我的练习...... 我很绝望,我不知道如何确保每个

回答 1 投票 0

如何使用 C# 在 MS .Net 4.5 中设置 SOAP 调用超时

我需要考虑 SOAP 服务器的极其缓慢的响应。我已经使用 Visual Studio 2012 用 C# 语言添加了该服务,我真的希望能够轻松设置超时值...

回答 2 投票 0

SOAP 标头时间戳签名无效

SOAP 标头中的一个 SAML 签名无效。您可以在以下网站确认它失败:https://tools.chilkat.io/xmlDsigVerify.cshtml。我们尝试过排除故障,但没有成功。我们

回答 1 投票 0

使用 Python requests.post() 发送 XML Soap 请求

我确信我这样做是错误的,因为我对 Xml 或 SOAP 一无所知,但我正在尝试使用 Python requests.post() 发送 SOAP 请求。我想我可以把身体作为

回答 1 投票 0

Java,如何在springboot Java中使用Soap XML api?

我是Java世界的新手,我正在使用Springboot框架和Eclipse。 我有相关服务的架构 xsd 和 wsdl 文件。 我从 xsd 和 wsdl 创建了 JAXB 类。 什么会是最好的

回答 1 投票 0

是否有使用 J2EE、Spring、JSF、PrimeFaces、SOAP 和 MySQL 的现成模板项目?

这个问题说明了一切。因为我已经花了几周时间尝试在 Tomcat 或 Jetty 服务器中查看某些内容来尝试完成我的练习...... 我很绝望,我不知道如何确保每个

回答 1 投票 0

在 WSO2 ESB 中将 Rest API 作为 SOAP 公开

我有一个 Rest Api (Python/flask),它以 json 格式发送响应。 我需要使用 Soap 发布包含 3 个参数(主体)的请求,但我不了解 Soap,也不了解示例。 我可以...

回答 3 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.