3

I am using the following code for insert / update (changed from this source: https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58):

var formatWFS = new ol.format.WFS();

// GML Format zur Interaktion mit WFS
var formatGML = new ol.format.GML({
  featureNS: 'http://my-address:8080/geoserver/web/myworkspace',
  featureType: 'MyWorkspace:MyLayer',
  srsName: myProjectionName
});

var transactWFS = function(transactionType,feature) {
  var node;
  switch(transactionType) {
    case 'insert':
      node = formatWFS.writeTransaction([feature],null,null,formatGML);
    break;
    case 'update':
      node = formatWFS.writeTransaction(null,[feature],null,formatGML);
      break;
    case 'delete':
      node = formatWFS.writeTransaction(null,null,[feature],formatGML);
      break;
  }
  s = new XMLSerializer();
  str = s.serializeToString(node);

  // XMLHttpRequest
  var xhttp = new XMLHttpRequest();
  var url = 'http://my-address:8080/geoserver/web/myworkspace/wfs';
  xhttp.open('POST', url, true);
  //xhttp.setRequestHeader('crossDomain', true);
  xhttp.setRequestHeader('dataType', 'xml');
  //xhttp.setRequestHeader('processData', false);
  xhttp.setRequestHeader('contentType', 'text/xml');
  //xhttp.onreadystatechange = handler;
  xhttp.send(str);
  xhttp.onreadystatechange = function() {
    console.log("Request Response: " + xhttp.responseText);
  };
}

The insert works like it should using this function:

// Button to add a Feature
$("#btn_add").click(function(e){
    e.preventDefault();
    // create feature from draw feature
    var feature = drawSource.getFeatures()[0];
    // set properties
    feature.setProperties({
      NAME: $("#name").val(),
      AGE: $("#age").val(),
      GEOLOC: feature.getGeometry()
    });
    // Insert feature
    transactWFS('insert', feature);
});

For update I am using this functions (taking values from text field like in the insert function and not changing the geometry):

// Button to change a Feature
$("#btn_change").click(function(e){
  e.preventDefault();
  // get selected feature from map (selectedFeature)
  var feature = selectedFeature;
  feature.setProperties({
      NAME: $("#name").val(),
      AGE: $("#age").val()
  });
  // update feature
  transactWFS('update', feature);
});

The update function is throwing this exception

<ows:Exception exceptionCode="NoApplicableCode">
  <ows:ExceptionText>Feature type 'MyWorkspace:MyLayer' is not available: </ows:ExceptionText>
</ows:Exception>

The feature type is not changed so I do not know why the insert is working but the update is not.

The "geoserver.log" Error Information (DEBUG level):

2015-12-01 11:36:22,184 INFO [geoserver.wfs] - Request: getServiceInfo 2015-12-01 11:36:22,200 DEBUG [geotools.xml] - schemaLocation found: http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd 2015-12-01 11:36:22,200 DEBUG [geotools.xml] - Found override for http://www.opengis.net/wfs: http://schemas.opengis.net/wfs/1.1.0/wfs.xsd ==> jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%208.0/webapps/geoserver/WEB-INF/lib/gs-wfs-2.8.0.jar!/org/geoserver/wfs/xml/v1_1_0/wfs.xsd 2015-12-01 11:36:22,200 DEBUG [geoserver.wfs] - Locating FeatureSource uri:'http://my-address:8080/geoserver/web/myworkspace' name:'MyWorkspace:MyLayer' 2015-12-01 11:36:22,200 ERROR [geoserver.ows] - org.geoserver.wfs.WFSTransactionException: Feature type 'MyWorkspace:MyLayer' is not available: at org.geoserver.wfs.Transaction.execute(Transaction.java:221) at org.geoserver.wfs.Transaction.transaction(Transaction.java:106) at org.geoserver.wfs.DefaultWebFeatureService.transaction(DefaultWebFeatureService.java:171) at sun.reflect.GeneratedMethodAccessor577.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.geoserver.ows.util.RequestObjectLogger.invoke(RequestObjectLogger.java:55) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at com.sun.proxy.$Proxy61.transaction(Unknown Source) at sun.reflect.GeneratedMethodAccessor576.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) 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.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:217) 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:142) 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:518) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2503) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2492) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) 2015-12-01 11:36:22,200 DEBUG [geoserver.filters] - Compressing output for mimetype: application/xml 2015-12-01 11:36:22,200 DEBUG [filter.GeoServerSecurityContextPersistenceFilter$1] - SecurityContextHolder now cleared, as request processing completed

And the input log to compare:

2015-12-01 11:43:58,111 DEBUG [geotools.xml] - schemaLocation found: http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd 2015-12-01 11:43:58,111 DEBUG [geotools.xml] - Found override for http://www.opengis.net/wfs: http://schemas.opengis.net/wfs/1.1.0/wfs.xsd ==> jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%208.0/webapps/geoserver/WEB-INF/lib/gs-wfs-2.8.0.jar!/org/geoserver/wfs/xml/v1_1_0/wfs.xsd 2015-12-01 11:43:58,111 DEBUG [geotools.xml] - Could not find declaration for: {http://my-address:8080/geoserver/web/myworkspace}geometry. Checking if containing type declares a single particle. 2015-12-01 11:43:58,111 DEBUG [geotools.xml] - Could not find declaration for: {http://my-address:8080/geoserver/web/myworkspace}geometry. Performing lookup by ignoring namespace 2015-12-01 11:43:58,111 DEBUG [geotools.xml] - Could not find declaration for: {http://my-address:8080/geoserver/web/myworkspace}geometry. Creating a mock element declaration and parsing anyways... 2015-12-01 11:43:58,126 DEBUG [geoserver.wfs] - Locating FeatureSource uri:'http://my-address:8080/geoserver/web/myworkspace' name:'MyLayer' 2015-12-01 11:43:58,126 DEBUG [geoserver.wfs] - located FeatureType w/ typeRef 'ORACLE MYDATASTORE:MyLayer' and elementName '{http://my-address:8080/geoserver/web/myworkspace}MyLayer' 2015-12-01 11:43:58,126 DEBUG [geoserver.wfs] - Transasction Insert:org.geoserver.wfs.request.Insert$WFS11@60401ca0 2015-12-01 11:43:58,126 TRACE [geotools.factory] - ENTRY (CoordinateOperationFactory, COORDINATE_OPERATION_FACTORY) 2015-12-01 11:43:58,126 TRACE [geotools.factory] - RETURN (CoordinateOperationFactory, COORDINATE_OPERATION_FACTORY): found implementation BufferedCoordinateOperationFactory. 2015-12-01 11:43:58,126 DEBUG [geoserver.wfs] - Use featureValidation to check contents of insert

7
  • 1
    are you sure the insert works or does it just not display an error? what is the datastore you are using on GeoServer? what does the DEBUG level log file say when it fails.
    – Ian Turton
    Dec 1, 2015 at 9:25
  • Yes I am sure the insert works properly. I am using an Oracle Database("Oracle NG - Oracle Database"). Where do I find this DEBUG level log? I attached the "geoserver.log" error to my question.
    – Lars
    Dec 1, 2015 at 9:49
  • You need to turn up the logging level in the global settings page - then you will see the actual XML received by GeoServer in the log.
    – Ian Turton
    Dec 1, 2015 at 10:25
  • I changed the logging level to DEBUG and attached the Input log for comparison.
    – Lars
    Dec 1, 2015 at 11:09
  • Figured it out: The featureType had to be set like this: featureType: 'MyLayer' and not to "MyWorkspace:MyLayer"! The DEBUG log helped though. Tank you.
    – Lars
    Dec 1, 2015 at 11:47

1 Answer 1

2

There was an error in the GML Format featureType Parameter:

var formatGML = new ol.format.GML({
  featureNS: 'http://my-address:8080/geoserver/web/myworkspace',
  featureType: 'MyLayer',
  srsName: myProjectionName
});

The featureType just needs the layername and not the "Workspace:LayerName"-format!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.