我在PostGIS的Tomcat容器中运行GeoServer,并使用OpenLayers 3 WFS事务(AJAX POST中的xml)将一个点(一次)插入数据库。工作区是mypoints,商店是my_points。这是Javascript:
// MY_POINT LAYER
var mypointssource = new ol.source.Vector({
url: 'http://localhost:8080/geoserver/mypoints/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=mypoints:my_points&srsname=EPSG:4326&outputFormat=application/json',
format: new ol.format.GeoJSON()
});
var mypoints = new ol.layer.Vector({
source: mypointssource,
style: new ol.style.Style({
image: new ol.style.Circle({
radius: 8,
fill: new ol.style.Fill({color: 'yellow'})
})
})
});
// DRAW_PNT LAYER
var drawpntsource = new ol.source.Vector();
var drawpnt = new ol.layer.Vector({
source: drawpntsource,
style: new ol.style.Style({
image: new ol.style.Circle({
radius: 3,
fill: new ol.style.Fill({
color: 'red'
})
})
})
});
// MAPQUEST TILE LAYER
var tile = new ol.layer.Tile({
source: new ol.source.MapQuest({layer: 'sat'})
});
// THE VIEW
var pointview = new ol.View({
center: [0, 0],
zoom: 3,
maxZoom: 16
});
// THE MAP
var map = new ol.Map({
target: 'map',
layers: [tile, mypoints, drawpnt],
view: pointview
});
// REFOCUS VIEW ON MYPOINTS +/- SOME PADDING
mypointssource.on('change', function(e) {
if (mypointssource.getState() == 'ready') {
var paddedExtent = [];
ext = mypointssource.getExtent();
var dX = 0.08 * (ext[2] - ext[0]);
var dY = 0.08 * (ext[3] - ext[1]);
paddedExtent.push(ext[0] - dX);
paddedExtent.push(ext[1] - dY);
paddedExtent.push(ext[2] + dX);
paddedExtent.push(ext[3] + dY);
pointview.fit(paddedExtent, map.getSize());
}
});
// DRAW INTERACTION
var entry = {};
var drawbutton = $('#draw');
var drawinteraction = new ol.interaction.Draw({
source: drawpntsource,
type: 'Point'
});
// DRAW TOGGLE BUTTON:
var active = false;
function toggleDraw() {
if (active == false) {
map.addInteraction(drawinteraction);
active = true;
} else {
map.removeInteraction(drawinteraction);
active = false;
}
}
// ADD EVENT HANDLER TO BUTTON
drawbutton.on('click', toggleDraw);
// WFS TRANSACTION FORMAT OBJ
var wfst = new ol.format.WFS({
featureNS: 'mypoints',
featureType: 'my_points',
schemaLocation: "http://schemas.opengis.net/wfs/1.0.0/wfs.xsd \
http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd \
http://localhost:8080/geoserver/mypoints/wfs/DescribeFeatureType?" +
"typename=mypoints:my_points"
});
// ON DRAW END
drawinteraction.on('drawend', function(evt) {
map.removeInteraction(drawinteraction);
drawbutton.hide();
var newpoint = evt.feature;
newpoint.set('the_geom', newpoint.getGeometry());
newpoint.set('geometry', null);
newpoint.set('title', "A generic title");
var node = wfst.writeTransaction([newpoint], null, null, {
gmlOptions: {srsName: "EPSG:3857"},
featureNS: "mypoints",
featureType: "my_points"
});
$('#messagebox').text(new XMLSerializer().serializeToString(node));
// THE WFS AJAX TRANSACTION REQUEST:
$.ajax({
type: "POST",
url: "http://localhost:8080/geoserver/mypoints/wfs",
data: new XMLSerializer().serializeToString(node),
contentType: 'text/xml',
success: function(data) {
var result = wfst.readTransactionResponse(data);
$('#messagebox').text(data);
console.log(data);
},
error: function(e) {
var errorMsg = e ? (e.status + ' ' + e.statusText) : "";
$('#messagebox').text(errorMsg);
},
context: this
});
});
大约有80%的时间可以正常工作,并且偶尔与我能够识别3天以上的任何内容相关,这会导致此服务器错误:
06 Feb 15:18:00 INFO [geoserver.wfs] -
Request: getServiceInfo
06 Feb 15:18:00 WARN [geotools.xml] - Schema location not specified as namespace/location pair. Ignoring http://localhost:8080/geoserver/mypoints/wfs/DescribeFeatureTypetypename=mypoints:my_points
06 Feb 15:18:00 ERROR [geoserver.ows] -
java.lang.IllegalArgumentException: java.lang.ClassCastException@59fa8bfc
at sun.reflect.GeneratedMethodAccessor224.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.geoserver.ows.Dispatcher.execute(Dispatcher.java:845)
at org.geoserver.ows.Dispatcher.handleRequestInternal(Dispatcher.java:275)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.filters.CorsFilter.handleSimpleCORS(CorsFilter.java:301)
at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:169)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.geoserver.filters.ThreadLocalsCleanupFilter.doFilter(ThreadLocalsCleanupFilter.java:28)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:75)
at org.geoserver.wms.animate.AnimatorFilter.doFilter(AnimatorFilter.java:71)
at org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:71)
at org.geoserver.filters.SpringDelegatingFilter.doFilter(SpringDelegatingFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.geoserver.platform.AdvancedDispatchFilter.doFilter(AdvancedDispatchFilter.java:50)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:69)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:73)
at org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:92)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:69)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:73)
at org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:92)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.geoserver.security.filter.GeoServerAnonymousAuthenticationFilter.doFilter(GeoServerAnonymousAuthenticationFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:69)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:73)
at org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:92)
at org.geoserver.security.filter.GeoServerBasicAuthenticationFilter.doFilter(GeoServerBasicAuthenticationFilter.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:69)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.geoserver.security.filter.GeoServerSecurityContextPersistenceFilter$1.doFilter(GeoServerSecurityContextPersistenceFilter.java:53)
at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:73)
at org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:92)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
at org.geoserver.security.GeoServerSecurityFilterChainProxy.doFilter(GeoServerSecurityFilterChainProxy.java:135)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.geoserver.filters.LoggingFilter.doFilter(LoggingFilter.java:87)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.geoserver.filters.GZIPFilter.doFilter(GZIPFilter.java:42)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.geoserver.filters.SessionDebugFilter.doFilter(SessionDebugFilter.java:48)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.geoserver.filters.FlushSafeFilter.doFilter(FlushSafeFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
我是GeoServer的新手,我想这个问题与我形成请求的方式有关。无论是URL还是与XML架构有关的东西,但对于我的生活,我无法弄清楚它是如何工作的,或者为什么它有时而不是其他工作。
注意:即使成功完成交易,架构位置未在顶部指定为命名空间/位置对警告,我也不认为这是直接原因,虽然如果有人知道那是什么,这是另一个问题......
谢谢!
答案 0 :(得分:0)
发现this回答非常有帮助。换句话说:基本上,当GeoServer获取 schemaLocation 中列出的XML模式定义时,如果.xsd文件驻留在同一服务器本身上(例如,它可以作为DescribeFeatureType请求访问,就像我有在我的ol.format.WFS选项中完成)它首先根据已知主机列表检查url的主机名。 然而,由于涉嫌错误,当它被引用为“localhost”时它不会识别自身,并且认为它是其他人它会自己向该文件发出GET请求。然后它产生一个线程来处理这个GET请求,该请求竞争使用初始线程访问模式文件。因此,偶尔会陷入僵局。
我已通过从事务XML的 schemaLocation 属性中删除DescribeFeatureType网址来解决此问题。