Summary of exception handling framework for Apache CXF Rest and Spring 3.0 MVC

Source: Internet
Author: User
Tags exception handling

There is no time to clean up, first give the data, how to implement a custom exception handling framework, the purpose is to throw out the definition exception in the rest request, and return the response of the abnormal JSON data.

has been using the predecessor in the Apache CXF framework encapsulated code to write the rest API, it is time to delve into the exception handling framework, and so the cottage of a spring MVC exception handling framework, feel a little bit of meaning, know a little bit of fur.


1 Customizing the Exceptionmapper of the JSR 311 (Restful) in CXF

http://blog.163.com/java_star/blog/static/117714805201201333531865/


2 Spring MVC Exception Unified processing (including demo source)

http://gaojiewyh.iteye.com/blog/1297746

Note: In this demo, if you want to return the JSON-formatted exception, you need to introduce the Jsonobject class, plus in the Controller

@ResponseBody

			else {//JSON format returns
				response.setstatus (401);
				try {
					Jsonobject jso = new Jsonobject ();
					try {
						jso.put ("Error", Ex.getmessage ());
					\ catch (jsonexception e) {
						//TODO auto-generated catch
						block E.printstacktrace ();
					}
					PrintWriter writer = Response.getwriter ();
					Writer.write (Jso.tostring ());
					Writer.flush ();
				} catch (IOException e) {
					e.printstacktrace ();
				}
			}

Look at the picture.


Add: spring3.0 Exception handling Advanced

http://blog.csdn.net/sinlff/article/details/5872724





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.