* @see AbstractFeatureInfoResponse#writeTo(OutputStream)
*/
@Override
public void writeTo(final OutputStream out) throws ServiceException, IOException {
final GetFeatureInfoRequest fInfoReq = getRequest();
final WMS wmsConfig = fInfoReq.getWMS();
//the 'response' object we'll pass to our OutputFormat
FeatureCollectionType features = WfsFactory.eINSTANCE.createFeatureCollectionType();
//the 'request' object we'll pass to our OutputFormat
GetFeatureType gfreq = WfsFactory.eINSTANCE.createGetFeatureType();
gfreq.setBaseUrl(fInfoReq.getBaseUrl());
for (Iterator i = results.iterator(); i.hasNext();) {
FeatureCollection<SimpleFeatureType, SimpleFeature> fc = (FeatureCollection)i.next();
features.getFeature().add(fc);
QueryType qt = WfsFactory.eINSTANCE.createQueryType();
String crs = GML2EncodingUtils.epsgCode(fc.getSchema().getCoordinateReferenceSystem());
if (crs != null) {
final String srsName = "EPSG:" + crs;
try {
qt.setSrsName(new URI(srsName));
} catch (URISyntaxException e) {
throw new ServiceException("Unable to determite coordinate system for featureType " + fc.getSchema().getTypeName() + ". Schema told us '" + srsName + "'", e);
}
}
gfreq.getQuery().add(qt);
}
//this is a dummy wrapper around our 'request' object so that the new Dispatcher will accept it.
Service serviceDesc = new Service("wms", null, null, Collections.EMPTY_LIST);
Operation opDescriptor = new Operation("",serviceDesc,null, new Object[] { gfreq });
final GeoServer gs = wmsConfig.getGeoServer();
GML2OutputFormat format = new GML2OutputFormat(gs);
format.write(features, out, opDescriptor);
}