Search in sources :

Example 1 with GetObservation

use of org.geotoolkit.sos.xml.v100.GetObservation in project geotoolkit by Geomatys.

the class AbstractGetObservation method getResponseStream.

/**
 * {@inheritDoc }
 */
@Override
public InputStream getResponseStream() throws IOException {
    if (offering == null) {
        throw new IllegalArgumentException("offering is not defined");
    }
    if (observedProperties == null) {
        throw new IllegalArgumentException("observedProperties is not defined");
    }
    if (responseFormat == null) {
        throw new IllegalArgumentException("responseFormat is not defined");
    }
    final URL url = new URL(serverURL);
    URLConnection conec = url.openConnection();
    conec = security.secure(conec);
    conec.setDoOutput(true);
    conec.setRequestProperty("Content-Type", "text/xml");
    OutputStream stream = conec.getOutputStream();
    stream = security.encrypt(stream);
    try {
        final Marshaller marsh = POOL.acquireMarshaller();
        final GetObservation observXml = new GetObservation(version, offering, (eventTimes != null) ? Arrays.asList(eventTimes) : null, (procedures != null) ? Arrays.asList(procedures) : null, Arrays.asList(observedProperties), featureOfInterest, result, responseFormat, resultModel, responseMode, srsName);
        marsh.marshal(observXml, stream);
        POOL.recycle(marsh);
    } catch (JAXBException ex) {
        throw new IOException(ex);
    }
    stream.close();
    return security.decrypt(conec.getInputStream());
}
Also used : GetObservation(org.geotoolkit.sos.xml.v100.GetObservation) Marshaller(javax.xml.bind.Marshaller) OutputStream(java.io.OutputStream) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 2 with GetObservation

use of org.geotoolkit.sos.xml.v100.GetObservation in project geotoolkit by Geomatys.

the class SOSClientDemo method main.

public static void main(String[] args) throws MalformedURLException, URISyntaxException, IOException, JAXBException {
    Demos.init();
    final MarshallerPool pool = SOSMarshallerPool.getInstance();
    final Unmarshaller um = pool.acquireUnmarshaller();
    // build a new SOS client
    final SensorObservationServiceClient sosServer = new SensorObservationServiceClient(new URL("http://test.geomatys.com/swe_TS/WS/sos?"), "1.0.0");
    /**
     * make a getCapabilities request
     */
    final GetCapabilitiesRequest getCapa = sosServer.createGetCapabilities();
    InputStream is = getCapa.getResponseStream();
    // unmarshall the response
    Capabilities capabilities = (Capabilities) um.unmarshal(is);
    // print the title of the server
    System.out.println(capabilities.getServiceIdentification().getTitle());
    // extract a sensorML identifier and outputFormat to make a describeSensor request
    Operation describeSensorOperation = capabilities.getOperationsMetadata().getOperation("DescribeSensor");
    String sensorID = ((ValueType) describeSensorOperation.getParameter("procedure").getAllowedValues().getValueOrRange().get(0)).getValue();
    String outputFormat = ((ValueType) describeSensorOperation.getParameter("outputFormat").getAllowedValues().getValueOrRange().get(0)).getValue();
    // extract a all the parameters necessary to make a getObservation request
    Operation getObservationOperation = capabilities.getOperationsMetadata().getOperation("GetObservation");
    String offering = ((ValueType) getObservationOperation.getParameter("offering").getAllowedValues().getValueOrRange().get(0)).getValue();
    String responseFormat = ((ValueType) getObservationOperation.getParameter("responseFormat").getAllowedValues().getValueOrRange().get(0)).getValue();
    String phenomenon = ((ValueType) getObservationOperation.getParameter("observedProperty").getAllowedValues().getValueOrRange().get(0)).getValue();
    String procedure = ((ValueType) getObservationOperation.getParameter("procedure").getAllowedValues().getValueOrRange().get(0)).getValue();
    String featureOfInterest = ((ValueType) getObservationOperation.getParameter("featureOfInterest").getAllowedValues().getValueOrRange().get(0)).getValue();
    /**
     * make a DescribeSensor request
     */
    final DescribeSensorRequest descSensor = sosServer.createDescribeSensor();
    descSensor.setSensorId(sensorID);
    descSensor.setOutputFormat(outputFormat);
    is = descSensor.getResponseStream();
    // unmarshall the response
    AbstractSensorML sensorMLResponse = (AbstractSensorML) um.unmarshal(is);
    System.out.println(sensorMLResponse);
    /**
     * make a GetObservation request
     */
    final GetObservationRequest getObs = sosServer.createGetObservation();
    getObs.setOffering(offering);
    getObs.setObservedProperties(phenomenon);
    getObs.setProcedures(procedure);
    getObs.setResponseFormat(responseFormat);
    getObs.setFeatureOfInterest(new FeatureOfInterest(Arrays.asList(featureOfInterest)));
    is = getObs.getResponseStream();
    // unmarshall the response
    ObservationCollectionType getObsResponse = (ObservationCollectionType) um.unmarshal(is);
    System.out.println(getObsResponse);
    pool.recycle(um);
}
Also used : GetCapabilitiesRequest(org.geotoolkit.sos.GetCapabilitiesRequest) ValueType(org.geotoolkit.ows.xml.v110.ValueType) InputStream(java.io.InputStream) ObservationCollectionType(org.geotoolkit.observation.xml.v100.ObservationCollectionType) MarshallerPool(org.apache.sis.xml.MarshallerPool) SOSMarshallerPool(org.geotoolkit.sos.xml.SOSMarshallerPool) Operation(org.geotoolkit.ows.xml.v110.Operation) URL(java.net.URL) AbstractSensorML(org.geotoolkit.sml.xml.AbstractSensorML) GetObservationRequest(org.geotoolkit.sos.GetObservationRequest) FeatureOfInterest(org.geotoolkit.sos.xml.v100.GetObservation.FeatureOfInterest) Capabilities(org.geotoolkit.sos.xml.v100.Capabilities) Unmarshaller(javax.xml.bind.Unmarshaller) DescribeSensorRequest(org.geotoolkit.sos.DescribeSensorRequest) SensorObservationServiceClient(org.geotoolkit.sos.SensorObservationServiceClient)

Aggregations

URL (java.net.URL)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URLConnection (java.net.URLConnection)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 MarshallerPool (org.apache.sis.xml.MarshallerPool)1 ObservationCollectionType (org.geotoolkit.observation.xml.v100.ObservationCollectionType)1 Operation (org.geotoolkit.ows.xml.v110.Operation)1 ValueType (org.geotoolkit.ows.xml.v110.ValueType)1 AbstractSensorML (org.geotoolkit.sml.xml.AbstractSensorML)1 DescribeSensorRequest (org.geotoolkit.sos.DescribeSensorRequest)1 GetCapabilitiesRequest (org.geotoolkit.sos.GetCapabilitiesRequest)1 GetObservationRequest (org.geotoolkit.sos.GetObservationRequest)1 SensorObservationServiceClient (org.geotoolkit.sos.SensorObservationServiceClient)1 SOSMarshallerPool (org.geotoolkit.sos.xml.SOSMarshallerPool)1 Capabilities (org.geotoolkit.sos.xml.v100.Capabilities)1 GetObservation (org.geotoolkit.sos.xml.v100.GetObservation)1