Throw custom exceptions in JAX-WS

I have a JAX-WS web service with a web method that can throw an exception.

@WebMethod
public Folder getTree() throws UnauthorizedException {
    //...
    // Get authorization data..
    //...
    if (!authorized) {
        throw new UnauthorizedException();
    }
    //...
}

It works correctly if the user is authorized, but when an exception is thrown, it does not generate a SOAP message with an error, it just resets the web service using

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)
    ...

and closes the connection

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  

It seems to me that I missed something simple

EDIT The problem only occurs if an exception is raised soon after the start of the web method. When a delay is introduced before throwing exceptions, for example

try {
    Thread.sleep(3000);
} catch (InterruptedException e) {
    e.printStackTrace();
}

throw new UnauthorizedException();

everything is working fine.

Does anyone know what might cause such strange behavior?

+3
source share
2 answers
+1

, , "Permission denied", - . , - , .

-1

Source: https://habr.com/ru/post/1765660/


All Articles