“ 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. javascript - node得到req不能得到boolean2. node.js - nodejs+express+vue3. node.js - 剛裝上最新node,npm install報這個錯誤!求ndoe大神解答!!!4. mysql - 查詢 修改數(shù)據(jù)庫優(yōu)化問題吧5. 做Redis集群的時候,可不可以將Master實例和Slave實例放在一個主機當(dāng)中?6. html - angular項目中如何讓外鏈網(wǎng)頁在本項目中展示?7. node.js - mongoDB使用$gte的問題8. Help!求幫助9. linux - 將java項目部署在vbox的centos系統(tǒng)上,無法實現(xiàn)外網(wǎng)訪問到j(luò)ava項目10. wordpress - nginx 反代 Varnish 走 Https ,WP后臺 ‘您沒有足夠的權(quán)限訪問該頁面。’

網(wǎng)公網(wǎng)安備