UndeclaredThrowableException due to SQLException in Spring + iBatis? - spring

I am getting the following exception when I typo the SQL driver name or the database server is offline, basically any SQLException.
I can't determine where the UndeclaredThrowableException is coming from. Line 194 in SqlMapClientTemplate is this:
logger.debug("Obtained JDBC Connection [" + springCon + "] for iBATIS operation");
Here is the trace:
java.lang.reflect.UndeclaredThrowableException
$Proxy59.toString(Unknown Source)
java.lang.String.valueOf(Unknown Source)
java.lang.StringBuffer.append(Unknown Source)
org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:194)
org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(SqlMapClientTemplate.java:249)
org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:296)
org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClientTemplate.java:290)
some of my reading points to some type of class loading problem? I can't figure out where the $Proxy is getting introduced?

The $Proxy59 class must be the type of the springCon variable. It is a JDK proxy type, probably introduced by the Spring framework, as a wrapper for the real connection. I know of a pooled connection provider that returns connections which suppress the close() method via a proxy (because the connection is pooled, calling close is not the client's task).
Maybe the proxy's handler for the toString() method throws a checked exception, which is possible with the proxy mechanics, but not allowed.
The Java Documentation says:
"If a checked exception is thrown by invoke that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException will be thrown by the method invocation on the proxy instance. The UndeclaredThrowableException will be constructed with the exception that was thrown by the invoke method."
Do you get any other exception logged, maybe directly before that, or mentioned as the exception cause?

Related

Upgrading from WebLogic 12.1.3 to 12.2.1.4 breaks our application using Spring Framework 3.0.2

Our company is having us upgrade from Oracle WebLogic 12.1.3 to 12.2.1.4 since 12.1.3 is out of support/going out of support.
We have a major application that is using Spring Framework v3.0.2. When we deploy the EAR to 12.2.1.4 and attempt to consume any of the web services, we get this error stack trace. I've removed names that specify our company with generic names but you should be able to get the gist of what is happening:
2021-06-02 15:21:50.019/27.406 Oracle Coherence GE 12.2.1.4.0 (thread=[STANDBY] ExecuteThread: '10' for queue: 'weblogic.kernel.Default (self-tuning)', member=n/a): Configured versioned, multi-cluster Management over ReST
02.06.2021 15:22:11 - error trying to getBean("DefaultJBL"): Error creating bean with name 'DefaultJBL' defined in URL [zip:C:/javadev/server/appserver.12.2.1.4/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/lasor/2wlg44/lib/Lasor_core-1.0.jar!/com/foo/app/corebuslogic/common/jbl/DefaultJBL.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Unexpected AOP exception; nested exception is java.lang.RuntimeException: java.lang.ClassNotFoundException: com.foo.app.corebuslogic.common.exceptions.LoggedException
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DefaultJBL' defined in URL [zip:C:/javadev/server/appserver.12.2.1.4/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/app/2wlg44/lib/App_core-1.0.jar!/com/foo/app/corebuslogic/common/jbl/DefaultJBL.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Unexpected AOP exception; nested exception is java.lang.RuntimeException: java.lang.ClassNotFoundException: com.aep.lasor.corebuslogic.common.exceptions.LoggedException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1045)
at com.foo.util.FOOApplicationContext.fetchBean(FOOApplicationContext.java:203)
at com.foo.app.buslogic.common.generic.GenericSessionBean.getBL(GenericSessionBean.java:293)
at com.foo.app.buslogic.common.generic.GenericSessionBean.query(GenericSessionBean.java:97)
I also believe the API is SOAP in 12.1.3 but I see REST specified in the 12.2.1.4 logs. Could this be the issue or am I reading that incorrectly?
Also, the classes is says it cannot find I've verified are there in the deployment area of WebLogic so I'm not sure why it can't find them.
Here is where the code throws an exception no matter what bean name I pass in but they've all been defined. The class is our FOOApplicationContext that implements org.springframework.context.ApplicationContextAware and has a fetchBean function that does the following:
public static Object fetchBean(final String beanName) throws FOOException {
Object object = null;
if (beanName == null) {
throw new FOOException("beanName is null");
}
try {
object = currentSpringContext().getBean(beanName);
} catch (Exception e) {
final String message = "error trying to getBean('"" + beanName + "\"): " + e.getMessage();
throw new FOOException(message, e);
}
return object;
}
When getBean() is called under WebLogic 12.1.3, it works. But it throws the AOP Exception error listed above when this exact same function is called under WebLogic 12.4.1.2. No code changes, etc. Not sure why this is.
We haven't created an actual server yet to deploy to, but instead I've installed it locally on my development machine. I've set up the database connections, etc the same way as do when locally installing 12.1.3. Is there something that has changed in regards to Spring Framework? The code was written over 8+ years ago and I inteherited the support for it and now I have to get us moved to WebLogic 12.2.1.4 before the end of this year and this is a major part of a very important application. The WebLogic application houses all the business logic and database access in it so without it, the front-end app is dead in the water.
Also, none of our registered beans will instantiate at all under WebLogic 12.2.1.4 but it works under 12.1.3. I've even recompiled the EAR file and again, it works under 12.1.3 but not 12.2.1.4.
I've found what appears to be a possibly circular reference between 2 objects that are not registered as beans, but the beans do depend on. So those 2 objects are not registered as beans. Not sure why it was done that way, but in any case, this doesn't seem to create a problem in 12.1.3. But one of the objects (FOOException) shows up in the error thrown when trying to create the DefaultJBL bean within the FOOApplicationContext object.
I'm not sure what else I can provide. Searching around the internet has not found a solution to my issue. I've found some that appeared as if they would fix it, but they turn out to not apply. I cannot seem to find anyone else with this issue, but Google and Duck Duck Go all find various "solutions" that don't apply to my situation.
Thanks!
ClassNotFound Exception, You may need to update the Dependencies pertaining to Spring Framework

How can I catch the ProvisioningException that can occur when Spring kafka cannot connect to Producer endpoint?

How can I catch the ProvisioningException that can occur when Spring kafka cannot connect to Producer endpoint during Spring-Boot initialization phase?
I am using the lib called spring-cloud-stream, or in my case, more specifically: spring-cloud-starter-stream-kafka .
I assume there must be a way to define a config-Bean, or AOP, that might be able to catch the null error thrown due to connection problems? The existing error is not informative enough when connectivity is gone:
Caused by: java.util.concurrent.TimeoutException: null
at org.apache.kafka.common.internals.KafkaFutureImpl$SingleWaiter.await(KafkaFutureImpl.java:108)
at org.apache.kafka.common.internals.KafkaFutureImpl.get(KafkaFutureImpl.java:272)
at org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner.createTopicAndPartitions(KafkaTopicProvisioner.java:355)
at org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner.createTopicIfNecessary(KafkaTopicProvisioner.java:329)
at org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner.createTopic(KafkaTopicProvisioner.java:306)
I'm talking about the "Bean Creation Phases" documented here: https://reflectoring.io/spring-bean-lifecycle/ which describes how to hook your own code to initialization phases but I want to hook 3rd party code.
NOTE: The bounty is expired. An answer outside of the context of Spring Kafka is ok the answer is still relevant to my question.
NOTE: I found another question that also does not provide a good answer: Spring - catch bean creation exception
you can for example Capture that in ExcepcionHander
#ControllerAdvice
#RestController
public class ExceptionHandler {
#ExceptionHandler(value = {ProvisioningException.class})
public void handleException(ProvisioningExceptione) {
....code....
}
I mean the main paoint is to know when do you get this error....
when invoking a method the method should throw it but instead if it is on the initializacion or something like that, it is diferent. I can see such information in your question, please be more specific

What exceptions can be thrown by exchange() on WebClient?

I've implemented a service which makes ReST calls out to other services to implement part of its functionality. I'm using the reactive WebClient for this, something like:
webClient.post()
.uri(....)
.contentType(....)
.accept(....)
.header(....)
.syncBody(someRequestObject)
.exchange()
.flatMap(someResponseHandler::handleResponse)
.doOnError(throwable -> {
// do interesting things depending on throwable
})
.retry(1, this::somePredicateDependingOnThrowable);
Now... I handle HTTP statuses in someResponseHandler::handleResponse, but what I really want to know is, what other kinds of exception/error to expect from the exchange() - i.e.
what exceptions/errors do I get if I can't connect to the downstream service at all?
What exceptions/errors do I get if the connection attempt times out?
What exceptions/errors do I get if I can connect but then the request times out before I get a response?
None of these are HTTP status codes, obviously - but I can't find any documentation to tell me what I can look for. Am I just not looking in the right places? I've had a look through the documentation for the reactive WebClient, and I've had a look through the Reactor Netty Reference Guide, but no luck.
For background, this is important because we do HATEOAS-based service discovery - for some of these exceptions, I want to trigger rediscovery, for some of them, I don't.
I recommend testing your code that uses the WebClient to see how it handles the various scenarios you mentioned. You can test your code against something like MockWebServer easily from unit tests. MockWebServer can simulate most of the errors mentioned here.
Having said that, here's what I have seen in my testing when using WebClient with the ReactorClientHttpConnector. Other connectors may throw slightly different exceptions, but will likely share a super class in the exception class hierarchy as those mentioned below.
Unknown host
java.net.UnknownHostException
Connection refused (port not open on server)
java.net.ConnectException (or subclass)
reactor-netty throws io.netty.channel.AbstractChannel$AnnotatedConnectException
Connect timeout
If you have configured a connect timeout, then you will receive java.net.ConnectException (or subclass)
reactor-netty throws io.netty.channel.ConnectTimeoutException
SSL handshake errors
javax.net.ssl.SSLHandshakeException (or subclass)
Request body encoding error
This varies by the encoder being used, but generally will be org.springframework.core.codec.EncodingException (or subclass)
Some encoders also throw java.lang.IllegalStateException if encoding is configured incorrectly
Response body decoding error
This varies by the decoder being used, but generally will be org.springframework.core.codec.DecodingException (or subclass)
Some decoders also throw java.lang.IllegalStateException if decoding is configured incorrectly
Read Timeout
If using reactor-netty, and you configured a io.netty.handler.timeout.ReadTimeoutHandler, then io.netty.handler.timeout.ReadTimeoutException
If you use the .timeout operator somewhere in the reactive stream call chain, then java.util.concurrent.TimeoutException
Write Timeout
If using reactor-netty, and you configured a io.netty.handler.timeout.WriteTimeoutHandler, then io.netty.handler.timeout.WriteTimeoutException
Connection closed by server prematurely (before response completes)
java.io.IOException (or subclass)
reactor-netty throws reactor.netty.http.client.PrematureCloseException
Others
Any exceptions that occur during your someResponseHandler::handleResponse

EJB call to varargs method failing from Java7 client

We have stateless session bean (EJB 3.0) that has a method which accepts varargs(variable arguments) as inputs. Method signature is as below:-
public String operation1(String arg1,List...arg4);
This EJB is deployed on Weblogic 10.3.2 running on a "Java6" JRE.
When this EJB method is invoked from a Java6 standalone client, the call is successful.
When I change the JRE from Java6 to Java7(without changing any other client code),the call fails with an unmarshal exception(Stack trace below).
javax.ejb.EJBException: Could not unmarshal method ID; nested exception is:
java.rmi.UnmarshalException: Method not found: 'operation1(Ljava.lang.String;Ljava.util.List...;)'; nested exception is: java.rmi.UnmarshalException: Method not found: 'operation1(Ljava.lang.String;Ljava.util.List...;)'
at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.unwrapRemoteException(RemoteBusinessIntfProxy.java:109)
at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:91)
at com.sun.proxy.$Proxy5.operation1(Unknown Source)
at com.MyEJBStandaloneClient.testOperation1(MyEJBStandaloneClient.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
EJB Code
#Stateless(mappedName = "MyBean")
public class MyBean implements MyBeanRemote{
public String operation1(String arg1,List...arg4) {
System.out.println("Input1 is:-"+arg1);
return "newString";
}
}
Remote class
#Remote
public interface MyBeanRemote {
public String operation1(String arg1,List... arg4);
}
The non-varargs methods(if any are added), within the same EJB are invoked successfully from Java7 clients & it is only the varargs methods in the EJB that have this problem.
Note that the same call works fine even with Java7 if the method signature on the Remote interface class is changed to the following
public String operation1(String arg1,List[] arg4);
But is there any way to make it work without changing the method signature?
Are there any known issues around this?
Thanks.
The problem you described is the consequence of an old bug from WebLogic.
In fact, EJB methods using varargs are ignored when it generates its stub classes.
The deep reason is that WebLogic EJB compiler incorrectly tries to append a transient modifier to the varargs argument.
Obviously, it results in an error, and so, the method stub is not generated.
At that time BEA created a path, CR327275, for WebLogic 10.0.MP1 to correct the issue. Unfortunately, this patch was apparently NOT included in WebLogic 10.3 release...
Feedbacks on this point are not that easy to find, but the Seam community made some. Here they are:
http://in.relation.to/Bloggers/Weblogic10SeamAndEJB3#H-Option1ApplyTheTtCR327275ttPatchBut
https://docs.jboss.org/seam/2.1.2/reference/en-US/html/weblogic.html
So, to solve your issue:
either, as you guessed, you have to change the method signature
or you contact WebLogic to get and install the former patch.
Regards,
Thomas

OSGi DS: Why are exceptions thrown by binding methods only logged?

Why is it spec to only log an exception thrown from a binding method?
I would expect that the component would not activate in this case.
How should exceptions thrown from binding methods be handled to ensure the component is set up correctly?
Just because the binding of a service reference throws an exception does not necessarily mean the component cannot be activated. Since the component is aware of the exception (after all, it's the binding method that threw it), it can be implemented in such a way that it can still be activated, e.g. by falling back on a default value or by providing limited services.
Binding methods should not throw any exception anyway, unlike activation methods that can make the activation fail.
Reference:
OSGi 112.5.7: "If a bind method throws an exception, SCR must log an error message containing the exception with the Log Service, if present, but the activation of the component configuration does not fail."

Resources