“ java.lang.UnsupportedOperationException:尚不支持。”
您看過這段代碼片段了嗎?
@Override public Result authenticate(HttpExchange he) {throw new UnsupportedOperationException('Not supported yet.'); }
正是這種情況會在您每次嘗試進行身份驗證時引發(fā)上述異常。
因此,在我看來,解決身份驗證問題的方法非常簡單:實施此方法。
解決方法我正在嘗試做的是:
我正在嘗試使用Java連接到[使用https]的Web Portal。我已經(jīng)編寫了使用Authenticator類提供用戶憑據(jù)的代碼。運行程序時出現(xiàn)異常:
“ java.lang.UnsupportedOperationException:尚不支持”
我有張貼的代碼:
public class Main { public class MyAuthenticator extends Authenticator {protected PasswordAuthentication getpasswordAuthentication() { String username = 'username'; String password = 'password'; // Return the information return new PasswordAuthentication(username,password.toCharArray());}@Overridepublic Result authenticate(HttpExchange he) { throw new UnsupportedOperationException('Not supported yet.');} } public static void main(String[] args) {// TODO code application logic hereTrustManager[] trustClients = new TrustManager[]{ new X509TrustManager() {public void checkClientTrusted(X509Certificate[] xcs,String string) throws CertificateException { throw new UnsupportedOperationException('Not supported yet.');}public void checkServerTrusted(X509Certificate[] xcs,String string) throws CertificateException { throw new UnsupportedOperationException('Not supported yet.');}public X509Certificate[] getAcceptedIssuers() { return null; //throw new UnsupportedOperationException('Not supported yet.');} }};try { SSLContext sslcontext = SSLContext.getInstance('SSL'); sslcontext.init(null,trustClients,new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory());} catch (Exception e) { System.out.println('in 1st catch ' + e);}try { URL url = new URL('https://someURL.server.com/fmk/jsp/ltpaLogin.jsp'); URLConnection urlconnection = url.openConnection(); System.out.println(urlconnection); System.out.print(urlconnection.getInputStream().toString());} catch (Exception e) { System.out.println('in 2ndcatch ' + e.getMessage());} }}
第二次Try中引發(fā)了異常“java.lang.UnsupportedOperationException:不支持”。我的方法正確嗎?如果沒有,還有其他選擇嗎?
當(dāng)我在Web瀏覽器中打開頁面時,我得到登錄頁面;一旦提供了憑據(jù),就會顯示W(wǎng)eb門戶
有人可以建議如何訪問Webportal并提供我的憑據(jù)并檢查身份驗證是否成功嗎?任何示例代碼片段都將對您有所幫助。
相關(guān)文章:
1. 在mybatis使用mysql的ON DUPLICATE KEY UPDATE語法實現(xiàn)存在即更新應(yīng)該使用哪個標(biāo)簽?2. mysql - 數(shù)據(jù)庫建字段,默認(rèn)值空和empty string有什么區(qū)別 1103. mysql - 這種分級一對多,且分級不平衡的模型該怎么設(shè)計表?4. Navicat for mysql 中以json格式儲存的數(shù)據(jù)存在大量反斜杠,如何去除?5. mac OSX10.12.4 (16E195)下Mysql 5.7.18找不到配置文件my.cnf6. mysql mysql_real_escape_string() 轉(zhuǎn)義問題7. 新人求教MySQL關(guān)于判斷后拼接條件進行查詢的sql語句8. mysql - 千萬數(shù)據(jù) 分頁,當(dāng)偏移量 原來越大時,怎么優(yōu)化速度9. MySQL FOREIGN KEY 約束報錯10. mysql - 數(shù)據(jù)庫表中,兩個表互為外鍵參考如何解決
