root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / protocols / SOAPProtocol.java @ 3073
History | View | Annotate | Download (4.36 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package es.gva.cit.catalogClient.protocols; |
42 |
|
43 |
import es.gva.cit.catalogClient.metadataXML.XMLNode; |
44 |
import es.gva.cit.catalogClient.metadataXML.XMLTree; |
45 |
|
46 |
import org.apache.soap.Constants; |
47 |
import org.apache.soap.Envelope; |
48 |
import org.apache.soap.SOAPException; |
49 |
import org.apache.soap.messaging.Message; |
50 |
import org.apache.soap.transport.SOAPTransport; |
51 |
import org.apache.soap.util.xml.XMLParserUtils; |
52 |
|
53 |
import org.w3c.dom.Document; |
54 |
|
55 |
import org.xml.sax.InputSource; |
56 |
|
57 |
import java.io.BufferedReader; |
58 |
import java.io.ByteArrayInputStream; |
59 |
import java.io.File; |
60 |
import java.io.FileWriter; |
61 |
import java.io.InputStream; |
62 |
|
63 |
import java.net.URL; |
64 |
|
65 |
import javax.xml.parsers.DocumentBuilder; |
66 |
|
67 |
|
68 |
/**
|
69 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
70 |
*/
|
71 |
public class SOAPProtocol implements IProtocols { |
72 |
public XMLNode[] doQuery(URL url, Object object, int firstRecord) { |
73 |
String message = (String) object; |
74 |
ByteArrayInputStream output = null; |
75 |
File fileAnswer = null; |
76 |
|
77 |
//Solo devuleve un nodo
|
78 |
XMLNode[] nodes = new XMLNode[1]; |
79 |
|
80 |
//get the envelope to send
|
81 |
try {
|
82 |
InputStream buffer = new ByteArrayInputStream(message.getBytes()); |
83 |
DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
|
84 |
Document doc = xdb.parse(new InputSource(buffer)); |
85 |
|
86 |
if (doc == null) { |
87 |
throw new SOAPException(Constants.FAULT_CODE_CLIENT, |
88 |
"parsing error");
|
89 |
} |
90 |
|
91 |
Envelope msgEnv = Envelope.unmarshall(doc.getDocumentElement()); |
92 |
|
93 |
// send the message
|
94 |
Message msg = new Message();
|
95 |
msg.send(url, "urn:this-is-the-action-uri", msgEnv);
|
96 |
|
97 |
// receive whatever from the transport and dump it to the screen
|
98 |
SOAPTransport st = msg.getSOAPTransport(); |
99 |
BufferedReader br = st.receive();
|
100 |
|
101 |
String line;
|
102 |
|
103 |
//File to save the answer
|
104 |
fileAnswer = new File("auxiliar"); |
105 |
|
106 |
FileWriter fwAnswer = new FileWriter(fileAnswer); |
107 |
|
108 |
fwAnswer.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
|
109 |
|
110 |
//Process the answer
|
111 |
while ((line = br.readLine()) != null) { |
112 |
System.out.println(line);
|
113 |
fwAnswer.write(line); |
114 |
fwAnswer.flush(); |
115 |
} |
116 |
|
117 |
fwAnswer.close(); |
118 |
|
119 |
nodes[0] = XMLTree.XMLToTree(fileAnswer);
|
120 |
|
121 |
if (nodes[0] == null) { |
122 |
nodes = null;
|
123 |
} |
124 |
} catch (Exception e) { |
125 |
return null; |
126 |
} |
127 |
|
128 |
return nodes;
|
129 |
} |
130 |
|
131 |
public static boolean isProtocolSupported(URL url) { |
132 |
return true; |
133 |
} |
134 |
|
135 |
/**
|
136 |
* This function returns a SOAP message
|
137 |
* @param message
|
138 |
* the XML message
|
139 |
* @return
|
140 |
*/
|
141 |
public static String setSOAPMessage(String message,String[] schemas) { |
142 |
String soap = "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\""; |
143 |
if (schemas != null){ |
144 |
for (int i=0 ; i<schemas.length ; i++){ |
145 |
soap = soap + " " + schemas[i];
|
146 |
} |
147 |
} |
148 |
soap = soap + ">";
|
149 |
soap = soap + "<SOAP:Body>" + message + "</SOAP:Body>" + "</SOAP:Envelope>"; |
150 |
return soap;
|
151 |
|
152 |
} |
153 |
} |