9.15. WebServiceContext
WebServiceContext はエンドポイントが初期化される時点で設定できるインジェクションが可能リソースとして扱われます。 WebServiceContext オブジェクトは次に、 同じエンドポイントオブジェクト宛ての複数の要求処理に同時使用されているスレッド数に関係なく、 スレッドローカル情報を使用して正しい情報を返します。
@WebService
public class EndpointJSE
{
@Resource
WebServiceContext wsCtx;
@WebMethod
public String testGetMessageContext()
{
SOAPMessageContext jaxwsContext = (SOAPMessageContext)wsCtx.getMessageContext();
return jaxwsContext != null ? "pass" : "fail";
}
...
@WebMethod
public String testGetUserPrincipal()
{
Principal principal = wsCtx.getUserPrincipal();
return principal.getName();
}
@WebMethod
public boolean testIsUserInRole(String role)
{
return wsCtx.isUserInRole(role);
}
}