0

Few words about my enviroment : Geoserver deployed on container (env Tomcat 7, dev Jetty), with module using postgresql 9.xx. Thing is, that geoserver uses postgresql 8.4 and we are replacing it with 9.3 on web-inf/lib(dont ask why etc.) Everything was working fine until I needed to introduce LargeObjects handling from Postgres. On dev env(jetty+netbeans) everything was fine, but as soon as WAR gets deployed on tomcat Im geting :

java.lang.NoSuchMethodError: org.postgresql.PGConnection.getLargeObjectAPI()Lorg/postgresql/largeobject/LargeObjectManager;

Here is code snippet which causes above:

PGConnection pgDbconn = (PGConnection) dbConn;
LargeObjectManager largeObjectAPI = pgDbconn.getLargeObjectAPI(); // first method
LargeObjectManager lobj = new LargeObjectManager((BaseConnection) pgDbconn); // second - directly

From what I saw on http://grepcode.com/file/repo1.maven.org/maven2/postgresql/postgresql/8.4-702.jdbc4/org/postgresql/PGConnection.java#PGConnection.getFastpathAPI%28%29 and http://grepcode.com/file/repo1.maven.org/maven2/org.postgresql/postgresql/9.3-1102-jdbc41/org/postgresql/PGConnection.java#PGConnection.getLargeObjectAPI%28%29 method exists on both jars. Any ideas why Im getting NoSuchMethodError, and whats the solution?

EDIT: Only postgresql9.xxx on web-inf/lib. Full stacktrace

org.jboss.resteasy.spi.UnhandledException: java.lang.NoSuchMethodError: org.postgresql.PGConnection.getLargeObjectAPI()Lorg/postgresql/largeobject/LargeObjectManager;
    org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:365)
    org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:233)
    org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:209)
    org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:557)
    org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:524)
    org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:126)
    org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
    org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
    org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.geoserver.filters.ThreadLocalsCleanupFilter.doFilter(ThreadLocalsCleanupFilter.java:27)
    org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:74)
    org.geoserver.wms.animate.AnimatorFilter.doFilter(AnimatorFilter.java:70)
    org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:70)
    org.geoserver.monitor.MonitorFilter.doFilter(MonitorFilter.java:137)
    org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:70)
    org.geoserver.flow.controller.IpBlacklistFilter.doFilter(IpBlacklistFilter.java:92)
    org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:70)
    org.geoserver.filters.SpringDelegatingFilter.doFilter(SpringDelegatingFilter.java:45)
    org.geoserver.platform.AdvancedDispatchFilter.doFilter(AdvancedDispatchFilter.java:49)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:68)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:72)
    org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:68)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:72)
    org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    org.geoserver.security.filter.GeoServerAnonymousAuthenticationFilter.doFilter(GeoServerAnonymousAuthenticationFilter.java:53)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:68)
    org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:72)
    org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    org.geoserver.security.filter.GeoServerBasicAuthenticationFilter.doFilter(GeoServerBasicAuthenticationFilter.java:82)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:68)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    org.geoserver.security.filter.GeoServerSecurityContextPersistenceFilter$1.doFilter(GeoServerSecurityContextPersistenceFilter.java:52)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:72)
    org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
    org.geoserver.security.GeoServerSecurityFilterChainProxy.doFilter(GeoServerSecurityFilterChainProxy.java:134)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    org.geoserver.filters.LoggingFilter.doFilter(LoggingFilter.java:75)
    org.geoserver.filters.GZIPFilter.doFilter(GZIPFilter.java:42)
    org.geoserver.filters.SessionDebugFilter.doFilter(SessionDebugFilter.java:47)
    org.geoserver.filters.FlushSafeFilter.doFilter(FlushSafeFilter.java:43)
    org.vfny.geoserver.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:109)

root cause

java.lang.NoSuchMethodError: org.postgresql.PGConnection.getLargeObjectAPI()Lorg/postgresql/largeobject/LargeObjectManager;
    org.geoserver.attachmentRS.AttachmentRS.getFile(AttachmentRS.java:310)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:483)
    org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
    org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269)
    org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227)
    org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:216)
    org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:542)
    org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:524)
    org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:126)
    org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
    org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
    org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.geoserver.filters.ThreadLocalsCleanupFilter.doFilter(ThreadLocalsCleanupFilter.java:27)
    org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:74)
    org.geoserver.wms.animate.AnimatorFilter.doFilter(AnimatorFilter.java:70)
    org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:70)
    org.geoserver.monitor.MonitorFilter.doFilter(MonitorFilter.java:137)
    org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:70)
    org.geoserver.flow.controller.IpBlacklistFilter.doFilter(IpBlacklistFilter.java:92)
    org.geoserver.filters.SpringDelegatingFilter$Chain.doFilter(SpringDelegatingFilter.java:70)
    org.geoserver.filters.SpringDelegatingFilter.doFilter(SpringDelegatingFilter.java:45)
    org.geoserver.platform.AdvancedDispatchFilter.doFilter(AdvancedDispatchFilter.java:49)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:68)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:72)
    org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:68)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:72)
    org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    org.geoserver.security.filter.GeoServerAnonymousAuthenticationFilter.doFilter(GeoServerAnonymousAuthenticationFilter.java:53)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:68)
    org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:72)
    org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    org.geoserver.security.filter.GeoServerBasicAuthenticationFilter.doFilter(GeoServerBasicAuthenticationFilter.java:82)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:68)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    org.geoserver.security.filter.GeoServerSecurityContextPersistenceFilter$1.doFilter(GeoServerSecurityContextPersistenceFilter.java:52)
    org.geoserver.security.filter.GeoServerCompositeFilter$NestedFilterChain.doFilter(GeoServerCompositeFilter.java:72)
    org.geoserver.security.filter.GeoServerCompositeFilter.doFilter(GeoServerCompositeFilter.java:91)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)
    org.geoserver.security.GeoServerSecurityFilterChainProxy.doFilter(GeoServerSecurityFilterChainProxy.java:134)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    org.geoserver.filters.LoggingFilter.doFilter(LoggingFilter.java:75)
    org.geoserver.filters.GZIPFilter.doFilter(GZIPFilter.java:42)
    org.geoserver.filters.SessionDebugFilter.doFilter(SessionDebugFilter.java:47)
    org.geoserver.filters.FlushSafeFilter.doFilter(FlushSafeFilter.java:43)
    org.vfny.geoserver.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:109)
stzmk
  • 3
  • 2
  • What's the full stacktrace, and do you have any other postgres jars on the runtime classpath? – Kayaman Dec 10 '14 at 09:57
  • @Kayaman Also please notice, that postgresql artifact changed groupid from postgresql in 8.xx to org.postgresql in 9.xx, may this be the issue? However, all other methods from both jars are working fine. – stzmk Dec 10 '14 at 10:04
  • Artifact change can't cause a `NoSuchMethodError`. Is the source code for Geoserver available? I'd go snoop around `org.geoserver.attachmentRS.AttachmentRS.getFile(AttachmentRS.java:310)`, but it still doesn't change the fact that `NSME` comes from the simple reason of having a different compile vs. runtime API. But if the method has been around since 7.3, it seems unlikely that you have a pre-7.3 JAR file lying hidden somewhere. – Kayaman Dec 10 '14 at 10:23
  • The class you pointed is our module, (310 is the code snippet in first post) using the feral GetLargeObjectAPI. And Im 100% sure that there is no pre 7.3 JAR lying anywhere. – stzmk Dec 10 '14 at 10:26

2 Answers2

0

Well then. Examine your mystical PGConnection class as follows:

PGConnection pgDbconn = (PGConnection) dbConn;
Class<PGConnection> clazz = pgDbconn.getClass();
for(Method m : clazz.getDeclaredMethods()) {
   log.info(m.getReturnType() + " " + m.getName());
}

Maybe that will shed some more light on your problem.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
  • The connection is `org.postgresql.jdbc4.Jdbc4Connection`, declared methods return only this specific class properties, however it inherits from jdbc2connection, which indeed has getLargeObjectApi and getFastpathAPI. Also the same code ran from console application stub works fine, when postgresql 8.4 or 9.3 is used. – stzmk Dec 10 '14 at 12:33
  • Well, what about using `getMethods()`. If the method is there (with a matching signature), try calling it with reflection. There's some black magic going on. – Kayaman Dec 10 '14 at 12:44
  • I agree on the black magic part : reflection invocation of method gave `java.lang.reflect.InvocationTargetException`: : `Caused by: java.lang.NoSuchMethodError: org.postgresql.core.BaseConnection.getFastpathAPI()Lorg/postgresql/fastpath/Fastpath; at org.postgresql.largeobject.LargeObjectManager.(LargeObjectManager.java:105) at org.postgresql.jdbc2.AbstractJdbc2Connection.getLargeObjectAPI(AbstractJdbc2Connection.java:382)` – stzmk Dec 10 '14 at 13:02
0

I solved it. The offending class was 7KB JAR on my WEB-INF/LIB called postgis-stubs. Probably it got loaded instead of postgresql, resulting in NSME. PGCONNECTION from postgis stubs

Thanks @kayaman, thanks for the second user, who mentioned about wrong driver loaded.

stzmk
  • 3
  • 2
  • Hah, that makes sense. This would've helped to determine it too: http://stackoverflow.com/questions/1983839/determine-which-jar-file-a-class-is-from – Kayaman Dec 11 '14 at 09:25