2011-10-04 193 views
0

我試圖提出「registerSensor」請求。看到下面的xml文件。 但不幸的是,我只收到一個異常,關於一個NULL GET請求。 什麼混淆我最深的是,我發送和POST方法讀取的事實。從服務器請求(ogc)「Sensor Observation Service」(傳感器觀察服務)請求

我知道這個問題可能不適合那個論壇,但我不知道在哪裏尋找....(如果你只是給出任何建議,除了ogc dokus之外,我甚至會很高興)

我測試了它自己的服務器上兩次,並點擊:http://giv-sos.uni-muenster.de:8080/52nSOSv3/

我的要求:

 <RegisterSensor 
    service="SOS" 
    version="1.0.0" 
    xmlns="http://www.opengis.net/sos/1.0" 
    xmlns:swe="http://www.opengis.net/swe/1.0.1" 
    xmlns:ows="http://www.opengeospatial.net/ows" 
    xmlns:xlink="http://www.w3.org/1999/xlink" 
    xmlns:gml="http://www.opengis.net/gml" 
    xmlns:ogc="http://www.opengis.net/ogc" 
    xmlns:om="http://www.opengis.net/om/1.0" 
    xmlns:sml="http://www.opengis.net/sensorML/1.0.1" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.opengis.net/sos/1.0"  
    http://schemas.opengis.net/sos/1.0.0/sosRegisterSensor.xsd http://www.opengis.net/om/1.0 
    http://schemas.opengis.net/om/1.0.0/extensions/observationSpecialization_override.xsd> 

    <SensorDescription> 
    <sml:SensorML version="1.0.1"> 
    <sml:member> 
    <sml:System xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > 
    <sml:identification> 
    <sml:IdentifierList> 
     <sml:identifier> 
     <sml:Term definition="urn:ogc:def:identifier:OGC:uniqueID"> 

     <sml:value>Test Sensor1</sml:value> 
     </sml:Term> 
     </sml:identifier> 
     </sml:IdentifierList> 
    </sml:identification> 
    <sml:capabilities> 
    <swe:SimpleDataRecord> 
     <swe:field name="status"> 
     <swe:Boolean> 
     <swe:value>true</swe:value> 
     </swe:Boolean> 
     </swe:field> 
     <!-- status indicates, whether sensor is mobile (true) or fixed (false) --> 
     <swe:field name="mobile"> 
     <swe:Boolean> 
      <swe:value>true</swe:value> 
     </swe:Boolean> 
     </swe:field> 
    </swe:SimpleDataRecord> 
    </sml:capabilities> 
    <sml:position name="sensorPosition"> 
    <swe:Position referenceFrame="urn:ogc:def:crs:EPSG:4326"> 
    <swe:location> 
     <swe:Vector gml:id="STATION_LOCATION"> 
     <swe:coordinate name="easting"> 
     <swe:Quantity> 
     <swe:uom code="degree"/> 
    <swe:value>12.99734</swe:value> 
    </swe:Quantity> 
     </swe:coordinate> 
    <swe:coordinate name="northing"> 
     <swe:Quantity> 
    <swe:uom code="degree"/> 
    <swe:value>47.79367</swe:value> 
    </swe:Quantity> 
    </swe:coordinate> 
    <swe:coordinate name="altitude"> 
     <swe:Quantity> 
    <swe:uom code="m"/> 
    <swe:value>433</swe:value> 
    </swe:Quantity> 
    </swe:coordinate> 
    </swe:Vector> 
    </swe:location> 
    </swe:Position> 
    </sml:position> 
    <sml:inputs> 
    <sml:InputList> 
     <sml:input name="position"> 
     <swe:ObservableProperty definition="urn:ogc:def:phenomenon:OGC:1.0.30:position"/> 
     </sml:input> 
     </sml:InputList> 
    </sml:inputs> 

    <sml:outputs> 
    <sml:OutputList> 
     <sml:output name="position"> 
    <swe:Quantity definition="urn:ogc:def:phenomenon:OGC:1.0.30:position"> 
    <gml:metaDataProperty> 
     <offering> 
     <id>position</id> 
     <name>Tracking Position Cartesian, in 2D</name> 
     </offering> 
     </gml:metaDataProperty> 
     <swe:uom code="m"/> 
    </swe:Quantity> 
    </sml:output> 

    <sml:output name="altitude"> 
    <swe:Quantity definition="urn:ogc:def:property:OGC:AltitudeAboveMSL"> 
     <gml:metaDataProperty> 
     <offering> 
     <id>altitude</id> 
     <name>Altitude above Mean Sea Level</name> 
     </offering> 
     </gml:metaDataProperty> 
     <swe:uom code="m"/> 
    </swe:Quantity> 
    </sml:output> 

    <sml:output name="convell_a"> 
     <swe:Quantity definition="urn:ogc:def:property:OGC:conva"> 
     <gml:metaDataProperty> 
      <offering> 
      <id>convell_a</id> 
      <name>Convidence Ellipse Semiaxis a</name> 
      </offering> 
     </gml:metaDataProperty> 
     <swe:uom code="m"/> 
     </swe:Quantity> 
    </sml:output> 

    <sml:output name="convell_b"> 
    <swe:Quantity definition="urn:ogc:def:property:OGC:convb"> 
     <gml:metaDataProperty> 
     <offering> 
    <id>convell_b</id> 
     <name>Convidence Ellipse Semiaxis b</name> 
    </offering> 
     </gml:metaDataProperty> 
    <swe:uom code="m"/> 
    </swe:Quantity> 
    </sml:output> 

    <sml:output name="convell_phi"> 
    <swe:Quantity definition="urn:ogc:def:property:OGC:convphi"> 
     <gml:metaDataProperty><offering> 
     <id>convell_phi</id> 
     <name>Convidence Ellipse Angle Phi</name> 
     </offering> 
     </gml:metaDataProperty> 
     <swe:uom code="m"/> 
    </swe:Quantity> 
    </sml:output> 

    </sml:OutputList> 
    </sml:outputs> 

    <sml:components> 
    <sml:ComponentList> 
      <sml:component name="sensorsystem"><sml:Component> 
      <sml:identification> 
      <sml:IdentifierList> 
     <sml:identifier> 
      <sml:Term definition="urn:ogc:def:identifier:OGC:uniqueID"> 
     <sml:value>urn:ogc:object:feature:Sensor:TUWSystem</sml:value> 
     </sml:Term> 
     </sml:identifier> 
     </sml:IdentifierList> 
     </sml:identification> 

     <sml:inputs> 
     <sml:InputList> 
      <sml:input name="position"> 
      <swe:ObservableProperty definition="urn:ogc:def:phenomenon:OGC:1.0.30:position"/> 
      </sml:input> 
     </sml:InputList> 
     </sml:inputs> 

     <sml:outputs> 
     <sml:OutputList> 
      <sml:output name="position"> 
      <swe:Quantity definition="urn:ogc:def:phenomenon:OGC:1.0.30:position"> 
     <gml:metaDataProperty> 
     <offering> 
      <id>position</id> 
      <name>Tracking Position Cartesian, in 2D</name> 
      </offering> 
      </gml:metaDataProperty> 
     <swe:uom code="m"/> 
     </swe:Quantity> 
     </sml:output> 

     <sml:output name="altitude"> 
      <swe:Quantity definition="urn:ogc:def:property:OGC:AltitudeAboveMSL"> 
      <gml:metaDataProperty> 
      <offering> 
      <id>altitude</id> 
      <name>Altitude above Mean Sea Level</name> 
      </offering> 
      </gml:metaDataProperty> 
      <swe:uom code="m"/> 
      </swe:Quantity> 
     </sml:output> 

     <sml:output name="convell_a"> 
      <swe:Quantity definition="urn:ogc:def:property:OGC:conva"> 
     <gml:metaDataProperty> 
      <offering> 
      <id>convell_a</id> 
      <name>Convidence Ellipse Semiaxis a</name> 
     </offering> 
      </gml:metaDataProperty> 
     <swe:uom code="m"/> 
      </swe:Quantity> 
     </sml:output> 

     <sml:output name="convell_b"> 
     <swe:Quantity definition="urn:ogc:def:property:OGC:convb"> 
      <gml:metaDataProperty> 
     <offering> 
     <id>convell_b</id> 
     <name>Convidence Ellipse Semiaxis b</name> 
      </offering> 
     </gml:metaDataProperty> 
     <swe:uom code="m"/> 
     </swe:Quantity> 
     </sml:output> 

     <sml:output name="convell_phi"> 
     <swe:Quantity definition="urn:ogc:def:property:OGC:convphi"> 
      <gml:metaDataProperty> 
      <offering> 
     <id>convell_phi</id> 
      <name>Convidence Ellipse Angle Phi</name> 
      </offering> 
      </gml:metaDataProperty> 
      <swe:uom code="m"/> 
     </swe:Quantity> 
     </sml:output> 
     </sml:OutputList> 
     </sml:outputs> 

     </sml:Component> 
     </sml:component> 
     </sml:ComponentList> 
     </sml:components> 
     </sml:System> 
     </sml:member> 
     </sml:SensorML> 
     </SensorDescription> 

     <ObservationTemplate> 
     <om:Measurement> 
     <om:samplingTime/> 
     <om:procedure/> 
     <om:observedProperty/> 
     <om:featureOfInterest> 
     </om:featureOfInterest> 
     <om:result uom=""> 
     </om:result> 
     </om:Measurement> 
     </ObservationTemplate> 
    </RegisterSensor> 

異常回應,我從服務器獲取:

<?xml version="1.0" encoding="UTF-8"?> 
<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows/1.1" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" 
xsi:schemaLocation="http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"> 
<ows:Exception exceptionCode="InvalidRequest" locator="REQUEST"> 
    <ows:ExceptionText>The GET request null is not supported by this SOS. 
</ows:ExceptionText> 
    </ows:Exception> 
</ows:ExceptionReport> 

Java代碼:

public class HttpRequest 
      extends Thread { 
      private String url = "http://giv-sos.uni-muenster.de:8080/52nSOSv3/sos"; 
      private String charset = "UTF-8"; 
      private String xml_request;     //request to db in xml format 

      private URLConnection connection; 
      private OutputStream output; 
      private InputStream input; 
      private String query;      //transformed xml request 

      /** Ctor. 
      * @param xml ogc request as String 
      */ 
      HttpRequest(String xml) { 
       this.xml_request = xml; 
      } 

      //thread 
      public void run() { 
       // converting String xml to application/x-www-form-urlencoded MIME format 
       try { 
        query = URLEncoder.encode(xml_request, charset);  //transforms special chars 
       } catch (UnsupportedEncodingException e) { 
        System.out.println(e.toString()); 
       } 

     System.out.println("REQUEST: "+xml_request.toString()); 

       // create connection 
       try { 
        connection = new URL(url).openConnection(); 
     System.out.println("CONNECTION: "+connection. toString()); 

        connection.setDoOutput(true);       //true = set method to POST 
        connection.setDoInput(true); 
        connection.setRequestProperty("Accept-Charset", charset); 
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset="+charset); 

       } catch (MalformedURLException ex) { 
        System.out.println("MalformedURLException: " + ex.toString()); 
       } catch (IOException ex) { 
        System.out.println("IOException: " + ex.toString()); 
       } catch (Exception ex) { 
        System.out.println("Exception: " + ex.toString()); 
       } 

       // open connection link 
       try { 
        connection.connect(); 
       } catch (IOException ex) { 
        System.out.println(ex.toString()); 
       } 

       try { 
        //write outputstream to server 
        output = connection.getOutputStream(); 
        output.write(query.getBytes(charset)); 

        //read response from server 
        input = new URL(url).openStream(); 
        Reader reader = new InputStreamReader(input); 
        BufferedReader bufferedReader = new BufferedReader(reader); 
        StringBuilder response = new StringBuilder(); 
        String line = null; 

        //read 
        while((line = bufferedReader.readLine()) != null) 
         response.append(line+"\n"); 

     System.out.println("RESPONSE: "+response.toString()); 

        //close reader 
        bufferedReader.close(); 


        // close stream 
       } catch (IOException ex) { 
        ex.printStackTrace(); 
       } finally { 
        if (output != null) 
         try { 
          output.close(); 
         } catch (IOException ex) { 
          System.out.println("IOEXCEPTION: "+ex.toString()); 
         } 
       } 

      } 
     } 

的exceptionCode =「InvalidRequest」是很明顯的,但還是讓我困惑,我無法找到與它線索的數獨....

我很高興每個答案!

+0

有沒有人有想法? – user972851

回答

1

這其實很簡單。您將GET(在OGC文檔中稱爲KVP或Key Value Pair)與服務器的SOAP接口混合在一起。所以,你可以使用KVP做這樣的事情得到了服務器的功能:

http://giv-sos.uni-muenster.de:8080/52nSOSv3?service=SOS&version=1.0.0&request=getCapabilities 

但通常註冊一個傳感器,必須具有管理權限,並能使用SOAP協議包括描述完整的XML文檔傳感器。這意味着你已經在SOAP信封中包裝了RegisterSensor XML(假設這是RegisterSensor而不是GetCapabilities,我在這裏簡要說明)。還要注意,服務/版本是與上面相同,但現在的請求參數是標籤:

<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding" xmlns:sos="http://www.opengis.net/sos/1.0"> 
    <soap:Header /> 
    <soap:Body> 
    <ns:GetCapabilities service="SOS" version="1.0.0" /> 
    </soap:Body> 
</soap:Envelope> 

試試這個獲得性能你最喜歡的SOS SOAP服務器上請求,看看如果你沒有得到一個性能文檔回。