Java Reference
In-Depth Information
} catch
catch ( Exception ex ) {
response . resume ( ex );
return
return ;
}
Response response = Response . ok ( confirmation ,
MediaType . APPLICATION_XML_TYPE )
. build ();
response . resume ( response );
}
}. start ();
}
}
Invoking AsyncResponse.resume(Throwable) is like throwing an exception from a regular
synchronous JAX-RS method. Standard JAX-RS exception handling is performed on the
passed-in Throwable . If a matching ExceptionMapper exists for the passed-in Throwable , it
will be used. Otherwise, the server will send back a 500 status code.
Cancel
There's a few other convenience methods on AsyncResponse we haven't covered yet:
package
package javax . ws . rs . container ;
public
public interface
interface AsyncResponse
AsyncResponse {
boolean
boolean cancel ();
boolean
boolean cancel ( int
int retryAfter );
boolean
boolean cancel ( Date retryAfter );
...
}
Each of the cancel() methods is really a precanned call to resume() :
// cancel()
response . resume ( Response . status ( 503 ). build ());
// cancel(int)
response . resume ( Response . status ( 503 )
. header ( HttpHeaders . RETRY_AFTER , 100 )
. build ());
// cancel(Date)
response . resume ( Response . status ( 503 )
. header ( HttpHeaders . RETRY_AFTER , date )
. build ());
Search WWH ::




Custom Search