0

I am trying to update the GeoServer layer style using REST API. First I wrote a function to update the layer and SLDon GeoServer and then another function to update the default style of uploaded. this all works perfectly fine. I deployed the same on an Ubuntu 20.04 server. On the server, everything else works fine including uploading sld, layer, and then publishing the layer. but updating default style does not work and gives an error of 403.

Code for Updating style

 var workspaceName = 'national';
 var storeName = 'FM_ICT_2012';
 var filePath = 'F:/xampp/htdocs/upload/uploads/FM_ICT_2012.tif';
 var fileName = 'FM_ICT_2012';
 var sldUrl = 'http://localhost/upload/uploads/FM_ICT_2012.sld'
async function updateStyle(){
  var url =
          "http://localhost:8080/geoserver/rest/layers/"+workspaceName+":" + fileName;
       
          var xhr = new XMLHttpRequest();
    xhr.open("PUT", url);
    xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
    xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
    xhr.setRequestHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS');
    xhr.setRequestHeader('Access-Control-Allow-Headers', '*');
    xhr.setRequestHeader('Access-Control-Max-Age', '1728000');
    xhr.setRequestHeader("Content-type", "text/xml");
    xhr.setRequestHeader("Authorization", "Basic YWRtaW46Z2Vvc2VydmVy");       
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4) {
        // console.log(xhr.status);
        console.log(xhr, 'log at 117');
        if (xhr.statusText == "Created" || xhr.statusText == "OK"){
          console.log('layer style updated');
                  }
        else{
          console.log('style could not be added');
          return;
        }
      }
    };
       
    var data = `<layer><defaultStyle><name>`+fileName+`</name></defaultStyle><enabled>true</enabled></layer>`;
  await xhr.send(data);
}

there might be some permission issues on the geoserver side but I have same configuration on a local server and the test code work perfectly fine over there as well. Please guide on how can this issue be resolved or if geoserver needs any permissions to be allowed to let REST APIs update the default style

Geoserver logs are as follows

2022-05-27 17:03:50,903 INFO [gwc.layer] - Truncating default style for layer kp:FM_ICT_2012, as it changed from kp:FM_ICT_2012 to raster
2022-05-27 17:03:50,905 INFO [seed.GWCTask] - Thread group finished TRUNCATE task after 0.0 seconds
2022-05-27 17:03:50,905 INFO [seed.GWCTask] - Thread group finished TRUNCATE task after 0.0 seconds
2022-05-27 17:03:50,906 INFO [seed.GWCTask] - Thread group finished TRUNCATE task after 0.0 seconds
2022-05-27 17:03:50,906 INFO [seed.GWCTask] - Thread group finished TRUNCATE task after 0.0 seconds
2022-05-27 17:03:50,908 INFO [seed.GWCTask] - Thread group finished TRUNCATE task after 0.0 seconds
2022-05-27 17:03:50,908 INFO [geoserver.gwc] - Saving GeoSeverTileLayer kp:FM_ICT_2012
2022-05-27 17:03:50,908 INFO [seed.GWCTask] - Thread group finished TRUNCATE task after 0.0 seconds
2022-05-27 17:03:50,912 WARN [catalog.impl] - Catalog listener threw exception handling event.
java.lang.NullPointerException
    at org.geoserver.security.SecureCatalogImpl.checkAccess(SecureCatalogImpl.java:657)
    at org.geoserver.security.SecureCatalogImpl.checkAccess(SecureCatalogImpl.java:531)
    at org.geoserver.security.SecureCatalogImpl.checkAccess(SecureCatalogImpl.java:664)
    at org.geoserver.security.SecureCatalogImpl.checkAccess(SecureCatalogImpl.java:511)
    at org.geoserver.security.SecureCatalogImpl.filterGroups(SecureCatalogImpl.java:1022)
    at org.geoserver.security.SecureCatalogImpl.getLayerGroups(SecureCatalogImpl.java:324)
    at org.geoserver.catalog.impl.AbstractFilteredCatalog.getLayerGroups(AbstractFilteredCatalog.java:229)
    at org.geoserver.catalog.impl.AbstractCatalogDecorator.getLayerGroups(AbstractCatalogDecorator.java:442)
    at org.geoserver.catalog.impl.LocalWorkspaceCatalog.getLayerGroups(LocalWorkspaceCatalog.java:393)
    at org.geoserver.gwc.layer.CatalogLayerEventListener.handleLayerInfoChange(CatalogLayerEventListener.java:435)
    at org.geoserver.gwc.layer.CatalogLayerEventListener.handlePostModifyEvent(CatalogLayerEventListener.java:282)
    at org.geoserver.catalog.impl.CatalogImpl.event(CatalogImpl.java:1735)
    at org.geoserver.catalog.impl.CatalogImpl.firePostModified(CatalogImpl.java:1711)
    at org.geoserver.catalog.impl.AbstractCatalogFacade.afterSaved(AbstractCatalogFacade.java:65)
    at org.geoserver.catalog.impl.DefaultCatalogFacade.save(DefaultCatalogFacade.java:416)
    at org.geoserver.catalog.impl.IsolatedCatalogFacade.save(IsolatedCatalogFacade.java:179)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.geoserver.catalog.LockingCatalogFacade.invoke(LockingCatalogFacade.java:36)
    at com.sun.proxy.$Proxy28.save(Unknown Source)
    at org.geoserver.catalog.impl.CatalogImpl.save(CatalogImpl.java:757)
    at org.geoserver.security.SecureCatalogImpl.save(SecureCatalogImpl.java:1371)
    at org.geoserver.catalog.impl.AbstractFilteredCatalog.save(AbstractFilteredCatalog.java:678)
    at org.geoserver.catalog.impl.AbstractCatalogDecorator.save(AbstractCatalogDecorator.java:348)
    at org.geoserver.catalog.impl.LocalWorkspaceCatalog.save(LocalWorkspaceCatalog.java:309)
    at org.geoserver.catalog.CascadeDeleteVisitor.removeStyleInLayer(CascadeDeleteVisitor.java:194)
    at org.geoserver.catalog.CascadeDeleteVisitor.visit(CascadeDeleteVisitor.java:242)
    at org.geoserver.catalog.impl.StyleInfoImpl.accept(StyleInfoImpl.java:141)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.geoserver.catalog.impl.ModificationProxy.invoke(ModificationProxy.java:127)
    at com.sun.proxy.$Proxy30.accept(Unknown Source)
    at org.geoserver.web.data.SelectionRemovalLink$1.onSubmit(SelectionRemovalLink.java:69)
    at org.geoserver.web.wicket.GeoServerDialog.submit(GeoServerDialog.java:163)
    at org.geoserver.web.wicket.GeoServerDialog$4.onSubmit(GeoServerDialog.java:175)
    at org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink$1.onSubmit(AjaxSubmitLink.java:111)
    at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior$AjaxFormSubmitter.onSubmit(AjaxFormSubmitBehavior.java:215)
    at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1309)
    at org.apache.wicket.markup.html.form.Form.process(Form.java:976)
    at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:797)
    at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(AjaxFormSubmitBehavior.java:171)
    at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:155)
    at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:601)
    at jdk.internal.reflect.GeneratedMethodAccessor590.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
    at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241)
    at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248)
    at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234)
    at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:895)
    at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
    at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265)
    at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222)
    at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293)
    at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:261)
    at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:203)
    at org.apache.wicket.protocol.http.WicketServlet.doPost(WicketServlet.java:159)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    at org.springframework.web.servlet.mvc.ServletWrappingController.handleRequestInternal(ServletWrappingController.java:166)
    at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:177)
    at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.apache.catalina.filters.CorsFilter.handleNonCORS(CorsFilter.java:357)
    at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:176)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.geoserver.filters.ThreadLocalsCleanupFilter.doFilter(ThreadLocalsCleanupFilter.java:26)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:69)
    at org.geoserver.wms.animate.AnimatorFilter.doFilter(AnimatorFilter.java:70)
    at org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:66)
    at org.geoserver.filters.SpringDelegatingFilter.doFilter(SpringDelegatingFilter.java:41)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.geoserver.platform.AdvancedDispatchFilter.doFilter(AdvancedDispatchFilter.java:37)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
    at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:70)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
    at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:74)
    at org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:70)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
    at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:74)
    at org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.geoserver.security.filter.GeoServerAnonymousAuthenticationFilter.doFilter(GeoServerAnonymousAuthenticationFilter.java:51)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:70)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
    at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:74)
    at org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    at org.geoserver.security.filter.GeoServerUserNamePasswordAuthenticationFilter.doFilter(GeoServerUserNamePasswordAuthenticationFilter.java:122)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:70)
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:158)
    at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:74)
    at org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:70)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
    at org.geoserver.security.filter.GeoServerSecurityContextPersistenceFilter$1.doFilter(GeoServerSecurityContextPersistenceFilter.java:52)
    at org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:74)
    at org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
    at org.geoserver.security.GeoServerSecurityFilterChainProxy.doFilter(GeoServerSecurityFilterChainProxy.java:142)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.geoserver.filters.LoggingFilter.doFilter(LoggingFilter.java:101)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.geoserver.filters.XFrameOptionsFilter.doFilter(XFrameOptionsFilter.java:77)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.geoserver.filters.GZIPFilter.doFilter(GZIPFilter.java:47)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.geoserver.filters.SessionDebugFilter.doFilter(SessionDebugFilter.java:46)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.geoserver.filters.FlushSafeFilter.doFilter(FlushSafeFilter.java:42)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:359)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:889)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
    at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:829)
2022-05-27 17:03:51,606 INFO [platform.resource] - Notifying ENTRY_MODIFY change on /opt/tomcat/apache-tomcat-9.0.59/webapps/geoserver/data/gwc-layers. Created: 0, removed: 0, modified: 1
4
  • What errors do you see in the log file?
    – Ian Turton
    Commented May 27, 2022 at 17:20
  • I have added the logs in the question as well I don't see any errors in this as well.
    – alauddin
    Commented May 28, 2022 at 10:29
  • looks like permissions - can you change the style with the GUI?
    – Ian Turton
    Commented May 29, 2022 at 15:53
  • yes, I can do that. I can even do that with the same API through postman. but not from the deployed application
    – alauddin
    Commented May 29, 2022 at 16:03

1 Answer 1

0

After searching a lot and looking at the configuration files I found out that I had not enabled the GET method for GeoServer in the Data directory web.xml file. After adding all the CORS filters and methods, the issue got resolved.

Your Answer

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

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