Отправка файла в защищенный веб-сервис SOAP

Мне нужно написать клиент, который вызывает веб-службу SOAP. Мне дают wsdl и SOAP request. Это защищенная веб-служба, и файл в виде вложения передается службе. Я протестировал ее с помощью SOAP UI, но мне нужно написать программу Java для вызова службы.

Вот wsdl

<definitions xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://xmlns.oracle.com/integration/b2b" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" name="WS_VT_SECURED_INBOUND" targetNamespace="http://xmlns.oracle.com/integration/b2b">
<types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/integration/b2b">
<element name="TransportFileRequest">
<complexType>
<sequence>
<element minOccurs="1" name="FileName" type="string"/>
<element minOccurs="1" name="FileType" type="string"/>
<element maxOccurs="1" minOccurs="1" name="messageID" type="string"/>
<element maxOccurs="1" minOccurs="1" name="senderID" type="string"/>
<element maxOccurs="1" minOccurs="1" name="checksum" type="string"/>
<element maxOccurs="1" minOccurs="1" name="timestamp" type="string"/>
<element maxOccurs="1" minOccurs="1" name="transportVersion" type="string"/>
<element maxOccurs="1" minOccurs="1" name="payload" type="anyType"/>
</sequence>
</complexType>
</element>
<element name="TransportFileResponse">
<complexType>
<sequence>
<element maxOccurs="1" minOccurs="1" name="Status" type="string"/>
<element maxOccurs="unbounded" minOccurs="0" name="ErrorMessage" type="string"/>
</sequence>
</complexType>
</element>
<element name="error" type="string"/>
</schema>
</types>
<message name="TransportFileResponseMessage">
<part name="FileTransportResponse" element="tns:TransportFileResponse"></part>
</message>
<message name="faultMessage">
<part name="faultMessage" element="tns:error"></part>
</message>
<message name="TransportFileRequestMessage">
<part name="FileTransportRequest" element="tns:TransportFileRequest"></part>
</message>
<portType name="TransportFilePort">
<operation name="sendFile">
<input message="tns:TransportFileRequestMessage"></input>
<output message="tns:TransportFileResponseMessage"></output>
<fault name="faultMessage" message="tns:faultMessage"></fault>
</operation>
</portType>
<binding name="TransportFilePortBinding" type="tns:TransportFilePort">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sendFile">
<soap:operation soapAction="sendFile" style="document"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="faultMessage">
<soap:fault name="faultMessage" use="literal"/>
</fault>
</operation>
</binding>
<service name="receiveFile_WS_VT_SECURED_INBOUND">
<port name="TransportFilePort_pt" binding="tns:TransportFilePortBinding">
<soap:address location="https://hostname:9443/wsx/services/receiveFile_WS_VT_SECURED_INBOUND"/>
</port>
</service>
</definitions>

А вот так выглядит SOAP-запрос

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:b2b="http://xmlns.oracle.com/integration/b2b">
   <soapenv:Header/>
   <soapenv:Body>
      <b2b:TransportFileRequest>
          <b2b:FileName>120_VERMONT_ACH_Sanity11march1.dat</b2b:FileName>
         <b2b:FileType>120</b2b:FileType>
         <b2b:MessageID>3454</b2b:MessageID>
         <b2b:SenderID>ekrjekrj</b2b:SenderID>
         <b2b:checksum>b2ee8af554ab6933085d341b71765bc8</b2b:checksum>
         <b2b:timestamp>3434</b2b:timestamp>
         <b2b:transportServiceVersion>4343</b2b:transportServiceVersion>
         <b2b:payload>120_VERMONT_ACH_Sanity11march1.dat</b2b:payload>
      </b2b:TransportFileRequest>
   </soapenv:Body>
</soapenv:Envelope>

В приведенном выше вложении файла

<b2b:payload>120_VERMONT_ACH_Sanity11march1.dat</b2b:payload>

Я знаю, что это можно сделать несколькими способами, например, с помощью библиотеки apache http client или любой другой. Но я никогда не работал с веб-сервисом, поэтому мало что о нем знаю. Хотя я начал с http-клиента apache, но не смог этого сделать. Для проблемы с Apache я разместил один вопрос https://stackoverflow.com/questions/22658949/sending-file-to-secured-soap-web-service-using-apache-http-client, но решения пока нет. Нет принуждения, что то же самое должно быть достигнуто с помощью http-клиента apache.

Пожалуйста, дайте мне знать, как я могу это сделать?


person Anand    schedule 27.03.2014    source источник


Ответы (1)


Используйте инфраструктуру, совместимую с JAX-WS, например Axis или CXF и следуйте нисходящему подходу.

Эти платформы предоставляют инструменты, которые помогут вам создать правильные классы клиента Java, начиная с WSDL.

Если вы хотите использовать HTTP-клиент, вам придется самостоятельно обрабатывать конверты SOAP, используя классы в java.xml.soap. См. SOAPMessage.

person Bruno Grieder    schedule 27.03.2014