Revision 41851

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.compat/org.gvsig.compat.se/src/main/java/org/gvsig/compat/se/net/downloader/se/SEDownloaderTask.java
58 58
            }
59 59
            connection = (HttpURLConnection) url.openConnection();
60 60
            connection.setUseCaches(false);
61
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (gvSIG) like Gecko");
61 62
            connection.setConnectTimeout(timeout);
62 63
            //If it uses a HTTP POST
63 64
            if (data != null) {
......
68 69
                os = new OutputStreamWriter(connection.getOutputStream());
69 70
                os.write(data);
70 71
                os.flush();
71
                is = new DataInputStream(connection.getInputStream());
72
            } else {
73
                is = new DataInputStream(url.openStream());
74 72
            }
73
            is = new DataInputStream(connection.getInputStream());
75 74

  
76 75
            dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(dstFile)));
77 76
            byte[] buffer = new byte[1024 * 4];
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.remoteclient/src/main/java/org/gvsig/remoteclient/wms/WMSProtocolHandlerFactory.java
24 24

  
25 25
package org.gvsig.remoteclient.wms;
26 26

  
27
import java.io.BufferedInputStream;
27 28
import java.io.DataInputStream;
28 29
import java.io.IOException;
29 30
import java.io.StringReader;
......
190 191
         return "";
191 192
     }
192 193
     
193
     private static String getSuitableWMSVersion(String host, String _version, int size) throws ConnectException, IOException, XmlPullParserException
194
     {
195
    	String request = WMSProtocolHandler.buildCapabilitiesSuitableVersionRequest(host, _version);
196
    	String version = new String();
197
    	StringReader reader = null;
198
    	DataInputStream dis = null;
199
		try
200
		{
201
			URL url = new URL(request);
202
            byte[] buffer = new byte[size];
194
    private static String readFromUrl(String url_s, int size) throws IOException {
195
        byte[] buffer = new byte[size];
196
        DataInputStream dis = null;
197
        BufferedInputStream bis = null;
198
        try {
199
            URL url = new URL(url_s);
203 200
            URLConnection conn = url.openConnection();
204 201
            conn.setRequestProperty("Accept", "text/xml, text/*, */*");
205 202
            conn.setRequestProperty("User-Agent", "Mozilla/5.0 (gvSIG) like Gecko");
206 203
            dis = new DataInputStream(conn.getInputStream());
207
            dis.readFully(buffer);
208
            String string = new String(buffer);
209

  
204
            bis = new BufferedInputStream(dis);
205
            bis.read(buffer);
206
        } finally {
207
            if( bis != null ) {
208
                try {
209
                    bis.close();
210
                } catch(Exception e) {                    
211
                    logger.warn("Can't close BufferedInputStream", e);
212
                }
213
                bis = null;
214
            }
215
            if( dis != null ) {
216
                try {
217
                    dis.close();
218
                } catch(Exception e) {                    
219
                    logger.warn("Can't close DataInputStream", e);
220
                }
221
                dis = null;
222
            }
223
        }
224
        String sbuffer = new String(buffer);
225
        return sbuffer;
226
    }
227
    
228
    private static String getSuitableWMSVersion(String host, String _version, int size) throws ConnectException, IOException, XmlPullParserException {
229
        String request = WMSProtocolHandler.buildCapabilitiesSuitableVersionRequest(host, _version);
230
        String version = new String();
231
        StringReader reader = null;
232
//        DataInputStream dis = null;
233
        try {
234
//            URL url = new URL(request);
235
//            byte[] buffer = new byte[size];
236
//            URLConnection conn = url.openConnection();
237
//            conn.setRequestProperty("Accept", "text/xml, text/*, */*");
238
//            conn.setRequestProperty("User-Agent", "Mozilla/5.0 (gvSIG) like Gecko");
239
//            dis = new DataInputStream(conn.getInputStream());
240
//            dis.readFully(buffer);
241
//            String string = new String(buffer);
242
            String string = readFromUrl(request, size);
243
            
210 244
            // patch for ArcIMS + WMS connector > 9.0 bug
211 245
            int a = string.toLowerCase().indexOf("<?xml");
212
            if (a !=-1)
213
            	string = string.substring(a, string.length());
246
            if ( a != -1 ) {
247
                string = string.substring(a, string.length());
248
            }
214 249
            // end patch
215 250

  
216

  
217 251
            reader = new StringReader(string);
218
	    	KXmlParser kxmlParser = null;
219
	    	kxmlParser = new KXmlParser();
220
    		kxmlParser.setInput(reader);
221
			kxmlParser.nextTag();
222
    		if ( kxmlParser.getEventType() != KXmlParser.END_DOCUMENT )
223
    		{
224
    			if ((kxmlParser.getName().compareTo(CapabilitiesTags.CAPABILITIES_ROOT1_1_0)==0)
225
    				||(kxmlParser.getName().compareTo(CapabilitiesTags.CAPABILITIES_ROOT1_1_1)==0)
226
    				||(kxmlParser.getName().compareTo(CapabilitiesTags.CAPABILITIES_ROOT1_3_0)==0))
227
    			{
228
    				version = kxmlParser.getAttributeValue("", CapabilitiesTags.VERSION);
229
    			}
230
    		}
231
    		// do not forget to close the Stream.
232
    		reader.close();
233
    		dis.close();
234
			return version;
235
		}
236
		catch(ConnectException conEx)
237
		{
238
			throw new ConnectException(conEx.getMessage());
239
		}
240
		catch(IOException ioEx)
241
		{
242
			throw new IOException(ioEx.getMessage());
243
		}
244
		catch(XmlPullParserException xmlEx)
245
		{
246
                    throw  xmlEx;
252
            KXmlParser kxmlParser = null;
253
            kxmlParser = new KXmlParser();
254
            kxmlParser.setInput(reader);
255
            kxmlParser.nextTag();
256
            if ( kxmlParser.getEventType() != KXmlParser.END_DOCUMENT ) {
257
                if ( (kxmlParser.getName().compareTo(CapabilitiesTags.CAPABILITIES_ROOT1_1_0) == 0)
258
                        || (kxmlParser.getName().compareTo(CapabilitiesTags.CAPABILITIES_ROOT1_1_1) == 0)
259
                        || (kxmlParser.getName().compareTo(CapabilitiesTags.CAPABILITIES_ROOT1_3_0) == 0) ) {
260
                    version = kxmlParser.getAttributeValue("", CapabilitiesTags.VERSION);
261
                }
262
            }
263
            // do not forget to close the Stream.
264
            reader.close();
265
            reader = null;
266
//            dis.close();
267
            return version;
268
        } catch (ConnectException conEx) {
269
            throw new ConnectException(conEx.getMessage());
270
        } catch (IOException ioEx) {
271
            throw new IOException(ioEx.getMessage());
272
        } catch (XmlPullParserException xmlEx) {
273
            throw xmlEx;
247 274
//                    logger.warn("Can't determine server version",xmlEx);
248 275
//                    return "";
249
		}
250
		finally{
251
			if (reader != null)
252
			{
253
				try{
254
					reader.close();
255
				}catch(Exception ex){
256
                                        logger.warn("Can't close reader",ex);
257
				}
258
			}
259
			if (dis != null)
260
			{
261
				try {
262
					dis.close();
263
				} catch(Exception ex) {
264
                                        logger.warn("Can't close input stream",ex);
265
				}
266
			}
267
		}
268
     }
276
        } finally {
277
            if ( reader != null ) {
278
                try {
279
                    reader.close();
280
                } catch (Exception ex) {
281
                    logger.warn("Can't close reader", ex);
282
                }
283
            }
284
//            if ( dis != null ) {
285
//                try {
286
//                    dis.close();
287
//                } catch (Exception ex) {
288
//                    logger.warn("Can't close input stream", ex);
289
//                }
290
//            }
291
        }
292
    }
269 293

  
270 294
     /**
271 295
      * It creates an instance of a WMSDriver class.

Also available in: Unified diff