Skip to content

Commit

Permalink
[GEOS-8335] Updated WMS 1.3.0 GetCapabilities not reload the service …
Browse files Browse the repository at this point in the history
…configuration from the database multiple times per layer and layer group and to only load the layers and layer groups from the catalog once per request.
  • Loading branch information
sikeoka committed Oct 11, 2017
1 parent 0290eed commit 76925eb
Showing 1 changed file with 25 additions and 40 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.AttributesImpl;


import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Envelope;
import org.geoserver.wfs.json.JSONType; import org.geoserver.wfs.json.JSONType;


Expand Down Expand Up @@ -191,6 +192,8 @@ private static class Capabilities_1_3_0_Translator extends TranslatorSupport {
DimensionHelper dimensionHelper; DimensionHelper dimensionHelper;


private boolean skipping; private boolean skipping;

private WMSInfo serviceInfo;


private LegendSample legendSample; private LegendSample legendSample;


Expand All @@ -211,6 +214,7 @@ public Capabilities_1_3_0_Translator(ContentHandler handler, WMS wmsConfig,
this.getMapFormats = getMapFormats; this.getMapFormats = getMapFormats;
this.extCapsProviders = extCapsProviders; this.extCapsProviders = extCapsProviders;
this.schemaBaseURL = schemaBaseURL; this.schemaBaseURL = schemaBaseURL;
this.serviceInfo = wmsConfig.getServiceInfo();


this.dimensionHelper = new DimensionHelper(Mode.WMS13, wmsConfig) { this.dimensionHelper = new DimensionHelper(Mode.WMS13, wmsConfig) {


Expand Down Expand Up @@ -318,7 +322,6 @@ String schemaLocation(String namespace, String uri) {
private void handleService() { private void handleService() {
start("Service"); start("Service");


final WMSInfo serviceInfo = wmsConfig.getServiceInfo();
element("Name", "WMS"); element("Name", "WMS");
element("Title", serviceInfo.getTitle()); element("Title", serviceInfo.getTitle());
element("Abstract", serviceInfo.getAbstract()); element("Abstract", serviceInfo.getAbstract());
Expand Down Expand Up @@ -618,7 +621,7 @@ public void chars(String text) {
public void end(String element) { public void end(String element) {
Capabilities_1_3_0_Translator.this.end(element); Capabilities_1_3_0_Translator.this.end(element);
} }
}, wmsConfig.getServiceInfo(), request); }, serviceInfo, request);
} catch (Exception e) { } catch (Exception e) {
throw new ServiceException("Extended capabilities provider threw error", e); throw new ServiceException("Extended capabilities provider threw error", e);
} }
Expand Down Expand Up @@ -662,7 +665,6 @@ private void handleLayers() {


final Catalog catalog = wmsConfig.getCatalog(); final Catalog catalog = wmsConfig.getCatalog();


WMSInfo serviceInfo = wmsConfig.getServiceInfo();
if(StringUtils.isBlank(serviceInfo.getRootLayerTitle())) { if(StringUtils.isBlank(serviceInfo.getRootLayerTitle())) {
element("Title", serviceInfo.getTitle()); element("Title", serviceInfo.getTitle());
} else { } else {
Expand Down Expand Up @@ -690,13 +692,16 @@ private void handleLayers() {
lgFilter = addNameSpaceFilterIfNeed(lgFilter, "workspace.name"); lgFilter = addNameSpaceFilterIfNeed(lgFilter, "workspace.name");


// handle root bounding box // handle root bounding box
CloseableIterator<LayerInfo> layers = catalog.list(LayerInfo.class, filter); List<LayerGroupInfo> layerGroups;
CloseableIterator<LayerGroupInfo> layerGroups = catalog.list(LayerGroupInfo.class, lgFilter); List<LayerInfo> layers;
try{ SortBy lgOrder = asc("name");
handleRootBbox(layers, layerGroups); SortBy order = asc("name");
}finally{ try (CloseableIterator<LayerGroupInfo> lgIter = catalog.list(LayerGroupInfo.class, lgFilter, null, null, lgOrder);
layers.close(); CloseableIterator<LayerInfo> iter = catalog.list(LayerInfo.class, filter, null, null, order)) {
layerGroups = Lists.newArrayList(lgIter);
layers = Lists.newArrayList(iter);
} }
handleRootBbox(layers, layerGroups);


// handle AuthorityURL // handle AuthorityURL
handleAuthorityURL(serviceInfo.getAuthorityURLs()); handleAuthorityURL(serviceInfo.getAuthorityURLs());
Expand All @@ -707,28 +712,15 @@ private void handleLayers() {
Set<LayerInfo> layersAlreadyProcessed = new HashSet<LayerInfo>(); Set<LayerInfo> layersAlreadyProcessed = new HashSet<LayerInfo>();


// encode layer groups // encode layer groups
{
SortBy layerGroupOrder = asc("name");
layerGroups = catalog.list(LayerGroupInfo.class, lgFilter, null, null,
layerGroupOrder);
}
try { try {
layersAlreadyProcessed = handleLayerGroups(layerGroups); layersAlreadyProcessed = handleLayerGroups(layerGroups);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Can't obtain Envelope of Layer-Groups: " throw new RuntimeException("Can't obtain Envelope of Layer-Groups: "
+ e.getMessage(), e); + e.getMessage(), e);
} finally {
layerGroups.close();
} }


// now encode each layer individually // now encode each layer individually
SortBy layerOrder = asc("name"); handleLayerTree(layers, layersAlreadyProcessed);
layers = catalog.list(LayerInfo.class, filter, null, null, layerOrder);
try {
handleLayerTree(layers, layersAlreadyProcessed);
} finally {
layers.close();
}


end("Layer"); end("Layer");
} }
Expand Down Expand Up @@ -813,25 +805,24 @@ private String qualifySRS(String srs) {
* @param layers available layers iterator * @param layers available layers iterator
* @param layersGroups available layer groups iterator * @param layersGroups available layer groups iterator
*/ */
private void handleRootBbox(Iterator<LayerInfo> layers, Iterator<LayerGroupInfo> layersGroups) { private void handleRootBbox(List<LayerInfo> layers, List<LayerGroupInfo> layersGroups) {


final Envelope world = new Envelope(-180, 180, -90, 90); final Envelope world = new Envelope(-180, 180, -90, 90);
Envelope latlonBbox = new Envelope(); Envelope latlonBbox = new Envelope();


LOGGER.finer("Collecting summarized latlonbbox and common SRS..."); LOGGER.finer("Collecting summarized latlonbbox and common SRS...");


// handle layers // handle layers
while (layers.hasNext()) { for (LayerInfo layer : layers) {
if (expandEnvelopeToContain(world, latlonBbox, if (expandEnvelopeToContain(world, latlonBbox,
layers.next().getResource().getLatLonBoundingBox())) { layer.getResource().getLatLonBoundingBox())) {
// our envelope already contains the world // our envelope already contains the world
break; break;
} }
} }


// handle layer groups // handle layer groups
while (layersGroups.hasNext()) { for (LayerGroupInfo layerGroup : layersGroups) {
LayerGroupInfo layerGroup = layersGroups.next();
ReferencedEnvelope referencedEnvelope = layerGroup.getBounds(); ReferencedEnvelope referencedEnvelope = layerGroup.getBounds();
if (referencedEnvelope == null) { if (referencedEnvelope == null) {
// no bounds available move on // no bounds available move on
Expand Down Expand Up @@ -874,14 +865,13 @@ private boolean expandEnvelopeToContain(Envelope world, Envelope envelope, Envel
return envelope.contains(world); return envelope.contains(world);
} }


private void handleLayerTree(final Iterator<LayerInfo> layers, Set<LayerInfo> layersAlreadyProcessed) { private void handleLayerTree(final List<LayerInfo> layers, Set<LayerInfo> layersAlreadyProcessed) {
// Build a LayerTree only for the layers that have a wms path set. Process the ones that // Build a LayerTree only for the layers that have a wms path set. Process the ones that
// don't first // don't first
LayerTree nestedLayers = new LayerTree(); LayerTree nestedLayers = new LayerTree();


//handle non nested layers //handle non nested layers
while (layers.hasNext()) { for (LayerInfo layer : layers) {
LayerInfo layer = layers.next();
if(layersAlreadyProcessed.contains(layer) || !isExposable(layer)){ if(layersAlreadyProcessed.contains(layer) || !isExposable(layer)){
continue; continue;
} }
Expand Down Expand Up @@ -1127,7 +1117,7 @@ private void element(String element, InternationalString is) {
} }
} }


protected Set<LayerInfo> handleLayerGroups(Iterator<LayerGroupInfo> layerGroups) throws FactoryException, protected Set<LayerInfo> handleLayerGroups(List<LayerGroupInfo> layerGroups) throws FactoryException,
TransformException, IOException { TransformException, IOException {
Set<LayerInfo> layersAlreadyProcessed = new HashSet<LayerInfo>(); Set<LayerInfo> layersAlreadyProcessed = new HashSet<LayerInfo>();


Expand Down Expand Up @@ -1170,11 +1160,7 @@ protected Set<LayerInfo> handleLayerGroups(Iterator<LayerGroupInfo> layerGroups)
* @param allGroups * @param allGroups
* *
*/ */
private List<LayerGroupInfo> filterNestedGroups(Iterator<LayerGroupInfo> iterator) { private List<LayerGroupInfo> filterNestedGroups(List<LayerGroupInfo> allGroups) {
List<LayerGroupInfo> allGroups = new ArrayList<LayerGroupInfo>();
while(iterator.hasNext()) {
allGroups.add(iterator.next());
}
LinkedHashSet<LayerGroupInfo> result = new LinkedHashSet<LayerGroupInfo>(allGroups); LinkedHashSet<LayerGroupInfo> result = new LinkedHashSet<LayerGroupInfo>(allGroups);
for(LayerGroupInfo group : allGroups) { for(LayerGroupInfo group : allGroups) {
for(PublishedInfo pi : group.getLayers()) { for(PublishedInfo pi : group.getLayers()) {
Expand Down Expand Up @@ -1512,10 +1498,9 @@ private void handleBBox(Envelope bbox, String srs) {
} }


private void handleAdditionalBBox(ReferencedEnvelope bbox, String crs, LayerInfo layer) { private void handleAdditionalBBox(ReferencedEnvelope bbox, String crs, LayerInfo layer) {
WMSInfo info = wmsConfig.getServiceInfo(); if (serviceInfo.isBBOXForEachCRS() && !serviceInfo.getSRS().isEmpty()) {
if (info.isBBOXForEachCRS() && !info.getSRS().isEmpty()) {
//output bounding box for each supported service srs //output bounding box for each supported service srs
for (String srs : info.getSRS()) { for (String srs : serviceInfo.getSRS()) {
srs = qualifySRS(srs); srs = qualifySRS(srs);
if (crs != null && srs.equals(crs)) { if (crs != null && srs.equals(crs)) {
continue; //already did this one continue; //already did this one
Expand Down

0 comments on commit 76925eb

Please sign in to comment.