Tôi đang sử dụng JAX WS để hiển thị một WebService. Một số hoạt động của dịch vụ này có thể tạo ra ngoại lệ. Không phải ngoại lệ máy chủ nội bộ, mà là ngoại lệ phụ thuộc vào các đối số đầu vào của lời gọi hoạt động.JAX-WS - Bản đồ Ngoại lệ đối với lỗi
Nếu tôi xác định rằng hoạt động của tôi ném một ngoại lệ tùy chỉnh, như vậy:
@WebService
@SOAPBinding(style = Style.RPC, use = Use.LITERAL)
public class MyServiceEndpointImpl implements MyServiceEndpoint {
@WebMethod
public void throwsException throws InvalidInputException;
}
tôi kết thúc với stacktrace sau khi chạy ứng dụng:
com.sun.xml.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class com.mypackage.ws.services.jaxws.InvalidInputExceptionBean is not found. Have you run APT to generate them?
at com.sun.xml.ws.model.RuntimeModeler.getClass(RuntimeModeler.java:285)
at com.sun.xml.ws.model.RuntimeModeler.processExceptions(RuntimeModeler.java:1006)
at com.sun.xml.ws.model.RuntimeModeler.processRpcMethod(RuntimeModeler.java:969)
at com.sun.xml.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:546)
at com.sun.xml.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:370)
at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:256)
at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:322)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:188)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:467)
at org.jvnet.jax_ws_commons.spring.SpringService.getObject(SpringService.java:333)
at org.jvnet.jax_ws_commons.spring.SpringService.getObject(SpringService.java:45)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport$1.run(FactoryBeanRegistrySupport.java:121)
Thêm @XmlRootEntity
-InvalidInputException
không giải quyết vấn đề.
Nếu đây không phải là cách được khuyến nghị để báo cáo lỗi trên các dịch vụ web, thì có cách nào tốt hơn không? Trường hợp ngoại lệ của tôi có được kế thừa từ RuntimeException
và dựa vào phương tiện để xử lý lỗi (tức là, mọi thứ sẽ kết thúc trong một SOAPException)? Tôi đã hy vọng cho một cái gì đó giống như Spring-WS 'SoapFaultAnnotationExceptionResolver
. Có cái gì tương tự ở tất cả có sẵn cho JAX-WS?
Có lẽ tôi nên lưu ý rằng lớp mà nó báo cáo là bị thiếu, com.mypackage.ws.services.jaxws.InvalidInputExceptionBean, thực sự không tồn tại. Nhưng tôi cho rằng đó là tự nhiên, rằng nó sẽ được tạo ra như các trạng thái ngoại lệ. – waxwing