001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.wfs.demo;
017:
018: import java.io.BufferedReader;
019: import java.io.IOException;
020: import java.io.InputStreamReader;
021: import java.io.OutputStreamWriter;
022: import java.io.Writer;
023: import java.net.HttpURLConnection;
024: import java.net.URL;
025:
026: /**
027: * summary sentence.
028: * <p>
029: * Paragraph ...
030: * </p><p>
031: * Responsibilities:
032: * <ul>
033: * <li>
034: * <li>
035: * </ul>
036: * </p><p>
037: * Example:<pre><code>
038: * PostDemo x = new PostDemo( ... );
039: * TODO code example
040: * </code></pre>
041: * </p>
042: * @author dzwiers
043: * @since 0.6.0
044: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wfs/src/test/java/org/geotools/data/wfs/demo/PostDemo.java $
045: */
046: public class PostDemo {
047: public static void main(String[] args) throws IOException {
048: String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
049: + "<DescribeFeatureType xmlns=\"http://www.opengis.net/wfs\" "
050: + "xmlns:gml=\"http://www.opengis.net/gml\" "
051: + "xmlns:ogc=\"http://www.opengis.net/ogc\" version=\"1.0.0\" "
052: + "service=\"WFS\" outputFormat=\"XMLSCHEMA\">"
053: + "<TypeName>envirodat</TypeName></DescribeFeatureType>";
054:
055: System.out.println(s + "\n\n\n");
056: URL url = new URL("http://map.ns.ec.gc.ca/envdat/map.aspx?");
057:
058: HttpURLConnection connection = (HttpURLConnection) url
059: .openConnection();
060: connection.setRequestMethod("POST");
061: connection.setDoOutput(true);
062: connection.setDoInput(true);
063: connection
064: .setRequestProperty("Content-type", "application/xml");
065:
066: url.openConnection().connect();
067: Writer w = new OutputStreamWriter(connection.getOutputStream());
068: w.write(s);
069: w.flush();
070: w.close();
071: BufferedReader r = new BufferedReader(new InputStreamReader(
072: connection.getInputStream()));
073: while (r.ready()) {
074: System.out.print((String) r.readLine());
075: }
076: }
077:
078: // public static void main(String[] args) throws IOException{
079: // String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
080: // "<DescribeFeatureType xmlns=\"http://www.opengis.net/wfs\" " +
081: // "xmlns:gml=\"http://www.opengis.net/gml\" " +
082: // "xmlns:ogc=\"http://www.opengis.net/ogc\" version=\"1.0.0\" " +
083: // "service=\"WFS\" outputFormat=\"XMLSCHEMA\">" +
084: // "</DescribeFeatureType>";
085: //
086: // System.out.println(s+"\n\n\n");
087: // URL url = new URL("http://www.refractions.net:8080/geoserver/wfs?");
088: //
089: // HttpURLConnection connection = (HttpURLConnection)url.openConnection();
090: // connection.setRequestMethod("POST");
091: // connection.setDoOutput(true);
092: // connection.setDoInput(true);
093: // connection.setRequestProperty("Content-type", "application/xml");
094: //
095: // url.openConnection().connect();
096: // Writer w = new OutputStreamWriter(connection.getOutputStream());
097: // w.write(s);
098: // w.flush();
099: // w.close();
100: // BufferedReader r = new BufferedReader(new InputStreamReader(connection.getInputStream()));
101: // while(r.ready()){
102: // System.out.print((String)r.readLine());
103: // }
104: // }
105: }
|