首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在java中发送带有"soap“的文件?

如何在java中发送带有"soap“的文件?
EN

Stack Overflow用户
提问于 2019-01-14 20:37:40
回答 1查看 84关注 0票数 0

我正在尝试用soap发送文件。但不知何故我失败了。帮助我,请给我下面的代码和我收到的错误。

公共空SendTest() {

代码语言:javascript
复制
    try {
        String filePath = "C:/test/fb344a10-713a-4e45-8810-6a82237947af.zip";
        String host = "https://test.efatura.gov.tr/earsiv/services/EArsivWsPort?wsdl";
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnectionFactory.createConnection();
        java.net.URL endpoint = new URL(host);
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        SOAPPart soapPart = message.getSOAPPart();
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
        soapEnvelope.addNamespaceDeclaration("EArsivWsService", "http://earsiv.vedop3.ggm.gov.org/");

        SOAPHeader header = message.getSOAPHeader();
        SOAPBody body = message.getSOAPBody();

        // QName qNameMethod=new QName("","sendDocumentFile","tns");
        // SOAPBodyElement bodyElement = (SOAPBodyElement)
        // body.addChildElement(qNameMethod);

        SOAPFactory soapFactory = SOAPFactory.newInstance();
        Name bodyName = soapFactory.createName("http://earsiv.vedop3.ggm.gov.org/", "tns", "sendDocumentFile");

        body.addChildElement(new QName("name","fb344a10-713a-4e45-8810-6a82237947af.zip"));
        URL url = new File(filePath).toURI().toURL();

        DataHandler dataHandler = new DataHandler(url);

        AttachmentPart attachment = message.createAttachmentPart(dataHandler);
        // attachment.setContentId("");

        message.addAttachmentPart(attachment);

        message.saveChanges();
        SOAPMessage response = connection.call(message, endpoint);
        ByteArrayOutputStream bOutput = new ByteArrayOutputStream(8192);
        response.writeTo(bOutput);
        String strResponse = bOutput.toString();// TODO use encoding for turkish
        System.out.println(strResponse);

    } catch (SOAPException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

错误响应:

代码语言:javascript
复制
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <soap:Fault>
      <faultcode xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">ns1:InvalidSecurity</faultcode>
      <faultstring>An error was discovered processing the &lt;wsse:Security> header</faultstring>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-22 15:55:56

SOAP消息应使用Wss签名

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54181717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档