【发布时间】:2011-04-14 18:26:35
【问题描述】:
我有一个带有可能引发异常的 Web 方法的 JAX-WS Web 服务。
@WebMethod
public Folder getTree() throws UnauthorizedException {
//...
// Get authorization data..
//...
if (!authorized) {
throw new UnauthorizedException();
}
//...
}
如果用户被授权,它可以正常工作,但是当抛出异常时,它不会生成带有错误的 SOAP 消息,它只会使 Web 服务崩溃
SEVERE: Unauthorized
ru.cos.xdoc.storage.UnauthorizedException: Unauthorized
at ru.cos.xdoc.storage.Storage.getTree(Storage.java:136)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
并关闭连接
HTTP/1.1 500 Internal Server Error
X-Powered-By: Servlet/2.5
Server: Sun GlassFish Enterprise Server v2.1.1
Content-Type: text/xml;charset="utf-8"
Transfer-Encoding: chunked
Date: Mon, 20 Sep 2010 15:43:59 GMT
Connection: close
我觉得我错过了一些简单的事情
编辑 已证明该问题仅在 Web 方法开始后不久引发异常的情况下出现。在抛出异常之前引入延迟时,例如
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
throw new UnauthorizedException();
一切正常。
有没有人知道是什么导致了这种奇怪的行为?
【问题讨论】: