简体   繁体   中英

How do i send the file with “soap” in java

I'm trying to send files with soap. but somehow I failed. Help me please gave me the codes below and the error I received.

public void SendTest() {

    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();
    }
}

Error response:

<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>

SOAP消息应使用Wss签名

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM