root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / protocols / HTTPPostProtocol.java @ 6078
History | View | Annotate | Download (3.03 KB)
1 | 3566 | jorpiell | |
---|---|---|---|
2 | 2820 | jorpiell | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 | *
|
||
4 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
19 | *
|
||
20 | * For more information, contact:
|
||
21 | *
|
||
22 | * Generalitat Valenciana
|
||
23 | * Conselleria d'Infraestructures i Transport
|
||
24 | * Av. Blasco Ib??ez, 50
|
||
25 | * 46010 VALENCIA
|
||
26 | * SPAIN
|
||
27 | *
|
||
28 | * +34 963862235
|
||
29 | * gvsig@gva.es
|
||
30 | * www.gvsig.gva.es
|
||
31 | *
|
||
32 | * or
|
||
33 | *
|
||
34 | * IVER T.I. S.A
|
||
35 | * Salamanca 50
|
||
36 | * 46005 Valencia
|
||
37 | * Spain
|
||
38 | *
|
||
39 | * +34 963163400
|
||
40 | * dac@iver.es
|
||
41 | */
|
||
42 | 2047 | luisw | package es.gva.cit.catalogClient.protocols; |
43 | 3613 | jorpiell | import es.gva.cit.catalogClient.metadataXML.XMLTree; |
44 | 2724 | jorpiell | import java.io.ByteArrayInputStream; |
45 | 3081 | jorpiell | import java.io.IOException; |
46 | 2724 | jorpiell | import java.io.InputStream; |
47 | 3081 | jorpiell | import java.io.OutputStreamWriter; |
48 | 3613 | jorpiell | import java.net.HttpURLConnection; |
49 | 2724 | jorpiell | import java.net.URL; |
50 | 3566 | jorpiell | import java.util.Collection; |
51 | 2047 | luisw | |
52 | /**
|
||
53 | 3108 | jorpiell | * This class implement the HTTP Post protocol.
|
54 | 2820 | jorpiell | *
|
55 | 3566 | jorpiell | *
|
56 | 2820 | jorpiell | * @author Jorge Piera Llodra (piera_jor@gva.es)
|
57 | 2047 | luisw | */
|
58 | public class HTTPPostProtocol implements IProtocols { |
||
59 | |||
60 | 3566 | jorpiell | /**
|
61 | *
|
||
62 | *
|
||
63 | *
|
||
64 | * @return
|
||
65 | * @param url
|
||
66 | * @param message
|
||
67 | * @param firstRecord
|
||
68 | */
|
||
69 | public Collection doQuery(URL url, Object message, int firstRecord) { |
||
70 | 3081 | jorpiell | String body = (String) message; |
71 | 2724 | jorpiell | ByteArrayInputStream output = null; |
72 | 3597 | jorpiell | |
73 | 2724 | jorpiell | try {
|
74 | 3081 | jorpiell | HttpURLConnection c = (HttpURLConnection) url.openConnection(); |
75 | 4238 | jorpiell | |
76 | c.setRequestProperty("SOAPAction","post"); |
||
77 | 3597 | jorpiell | c.setRequestMethod("POST");
|
78 | 4238 | jorpiell | c.setDoOutput(true);
|
79 | 3597 | jorpiell | c.setRequestProperty("Content-Type", "text/xml; charset=UTF-8"); |
80 | |||
81 | 3116 | jorpiell | |
82 | 3597 | jorpiell | |
83 | 3081 | jorpiell | // Write the request.
|
84 | OutputStreamWriter w =
|
||
85 | new OutputStreamWriter(c.getOutputStream(), "UTF-8"); |
||
86 | 3116 | jorpiell | |
87 | 3081 | jorpiell | w.write(body); |
88 | 3116 | jorpiell | w.flush(); |
89 | |||
90 | InputStream is = c.getInputStream();
|
||
91 | byte[] buf = new byte[1024]; |
||
92 | int len;
|
||
93 | String str = ""; |
||
94 | |||
95 | while ((len = is.read(buf)) > 0) { |
||
96 | str = str + new String(buf, 0, len); |
||
97 | } |
||
98 | 3081 | jorpiell | |
99 | 3116 | jorpiell | System.out.println(str);
|
100 | output = new ByteArrayInputStream(str.getBytes()); |
||
101 | 3081 | jorpiell | |
102 | } catch (IOException e) { |
||
103 | // TODO Auto-generated catch block
|
||
104 | 3117 | jorpiell | //e.printStackTrace();
|
105 | 2724 | jorpiell | return null; |
106 | 3081 | jorpiell | } |
107 | |||
108 | 3566 | jorpiell | Collection col = new java.util.ArrayList(); |
109 | col.add(XMLTree.xmlToTree(output)); |
||
110 | return col;
|
||
111 | 3081 | jorpiell | |
112 | 3566 | jorpiell | } |
113 | } |