CancellableConnection () { return new CancellableConnection() { PostMethod myMethod; @Override protected void doTest() throws Exception { if (StringUtil.isNotEmpty(myToken)) { myMethod = getLogoutMethod(); LOG.debug("Revoking previously used token"); getHttpClient().executeMethod(myMethod); } myMethod = getLoginMethod(); login(myMethod); } @Override public void cancel() { if (myMethod != null) { myMethod.abort(); } } }; }