JAX-WS的异常处理

JAX-WS中的服务端的自定义异常使用javax.xml.ws.WebFault注解来完成,这样的异常会在WSDL文件中的<wsdl:operation...中的子元素<wsdl:fault...

package com.nantian.service;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.ws.WebFault;

@WebFault(name="HelloServiceException")
public class HelloServiceException extends Exception {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private HelloServiceFault details;

	public HelloServiceException(String msg) {
		super(msg);
	}

	public HelloServiceException(HelloServiceFault details) {
		super();
		this.details = details;
	}

	public HelloServiceFault getFaultInfo() {
		return details;
	}

	@XmlRootElement(name = "HelloServiceFault")
	public static class HelloServiceFault {
		private String t;

		public HelloServiceFault(String t) {
			super();
			this.t = t;
		}

		public HelloServiceFault() {
			super();
		}

		public String getT() {
			return t;
		}

		public void setT(String t) {
			this.t = t;
		}
		
	}
}

 这里需要注意一下几个问题:

1)自定义异常必须包含一个异常信息msg,和一个封装具体错误消息的bean,这个bean上必须使用JAXB注解

2)自定义异常必须有一个getDefaultInfo()的方法返回封装具体错误信息的bean

猜你喜欢

转载自liguangqinlong.iteye.com/blog/2343750