Hello,
j'ai crée un web service qui contient une opération (une procédure). Celle-ci renvoit un tableau de pdf en binaire.
voici le code du service web:
voici le code client:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 @WebService(serviceName = "testWSBinaryPDF", wsdlLocation="WEB-INF/wsdl/TestWSBinaryPDF.wsdl") public class testWSBinaryPDF { private static final String[] FILES = {"monpdf2.pdf", "monpdf1.pdf"}; @WebMethod(operationName = "getPdf") public List<byte[]> getPdf() throws IOException { List<byte[]> files = new ArrayList<byte[]>(); for (String file:FILES) { URL resource = this.getClass().getResource("/pdf/ressources/"+file); InputStream in = resource.openStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1024] ; for(int read; (read = in.read(buf)) != -1;) { bos.write(buf); } files.add(bos.toByteArray()); } return files; } }
il faudrait que je récupère ces données binaire pour créer les pdfs reçu...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public static void main(String[] args) { DataOutputStream dos=null; FileOutputStream fos=null; try { // Call Web Service Operation pdf.binary.TestWSBinaryPDF_Service service = new pdf.binary.TestWSBinaryPDF_Service(); pdf.binary.TestWSBinaryPDF port = service.getTestWSBinaryPDFPort(); List<DataHandler> pdfs = port.getPdf(); int i=0; for (DataHandler pdf : pdfs) { fos=new FileOutputStream("C:\monpdf"+i+".pdf"); dos = new DataOutputStream(pdf.getOutputStream()); dos.writeByte(1024); dos.close(); //System.out.println(pdf.getOutputStream()); i++; } } catch (Exception ex) { System.out.println(ex.getStackTrace()); } }
Partager