“ java.lang.UnsupportedOperationException:尚不支持。”
您看過這段代碼片段了嗎?
@Override public Result authenticate(HttpExchange he) {throw new UnsupportedOperationException('Not supported yet.'); }
正是這種情況會(huì)在您每次嘗試進(jìn)行身份驗(yàn)證時(shí)引發(fā)上述異常。
因此,在我看來,解決身份驗(yàn)證問題的方法非常簡(jiǎn)單:實(shí)施此方法。
解決方法我正在嘗試做的是:
我正在嘗試使用Java連接到[使用https]的Web Portal。我已經(jīng)編寫了使用Authenticator類提供用戶憑據(jù)的代碼。運(yùn)行程序時(shí)出現(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瀏覽器中打開頁面時(shí),我得到登錄頁面;一旦提供了憑據(jù),就會(huì)顯示W(wǎng)eb門戶
有人可以建議如何訪問Webportal并提供我的憑據(jù)并檢查身份驗(yàn)證是否成功嗎?任何示例代碼片段都將對(duì)您有所幫助。
相關(guān)文章:
1. javascript - 如圖,百度首頁,查看源代碼為什么什么都沒有?2. android - weex 項(xiàng)目createInstanceReferenceError: Vue is not defined3. html - 關(guān)于CSS實(shí)現(xiàn)border的0.5px設(shè)置?4. javascript - 原生APP內(nèi)嵌H5頁面分享到微信朋友圈,二次分享問題。5. javascript - 為什么clearInterVal不起作用呢?6. PHPExcel表格導(dǎo)入數(shù)據(jù)庫怎么導(dǎo)入7. android - 哪位大神知道java后臺(tái)的api接口的對(duì)象傳到前端后輸入日期報(bào)錯(cuò),是什么情況?求大神指點(diǎn)8. pdo 寫入到數(shù)據(jù)庫的內(nèi)容為中文的時(shí)候?qū)懭雭y碼9. PHP類封裝的插入數(shù)據(jù),總是插入不成功,返回false;10. vue2.0+webpack 如何使用bootstrap?
