i am currently trying to understand the exception handling in JHipster.
I want to throw an exception in a service. The exception message shall be translated in the UI and parameters shall be set for the message. The CustomParameterizedException would fit perfectly. But from an architectural perspective, i think i can't use it in a service, as the exception is located in the web package. Why is it located in the web package? I would expect it to be in an own package exception or similar, so it can be accessed from every layer in the application.
I've also seen in the ExceptionTranslator.processRuntimeException method, that any RuntimeException can be handled, if the ResponseStatus annotation is set on the Exception. As far as i can see, the translation in the UI will only be done based on the error code. So i cannot use it for custom error messages, that i need.
How do you do the exception handling in other layers than the web layer in a jHipster application?
Thanks for your help in advance!
CustomParameterizedException is in a web package because it uses ParameterizedErrorVM which is a view model which gets serialized in JSON and used by Angular part of your app. This is generated code, feel free to change it to fit your needs.
Spring MVC offers several ways to handle exceptions as shown in this blog post.
You could also uses AOP to implement a default processing like logging or translating exceptions, see LoggingAspect in your JHipster app.
Related
I started using SpringBoot and like it a lot. I see that #RestController automatically serializes POJOs to json. I like that functioonality, but would like to use it outside of a web server context.
Basically I'd like to have all the part of SpringBoot until the point where the response is in JSON format, but then I don't want to deliver it via a web server, but rather my own implementation.
Is there an interface I have to implement in order to get SpringBoot to accept non-web-requests and return non-web-responses.
An example to make clear what I want:
Right now I can access localhost:8080/hello and SpringBoot will return "world".
Is there a way to make this work on console. E.g. I enter "hello" on console and press enter and I get "world" delivered to console by SpringBoot.
So instead of a web interface via tomcat I'd like to implement a console interface but with the same SpringBoot functionality.
UPDATE: The console application was probably not the right example. I am looking for a more general approach. So let's say instead of a console interface I want an Arduino to be able to send "hello" to SpringBoot via a serial bluetooth connection and SpringBoot should return "world" on that same bluetooth serial connection. My question is, whether there is an interface I need to implement in order to tell SpringBoot how to accept REST requests and how to send responses. And I don't want to focus on a particular implementation (like console or BT serial), but instead, once the SpringBoot application is created, I'd like to just replace the tomcat web interface by a BT serial interface or a console interface or any other interface I want to implement, but keep all of the logic (Controllers, Models etc).
Thanks.
Sure! You can create a console application.
You will need to create a class that implements ConsoleRunner. Please find a tutorial here:
https://www.baeldung.com/spring-boot-console-app
If it is the JSON de/serialization that interests you.
You can use Jackson's ObjectMapper .
You don't need the whole spring-boot web stuff.
You can ommit the starter-web dependency and use CommandLineRunner and jackson to have a console application that de/serializes your responses/requests to json.
Im migrating my code to a core application.
So far so good. i got it all running, but there is one problem.
I had a ui (with razor) and using the CatchAllHandlers. And for the api i used HandlerFactoryPath to prefix the urls.
Now i have 2 problems:
It seems CatchAllHandlers isn't used?
Route is only processed if route starts with HandlerFactoryPath?
The second issue is fixable but how would i go around the first one?
Do i make my own middle-ware or does servicestack support other ways of doing this?
CatchAllHandlers are executed in .NET Core, it's also what ServiceStack's new MVC RazorFormat uses to process Content Pages.
Specifying a HandlerFactoryPath, e.g:
SetConfig(new HostConfig {
HandlerFactoryPath = "api"
});
Tells ServiceStack that you only want to listen to requests from the /api path info. All other requests are passed through ServiceStack who calls the next module in .NET Core pipeline as per .NET Core's convention when it's not configured to handle a route.
Not sure if it's relevant to your solution but in ServiceStack .NET Core you can register a ServiceStack Handler in .NET Core module pipeline so you could for instance return a /default.cshtml Content Razor Page for each request that's not handled by ServiceStack, by registering it after ServiceStack:
app.UseServiceStack(new AppHost());
app.Use(new RazorHandler("/default"));
I try to extract the XML data for a form using the REST service like this :
http://localhost:8080/orbeon/fr/service/mysql/crud/<App-name>/<form-name>/data/<document_id>/data.xml
I first had to adapt the properties-local.xml to allow public access to the service, and now I can get in, but the server returns an HTTP 500, and I see a nice org.orbeon.oxf.common.ValidationException being throwed up.
In the stack trace I see that it tries to perform some XSLT transformation, but I only ask for the xml form data, so it should'nt. Or am I wrong ?
The MySQL Persistence Layer is working well.
Any hints ?
You can't directly call the specific persistence layers, because they need to receive special configuration headers. Instead, call the persistence service:
http://localhost:8080/orbeon/fr/service/persistence/crud/<App-name>/<form-name>/data/<document_id>/data.xml
The persistence service passes what is needed to the persistence layers.
I'm using BlazeDS to connect my Flex front end to my Java backend, and was wondering if there is any way I can get the complete stack trace in case of an exception to be passed to the front end. When I set a break point in the exception handler in Flex, I just see a basic message, fault string etc.
Would appreciate any help.
Thanks!
You could create a custom exception; then catch all serverside exceptions at highest level and rethrow your custom exception with the stacktrace of the original exception as a property. You should be able to access this clientside.
Also, if you're using Spring on the server side, the Spring BlazeDS integration can translate server-side exceptions into cleaner client-side ones using exception translators.
When I read a message with a WSO2 ESB Proxy, I need to define a specific datatype and this is then applying a certain MessageBuilder (defined in the axis2.xml).
But when the MessageBuilder fails (i.e. I try to read a text file with the XMLBuilder) I get an exception in the console, but my "faultSequence" is not called. But I need to do a certain Error Handling in case of any read problem.
How can I catch Exceptions from the Transport Layer (MessageBuilder) in a Proxy?
As far as i understand , your requirement is to catch an Error in the Transport layer and handle that in the Application level (i.e : Mediation level). which means the layer above.
But i think it violates layered architecture of the messaging framework. You should catch the Exception at the Message Builder itself and throw an Axis Fault so that underlying synapse transport layer (in this case Axis2) will handle that error. (It will send a fault to the client.)
If we look at the TCP protocol stack that is the practice which is commonly used.
If you really want to filter this errors at mediation level. Catch that Error in the Message Builder and add a Message Context property or custom message and pass it as a successful message. And Do a filter in mediation level and handle.
But again that is ugly.
:)
--Charith
Have you defined onError attribute in your configuration?
<sequence name="main" onError="myFaultSequence">
You can have more information in this sample.