I have a spring mvc portlet that remotely calls an ejb 3. Now when the ejb throws an exception, on the portal side I just see 'EJB Exception'. I do not have access to the actual ejb 3 logs. So what can I do so that the whole exception stack trace is available on the portal side?
You can catch the EJBException (note that it's a RuntimeException, so, your code is not 'required' to catch it) and then call the getCausedByException method, to have access to the original exception. With it, you can do whatever you want, including rethrow it.
Related
So I have this web service that I am testing using MS Test and I want to get the original exception class which is InvalidOperationException. However whenever I run my test, the exception that I get is the FaultException class (which is the default exception when consuming a web service). I only get the exception in the message property of the exception.
Below is the exception message that I am getting.
`System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: Invalid Entity\n at BL.Lib.WebService.BLWebServiceImpl.UpdateIDNumber(GetUpdateIDNumberRequest idNumberRequest) in [some file]:line 369\n at SSMWebService.Blacklist.BLWebService.BlacklistUpdateIDNumber(GetUpdateIDNumberRequest request) in [some asmx file]:line 132\n --- End of inner exception stack trace ---
Is there a way to get the InvalidOperationException class from the web service?
In .NET Core you can easily add a detailed exception page for developers:
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
This then gives you the exception details:
However, I'd like to include additional exception detail - for instance the SQL query attempted when the exception is a SqlException.
I can write my own exception handler from scratch with app.UseExceptionHandler, but I'd rather extend the built-in error. For instance by adding a tab to the results including additional info.
Is it possible to extend the information on this exception page?
What is the concept behind exception handling in Spring Integration or any other EAI framework: Are they treated as a Message?
Lets say that a JMS timeout exception was thrown from jms-outbound-gateway. Now it has to be moved all the way upto the parent custom gateway addEmployeeGateway which defines a method called addEmployee which throws a custom exception called SystemDownException. These two components are connected through request and reply channels and thats the only medium of communication. Does it mean that Exceptions are also treated as messages?
Also, if i had to map the JMS timeout exception to my custom exception SystemDownException and rethrow the SystemDownException how and where would i achieve this. I dont want to use an errorchannel.
The general mechanism for handling exceptions is an error-channel on the inbound (or some intermediate) endpoint; the ErrorMessage payload has failedMessage and cause properties.
The mechanism is similar to try {...} catch {...} in Java.
I dont want to use an errorchannel.
Alternatively, you can configure a custom request handler advice on the JMS outbound gateway; there, you can do whatever you want, including throwing your SystemDownException after catching an exception on callback.execute().
I have just implemented exception handling for a unique-constraint of a JPA entity. It is working as I want it to, but when triggered dumps the handled exceptions to the container logfile.
A JPA entity is managed by a SLSB (Service Façade). The Service Façade is called from another SLSB, which provides remoting capabilities based on JAX-RS.
In the Service Façade, the EntityManager operations are wrapped in a try-catch-block, detecting the cause of the unique-constraint-violation. It then throws a custom checked ApplicationException.
The REST-Bean catches the ApplicationException and throws a custom unchecked BadRequestException.
An ExceptionMapper outputs the BadRequestException to the remote client.
This is all working well. The part that I don't understand is: the (handled) exceptions get logged in the container's logfile (complete with a long stacktrace):
[#|2010-09-29T18:49:39.185+0200|WARNING|glassfish3.0.1|org.eclipse.persistence.session.file:/Users/hank/NetBeansProjects/CoreServer/build/classes/_coreServerPersistenceUnit|_ThreadID=30;_ThreadName=Thread-1;|
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry....
....
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry....
and from throwing the BadRequestException:
[#|2010-09-29T18:49:39.336+0200|WARNING|glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=30;_ThreadName=Thread-1;|A system exception occurred during an invocation on EJB ShopperResource method public javax.ws.rs.core.Response mvs.gateway.ShopperResource.create(javax.xml.bind.JAXBElement)
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119)
....
Caused by: mvs.api.exception.BadRequestException: mvs.api.exception.MvsCause: Field 'MSISDN' must be unique!
Is this how it should be? I thought since I handle the exceptions, they wouldn't be dumped to the log?
The exceptions are logged because you have exception logging enabled.
Exceptions get logged by default when your log level is WARNING or greater. If you set your log level to SEVERE or OFF then they will not be logged.
i.e.
"eclipselink.logging.level"="SEVERE"
You can also set the "eclipselink.logging.exceptions"="false" property to disable just exception logging.
See,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging
It's the database layer that does the logging of the exceptions. The time you catch them they are already written to the log.
I have a custom portlet made for liferay and sometimes it throws an exception. Why it throws exceptions is irrelevant.
How to catch exceptions thrown by portlet handler methods in order to email information about them? I know I could do try catching on every handler method but it would be a much more elegant and cleaner solution to catch the exception on a higher level and just email some information about the error.
I'm using Spring Portlet MVC, so i got all spring-related niceties at hand.
Problem(s) solved.
Made a class that implements org.springframework.web.portlet.HandlerExceptionResolver and declared it in applicationContext.xml:
<bean id="myExeptionResolver" class="net.foo.bar.MyExeptionResolver" />
Spring picks the class up and magically knows what it's for.
For the emailing I used Liferay's MailEngine.
I created a maven archetype for spring based portlet. There is an implementation of exception resolver that emails an administrator based on level of priority.