use of org.geotoolkit.sos.xml.v100.GetObservation.FeatureOfInterest 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());
}
use of org.geotoolkit.sos.xml.v100.GetObservation.FeatureOfInterest 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);
}
Aggregations