身份验证令牌已过期对输出流的影响

时间:2016-05-15 11:10:57

标签: java authentication httpurlconnection access-token

我正在基于身份验证令牌建立连接HttpURLConnection httpCon。并使用以下方式创建OutputStream out:     //初始

// Account account is created (joss.model.Account)
Access mAccess = account.authenticate();
String mToken = mAccess.getToken() 

String getAuthToken()
{
  return mToken; 
}

HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("PUT");
httpCon.addRequestProperty("X-Auth-Token", getAuthToken());
httpCon.addRequestProperty("Content-Type", contentType);

httpCon.setDoInput(true);
httpCon.setRequestProperty("Connection", "close");
httpCon.setReadTimeout(READ_TIMEOUT);
httpCon.setRequestProperty("Transfer-Encoding","chunked");
httpCon.setDoOutput(true);
httpCon.setChunkedStreamingMode(STREAMING_CHUNK);
OutputStream out   = httpCon.getOutputStream();

//Thread.sleep(expireTime * 1.2);
out.write("Data".getBytes()); //write to a file
out.close

身份验证令牌在几分钟后过期。如果我评论Thread.sleep(ExpireTime * 1.2);一切正常。如果没有,过期时间过去了 我认为我应该401 not authorized,但在这种情况下 我尝试在令牌过期后关闭OutputStream我在关闭时得到java.lang.NullPointerException并且最终没有写入任何内容(文件为空)。

我该如何解决?

0 个答案:

没有答案