2017-09-08 1 views
0

SOAP 서비스를 사용하여 pdf 파일을 다운로드하려고합니다. wsdl 가져 오기에 몇 가지 문제가 있습니다. 따라서 스텁에 적절한 메서드가 없으며 Apache Axis 서비스 호출 메서드를 사용하여 파일을 다운로드하려고합니다. SOAPEnvelope 응답에서 byte [] 가져 오는 방법

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP-ENV:Header/> 
    <SOAP-ENV:Body> 
     <ns2:getFileStreamResponse xmlns:ns2="http://spring.io/guides/gs-producing-web-service"> 
      <ns2:FileByteStream>L1VzZXJzL3BrdW1hci9Eb2N1bWVudHMvTmFyZW5kcmFTaW5naC5wZGY=</ns2:FileByteStream> 
     </ns2:getFileStreamResponse> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

이것은 사용하려고하는 자바 코드입니다.

String SOAP_REQUEST = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" + 
      "\t\t\t\t xmlns:gs=\"http://spring.io/guides/gs-producing-web-service\">\n" + 
      " <soapenv:Header/>\n" + 
      " <soapenv:Body>\n" + 
      "  <gs:getFileStreamRequest>\n" + 
      "   <gs:id>12313</gs:id>\n" + 
      "   <gs:token>Ratakkdajd</gs:token>\n" + 
      "   <gs:path>/Users/pkumar/Documents/NarendraSingh.pdf</gs:path>\n" + 
      "  </gs:getFileStreamRequest>\n" + 
      " </soapenv:Body>\n" + 
      "</soapenv:Envelope>"; 

    String HOST_ADDRESS = "http://localhost:8080/ws"; 

    SOAPEnvelope resp = null; 
    try { 
     byte[] reqBytes = SOAP_REQUEST.getBytes(); 
     ByteArrayInputStream bis = new ByteArrayInputStream(reqBytes); 
     StreamSource ss = new StreamSource(bis); 
     MessageFactoryImpl messageFactory = new MessageFactoryImpl(); 
     SOAPMessage msg = messageFactory.createMessage(); 
     SOAPPart soapPart = msg.getSOAPPart(); 
     soapPart.setContent(ss); 
     Service service = new Service(); 
     org.apache.axis.client.Call call = (org.apache.axis.client.Call)service.createCall(); 
     call.setTargetEndpointAddress(HOST_ADDRESS); 
     call.setProperty(call.CHECK_MUST_UNDERSTAND, false); 
     resp = call.invoke(((org.apache.axis.SOAPPart)soapPart).getAsSOAPEnvelope()); 
     byte[] output = resp.getBodyElements().get(0).toString().getBytes(); 
     return output; 

    } catch (Exception ex) { 
     throw new Exception(ex.getMessage()); 
    } 

나는 SOAPEnvelope resp에서 byte[] FileByteStream을 얻을 수있는 방법을 찾을 수 없습니다. SOAP API를 사용하여 어떤 경험이든이 파일을 만들었습니까?

는 WSDL 가져 오기 내가 쉽게 일 동안 그것에 대해 진행 한 후이 코드

CountriesPortServiceLocator locator = new CountriesPortServiceLocator(); 
CountriesPort service = locator.getCountriesPortSoap11(new URL("http://localhost:8080/ws")); 
GetFileStreamRequest request = new GetFileStreamRequest(123, 
     "321323", 
     "remote_file_path.pdf"); 
GetFileStreamResponse response = service.getFileStream(request); 

byte[] fileStream = response.getFileByteStream(); 
new FileOutputStream("output.pdf").write(fileStream); 

답변

0

을 사용하여 파일을 다운로드 할 수 올바르게 작동하는 경우, 클라이언트에서 좋은 사람이 솔루션 나를 도왔다.

SOAPEnvelope 클래스 따라서 우리는 원래의 바이트 [얻기 위해 다시 디코딩해야 실제로 Byte64를 부호화 우리는 따라서 태그 (fileByteStream) 텍스트 노드의 문자열 표시로 이동할 수 이용한 방법 등 DOM 지원] .

//Invoke the WebService. 
SOAPEnvelope resp = call.invoke(((org.apache.axis.SOAPPart) soapPart).getAsSOAPEnvelope()); 
//Extract and decode the fileStream from the response 
byte[] output = Base64.decode(resp.getBody().getElementsByTagName("FileByteStream").item(0).getLastChild().getNodeValue()); 
관련 문제