Revision 3566 trunk/applications/appCatalogYNomenclatorClient/src/es/gva/cit/catalogClient/protocols/SOAPProtocol.java
SOAPProtocol.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
1 |
|
|
2 |
/* gvSIG. Sistema de Informaci??n Geogr??fica de la Generalitat Valenciana |
|
2 | 3 |
* |
3 | 4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
4 | 5 |
* |
... | ... | |
20 | 21 |
* |
21 | 22 |
* Generalitat Valenciana |
22 | 23 |
* Conselleria d'Infraestructures i Transport |
23 |
* Av. Blasco Ib��ez, 50
|
|
24 |
* Av. Blasco Ib????ez, 50
|
|
24 | 25 |
* 46010 VALENCIA |
25 | 26 |
* SPAIN |
26 | 27 |
* |
... | ... | |
39 | 40 |
* dac@iver.es |
40 | 41 |
*/ |
41 | 42 |
package es.gva.cit.catalogClient.protocols; |
42 |
|
|
43 |
import es.gva.cit.catalogClient.metadataXML.XMLNode; |
|
44 | 43 |
import es.gva.cit.catalogClient.metadataXML.XMLTree; |
45 |
|
|
44 |
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; |
|
46 | 52 |
import org.apache.soap.Constants; |
47 | 53 |
import org.apache.soap.Envelope; |
48 | 54 |
import org.apache.soap.SOAPException; |
49 | 55 |
import org.apache.soap.messaging.Message; |
50 | 56 |
import org.apache.soap.transport.SOAPTransport; |
51 | 57 |
import org.apache.soap.util.xml.XMLParserUtils; |
52 |
|
|
53 | 58 |
import org.w3c.dom.Document; |
54 |
|
|
55 | 59 |
import org.xml.sax.InputSource; |
56 | 60 |
|
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 | 61 |
/** |
62 |
* |
|
63 |
* |
|
64 |
* |
|
69 | 65 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
70 | 66 |
*/ |
71 | 67 |
public class SOAPProtocol implements IProtocols { |
72 |
public XMLNode[] doQuery(URL url, Object object, int firstRecord) { |
|
68 |
|
|
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) { |
|
73 | 79 |
String message = (String) object; |
74 | 80 |
File fileAnswer = null; |
75 |
|
|
76 |
//Solo devuleve un nodo |
|
77 |
XMLNode[] nodes = new XMLNode[1]; |
|
78 |
|
|
81 |
|
|
79 | 82 |
//get the envelope to send |
80 | 83 |
try { |
81 | 84 |
InputStream buffer = new ByteArrayInputStream(message.getBytes()); |
82 | 85 |
DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder(); |
83 | 86 |
Document doc = xdb.parse(new InputSource(buffer)); |
84 |
|
|
85 | 87 |
if (doc == null) { |
86 | 88 |
throw new SOAPException(Constants.FAULT_CODE_CLIENT, |
87 | 89 |
"parsing error"); |
88 | 90 |
} |
89 |
|
|
90 | 91 |
Envelope msgEnv = Envelope.unmarshall(doc.getDocumentElement()); |
91 |
|
|
92 | 92 |
// send the message |
93 | 93 |
Message msg = new Message(); |
94 | 94 |
msg.send(url, "urn:this-is-the-action-uri", msgEnv); |
95 |
|
|
96 | 95 |
// receive whatever from the transport and dump it to the screen |
97 | 96 |
SOAPTransport st = msg.getSOAPTransport(); |
98 | 97 |
BufferedReader br = st.receive(); |
99 |
|
|
100 | 98 |
String line; |
101 |
|
|
102 | 99 |
//File to save the answer |
103 | 100 |
fileAnswer = new File("auxiliar"); |
104 |
|
|
105 | 101 |
FileWriter fwAnswer = new FileWriter(fileAnswer); |
106 |
|
|
107 | 102 |
fwAnswer.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); |
108 |
|
|
109 | 103 |
//Process the answer |
110 | 104 |
while ((line = br.readLine()) != null) { |
111 | 105 |
System.out.println(line); |
112 | 106 |
fwAnswer.write(line); |
113 | 107 |
fwAnswer.flush(); |
114 | 108 |
} |
115 |
|
|
116 | 109 |
fwAnswer.close(); |
117 |
|
|
118 |
nodes[0] = XMLTree.xmlToTree(fileAnswer); |
|
119 |
|
|
120 |
if (nodes[0] == null) { |
|
121 |
nodes = null; |
|
122 |
} |
|
110 |
|
|
111 |
|
|
123 | 112 |
} catch (Exception e) { |
124 | 113 |
return null; |
125 | 114 |
} |
115 |
Collection col = new java.util.ArrayList(); |
|
116 |
col.add(XMLTree.xmlToTree(fileAnswer)); |
|
117 |
return col; |
|
118 |
} |
|
126 | 119 |
|
127 |
return nodes; |
|
128 |
} |
|
129 |
|
|
130 |
public static boolean isProtocolSupported(URL url) { |
|
120 |
/** |
|
121 |
* |
|
122 |
* |
|
123 |
* |
|
124 |
* @return |
|
125 |
* @param url |
|
126 |
*/ |
|
127 |
public static boolean isProtocolSupported(URL url) { |
|
131 | 128 |
return true; |
132 |
} |
|
129 |
}
|
|
133 | 130 |
|
134 |
/** |
|
135 |
* This function returns a SOAP message |
|
136 |
* @param message |
|
137 |
* the XML message |
|
138 |
* @return |
|
139 |
*/ |
|
140 |
public static String setSOAPMessage(String message,String[] schemas) { |
|
131 |
/** |
|
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) { |
|
141 | 140 |
String soap = "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\""; |
142 | 141 |
if (schemas != null){ |
143 | 142 |
for (int i=0 ; i<schemas.length ; i++){ |
... | ... | |
148 | 147 |
soap = soap + "<SOAP:Body>" + message + "</SOAP:Body>" + "</SOAP:Envelope>"; |
149 | 148 |
return soap; |
150 | 149 |
|
151 |
} |
|
152 |
} |
|
150 |
} |
|
151 |
} |
Also available in: Unified diff