本文整理了Java中org.geoserver.config.GeoServer
类的一些代码示例,展示了GeoServer
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GeoServer
类的具体详情如下:
包路径:org.geoserver.config.GeoServer
类名称:GeoServer
[英]Facade providing access to the GeoServer configuration.
Singleton objects must take care not to maintain references to configuration entities. For instance the following would an error:
class MySingleton {
ServiceInfo service;
MySingleton(GeoServer gs) {
this.service = gs.getServiceByName("mySerfvice", ServiceInfo.class);
}
}
The reason being that when changes occur to the configuration externally (be it through the web ui or restconfig, etc...) any cached configuration objects become stale. So singleton objects should look up configuration objects on demand.
[中]Facade提供对GeoServer配置的访问。
####单身人士须知
单例对象必须注意不要维护对配置实体的引用。例如,以下错误:
class MySingleton {
ServiceInfo service;
MySingleton(GeoServer gs) {
this.service = gs.getServiceByName("mySerfvice", ServiceInfo.class);
}
}
原因是当外部配置发生更改时(通过web ui或restconfig等…)任何缓存的配置对象都会过时。所以单例对象应该根据需要查找配置对象。
代码示例来源:origin: geoserver/geoserver
Class<T> serviceClass, String workspace, GeoServer geoServer) {
Catalog catalog = geoServer.getCatalog();
WorkspaceInfo ws = null;
if (workspace != null) {
ws = catalog.getWorkspaceByName(workspace);
old = geoServer.getService(ws, serviceClass);
} else {
old = geoServer.getService(serviceClass);
geoServer.save(old);
} else {
geoServer.add(created);
代码示例来源:origin: geoserver/geoserver
ws = catalog.getWorkspaceByName(first);
if (ws != null) {
LocalWorkspace.set(ws);
NamespaceInfo ns = catalog.getNamespaceByPrefix(ws.getName());
if (ns != null) {
LayerInfo l = catalog.getLayerByName(new NameImpl(ns.getURI(), last));
if (l != null) {
LocalPublished.set(l);
if (!gs.getGlobal().isGlobalServices()) {
throw new ServiceException("No such workspace '" + request.context + "'");
} else if (!gs.getGlobal().isGlobalServices()) {
throw new ServiceException("No workspace specified");
代码示例来源:origin: geoserver/geoserver
public void mangleURL(
StringBuilder baseURL, StringBuilder path, Map<String, String> kvp, URLType type) {
// first check the system property, then fall back to configuration
String proxyBase =
(GeoServerExtensions.getProperty(Requests.PROXY_PARAM) != null)
? GeoServerExtensions.getProperty(Requests.PROXY_PARAM)
: this.geoServer.getSettings().getProxyBaseUrl();
// Mangles the URL base in different ways based on a flag
// (for two reasons: a) speed; b) to make the admin aware of
// possible security liabilities)
baseURL =
(this.geoServer.getGlobal().isUseHeadersProxyURL() == true && proxyBase != null)
? this.mangleURLHeaders(baseURL, proxyBase)
: this.mangleURLFixedURL(baseURL, proxyBase);
}
代码示例来源:origin: geoserver/geoserver
public UpdateSequenceListener(GeoServer geoServer) {
this.geoServer = geoServer;
geoServer.getCatalog().addListener(this);
geoServer.addListener(this);
}
代码示例来源:origin: geoserver/geoserver
synchronized void incrementSequence() {
// prevent infinite loop on configuration update
if (updating) return;
try {
updating = true;
GeoServerInfo gsInfo = geoServer.getGlobal();
gsInfo.setUpdateSequence(gsInfo.getUpdateSequence() + 1);
geoServer.save(gsInfo);
} finally {
updating = false;
}
}
代码示例来源:origin: geoserver/geoserver
@Override
public void initialize(GeoServer geoServer) throws Exception {
// Consider moving earlier to make use of the requested LockProvider during initial
// configuration
String lockProviderName = geoServer.getGlobal().getLockProviderName();
setLockProvider(lockProviderName);
geoServer.addListener(listener);
}
代码示例来源:origin: org.geoserver/gs-wfs
@Test
public void testGetFeatureReproject11() throws Exception {
WFSInfo wfs = getWFS();
wfs.setFeatureBounding(true);
getGeoServer().save(wfs);
Document doc =
getAsDOM(
"wfs?request=GetFeature&typename=cite:Geometryless&version=1.1.0&service=wfs&srsName=EPSG:900913");
assertEquals("wfs:FeatureCollection", doc.getDocumentElement().getNodeName());
NodeList featureMembers = doc.getElementsByTagName("gml:featureMembers");
assertFalse(featureMembers.getLength() == 0);
NodeList features = doc.getElementsByTagName("cite:Geometryless");
assertEquals(3, features.getLength());
}
代码示例来源:origin: org.geoserver/wcs1_0
public void testSkipMisconfigured() throws Exception {
// enable skipping of misconfigured layers
GeoServerInfo global = getGeoServer().getGlobal();
global.setResourceErrorHandling(ResourceErrorHandling.SKIP_MISCONFIGURED_LAYERS);
getGeoServer().save(global);
// manually misconfigure one layer
CoverageStoreInfo cvInfo = getCatalog().getCoverageStoreByName(MockData.TASMANIA_DEM.getLocalPart());
cvInfo.setURL("file:///I/AM/NOT/THERE");
getCatalog().save(cvInfo);
Document dom = getAsDOM(BASEPATH + "?request=DescribeCoverage&service=WCS&version=1.0.0");
checkValidationErrors(dom, WCS10_DESCRIBECOVERAGE_SCHEMA);
int count = getCatalog().getCoverages().size();
assertEquals(count - 1, dom.getElementsByTagName("wcs:CoverageOffering").getLength());
}
代码示例来源:origin: org.geoserver/gs-wcs1_1
@Test
public void testEnabledServiceResponse() throws Exception {
WCSInfo wcs = getGeoServer().getService(WCSInfo.class);
wcs.setEnabled(true);
getGeoServer().save(wcs);
Document doc = getAsDOM("wcs?service=WCS&request=getCapabilities");
assertEquals("wcs:Capabilities", doc.getDocumentElement().getNodeName());
}
}
代码示例来源:origin: geoserver/geoserver
@Override
protected void onSetUp(SystemTestData testData) throws Exception {
super.onSetUp(testData);
LayerInfo li = getCatalog().getLayerByName(getLayerId(SystemTestData.BUILDINGS));
Resource resource = getDataDirectory().config(li);
Document dom;
try (InputStream is = resource.in()) {
dom = dom(resource.in());
}
Element defaultStyle = (Element) dom.getElementsByTagName("defaultStyle").item(0);
Element defaultStyleId = (Element) defaultStyle.getElementsByTagName("id").item(0);
defaultStyleId.setTextContent("danglingReference");
try (OutputStream os = resource.out()) {
print(dom, os);
}
getGeoServer().reload();
}
代码示例来源:origin: org.geoserver/gs-wms
@Test
public void testDescribeLayerVersion111() throws Exception {
String layer = MockData.FORESTS.getPrefix() + ":" + MockData.FORESTS.getLocalPart();
String request = "wms?service=wms&version=1.1.1&request=DescribeLayer&layers=" + layer;
assertEquals("src/test/resources/geoserver", getGeoServer().getGlobal().getProxyBaseUrl());
Document dom = getAsDOM(request, true);
assertEquals(
"1.1.1",
dom.getDocumentElement().getAttributes().getNamedItem("version").getNodeValue());
}
代码示例来源:origin: org.geoserver/gs-wcs1_1
@Test
public void testUpdateSequenceEqualsGet() throws Exception {
long updateIndex = getGeoServer().getGlobal().getUpdateSequence();
Document dom =
getAsDOM(
BASEPATH
+ "?request=GetCapabilities&service=WCS&updateSequence="
+ Long.toString(updateIndex));
checkValidationErrors(dom, WCS11_SCHEMA);
final Node root = dom.getFirstChild();
assertEquals("wcs:Capabilities", root.getNodeName());
assertEquals(0, root.getChildNodes().getLength());
}
代码示例来源:origin: org.geoserver/gs-wfs
@Test
public void testSkipMisconfiguredLayers() throws Exception {
// make sure AggregateGeoFeature is in the mock data set
Document doc = getAsDOM("wfs?service=WFS&request=DescribeFeatureType&version=1.0.0");
assertEquals("xsd:schema", doc.getDocumentElement().getNodeName());
XMLAssert.assertXpathEvaluatesTo(
"1", "count(//xsd:import[contains(@schemaLocation, 'AggregateGeoFeature')])", doc);
// enable skipping of misconfigured layers
GeoServerInfo global = getGeoServer().getGlobal();
global.setResourceErrorHandling(ResourceErrorHandling.SKIP_MISCONFIGURED_LAYERS);
getGeoServer().save(global);
// misconfigure a layer
FeatureTypeInfo ftype =
getCatalog().getFeatureTypeByName(CiteTestData.AGGREGATEGEOFEATURE.getLocalPart());
ftype.setNativeName("NOT ACTUALLY THERE");
getCatalog().save(ftype);
// check the results again
doc = getAsDOM("wfs?service=WFS&request=DescribeFeatureType&version=1.0.0");
assertEquals("xsd:schema", doc.getDocumentElement().getNodeName());
XMLAssert.assertXpathEvaluatesTo(
"0", "count(//xsd:import[contains(@schemaLocation, 'AggregateGeoFeature')])", doc);
}
代码示例来源:origin: org.geoserver/gs-wms
@Test
public void testMisconfiguredLayerIsSkippedWhenWMSServiceIsConfiguredThatWay()
throws Exception {
GeoServerInfo global = getGeoServer().getGlobal();
global.setResourceErrorHandling(ResourceErrorHandling.SKIP_MISCONFIGURED_LAYERS);
getGeoServer().save(global);
Document caps = getAsDOM("wms?service=WMS&request=GetCapabilities&version=1.1.1");
assertEquals("WMT_MS_Capabilities", caps.getDocumentElement().getTagName());
// we misconfigured all the layers in the server, so there should be no named layers now.
XMLAssert.assertXpathEvaluatesTo("", "//Layer/Name/text()", caps);
}
代码示例来源:origin: org.geoserver/gs-wcs1_1
@Test
public void testMetadataLinksTransormToProxyBaseURL() throws Exception {
Catalog catalog = getCatalog();
CoverageInfo ci = catalog.getCoverageByName(getLayerId(TASMANIA_DEM));
MetadataLinkInfo ml = catalog.getFactory().createMetadataLink();
ml.setContent("/metadata?key=value");
ml.setAbout("http://www.geoserver.org");
ci.getMetadataLinks().add(ml);
catalog.save(ci);
String proxyBaseUrl = getGeoServer().getGlobal().getSettings().getProxyBaseUrl();
Document dom =
getAsDOM(
"wcs?request=DescribeCoverage&service=WCS&version=1.1.1&identifiers="
+ TASMANIA_DEM.getLocalPart());
checkValidationErrors(dom, WCS11_SCHEMA);
String xpathBase = "//wcs:CoverageDescription/ows:Metadata";
assertXpathEvaluatesTo("http://www.geoserver.org", xpathBase + "/@about", dom);
assertXpathEvaluatesTo("simple", xpathBase + "/@xlink:type", dom);
assertXpathEvaluatesTo(
proxyBaseUrl + "/metadata?key=value", xpathBase + "/@xlink:href", dom);
}
}
代码示例来源:origin: org.geoserver/gs-wcs1_1
@Test
public void testSkipMisconfigured() throws Exception {
// enable skipping of misconfigured layers
GeoServerInfo global = getGeoServer().getGlobal();
global.setResourceErrorHandling(ResourceErrorHandling.SKIP_MISCONFIGURED_LAYERS);
getGeoServer().save(global);
// manually misconfigure one layer
CoverageInfo cvInfo = getCatalog().getCoverageByName(getLayerId(MockData.TASMANIA_DEM));
ReferencedEnvelope BBox = cvInfo.getLatLonBoundingBox();
try {
cvInfo.setLatLonBoundingBox(null);
getCatalog().save(cvInfo);
// check we got everything but that specific layer, and that the output is still schema
// compliant
Document dom =
getAsDOM(BASEPATH + "?request=GetCapabilities&service=WCS&version=1.1.1");
checkValidationErrors(dom, WCS11_SCHEMA);
// print(dom);
int count = getCatalog().getCoverages().size();
assertEquals(count - 2, dom.getElementsByTagName("wcs:CoverageSummary").getLength());
} finally {
cvInfo.setLatLonBoundingBox(BBox);
getCatalog().save(cvInfo);
}
}
代码示例来源:origin: org.geoserver/gs-restconfig
@Test
public void testWorkspacesWithProxyHeaders() throws Exception {
GeoServerInfo ginfo = getGeoServer().getGlobal();
SettingsInfo settings = getGeoServer().getGlobal().getSettings();
ginfo.setUseHeadersProxyURL(true);
settings.setProxyBaseUrl(
"${X-Forwarded-Proto}://${X-Forwarded-Host}/${X-Forwarded-Path} ${X-Forwarded-Proto}://${X-Forwarded-Host}");
ginfo.setSettings(settings);
getGeoServer().save(ginfo);
assertEquals(
200,
getAsServletResponse(RestBaseController.ROOT_PATH + "/workspaces.xml").getStatus());
Document dom = getAsDOM(RestBaseController.ROOT_PATH + "/workspaces.xml");
assertEquals(0, dom.getElementsByTagName("workspace").getLength());
super.login();
dom = getAsDOM(RestBaseController.ROOT_PATH + "/workspaces.xml");
assertEquals(
getCatalog().getWorkspaces().size(),
dom.getElementsByTagName("workspace").getLength());
assertEquals(
200,
getAsServletResponse(RestBaseController.ROOT_PATH + "/workspaces.xml").getStatus());
dom = getAsDOM(RestBaseController.ROOT_PATH + "/workspaces.xml");
assertEquals(
getCatalog().getWorkspaces().size(),
dom.getElementsByTagName("workspace").getLength());
}
代码示例来源:origin: geoserver/geoserver
@Test
public void testContextStartup() {
GeoServer config = (GeoServer) applicationContext.getBean("geoServer");
assertNotNull(
config.getCatalog()
.getFeatureTypeByName(
MockData.BUILDINGS.getNamespaceURI(),
MockData.BUILDINGS.getLocalPart()));
assertNotNull(
config.getCatalog()
.getFeatureTypeByName(
MockData.BASIC_POLYGONS.getNamespaceURI(),
MockData.BASIC_POLYGONS.getLocalPart()));
}
}
代码示例来源:origin: geoserver/geoserver
@RunTestSetup
@Test
public void testGeoServerReload() throws Exception {
Catalog cat = getCatalog();
FeatureTypeInfo lakes =
cat.getFeatureTypeByName(
MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
assertFalse("foo".equals(lakes.getTitle()));
GeoServerDataDirectory dd = new GeoServerDataDirectory(getResourceLoader());
File info = dd.findResourceFile(lakes);
// File info = getResourceLoader().find("featureTypes", "cite_Lakes", "info.xml");
FileReader in = new FileReader(info);
Element dom = ReaderUtils.parse(in);
Element title = ReaderUtils.getChildElement(dom, "title");
title.getFirstChild().setNodeValue("foo");
OutputStream output = new FileOutputStream(info);
try {
TransformerFactory.newInstance()
.newTransformer()
.transform(new DOMSource(dom), new StreamResult(output));
} finally {
output.close();
}
getGeoServer().reload();
lakes =
cat.getFeatureTypeByName(
MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
assertEquals("foo", lakes.getTitle());
}
代码示例来源:origin: org.geoserver/gs-wfs
void doTestSrsNameSyntax11(SrsNameStyle srsNameStyle, boolean doSave) throws Exception {
if (doSave) {
WFSInfo wfs = getWFS();
GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_11);
gml.setSrsNameStyle(srsNameStyle);
getGeoServer().save(wfs);
}
String q = "wfs?request=getfeature&service=wfs&version=1.1.0&typename=cgf:Points";
Document d = getAsDOM(q);
assertEquals("wfs:FeatureCollection", d.getDocumentElement().getNodeName());
XMLAssert.assertXpathExists(
"//gml:Envelope[@srsName = '" + srsNameStyle.getPrefix() + "32615']", d);
XMLAssert.assertXpathExists(
"//gml:Point[@srsName = '" + srsNameStyle.getPrefix() + "32615']", d);
}
}
内容来源于网络,如有侵权,请联系作者删除!