svn-gvsig-desktop / tags / v1_0_2_Build_909 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / protocols / SOAPProtocol.java @ 11150
History | View | Annotate | Download (4.48 KB)
1 | 3566 | jorpiell | |
---|---|---|---|
2 | 3593 | jorpiell | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 | 2820 | jorpiell | *
|
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 | 3593 | jorpiell | * Av. Blasco Ib??ez, 50
|
25 | 2820 | jorpiell | * 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 | 3566 | jorpiell | import java.io.BufferedReader; |
45 | import java.io.ByteArrayInputStream; |
||
46 | import java.io.File; |
||
47 | import java.io.FileWriter; |
||
48 | import java.io.InputStream; |
||
49 | import java.net.URL; |
||
50 | import java.util.Collection; |
||
51 | import javax.xml.parsers.DocumentBuilder; |
||
52 | 2047 | luisw | import org.apache.soap.Constants; |
53 | import org.apache.soap.Envelope; |
||
54 | import org.apache.soap.SOAPException; |
||
55 | import org.apache.soap.messaging.Message; |
||
56 | import org.apache.soap.transport.SOAPTransport; |
||
57 | import org.apache.soap.util.xml.XMLParserUtils; |
||
58 | import org.w3c.dom.Document; |
||
59 | import org.xml.sax.InputSource; |
||
60 | |||
61 | /**
|
||
62 | 3566 | jorpiell | *
|
63 | *
|
||
64 | *
|
||
65 | 2820 | jorpiell | * @author Jorge Piera Llodra (piera_jor@gva.es)
|
66 | 2047 | luisw | */
|
67 | public class SOAPProtocol implements IProtocols { |
||
68 | 3566 | jorpiell | |
69 | /**
|
||
70 | *
|
||
71 | *
|
||
72 | *
|
||
73 | * @return
|
||
74 | * @param url
|
||
75 | * @param object
|
||
76 | * @param firstRecord
|
||
77 | */
|
||
78 | public Collection doQuery(URL url, Object object, int firstRecord) { |
||
79 | 2724 | jorpiell | String message = (String) object; |
80 | File fileAnswer = null; |
||
81 | 3566 | jorpiell | |
82 | 2724 | jorpiell | //get the envelope to send
|
83 | try {
|
||
84 | InputStream buffer = new ByteArrayInputStream(message.getBytes()); |
||
85 | DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
|
||
86 | Document doc = xdb.parse(new InputSource(buffer)); |
||
87 | if (doc == null) { |
||
88 | throw new SOAPException(Constants.FAULT_CODE_CLIENT, |
||
89 | "parsing error");
|
||
90 | } |
||
91 | Envelope msgEnv = Envelope.unmarshall(doc.getDocumentElement()); |
||
92 | // send the message
|
||
93 | Message msg = new Message();
|
||
94 | msg.send(url, "urn:this-is-the-action-uri", msgEnv);
|
||
95 | // receive whatever from the transport and dump it to the screen
|
||
96 | SOAPTransport st = msg.getSOAPTransport(); |
||
97 | BufferedReader br = st.receive();
|
||
98 | String line;
|
||
99 | //File to save the answer
|
||
100 | fileAnswer = new File("auxiliar"); |
||
101 | FileWriter fwAnswer = new FileWriter(fileAnswer); |
||
102 | fwAnswer.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
|
||
103 | //Process the answer
|
||
104 | while ((line = br.readLine()) != null) { |
||
105 | System.out.println(line);
|
||
106 | fwAnswer.write(line); |
||
107 | fwAnswer.flush(); |
||
108 | } |
||
109 | fwAnswer.close(); |
||
110 | 3566 | jorpiell | |
111 | |||
112 | 2724 | jorpiell | } catch (Exception e) { |
113 | return null; |
||
114 | } |
||
115 | 3566 | jorpiell | Collection col = new java.util.ArrayList(); |
116 | col.add(XMLTree.xmlToTree(fileAnswer)); |
||
117 | return col;
|
||
118 | } |
||
119 | 2724 | jorpiell | |
120 | 3566 | jorpiell | /**
|
121 | *
|
||
122 | *
|
||
123 | *
|
||
124 | * @return
|
||
125 | * @param url
|
||
126 | */
|
||
127 | public static boolean isProtocolSupported(URL url) { |
||
128 | 2724 | jorpiell | return true; |
129 | 3566 | jorpiell | } |
130 | 2724 | jorpiell | |
131 | 3566 | jorpiell | /**
|
132 | * This function returns a SOAP message
|
||
133 | *
|
||
134 | *
|
||
135 | * @return
|
||
136 | * @param message the XML message
|
||
137 | * @param schemas
|
||
138 | */
|
||
139 | public static String setSOAPMessage(String message, String[] schemas) { |
||
140 | 4238 | jorpiell | String soap = "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\" " + |
141 | "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" ;
|
||
142 | 3069 | jorpiell | if (schemas != null){ |
143 | for (int i=0 ; i<schemas.length ; i++){ |
||
144 | soap = soap + " " + schemas[i];
|
||
145 | } |
||
146 | } |
||
147 | soap = soap + ">";
|
||
148 | soap = soap + "<SOAP:Body>" + message + "</SOAP:Body>" + "</SOAP:Envelope>"; |
||
149 | return soap;
|
||
150 | |||
151 | 3566 | jorpiell | } |
152 | } |