root / tags / Root_v061 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / protocols / HTTPPostProtocol.java @ 4812
History | View | Annotate | Download (3.03 KB)
1 |
|
---|---|
2 |
/* 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 |
package es.gva.cit.catalogClient.protocols; |
43 |
import es.gva.cit.catalogClient.metadataXML.XMLTree; |
44 |
import java.io.ByteArrayInputStream; |
45 |
import java.io.IOException; |
46 |
import java.io.InputStream; |
47 |
import java.io.OutputStreamWriter; |
48 |
import java.net.HttpURLConnection; |
49 |
import java.net.URL; |
50 |
import java.util.Collection; |
51 |
|
52 |
/**
|
53 |
* This class implement the HTTP Post protocol.
|
54 |
*
|
55 |
*
|
56 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
57 |
*/
|
58 |
public class HTTPPostProtocol implements IProtocols { |
59 |
|
60 |
/**
|
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 |
String body = (String) message; |
71 |
ByteArrayInputStream output = null; |
72 |
|
73 |
try {
|
74 |
HttpURLConnection c = (HttpURLConnection) url.openConnection(); |
75 |
|
76 |
c.setRequestProperty("SOAPAction","post"); |
77 |
c.setRequestMethod("POST");
|
78 |
c.setDoOutput(true);
|
79 |
c.setRequestProperty("Content-Type", "text/xml; charset=UTF-8"); |
80 |
|
81 |
|
82 |
|
83 |
// Write the request.
|
84 |
OutputStreamWriter w =
|
85 |
new OutputStreamWriter(c.getOutputStream(), "UTF-8"); |
86 |
|
87 |
w.write(body); |
88 |
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 |
|
99 |
System.out.println(str);
|
100 |
output = new ByteArrayInputStream(str.getBytes()); |
101 |
|
102 |
} catch (IOException e) { |
103 |
// TODO Auto-generated catch block
|
104 |
//e.printStackTrace();
|
105 |
return null; |
106 |
} |
107 |
|
108 |
Collection col = new java.util.ArrayList(); |
109 |
col.add(XMLTree.xmlToTree(output)); |
110 |
return col;
|
111 |
|
112 |
} |
113 |
} |